VideoStreamEncoder repro
by henbos
JavaScript
(async () => {
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
// It doesn't matter if it's a track from a camera or for a canvas.
const stream = await navigator.mediaDevices.getUserMedia({video:true});
const [track] = stream.getTracks();
// Ensure we have two senders with the same MediaStreamTrack.
const t1 = pc1.addTransceiver("video", {direction:"sendonly"});
const t2 = pc1.addTransceiver("video", {direction:"sendonly"});
await t1.sender.replaceTrack(track);
await t2.sender.replaceTrack(track);
// Exchange O/A and candidates for VideoStreamEncoders to get
// created and start encoding.
exchangeIceCandidates(pc1, pc2);
await pc1.setLocalDescription();
await pc2.setRemoteDescription(pc1.localDescription);
await pc2.setLocalDescription();
await pc1.setRemoteDescription(pc2.localDescription);
console.log("O/A exchange completed. Wait for crash...");
})();
function exchangeIceCandidates(pc1, pc2) {
function doExchange(localPc, remotePc) {
localPc.addEventListener("icecandidate", event => {
const { candidate } = event;
if(candidate && remotePc.signalingState !== "closed") {
remotePc.addIceCandidate(candidate);
}
});
}
doExchange(pc1, pc2);
doExchange(pc2, pc1);
}