fix(webcams): handle Firefox video stream cleanup edge case
Firefox doesnt fire the ended evt/onended callback for live video mediastreamtracks. That caused the stream storage to not run the cleanup procedure in some scenarios Manually emit the ended event which works with the onended callback when a track is stopped
This commit is contained in:
parent
60dd10510c
commit
d8dae1ec90
@ -52,6 +52,9 @@ const storeStream = (deviceId, stream) => {
|
||||
const track = MediaStreamUtils.getVideoTracks(stream)[0];
|
||||
if (track) {
|
||||
track.addEventListener('ended', cleanup, { once: true });
|
||||
// Extra safeguard: Firefox doesn't fire the 'ended' when it should
|
||||
// but it invokes the callback (?), so hook up to both
|
||||
track.onended = cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,12 @@
|
||||
const stopMediaStreamTracks = (stream) => {
|
||||
if (stream && typeof stream.getTracks === 'function') {
|
||||
stream.getTracks().forEach(track => {
|
||||
if (typeof track.stop === 'function') {
|
||||
if (typeof track.stop === 'function' && track.readyState !== 'ended') {
|
||||
track.stop();
|
||||
// Manually emit the event as a safeguard; Firefox doesn't fire it when it
|
||||
// should with live MediaStreamTracks...
|
||||
const trackStoppedEvt = new MediaStreamTrackEvent('ended', { track });
|
||||
track.dispatchEvent(trackStoppedEvt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -38,7 +38,13 @@ function noop(error) {
|
||||
logger.error(error);
|
||||
}
|
||||
function trackStop(track) {
|
||||
track && track.stop && track.stop();
|
||||
if (track && typeof track.stop === 'function' && track.readyState !== 'ended') {
|
||||
track.stop();
|
||||
// Manually emit the event as a safeguard; Firefox doesn't fire it when it
|
||||
// should with live MediaStreamTracks...
|
||||
const trackStoppedEvt = new MediaStreamTrackEvent('ended', { track });
|
||||
track.dispatchEvent(trackStoppedEvt);
|
||||
}
|
||||
}
|
||||
function streamStop(stream) {
|
||||
let track = stream.track;
|
||||
|
Loading…
Reference in New Issue
Block a user