Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

RTCPeerConnection.onicecandidate

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The RTCPeerConnection.onicecandidate property is an EventHandler which specifies a function to be called when the icecandidate event occurs on an RTCPeerConnection instance. This happens whenever the local ICE agent needs to deliver a message to the other peer through the signaling server. This lets the ICE agent perform negotiation with the remote peer without the browser itself needing to know any specifics about the technology being used for signaling; simply implement this method to use whatever messaging technology you choose to send the ICE candidate to the remote peer.

Syntax

RTCPeerConnection.onicecandidate = eventHandler;

Value

This should be set to a function which you provide that accepts as input an RTCPeerConnectionIceEvent object representing the icecandidate event. The function should deliver the ICE candidate, whose SDP can be found in the event's candidate property, to the remote peer through the signaling server.

If the event's candidate property is null, ICE gathering has finished.

Example

The example below, which is based on the code from the article Signaling and video calling, sets up a handler for icecandidate events to send the candidates to the remote peer.

pc.onicecandidate = function(event) {
  if (event.candidate) {
    // Send the candidate to the remote peer
  } else {
    // All ICE candidates have been sent
  }
}

Specifications

Specification Status Comment
WebRTC 1.0: Real-time Communication Between Browser
The definition of 'RTCPeerConnection.onicecandidate' in that specification.
Working Draft Initial specification.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) 18 (18) [1] No support (Yes) ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? 18.0 (18) No support ? ?

[1] Though this property is not prefixed, the RTCPeerConnection interface it's a member of was until Firefox 44.

See also

Document Tags and Contributors

 Contributors to this page: Sheppy, nils, teoli, rmnguleria
 Last updated by: Sheppy,