From 289d0c4cac6f5d3a492bb314e26d5d72970726f5 Mon Sep 17 00:00:00 2001 From: Taruntej Kanakamalla Date: Mon, 9 Jun 2025 14:41:27 +0530 Subject: [PATCH] whip: server: pick session-id from the endpoint if specified Use any string present after the "whip/endpoint" in the POST url's endpoint as the session id of the producer Continue to generate a UUID for the session id if it is not specified as a part of the endpoint Part-of: --- net/webrtc/src/whip_signaller/imp.rs | 34 +++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/net/webrtc/src/whip_signaller/imp.rs b/net/webrtc/src/whip_signaller/imp.rs index 115cfdf62..449d584e9 100644 --- a/net/webrtc/src/whip_signaller/imp.rs +++ b/net/webrtc/src/whip_signaller/imp.rs @@ -792,8 +792,19 @@ impl WhipServer { async fn post_handler( &self, body: warp::hyper::body::Bytes, + id: Option, ) -> Result, warp::Rejection> { - let session_id = uuid::Uuid::new_v4().to_string(); + let session_id = match id { + Some(id) => { + gst::debug!(CAT, imp = self, "got session id {id} from the URL"); + id + } + None => { + gst::info!(CAT, imp = self, "no session id in the URL, generating UUID"); + uuid::Uuid::new_v4().to_string() + } + }; + let (tx, mut rx) = mpsc::channel::>(1); let wait_timeout = { let mut settings = self.settings.lock().unwrap(); @@ -986,7 +997,24 @@ impl WhipServer { #[weak(rename_to = self_)] self, #[upgrade_or_panic] - move |body| async move { self_.post_handler(body).await } + move |body| async move { self_.post_handler(body, None).await } + )); + + // POST /endpoint/ + let post_filter_with_id = warp::post() + .and(warp::path(ENDPOINT_PATH)) + .and(warp::path::param::()) + .and(warp::path::end()) + .and(warp::header::exact( + http::header::CONTENT_TYPE.as_str(), + CONTENT_SDP, + )) + .and(warp::body::bytes()) + .and_then(glib::clone!( + #[weak(rename_to = self_)] + self, + #[upgrade_or_panic] + move |id, body| async move { self_.post_handler(body, Some(id)).await } )); // OPTIONS /endpoint @@ -1029,7 +1057,7 @@ impl WhipServer { )); let api = prefix - .and(post_filter) + .and(post_filter.or(post_filter_with_id)) .or(prefix.and(options_filter)) .or(prefix.and(patch_filter)) .or(prefix.and(delete_filter));