Skip to content
im-pingo edited this page Mar 26, 2026 · 1 revision

English | 中文

WebRTC (WHIP/WHEP)

LiveForge supports WebRTC for ultra-low-latency publish and subscribe using the WHIP and WHEP standards.

Configuration

webrtc:
  enabled: true
  listen: ":8443"
  ice_servers:
    - urls: ["stun:stun.l.google.com:19302"]
  udp_port_range: [20000, 30000]
  candidates: []
  # tls: true          # Optional: override global TLS setting
Field Type Default Description
enabled bool true Enable/disable the WebRTC module
listen string ":8443" HTTP signaling server listen address
ice_servers list Google STUN STUN/TURN servers for ICE candidate gathering
udp_port_range [int, int] [20000, 30000] UDP port range for ICE media transport
candidates list [] External IP addresses to advertise as ICE host candidates (for NAT/Docker)
tls *bool nil Per-module TLS override (see Server & TLS)

ICE Server Configuration

ice_servers:
  - urls: ["stun:stun.l.google.com:19302"]
  - urls: ["turn:turn.example.com:3478"]
    username: "user"
    credential: "pass"

WHIP Publish

WHIP (WebRTC-HTTP Ingestion Protocol) allows publishing a stream via a single HTTP POST.

Endpoint: POST /webrtc/whip/{app}/{key}

The request body is an SDP offer with Content-Type: application/sdp. The response is an SDP answer with HTTP status 201 Created.

Browser Console Example

Open the web console at http://localhost:8090/console, click "+ WebRTC Publish", select camera and microphone, and start streaming. The console uses the WHIP endpoint internally.

curl Example

curl -X POST http://localhost:8443/webrtc/whip/live/stream1 \
  -H "Content-Type: application/sdp" \
  -d @offer.sdp

The Location header in the response contains the session URL for management.

WHEP Subscribe

WHEP (WebRTC-HTTP Egress Protocol) allows subscribing to a stream via a single HTTP POST.

Endpoint: POST /webrtc/whep/{app}/{key}

Playback Modes

Append a mode query parameter to control startup behavior:

Mode URL Behavior
realtime (default) /webrtc/whep/live/stream1 Skip GOP cache, wait for the next live keyframe. Lowest latency.
live /webrtc/whep/live/stream1?mode=live Send GOP cache for immediate playback, then live frames.

Session Management

Delete a Session

DELETE /webrtc/session/{session-id}

Tears down the peer connection and releases all resources.

ICE Trickle (PATCH)

PATCH /webrtc/session/{session-id}
Content-Type: application/trickle-ice-sdpfrag

Used for trickle ICE candidate delivery.

Supported Codecs

Type Codecs
Video H.264, H.265, VP8, VP9, AV1
Audio Opus, G.711 (PCMU/PCMA)

Use Cases

  • Browser-to-browser streaming -- publish from a browser camera via WHIP, watch in another browser via WHEP
  • Ultra-low-latency monitoring -- sub-second end-to-end latency
  • Interactive live streaming -- real-time bidirectional communication
  • Protocol bridging -- publish via WHIP, distribute via HLS/DASH/RTMP to large audiences

Clone this wiki locally