From 5c47882b194bdd6c65a942a980d6f032edf450dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20Anton=20Gl=C3=A4ser?= Date: Tue, 29 Mar 2022 10:51:48 +0200 Subject: [PATCH] added own_id param as statefull id for viewer --- public/main.mjs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/public/main.mjs b/public/main.mjs index 6fbaf3c..f53b347 100644 --- a/public/main.mjs +++ b/public/main.mjs @@ -59,9 +59,12 @@ sf.streamId_text = "Loading..."; sf.streamURL_text = "Loading..."; let connectToId = new URL(window.location.href).searchParams.get("id"); +let ownId = new URL(window.location.href).searchParams.get("own_id") let bitrate = new URL(window.location.href).searchParams.get("br") || 50000; +//Connect to ID means: Iam the screensharer now. +//no ID Specified = Iam the Viewer if (connectToId) { sf.streamURLCont_style = "display:none"; sf.connectToCont_style = "display:block"; @@ -71,11 +74,23 @@ if (connectToId) { sf.connectToCont_style = "display:none"; } -var peer = new Peer({ - host: window.location.hostname, - port: window.location.port, - path: "/peerjs", -}); +if (ownId) { + var peer = new Peer(ownId, { + host: window.location.hostname, + port: window.location.port, + path: "/peerjs", + }); + + +} else { + var peer = new Peer({ + host: window.location.hostname, + port: window.location.port, + path: "/peerjs", + }); +} + + function bitrateTransform(sdp) { var arr = sdp.split("\r\n"); @@ -101,7 +116,8 @@ let currentStream = undefined; peer.on("open", (id) => { console.log("ID", id); sf.streamId_text = id; - let url = new URL(window.location.href); + //clearing the params from the url + let url = new URL(window.location.href.split('?')[0]); url.searchParams.set("id", id); sf.streamURL_text = url.href; sf.streamURL_href = url.href; @@ -117,7 +133,7 @@ peer.on("open", (id) => { video: true, }) .then((stream) => { - if(currentStream) { + if (currentStream) { currentStream.getTracks().forEach(track => track.stop()) } currentStream = stream;