WHIP/WHEP protocols, NAT traversal, and sub-500ms streaming
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.
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]Standard protocol for WebRTC playback. Player sends SDP offer, receives answer with playback tracks.
POST /whep/stream_xyz
Content-Type: application/sdp
[SDP Offer]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');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.
Discovers your public IP address and port through NAT. Works for ~80% of connections.
stun:stun.cloudflare.com:3478 (Global anycast)Relays media through Cloudflare edge when direct connection fails (symmetric NATs). Fallback for ~20%.
turn:turn.cloudflare.com:3478?transport=udpTries multiple connection paths (host, srflx, relay) and picks the best one. Typical success: over 99.5%.
Video and audio codecs supported by WAVE WebRTC
VP8VP9H.264AV1OpusG.711AACAchieve sub-500ms glass-to-glass latency
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 MbpsAdaptive jitter buffer smooths packet arrival times (20-200ms typical).
Recovers lost packets without retransmission (OpusFEC for audio, FlexFEC for video).
Encoder sends multiple quality layers simultaneously. Edge selects best layer per viewer.
Layers: 1080p@3Mbps, [email protected], 360p@500KbpsWhen to choose WebRTC over other protocols
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
Multi-party calls, screen sharing, collaboration
Business Impact: 40% improvement in meeting productivity. Replace expensive conferencing infrastructure ($500K+ annually)
Cloud gaming, interactive streaming, esports
Business Impact: Sub-100ms latency maintains competitive advantage. Enables new gaming revenue streams ($X per viewer)
Shopping streams, product demos, instant checkout
Business Impact: 55% increase in purchase intent with <300ms latency. Average order value 30% higher on live shopping