Skip to content

Instantly share code, notes, and snippets.

@markandrus
Last active July 24, 2017 21:40
Show Gist options
  • Save markandrus/c970eeaf37c5b26cc8c7d7b4973cdc2a to your computer and use it in GitHub Desktop.
Save markandrus/c970eeaf37c5b26cc8c7d7b4973cdc2a to your computer and use it in GitHub Desktop.
const pc = new RTCPeerConnection()
// 1. addTransceiver('audio')
const transceiver1 = pc.addTransceiver('audio')
// 2. negotiate
const offer1 = await pc.createOffer()
await pc.setLocalDescription(offer1)
await pc.setRemoteDescription(answer1)
// 3. stop()
transceiver1.stop()
// 4. negotiate
//
// o If an RtpTransceiver has been stopped and is associated with an m=
// section, and the m= section is not being recycled as described
// above, an m= section MUST be generated for it with the port set to
// zero and all "a=msid" lines removed.
//
const offer2 = await pc.createOffer()
await pc.setLocalDescription(offer2)
await pc.setRemoteDescription(answer2)
// 5. addTransceiver('audio')
const transceiver2 = pc.addTransceiver('audio')
// 6. negotiate
//
// o If any RtpTransceiver has been added, and there exists an m=
// section with a zero port in the current local description or the
// current remote description, that m= section MUST be recycled by
// generating an m= section for the added RtpTransceiver as if the m=
// section were being added to the session description (including a
// new MID value), and placing it at the same index as the m= section
// with a zero port.
//
// `offer3` contains one m= section, and `pc.getTransceivers()` returns 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