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.
1. Create a Realtime SFU app
- In the Cloudflare dashboard, go to Realtime > SFU.
- Create an application. Use a separate one for development.
- Copy its App ID and API token.
2. Get the code
git clone https://github.com/mazupo/cf-sfu-worker.git
cd cf-sfu-worker
npm install3. Make the keys
npm run keysIt prints two key pairs:
DEVICE_PRIVATE_KEY=MC4CAQAwBQYDK2VwBCIEI...
DEVICE_PUBLIC_KEY=q3Vb0Zr6...
VIEWER_PRIVATE_KEY=MC4CAQAwBQYDK2VwBCIEI...
VIEWER_PUBLIC_KEY=Xk9f2LmP...- The private keys stay in the worker.
- Devices send the device public key. Viewers send the viewer public key.
4. Fill in .dev.vars
cp .dev.vars.example .dev.varsSet these four values:
REALTIME_SFU_APP_ID=<App ID>
REALTIME_SFU_BEARER_TOKEN=<API token>
DEVICE_PRIVATE_KEY=<from npm run keys>
VIEWER_PRIVATE_KEY=<from npm run keys>5. Start the worker
npm run devThe worker runs at http://localhost:8787.
6. Watch the test camera
- Open localhost:8787/sfu/device. This page acts as a camera.
- Enter the Device public key and a room, such as
lab-a. Click Connect. The state showssleeping. - In another tab, open localhost:8787/sfu/.
- Enter the Viewer public key and the same room. Click Join.
The camera wakes and the video shows in a few seconds. Click Leave: about 30 seconds later, the camera goes back to sleeping.
Try more
- Data channels: check Enable IPC on both pages before you connect. Then send messages both ways.
- Share a link: add
?room=lab-a&viewer_key=<viewer public key>to the viewer URL. The page fills in the form. - Server state: open it on either page to see what the worker holds.
- Dashboard: localhost:8787/sfu/admin/ lists every room.
- Other devices:
npm run devlistens on all interfaces. Usehttp://<your computer's IP>:8787from your network. The Camera source works only onlocalhostorhttps.
Next
- Connect pi-webrtc to stream a real camera.
- Deploy the worker to your Cloudflare account.

