Skip to main content
← Back to Protocols

WebRTC Technical Deep-Dive

WHIP/WHEP protocols, NAT traversal, and sub-500ms streaming

Advanced
Sub-500ms latency
Cloudflare Calls

WebRTC Architecture

How WAVE implements WebRTC with Cloudflare Calls

WAVE uses WHIP (WebRTC HTTP Ingest Protocol) for publishing and WHEP (WebRTC HTTP Egress Protocol) for playback, both powered by Cloudflare Calls for global edge processing.

WHIP (Publishing)

Standard protocol for WebRTC ingest. Encoder sends SDP offer via HTTP POST, receives answer with ICE candidates.

POST /whip/stream_xyz
Content-Type: application/sdp

[SDP Offer]

WHEP (Playback)

Standard protocol for WebRTC playback. Player sends SDP offer, receives answer with playback tracks.

POST /whep/stream_xyz
Content-Type: application/sdp

[SDP Offer]

SDP Offer/Answer Flow

WebRTC session negotiation

// 1. Create peer connection with Cloudflare ICE servers
const pc = new RTCPeerConnection({
  iceServers: [
    { urls: 'stun:stun.cloudflare.com:3478' },
    {
      urls: 'turn:turn.cloudflare.com:3478',
      username: 'cloudflare',
      credential: 'credentials-from-api'
    }
  ]
});

// 2. Add local media tracks
const stream = await navigator.mediaDevices.getUserMedia({
  video: { width: 1920, height: 1080 },
  audio: true
});

stream.getTracks().forEach(track => pc.addTrack(track, stream));

// 3. Create SDP offer
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);

// 4. Send offer to WAVE WHIP endpoint
const response = await fetch('https://rtc.wave.inc/whip/stream_xyz', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer wave_live_xxxxx',
    'Content-Type': 'application/sdp'
  },
  body: offer.sdp
});

// 5. Receive SDP answer
const answer = await response.text();
await pc.setRemoteDescription({ type: 'answer', sdp: answer });

// 6. ICE candidates exchange automatically
// Cloudflare Calls handles STUN/TURN negotiation

console.log('Publishing started! Latency: <200ms encoder-to-edge');

NAT Traversal (ICE/STUN/TURN)

How WebRTC connects through firewalls and NATs

WebRTC uses ICE (Interactive Connectivity Establishment) to find the best path between peers, even through NATs and firewalls.

STUN

Session Traversal Utilities for NAT

Discovers your public IP address and port through NAT. Works for ~80% of connections.

stun:stun.cloudflare.com:3478 (Global anycast)
TURN

Traversal Using Relays around NAT

Relays media through Cloudflare edge when direct connection fails (symmetric NATs). Fallback for ~20%.

turn:turn.cloudflare.com:3478?transport=udp
ICE

Interactive Connectivity Establishment

Tries multiple connection paths (host, srflx, relay) and picks the best one. Typical success: over 99.5%.

Priority order: Host candidate → Server reflexive (STUN) → Relay (TURN)

Codec Support

Video and audio codecs supported by WAVE WebRTC

Video Codecs

VP8
Full
Recommended
Quality: Good
CPU: Medium
VP9
Full
Recommended
Quality: Excellent
CPU: High
H.264
Full
Recommended
Quality: Good
CPU: Low
AV1
Partial
Quality: Excellent
CPU: Very High

Audio Codecs

Opus
Full
Recommended
Quality: Excellent
CPU: Low
G.711
Full
Quality: Good
CPU: Very Low
AAC
Limited
Quality: Good
CPU: Low

Performance Optimization

Achieve sub-500ms glass-to-glass latency

Bandwidth Adaptation

WebRTC dynamically adjusts bitrate based on network conditions using RTCP feedback.

// Congestion Control: GCC (Google Congestion Control)
Target bitrate: 2.5 Mbps → Network congestion → Adapt to 1.5 Mbps

Jitter Buffering

Adaptive jitter buffer smooths packet arrival times (20-200ms typical).

Lower buffer = lower latency but more sensitive to network jitter

FEC (Forward Error Correction)

Recovers lost packets without retransmission (OpusFEC for audio, FlexFEC for video).

Tolerates up to 15% packet loss with minimal quality degradation

Simulcast

Encoder sends multiple quality layers simultaneously. Edge selects best layer per viewer.

Layers: 1080p@3Mbps, [email protected], 360p@500Kbps

Ideal Use Cases

When to choose WebRTC over other protocols

Interactive Live Streams

<500ms

Auctions, live sports betting, Q&A sessions

Business Impact: 35% higher conversion on premium interactive features. Live auctions generate 2.5x revenue vs traditional streams

Video Conferencing

<200ms

Multi-party calls, screen sharing, collaboration

Business Impact: 40% improvement in meeting productivity. Replace expensive conferencing infrastructure ($500K+ annually)

Real-time Gaming

<100ms

Cloud gaming, interactive streaming, esports

Business Impact: Sub-100ms latency maintains competitive advantage. Enables new gaming revenue streams ($X per viewer)

Live Commerce

<300ms

Shopping streams, product demos, instant checkout

Business Impact: 55% increase in purchase intent with <300ms latency. Average order value 30% higher on live shopping

WebRTC Technical Deep-Dive | WAVE Docs | WAVE