RTCPeerConnection: iceconnectionstatechange event

An iceconnectionstatechange event is sent to an RTCPeerConnection object each time the ICE connection state changes during the negotiation process. The new ICE connection state is available in the object's iceConnectionState} property.

Bubbles No
Cancelable No
Interface Event
Event handler property oniceconnectionstatechange

One common task performed by the iceconnectionstatechange event listener: to trigger ICE restart when the state changes to failed. See ICE restart in Lifetime of a WebRTC session for further information.

Examples

An event handler for this event can be added using the RTCPeerConnection.oniceconnectionstatechange property or by using addEventListener() on the RTCPeerConnection.

In this example, a handler for iceconnectionstatechange is set up to cleanly shut down a conference call when the ICE connection enters the disconnected state.

pc.addEventListener("iceconnectionstatechange", ev => {
  if (pc.iceConnectionState === "disconnected") {
    closeVideoCall(pc);  // Our code to shut down the call
  }
}, false);

This can also be written as:

pc.oniceconnectionstatechange = ev => {
  if (pc.iceConnectionState === "disconnected") {
    closeVideoCall(pc);  // Our code to shut down the call
  }
}

Specifications

Specification Status Comment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'iceconnectionstatechange' 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
iceconnectionstatechange eventChrome Full support 28Edge Full support 15Firefox Full support 22IE ? Opera Full support 43Safari Full support 11WebView Android Full support YesChrome Android Full support 28Edge 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