oxpulse-sfu-kit 0.3.0

Reusable multi-client SFU kit built on top of str0m. Simulcast, fanout, per-peer event routing.
Documentation

oxpulse-sfu-kit

CI Crates.io docs.rs License: MIT OR Apache-2.0 MSRV

Reusable multi-client SFU primitives built on top of str0m.

str0m is a sans-I/O Rust WebRTC library — you plug in your own networking. This crate adds the multi-client glue that str0m's examples/chat.rs leaves as an exercise: per-peer state machines, UDP packet routing, event fanout, and simulcast layer forwarding.

What this gives you

  • Client — per-peer state machine wrapping str0m::Rtc
  • Registry — room-level UDP routing and event fanout
  • Propagated — the event enum flowing between registry and clients
  • Simulcast layer forwarding — per-subscriber RID filter (q/h/f)
  • Optional: dominant speaker detection (active-speaker feature)
  • Optional: Prometheus metrics (metrics-prometheus feature)

Not included (by design)

  • Signaling (bring your own — WebSocket, HTTP, gRPC)
  • TURN server (run coturn or similar)
  • Bandwidth estimation beyond str0m's Event::EgressBitrateEstimate
  • End-to-end encryption (use SFrame)

Usage

Add to Cargo.toml:

[dependencies]
oxpulse-sfu-kit = "0.1"

Minimal run loop:

use oxpulse_sfu_kit::{SfuConfig, udp_loop};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let config = SfuConfig { udp_port: 3478, ..SfuConfig::default() };
    let shutdown = async { tokio::signal::ctrl_c().await.unwrap() };
    udp_loop::run_udp_loop(config, shutdown).await
}

Insert a peer after completing ICE/DTLS signaling:

use oxpulse_sfu_kit::{Client, Registry, SfuRtcBuilder};
use oxpulse_sfu_kit::metrics::SfuMetrics;
use std::sync::Arc;

let mut registry = Registry::new(Arc::new(SfuMetrics::default()));
let rtc = SfuRtcBuilder::new().build(); // or SfuRtc::from_raw(raw_rtc) for advanced use
let client = Client::new(rtc, Arc::new(SfuMetrics::default()));
registry.insert(client);

Feature flags

Flag What it does
active-speaker Dominant speaker tracking via rust-dominant-speaker. Adds Propagated::ActiveSpeakerChanged and Registry::tick_active_speaker / Registry::record_audio_level.
metrics-prometheus Prometheus counters on SfuMetrics. You choose how to expose them (axum, warp, etc.).
test-utils Test seam helpers (test_seed module, Registry::*_for_tests methods). Gate your own tests on this.

Examples

cargo run --example basic-sfu --features active-speaker,metrics-prometheus

See examples/basic-sfu.rs for a complete single-node SFU with a Prometheus /metrics endpoint.

Relationship to str0m

We build on str0m's Rtc state machine. We do not replace it — we connect multiple instances together for multi-party rooms. All credit for the underlying protocol work goes to Martin Algesten and the str0m contributors.

Extracted from

Originally built as part of OxPulse Chat. Published standalone for the broader Rust WebRTC ecosystem.

License

Dual MIT / Apache-2.0. See LICENSE-MIT and LICENSE-APACHE.

Status

v0.1 — Initial release. API may shift during v0.x; we commit to stability from v1.