I can get this to work on Firefox and Chrome but not Safari. On Safari it will be created but then the browser crashes when you use that for RTCPeerConnection.addTrack.
Is there a way to create a MediaStreamTrack of type video that is just a blank video?
let silence = () => {
let ctx = new AudioContext(), oscillator = ctx.createOscillator();
let dst = oscillator.connect(ctx.createMediaStreamDestination());
oscillator.start();
return Object.assign(dst.stream.getAudioTracks()[0], { enabled: false });
}
let black = ({ width = 3840, height = 2160 } = {}) => {
let canvas = Object.assign(document.createElement("canvas"), { width, height });
canvas.getContext('2d').fillRect(0, 0, width, height);
let stream = canvas.captureStream();
return Object.assign(stream.getVideoTracks()[0], { enabled: false });
}
let blackSilence = (...args) => new MediaStream([black(), silence()]);