The RTCPeerConnection.onicegatheringstatechange
property is an event handler 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 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"; break; case "gathering": label = "Determining route"; break; } document.getElementById("iceStatus").innerHTML = label; }
Specification |
---|
WebRTC 1.0: Real-Time Communication Between Browsers (WebRTC 1.0) # dom-rtcpeerconnection-onicegatheringstatechange |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
onicegatheringstatechange |
59 |
15 |
22 |
No |
46 |
11 |
59 |
59 |
44 |
43 |
11 |
7.0 |
icegatheringstatechange
event and its type, Event
.RTCPeerConnection.iceGatheringState
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/onicegatheringstatechange