Search code examples
webrtcstunturn

For a TURN server that supports STUN, do I need to list both STUN and TURN urls in the client?


If I have a TURN server that can also act as a STUN, should my urls in my client looks like this?

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

or like this?

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

I only want the TURN functionality used if necessary, not for every connection.

Thanks!


Solution

  • You can write it like the second option. It will try to connect with the stun server and fallback to the turn server when the stun method doesn't work.