Skip to content

Instantly share code, notes, and snippets.

@markandrus
Last active July 24, 2017 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markandrus/7761495b9af1a319e3ddba1f44fe0e7e to your computer and use it in GitHub Desktop.
Save markandrus/7761495b9af1a319e3ddba1f44fe0e7e to your computer and use it in GitHub Desktop.
const pc = new RTCPeerConnection()
// 1. addTrack(audioTrack1)
const sender1 = pc.addTrack(audioTrack1)
// 2. negotiate
const offer1 = await pc.createOffer()
await pc.setLocalDescription(offer1)
await pc.setRemoteDescription(answer1)
// 3. removeTrack(sender1)
pc.removeTrack(sender1)
// 4. negotiate
const offer2 = await pc.createOffer()
await pc.setLocalDescription(offer2)
await pc.setRemoteDescription(answer2)
// 5. addTrack(audioTrack2)
//
// The following does not hold, so create a new RTCRtpTransceiver:
//
// o The sender has never been used to send. More precisely, the
// RTCRtpTransceiver associated with the sender has never had a
// currentDirection of sendrecv or sendonly.
//
const sender2 = pc.addTrack(audioTrack2)
// 6. negotiate
//
// `offer3` contains two m= sections, and `pc.getTransceivers()`
// contains two RTCRtpTransceivers.
const offer3 = await pc.createOffer()
await pc.setLocalDescription(offer3)
await pc.setRemoteDescription(answer3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment