@camstack/addon-provider-onvif 1.2.109 → 1.2.111

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-vl6nBE8d.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,66 @@ 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
+ }),
29110
+ /**
29111
+ * Make WHERE THE HEAD IS POINTING RIGHT NOW this camera's home.
29112
+ *
29113
+ * `setHomePreset` takes a preset id, and a preset id is the wrong shape for
29114
+ * the most natural thing an operator does: aim the camera, then say "here".
29115
+ * It is also the only shape a camera whose home is NOT a preset can accept
29116
+ * -- Reolink's home is a guard point, a stored position with no id at all,
29117
+ * and hiding the control for that case (as the UI briefly did) left the one
29118
+ * vendor with a native home unable to set it.
29119
+ *
29120
+ * Each provider does it its own way:
29121
+ * reolink `setGrd` with `needSetPos`, pinning the guard point here
29122
+ * hikvision / amcrest save a preset, then pin it as home
29123
+ * onvif REFUSES -- its home is the PTZ origin and cannot be moved
29124
+ *
29125
+ * A provider that cannot honour it throws rather than silently doing
29126
+ * nothing: an operator who pressed "set home here" and saw no error would
29127
+ * believe it took.
29128
+ */
29129
+ captureHomeHere: method(object({ deviceId: number() }), _void(), {
29130
+ kind: "mutation",
29131
+ auth: "admin"
29132
+ }),
29133
+ /**
29134
+ * How long the camera waits, idle, before returning home on its own --
29135
+ * `null` when it has no such behaviour.
29136
+ *
29137
+ * Reolink's guard point carries one (`timeout`, freely settable in
29138
+ * seconds). It is a real function of the camera that we did not expose at
29139
+ * all, and it belongs next to the home it governs rather than in a vendor
29140
+ * settings page nobody associates with Home.
29141
+ */
29142
+ getHomeReturnSeconds: method(object({ deviceId: number() }), number().int().nullable()),
29143
+ /** Set the idle-return delay. Refused by a camera that has no such timer. */
29144
+ setHomeReturnSeconds: method(object({
29145
+ deviceId: number(),
29146
+ seconds: number().int().min(0).max(3600)
29147
+ }), _void(), {
29148
+ kind: "mutation",
29149
+ auth: "admin"
29150
+ }),
28960
29151
  /**
28961
29152
  * Pull the current PTZ position. Redundant with the auto-injected
28962
29153
  * `getStatus` method (see `status` below); kept for callers that
@@ -36801,6 +36992,12 @@ Object.freeze({
36801
36992
  addonId: null,
36802
36993
  access: "create"
36803
36994
  },
36995
+ "ptz.captureHomeHere": {
36996
+ capName: "ptz",
36997
+ capScope: "device",
36998
+ addonId: null,
36999
+ access: "create"
37000
+ },
36804
37001
  "ptz.continuousMove": {
36805
37002
  capName: "ptz",
36806
37003
  capScope: "device",
@@ -36813,6 +37010,18 @@ Object.freeze({
36813
37010
  addonId: null,
36814
37011
  access: "delete"
36815
37012
  },
37013
+ "ptz.getHomePreset": {
37014
+ capName: "ptz",
37015
+ capScope: "device",
37016
+ addonId: null,
37017
+ access: "view"
37018
+ },
37019
+ "ptz.getHomeReturnSeconds": {
37020
+ capName: "ptz",
37021
+ capScope: "device",
37022
+ addonId: null,
37023
+ access: "view"
37024
+ },
36816
37025
  "ptz.getOptions": {
36817
37026
  capName: "ptz",
36818
37027
  capScope: "device",
@@ -36861,6 +37070,18 @@ Object.freeze({
36861
37070
  addonId: null,
36862
37071
  access: "create"
36863
37072
  },
37073
+ "ptz.setHomePreset": {
37074
+ capName: "ptz",
37075
+ capScope: "device",
37076
+ addonId: null,
37077
+ access: "create"
37078
+ },
37079
+ "ptz.setHomeReturnSeconds": {
37080
+ capName: "ptz",
37081
+ capScope: "device",
37082
+ addonId: null,
37083
+ access: "create"
37084
+ },
36864
37085
  "ptz.stop": {
36865
37086
  capName: "ptz",
36866
37087
  capScope: "device",
@@ -40024,6 +40245,11 @@ Object.freeze({
40024
40245
  form: "single",
40025
40246
  optional: false
40026
40247
  }],
40248
+ "ptz.captureHomeHere": [{
40249
+ name: "deviceId",
40250
+ form: "single",
40251
+ optional: false
40252
+ }],
40027
40253
  "ptz.continuousMove": [{
40028
40254
  name: "deviceId",
40029
40255
  form: "single",
@@ -40034,6 +40260,16 @@ Object.freeze({
40034
40260
  form: "single",
40035
40261
  optional: false
40036
40262
  }],
40263
+ "ptz.getHomePreset": [{
40264
+ name: "deviceId",
40265
+ form: "single",
40266
+ optional: false
40267
+ }],
40268
+ "ptz.getHomeReturnSeconds": [{
40269
+ name: "deviceId",
40270
+ form: "single",
40271
+ optional: false
40272
+ }],
40037
40273
  "ptz.getOptions": [{
40038
40274
  name: "deviceId",
40039
40275
  form: "single",
@@ -40074,6 +40310,16 @@ Object.freeze({
40074
40310
  form: "single",
40075
40311
  optional: false
40076
40312
  }],
40313
+ "ptz.setHomePreset": [{
40314
+ name: "deviceId",
40315
+ form: "single",
40316
+ optional: false
40317
+ }],
40318
+ "ptz.setHomeReturnSeconds": [{
40319
+ name: "deviceId",
40320
+ form: "single",
40321
+ optional: false
40322
+ }],
40077
40323
  "ptz.stop": [{
40078
40324
  name: "deviceId",
40079
40325
  form: "single",
@@ -41109,295 +41355,6 @@ DEFAULT_NATIVE_LEASE_SETTINGS.admission;
41109
41355
  var MB = 1024 * 1024;
41110
41356
  1024 * MB, 3072 * MB;
41111
41357
  //#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
41358
  //#region ../../node_modules/xml2js/lib/defaults.js
41402
41359
  var require_defaults = /* @__PURE__ */ __commonJSMin(((exports) => {
41403
41360
  (function() {
@@ -50193,6 +50150,12 @@ var import_onvif = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
50193
50150
  Discovery: require_discovery().Discovery
50194
50151
  };
50195
50152
  })))();
50153
+ /**
50154
+ * How long one ONVIF `ContinuousMove` runs before the camera stops itself, ms.
50155
+ * The DENOMINATOR of "how far did the head travel per pulse", so it is named
50156
+ * and exported rather than left inline where no caller could read it.
50157
+ */
50158
+ var ONVIF_PTZ_TIMEOUT_MS = 1e3;
50196
50159
  var OnvifClient = class {
50197
50160
  host;
50198
50161
  port;
@@ -50288,7 +50251,7 @@ var OnvifClient = class {
50288
50251
  x: options.x ?? 0,
50289
50252
  y: options.y ?? 0,
50290
50253
  zoom: options.zoom ?? 0,
50291
- timeout: 1e3
50254
+ timeout: ONVIF_PTZ_TIMEOUT_MS
50292
50255
  }, (err) => {
50293
50256
  if (err) reject(err);
50294
50257
  else resolve();
@@ -50347,6 +50310,320 @@ var OnvifClient = class {
50347
50310
  }
50348
50311
  };
50349
50312
  //#endregion
50313
+ //#region src/onvif-camera.ts
50314
+ var onvifCameraSchema = object({
50315
+ name: string().describe("Camera display name"),
50316
+ host: string().describe("Camera IP address or hostname"),
50317
+ port: number().default(80).describe("ONVIF port (default: 80)"),
50318
+ username: string().default("").describe("ONVIF username"),
50319
+ password: string().default("").describe("ONVIF password"),
50320
+ rtspUrl: string().describe("Primary RTSP stream URL"),
50321
+ subStreamUrl: string().default("").describe("Sub-stream RTSP URL (optional)"),
50322
+ snapshotUrl: string().default("").describe("Native snapshot URL (optional)"),
50323
+ profileToken: string().default("").describe("Main ONVIF media profile token"),
50324
+ subProfileToken: string().default("").describe("Sub-stream ONVIF media profile token (optional)"),
50325
+ videoWidth: number().optional().describe("Main stream video width"),
50326
+ videoHeight: number().optional().describe("Main stream video height"),
50327
+ subVideoWidth: number().optional().describe("Sub-stream video width"),
50328
+ subVideoHeight: number().optional().describe("Sub-stream video height"),
50329
+ hasPtz: boolean().default(false).describe("Whether camera supports PTZ"),
50330
+ manufacturer: string().default("").describe("Camera manufacturer"),
50331
+ model: string().default("").describe("Camera model"),
50332
+ firmware: string().default("").describe("Camera firmware version")
50333
+ });
50334
+ /**
50335
+ * ONVIF camera device.
50336
+ *
50337
+ * Implements `IDevice` with the `NativeSnapshot` feature when a snapshot
50338
+ * URL is available. PTZ methods are exposed as plain instance methods so the
50339
+ * addon / capability layer can delegate to them; they are NOT registered as a
50340
+ * `DeviceFeature` because the existing capability system handles PTZ via
50341
+ * the `PanTiltZoom` feature.
50342
+ */
50343
+ var OnvifCamera = class {
50344
+ id;
50345
+ stableId;
50346
+ type = DeviceType.Camera;
50347
+ name;
50348
+ /** Operator-organisational location label. Settable via the
50349
+ * device-manager cap; legacy ONVIF cameras default to null. */
50350
+ location = null;
50351
+ /** Soft-disabled flag — drivers consult this; the kernel doesn't
50352
+ * enforce. Defaults to false (active). */
50353
+ disabled = false;
50354
+ parentDeviceId;
50355
+ features;
50356
+ config;
50357
+ ctx;
50358
+ online = true;
50359
+ markOnline(online) {
50360
+ this.online = online;
50361
+ }
50362
+ /**
50363
+ * Invoke a device custom action. ONVIF cameras register no device
50364
+ * custom actions, so every action is unknown — mirrors `BaseDevice`'s
50365
+ * default of throwing for an unregistered action.
50366
+ */
50367
+ async runDeviceAction(action, _input) {
50368
+ throw new Error(`unknown device action "${action}" on device ${this.id}`);
50369
+ }
50370
+ /**
50371
+ * Live ONVIF client — injected after connection is established.
50372
+ * `null` when the camera is being restored from DB without a live connection.
50373
+ */
50374
+ client;
50375
+ /** Control-plane reachability poll — drives `online` from ONVIF
50376
+ * `getDeviceInformation` liveness, decoupled from stream-broker video
50377
+ * health. Started on `attachClient`, stopped on `removeDevice`. */
50378
+ reachabilityPoll = null;
50379
+ constructor(ctx, initialData, client = null) {
50380
+ this.ctx = ctx;
50381
+ this.id = ctx.id;
50382
+ this.stableId = ctx.stableId;
50383
+ this.parentDeviceId = ctx.parentDeviceId;
50384
+ this.client = client;
50385
+ this.config = DeviceConfig.fromSchema(onvifCameraSchema, ctx.persistConfig, initialData);
50386
+ this.name = this.config.get("name") || String(initialData["name"] ?? "ONVIF Camera");
50387
+ this.features = this.config.get("snapshotUrl") ? [DeviceFeature.NativeSnapshot] : [];
50388
+ this.registerNativeCapabilities();
50389
+ }
50390
+ /**
50391
+ * Publish per-device native capability providers via
50392
+ * `DeviceContext.registerNativeCap`. Called once from the constructor
50393
+ * after `config` and `features` are settled. The kernel cleans these
50394
+ * registrations up automatically on `device-manager.remove(deviceId)`
50395
+ * via `CapabilityRegistry.unregisterAllNativeForDevice`.
50396
+ *
50397
+ * Note: legacy `INativeSnapshot` / direct PTZ method exposure on the
50398
+ * class is intentionally retained — it will be removed in Task 8.1
50399
+ * after the legacy consumers are swept.
50400
+ */
50401
+ registerNativeCapabilities() {
50402
+ if (this.config.get("snapshotUrl")) this.ctx.registerNativeCap(snapshotCapability, {
50403
+ getSnapshot: async ({ deviceId }) => {
50404
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50405
+ const buf = await this.getSnapshot();
50406
+ if (buf.length === 0) return null;
50407
+ return {
50408
+ base64: buf.toString("base64"),
50409
+ contentType: "image/jpeg"
50410
+ };
50411
+ },
50412
+ invalidateCache: async () => {}
50413
+ });
50414
+ if (this.hasPtz()) this.ctx.registerNativeCap(ptzCapability, {
50415
+ move: async ({ deviceId, pan, tilt, zoom, speed }) => {
50416
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50417
+ await this.ptzMove({
50418
+ pan,
50419
+ tilt,
50420
+ zoom,
50421
+ speed
50422
+ });
50423
+ },
50424
+ continuousMove: async () => {
50425
+ throw new Error("OnvifCamera: continuousMove not implemented");
50426
+ },
50427
+ stop: async ({ deviceId }) => {
50428
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50429
+ await this.ptzStop();
50430
+ },
50431
+ getPresets: async ({ deviceId }) => {
50432
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50433
+ return (await this.getPtzPresets()).map((preset) => ({
50434
+ ...preset,
50435
+ fn: null,
50436
+ writable: false
50437
+ }));
50438
+ },
50439
+ goToPreset: async ({ deviceId, presetId }) => {
50440
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50441
+ await this.goToPreset(presetId);
50442
+ },
50443
+ savePreset: async () => {
50444
+ throw new Error("OnvifCamera: savePreset not implemented");
50445
+ },
50446
+ deletePreset: async () => {
50447
+ throw new Error("OnvifCamera: deletePreset not implemented");
50448
+ },
50449
+ goHome: async ({ deviceId }) => {
50450
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50451
+ await this.goHome();
50452
+ },
50453
+ getHomePreset: async ({ deviceId }) => {
50454
+ if (deviceId !== this.id) throw new Error(`OnvifCamera: deviceId mismatch, expected ${this.id}, got ${deviceId}`);
50455
+ return {
50456
+ presetId: null,
50457
+ source: "native"
50458
+ };
50459
+ },
50460
+ captureHomeHere: async () => {
50461
+ throw new Error("OnvifCamera: home is the PTZ origin on ONVIF and cannot be moved to the current position");
50462
+ },
50463
+ getHomeReturnSeconds: async () => {
50464
+ return null;
50465
+ },
50466
+ setHomeReturnSeconds: async () => {
50467
+ throw new Error("OnvifCamera: no idle-return timer on this driver");
50468
+ },
50469
+ setHomePreset: async () => {
50470
+ throw new Error("OnvifCamera: home is the PTZ origin on ONVIF and cannot be pointed at a preset");
50471
+ },
50472
+ getPosition: async () => {
50473
+ throw new Error("OnvifCamera: getPosition not implemented");
50474
+ },
50475
+ getOptions: async () => {
50476
+ return {
50477
+ hasPan: true,
50478
+ hasTilt: true,
50479
+ hasZoom: true,
50480
+ supportsPresets: true,
50481
+ hasAutofocus: false,
50482
+ speedSteps: null,
50483
+ moveImpulseMs: ONVIF_PTZ_TIMEOUT_MS
50484
+ };
50485
+ },
50486
+ getStatus: async () => ({
50487
+ pan: null,
50488
+ tilt: null,
50489
+ zoom: null,
50490
+ autofocus: false
50491
+ }),
50492
+ setAutofocus: async () => {}
50493
+ });
50494
+ }
50495
+ async getSnapshot() {
50496
+ const url = this.config.get("snapshotUrl");
50497
+ if (!url) return Buffer.alloc(0);
50498
+ const res = await fetch(url);
50499
+ if (!res.ok) throw new Error(`ONVIF snapshot fetch failed: ${res.status} ${res.statusText}`);
50500
+ return Buffer.from(await res.arrayBuffer());
50501
+ }
50502
+ hasPtz() {
50503
+ return this.config.get("hasPtz");
50504
+ }
50505
+ async ptzMove(cmd) {
50506
+ if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
50507
+ await this.client.ptzMove({
50508
+ x: cmd.pan,
50509
+ y: cmd.tilt,
50510
+ zoom: cmd.zoom,
50511
+ speed: cmd.speed
50512
+ });
50513
+ }
50514
+ async ptzStop() {
50515
+ if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
50516
+ await this.client.ptzStop();
50517
+ }
50518
+ async getPtzPresets() {
50519
+ if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
50520
+ return (await this.client.getPtzPresets()).map((p) => ({
50521
+ id: p.token,
50522
+ name: p.name
50523
+ }));
50524
+ }
50525
+ async goToPreset(presetId) {
50526
+ if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
50527
+ await this.client.gotoPreset(presetId);
50528
+ }
50529
+ async goHome() {
50530
+ if (!this.client) throw new Error(`OnvifCamera ${this.stableId}: no live client for PTZ`);
50531
+ await this.client.ptzAbsoluteMove({
50532
+ x: 0,
50533
+ y: 0,
50534
+ zoom: 0
50535
+ });
50536
+ }
50537
+ getRtspUrl() {
50538
+ return this.config.get("rtspUrl");
50539
+ }
50540
+ getSubStreamUrl() {
50541
+ return this.config.get("subStreamUrl");
50542
+ }
50543
+ async getStreamSources() {
50544
+ const sources = [];
50545
+ const rtspUrl = this.config.get("rtspUrl");
50546
+ if (rtspUrl) {
50547
+ const videoWidth = this.config.get("videoWidth");
50548
+ const videoHeight = this.config.get("videoHeight");
50549
+ const mainSource = {
50550
+ id: "main",
50551
+ label: "Main Stream",
50552
+ protocol: "rtsp",
50553
+ url: rtspUrl,
50554
+ profileHint: "high",
50555
+ ...videoWidth !== void 0 && videoHeight !== void 0 ? { resolution: {
50556
+ width: videoWidth,
50557
+ height: videoHeight
50558
+ } } : {}
50559
+ };
50560
+ sources.push(mainSource);
50561
+ }
50562
+ const subStreamUrl = this.config.get("subStreamUrl");
50563
+ if (subStreamUrl) {
50564
+ const subVideoWidth = this.config.get("subVideoWidth");
50565
+ const subVideoHeight = this.config.get("subVideoHeight");
50566
+ const subSource = {
50567
+ id: "sub",
50568
+ label: "Sub Stream",
50569
+ protocol: "rtsp",
50570
+ url: subStreamUrl,
50571
+ profileHint: "low",
50572
+ ...subVideoWidth !== void 0 && subVideoHeight !== void 0 ? { resolution: {
50573
+ width: subVideoWidth,
50574
+ height: subVideoHeight
50575
+ } } : {}
50576
+ };
50577
+ sources.push(subSource);
50578
+ }
50579
+ return sources;
50580
+ }
50581
+ /**
50582
+ * Attach a live ONVIF client after the device has been created from DB.
50583
+ * Called by the addon when it successfully connects to the camera on boot.
50584
+ */
50585
+ attachClient(client) {
50586
+ this.client = client;
50587
+ this.online = true;
50588
+ this.startReachabilityPolling();
50589
+ }
50590
+ /** Start the control-plane reachability poll: an ONVIF
50591
+ * `getDeviceInformation` round-trip every 30s drives `online`, with
50592
+ * hysteresis. Replaces the old stream-health→online coupling so a
50593
+ * reachable on-demand camera still reports ONLINE. Re-armed on each
50594
+ * `attachClient` (reconnect) — the prior poll is stopped first. */
50595
+ startReachabilityPolling() {
50596
+ this.reachabilityPoll?.stop();
50597
+ this.reachabilityPoll = startReachabilityPoll({
50598
+ probe: async () => {
50599
+ const client = this.client;
50600
+ if (!client) return false;
50601
+ await client.getDeviceInfo();
50602
+ return true;
50603
+ },
50604
+ setOnline: (online) => {
50605
+ this.markOnline(online);
50606
+ },
50607
+ isEnabled: () => !this.disabled && this.client !== null,
50608
+ logger: this.ctx.logger
50609
+ });
50610
+ }
50611
+ async removeDevice() {
50612
+ this.reachabilityPoll?.stop();
50613
+ this.reachabilityPoll = null;
50614
+ this.client?.disconnect();
50615
+ this.client = null;
50616
+ this.online = false;
50617
+ this.ctx.logger.info("Removed ONVIF camera", { meta: { stableId: this.stableId } });
50618
+ }
50619
+ getSettingsUISchema() {
50620
+ return { sections: [] };
50621
+ }
50622
+ async applySettingsPatch(patch) {
50623
+ await this.config.setAll(patch);
50624
+ }
50625
+ };
50626
+ //#endregion
50350
50627
  //#region src/onvif-discovery.ts
50351
50628
  /**
50352
50629
  * Discovers ONVIF cameras on the local network via WS-Discovery.