feat(cameras): booth camera tiles — latest snapshot at rest, live video while a vehicle is in view

Footer camera chips open/close a tile per camera (bottom right, ~15% wide, stacking
leftwards); the open set is a per-user preference (users.open_cameras). A tile shows the
camera's newest entry/exit snapshot and switches to live video while that camera pushes
vehicle events (per-camera activity, same 30 s TTL as lane status).

- devices: RTSP MJPEG client + RFC 2435 RTP/JPEG reassembly; Hikvision openLiveStream()
  on the sub-stream (x02, must be MJPEG — H.264 is refused with that reason)
- server: CameraLiveHub (one shared upstream per camera, latest-frame delivery, fps cap,
  linger, backoff), CameraActivity, /api/cameras/:id/latest-snapshot, WS
  /api/cameras/:id/live (shared handshake auth with /api/ws + device:read),
  PUT /api/auth/open-cameras, migration 0033 (open_cameras + snapshot device/time index)
- web: CameraDock, footer toggles, binary frames in the platform socket (Tauri too)
- .gitattributes: *.jpg / *.bin binary (byte-exact test fixtures)

Verified on park-lab cameras end to end and in headless Firefox.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 12:48:50 +01:00
parent b6f7ea65a4
commit 39fb5fb7c2
36 changed files with 2067 additions and 45 deletions
+33
View File
@@ -94,6 +94,8 @@ export interface SessionUser {
theme: Theme;
/** Preferred UI font scale, percent of base (100 = base; clamped 80–160). */
fontScale: number;
/** Booth camera tiles left open (camera device ids, opening order). */
openCameras: string[];
/** Optional display name (profile metadata); null if unset. */
fullName: string | null;
/** Optional contact email (profile metadata); null if unset. */
@@ -156,6 +158,37 @@ export function setFontScalePref(fontScale: number): Promise<{ fontScale: number
return apiFetch("/api/auth/font-scale", { method: "PUT", body: JSON.stringify({ fontScale }) });
}
/** Persist which booth camera tiles are open (restored on next login). */
export function setOpenCamerasPref(openCameras: string[]): Promise<{ openCameras: string[] }> {
return apiFetch("/api/auth/open-cameras", { method: "PUT", body: JSON.stringify({ openCameras }) });
}
/** The newest entry/exit snapshot a camera captured (a camera tile's resting picture). */
export interface CameraSnapshotMeta {
id: string;
direction: "entry" | "exit";
capturedAt: string;
}
/** Latest snapshot metadata for a camera, or null when it has none yet. */
export async function fetchLatestCameraSnapshot(deviceId: string): Promise<CameraSnapshotMeta | null> {
try {
return await apiFetch<CameraSnapshotMeta>(`/api/cameras/${encodeURIComponent(deviceId)}/latest-snapshot`);
} catch (err) {
if (err instanceof ApiError && err.status === 404) return null;
throw err;
}
}
/** Snapshot bytes as an object URL. Fetched (not an <img src>) so it works in the
* desktop shell too, whose webview does not carry the session cookie. The caller
* revokes the URL. */
export async function fetchSnapshotObjectUrl(id: string): Promise<string> {
const res = await platformFetch(apiUrl(`/api/snapshots/${encodeURIComponent(id)}`), { credentials: "include" });
if (!res.ok) throw new ApiError(`/api/snapshots/${id}: ${res.status}`, res.status);
return URL.createObjectURL(await res.blob());
}
/** Edit MY own profile (display name / email). Returns the refreshed session.
* Self-service — touches only the signed-in user; no `user:*` permission needed. */
export function updateMyProfile(patch: {