1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-12-22 23:35:46 +01:00

Update client code for renegotiation.

We now need to deal with the case where a track disappears from the
labels array.
This commit is contained in:
Juliusz Chroboczek 2021-02-03 19:46:44 +01:00
parent 263258a0c1
commit 6054ae6cc6
2 changed files with 35 additions and 0 deletions

View file

@ -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
*/

View file

@ -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;