From 2faca7374942aef79ff94bbfb3e578bf6bbb2817 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Thu, 22 Jun 2023 13:19:57 +0200 Subject: [PATCH] hls, webrtc: in the web page, pass query parameters to inner requests (#1976) --- internal/core/hls_http_server.go | 6 +++++- internal/core/hls_index.html | 2 +- internal/core/webrtc_http_server.go | 6 +++++- internal/core/webrtc_publish_index.html | 13 +++++++------ internal/core/webrtc_read_index.html | 6 +++--- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/internal/core/hls_http_server.go b/internal/core/hls_http_server.go index 53c3ac52..8b75fe3c 100644 --- a/internal/core/hls_http_server.go +++ b/internal/core/hls_http_server.go @@ -125,7 +125,11 @@ func (s *hlsHTTPServer) onRequest(ctx *gin.Context) { dir, fname = pa, "" if !strings.HasSuffix(dir, "/") { - ctx.Writer.Header().Set("Location", "/"+dir+"/") + l := "/" + dir + "/" + if ctx.Request.URL.RawQuery != "" { + l += "?" + ctx.Request.URL.RawQuery + } + ctx.Writer.Header().Set("Location", l) ctx.Writer.WriteHeader(http.StatusMovedPermanently) return } diff --git a/internal/core/hls_index.html b/internal/core/hls_index.html index 3c415b46..5956cf54 100644 --- a/internal/core/hls_index.html +++ b/internal/core/hls_index.html @@ -44,7 +44,7 @@ const create = () => { } }); - hls.loadSource('index.m3u8'); + hls.loadSource('index.m3u8' + window.location.search); hls.attachMedia(video); video.play(); diff --git a/internal/core/webrtc_http_server.go b/internal/core/webrtc_http_server.go index 6db986ee..4d4a5606 100644 --- a/internal/core/webrtc_http_server.go +++ b/internal/core/webrtc_http_server.go @@ -221,7 +221,11 @@ func (s *webRTCHTTPServer) onRequest(ctx *gin.Context) { publish = false if !strings.HasSuffix(dir, "/") { - ctx.Writer.Header().Set("Location", "/"+dir+"/") + l := "/" + dir + "/" + if ctx.Request.URL.RawQuery != "" { + l += "?" + ctx.Request.URL.RawQuery + } + ctx.Writer.Header().Set("Location", l) ctx.Writer.WriteHeader(http.StatusMovedPermanently) return } diff --git a/internal/core/webrtc_publish_index.html b/internal/core/webrtc_publish_index.html index 2251412b..6792d4ce 100644 --- a/internal/core/webrtc_publish_index.html +++ b/internal/core/webrtc_publish_index.html @@ -190,7 +190,7 @@ class Transmitter { start() { console.log("requesting ICE servers"); - fetch(new URL('whip', window.location.href), { + fetch(new URL('whip', window.location.href) + window.location.search, { method: 'OPTIONS', }) .then((res) => this.onIceServers(res)) @@ -223,11 +223,12 @@ class Transmitter { const audioCodec = document.getElementById('audio_codec').value; const videoBitrate = document.getElementById('video_bitrate').value; - let params = '?video_codec=' + videoCodec + - '&audio_codec=' + audioCodec + - '&video_bitrate=' + videoBitrate; + const p = new URLSearchParams(window.location.search); + p.set('video_codec', videoCodec); + p.set('audio_codec', audioCodec); + p.set('video_bitrate', videoBitrate); - fetch(new URL('whip', window.location.href) + params, { + fetch(new URL('whip', window.location.href) + '?' + p.toString(), { method: 'POST', headers: { 'Content-Type': 'application/sdp', @@ -293,7 +294,7 @@ class Transmitter { } sendLocalCandidates(candidates) { - fetch(new URL('whip', window.location.href), { + fetch(new URL('whip', window.location.href) + window.location.search, { method: 'PATCH', headers: { 'Content-Type': 'application/trickle-ice-sdpfrag', diff --git a/internal/core/webrtc_read_index.html b/internal/core/webrtc_read_index.html index 05845b8b..c178be51 100644 --- a/internal/core/webrtc_read_index.html +++ b/internal/core/webrtc_read_index.html @@ -104,7 +104,7 @@ class WHEPClient { start() { console.log("requesting ICE servers"); - fetch(new URL('whep', window.location.href), { + fetch(new URL('whep', window.location.href) + window.location.search, { method: 'OPTIONS', }) .then((res) => this.onIceServers(res)) @@ -138,7 +138,7 @@ class WHEPClient { console.log("sending offer"); - fetch(new URL('whep', window.location.href), { + fetch(new URL('whep', window.location.href) + window.location.search, { method: 'POST', headers: { 'Content-Type': 'application/sdp', @@ -204,7 +204,7 @@ class WHEPClient { } sendLocalCandidates(candidates) { - fetch(new URL('whep', window.location.href), { + fetch(new URL('whep', window.location.href) + window.location.search, { method: 'PATCH', headers: { 'Content-Type': 'application/trickle-ice-sdpfrag',