From 6e548deded288002bc976ef9db65fa9f99a70869 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Tue, 24 Nov 2020 23:22:24 +0100 Subject: [PATCH] Handle removetrack event on streamed videos. Probably useless, but I'm supersticious. --- static/sfu.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/static/sfu.js b/static/sfu.js index 0a5915c..4be42d8 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -902,13 +902,25 @@ async function addFileMedia(file) { stream.onaddtrack = function(e) { let t = e.track; c.pc.addTrack(t, stream); - t.onended = e => { - delUpMedia(c); - } c.labels[t.id] = t.kind; c.onstats = gotUpStats; c.setStatsInterval(2000); }; + stream.onremovetrack = function(e) { + let t = e.track; + delete(c.labels[t.id]); + + /** @type {RTCRtpSender} */ + let sender; + c.pc.getSenders().forEach(s => { + if(s.track === t) + sender = s; + }); + if(sender) { + c.pc.removeTrack(sender) + } else + console.warn('Removing unknown track'); + }; setMedia(c, true, video); video.play(); setButtonsVisibility()