Skip to content

Release WebRTC@v3.0.0

Woodrow Douglass edited this page Jul 29, 2020 · 13 revisions

Breaking Changes

Trickle ICE is now enabled by default

Before Pion WebRTC would gather all candidates before a CreateOffer or CreateAnswer generated a SDP. This would cause a few issues in real world applications. You can read about the benefits of Trickle ICE here

  • Longer call connection times since we blocked for STUN/TURN even if not needed
  • This didn't comply with the WebRTC spec
  • Made it harder for users to filter/process ICE Candidates

Now you should exchange ICE Candidates that are pushed via the OnICECandidate callback.

Before

  peerConnection, _ := webrtc.NewPeerConnection(webrtc.Configuration{})

  offer, _ := peerConnection.CreateOffer()
  peerConnection.SetLocalDescription(offer)

  // Send `offer` to remote peer
  websocket.Write(offer)

After

  peerConnection, _ := webrtc.NewPeerConnection(webrtc.Configuration{})

  // Set ICE Candidate handler. As soon as a PeerConnection has gathered a candidate
  // send it to the other peer
  peerConnection.OnICECandidate(func(i *webrtc.ICECandidate) {
    // Send ICE Candidate via Websocket/HTTP/$X to remote peer
  })

  // Listen for ICE Candidates from the remote peer
  peerConnection.AddICECandidate(remoteCandidate)

  // You still signal like before, but `CreateOffer` will be much faster
  offer, _ := peerConnection.CreateOffer()
  peerConnection.SetLocalDescription(offer)

  // Send `offer` to remote peer
  websocket.Write(offer)

If you are unable to migrate we have provided a helper function to simulate the pre-v3 behavior.

Helper function to simulate non-trickle ICE

  peerConnection, _ := webrtc.NewPeerConnection(webrtc.Configuration{})

  offer, _ := peerConnection.CreateOffer()

  // Create channel that is blocked until ICE Gathering is complete
  gatherComplete := webrtc.GatheringCompletePromise(peerConnection)
  peerConnection.SetLocalDescription(offer)
  <-gatherComplete

  // Send `LocalDescription` to remote peer
  // This is the offer but populated with all the ICE Candidates
  websocket.Write(*peerConnection.LocalDescription())

This was changed with bb3aa9

A data channel is no longer implicitly created with a PeerConnection

To simulate the old functionality, call CreateDataChannel after creating your PeerConnection

New Features

ICE Restarts

You can now initiate and accept an ICE Restart! This means that if a PeerConnection goes to Disconnected or Failed because of network interruption it is no longer fatal.

To use you just need to pass ICERestart: true in your OfferOptions. The answering PeerConnection will then restart also. This is supported in FireFox/Chrome and Mobile WebRTC Clients.

  peerConn, _ := NewPeerConnection(Configuration{})

  // PeerConnection goes to ICEConnectionStateFailed

  offer, _ := peerConn.CreateOffer(&OfferOptions{ICERestart: true})

This was implemented in f29414