bigbluebutton-Github/bigbluebutton-html5/imports/ui/services/webrtc-base/utils.js
prlanzarin cd9b8ccef4 fix: handle Firefox stream cleanup edge case (peer.js)
Firefox doesn't fire the ended evt/onended callback for live
 MediaStreamTrack(s). We rely on that event.

 Manually emit the ended event which works with the onended callback
 when a track is stopped
2022-07-15 14:25:37 +00:00

30 lines
673 B
JavaScript

const stopTrack = (track) => {
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);
}
};
const stopStream = (stream) => {
stream.getTracks().forEach(stopTrack);
};
const silentConsole = {
log: () => {},
info: () => {},
error: () => {},
warn: () => {},
debug: () => {},
trace: () => {},
assert: () => {},
};
export {
stopStream,
stopTrack,
silentConsole,
};