Skip to content

Commit

Permalink
fix: resource url
Browse files Browse the repository at this point in the history
  • Loading branch information
hongcha98 committed Feb 4, 2024
1 parent fff50aa commit 480ff96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libs/libwish/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ reqwest = { version = "0.11.20", features = [
], default-features = false }
parse_link_header = "0.3"
base64 = "0.21.3"
url = "2.4.1"
18 changes: 12 additions & 6 deletions libs/libwish/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use reqwest::{
Body, Method, Response, StatusCode,
};
use std::str::FromStr;
use url::Url;
use webrtc::{
ice_transport::ice_server::RTCIceServer,
peer_connection::sdp::session_description::RTCSessionDescription,
Expand Down Expand Up @@ -62,7 +63,16 @@ impl Client {
.ok_or_else(|| anyhow::anyhow!("Response missing location header"))?
.to_str()?
.to_owned();
self.resource_url = Some(resource_url);
let mut url = Url::parse(self.url.as_str())?;
match Url::parse(resource_url.as_str()) {
Ok(url) => {
self.resource_url = Some(url.into());
}
Err(_) => {
url.set_path(resource_url.as_str());
self.resource_url = Some(url.into());
}
}
let ice_servers = Self::parse_ide_servers(&response)?;
let sdp =
RTCSessionDescription::answer(String::from_utf8(response.bytes().await?.to_vec())?)?;
Expand All @@ -79,11 +89,7 @@ impl Client {
continue;
}
ice_servers.push(RTCIceServer {
urls: vec![link
.uri
.to_string()
.replacen("://", ":", 1)
.replace('/', "")],
urls: vec![link.uri.to_string()],
username: link.queries.remove("username").unwrap_or("".to_owned()),
credential: link.queries.remove("credential").unwrap_or("".to_owned()),
credential_type: link
Expand Down

0 comments on commit 480ff96

Please sign in to comment.