Skip to content

WebRTC (WHEP)

For ultra-low latency (<50ms) live monitoring, RUSEON Core provides a production-grade WebRTC streaming pipeline powered by Pion WebRTC v4.


WHEP Protocol Architecture

RUSEON Core implements the standard WHEP (WebRTC HTTP Egress Protocol) with Non-Trickle ICE:

  1. The browser client sends an HTTP POST request containing its SDP Offer to /stream/webrtc/whep/:id.
  2. The server initializes a PeerConnection using its pre-warmed webrtc.API instance, attaches the camera's H.264 video track, and creates the "metadata" DataChannel.
  3. The server generates and returns the SDP Answer (201 Created with Content-Type: application/sdp).
  4. Video packets and AI metadata flow directly to the client over SRTP / SCTP.

High-Performance Optimizations

1. Pre-generated DTLS Certificate

Generating ECDSA/RSA certificates at runtime causes noticeable 100-300ms connection delays. RUSEON Core pre-generates a single ECDSA P-256 certificate at server startup and shares it across all peer connections, making initial handshakes instantaneous.

2. UDP Port Multiplexer (Single UDP Port)

Instead of allocating random ephemeral UDP ports for every viewer (which complicates firewall configurations), RUSEON Core multiplexes all WebRTC ICE sessions through a single configurable UDP port:

yaml
server:
  webrtc:
    listen_port: 8555

3. NAT 1:1 Public IP Mapping

For deployments behind NAT, Docker, or Kubernetes LoadBalancers, external IPs are explicitly advertised to clients:

yaml
server:
  webrtc:
    nat_1_to_1_ips:
      - "203.0.113.10"

4. Custom STUN / TURN Configuration

Enterprise air-gapped networks and strict symmetric NATs are fully supported via configurable TURN relays:

yaml
server:
  webrtc:
    ice_servers:
      - "stun:stun.l.google.com:19302"
      - "turn:turn.company.local:3478"
    ice_transport_policy: "all" # or "relay"
    turn_username: "webrtc_user"
    turn_password: "turn_password"

SPS / PPS Keyframe Injection

To allow clients to start decoding immediately upon connection without waiting for the camera's native GOP cycle, RUSEON Core caches SPS/PPS parameter sets from the RTSP SDP handshake and prepends them in Annex-B format before every IDR Keyframe.


Real-Time Metadata DataChannel

Alongside the video track, RUSEON Core opens an SCTP DataChannel labeled "metadata". AI bounding boxes and event objects pushed via gRPC are broadcasted in JSON format over this channel with zero buffering, synchronized with the video playback.

Released under the MIT License.