Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

The page draws the camera from /camera/<id>/ws when relayed and reconnects after 2 s without a frame #182

Merged opened this

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

Merged

When the page is relayed, it now draws each camera from WS /camera/ /ws, and it reopens the socket after 2 s without a frame. I haven't run it against a live relay or a preview. ui/video.js (new): Loaded by dynamic import, so the first visit gets no heavier.

Notes

shipped merged

opened this

When the page is relayed, it now draws each camera from WS /camera/<id>/ws, and it reopens the socket after 2 s without a frame. I haven't run it against a live relay or a preview.

  • ui/video.js (new):

- Loaded by dynamic import, so the first visit gets no heavier. It draws each binary frame as it arrives. - It reopens a socket that closes or errors after 500 ms, and ignores late frames from a replaced socket. - On a slow link it drops frames to the plan's fps. The socket has no ?fps= parameter, so that happens in the browser. - It exports cameraSource(relayed), the choice between the socket and the plain <img>. The page doesn't call it, because that would need a static import; only the test uses it.

  • viewer.html:

- Relayed cameras in stream mode use the socket. The <img src=/camera/<id>/stream> path and its onerror retry stay for the local case. - Snapshot mode is unchanged. The frozen-picture canvas check is skipped for socket cameras, and their "live" label comes from the time of the last frame.

  • ui/video.test.ts (new): 8 tests cover the relayed/local choice and the socket address. They also cover the 2 s reconnect (including a silent replacement socket), reconnect after close, close, fps limiting and ignoring text messages.

bun test in Software/so101 gives 428 pass and 1 fail. The failure is server.test.ts "serves the model…", which expects /vendor/three/build/three.module.js to return 200 and got 404. It fails the same way with my change stashed, so I left it. bun x tsc --noEmit printed only a bun tempdir warning, no type errors. The first-visit size test passes.

🤖 Generated with Claude Code

Closes #140

1 earlier comment · 1 event
commented

When the page is relayed, it now draws each camera from WS /camera/<id>/ws, and it reopens the socket after 2 s without a frame. I haven't run it against a live relay or a preview.

  • ui/video.js (new):

- Loaded by dynamic import, so the first visit gets no heavier. It draws each binary frame as it arrives. - It reopens a socket that closes or errors after 500 ms, and ignores late frames from a replaced socket. - On a slow link it drops frames to the plan's fps. The socket has no ?fps= parameter, so that happens in the browser. - It exports cameraSource(relayed), the choice between the socket and the plain <img>. The page doesn't call it, because that would need a static import; only the test uses it.

  • viewer.html:

- Relayed cameras in stream mode use the socket. The <img src=/camera/<id>/stream> path and its onerror retry stay for the local case. - Snapshot mode is unchanged. The frozen-picture canvas check is skipped for socket cameras, and their "live" label comes from the time of the last frame.

  • ui/video.test.ts (new): 8 tests cover the relayed/local choice and the socket address. They also cover the 2 s reconnect (including a silent replacement socket), reconnect after close, close, fps limiting and ignoring text messages.

bun test in Software/so101 gives 428 pass and 1 fail. The failure is server.test.ts "serves the model…", which expects /vendor/three/build/three.module.js to return 200 and got 404. It fails the same way with my change stashed, so I left it. bun x tsc --noEmit printed only a bun tempdir warning, no type errors. The first-visit size test passes.

🤖 Generated with Claude Code

Changes requested — before the latest push

The reconnect logic in ui/video.js is sound and well tested. Three things stop it landing.

Fix first: cameraSource is exported and tested but the page never calls it, so it is dead code in production, and its test proves nothing about viewer.html. Delete it and its test. Better, make the page decide through a function the tests also exercise, or test the showCam branch directly.

The wiring in viewer.html is untested. Nothing fails if showCam stops calling startFeed, if the stale-mark guard breaks, or if the live-label line in the interval stops using lastFrame. Add a test that covers that wiring, for example by extracting the frame-to-img and blob-revoke step into video.js and testing it.

There is no README change. Say that relayed cameras are drawn from WS /camera/<id>/ws, that the socket reopens after 2 s without a frame, and that a local server keeps the plain MJPEG img.

The author says it was never run against the relay or the preview. Please try it on the preview and say what you saw. Also confirm that the one failing server.test.ts test (three.module.js returning 404) fails on main too, because the push is meant to be green.

commented

Pushed to #182 as 5febea5. I couldn't confirm the socket on the preview from here, so the page wiring is checked only by tests and by reading the page source.

Dead code. I deleted cameraSource and its test.

Untested wiring. The frame drawing, the live check and the guard against a stale load now live in src/ui/video.js:

  • drawFrame: sets the image to the new frame's object URL and revokes the previous one. It also records when the last frame arrived.
  • isLive: the "live" label for a socket camera.
  • attach: opens the socket only if the camera hasn't been shown, hidden or removed since the load began. viewer.html counts that with c.epoch, which replaces the old mark object.

video.test.ts covers all three. It also has page-source checks on viewer.html: the relayed branch calls startFeed, the local branch keeps the <img> stream, and video.attach and video.isLive are called. Another check confirms that show, hide and remove call stopFeed. These source checks are string matches, so they catch someone deleting the wiring but not a runtime fault in the page. 13 tests pass, and bun x tsc --noEmit shows no type errors.

README. Software/README.md now says relayed cameras are drawn from WS /camera/<id>/ws, the socket reopens after 2 s without a frame, and a local server keeps the plain MJPEG <img>.

server.test.ts failure. The three.module.js 404 test fails identically on origin/main: 52 pass and that one fails, against 50 pass and that one fails on this branch. It looks like the vendored three.js isn't installed in this sandbox, so I'd expect the forge's check to pass it. That is an inference, not something I verified.

Preview. Preview #182 serves the new build: the page links video.js and attach is in it. /cameras lists "Camera 1" and /camera/1/snapshot returns 200. The WebSocket is where I'm stuck. A Bun client to wss://…/camera/1/ws errored with zero frames. A raw upgrade request through this sandbox's proxy came back as HTTP/2 with a 404 JSON body. That may be the proxy dropping the upgrade rather than the app, since the relay route exists on main. So I never saw frames drawn or a reconnect in a browser. Someone with a browser should open the preview, watch the camera pane, and block the socket to see it reopen after about 2 s.

🤖 Generated with Claude Code

Approved

Approved. The relayed page now draws each camera from WS /camera/<id>/ws and reopens the socket after 2 s without a frame. The local server keeps the plain <img> stream. video.js loads only when a camera is first shown, so the first paint is unchanged. The socket address is built on the page origin with the id encoded. Late frames from a replaced socket are ignored. Blob URLs are revoked, and show, hide and remove all stop the feed. The tests would fail without the change, and the README covers it. Nothing is added to the terminal; this is a page-only rendering change.

I could not see frames in the preview. / answers 200 and the code reads right, but the WebSocket path was not exercised, and smith says the same.

Two things I would do next:

  1. Bandwidth on a slow link. Client-side maxFps drops frames after they are downloaded, so a phone on 4G still receives every frame. The old ?fps= on the stream limited the server. That is a regression for mobile #49/#50. Have the relay accept ?fps= on the socket, or ask the relay to send fewer frames.
  2. The wiring tests match strings in viewer.html. They catch deletion but not a runtime fault. Replace them with a small browser-run check when one exists. Also revoke c.blob in stopFeed or in the hidden branch of showCam, so one frame is not held while the pane is hidden.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs