Start Chatting

How WebRTC Works: STUN, TURN, ICE & Peer-to-Peer Video

WebRTC is the open technology that lets browsers send live audio and video directly between users. Here is how it powers platforms like Aznabee - including STUN, TURN, and ICE.

See WebRTC in action - start a free stranger video chat on Aznabee.

Try Live Video Chat
Get the Aznabee app to unlock all filters - download on Google Play

What is WebRTC?

WebRTC (Web Real-Time Communication) is a set of APIs and protocols that let web apps capture camera/microphone input and exchange media with low latency - usually peer-to-peer, without a custom plugin. Chrome, Firefox, Safari, and Edge all ship WebRTC, which is why modern video chat sites can run entirely in the browser.

For random chat products, WebRTC is ideal: once two strangers are matched, their browsers can negotiate a direct path for video and audio. The matching service helps them find each other; the heavy media often does not need to pass through your chat servers.

Why it matters for users

Peer-to-peer paths usually mean lower delay and lower server cost. When a direct path is blocked by a strict network, TURN relays keep the call alive.

The connection flow

A WebRTC call is not a single HTTP request. It is a short dance between browsers, a signaling channel, and optional helper servers:

  1. Get local media - getUserMedia asks for camera and mic permission and produces a local MediaStream.
  2. Create a peer connection - an RTCPeerConnection object represents one side of the call and holds codecs, tracks, and network state.
  3. Exchange offers and answers - SDP (Session Description Protocol) describes what each side can send/receive. That SDP is sent over your app's signaling channel (WebSocket, etc.).
  4. Gather ICE candidates - each browser discovers possible network addresses (host, server-reflexive via STUN, relay via TURN).
  5. Connect and stream - ICE picks a working candidate pair; encrypted media (DTLS-SRTP) starts flowing.

Signaling

WebRTC does not define how peers find each other. Your application must provide signaling: a way to pass SDP offers/answers and ICE candidates between browsers before the media path exists. On a random video chat site, signaling is usually tied to a matchmaking room - when two users are paired, the server forwards their WebRTC messages until the peer connection is up.

After the call is established, signaling can stay open for hang-up, skip-to-next-stranger, or text chat messages, but the video itself prefers the peer (or TURN) path.

What STUN servers do

Most devices sit behind a NAT (router) and do not know their public IP/port as seen from the internet. A STUN server (Session Traversal Utilities for NAT) answers a simple question: "What address do you see me as?"

With that server-reflexive address, two peers on typical home networks can often punch through and talk directly. STUN is lightweight: it helps discovery; it does not carry your video forever.

STUN in practice

Public STUN endpoints (including ones from Google and others) are commonly listed in iceServers when creating an RTCPeerConnection. Many successful calls never need anything heavier than STUN.

What TURN servers do

Some networks block UDP hole punching or sit behind restrictive firewalls (corporate Wi‑Fi, some mobile carriers). When a direct path fails, TURN (Traversal Using Relays around NAT) steps in: media is relayed through a server that both peers can reach.

TURN costs more bandwidth on the operator side, so well-built apps try peer-to-peer first and fall back to TURN only when ICE cannot find a direct pair. For users, TURN is invisible - the call just works.

  • STUN: discover public address → prefer direct P2P.
  • TURN: relay media when P2P is impossible.

ICE candidates explained

ICE (Interactive Connectivity Establishment) coordinates STUN and TURN. Each possible path is an ICE candidate: a local host address, a STUN-derived public mapping, or a TURN relay address. Peers exchange candidates through signaling, then ICE connectivity checks find the best working pair.

You may hear "ICE failed" when no candidate pair succeeds - usually a network policy issue, missing TURN credentials, or a signaling bug. Fixing ICE often means verifying STUN/TURN config and that candidates are forwarded promptly.

Encryption and security

WebRTC media is encrypted with DTLS-SRTP. Browsers also enforce secure origins (HTTPS) for camera access in normal deployments. That does not replace common-sense safety: the other person can still see what you show on camera. Encryption protects the path; it does not verify who the stranger is. Read video chat safety for user-facing guidance.

How Aznabee uses WebRTC

Aznabee matches strangers, then uses WebRTC so your browser can negotiate a live call. Signaling helps exchange offers and ICE candidates; STUN/TURN help those candidates succeed across real-world networks. Modes like skip-to-next peer tear down one RTCPeerConnection and start another with a new match.

You do not need to understand any of this to chat - but knowing the stack explains why allowing camera access, using HTTPS, and having a decent network matter for random video quality.

FAQ

Is WebRTC the same as Zoom or Meet?

Those products also use real-time media stacks (often including WebRTC-related tech), but they add accounts, SFUs (servers that mix many streams), and meeting rooms. Random chat leans harder on one-to-one peer connections plus lightweight matchmaking.

Do I need to open ports for WebRTC?

End users usually do not. STUN/TURN and ICE are designed to work through typical consumer NATs. Very locked-down networks may only succeed via TURN over permitted ports.

Why is my video chat lagging?

Latency often comes from weak Wi‑Fi, CPU load from encoding, or a TURN relay far from both users. Closing other tabs that use the camera and switching networks can help.


Related reading

Experience peer-to-peer video chat

Aznabee uses WebRTC under the hood. Start a free match and see it live - no account required.

Start Chatting on Aznabee