@camstack/addon-provider-onvif 1.2.108 → 1.2.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/addon.js CHANGED
@@ -5363,7 +5363,7 @@ var ZodIssueCode = {
5363
5363
  var ZodFirstPartyTypeKind;
5364
5364
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5365
5365
  //#endregion
5366
- //#region ../types/dist/sleep-BDR76Ykr.mjs
5366
+ //#region ../types/dist/sleep-B1y0Fo1U.mjs
5367
5367
  /**
5368
5368
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5369
5369
  * window to float samples (D455).
@@ -28886,14 +28886,81 @@ DeviceType.Camera, method(object({ deviceId: number() }), PrivacyMaskOptionsSche
28886
28886
  kind: "mutation",
28887
28887
  auth: "admin"
28888
28888
  });
28889
+ /**
28890
+ * What a preset id DOES on this camera.
28891
+ *
28892
+ * On several PTZ firmwares the preset namespace is shared: low ids are stored
28893
+ * positions, a reserved band triggers camera FUNCTIONS. The dispensa camera
28894
+ * (Hikvision) returns its own reserved band in the preset list, named by the
28895
+ * firmware:
28896
+ *
28897
+ * 34 Back to origin · 39 Day mode · 40 Night mode · 46 Day/Night Auto Mode
28898
+ * 92 Set manual limits · 93 Save manual limits · 94 Remote reboot
28899
+ * 95 Call OSD menu
28900
+ *
28901
+ * We used to hand all of these to the UI as ordinary presets. Saving over one
28902
+ * is what produced `PUT /ISAPI/PTZCtrl/channels/1/presets/34 -> HTTP 500`: the
28903
+ * camera refusing to let "Back to origin" be overwritten, surfaced to the
28904
+ * operator as a transport failure.
28905
+ *
28906
+ * A function preset stays fully usable as a DESTINATION -- `goToPreset('34')`
28907
+ * is the single most useful thing that camera can do. Only `savePreset` and
28908
+ * `deletePreset` are gated.
28909
+ */
28910
+ var PtzPresetFunctionSchema = _enum([
28911
+ "home",
28912
+ "day-mode",
28913
+ "night-mode",
28914
+ "day-night-auto",
28915
+ "set-limits",
28916
+ "save-limits",
28917
+ "reboot",
28918
+ "osd-menu"
28919
+ ]);
28889
28920
  var PtzPresetSchema = object({
28890
28921
  id: string(),
28891
- name: string()
28922
+ name: string(),
28923
+ /**
28924
+ * The firmware function this id performs, when the provider KNOWS the id is
28925
+ * reserved. `null` = an ordinary stored position, OR a reserved id this
28926
+ * provider does not recognise -- the two are told apart by `writable`.
28927
+ */
28928
+ fn: PtzPresetFunctionSchema.nullable(),
28929
+ /**
28930
+ * Whether `savePreset` / `deletePreset` may target this id. A provider sets
28931
+ * it false only for a band it KNOWS is reserved; where the firmware is not
28932
+ * documented it stays true and a refusal comes from the camera, named.
28933
+ */
28934
+ writable: boolean()
28892
28935
  });
28936
+ /**
28937
+ * Where the head is pointing -- per axis, and `null` when the driver cannot
28938
+ * read it.
28939
+ *
28940
+ * It used to be three REQUIRED numbers, which left a provider that cannot read
28941
+ * position no way to say so. All four said `0`:
28942
+ *
28943
+ * reolink `return { pan: 0, tilt: 0, zoom: 0 }` "until a position-query
28944
+ * path lands upstream"
28945
+ * hikvision stub, "firmware-dependent and frequently absent"
28946
+ * amcrest stub, "no generic absolute-position read for this model family"
28947
+ * onvif throws
28948
+ *
28949
+ * So every consumer asking where a camera points was told "perfectly centred"
28950
+ * by four cameras that had never looked. That is D393 -- a measurement that
28951
+ * FAILED is `null`, never `0`, and the type says so all the way to the
28952
+ * decision -- the same shape as the unreadable `statfs` folded into "0 bytes of
28953
+ * headroom", which evacuated a healthy disk.
28954
+ *
28955
+ * D393 also says to check for a narrower structural TWIN of the result type.
28956
+ * There is one: `PtzStatusSchema` extends this, so the lie had already
28957
+ * propagated into `getStatus`, which is the surface `getPosition`'s own comment
28958
+ * tells callers to migrate to.
28959
+ */
28893
28960
  var PtzPositionSchema = object({
28894
- pan: number(),
28895
- tilt: number(),
28896
- zoom: number()
28961
+ pan: number().nullable(),
28962
+ tilt: number().nullable(),
28963
+ zoom: number().nullable()
28897
28964
  });
28898
28965
  var PtzMoveCommandSchema = object({
28899
28966
  pan: number().optional(),
@@ -28915,7 +28982,72 @@ var PtzOptionsSchema = object({
28915
28982
  maxPresets: number().optional(),
28916
28983
  /** Whether the camera exposes a controllable autofocus toggle
28917
28984
  * (boolean `hasX` per the getOptions availability convention). */
28918
- hasAutofocus: boolean()
28985
+ hasAutofocus: boolean(),
28986
+ /**
28987
+ * How many distinct speeds this camera's NATIVE scale offers.
28988
+ *
28989
+ * The cap's `speed` is normalized 0..1 and each provider maps it down --
28990
+ * Baichuan 1..63, Dahua 1..8, ISAPI's percentage -100..100. The normalized
28991
+ * value hides how coarse that really is: asking an amcrest for `0.37` is
28992
+ * meaningless, because it has eight steps and three of them round to the
28993
+ * same one. A loop that tunes its own gain has to know the granularity of
28994
+ * the knob it is turning.
28995
+ *
28996
+ * `null` = the driver does not know, or the scale is continuous (ONVIF takes
28997
+ * a float). Never a made-up number.
28998
+ */
28999
+ speedSteps: number().int().positive().nullable(),
29000
+ /**
29001
+ * How long ONE `move` pulse runs on this driver, ms.
29002
+ *
29003
+ * `move` is a self-terminating burst everywhere, but every provider hardcoded
29004
+ * its own duration in private -- 200 reolink, 350 amcrest, 500 hikvision,
29005
+ * 1000 onvif -- so no caller could read it. It is the DENOMINATOR of "how far
29006
+ * did the head travel per pulse": without it a measured displacement has no
29007
+ * gain to be divided into.
29008
+ *
29009
+ * `null` = the driver cannot say.
29010
+ */
29011
+ moveImpulseMs: number().int().positive().nullable()
29012
+ });
29013
+ /**
29014
+ * Which preset `goHome` goes to, and WHO decided.
29015
+ *
29016
+ * `goHome` used to be three vendor "conventions" written in three comments --
29017
+ * Reolink preset 0, Hikvision preset '1', Dahua preset 1 -- and on this fleet
29018
+ * not one of the three cameras honours its own:
29019
+ *
29020
+ * 592 Videocamera camera Daniel (reolink) preset 0 holds "stanza"
29021
+ * 1438 Videocamera dispensa (hikvision) preset 1 holds "Credenza"
29022
+ * 3836 Videocamera studio (amcrest) preset 1 holds "Preset1"
29023
+ *
29024
+ * So `goHome` meant "go wherever the operator happened to save in slot 0 or 1",
29025
+ * and two of the three swallowed the failure in a bare `catch`. For autotrack
29026
+ * this is the HOTTEST path -- it runs every time a subject is released -- so it
29027
+ * needs an answer that is true per camera and audible when it is missing.
29028
+ *
29029
+ * `source` is what makes it honest:
29030
+ * - `operator` -- picked in the UI, stored by the provider.
29031
+ * - `firmware` -- the camera itself named a preset `fn: 'home'` (Hikvision's
29032
+ * "Back to origin"), adopted as the default with nothing to configure.
29033
+ * - `native` -- the driver homes WITHOUT a preset at all. ONVIF does:
29034
+ * `goHome` is `ptzAbsoluteMove({x:0, y:0, zoom:0})`. `presetId` is null and
29035
+ * that is not a failure -- there is nothing to pick, and the UI must offer
29036
+ * no picker.
29037
+ * - `none` -- nothing is configured and the camera names nothing.
29038
+ * `goHome` REFUSES rather than moving the head somewhere arbitrary.
29039
+ *
29040
+ * `source === 'none'` is the refusal condition, NOT `presetId === null`: the
29041
+ * native case has no preset and homes perfectly well.
29042
+ */
29043
+ var PtzHomePresetSchema = object({
29044
+ presetId: string().nullable(),
29045
+ source: _enum([
29046
+ "operator",
29047
+ "firmware",
29048
+ "native",
29049
+ "none"
29050
+ ])
28919
29051
  });
28920
29052
  var ptzCapability = {
28921
29053
  name: "ptz",
@@ -28956,7 +29088,25 @@ var ptzCapability = {
28956
29088
  auth: "admin"
28957
29089
  }),
28958
29090
  getOptions: method(object({ deviceId: number() }), PtzOptionsSchema),
29091
+ /**
29092
+ * Move to the camera's configured home preset. THROWS when
29093
+ * `getHomePreset()` resolves to `none` -- a head that did not move must
29094
+ * never look like a head that went home.
29095
+ */
28959
29096
  goHome: method(object({ deviceId: number() }), _void(), { kind: "mutation" }),
29097
+ /** Which preset `goHome` targets, and who decided it. */
29098
+ getHomePreset: method(object({ deviceId: number() }), PtzHomePresetSchema),
29099
+ /**
29100
+ * Pin the home preset for this camera. `null` clears the operator's choice
29101
+ * and falls back to whatever the firmware names, or to `none`.
29102
+ */
29103
+ setHomePreset: method(object({
29104
+ deviceId: number(),
29105
+ presetId: string().nullable()
29106
+ }), _void(), {
29107
+ kind: "mutation",
29108
+ auth: "admin"
29109
+ }),
28960
29110
  /**
28961
29111
  * Pull the current PTZ position. Redundant with the auto-injected
28962
29112
  * `getStatus` method (see `status` below); kept for callers that
@@ -36813,6 +36963,12 @@ Object.freeze({
36813
36963
  addonId: null,
36814
36964
  access: "delete"
36815
36965
  },
36966
+ "ptz.getHomePreset": {
36967
+ capName: "ptz",
36968
+ capScope: "device",
36969
+ addonId: null,
36970
+ access: "view"
36971
+ },
36816
36972
  "ptz.getOptions": {
36817
36973
  capName: "ptz",
36818
36974
  capScope: "device",
@@ -36861,6 +37017,12 @@ Object.freeze({
36861
37017
  addonId: null,
36862
37018
  access: "create"
36863
37019
  },
37020
+ "ptz.setHomePreset": {
37021
+ capName: "ptz",
37022
+ capScope: "device",
37023
+ addonId: null,
37024
+ access: "create"
37025
+ },
36864
37026
  "ptz.stop": {
36865
37027
  capName: "ptz",
36866
37028
  capScope: "device",
@@ -40034,6 +40196,11 @@ Object.freeze({
40034
40196
  form: "single",
40035
40197
  optional: false
40036
40198
  }],
40199
+ "ptz.getHomePreset": [{
40200
+ name: "deviceId",
40201
+ form: "single",
40202
+ optional: false
40203
+ }],
40037
40204
  "ptz.getOptions": [{
40038
40205
  name: "deviceId",
40039
40206
  form: "single",
@@ -40074,6 +40241,11 @@ Object.freeze({
40074
40241
  form: "single",
40075
40242
  optional: false
40076
40243
  }],
40244
+ "ptz.setHomePreset": [{
40245
+ name: "deviceId",
40246
+ form: "single",
40247
+ optional: false
40248
+ }],
40077
40249
  "ptz.stop": [{
40078
40250
  name: "deviceId",
40079
40251
  form: "single",
@@ -41109,295 +41281,6 @@ DEFAULT_NATIVE_LEASE_SETTINGS.admission;
41109
41281
  var MB = 1024 * 1024;
41110
41282
  1024 * MB, 3072 * MB;
41111
41283
  //#endregion
41112
- //#region src/onvif-camera.ts
41113
- var onvifCameraSchema = object({
41114
- name: string().describe("Camera display name"),
41115
- host: string().describe("Camera IP address or hostname"),
41116
- port: number().default(80).describe("ONVIF port (default: 80)"),
41117
- username: string().default("").describe("ONVIF username"),
41118
- password: string().default("").describe("ONVIF password"),
41119
- rtspUrl: string().describe("Primary RTSP stream URL"),
41120
- subStreamUrl: string().default("").describe("Sub-stream RTSP URL (optional)"),
41121
- snapshotUrl: string().default("").describe("Native snapshot URL (optional)"),
41122
- profileToken: string().default("").describe("Main ONVIF media profile token"),
41123
- subProfileToken: string().default("").describe("Sub-stream ONVIF media profile token (optional)"),
41124
- videoWidth: number().optional().describe("Main stream video width"),
41125
- videoHeight: number().optional().describe("Main stream video height"),
41126
- subVideoWidth: number().optional().describe("Sub-stream video width"),
41127
- subVideoHeight: number().optional().describe("Sub-stream video height"),
41128
- hasPtz: boolean().default(false).describe("Whether camera supports PTZ"),
41129
- manufacturer: string().default("").describe("Camera manufacturer"),
41130
- model: string().default("").describe("Camera model"),
41131
- firmware: string().default("").describe("Camera firmware version")
41132
- });
41133
- /**
41134
- * ONVIF camera device.
41135
- *
41136
- * Implements `IDevice` with the `NativeSnapshot` feature when a snapshot
41137
- * URL is available. PTZ methods are exposed as plain instance methods so the
41138
- * addon / capability layer can delegate to them; they are NOT registered as a
41139
- * `DeviceFeature` because the existing capability system handles PTZ via
41140
- * the `PanTiltZoom` feature.
41141
- */
41142
- var OnvifCamera = class {
41143
- id;
41144
- stableId;
41145
- type = DeviceType.Camera;
41146
- name;
41147
- /** Operator-organisational location label. Settable via the
41148
- * device-manager cap; legacy ONVIF cameras default to null. */
41149
- location = null;
41150
- /** Soft-disabled flag — drivers consult this; the kernel doesn't
41151
- * enforce. Defaults to false (active). */
41152
- disabled = false;
41153
- parentDeviceId;
41154
- features;
41155
- config;
41156
- ctx;
41157
- online = true;
41158
- markOnline(online) {
41159
- this.online = online;
41160
- }
41161
- /**
41162
- * Invoke a device custom action. ONVIF cameras register no device
41163
- * custom actions, so every action is unknown — mirrors `BaseDevice`'s
41164
- * default of throwing for an unregistered action.
41165
- */
41166
- async runDeviceAction(action, _input) {
41167
- throw new Error(`unknown device action "${action}" on device ${this.id}`);
41168
- }
41169
- /**
41170
- * Live ONVIF client — injected after connection is established.
41171
- * `null` when the camera is being restored from DB without a live connection.
41172
- */
41173
- client;
41174
- /** Control-plane reachability poll — drives `online` from ONVIF
41175
- * `getDeviceInformation` liveness, decoupled from stream-broker video
41176
- * health. Started on `attachClient`, stopped on `removeDevice`. */
41177
- reachabilityPoll = null;
41178
- constructor(ctx, initialData, client = null) {
41179
- this.ctx = ctx;
41180
- this.id = ctx.id;
41181
- this.stableId = ctx.stableId;
41182
- this.parentDeviceId = ctx.parentDeviceId;
41183
- this.client = client;
41184
- this.config = DeviceConfig.fromSchema(onvifCameraSchema, ctx.persistConfig, initialData);
41185
- this.name = this.config.get("name") || String(initialData["name"] ?? "ONVIF Camera");
41186
- this.features = this.config.get("snapshotUrl") ? [DeviceFeature.NativeSnapshot] : [];
41187
- this.registerNativeCapabilities();
41188
- }
41189
- /**
41190
- * Publish per-device native capability providers via
41191
- * `DeviceContext.registerNativeCap`. Called once from the constructor
41192
- * after `config` and `features` are settled. The kernel cleans these
41193
- * registrations up automatically on `device-manager.remove(deviceId)`
41194
- * via `CapabilityRegistry.unregisterAllNativeForDevice`.
41195
- *
41196
- * Note: legacy `INativeSnapshot` / direct PTZ method exposure on the
41197
- * class is intentionally retained — it will be removed in Task 8.1
41198
- * after the legacy consumers are swept.
41199
- */
41200
- registerNativeCapabilities() {
41201
- if (this.config.get("snapshotUrl")) this.ctx.registerNativeCap(snapshotCapability, {
41202
- getSnapshot: async ({ deviceId }) => {
41203
- if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
41204
- const buf = await this.getSnapshot();
41205
- if (buf.length === 0) return null;
41206
- return {
41207
- base64: buf.toString("base64"),
41208
- contentType: "image/jpeg"
41209
- };
41210
- },
41211
- invalidateCache: async () => {}
41212
- });
41213
- if (this.hasPtz()) this.ctx.registerNativeCap(ptzCapability, {
41214
- move: async ({ deviceId, pan, tilt, zoom, speed }) => {
41215
- if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
41216
- await this.ptzMove({
41217
- pan,
41218
- tilt,
41219
- zoom,
41220
- speed
41221
- });
41222
- },
41223
- continuousMove: async () => {
41224
- throw new Error("OnvifCamera: continuousMove not implemented");
41225
- },
41226
- stop: async ({ deviceId }) => {
41227
- if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
41228
- await this.ptzStop();
41229
- },
41230
- getPresets: async ({ deviceId }) => {
41231
- if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
41232
- return this.getPtzPresets();
41233
- },
41234
- goToPreset: async ({ deviceId, presetId }) => {
41235
- if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
41236
- await this.goToPreset(presetId);
41237
- },
41238
- savePreset: async () => {
41239
- throw new Error("OnvifCamera: savePreset not implemented");
41240
- },
41241
- deletePreset: async () => {
41242
- throw new Error("OnvifCamera: deletePreset not implemented");
41243
- },
41244
- goHome: async ({ deviceId }) => {
41245
- if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
41246
- await this.goHome();
41247
- },
41248
- getPosition: async () => {
41249
- throw new Error("OnvifCamera: getPosition not implemented");
41250
- },
41251
- getOptions: async () => {
41252
- return {
41253
- hasPan: true,
41254
- hasTilt: true,
41255
- hasZoom: true,
41256
- supportsPresets: true,
41257
- hasAutofocus: false
41258
- };
41259
- },
41260
- getStatus: async () => ({
41261
- pan: 0,
41262
- tilt: 0,
41263
- zoom: 0,
41264
- autofocus: false
41265
- }),
41266
- setAutofocus: async () => {}
41267
- });
41268
- }
41269
- async getSnapshot() {
41270
- const url = this.config.get("snapshotUrl");
41271
- if (!url) return Buffer.alloc(0);
41272
- const res = await fetch(url);
41273
- if (!res.ok) throw new Error(`ONVIF snapshot fetch failed: ${res.status} ${res.statusText}`);
41274
- return Buffer.from(await res.arrayBuffer());
41275
- }
41276
- hasPtz() {
41277
- return this.config.get("hasPtz");
41278
- }
41279
- async ptzMove(cmd) {
41280
- if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
41281
- await this.client.ptzMove({
41282
- x: cmd.pan,
41283
- y: cmd.tilt,
41284
- zoom: cmd.zoom,
41285
- speed: cmd.speed
41286
- });
41287
- }
41288
- async ptzStop() {
41289
- if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
41290
- await this.client.ptzStop();
41291
- }
41292
- async getPtzPresets() {
41293
- if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
41294
- return (await this.client.getPtzPresets()).map((p) => ({
41295
- id: p.token,
41296
- name: p.name
41297
- }));
41298
- }
41299
- async goToPreset(presetId) {
41300
- if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
41301
- await this.client.gotoPreset(presetId);
41302
- }
41303
- async goHome() {
41304
- if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
41305
- await this.client.ptzAbsoluteMove({
41306
- x: 0,
41307
- y: 0,
41308
- zoom: 0
41309
- });
41310
- }
41311
- getRtspUrl() {
41312
- return this.config.get("rtspUrl");
41313
- }
41314
- getSubStreamUrl() {
41315
- return this.config.get("subStreamUrl");
41316
- }
41317
- async getStreamSources() {
41318
- const sources = [];
41319
- const rtspUrl = this.config.get("rtspUrl");
41320
- if (rtspUrl) {
41321
- const videoWidth = this.config.get("videoWidth");
41322
- const videoHeight = this.config.get("videoHeight");
41323
- const mainSource = {
41324
- id: "main",
41325
- label: "Main Stream",
41326
- protocol: "rtsp",
41327
- url: rtspUrl,
41328
- profileHint: "high",
41329
- ...videoWidth !== void 0 && videoHeight !== void 0 ? { resolution: {
41330
- width: videoWidth,
41331
- height: videoHeight
41332
- } } : {}
41333
- };
41334
- sources.push(mainSource);
41335
- }
41336
- const subStreamUrl = this.config.get("subStreamUrl");
41337
- if (subStreamUrl) {
41338
- const subVideoWidth = this.config.get("subVideoWidth");
41339
- const subVideoHeight = this.config.get("subVideoHeight");
41340
- const subSource = {
41341
- id: "sub",
41342
- label: "Sub Stream",
41343
- protocol: "rtsp",
41344
- url: subStreamUrl,
41345
- profileHint: "low",
41346
- ...subVideoWidth !== void 0 && subVideoHeight !== void 0 ? { resolution: {
41347
- width: subVideoWidth,
41348
- height: subVideoHeight
41349
- } } : {}
41350
- };
41351
- sources.push(subSource);
41352
- }
41353
- return sources;
41354
- }
41355
- /**
41356
- * Attach a live ONVIF client after the device has been created from DB.
41357
- * Called by the addon when it successfully connects to the camera on boot.
41358
- */
41359
- attachClient(client) {
41360
- this.client = client;
41361
- this.online = true;
41362
- this.startReachabilityPolling();
41363
- }
41364
- /** Start the control-plane reachability poll: an ONVIF
41365
- * `getDeviceInformation` round-trip every 30s drives `online`, with
41366
- * hysteresis. Replaces the old stream-health→online coupling so a
41367
- * reachable on-demand camera still reports ONLINE. Re-armed on each
41368
- * `attachClient` (reconnect) — the prior poll is stopped first. */
41369
- startReachabilityPolling() {
41370
- this.reachabilityPoll?.stop();
41371
- this.reachabilityPoll = startReachabilityPoll({
41372
- probe: async () => {
41373
- const client = this.client;
41374
- if (!client) return false;
41375
- await client.getDeviceInfo();
41376
- return true;
41377
- },
41378
- setOnline: (online) => {
41379
- this.markOnline(online);
41380
- },
41381
- isEnabled: () => !this.disabled && this.client !== null,
41382
- logger: this.ctx.logger
41383
- });
41384
- }
41385
- async removeDevice() {
41386
- this.reachabilityPoll?.stop();
41387
- this.reachabilityPoll = null;
41388
- this.client?.disconnect();
41389
- this.client = null;
41390
- this.online = false;
41391
- this.ctx.logger.info("Removed ONVIF camera", { meta: { stableId: this.stableId } });
41392
- }
41393
- getSettingsUISchema() {
41394
- return { sections: [] };
41395
- }
41396
- async applySettingsPatch(patch) {
41397
- await this.config.setAll(patch);
41398
- }
41399
- };
41400
- //#endregion
41401
41284
  //#region ../../node_modules/xml2js/lib/defaults.js
41402
41285
  var require_defaults = /* @__PURE__ */ __commonJSMin(((exports) => {
41403
41286
  (function() {
@@ -50193,6 +50076,12 @@ var import_onvif = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
50193
50076
  Discovery: require_discovery().Discovery
50194
50077
  };
50195
50078
  })))();
50079
+ /**
50080
+ * How long one ONVIF `ContinuousMove` runs before the camera stops itself, ms.
50081
+ * The DENOMINATOR of "how far did the head travel per pulse", so it is named
50082
+ * and exported rather than left inline where no caller could read it.
50083
+ */
50084
+ var ONVIF_PTZ_TIMEOUT_MS = 1e3;
50196
50085
  var OnvifClient = class {
50197
50086
  host;
50198
50087
  port;
@@ -50288,7 +50177,7 @@ var OnvifClient = class {
50288
50177
  x: options.x ?? 0,
50289
50178
  y: options.y ?? 0,
50290
50179
  zoom: options.zoom ?? 0,
50291
- timeout: 1e3
50180
+ timeout: ONVIF_PTZ_TIMEOUT_MS
50292
50181
  }, (err) => {
50293
50182
  if (err) reject(err);
50294
50183
  else resolve();
@@ -50347,6 +50236,311 @@ var OnvifClient = class {
50347
50236
  }
50348
50237
  };
50349
50238
  //#endregion
50239
+ //#region src/onvif-camera.ts
50240
+ var onvifCameraSchema = object({
50241
+ name: string().describe("Camera display name"),
50242
+ host: string().describe("Camera IP address or hostname"),
50243
+ port: number().default(80).describe("ONVIF port (default: 80)"),
50244
+ username: string().default("").describe("ONVIF username"),
50245
+ password: string().default("").describe("ONVIF password"),
50246
+ rtspUrl: string().describe("Primary RTSP stream URL"),
50247
+ subStreamUrl: string().default("").describe("Sub-stream RTSP URL (optional)"),
50248
+ snapshotUrl: string().default("").describe("Native snapshot URL (optional)"),
50249
+ profileToken: string().default("").describe("Main ONVIF media profile token"),
50250
+ subProfileToken: string().default("").describe("Sub-stream ONVIF media profile token (optional)"),
50251
+ videoWidth: number().optional().describe("Main stream video width"),
50252
+ videoHeight: number().optional().describe("Main stream video height"),
50253
+ subVideoWidth: number().optional().describe("Sub-stream video width"),
50254
+ subVideoHeight: number().optional().describe("Sub-stream video height"),
50255
+ hasPtz: boolean().default(false).describe("Whether camera supports PTZ"),
50256
+ manufacturer: string().default("").describe("Camera manufacturer"),
50257
+ model: string().default("").describe("Camera model"),
50258
+ firmware: string().default("").describe("Camera firmware version")
50259
+ });
50260
+ /**
50261
+ * ONVIF camera device.
50262
+ *
50263
+ * Implements `IDevice` with the `NativeSnapshot` feature when a snapshot
50264
+ * URL is available. PTZ methods are exposed as plain instance methods so the
50265
+ * addon / capability layer can delegate to them; they are NOT registered as a
50266
+ * `DeviceFeature` because the existing capability system handles PTZ via
50267
+ * the `PanTiltZoom` feature.
50268
+ */
50269
+ var OnvifCamera = class {
50270
+ id;
50271
+ stableId;
50272
+ type = DeviceType.Camera;
50273
+ name;
50274
+ /** Operator-organisational location label. Settable via the
50275
+ * device-manager cap; legacy ONVIF cameras default to null. */
50276
+ location = null;
50277
+ /** Soft-disabled flag — drivers consult this; the kernel doesn't
50278
+ * enforce. Defaults to false (active). */
50279
+ disabled = false;
50280
+ parentDeviceId;
50281
+ features;
50282
+ config;
50283
+ ctx;
50284
+ online = true;
50285
+ markOnline(online) {
50286
+ this.online = online;
50287
+ }
50288
+ /**
50289
+ * Invoke a device custom action. ONVIF cameras register no device
50290
+ * custom actions, so every action is unknown — mirrors `BaseDevice`'s
50291
+ * default of throwing for an unregistered action.
50292
+ */
50293
+ async runDeviceAction(action, _input) {
50294
+ throw new Error(`unknown device action "${action}" on device ${this.id}`);
50295
+ }
50296
+ /**
50297
+ * Live ONVIF client — injected after connection is established.
50298
+ * `null` when the camera is being restored from DB without a live connection.
50299
+ */
50300
+ client;
50301
+ /** Control-plane reachability poll — drives `online` from ONVIF
50302
+ * `getDeviceInformation` liveness, decoupled from stream-broker video
50303
+ * health. Started on `attachClient`, stopped on `removeDevice`. */
50304
+ reachabilityPoll = null;
50305
+ constructor(ctx, initialData, client = null) {
50306
+ this.ctx = ctx;
50307
+ this.id = ctx.id;
50308
+ this.stableId = ctx.stableId;
50309
+ this.parentDeviceId = ctx.parentDeviceId;
50310
+ this.client = client;
50311
+ this.config = DeviceConfig.fromSchema(onvifCameraSchema, ctx.persistConfig, initialData);
50312
+ this.name = this.config.get("name") || String(initialData["name"] ?? "ONVIF Camera");
50313
+ this.features = this.config.get("snapshotUrl") ? [DeviceFeature.NativeSnapshot] : [];
50314
+ this.registerNativeCapabilities();
50315
+ }
50316
+ /**
50317
+ * Publish per-device native capability providers via
50318
+ * `DeviceContext.registerNativeCap`. Called once from the constructor
50319
+ * after `config` and `features` are settled. The kernel cleans these
50320
+ * registrations up automatically on `device-manager.remove(deviceId)`
50321
+ * via `CapabilityRegistry.unregisterAllNativeForDevice`.
50322
+ *
50323
+ * Note: legacy `INativeSnapshot` / direct PTZ method exposure on the
50324
+ * class is intentionally retained — it will be removed in Task 8.1
50325
+ * after the legacy consumers are swept.
50326
+ */
50327
+ registerNativeCapabilities() {
50328
+ if (this.config.get("snapshotUrl")) this.ctx.registerNativeCap(snapshotCapability, {
50329
+ getSnapshot: async ({ deviceId }) => {
50330
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50331
+ const buf = await this.getSnapshot();
50332
+ if (buf.length === 0) return null;
50333
+ return {
50334
+ base64: buf.toString("base64"),
50335
+ contentType: "image/jpeg"
50336
+ };
50337
+ },
50338
+ invalidateCache: async () => {}
50339
+ });
50340
+ if (this.hasPtz()) this.ctx.registerNativeCap(ptzCapability, {
50341
+ move: async ({ deviceId, pan, tilt, zoom, speed }) => {
50342
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50343
+ await this.ptzMove({
50344
+ pan,
50345
+ tilt,
50346
+ zoom,
50347
+ speed
50348
+ });
50349
+ },
50350
+ continuousMove: async () => {
50351
+ throw new Error("OnvifCamera: continuousMove not implemented");
50352
+ },
50353
+ stop: async ({ deviceId }) => {
50354
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50355
+ await this.ptzStop();
50356
+ },
50357
+ getPresets: async ({ deviceId }) => {
50358
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50359
+ return (await this.getPtzPresets()).map((preset) => ({
50360
+ ...preset,
50361
+ fn: null,
50362
+ writable: false
50363
+ }));
50364
+ },
50365
+ goToPreset: async ({ deviceId, presetId }) => {
50366
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50367
+ await this.goToPreset(presetId);
50368
+ },
50369
+ savePreset: async () => {
50370
+ throw new Error("OnvifCamera: savePreset not implemented");
50371
+ },
50372
+ deletePreset: async () => {
50373
+ throw new Error("OnvifCamera: deletePreset not implemented");
50374
+ },
50375
+ goHome: async ({ deviceId }) => {
50376
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50377
+ await this.goHome();
50378
+ },
50379
+ getHomePreset: async ({ deviceId }) => {
50380
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50381
+ return {
50382
+ presetId: null,
50383
+ source: "native"
50384
+ };
50385
+ },
50386
+ setHomePreset: async () => {
50387
+ throw new Error("OnvifCamera: home is the PTZ origin on ONVIF and cannot be pointed at a preset");
50388
+ },
50389
+ getPosition: async () => {
50390
+ throw new Error("OnvifCamera: getPosition not implemented");
50391
+ },
50392
+ getOptions: async () => {
50393
+ return {
50394
+ hasPan: true,
50395
+ hasTilt: true,
50396
+ hasZoom: true,
50397
+ supportsPresets: true,
50398
+ hasAutofocus: false,
50399
+ speedSteps: null,
50400
+ moveImpulseMs: ONVIF_PTZ_TIMEOUT_MS
50401
+ };
50402
+ },
50403
+ getStatus: async () => ({
50404
+ pan: null,
50405
+ tilt: null,
50406
+ zoom: null,
50407
+ autofocus: false
50408
+ }),
50409
+ setAutofocus: async () => {}
50410
+ });
50411
+ }
50412
+ async getSnapshot() {
50413
+ const url = this.config.get("snapshotUrl");
50414
+ if (!url) return Buffer.alloc(0);
50415
+ const res = await fetch(url);
50416
+ if (!res.ok) throw new Error(`ONVIF snapshot fetch failed: ${res.status} ${res.statusText}`);
50417
+ return Buffer.from(await res.arrayBuffer());
50418
+ }
50419
+ hasPtz() {
50420
+ return this.config.get("hasPtz");
50421
+ }
50422
+ async ptzMove(cmd) {
50423
+ if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
50424
+ await this.client.ptzMove({
50425
+ x: cmd.pan,
50426
+ y: cmd.tilt,
50427
+ zoom: cmd.zoom,
50428
+ speed: cmd.speed
50429
+ });
50430
+ }
50431
+ async ptzStop() {
50432
+ if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
50433
+ await this.client.ptzStop();
50434
+ }
50435
+ async getPtzPresets() {
50436
+ if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
50437
+ return (await this.client.getPtzPresets()).map((p) => ({
50438
+ id: p.token,
50439
+ name: p.name
50440
+ }));
50441
+ }
50442
+ async goToPreset(presetId) {
50443
+ if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
50444
+ await this.client.gotoPreset(presetId);
50445
+ }
50446
+ async goHome() {
50447
+ if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
50448
+ await this.client.ptzAbsoluteMove({
50449
+ x: 0,
50450
+ y: 0,
50451
+ zoom: 0
50452
+ });
50453
+ }
50454
+ getRtspUrl() {
50455
+ return this.config.get("rtspUrl");
50456
+ }
50457
+ getSubStreamUrl() {
50458
+ return this.config.get("subStreamUrl");
50459
+ }
50460
+ async getStreamSources() {
50461
+ const sources = [];
50462
+ const rtspUrl = this.config.get("rtspUrl");
50463
+ if (rtspUrl) {
50464
+ const videoWidth = this.config.get("videoWidth");
50465
+ const videoHeight = this.config.get("videoHeight");
50466
+ const mainSource = {
50467
+ id: "main",
50468
+ label: "Main Stream",
50469
+ protocol: "rtsp",
50470
+ url: rtspUrl,
50471
+ profileHint: "high",
50472
+ ...videoWidth !== void 0 && videoHeight !== void 0 ? { resolution: {
50473
+ width: videoWidth,
50474
+ height: videoHeight
50475
+ } } : {}
50476
+ };
50477
+ sources.push(mainSource);
50478
+ }
50479
+ const subStreamUrl = this.config.get("subStreamUrl");
50480
+ if (subStreamUrl) {
50481
+ const subVideoWidth = this.config.get("subVideoWidth");
50482
+ const subVideoHeight = this.config.get("subVideoHeight");
50483
+ const subSource = {
50484
+ id: "sub",
50485
+ label: "Sub Stream",
50486
+ protocol: "rtsp",
50487
+ url: subStreamUrl,
50488
+ profileHint: "low",
50489
+ ...subVideoWidth !== void 0 && subVideoHeight !== void 0 ? { resolution: {
50490
+ width: subVideoWidth,
50491
+ height: subVideoHeight
50492
+ } } : {}
50493
+ };
50494
+ sources.push(subSource);
50495
+ }
50496
+ return sources;
50497
+ }
50498
+ /**
50499
+ * Attach a live ONVIF client after the device has been created from DB.
50500
+ * Called by the addon when it successfully connects to the camera on boot.
50501
+ */
50502
+ attachClient(client) {
50503
+ this.client = client;
50504
+ this.online = true;
50505
+ this.startReachabilityPolling();
50506
+ }
50507
+ /** Start the control-plane reachability poll: an ONVIF
50508
+ * `getDeviceInformation` round-trip every 30s drives `online`, with
50509
+ * hysteresis. Replaces the old stream-health→online coupling so a
50510
+ * reachable on-demand camera still reports ONLINE. Re-armed on each
50511
+ * `attachClient` (reconnect) — the prior poll is stopped first. */
50512
+ startReachabilityPolling() {
50513
+ this.reachabilityPoll?.stop();
50514
+ this.reachabilityPoll = startReachabilityPoll({
50515
+ probe: async () => {
50516
+ const client = this.client;
50517
+ if (!client) return false;
50518
+ await client.getDeviceInfo();
50519
+ return true;
50520
+ },
50521
+ setOnline: (online) => {
50522
+ this.markOnline(online);
50523
+ },
50524
+ isEnabled: () => !this.disabled && this.client !== null,
50525
+ logger: this.ctx.logger
50526
+ });
50527
+ }
50528
+ async removeDevice() {
50529
+ this.reachabilityPoll?.stop();
50530
+ this.reachabilityPoll = null;
50531
+ this.client?.disconnect();
50532
+ this.client = null;
50533
+ this.online = false;
50534
+ this.ctx.logger.info("Removed ONVIF camera", { meta: { stableId: this.stableId } });
50535
+ }
50536
+ getSettingsUISchema() {
50537
+ return { sections: [] };
50538
+ }
50539
+ async applySettingsPatch(patch) {
50540
+ await this.config.setAll(patch);
50541
+ }
50542
+ };
50543
+ //#endregion
50350
50544
  //#region src/onvif-discovery.ts
50351
50545
  /**
50352
50546
  * Discovers ONVIF cameras on the local network via WS-Discovery.