Commit 6054ae6c authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Update client code for renegotiation.

We now need to deal with the case where a track disappears from the
labels array.
parent 263258a0
......@@ -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
*/
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment