WebRTC iceGatheringState never "completed"

1 day ago 3
ARTICLE AD BOX

I have attached a minimal example below, of an RTCPeerConnection whose iceGatheringState is being logged via the onicegatheringstatechange event.

The iceGatheringState read-only property of the RTCPeerConnection interface returns a string that describes the overall ICE gathering state for this connection. This lets you detect, for example, when collection of ICE candidates has finished.

(...)

The possible values are:

new The peer connection was just created and hasn't done any networking yet.

gathering The ICE agent is in the process of gathering candidates for the connection.

complete The ICE agent has finished gathering candidates. If something happens that requires collecting new candidates, such as a new interface being added or the addition of a new ICE server, the state will revert to gathering to gather those candidates.

Source: https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceGatheringState

So, after some time has elapsed, I'm expecting to see all three states in the following order:

new gathering complete

However, complete never seems to happen, no matter how long I wait.

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>WebRTC test</title> </head> <body> <button onclick="gather()">Gather</button> <script> async function gather() { const connection = new RTCPeerConnection() connection.onicegatheringstatechange = function() { document.body.innerHTML += "<br>" + connection.iceGatheringState } connection.onicegatheringstatechange() const channel = connection.createDataChannel("mychannel") const offer = await connection.createOffer() await connection.setLocalDescription(offer) } </script> </body> </html>
Read Entire Article