You demo the call from the office and it's perfect: video on both sides, no complaints. That evening a colleague joins from a phone on 4G, the call sits on "Connecting..." for half a minute and then iceConnectionState turns failed. The next week a customer in a hotel gets the same thing, and nobody changed the code.
The code isn't the problem. The problem is the path, and the browser already wrote down which paths it tried. Every candidate it gathered and every connectivity check it sent is in getStats() and in chrome://webrtc-internals. Most of the time the cause is one of four things, and you can read them straight out of that data.
To make that faster I wrote webrtc-ice-candidate-doctor, a small TypeScript CLI. Give it an SDP, a getStats() snapshot or a webrtc-internals dump, and it tells you which path is missing.
Three kinds of address, and why the office hides the problem
ICE (RFC 8445) collects candidate addresses and tests them in pairs:
- host: the device's own address, like
192.168.1.23. Chrome and Firefox often replace it with a random<uuid>.localmDNS name, so the page doesn't learn your LAN IP. - srflx (server-reflexive): the address a STUN server saw your packet come from, outside your NAT.
- relay: an address on a TURN server (RFC 8656) that forwards media for you.
For each pair, both sides send STUN binding requests and wait for responses. The first pair that gets answers in both directions carries the call. On most office networks, host or srflx works, so you never find out whether your relay works at all. That's the trap: a missing TURN setup only shows up on networks where it's the only option.
Failure 1: 4G and CGNAT, where srflx is a dead end
On mobile data, the device often has an address in 100.64.0.0/10. That's RFC 6598 shared address space, used for carrier-grade NAT. Your srflx candidate is then an address on the carrier's NAT, shared with other subscribers.
That's only a problem if the NAT uses what RFC 4787 calls endpoint-dependent mapping (usually called "symmetric NAT"). The NAT then picks a new external port for each destination. The port the STUN server saw isn't the one a packet to your peer would use, so the peer's checks to your srflx address go nowhere. A direct path can still turn up as a peer-reflexive candidate if the other side's NAT is friendlier. If it isn't, only a relay will work.
You can see this in the candidate-pair stats: requestsSent keeps going up and responsesReceived stays at 0. That's the check the tool runs:
const unanswered = snap.pairs.filter((p) => { const l = byId.get(p.localId), r = byId.get(p.remoteId); return p.requestsSent > 0 && p.responsesReceived === 0 && (l?.type === 'srflx' || r?.type === 'srflx' || l?.type === 'prflx' || r?.type === 'prflx'); }); Here it is on a synthetic 4G sample: a CGNAT host address, a STUN-only configuration, 18 checks to the peer's srflx address and no answers:
The fix isn't another STUN server. It's TURN.
Failure 2: TURN exists, but only over UDP
Hotel and corporate networks often block outbound UDP and allow TCP to ports like 80 and 443. If your configuration says only turn:turn.example.com:3478, that's UDP. RFC 7065 makes UDP the default for turn:, and port 3478 for both turn: and stun:. On a network that drops UDP, the browser can't reach the TURN server at all.
The browser does tell you. RTCPeerConnection fires an icecandidateerror event, and the W3C spec says that when no host candidate can reach the server, errorCode is 701, a value outside the STUN error range. The tool reads the URLs with the RFC 7065 defaults:
const secure = scheme.endsWith('s'); return { raw, scheme, host: m[2], port: m[3] ? Number(m[3]) : secure ? 5349 : 3478, transport: secure ? 'tls' : t === 'tcp' ? 'tcp' : 'udp', }; The hotel sample (a webrtc-internals-style dump) gives this:
local host 1, mdns 0, srflx 0, prflx 0, relay 0 TURN URLs turn:turn.example.com:3478/udp ERROR HOST_ONLY the local side has only host candidates: no STUN or TURN server answered (or none is configured). ... WARN TURN_URLS_UDP_ONLY TURN URLs are UDP only (turn:turn.example.com:3478?transport=udp): add turn:...?transport=tcp and turns:...:443 ... ERROR TURN_UNREACHABLE turn:turn.example.com:3478?transport=udp: errorCode 701 x1, server not reachable: no host candidate got a response from it ... Diagnosis: -> UDP to the TURN server never got an answer and there is no TCP/TLS TURN URL. On networks that only let TCP/443 out, add turns:turn.example.com:443?transport=tcp (coturn tls-listening-port=443 with cert/pkey). Add turn:...?transport=tcp and turns:...:443?transport=tcp (TLS over TCP). Only the leg from the browser to the TURN server changes. The relay still talks UDP to the peer. In getStats(), a local relay candidate's relayProtocol (udp, tcp or tls) shows which leg you got. SDP doesn't carry it, so for SDP input the tool only notes that it can't tell.
Relaying over TCP works, but it costs something: one lost packet holds up the ones behind it until it's resent. It's a fallback, not the default path.
Failure 3: the relay candidate is missing because the credentials expired
You configured TURN on every transport and there's still no relay candidate. Look for 401 in the icecandidateerror events.
A common setup is coturn's use-auth-secret (the "TURN REST API"). Your backend issues time-limited credentials: the username is <expiry unix timestamp>:<user> and the password is base64(HMAC-SHA1(secret, username)). Credentials cached in the page, handed out with a short TTL, or minted on a server with a wrong clock fail with 401 once that timestamp passes. The tool reads the expiry right out of the username and compares it with the capture time:
export function restCredentialExpiry(username: string | undefined, separator = ':'): Date | undefined { if (!username) return undefined; const first = username.split(separator)[0]; if (!/^\d{9,11}$/.test(first)) return undefined; return new Date(Number(first) * 1000); } ERROR TURN_CREDENTIAL_EXPIRED TURN REST username "1796542200:agent-7" expired at 2026-12-06T07:30:00.000Z, 2550 s before this capture ... ERROR TURN_AUTH_FAILED turns:turn.example.com:443?transport=tcp: errorCode 401 x1, Unauthorized ... Mint credentials per session, right before you create the RTCPeerConnection. Choose a TTL that covers the longest call plus any ICE restarts.
Failure 4: only .local names on offer
If an offer or answer carries only <uuid>.local host candidates and no srflx or relay, the peer has to resolve those names with multicast DNS on the same LAN. Two tabs on one laptop connect. A media server or SIP gateway in the cloud usually can't resolve .local at all. The tool flags this as MDNS_ONLY (or REMOTE_MDNS_ONLY). The fix is the same: give that side STUN and TURN.
The fix, in two configs
Client:
new RTCPeerConnection({ iceServers: [{ urls: [ 'turn:turn.example.com:3478?transport=udp', 'turn:turn.example.com:3478?transport=tcp', 'turns:turn.example.com:443?transport=tcp', ], username, credential, // short-lived, from your backend }], }); coturn:
listening-port=3478 tls-listening-port=443 # default is 5349 cert=/etc/coturn/fullchain.pem pkey=/etc/coturn/privkey.pem external-ip=198.51.100.20/10.0.0.5 # public/private if coturn sits behind NAT realm=turn.example.com use-auth-secret static-auth-secret=<from your secret store> Open the relay port range (min-port to max-port, UDP) in the firewall too. Then test TURN on its own: set iceTransportPolicy: 'relay' in a test build. The browser gathers only relay candidates, so if the call connects, TURN works. If no relay candidate shows up, the icecandidateerror codes tell you why.
What it can't see
It reads what the browser recorded. It can't see the firewall or the NAT. "0 responses" tells you the checks weren't answered, not why. The five sample files are synthetic, with RFC 1918, RFC 6598 and RFC 5737 addresses. There are 17 node:test tests, and the CLI exits with code 2 on any error, so you can run it on saved dumps in CI.
The takeaway
When a call works on Wi-Fi and fails everywhere else, don't start with the code. Open the candidate-pair stats and ask three questions. Is there a relay candidate? Can it reach TURN over TCP/TLS on 443, not just UDP? Do the srflx pairs ever get a response? The browser already recorded the answers.
Code: github.com/AhmedElbashier/webrtc-ice-candidate-doctor has the CLI, five synthetic samples, 17 tests and the raw output. Run npm test, then node src/cli.ts samples/*.
If you want a browser phone to try this on, my webrtc-sip-softphone comes with a one-command Kamailio + FreeSWITCH lab.
I'm Ahmed, a full-stack and integrations engineer (.NET, Next.js, VoIP/WebRTC/SIP). More of my work is on GitHub and my portfolio.


