Browse Source

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

pull/1978/head
Alessandro Ros 2 years ago committed by GitHub
parent
commit
2faca73749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      internal/core/hls_http_server.go
  2. 2
      internal/core/hls_index.html
  3. 6
      internal/core/webrtc_http_server.go
  4. 13
      internal/core/webrtc_publish_index.html
  5. 6
      internal/core/webrtc_read_index.html

6
internal/core/hls_http_server.go

@ -125,7 +125,11 @@ func (s *hlsHTTPServer) onRequest(ctx *gin.Context) {
dir, fname = pa, "" dir, fname = pa, ""
if !strings.HasSuffix(dir, "/") { 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) ctx.Writer.WriteHeader(http.StatusMovedPermanently)
return return
} }

2
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); hls.attachMedia(video);
video.play(); video.play();

6
internal/core/webrtc_http_server.go

@ -221,7 +221,11 @@ func (s *webRTCHTTPServer) onRequest(ctx *gin.Context) {
publish = false publish = false
if !strings.HasSuffix(dir, "/") { 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) ctx.Writer.WriteHeader(http.StatusMovedPermanently)
return return
} }

13
internal/core/webrtc_publish_index.html

@ -190,7 +190,7 @@ class Transmitter {
start() { start() {
console.log("requesting ICE servers"); console.log("requesting ICE servers");
fetch(new URL('whip', window.location.href), { fetch(new URL('whip', window.location.href) + window.location.search, {
method: 'OPTIONS', method: 'OPTIONS',
}) })
.then((res) => this.onIceServers(res)) .then((res) => this.onIceServers(res))
@ -223,11 +223,12 @@ class Transmitter {
const audioCodec = document.getElementById('audio_codec').value; const audioCodec = document.getElementById('audio_codec').value;
const videoBitrate = document.getElementById('video_bitrate').value; const videoBitrate = document.getElementById('video_bitrate').value;
let params = '?video_codec=' + videoCodec + const p = new URLSearchParams(window.location.search);
'&audio_codec=' + audioCodec + p.set('video_codec', videoCodec);
'&video_bitrate=' + videoBitrate; 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', method: 'POST',
headers: { headers: {
'Content-Type': 'application/sdp', 'Content-Type': 'application/sdp',
@ -293,7 +294,7 @@ class Transmitter {
} }
sendLocalCandidates(candidates) { sendLocalCandidates(candidates) {
fetch(new URL('whip', window.location.href), { fetch(new URL('whip', window.location.href) + window.location.search, {
method: 'PATCH', method: 'PATCH',
headers: { headers: {
'Content-Type': 'application/trickle-ice-sdpfrag', 'Content-Type': 'application/trickle-ice-sdpfrag',

6
internal/core/webrtc_read_index.html

@ -104,7 +104,7 @@ class WHEPClient {
start() { start() {
console.log("requesting ICE servers"); console.log("requesting ICE servers");
fetch(new URL('whep', window.location.href), { fetch(new URL('whep', window.location.href) + window.location.search, {
method: 'OPTIONS', method: 'OPTIONS',
}) })
.then((res) => this.onIceServers(res)) .then((res) => this.onIceServers(res))
@ -138,7 +138,7 @@ class WHEPClient {
console.log("sending offer"); console.log("sending offer");
fetch(new URL('whep', window.location.href), { fetch(new URL('whep', window.location.href) + window.location.search, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/sdp', 'Content-Type': 'application/sdp',
@ -204,7 +204,7 @@ class WHEPClient {
} }
sendLocalCandidates(candidates) { sendLocalCandidates(candidates) {
fetch(new URL('whep', window.location.href), { fetch(new URL('whep', window.location.href) + window.location.search, {
method: 'PATCH', method: 'PATCH',
headers: { headers: {
'Content-Type': 'application/trickle-ice-sdpfrag', 'Content-Type': 'application/trickle-ice-sdpfrag',

Loading…
Cancel
Save