2022-07-12 21:24:44 +08:00
|
|
|
const stopTrack = (track) => {
|
2022-07-15 22:25:37 +08:00
|
|
|
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);
|
|
|
|
}
|
2022-07-12 21:24:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const stopStream = (stream) => {
|
|
|
|
stream.getTracks().forEach(stopTrack);
|
|
|
|
};
|
|
|
|
|
|
|
|
const silentConsole = {
|
|
|
|
log: () => {},
|
|
|
|
info: () => {},
|
|
|
|
error: () => {},
|
|
|
|
warn: () => {},
|
|
|
|
debug: () => {},
|
|
|
|
trace: () => {},
|
|
|
|
assert: () => {},
|
|
|
|
};
|
|
|
|
|
|
|
|
export {
|
|
|
|
stopStream,
|
|
|
|
stopTrack,
|
|
|
|
silentConsole,
|
|
|
|
};
|