diff --git a/stream/webrtc/webrtc.go b/stream/webrtc/webrtc.go index 4697560..6945d79 100644 --- a/stream/webrtc/webrtc.go +++ b/stream/webrtc/webrtc.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "math/rand" + "strings" "github.com/pion/webrtc/v3" "gitlab.crans.org/nounous/ghostream/internal/monitoring" @@ -120,6 +121,14 @@ func newPeerHandler(remoteSdp struct { } streamID := remoteSdp.StreamID + split := strings.SplitN(streamID, "@", 2) + streamID = split[0] + quality := "source" + if len(split) == 2 { + quality = split[1] + } + log.Printf("New WebRTC session for stream %s, quality %s", streamID, quality) + // TODO Consider the quality // Set the handler for ICE connection state // This will notify you when the peer has connected/disconnected diff --git a/web/static/js/videoQuality.js b/web/static/js/videoQuality.js new file mode 100644 index 0000000..af4060f --- /dev/null +++ b/web/static/js/videoQuality.js @@ -0,0 +1,8 @@ +document.getElementsByName("quality").forEach(function (elem) { + elem.onclick = function () { + // Restart the connection with a new quality + peerConnection.createOffer({"iceRestart": true}).then(offer => { + return peerConnection.setLocalDescription(offer) + }).catch(console.log) + } +}) diff --git a/web/static/js/viewer.js b/web/static/js/viewer.js index d83e910..b9b7f20 100644 --- a/web/static/js/viewer.js +++ b/web/static/js/viewer.js @@ -52,7 +52,7 @@ startPeerConnection = () => { // The server replies with its description // After setRemoteDescription, the browser will fire ontrack events console.log("Sending session description to server") - fetch(window.location.href, { + fetch(window.location.href + document.quality_form.quality.value, { method: 'POST', headers: { 'Accept': 'application/json', diff --git a/web/template/viewer.html b/web/template/viewer.html index 50632dc..d2f9bb1 100644 --- a/web/template/viewer.html +++ b/web/template/viewer.html @@ -6,6 +6,19 @@ +