From 1e977213d10a933d12400a2cb575c20bbac19468 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Fri, 12 Jun 2020 21:28:35 +0200 Subject: [PATCH] Check media status in setMediaStatus. --- static/sfu.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/static/sfu.js b/static/sfu.js index 3b93949..50b10f8 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -527,7 +527,7 @@ function setMedia(id) { media.srcObject = c.stream; setLabel(id); - setMediaStatus(id, false); + setMediaStatus(id); resizePeers(); } @@ -543,7 +543,11 @@ function delMedia(id) { resizePeers(); } -function setMediaStatus(id, good) { +function setMediaStatus(id) { + let c = up[id] || down[id]; + let state = c && c.pc && c.pc.iceConnectionState; + let good = state === 'connected' || state === 'completed'; + let media = document.getElementById('media-' + id); if(!media) { console.warn('Setting status of unknown media.'); @@ -737,9 +741,7 @@ async function gotOffer(id, labels, offer) { }; pc.oniceconnectionstatechange = e => { - setMediaStatus(id, - pc.iceConnectionState === 'connected' || - pc.iceConnectionState === 'completed'); + setMediaStatus(id); } c.pc.ontrack = function(e) { @@ -1195,9 +1197,7 @@ async function newUpStream(id) { }; pc.oniceconnectionstatechange = e => { - setMediaStatus(id, - pc.iceConnectionState === 'connected' || - pc.iceConnectionState === 'completed'); + setMediaStatus(id); if(pc.iceConnectionState === 'failed') { try { pc.restartIce();