diff --git a/static/galene.js b/static/galene.js index f504bf0..a95bcc7 100644 --- a/static/galene.js +++ b/static/galene.js @@ -349,6 +349,15 @@ function gotDownStream(c) { c.ondowntrack = function(track, transceiver, label, stream) { setMedia(c, false); }; + c.onnegotiationcompleted = function() { + let found = false; + for(let key in c.labels) { + if(c.labels[key] === 'video') + found = true; + } + if(!found) + resetMedia(c); + } c.onstatus = function(status) { setMediaStatus(c); }; @@ -1372,6 +1381,22 @@ async function setMedia(c, isUp, mirror, video) { } } +/** + * resetMedia resets the source stream of the media element associated + * with c. This has the side-effect of resetting any frozen frames. + * + * @param {Stream} c + */ +function resetMedia(c) { + let media = /** @type {HTMLVideoElement} */ + (document.getElementById('media-' + c.localId)); + if(!media) { + console.error("Resetting unknown media element") + return; + } + media.srcObject = media.srcObject; +} + /** * @param {Element} elt */ diff --git a/static/protocol.js b/static/protocol.js index 49d806a..48d7bcf 100644 --- a/static/protocol.js +++ b/static/protocol.js @@ -622,6 +622,16 @@ ServerConnection.prototype.gotOffer = async function(id, labels, source, usernam } c.labelsByMid = labels; + c.labels = {}; + c.pc.getTransceivers().forEach(transceiver => { + let label = c.labelsByMid[transceiver.mid]; + let track = transceiver.receiver && transceiver.receiver.track; + if(label && track) { + c.labels[track.id] = label; + } else if(!track) { + console.warn("Couldn't find track for label"); + } + }); c.source = source; c.username = username;