WebRTC
ActiveWeb Real-Time Communication (WebRTC) is a collection of IETF and W3C standards that enables peer-to-peer audio, video, and arbitrary data exchange directly between browsers and devices, without plugins or intermediate servers for the media path. WebRTC is used by Google Meet, Discord, Zoom (web), WhatsApp Web, and every major video calling product.
In one line
WebRTC (RFC 8825 suite, 2021) enables peer-to-peer audio, video, and data exchange directly in the browser via the RTCPeerConnection API. Connections use ICE (RFC 8445) to discover and negotiate network paths through NAT – STUN (RFC 5389) discovers public IP, TURN (RFC 8656) relays media when direct path fails. Media is encrypted with DTLS-SRTP (RFC 5764). SDP offer/answer (RFC 3264) negotiates codecs and media parameters. Data channels use SCTP over DTLS (RFC 8831).
Quick Reference
| Field | Size | Description |
|---|---|---|
| ICE | RFC 8445 | Interactive Connectivity Establishment. Gathers local network candidates, discovers public address via STUN, uses TURN relay as fallback. Connectivity checks select the best path. |
| STUN | RFC 5389/8489 | Session Traversal Utilities for NAT. A server that echoes your public IP:port back to you. Used by ICE to discover server-reflexive (srflx) candidates. |
| TURN | RFC 8656 | Traversal Using Relays around NAT. A relay server that forwards media when direct P2P fails. Required for symmetric NAT (~20–30% of connections). Adds latency and bandwidth cost. |
| DTLS | RFC 6347 | Datagram TLS. Encrypts all WebRTC media and data. DTLS handshake establishes keys for SRTP (media) and SCTP (data channels). Mandatory – WebRTC never sends unencrypted media. |
| SRTP | RFC 3711 | Secure Real-time Transport Protocol. Encrypts audio/video streams. Keys derived from DTLS handshake (DTLS-SRTP, RFC 5764). AES-CM-128 or AES-GCM. |
| SDP Offer/Answer | RFC 3264 | Session Description Protocol negotiation. Offerer sends SDP describing capabilities; answerer responds with accepted subset. Defines codecs, ICE credentials, DTLS fingerprint. |
| SCTP | RFC 8831 | Stream Control Transmission Protocol over DTLS. Powers RTCDataChannel. Supports ordered/unordered, reliable/unreliable, and partially reliable delivery modes. |
| BUNDLE | RFC 8843 | Multiplexes all media streams (audio, video, data) on a single ICE component and port. Reduces TURN relay cost and NAT state. Enabled by default in modern browsers. |
| Signaling | Not specified | WebRTC does not define a signaling protocol. SDP offer/answer must be exchanged out-of-band via WebSocket, HTTP, or any other channel. |
Key Characteristics
Peer-to-peer media
When ICE succeeds with a direct path, media flows P2P without any intermediate server. Sub-100 ms latency for real-time video calls on good networks.
Mandatory encryption
All WebRTC media and data is encrypted. DTLS-SRTP for media streams, DTLS for data channels. There is no opt-out. The spec explicitly forbids cleartext media.
NAT traversal complexity
ICE handles most NAT types automatically, but symmetric NAT requires TURN relay. Deploy TURN servers for production. Coturn is the most common open-source TURN server.
Low-latency media
VP8, VP9, H.264 video codecs. Opus audio codec (48 kHz, 2.5–120 ms frame size). Adaptive bitrate, jitter buffer, packet loss concealment built in.
Message Format
// WebRTC connection flow (simplified)
// 1. Get local media
const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
// 2. Create RTCPeerConnection with ICE servers
const pc = new RTCPeerConnection({
iceServers: [
{ urls: "stun:stun.example.com:3478" },
{ urls: "turn:turn.example.com:3478",
username: "user", credential: "pass" }
]
});
stream.getTracks().forEach(t => pc.addTrack(t, stream));
// 3. Create SDP offer
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
// 4. Exchange SDP via signaling channel (your WebSocket/HTTP)
signalingChannel.send(JSON.stringify({ sdp: offer }));// SDP offer (abbreviated)
v=0
o=- 123456 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE 0 1
a=msid-semantic: WMS
m=audio 9 UDP/TLS/RTP/SAVPF 111
a=rtpmap:111 opus/48000/2
a=ice-ufrag:abc123
a=ice-pwd:xxxxxxxxxxxxxxxxxxxx
a=fingerprint:sha-256 AA:BB:CC:...
a=setup:actpass
// ICE candidate (server-reflexive)
candidate:1 1 UDP 1686052607 203.0.113.1 54321 typ srflx
raddr 192.168.1.5 rport 12345 generation 0
// Data channel creation
const dc = pc.createDataChannel("chat", {
ordered: true, // TCP-like delivery
maxRetransmits: 3 // or use maxPacketLifeTime
});
dc.onmessage = (e) => console.log(e.data);