added own_id param as statefull id for viewer

This commit is contained in:
Leonard Anton Gläser 2022-03-29 10:51:48 +02:00
parent ec4c4dcb06
commit 5c47882b19

View File

@ -59,9 +59,12 @@ sf.streamId_text = "Loading...";
sf.streamURL_text = "Loading..."; sf.streamURL_text = "Loading...";
let connectToId = new URL(window.location.href).searchParams.get("id"); 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; 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) { if (connectToId) {
sf.streamURLCont_style = "display:none"; sf.streamURLCont_style = "display:none";
sf.connectToCont_style = "display:block"; sf.connectToCont_style = "display:block";
@ -71,11 +74,23 @@ if (connectToId) {
sf.connectToCont_style = "display:none"; sf.connectToCont_style = "display:none";
} }
var peer = new Peer({ if (ownId) {
host: window.location.hostname, var peer = new Peer(ownId, {
port: window.location.port, host: window.location.hostname,
path: "/peerjs", port: window.location.port,
}); path: "/peerjs",
});
} else {
var peer = new Peer({
host: window.location.hostname,
port: window.location.port,
path: "/peerjs",
});
}
function bitrateTransform(sdp) { function bitrateTransform(sdp) {
var arr = sdp.split("\r\n"); var arr = sdp.split("\r\n");
@ -101,7 +116,8 @@ let currentStream = undefined;
peer.on("open", (id) => { peer.on("open", (id) => {
console.log("ID", id); console.log("ID", id);
sf.streamId_text = 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); url.searchParams.set("id", id);
sf.streamURL_text = url.href; sf.streamURL_text = url.href;
sf.streamURL_href = url.href; sf.streamURL_href = url.href;
@ -117,7 +133,7 @@ peer.on("open", (id) => {
video: true, video: true,
}) })
.then((stream) => { .then((stream) => {
if(currentStream) { if (currentStream) {
currentStream.getTracks().forEach(track => track.stop()) currentStream.getTracks().forEach(track => track.stop())
} }
currentStream = stream; currentStream = stream;