Skip to content

Record phone video into experiment directories - #58

Merged
mcroomp merged 3 commits into
mainfrom
experiment-video
Nov 18, 2026
Merged

mcroomp merged 3 commits into
mainfrom
experiment-video

Conversation

@mcroomp

@mcroomp mcroomp commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Lets phones record video for experiments. Each recording is saved in the experiment's directory, next to experiment.txt and mavlog.json.

How it works

  • serve --https-port also serves LinkHub over HTTPS. Phone browsers only allow camera access over HTTPS. The self-signed certificate is kept in <data-dir>/tls/ and is only regenerated when the LAN address changes, so each phone accepts the certificate warning once.
  • run_linkhub_ui.cmd now listens on 0.0.0.0 with HTTPS on port 9443.
  • Phones register independently of experiments. 📷 Cameras in the header shows how many phones are connected and opens a QR code for https://<lan-ip>:9443/camera. On the phone, tap Enable camera once and leave the page open. After that, a reload reconnects without a tap.
  • The phone page checks in with POST /v1/camera/{device}/heartbeat every 1.5 s, and the reply says whether an experiment is running. The phone starts recording when an experiment starts and finishes the file when it stops. It then waits for the next experiment.
  • Disconnect on the phone finishes and uploads any recording, releases the camera, and removes the phone's registration with DELETE /v1/camera/{device}. It then closes the page, or shows a Disconnected screen with Reconnect if the browser won't close it.
  • Recordings upload as ordered 2 s chunks to POST /v1/experiment/{id}/video/{stream}?seq=N. Each recording gets its own file, video-<device>-<rand>.webm or .mp4, which grows as chunks arrive. Repeated chunks are acknowledged without being written again, so phones can retry; a gap in the sequence returns 409. The final chunk is accepted for up to 120 s after stop.

Testing

  • cargo test --workspace and cargo fmt --check pass. Tests cover phone registration and heartbeat, the camera status endpoint, ordered chunk appends and TLS host detection.
  • npm run build passes.
  • Live server check: a browser tab acting as a phone, with a synthetic canvas video standing in for the camera, enabled once. It then automatically recorded two experiments in a row; each directory got its own finished video-*.webm. The header showed "📷 1 camera".
  • Disconnect during a running experiment: the recording was saved and marked finished, the registration was removed, and the tab closed.
  • Not yet tested with a real phone.

Base automatically changed from experiment-workflow to main November 18, 2026 09:26
LinkHub optionally serves HTTPS with a persisted self-signed certificate so phone browsers can use the camera. Start Experiment shows a QR code for a phone recording page that uploads ordered MediaRecorder chunks into video-<stream>.<ext> in the experiment directory; stopping the experiment ends every phone recording.
Phones enable the camera once and send heartbeats; the page starts recording whenever an experiment is active and finalizes it on stop, then waits for the next one. The UI camera button is always available and shows connected phones.
Disconnect finishes and uploads any recording, releases the camera, removes the registration via DELETE /v1/camera/{device}, and closes the page or shows a disconnected screen.
@mcroomp
mcroomp merged commit 4d73c84 into main Nov 18, 2026
12 of 13 checks passed
@mcroomp
mcroomp deleted the experiment-video branch November 18, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant