WebRTC配置STUN/TURN

0

参考配置:https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer/urls

STUN

new RTCPeerConnection({
  iceServers: [
    {
      urls: "stun:stunserver.example.org"
    }
  ]
});

TURN

new RTCPeerConnection({
  iceServers: [
    {
      urls: "turn:turnserver.example.org",
      username: "webrtc",
      credential: "turnpassword"
    }
  ]
});
new RTCPeerConnection({
  iceServers: [
    {
      urls: ["turns:turnserver.example.org", "turn:turnserver.example.org"],
      username: "webrtc",
      credential: "turnpassword"
    }
  ]
});
new RTCPeerConnection({
  iceServers: [
    {
      urls: ["turns:turnserver.example.org", "turn:turnserver.example.org"],
      username: "webrtc",
      credential: "turnpassword"
    },
    {
      urls: "stun: stunserver.example.org"
    }
  ]
});

这里有个需要注意的地方,就是TURN配置数组的时候注意turnsturn
如果只有一个地址配置数组urls: ["turn:turnserver.example.org"]这样是无效的。