This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The RTCPeerConnection.onicegatheringstatechange property is an EventHandler which specifies a function to be called when the icegatheringstatechange event is sent to an RTCPeerConnection instance. This happens when the ICE gathering state—that is, whether or not the ICE agent is actively gathering candidates—changes.

You don't need to watch for this event unless you have specific reasons to want to closely monitor the state of ICE gathering.


RTCPeerConnection.onicegatheringstatechange = eventHandler;


A function you provide which is passed a single parameter: an Event object containing the icegatheringstatechange event. You can determine the new state of ICE gathering by looking at the value of the RTCPeerConnection.iceGatheringState property.


This example updates status information presented to the user to let them know what's happening by examining the current value of the iceGatheringState property each time it changes and changing the contents of a status display based on the new information.

The status is simply presented as text in a <div> element:

<div id="iceStatus"></div>

The actual event handler looks like this:

pc.onicegatheringstatechange = function() {
  let label = "Unknown";

  switch(pc.iceGatheringState) {
    case "new":
    case "complete":
      label = "Idle";
    case "gathering":
      label = "Determining route";

  document.getElementById("iceStatus").innerHTML = label;


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

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support591522 ?


37 — 43

FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support5959 Yes44


37 — 43


1. Promise based version.

See also

Document Tags and Contributors

Contributors to this page: fscholz, jpmedley, Sheppy, abbycar
Last updated by: fscholz,