cf-sfu-worker
讓團隊一起觀看、通話並操控 pi-webrtc 裝置的 Cloudflare Worker — 本機執行、部署,以及撰寫客戶端用的協定。
Getting Started
Run the worker on your computer, then connect a real camera to it.
Run it on your computer
Start the worker on your computer, and watch a test camera in your browser. You need Node.js 22 or newer and a Cloudflare account.
Connect pi-webrtc
Stream a Raspberry Pi or a Jetson camera to the worker with pi-webrtc. First install pi-webrtc on the device. See its Getting Started.
Troubleshooting
Common errors, and how to fix them. Errors from the token API come as { "error": { "code", "message" } }.
Deployment
Put the worker on your Cloudflare account, configure it, and protect its dashboard.
Deploy
Put the worker on your Cloudflare account. Use the Deploy button, or deploy from your computer with Wrangler.
Configuration
Every secret and variable of the worker. Set secrets with npx wrangler secret put <NAME>, or in the dashboard under Settings > Variables and Secrets. Change...
Dashboard
The dashboard at /sfu/admin/ lists every room, with its devices and viewers. This page shows how to open it on a deployed worker, and where to find the debug...
Reference
How devices and viewers talk to the worker. Read these to write your own client. pi-webrtc and @mazupo/client already do all of this.
Token API
A device or a viewer trades a public key for a short access token. Then it opens a WebSocket with that token.
Messages
The messages on the socket, and the rules for devices and viewers. The messages are protobuf, defined in protos/cloudflare.proto of mazupo/protocol.
Data channels
A device can open two data channels. The SFU copies what the device sends to every viewer that opens them. Only the viewer that controls the device can send...
Voice
Viewers in a room can talk to each other. The devices in the room can play their voices.
Development
How the worker works inside, and how to change and test it.

