Configure ICE candidate filtering and TURN-only mode for enterprise firewall traversal in WebRTC

domain: developer.mozilla.org · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. When constructing RTCPeerConnection, pass a configuration object with iceTransportPolicy: 'relay' to force all media through TURN relays and prevent host and server-reflexive candidates from being gathered — this ensures traffic exits through a known TURN server that is permitted by the enterprise firewall.
  2. Supply your TURN server(s) in the iceServers array of the RTCPeerConnection configuration with urls: ['turn:turn.example.com:443?transport=tcp'] to use TCP on port 443, which most enterprise firewalls permit for HTTPS traffic.
  3. On the TURN server, enable the TURN-over-TLS (turns:) variant so the TURN handshake and relay traffic are wrapped in TLS on port 443, further bypassing deep-packet inspection that blocks plain TURN.
  4. Add a STUN server to the iceServers array for scenarios where direct connectivity is allowed; the STUN server helps gather server-reflexive candidates that work when only NAT (not firewall) traversal is needed.
  5. Monitor RTCPeerConnection.getStats() and filter for candidate-pair entries to confirm that the selected candidate pair type is 'relay'; if a non-relay pair is selected despite iceTransportPolicy: 'relay', the TURN configuration is likely misconfigured.
  6. Handle TURN credential expiry gracefully: if the ICE process begins after TURN credentials have expired, candidates will fail to gather; refresh credentials and restart ICE via RTCPeerConnection.restartIce() before expiry.

Known gotchas

Related routes

Configure a self-hosted coturn TURN server for WebRTC NAT traversal
webrtc.org · 6 steps · unrated
Enable WebRTC simulcast with VP8 spatial layers in a browser sender using RTCRtpSendParameters
developer.mozilla.org · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans