Skip to content

Commit

Permalink
Return whip_resource optionally if location exists and non-empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kc5nra committed Dec 15, 2022
1 parent 19710d1 commit 6994c0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
8 changes: 3 additions & 5 deletions plugins/obs-webrtc/webrtc/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,10 @@ impl OutputStream {
.local_description()
.await
.ok_or_else(|| anyhow!("No local description available"))?;
let answer = whip::offer(url, bearer_token, offer).await?;
self.peer_connection
.set_remote_description(answer.0)
.await?;
let (answer, whip_resource) = whip::offer(url, bearer_token, offer).await?;
self.peer_connection.set_remote_description(answer).await?;

*self.whip_resource.lock().unwrap() = answer.1;
*self.whip_resource.lock().unwrap() = whip_resource;

Ok(())
}
Expand Down
19 changes: 13 additions & 6 deletions plugins/obs-webrtc/webrtc/src/whip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,22 @@ pub async fn offer(
.send()
.await?;

// Retrieve resource from location and ensure it's non-empty
let whip_resource = res
.headers()
.get(LOCATION)
.map(|v| v.to_str().map(|v| v.to_owned()).ok())
.map(|v| {
v.to_str()
.map(|v| {
if v.is_empty() {
None
} else {
Some(v.to_owned())
}
})
.ok()
.flatten()
})
.flatten();

let body = res.text().await?;
Expand All @@ -40,11 +52,6 @@ pub async fn offer(
}

pub async fn delete(url: &str) -> Result<()> {
if url.is_empty() {
debug!("Not sending DELETE since there is no WHIP resource.");
return Ok(());
}

let client = reqwest::Client::new();

debug!("Sending DELETE to whip resource.");
Expand Down

0 comments on commit 6994c0d

Please sign in to comment.