A plain-English guide to how WebRTC connections form (SDP, ICE, DTLS, SRTP), which servers are involved, and how it compares with RTMP, HLS and SRT.
You click a link and a video call just starts. No download, no plugin, no "please install this first."
That small bit of magic is WebRTC, and it's why a live auction bid, a telehealth visit or a multiplayer game can feel instant. Let's break down how it works, in plain English.
What is WebRTC?
WebRTC (Web Real-Time Communication) is a free, open-source protocol suite that lets browsers and devices stream audio, video and data to each other in under 500 milliseconds. It's standardized by the W3C and IETF, and WebRTC 1.0 became an official W3C Recommendation in January 2021.
Before it, real-time video meant Flash, Silverlight or a plugin nobody wanted to install.
The 3 JavaScript APIs
-
getUserMediacaptures your camera and mic. It's the only one that asks for permission. -
RTCPeerConnectionhandles negotiation, encryption and media flow. -
RTCDataChannelsends text, files or any binary data alongside your video.
Here's what the start of a connection looks like in code:
const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true }); const pc = new RTCPeerConnection({ iceServers: [{ urls: "stun:stun.l.google.com:19302" }] }); stream.getTracks().forEach((track) => pc.addTrack(track, stream)); const offer = await pc.createOffer(); await pc.setLocalDescription(offer); // Send `offer` to the other peer through your signaling server (Google's public STUN server is fine for development. Use dedicated infrastructure in production.)
How two browsers actually connect
- Media capture: the browser accesses your camera and mic, after you allow it.
- SDP offer/answer: both sides compare codecs and settings, like agreeing on a common language before talking.
- ICE gathering: each peer finds its public address via STUN and tests candidate routes. If no direct path works, a TURN relay steps in, which happens in roughly 15-20% of enterprise sessions.
- DTLS handshake: encryption keys are agreed before a single frame is sent.
- RTP/SRTP delivery: encrypted audio and video flow over UDP, and Google Congestion Control adapts quality if the network gets shaky.
The 5 building blocks
| Component | What it does |
|---|---|
| SDP | Describes what each peer can send and receive |
| ICE | Finds the best network path between peers |
| STUN | Tells a peer its public IP address |
| TURN | Relays media when a direct connection fails |
| RTP/SRTP | Carries the actual audio and video packets |
The 4 servers in a production setup
- Application server: hosts your app and API
- Signaling server: passes SDP and ICE messages (metadata only, never media)
- STUN/TURN server: NAT traversal and relay fallback
- Media server: SFU/MCU, recording, transcoding and protocol conversion. You need this once you go beyond a simple 1:1 call.
WebRTC vs other protocols
| Protocol | Typical latency | Transport | Browser native |
|---|---|---|---|
| WebRTC | 0.2-0.5 s | UDP (SRTP) | Yes |
| RTMP | 3-6 s | TCP | No |
| HLS | 8-30 s | HTTP/TCP | Yes |
| LL-HLS | 2-5 s | HTTP/2 + TCP | Yes |
| SRT | Sub-second | UDP | No |
| RTSP | 1-3 s | UDP/TCP | No |
The gap is structural: WebRTC runs over UDP and doesn't wait for lost packets, while TCP-based protocols pause until everything arrives.
Is it secure?
Yes, and it's not optional. DTLS-SRTP encryption is mandatory in the spec, so there's no "unencrypted mode." Camera access always needs user permission, and browsers hide local IPs with mDNS candidates.
Scaling beyond 1:1
Peer-to-peer works great for 2 people. As a mesh it starts to struggle around 4-6 participants, because everyone uploads to everyone. An SFU fixes this by taking one stream from each participant and forwarding it selectively. For very large audiences, the common pattern is hybrid: WebRTC for interactive users, HLS over a CDN for the overflow.
Browser support
Chrome 23+, Firefox 22+, Safari 12.1+, Edge 79+ and Opera 18+ support WebRTC natively, covering more than 85% of installed browsers.
That's the short version! The full guide, with FAQs, mobile SDKs and audio streaming details, is on the Ant Media blog: What is WebRTC and how does it work?
What's the trickiest part of WebRTC you've run into? Let me know in the comments. 👇
