shinyoshiaki / werift-webrtc

WebRTC Implementation for TypeScript (Node.js), includes ICE/DTLS/SCTP/RTP/SRTP/WEBM/MP4
MIT License
469 stars 30 forks source link

Question regarding candidate selection #338

Closed koush closed 1 year ago

koush commented 1 year ago

How is ice candidate pair selection currently done? Is it first successful connection? It seems that sometimes my TURN candidates are being used even when a local pair exists. And in some cases (T-Mobile 6to4 detected) I’d like to force usage of a specific TURN server over the STUN pair.

I’m considering implementing a flexible mechanism to make network specific decisions but would like to understand the current rationale first.

shinyoshiaki commented 1 year ago

How is ice candidate pair selection currently done? Is it first successful connection?

Yes it is, the ICE module is based on the aioice code and is influenced by the specification of the reference implementation.

The ICE specification does not define criteria for selection, so there is room for optimization https://datatracker.ietf.org/doc/html/rfc8445#section-8.1.1

The criteria for stopping the connectivity checks and for picking a pair for nomination are outside the scope of this specification. They are a matter of local optimization. The only requirement is that the agent MUST eventually pick one and only one candidate pair and generate a check for that pair with the USE-CANDIDATE attribute set.

koush commented 1 year ago

Thanks for the explanation!

Currently I am using trickle ice and slightly delaying delivery of undesirable candidates before calling addIceCandidate in werift. This seems to work well enough for my purposes. I see there is an iceFilterStunResponse option as well that can allow me to avoid the problematic Tmobile 6to4 candidates.