WebRTC SFU Server

High-performance Selective Forwarding Unit with server-authoritative signaling and perfect negotiation

Architecture

Selective Forwarding Unit (SFU)

The server acts as an SFU: it receives media streams from each participant and intelligently forwards only the required streams to others. This approach offers excellent scalability and allows clients to control which streams they receive.

Server-Authoritative Signaling

The server controls the negotiation flow. It can initiate offers for new participants, track additions/removals, simulcast layer changes, and ICE restarts.

Perfect Negotiation

Client operates as a Polite Peer. When the server sends an sfu_offer, the client always yields.

1. Initial Join Flow

  • Client receives sfu_joined event
  • Creates initial offer → setLocalDescription
  • Sends sfu_offer to server

2. Handling sfu_offer from Server

if (makingOffer || pc.signalingState !== "stable") {
  await pc.setLocalDescription({ type: "rollback" });
}
await pc.setRemoteDescription(offer);
const answer = await pc.createAnswer();
await pc.setLocalDescription(answer);
// send sfu_answer

This logic handles regular renegotiation and ICE restart identically.

Trickle ICE

Candidates are sent immediately. When the last candidate arrives, send sfu_ice_candidate with data: null.

ICE Restart

Triggered via WebSocket event or manually by sending sfu_ice_restart .

Unified Plan

RTCRtpTransceivers for dynamic track management

Fast Negotiation

Server-authoritative perfect negotiation

ICE Restart

Robust reconnection handling

Explore full API specifications