TURN server fallback

STUN works for most home networks. Symmetric NATs and tight corporate firewalls drop direct peer connections, and the call freezes after the SDP exchange. A TURN server fixes this by relaying media through a public host the browser can always reach.

When STUN fails, TURN relays

A symmetric NAT means the public address discovered for one peer does not work for the other. TURN sits in the middle and forwards media.

static/client.js
javascript
const pc = new RTCPeerConnection({
  iceServers: [
    { urls: 'stun:stun.l.google.com:19302' },
    {
      urls: ['turn:turn.example.com:3478?transport=udp', 'turn:turn.example.com:3478?transport=tcp'],
      username: process.env.TURN_USERNAME,
      credential: process.env.TURN_PASSWORD,
    },
  ],
  iceTransportPolicy: 'all', // try direct first, fall back to relay
});

List STUN first and TURN as fallback. iceTransportPolicy left at the default lets the browser try direct paths before paying the relay cost.

Quiz: Quiz

Loading practice…