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