WebRTC answerer client ICE gathering event not triggered

I have a working answerer-only WebRTC client to view video from a remote device. This client, works in all common web browsers (Chrome, Edge, Firefox, etc.) except in Safari.

After trying to debug the problem, I noticed that after calling await peerConnection.setLocalDescription(answer); RTCPeerConnection.iceGatheringState never changes to the "gathering" state and stays the default initial "new" state. This is a problem because the ICE candidates can never be gathered and thus the client in Safari does not work at all.

What is surprising and weird is that by explicitly calling setLocalDescription(), ICE gathering should start as mentioned in the documentation: https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/icecandidate_event. However, in Safari, this never happens.

I experienced this issue in both Safari 18.x and 21.x versions.

Yeah, this seems to be a known Safari WebRTC bug — ICE gathering sometimes doesn’t start automatically after setLocalDescription(). A common workaround is to trigger it manually by adding a dummy data channel or calling createDataChannel() before setting the description. Also make sure you’re using a secure (HTTPS) context, as Safari blocks ICE on insecure origins.

WebRTC answerer client ICE gathering event not triggered
 
 
Q