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
+52
View File
@@ -0,0 +1,52 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { FastifyBaseLogger } from "fastify";
import { CameraActivity } from "./camera-activity.js";
import { deviceEvents, type CameraActivityEvent } from "./device-events.js";
// Per-camera activity drives the booth tiles' snapshot→live switch: one "active" edge
// per run of pushes, re-armed by each push, one "idle" edge TTL after the last push.
const logger = { debug: vi.fn(), info: vi.fn(), warn: vi.fn() } as unknown as FastifyBaseLogger;
let seen: CameraActivityEvent[];
let off: () => void;
beforeEach(() => {
vi.useFakeTimers();
seen = [];
off = deviceEvents.onCameraActivity((e) => seen.push(e));
});
afterEach(() => {
off();
vi.useRealTimers();
});
describe("CameraActivity", () => {
it("emits active once, re-arms on each push, idles after the TTL", () => {
const a = new CameraActivity(logger, 30_000);
a.vehicleDetected("cam1");
vi.advanceTimersByTime(20_000);
a.vehicleDetected("cam1"); // re-arm
expect(seen).toEqual([{ deviceId: "cam1", active: true }]);
expect(a.snapshot()).toEqual(["cam1"]);
vi.advanceTimersByTime(29_000);
expect(seen).toHaveLength(1);
vi.advanceTimersByTime(1_000);
expect(seen).toEqual([
{ deviceId: "cam1", active: true },
{ deviceId: "cam1", active: false },
]);
expect(a.snapshot()).toEqual([]);
});
it("tracks cameras independently", () => {
const a = new CameraActivity(logger, 1_000);
a.vehicleDetected("entry");
vi.advanceTimersByTime(600);
a.vehicleDetected("exit");
vi.advanceTimersByTime(400);
expect(a.snapshot()).toEqual(["exit"]);
a.stop();
vi.advanceTimersByTime(5_000);
expect(seen.filter((e) => !e.active)).toEqual([{ deviceId: "entry", active: false }]);
});
});