39fb5fb7c2
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>
474 lines
20 KiB
TypeScript
474 lines
20 KiB
TypeScript
import type {
|
||
CameraDevice,
|
||
LiveStreamDevice,
|
||
LiveVideoSource,
|
||
ClockSyncResult,
|
||
DeviceHealth,
|
||
Snapshot,
|
||
SnapshotContext,
|
||
} from "../interfaces.js";
|
||
import type { CameraDriver, ConfigField, DeviceConfig } from "../registry.js";
|
||
import {
|
||
hostField,
|
||
passwordField,
|
||
portField,
|
||
usernameField,
|
||
stubLog,
|
||
} from "./common.js";
|
||
import { digestGet, digestRequest } from "./http-digest.js";
|
||
import { RtspMjpegStream } from "./rtsp-mjpeg.js";
|
||
|
||
// Camera drivers — entry/exit snapshot-on-event. The host pulls a still over
|
||
// HTTP when an event fires; the bytes are stored and referenced from the signed
|
||
// event as an independent fraud-control record (the camera PULLS, it never pushes
|
||
// to us). Hikvision (ISAPI) and Dahua (CGI) differ in the snapshot URL, the
|
||
// channel encoding and the clock endpoint. Both use HTTP Digest auth (see ./http-digest.ts).
|
||
//
|
||
// VERIFIED on hardware (2026-09-17): a Dahua IPC-HFW2549T-AS-IL (fw 2.880) at
|
||
// 10.0.10.11 returns a 2880×1620 JPEG from /cgi-bin/snapshot.cgi?channel=1 —
|
||
// and HTTP 400 for channel=0. See wiki/entities/dahua-ipc-hfw2549t.md.
|
||
//
|
||
// VERIFIED on hardware (2026-06-15): a Hikvision unit at 10.0.10.121 returns a
|
||
// 2688×1520 JPEG from /ISAPI/Streaming/channels/101/picture with Digest auth.
|
||
// See wiki/entities/lpr-camera.md.
|
||
|
||
const DEFAULT_TIMEOUT_MS = 8000;
|
||
|
||
// Hikvision returns HTTP 503 (statusCode 2 / "Device Busy" / subStatus deviceBusy) —
|
||
// and occasionally 500 — when its snapshot encoder is momentarily occupied (another
|
||
// snapshot in flight, a stream starting, on-camera VCA). It is TRANSIENT: a retry a
|
||
// few hundred ms later succeeds. The newer G3H sensors (e.g. DS-2CD1047G3H) hit it
|
||
// more readily. So a standalone capture retries a few times before giving up; we do
|
||
// NOT retry config errors (401 auth, 404 path/channel) — those won't self-heal.
|
||
// (Concurrent same-camera hits are separately de-duped by captureSnapshotShared in
|
||
// the server.) See wiki/entities/lpr-camera.md ("503 Device Busy").
|
||
const SNAPSHOT_RETRY_STATUSES = new Set([500, 503]);
|
||
const SNAPSHOT_MAX_ATTEMPTS = 4;
|
||
const SNAPSHOT_RETRY_BASE_MS = 250;
|
||
|
||
const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
|
||
|
||
/** Coarse, STABLE size label for the health-check detail: nearest power-of-two KB
|
||
* (`≈16 KB`, `≈256 KB`). JPEG frame size varies with every frame, and the device
|
||
* monitor logs + re-emits a status whenever the detail string changes — an exact
|
||
* byte count made every healthy camera "change" on nearly every poll, spamming the
|
||
* rotated container logs. A pow-2 bucket keeps the diagnostic value (a suddenly
|
||
* tiny frame still shows) while flapping only on a real scene/stream shift. */
|
||
function sizeBucket(bytes: number): string {
|
||
const kb = bytes / 1024;
|
||
if (kb < 1) return "<1 KB"; // empty-ish 200 body — suspicious, worth seeing as-is
|
||
const pow = Math.round(Math.log2(kb));
|
||
return `≈${2 ** pow} KB`;
|
||
}
|
||
|
||
class HttpCamera implements CameraDevice {
|
||
readonly #host: string;
|
||
readonly #port: number;
|
||
readonly #user: string;
|
||
readonly #password: string;
|
||
readonly #channel: number;
|
||
/** Hikvision stream within the channel: 1 = main (high-res), 2 = sub (lighter).
|
||
* Some models (e.g. the G3H) keep the MAIN encoder saturated and return a
|
||
* persistent 503 deviceBusy on the main-stream snapshot, while the sub-stream
|
||
* serves fine — so this is selectable. Ignored by drivers (Dahua) that don't
|
||
* encode a stream in the path. See wiki/entities/lpr-camera.md ("503 Device Busy"). */
|
||
readonly #stream: number;
|
||
readonly #timeout: number;
|
||
// Source outbound from the device-facing NIC on a multi-homed host (the
|
||
// multi-subnet source-address trap — see wiki/concepts/wsl-dev-networking.md).
|
||
readonly #localAddress: string | undefined;
|
||
/** RTSP port for the live view (not a Setup field: 554 everywhere so far). */
|
||
readonly #rtspPort: number;
|
||
|
||
constructor(
|
||
readonly driverId: string,
|
||
config: DeviceConfig,
|
||
/** Builds the snapshot path from the configured channel + stream (1=main, 2=sub). */
|
||
private readonly snapshotPath: (channel: number, stream: number) => string,
|
||
) {
|
||
this.#host = String(config.host);
|
||
this.#port = Number(config.port ?? 80);
|
||
this.#user = String(config.username ?? "");
|
||
this.#password = String(config.password ?? "");
|
||
this.#channel = Number(config.channel ?? 1);
|
||
// 1 = main, 2 = sub. Clamp to those two; default main for back-compat.
|
||
this.#stream = Number(config.stream) === 2 ? 2 : 1;
|
||
this.#timeout = Number(config.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
||
this.#localAddress = config.localAddress
|
||
? String(config.localAddress)
|
||
: undefined;
|
||
this.#rtspPort = Number(config.rtspPort ?? 554);
|
||
}
|
||
|
||
async connect(): Promise<void> {}
|
||
async disconnect(): Promise<void> {}
|
||
|
||
async healthCheck(): Promise<DeviceHealth> {
|
||
// The only honest liveness probe for a snapshot camera is to actually pull a
|
||
// frame: it exercises reachability + auth + the path/channel in one shot.
|
||
try {
|
||
const res = await this.#get();
|
||
if (res.status === 200)
|
||
return { status: "ready", detail: `snapshot ${sizeBucket(res.body.length)}` };
|
||
if (res.status === 401)
|
||
return {
|
||
status: "degraded",
|
||
detail: "auth rejected (check username/password)",
|
||
};
|
||
return { status: "degraded", detail: `HTTP ${res.status}` };
|
||
} catch (err) {
|
||
return { status: "offline", detail: (err as Error).message };
|
||
}
|
||
}
|
||
|
||
async captureSnapshot(ctx: SnapshotContext): Promise<Snapshot> {
|
||
// Retry transient "Device Busy" (503/500); a config error (401/404) fails fast.
|
||
let res = await this.#get();
|
||
for (
|
||
let attempt = 1;
|
||
res.status !== 200 &&
|
||
SNAPSHOT_RETRY_STATUSES.has(res.status) &&
|
||
attempt < SNAPSHOT_MAX_ATTEMPTS;
|
||
attempt++
|
||
) {
|
||
// Linear backoff (250/500/750ms) — the encoder frees within a frame or two.
|
||
await sleep(SNAPSHOT_RETRY_BASE_MS * attempt);
|
||
stubLog(
|
||
this.driverId,
|
||
`captureSnapshot ${ctx.direction} retry ${attempt} (was HTTP ${res.status})`,
|
||
);
|
||
res = await this.#get();
|
||
}
|
||
if (res.status !== 200) {
|
||
// Name the busy case so the operator/telemetry can tell "camera busy" from a
|
||
// real fault (offline / auth / wrong path).
|
||
const busy = SNAPSHOT_RETRY_STATUSES.has(res.status)
|
||
? " (device busy)"
|
||
: "";
|
||
throw new Error(
|
||
`${this.driverId} snapshot failed (${ctx.direction}): HTTP ${res.status}${busy}`,
|
||
);
|
||
}
|
||
// Per-snapshot chatter → debug (a busy lane logs one every few seconds); the retry
|
||
// and failure lines above stay at info/throw.
|
||
stubLog(this.driverId, `captureSnapshot ${ctx.direction} (${res.body.length} bytes)`, "debug");
|
||
return {
|
||
bytes: res.body,
|
||
contentType: res.contentType || "image/jpeg",
|
||
capturedAt: new Date().toISOString(),
|
||
};
|
||
}
|
||
|
||
#get() {
|
||
return digestGet({
|
||
host: this.#host,
|
||
port: this.#port,
|
||
path: this.snapshotPath(this.#channel, this.#stream),
|
||
user: this.#user,
|
||
password: this.#password,
|
||
timeoutMs: this.#timeout,
|
||
localAddress: this.#localAddress,
|
||
});
|
||
}
|
||
|
||
/** An RTSP MJPEG session on `path` with this camera's address + credentials. */
|
||
protected rtspStream(path: string): LiveVideoSource {
|
||
return new RtspMjpegStream({
|
||
host: this.#host,
|
||
port: this.#rtspPort,
|
||
path,
|
||
user: this.#user,
|
||
password: this.#password,
|
||
timeoutMs: this.#timeout,
|
||
...(this.#localAddress ? { localAddress: this.#localAddress } : {}),
|
||
});
|
||
}
|
||
|
||
protected get channel(): number {
|
||
return this.#channel;
|
||
}
|
||
|
||
/** Digest request against an arbitrary device path (ISAPI / CGI config reads+writes). */
|
||
protected deviceRequest(method: "GET" | "PUT", path: string, body?: string) {
|
||
return digestRequest({
|
||
host: this.#host,
|
||
port: this.#port,
|
||
path,
|
||
method,
|
||
body,
|
||
user: this.#user,
|
||
password: this.#password,
|
||
timeoutMs: this.#timeout,
|
||
localAddress: this.#localAddress,
|
||
});
|
||
}
|
||
}
|
||
|
||
// --- Hikvision clock sync (ISAPI /System/time) ---------------------------------
|
||
// These cameras lose their clock on a power cut (no/dead RTC battery): they reboot
|
||
// at the 1970 epoch and stay there until a human logs into the web UI (which
|
||
// silently pushes the browser clock). A wrong camera clock corrupts the OSD
|
||
// timestamp burned into every snapshot — the evidence trail — and the times on
|
||
// ANPR pushes. So the host (the site's time authority — offline-first, no NTP
|
||
// dependency) re-syncs the camera over the same Digest-auth ISAPI used for
|
||
// snapshots. The device monitor calls this at the offline→ready edge (the
|
||
// power-restored moment), a daily backstop, and whenever the site's UTC offset
|
||
// changes (DST). See wiki/entities/lpr-camera.md.
|
||
//
|
||
// TIME ZONE: the OSD shows the camera's LOCAL time = instant + its `timeZone` setting.
|
||
// park-2 (2026-10-09) ran both cameras on the factory CST-8 (Beijing): the instant was
|
||
// right, the burned-in time six hours off, and a correct-instant sync never touched it.
|
||
// This firmware (DS-2CD1047G3H) also ignores the DST rule in a POSIX-style zone string
|
||
// ("CET-1:00:00DST01:00:00,M3.5.0/02:00:00,M10.5.0/03:00:00" was accepted, echoed back,
|
||
// and NOT applied — OSD stayed on +01:00 in October). So the host owns DST too: the zone
|
||
// is written as a FIXED offset equal to the site's CURRENT offset ("CST-2:00:00" in summer,
|
||
// "CST-1:00:00" in winter — Hikvision's inverted POSIX sign) and rewritten at the next
|
||
// sync after the site's offset changes. The abbreviation is cosmetic (the camera renames
|
||
// whatever we send to "CST").
|
||
|
||
/** The Hikvision `timeZone` string for a FIXED offset equal to `localIso`'s UTC offset:
|
||
* "+02:00" → "CST-2:00:00", "-05:30" → "CST+5:30:00", "+00:00" → "CST0:00:00". */
|
||
export function hikvisionFixedZone(localIso: string): string {
|
||
const m = localIso.match(/([+-])(\d{2}):(\d{2})$/);
|
||
if (!m) throw new Error(`syncClock: host time has no utc offset: ${localIso}`);
|
||
const hours = Number(m[2]);
|
||
const minutes = m[3];
|
||
if (hours === 0 && minutes === "00") return "CST0:00:00";
|
||
// POSIX (and Hikvision) sign is inverted: east of UTC is negative.
|
||
const sign = m[1] === "+" ? "-" : "+";
|
||
return `CST${sign}${hours}:${minutes}:00`;
|
||
}
|
||
|
||
class HikvisionCamera extends HttpCamera implements LiveStreamDevice {
|
||
/**
|
||
* Live view for the booth's camera tiles: the channel's SUB-stream (x02) over RTSP,
|
||
* which must be set to MJPEG on the camera (H.264 is refused with that reason).
|
||
* The ANPR/evidence stills keep coming from /picture on the configured stream —
|
||
* the codec of the sub-stream does not change them (measured on park-lab
|
||
* 2026-11-17: no extra 503s with a stream open). See wiki/decisions/camera-live-view.md.
|
||
*/
|
||
openLiveStream(): LiveVideoSource {
|
||
return this.rtspStream(`/Streaming/Channels/${this.channel}02`);
|
||
}
|
||
|
||
/**
|
||
* Read the camera clock + zone. Rewrite the zone when it is not the site's current
|
||
* fixed offset (see above); otherwise set the clock only when it drifts more than
|
||
* `maxDriftSec` from `localIso` (the site's wall-clock now, WITH utc offset). The PUT
|
||
* always carries both: `localIso`'s explicit offset makes the instant unambiguous
|
||
* regardless of the zone the camera applies to it.
|
||
*/
|
||
async syncClock(localIso: string, maxDriftSec: number): Promise<ClockSyncResult> {
|
||
const read = await this.deviceRequest("GET", "/ISAPI/System/time");
|
||
if (read.status !== 200) {
|
||
throw new Error(`clock read failed: HTTP ${read.status}`);
|
||
}
|
||
const xml = read.body.toString("utf8");
|
||
const cameraTime = xml.match(/<localTime>([^<]+)<\/localTime>/)?.[1]?.trim() ?? null;
|
||
const timeZone = xml.match(/<timeZone>([^<]+)<\/timeZone>/)?.[1]?.trim() ?? "";
|
||
const wantZone = hikvisionFixedZone(localIso);
|
||
const zoneChanged = timeZone !== wantZone;
|
||
|
||
// Drift: parse both sides as instants. A camera reply without a UTC offset (or
|
||
// otherwise unparseable) can't be trusted → treat as infinite drift and sync.
|
||
const cameraMs = cameraTime ? Date.parse(cameraTime) : NaN;
|
||
const hostMs = Date.parse(localIso);
|
||
const driftSeconds = Number.isFinite(cameraMs)
|
||
? Math.round(Math.abs(hostMs - cameraMs) / 1000)
|
||
: null;
|
||
if (!zoneChanged && driftSeconds != null && driftSeconds <= maxDriftSec) {
|
||
return { driftSeconds, synced: false, zoneChanged: false, timeZone };
|
||
}
|
||
|
||
const body =
|
||
`<?xml version="1.0" encoding="UTF-8"?>` +
|
||
`<Time><timeMode>manual</timeMode><localTime>${localIso}</localTime>` +
|
||
`<timeZone>${wantZone}</timeZone>` +
|
||
`</Time>`;
|
||
const put = await this.deviceRequest("PUT", "/ISAPI/System/time", body);
|
||
if (put.status !== 200) {
|
||
throw new Error(`clock set failed: HTTP ${put.status}`);
|
||
}
|
||
stubLog(
|
||
this.driverId,
|
||
`clock synced (was ${driftSeconds ?? "unparseable"}s off${zoneChanged ? `; zone ${timeZone || "unset"} → ${wantZone}` : ""})`,
|
||
);
|
||
return { driftSeconds, synced: true, zoneChanged, timeZone: wantZone };
|
||
}
|
||
}
|
||
|
||
// --- Dahua clock sync (CGI global.cgi getCurrentTime / setCurrentTime) --------------
|
||
// Same problem, different surface. The Dahua CGI reads and writes the clock as a
|
||
// NAIVE local wall-time string ("2026-09-17 10:35:49", no offset) in whatever time
|
||
// zone / DST the camera is configured for. We deliberately write the HOST's local
|
||
// wall time verbatim: what must match the booth is the OSD timestamp burned into
|
||
// every snapshot and the event times, i.e. the wall clock — not the camera's idea
|
||
// of UTC. (The bench unit ran a year-round UTC+1 with DST off and NTP off; after
|
||
// this sync its OSD read the booth's time.) VERIFIED on hardware 2026-09-17:
|
||
// setCurrentTime answers 200 "OK" and getCurrentTime reads the new value back.
|
||
// See wiki/entities/dahua-ipc-hfw2549t.md.
|
||
|
||
const DAHUA_TIME_PATH = "/cgi-bin/global.cgi?action=getCurrentTime";
|
||
|
||
/** "2026-09-17T10:35:49+02:00" (host localIso, WITH offset) → "2026-09-17 10:35:49"
|
||
* (the naive wall time the Dahua CGI speaks). */
|
||
function naiveWallTime(localIso: string): string {
|
||
const m = localIso.match(/^(\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2}:\d{2})/);
|
||
if (!m) throw new Error(`syncClock: unparseable host time ${localIso}`);
|
||
return `${m[1]} ${m[2]}`;
|
||
}
|
||
|
||
/** Parse a naive "YYYY-MM-DD HH:MM:SS" as an instant in the HOST's zone — both sides
|
||
* of the drift comparison go through this, so the zone cancels out. */
|
||
function naiveMs(naive: string): number {
|
||
return Date.parse(naive.replace(" ", "T"));
|
||
}
|
||
|
||
class DahuaCamera extends HttpCamera {
|
||
async syncClock(localIso: string, maxDriftSec: number): Promise<ClockSyncResult> {
|
||
const read = await this.deviceRequest("GET", DAHUA_TIME_PATH);
|
||
if (read.status !== 200) {
|
||
throw new Error(`clock read failed: HTTP ${read.status}`);
|
||
}
|
||
// Reply body: "result=2026-09-17 09:35:51"
|
||
const cameraNaive =
|
||
read.body.toString("utf8").match(/result=(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/)?.[1] ?? null;
|
||
const hostNaive = naiveWallTime(localIso);
|
||
|
||
const cameraMs = cameraNaive ? naiveMs(cameraNaive) : NaN;
|
||
const driftSeconds = Number.isFinite(cameraMs)
|
||
? Math.round(Math.abs(naiveMs(hostNaive) - cameraMs) / 1000)
|
||
: null;
|
||
if (driftSeconds != null && driftSeconds <= maxDriftSec) {
|
||
return { driftSeconds, synced: false };
|
||
}
|
||
|
||
const set = await this.deviceRequest(
|
||
"GET",
|
||
`/cgi-bin/global.cgi?action=setCurrentTime&time=${encodeURIComponent(hostNaive)}`,
|
||
);
|
||
// Dahua answers 200 with a body of "OK"; a refused write is a non-200 or "Error".
|
||
if (set.status !== 200 || !/^OK/.test(set.body.toString("utf8").trim())) {
|
||
throw new Error(
|
||
`clock set failed: HTTP ${set.status} ${set.body.toString("utf8").trim().slice(0, 40)}`,
|
||
);
|
||
}
|
||
stubLog(this.driverId, `clock synced (was ${driftSeconds ?? "unparseable"}s off)`);
|
||
return { driftSeconds, synced: true };
|
||
}
|
||
}
|
||
|
||
const channelField: ConfigField = {
|
||
key: "channel",
|
||
label: "Channel",
|
||
type: "number",
|
||
required: false,
|
||
default: 1,
|
||
};
|
||
|
||
// Hikvision stream-within-channel for the snapshot: main (01) is full-res; sub (02)
|
||
// is lighter. Default MAIN (back-compat). Switch to SUB when the main encoder is
|
||
// saturated and returns a persistent 503 deviceBusy (seen on DS-2CD1047G3H-LIU) —
|
||
// the sub-stream is also the better fit for snapshot/ANPR (smaller, faster, doesn't
|
||
// contend with live-view/recording). See wiki/entities/lpr-camera.md.
|
||
const streamField: ConfigField = {
|
||
key: "stream",
|
||
label: "Snapshot stream",
|
||
type: "select",
|
||
required: false,
|
||
default: "1",
|
||
options: [
|
||
{ value: "1", label: "Main (01)" },
|
||
{ value: "2", label: "Sub (02)" },
|
||
],
|
||
};
|
||
|
||
// Dahua has no stream selector (its CGI snapshot isn't stream-encoded in the path).
|
||
const cameraConfigFields = [
|
||
hostField,
|
||
portField(80),
|
||
usernameField,
|
||
passwordField,
|
||
channelField,
|
||
];
|
||
const hikvisionConfigFields = [...cameraConfigFields, streamField];
|
||
|
||
// Hikvision "Alarm Server" PUSH config. The newer firmware (Event → Smart/VCA →
|
||
// "Detection Target: Human/Vehicle", Notify Surveillance Center, Alarm Settings →
|
||
// Alarm Server) HTTP-POSTs an EventNotificationAlert to a URL we host every time the
|
||
// chosen target is detected — same shape as the Dingtian Input Link push. When enabled,
|
||
// the admin points the camera's Alarm Server at /api/devices/hikvision/:deviceId/event
|
||
// and we record what it sends. See routes/hikvision-alarm.ts, wiki/entities/lpr-camera.md.
|
||
const alarmPushFields: ConfigField[] = [
|
||
{
|
||
key: "alarmPushEnabled",
|
||
label: "Alarm Server push (Event → vehicle)",
|
||
type: "boolean",
|
||
required: false,
|
||
default: false,
|
||
help: "The camera POSTs each detected event to us (set its Alarm Settings → Alarm Server to this backend). No polling.",
|
||
},
|
||
{
|
||
key: "pushUser",
|
||
label: "Alarm push username (optional)",
|
||
type: "string",
|
||
required: false,
|
||
help: "Only if the camera's Alarm Server is set to authenticate (HTTP Digest). Leave blank to accept by source-IP only.",
|
||
},
|
||
{
|
||
key: "pushPassword",
|
||
label: "Alarm push password (optional)",
|
||
type: "secret",
|
||
required: false,
|
||
help: "Paired with the username above for Digest auth on the push. Leave blank for source-IP-only.",
|
||
},
|
||
{
|
||
key: "skipSourceIpCheck",
|
||
label: "Don't verify push source IP",
|
||
type: "boolean",
|
||
required: false,
|
||
default: false,
|
||
help: "Accept pushes regardless of the source IP. Needed when the network rewrites the inbound source address (e.g. WSL mirrored mode reports the host's own IP, not the camera's), which would otherwise reject every push. Leave OFF on a normal LAN.",
|
||
},
|
||
];
|
||
|
||
export const hikvisionDriver: CameraDriver = {
|
||
id: "hikvision",
|
||
category: "camera",
|
||
label: "Hikvision camera",
|
||
description:
|
||
"Hikvision snapshot via ISAPI (HTTP Digest) + optional Alarm Server event push.",
|
||
transports: ["tcp-ip"],
|
||
// The camera PULLS snapshots, but with Alarm Server on it ALSO pushes events to us —
|
||
// so it may need the backend push IP at assign time (like the Dingtian).
|
||
pushesToBackend: true,
|
||
configFields: [...hikvisionConfigFields, ...alarmPushFields],
|
||
// ISAPI channel id: <channel><stream>, e.g. ch1 main = 101, ch1 sub = 102, ch2 main = 201.
|
||
// stream 1 → "01" (main), 2 → "02" (sub).
|
||
create: (c) =>
|
||
new HikvisionCamera(
|
||
"hikvision",
|
||
c,
|
||
(ch, stream) => `/ISAPI/Streaming/channels/${ch}0${stream}/picture`,
|
||
),
|
||
};
|
||
|
||
export const dahuaDriver: CameraDriver = {
|
||
id: "dahua",
|
||
category: "camera",
|
||
label: "Dahua camera",
|
||
description: "Dahua snapshot via CGI (HTTP Digest) + clock sync.",
|
||
transports: ["tcp-ip"],
|
||
configFields: cameraConfigFields,
|
||
// snapshot.cgi channels are 1-BASED, exactly as the admin enters them (only Dahua's
|
||
// configManager TABLES are 0-indexed — the earlier `ch - 1` here drew a permanent
|
||
// HTTP 400 on real hardware, 2026-09-17). No stream in the path: `subtype` is
|
||
// ignored by snapshot.cgi, the still always comes off the main stream.
|
||
create: (c) =>
|
||
new DahuaCamera(
|
||
"dahua",
|
||
c,
|
||
(ch) => `/cgi-bin/snapshot.cgi?channel=${Math.max(1, ch)}`,
|
||
),
|
||
};
|