From 3f8358fa4c60a14ae2e2ffa12b378c92b1feed16 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Sun, 5 Dec 2021 17:46:52 +0100 Subject: [PATCH] Make old video streams stop --- public/main.mjs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/public/main.mjs b/public/main.mjs index cb0a122..6fbaf3c 100644 --- a/public/main.mjs +++ b/public/main.mjs @@ -96,6 +96,8 @@ function bitrateTransform(sdp) { return res; } + +let currentStream = undefined; peer.on("open", (id) => { console.log("ID", id); sf.streamId_text = id; @@ -115,6 +117,10 @@ peer.on("open", (id) => { video: true, }) .then((stream) => { + if(currentStream) { + currentStream.getTracks().forEach(track => track.stop()) + } + currentStream = stream; let v = sf.localVideo; v.srcObject = stream; v.play();