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

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

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.

Notes

shipped merged

opened this

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 install and bun x tsc --noEmit both fail in this sandbox with bun is unable to write files to tempdir.
  • Test run: the full bun test gives 414 pass and 1 fail. The failure is "serves the model, its meshes and the vendored libraries", which I think fails only because node_modules isn't installed, though I didn't check it against main. The new and nearby suites (relay, camera-feed, camera-socket, cameras) pass.
  • One upstream connection: CameraFeed in src/camera-feed.ts gets an attach(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: broadcastOffline also calls each sink's offline(), which includes the repeat every offlineEveryMs. The offline picture is the PNG from src/offline-frame.ts.
  • CameraSocket.replace(picture): a new method in src/camera-socket.ts. push only 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 CameraSocket and 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

Closes #139

commented

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 install and bun x tsc --noEmit both fail in this sandbox with bun is unable to write files to tempdir.
  • Test run: the full bun test gives 414 pass and 1 fail. The failure is "serves the model, its meshes and the vendored libraries", which I think fails only because node_modules isn't installed, though I didn't check it against main. The new and nearby suites (relay, camera-feed, camera-socket, cameras) pass.
  • One upstream connection: CameraFeed in src/camera-feed.ts gets an attach(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: broadcastOffline also calls each sink's offline(), which includes the repeat every offlineEveryMs. The offline picture is the PNG from src/offline-frame.ts.
  • CameraSocket.replace(picture): a new method in src/camera-socket.ts. push only 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 CameraSocket and 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

commented

I merged main into this branch and pushed. The merge had one conflict, in the import block of src/relay.ts.

  • Conflict: main replaced the admin imports with a single handleAdmin import from ./admin-routes.ts. I took that and kept this branch's CameraSocket and OFFLINE_FRAME imports. Nothing else in relay.ts still used the old admin imports.
  • Tests: bun test gives 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 because node_modules isn't installed in this sandbox, though I haven't checked it against main.
  • Type check: not run here, because bun install and bun x tsc --noEmit fail in this sandbox with bun 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

Approved

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:

  1. 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.
  2. 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.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs