Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
The relay serves WS /camera/<id>/ws from the shared camera feed, and the offline picture when the Pi camera is down #172
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
The relay now serves WS /camera/ /ws in src/relay.ts. It sends whole binary JPEG frames from the shared feed and sends the offline picture when the camera is down. I couldn't run tsc here, so the type check is unverified.
shipped merged
The relay now serves WS /camera/<id>/ws in src/relay.ts. It sends whole binary JPEG frames from the shared feed and sends the offline picture when the camera is down. I couldn't run tsc here, so the type check is unverified. The forge's check will run it on this push.
- Environment problem:
bun installandbun x tsc --noEmitboth fail in this sandbox withbun is unable to write files to tempdir. - Test run: the full
bun testgives 414 pass and 1 fail. The failure is "serves the model, its meshes and the vendored libraries", which I think fails only becausenode_modulesisn't installed, though I didn't check it againstmain. The new and nearby suites (relay,camera-feed,camera-socket,cameras) pass.
- One upstream connection:
CameraFeedinsrc/camera-feed.tsgets anattach(sink)method. It gathers whole frames from the same upstream connection the HTTP viewers already share, and only while a sink is attached. A sink counts as a viewer, so it keeps the upstream open and lets it go after the usual linger. - Offline frame:
broadcastOfflinealso calls each sink'soffline(), which includes the repeat everyofflineEveryMs. The offline picture is the PNG fromsrc/offline-frame.ts. CameraSocket.replace(picture): a new method insrc/camera-socket.ts.pushonly accepts JPEGs, so this is how the offline PNG gets through, and a late joiner gets it until the next real frame arrives.- Relay route: an unknown id or a cross-origin request is refused with a plain HTTP 404 or 403. Each camera gets one
CameraSocketand one tap on the feed. They are created for the first viewer and dropped when the last one leaves. - Gap, camera removal: removing a camera from the list closes its feed, but WS viewers stay connected showing their last frame.
- Gap, lobby gating: like the HTTP camera GET, the camera socket is not gated by the lobby. Anyone on the same origin can watch.
- Tests (
src/relay.test.ts):
- Two viewers each get a whole JPEG while the fake MJPEG upstream records exactly one connection. - A stalled upstream gives the offline frame. - An unknown id never opens.
- Unchanged:
forge.json, and no new dependencies.
🤖 Generated with Claude Code
I merged main into this branch and pushed. The merge had one conflict, in the import block of src/relay.ts.
- Conflict:
mainreplaced the admin imports with a singlehandleAdminimport from./admin-routes.ts. I took that and kept this branch'sCameraSocketandOFFLINE_FRAMEimports. Nothing else inrelay.tsstill used the old admin imports. - Tests:
bun testgives 415 pass and 1 fail. The failure is the same one as before the merge: "serves the model, its meshes and the vendored libraries". I think it fails only becausenode_modulesisn't installed in this sandbox, though I haven't checked it againstmain. - Type check: not run here, because
bun installandbun x tsc --noEmitfail in this sandbox withbun is unable to write files to tempdir. The forge's check will run it on this push.
The PR itself is unchanged: WS /camera/<id>/ws serves whole JPEG frames from the shared camera feed, sends the offline picture when the camera is down, and refuses unknown ids.
🤖 Generated with Claude Code
Does what the issue asked: WS /camera/<id>/ws shares the one upstream connection, sends whole JPEGs, sends the offline PNG when the source is down, and refuses unknown ids and cross-origin upgrades. Tests cover the two-viewer/one-connection case, the offline frame and the unknown id. No new dependency. I did not exercise the preview.
Two things to do next:
- Removing a camera leaves its WS viewers connected on a stale last frame, and the watched entry stays until they close. Close those sockets (or push the offline frame) when the camera is removed, and add a test.
- Add a line to the README saying how to use the WS endpoint; the route is only documented in the relay.ts header. Add a test that a late joiner receives the replaced offline picture.
The relay now serves
WS /camera/<id>/wsinsrc/relay.ts. It sends whole binary JPEG frames from the shared feed and sends the offline picture when the camera is down. I couldn't runtschere, so the type check is unverified. The forge's check will run it on this push.bun installandbun x tsc --noEmitboth fail in this sandbox withbun is unable to write files to tempdir.bun testgives 414 pass and 1 fail. The failure is "serves the model, its meshes and the vendored libraries", which I think fails only becausenode_modulesisn't installed, though I didn't check it againstmain. The new and nearby suites (relay,camera-feed,camera-socket,cameras) pass.CameraFeedinsrc/camera-feed.tsgets anattach(sink)method. It gathers whole frames from the same upstream connection the HTTP viewers already share, and only while a sink is attached. A sink counts as a viewer, so it keeps the upstream open and lets it go after the usual linger.broadcastOfflinealso calls each sink'soffline(), which includes the repeat everyofflineEveryMs. The offline picture is the PNG fromsrc/offline-frame.ts.CameraSocket.replace(picture): a new method insrc/camera-socket.ts.pushonly accepts JPEGs, so this is how the offline PNG gets through, and a late joiner gets it until the next real frame arrives.CameraSocketand one tap on the feed. They are created for the first viewer and dropped when the last one leaves.src/relay.test.ts):- Two viewers each get a whole JPEG while the fake MJPEG upstream records exactly one connection. - A stalled upstream gives the offline frame. - An unknown id never opens.
forge.json, and no new dependencies.🤖 Generated with Claude Code
Closes #139