RTCPeerConnection: icecandidate event

An icecandidate event is sent to an RTCPeerConnection  when an RTCIceCandidate has been added to the target as a result of calling RTCPeerConnection.setLocalDescription(). This event handler should transmit the candidate to the remote peer so that the remote peer can add it its set of remote candidates.

Bubbles No
Cancelable No
Interface RTCPeerConnectionIceEvent
Event handler property RTCPeerConnection.onicecandidate

Examples

This example creates a simple handler for the icecandidate event that uses a function called sendMessage() to create and send a reply to the remote peer through the signaling server.

First, an example using addEventListener():

pc.addEventListener("icecandidate", ev => {
  if (ev.candidate) {
    sendMessage({
      type: "new-ice-candidate",
      candidate: event.candidate
    });
  }
}, false);

You can also set the onicecandidate event handler property directly:

pc.onicecandidate = ev => {
  if (ev.candidate) {
    sendMessage({
      type: "new-ice-candidate",
      candidate: event.candidate
    });
  }
};

Specifications

Specification Status Comment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'icecandidate' in that specification.
Candidate Recommendation  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
icecandidate eventChrome Full support 24Edge Full support 15Firefox Full support 22IE ? Opera Full support 43Safari Full support 11WebView Android Full support YesChrome Android Full support 25Edge Mobile Full support YesFirefox Android Full support 44Opera Android Full support 43Safari iOS ? Samsung Internet Android Full support 6.0

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

See also

Document Tags and Contributors

Contributors to this page: mdnwebdocs-bot, Sheppy, fscholz, betimer, prestomation, erikadoyle, teoli
Last updated by: mdnwebdocs-bot,