hls, webrtc: in the web page, pass query parameters to inner requests (#1976)

This commit is contained in:
Alessandro Ros 2023-06-22 13:19:57 +02:00 committed by GitHub
parent 5224531551
commit 2faca73749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 12 deletions

View File

@ -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
}

View File

@ -44,7 +44,7 @@ const create = () => {
}
});
hls.loadSource('index.m3u8');
hls.loadSource('index.m3u8' + window.location.search);
hls.attachMedia(video);
video.play();

View File

@ -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
}

View File

@ -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',

View File

@ -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',