files/en-us/web/api/rtcicetransport/gatheringstatechange_event/index.md
{{APIRef("WebRTC")}}
A gatheringstatechange event is sent to an {{domxref("RTCIceTransport")}} when its {{Glossary("ICE")}} candidate gathering state changes.
The gathering state, whose actual status can be found in the transport object's {{domxref("RTCIceTransport.gatheringState", "gatheringState")}} property, indicates whether or not the ICE agent has begun gathering candidates on this transport, and if so, if it has finished doing so.
This event is not cancelable and does not bubble.
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("gatheringstatechange", (event) => { })
ongatheringstatechange = (event) => { }
A generic {{domxref("Event")}}.
This example creates a handler for gatheringstatechange events on each {{domxref("RTCRtpSender")}} associated with a given {{domxref("RTCPeerConnection")}}. Here, the {{domxref("EventTarget.addEventListener", "addEventListener()")}} method is called to add a listener for gatheringstatechange events:
pc.getSenders().forEach((sender) => {
sender.transport.iceTransport.addEventListener(
"gatheringstatechange",
(ev) => {
let transport = ev.target;
if (transport.gatheringState === "complete") {
/* this transport has finished gathering candidates,
but others may still be working on it */
}
},
);
});
Likewise, you can use the ongatheringstatechange event handler property:
pc.getSenders().forEach((sender) => {
sender.transport.iceTransport.ongatheringstatechange = (ev) => {
let transport = ev.target;
if (transport.gatheringState === "complete") {
/* this transport has finished gathering candidates,
but others may still be working on it */
}
};
});
{{Specifications}}
{{Compat}}