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

Migrated from github.com/Trevato/SO-ARM100

Fast on a phone over 4G: first view under 2 s, the camera adapts to the connection, nothing loads until it is needed #69

Merged opened this in answer to

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

Merged

I've pushed the branch. I couldn't measure Lighthouse LCP/INP/CLS or take the Playwright screenshots the issue asks for: Chromium is installed but can't start in this sandbox (socket() failed: Operation not permitted). So there are no before/after Lighthouse numbers and no screenshots in this pull.

Notes

shipped merged

opened this

I've pushed the branch. I couldn't measure Lighthouse LCP/INP/CLS or take the Playwright screenshots the issue asks for: Chromium is installed but can't start in this sandbox (socket() failed: Operation not permitted). So there are no before/after Lighthouse numbers and no screenshots in this pull. What I did measure is below.

What a phone gets now

  • The camera starts as soon as the page's script runs. The relay writes the link mode and the camera list into the page as inert JSON (<script type="application/json" id="boot">, every < escaped). Before, the page asked six things one after another (/link, /limits, /settings, /poses, /model.json, /link again) before requesting the camera. Now the camera goes first and the other four go out at once. On a link with 150 ms round trips that is about 0.9 s off the first camera frame. That figure is worked out from the round-trip count, not measured.
  • One WebSocket. /live now also carries the arm's status. The relay reads it once per 200 ms tick for everyone and sends it only when it changes. A page with that socket open no longer polls /status; before, it polled 5 times a second, about 1.1 KB per answer. A page that opens later gets the last status straight away. Without /live (straight to an arm server), the page polls as before.
  • The camera follows the connection (src/ui/camera-plan.js). On a slow link (round trips over 400 ms, or the browser reporting 3G or a low downlink) the relay holds that one viewer's stream to 5 fps, or 2 fps when the browser asks to save data (/camera/<id>/stream?fps=1-30). Skipped frames are dropped whole, so the viewer always gets complete pictures. Snapshots are kept only for 2G or round trips over a second. The first frame already follows this, so a 3G phone starts at ?fps=5. A new Auto / Saver / Full button in the top bar overrides it, and the choice is kept in the browser. A hidden page (another tab, a locked phone) fetches no video at all.
  • Less up front. A new page gets the last 30 chat lines instead of up to 200; Earlier messages asks for 50 more at a time ({"type":"history","before":id}). The 3D-calibration panel (now src/ui/calibration.js) and /leader-map.js load only when they're used. First load went from 49.2 KB to 47.1 KB gzipped, and a new test in src/server.test.ts fails if it reaches 50 KB. The page answers in 6–7 ms locally.
  • Stop buttons. #60 had already hidden the second Stop on phones, but that left a phone driver no way to end a playback or a move except the E-stop: "Hold" goes through /torque, which the server refuses while something is driving. Now there is one Stop, the red E-stop. A second button appears only while a move, a playback, a recording or a park runs, labelled for what it ends (End playback, …), on every screen size. The space bar still works.

One test changed because it was checking the old design: the assertion in server.test.ts that pinned the CSS rule hiding #stop on phones. It now checks the new rule (the button starts hidden, is labelled for what it ends, and the page has exactly one "Stop").

How it was checked

  • The type check is clean, and 142 tests pass across the server, relay, lobby, camera-feed and src/ui suites. New tests cover the paged chat history, status pushes (sent once, again only on change, and to a page that opens later), the per-viewer frame rate, the boot JSON (escaping, gzip and plain), the new plan cases, the calibration rows and the first-load budget.
  • I ran the page's own script against the running app under linkedom, installed only in the temp dir. With no errors, it shows the camera, applies the pushed status, requests ?fps=5 on 3G, and loads older chat lines on request.

Left for later: shrinking the picture itself (resizing JPEGs needs a decoder, which means a dependency); sending the camera list over /live (it's still polled every 3 s); moving the rest of the Admin tab out of the first load; and the bottom-sheet and overlay redesign the issue points to.

To try it: open the PR preview on a phone, or in Chrome's device mode with "Slow 4G". The camera label should say "· 5 fps, slow link", and the top-bar button cycles Auto → Saver → Full. With a camera listed in /admin/camera-list, start a playback and the strip shows End playback next to the red Stop.

🤖 Generated with Claude Code

Closes #53

commented

I've pushed the branch. I couldn't measure Lighthouse LCP/INP/CLS or take the Playwright screenshots the issue asks for: Chromium is installed but can't start in this sandbox (socket() failed: Operation not permitted). So there are no before/after Lighthouse numbers and no screenshots in this pull. What I did measure is below.

What a phone gets now

  • The camera starts as soon as the page's script runs. The relay writes the link mode and the camera list into the page as inert JSON (<script type="application/json" id="boot">, every < escaped). Before, the page asked six things one after another (/link, /limits, /settings, /poses, /model.json, /link again) before requesting the camera. Now the camera goes first and the other four go out at once. On a link with 150 ms round trips that is about 0.9 s off the first camera frame. That figure is worked out from the round-trip count, not measured.
  • One WebSocket. /live now also carries the arm's status. The relay reads it once per 200 ms tick for everyone and sends it only when it changes. A page with that socket open no longer polls /status; before, it polled 5 times a second, about 1.1 KB per answer. A page that opens later gets the last status straight away. Without /live (straight to an arm server), the page polls as before.
  • The camera follows the connection (src/ui/camera-plan.js). On a slow link (round trips over 400 ms, or the browser reporting 3G or a low downlink) the relay holds that one viewer's stream to 5 fps, or 2 fps when the browser asks to save data (/camera/<id>/stream?fps=1-30). Skipped frames are dropped whole, so the viewer always gets complete pictures. Snapshots are kept only for 2G or round trips over a second. The first frame already follows this, so a 3G phone starts at ?fps=5. A new Auto / Saver / Full button in the top bar overrides it, and the choice is kept in the browser. A hidden page (another tab, a locked phone) fetches no video at all.
  • Less up front. A new page gets the last 30 chat lines instead of up to 200; Earlier messages asks for 50 more at a time ({"type":"history","before":id}). The 3D-calibration panel (now src/ui/calibration.js) and /leader-map.js load only when they're used. First load went from 49.2 KB to 47.1 KB gzipped, and a new test in src/server.test.ts fails if it reaches 50 KB. The page answers in 6–7 ms locally.
  • Stop buttons. #60 had already hidden the second Stop on phones, but that left a phone driver no way to end a playback or a move except the E-stop: "Hold" goes through /torque, which the server refuses while something is driving. Now there is one Stop, the red E-stop. A second button appears only while a move, a playback, a recording or a park runs, labelled for what it ends (End playback, …), on every screen size. The space bar still works.

One test changed because it was checking the old design: the assertion in server.test.ts that pinned the CSS rule hiding #stop on phones. It now checks the new rule (the button starts hidden, is labelled for what it ends, and the page has exactly one "Stop").

How it was checked

  • The type check is clean, and 142 tests pass across the server, relay, lobby, camera-feed and src/ui suites. New tests cover the paged chat history, status pushes (sent once, again only on change, and to a page that opens later), the per-viewer frame rate, the boot JSON (escaping, gzip and plain), the new plan cases, the calibration rows and the first-load budget.
  • I ran the page's own script against the running app under linkedom, installed only in the temp dir. With no errors, it shows the camera, applies the pushed status, requests ?fps=5 on 3G, and loads older chat lines on request.

Left for later: shrinking the picture itself (resizing JPEGs needs a decoder, which means a dependency); sending the camera list over /live (it's still polled every 3 s); moving the rest of the Admin tab out of the first load; and the bottom-sheet and overlay redesign the issue points to.

To try it: open the PR preview on a phone, or in Chrome's device mode with "Slow 4G". The camera label should say "· 5 fps, slow link", and the top-bar button cycles Auto → Saver → Full. With a camera listed in /admin/camera-list, start a playback and the strip shows End playback next to the red Stop.

🤖 Generated with Claude Code

Approved

Approved from the diff. I could not reach the preview from my sandbox (the proxy blocked it), so I did not try it on a phone. Nothing here is unusable by keyboard or on a small screen as far as the source shows.

What holds up:

  • Boot JSON is inert application/json with every "<" escaped, and a test covers it.
  • fps is parsed strictly to a whole number 1-30.
  • Frames are dropped whole per viewer.
  • Chat history is read-only and validates before.
  • Status is pushed only on change.
  • The first load has a 50 KB gzip test.
  • There is one Stop, and the second button is named for what it ends.

Two things to do next:

  1. Measure it. Run Lighthouse (LCP, CLS, INP) and take 360px screenshots on a machine where Chromium starts, and add the numbers to the issue. The 0.9 s saving is worked out, not measured.
  2. Check the "End playback" button for a screen reader and for focus. When #stop is toggled hidden and its label changes, either announce it (an aria-live region) or keep it in a stable place so keyboard users do not lose focus. Also make sure the Earlier messages button keeps focus on the first newly loaded line.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs