WebRTC unmute outbound-rtp

by jib1

HTML

<div id="div"></div><br>

CSS

body { white-space: pre; font-family: monospace; }

JavaScript

const console = { log: msg => div.innerHTML += msg + "<br>" };
const gUM = c => navigator.mediaDevices.getUserMedia(c);
const pc1 = new RTCPeerConnection(), pc2 = new RTCPeerConnection();

(async () => {
  pc1.addTrack((await gUM({video:true})).getTracks()[0]);
  const {track} = await new Promise(r => pc2.ontrack = r);
  await new Promise(r => track.onunmute = r);
  const stats = await pc1.getStats();
  console.log(`SSRC = ${[...stats.values()].find(({type}) => type == "outbound-rtp")?.ssrc}`);
})();

pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate);
pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate);
pc1.oniceconnectionstatechange = () => console.log(pc1.iceConnectionState);

pc1.onnegotiationneeded = async () => {
  await pc1.setLocalDescription();
  await pc2.setRemoteDescription(pc1.localDescription);
  await pc2.setLocalDescription();
  await pc1.setRemoteDescription(pc2.localDescription);
};