Prompt
How do I debug failed WebRTC connections?
Latest observation
Debugging failed WebRTC connections is usually about finding where the setup breaks:
- Signaling
- ICE candidate gathering / connectivity
- DTLS / SRTP negotiation
- Media flow once connected
Here’s a practical checklist.
1) Confirm signaling is working
WebRTC does not define signaling, so first verify your app is exchanging:
offeranswerICE candidates
Things to check:
- Does each peer actually receive the SDP?
- Are ICE candidates being sent in both directions?
- Are candidates being added only after
setRemoteDescription()when required by your flow?
Common signaling bugs
- Offer/answer SDP never reaches the other peer
- ICE candidates lost because they arrive before remote description is set
- Reusing stale SDP/ICE from a previous call
- Mismatched offer/answer state transitions
2) Inspect RTCPeerConnection state transitions
Log these events and states:
signalingStateiceConnectionStateiceGatheringStateconnectionState
Example:
pc.oniceconnectionstatechange = () => {
console.log('iceConnectionState:', pc.iceConnectionState);
};
pc.onconnectionstatechange = () => {
console.log('connectionState:', pc.connectionState);
};
pc.onsignalingstatechange = () => {
console.log('signalingState:', pc.signalingState);
};
pc.onicegatheringstatechange = () => {
console.log('iceGatheringState:', pc.iceGatheringState);
};
Useful meanings
new/checking: negotiation underwayconnected: ICE succeededcompleted: ICE fully establishedfailed: ICE could not find a working pathdisconnected: temporary network issueclosed: peer connection closed
If you get stuck in checking or failed, the issue is usually ICE/network related.
3) Gather and examine ICE candidates
Make sure candidates are actually being found:
pc.onicecandidate = (e) => {
if (e.candidate) {
console.log('ICE candidate:', e.candidate.candidate);
} else {
console.log('ICE gathering complete');
}
};
What to look for
- Do you get any candidates at all?
- Are they only
hostcandidates? - Do you get
srflx(server reflexive via STUN) orrelay(via TURN) candidates?
If you only have host candidates and peers are on different networks/NATs, the connection may fail unless a TURN server is available.
4) Verify STUN/TURN configuration
A very common cause of failure is bad or missing TURN configuration.
STUN
Helps discover public-facing addresses.
Example:
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
TURN
Used when direct peer-to-peer connectivity fails.
Example:
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{
urls: 'turn:turn.example.com:3478',
username: 'user',
credential: 'pass'
}
]
Common TURN problems
- Wrong username/password
- TURN server unreachable from client network
- UDP blocked, but no TCP/TLS TURN fallback configured
- TURN server certificates invalid for
turns: - Incorrect ports/firewall rules
If signaling works but ICE fails, TURN is one of the first things to validate.
5) Use browser WebRTC internals
Chrome / Edge
Go to:
chrome://webrtc-internals/
This is extremely useful. It shows:
- SDP offer/answer
- ICE candidates
- connection state changes
- selected candidate pair
- stats
Firefox
Use:
about:webrtc
These tools often reveal:
- No candidates gathered
- STUN requests not returning
- Candidate pair never selected
- DTLS handshake failure
- Media track errors
6) Check SDP for obvious problems
Look at the SDP offer and answer.
Things to verify
- Both peers include compatible codecs
m=sections are present for audio/video/dataa=ice-ufraganda=ice-pwdare presenta=fingerprintexists for DTLSa=rtcp-muxis present when expected- Direction attributes make sense:
sendrecv,sendonly,recvonly,inactive
Common SDP issues
- SDP munging breaks syntax
- Codecs removed accidentally
- BUNDLE or RTCP mux incompatibility
- Incomplete answer generated by signaling layer
7) Check DTLS/SRTP and certificate issues
If ICE connects but media does not flow, the problem may be in DTLS/SRTP.
Signs:
iceConnectionStatebecomesconnectedconnectionStatenever reachesconnected- No media packets received
Possible causes:
- Certificate mismatch
- DTLS handshake failure
- SDP negotiation mismatch
- Firewall/proxy interference with packets
Browser internals and stats can help show whether DTLS succeeded.
8) Use getStats() to diagnose media and transport
getStats() is one of the best debugging tools.
Example:
const stats = await pc.getStats();
stats.forEach(report => {
console.log(report.type, report.id, report);
});
Useful stats to inspect
candidate-pairlocal-candidateremote-candidatetransportinbound-rtpoutbound-rtptrack
Key indicators
For candidate-pair:
statenominatedselectedbytesSentbytesReceived
If bytes stay at zero, connectivity or media flow is broken.
9) Test network conditions
WebRTC can fail because of environment, not code.
Check:
- Corporate firewalls
- Symmetric NAT
- UDP blocked
- VPN interference
- Mobile networks with strict NAT
- Browser permissions
Quick test
Try:
- Same LAN
- Different networks
- With and without VPN
- With TURN only
If it works only on the same network, you likely need TURN.
10) Simplify to isolate the problem
To debug efficiently:
- Start with audio-only
- Remove custom SDP munging
- Use a known-good STUN/TURN config
- Test with two browsers on the same machine first
- Then same LAN
- Then different networks
This narrows down whether the issue is:
- App logic
- Signaling
- ICE
- Network/firewall
- Media negotiation
11) Log the exact sequence
A lot of WebRTC bugs are ordering problems. Log these steps:
- create offer
- set local description
- send offer
- receive answer
- set remote description
- send candidate
- add candidate
- connection state changes
This often reveals bugs like:
- calling
addIceCandidate()too early - setting remote description twice
- failing to wait for
setLocalDescription()to finish
12) Consider browser-specific behavior
Different browsers may behave differently around:
- Trickle ICE
- SDP formatting
- codec preferences
- mDNS host candidates
- autoplay restrictions
- permissions
If it works in one browser but not another, compare:
- SDPs
- ICE candidates
- stats output
- browser console errors
Quick debugging flow
If a WebRTC connection fails, check in this order:
- Did signaling messages arrive?
- Are ICE candidates exchanged?
- Do any candidates appear?
- Does ICE reach
connected? - Does DTLS complete?
- Do media stats show bytes flowing?
- Is TURN configured and working?
Best first tools
- Browser console logs
chrome://webrtc-internals/about:webrtcgetStats()- TURN server logs
- Network/firewall inspection
If you want, I can also give you:
- a WebRTC debugging checklist,
- a sample logging wrapper for RTCPeerConnection, or
- help you debug a specific failed connection if you paste your logs / SDP / stats.