WebRTC + STUN/TURN in LiveKit — explained

why we need a TURN server (STUNner) and a SIP service — grounded in the LiveKit & STUNner docs
P2P mesh — NOT LiveKit every pair connects → N² links, doesn't scale SFU — LiveKit ✓ SFU server agent each participant ↔ server only

1. LiveKit is an SFU — not peer-to-peer

Participants don't connect to each other. Every participant — the user and the tm-agent — opens one WebRTC connection to the LiveKit server (the SFU), which forwards a copy of each track to everyone else.

"LiveKit is an opinionated, horizontally-scaling WebRTC Selective Forwarding Unit… a publisher sends media to the server, and the server forwards a copy of each track to each interested subscriber."— LiveKit docs, SFU internals
NAT / firewall Clientbrowser NAT / LB SFU STUN"my public IP?" TURNrelay (STUNner) host candidate ✗ (NAT blocks) srflx (may work) relay ✓ always works

2. ICE, STUN & TURN — crossing NAT

Each client→SFU leg is a WebRTC connection that must punch through NAT. WebRTC uses ICE to find a working path by gathering candidates:

STUN = discover address. TURN = relay the media. Both exist purely to traverse NAT — like your teammate said, "macam NAT."

LiveKit "will attempt to use STUN to discover the true IP… if a direct path can't be found, TURN relays the media."— LiveKit docs, Ports & firewall
Clientbrowser Kubernetes / CCE cluster Load Bal.UDP 3478 STUNnerTURN server SFU podprivate 10.x relay media UDPRoute no hostNetwork

3. Why STUNner — SFU behind a load balancer

The SFU runs as a pod on a private IP, behind a load balancer — a browser can't reach a pod IP directly (exactly your lead's point: "livekit server lives behind load balancer").

"LiveKit itself will not use STUNner… we are just telling LiveKit to instruct its clients to use STUNner to reach the LiveKit media servers."— STUNner docs, LiveKit example
On CAE: STUNner's 3478 is exposed internally only — all WebRTC clients are on the VPN, so no public IP needed.
LiveKit room SFU WebRTC userbrowser / BTW STUNnerTURN 3478 WebRTC Nubitelphone trunk SIP svc5060 · VM SIP tm-agentin-cluster direct

4. Two doors into the same room

Different participant types join the same SFU room via different paths — this is why both a TURN server and a SIP service exist:

"This has nothing to do with Nubitel. STUNner is for LiveKit participants using WebRTC… Nubitel joins LiveKit as a SIP participant, not WebRTC."— the design clarification, in plain terms
Grounded in: LiveKit SFU internals · LiveKit ports & firewall · STUNner LiveKit example