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