对于支持STUN的TURN服务器,我是否需要在客户端中同时列出STUN和TURN URL?

时间:2020-07-30 16:15:25

标签: webrtc stun turn

如果我有可以充当STUN的TURN服务器,客户端中的网址应该看起来像这样吗?

myPeerConnection = new RTCPeerConnection({
  iceServers: [
    {
      urls: "turn:example.org"
    }
  ]
});

还是这样?

myPeerConnection = new RTCPeerConnection({
  iceServers: [
    {
      urls: "stun:example.org"
    },
    {
      urls: "turn:example.org"
    }
  ]
});

我只希望在必要时使用TURN功能,而不是每个连接都使用。

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以像第二个选项一样编写它。当stun方法不起作用时,它将尝试与stun服务器连接并回退到turn服务器。