Search code examples
javascriptwebrtc

Order of adding ice-candidates to webrtc-connection


MDN documentation for RTCPeerConnection.addIceCandidate() says that it returns a promise. So an ice-candidate will likely is being processed yet when this methods returns.
I get several ice-candidates from a remote and do not wait - whether addIceCandidate() gets resolved or not.

The question is: should I necessarily wait when the previous promise p = addIceCandidate will be rejected or resolved ? Or it doesn't matter ?


Solution

  • The order does not matter, this operation is serialized in the operations queue: https://w3c.github.io/webrtc-pc/#dom-peerconnection-addicecandidate

    Errors from addIceCandidate should be extremly rare but you should monitor them nonetheless. One example of an error is trying to add a candidate when there is not remote description.