Establish and manage WebRTC peer connections

JavaScript

const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate);
pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate);
async function run() {
  const t = pc1.addTransceiver('audio');
  t.direction = 'sendonly';
  await pc1.setLocalDescription();
  await pc2.setRemoteDescription(pc1.localDescription);
  pc2.getTransceivers()[0].direction = 'recvonly';
  await pc2.setLocalDescription();
  await pc1.setRemoteDescription({type: 'answer', sdp: pc2.localDescription.sdp.replace('recvonly', 'sendrecv')});
  console.log(t.direction, t.currentDirection);
}
run();