I built a self-hosted WebRTC SFU with host-safety gates for scale tests
I’ve spent too long guessing why my browser demo wasn’t streaming. The useful answer came from actually running the publisher and viewer.
With Hami Media on a loopback server, I opened the streamer and viewer examples in two browser tabs and clicked Go Live. No token was copied into either page or put in the URL: when the optional token field is blank, each page asks the local server for its own short-lived, role-scoped token.
What I verified
- The publisher reached LIVE, and the server received audio and video tracks.
- The viewer rendered video at 1280×720 and received live audio and video tracks.
- A chat message sent by the publisher appeared in the viewer.
This was two tabs on one Mac, connected to 127.0.0.1:18082.
Why this is more than a demo
Hami Media is a single-binary WebRTC SFU. Beyond the loopback browser flow verified above, it includes several pieces of engineering work:
- Host-safety gates for scale-proof runs. The
sfu-singleandm9hmodes check used swap, memory pressure, and free-disk headroom before starting; a watchdog monitors these runs. This gate does not currently apply to every mode, includingserve. - Measured capacity estimates.
./hami-media capacityreports host-specific publisher/viewer recommendations scaled from measured anchors, not beyond them. - Reproducible benchmarks. Benchmark protocols are preregistered and run artifacts are committed, so readers can inspect the methodology and reproduce reported measurements.
Repo: github.com/kn33r0s3/hami-media
Try the local flow
The server still needs its HMAC signing key configured. “No token copy-paste” means the browser examples handle their short-lived local tokens for you; it does not mean the server has no authentication setup.
Build Hami Media and start it bound to loopback:
go build -o hami-media . HAMI_SFU_HMAC_KEY_FILE=/path/to/hami.key ./hami-media -mode=serve -serve-listen=127.0.0.1:18082 Then open http://127.0.0.1:18082/examples/streamer.html, click Go Live, and open http://127.0.0.1:18082/examples/viewer.html in another tab and click Watch Room. The local token-minting route is restricted to loopback and same-origin requests. Remote servers still require a supplied token.
The limit
This test proves the local loopback flow, not remote viewing over the public internet: this test server advertised loopback-only WebRTC candidates, and an HTTPS tunnel does not carry media. The next milestone is proving a phone on cellular can watch through TURN; that complete path is not yet verified end-to-end.
AI disclosure: Copilot assisted with implementation, browser verification, and this draft. The local browser result was observed; the remote path was not tested.