RTCPeerConnection 如何使用 STUN/TURN 服务器数组?

How does RTCPeerConnection use the array of STUN/TURN servers?

我们正在使用所提供的 STUN/TURN 服务器列表对 Web RTC 的行为进行一些研究。我找不到任何文档,所以我正在做一些测试,但我希望有人能提供一个明确的解释。

根据文档 (https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer/urls),我们可以提供任意数量的服务器。

为了提供更多上下文,我们有一个使用 Google Stun 服务器(stun.l.google.com:19302)的 WebRTC 应用程序,但是我们正在迁移到我们自己的 STUN 服务器上。我们有一个 API returns 要使用的 STUN 服务器列表,但是根据行为我们可能会提供不同的列表。

感谢您的帮助

But how does the RTCPeerConnection choose the server to use?

RTCPeerConnection 没有选择服务器,而是选择了一对 ICE 候选者。通过联系服务器生成 ICE 候选人。

Does it try the first one and if it fails try the second one until one works?

它联系了他们所有人(这个过程叫做聚集)。您的 WebRTC 实现 可能 在建立连接后停止收集。

Should all the servers be up and running or is the connection able to skip an unreachable server?

服务器宕机也没关系。 Trickle ICE 允许在所有连接检查都不起作用时继续进行连接检查。

If the first server is able to conclude the negociation, does it still try with the remaining servers?

两个 WebRTC 代理不通过 STUN 服务器进行通信,这个问题有一些细微差别。在 WebRTC for the Curious 的 connectivity 章节中查看 ICE 如何完成这些步骤。

Does it simply change the list of candidates?

是啊!对于每个 STUN 服务器,您 可能 有另一个候选者。这取决于您的 NAT 的行为。您可能位于仅提供一个映射的 NAT 配置之后。不太可能,但仍有可能!