Using TURN servers for WebRTC calls

TURN servers are needed to connect users behind firewalls to WebRTC calls. Without them, the users behind firewall won’t be able to connect to WebRTC calls with their audio and video streams. There are no such publicly available TURN servers as TURN servers use up a lot of bandwidth to relay audio/video streams which makes them very very costly. Either you can host your own TURN servers and pay the bills by yourself for usage or take up commercially available TURN server.

  • COTURN is an open source TURN server which one can host yourself and use. Be careful to configure it properly so that it covers maximum scenarios for NAT traversal.

  • Twillio TURN is a commercially available STUN / TURN server which one can use in a pay per use model.

A sample turn credential looks like this.

const iceServers = [
  {urls: "stun:turn.yourdomain.com:3478"},
  {
    urls: "turn:turn.yourdomain.com:3478",
    username: "username",
    credential: "password",
  },
  {
    urls: "turn:turn.yourdomain.com:443",
    username: "username",
    credential: "password",
  },
  {
    urls: "turn:turn.yourdomain.com:443?transport=tcp",
    username: "username",
    credential: "password",
  }
  ];

The above mentioned iceServers parameters one can pass to the RTCPeerConnection object while instantiating it use the TURN server credentials while joining a call in case the user is blocked by a firewall.
Feel free to ask any questions or doubt here.