@camstack/addon-provider-reolink 1.2.148 → 1.2.150
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 +820 -44
- package/dist/addon.mjs +820 -44
- package/package.json +1 -1
package/dist/addon.mjs
CHANGED
|
@@ -5385,7 +5385,7 @@ var ZodIssueCode = {
|
|
|
5385
5385
|
var ZodFirstPartyTypeKind;
|
|
5386
5386
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5387
5387
|
//#endregion
|
|
5388
|
-
//#region ../types/dist/sleep-
|
|
5388
|
+
//#region ../types/dist/sleep-BVhJDJka.mjs
|
|
5389
5389
|
/**
|
|
5390
5390
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5391
5391
|
* window to float samples (D455).
|
|
@@ -6956,6 +6956,18 @@ function systemMethod(input, output, options) {
|
|
|
6956
6956
|
systemOnly: true
|
|
6957
6957
|
};
|
|
6958
6958
|
}
|
|
6959
|
+
/**
|
|
6960
|
+
* A method a SOURCE of a collection cap may legitimately not serve — OPTIONAL
|
|
6961
|
+
* on `InferProvider`. The `providerOptional: true` literal is what
|
|
6962
|
+
* `InferProvider` keys on; see {@link CapabilityMethodSchema.providerOptional}
|
|
6963
|
+
* for when this is the honest answer and when it is a soft stub.
|
|
6964
|
+
*/
|
|
6965
|
+
function optionalMethod(input, output, options) {
|
|
6966
|
+
return {
|
|
6967
|
+
...method(input, output, options),
|
|
6968
|
+
providerOptional: true
|
|
6969
|
+
};
|
|
6970
|
+
}
|
|
6959
6971
|
/** Shorthand to define an event schema */
|
|
6960
6972
|
function event(data) {
|
|
6961
6973
|
return { data };
|
|
@@ -25341,6 +25353,77 @@ var ClipPlaybackSchema = object({
|
|
|
25341
25353
|
* which days it asked for and got nothing — "no clips" would be a lie about a
|
|
25342
25354
|
* card that is full of them.
|
|
25343
25355
|
*/
|
|
25356
|
+
/**
|
|
25357
|
+
* The operator's authorisation to WAKE a sleeping camera for one clip read.
|
|
25358
|
+
*
|
|
25359
|
+
* ONE value, absent by default, and it is a `force`-shaped operator signal in
|
|
25360
|
+
* exactly the sense `snapshot-wake-gate.ts` uses the word: *"`snapshot.getSnapshot`'s
|
|
25361
|
+
* `force` flag, and nothing else… a background caller must never set it…
|
|
25362
|
+
* Stale but honest beats woken"*. A scheduler, a retry, a reconcile and a
|
|
25363
|
+
* prefetch never set it; a surface sets it only behind the same confirm the
|
|
25364
|
+
* "Wake and refresh" gesture uses, and it is refused below 15 % battery
|
|
25365
|
+
* exactly as that gesture is.
|
|
25366
|
+
*
|
|
25367
|
+
* The gate is decided BEFORE `getApi()`, because on UDP the login IS the wake
|
|
25368
|
+
* (D549) — a read that opened a session and then checked would have woken the
|
|
25369
|
+
* camera to find out it was not allowed to.
|
|
25370
|
+
*
|
|
25371
|
+
* **One authorised yes is one wake.** `next-natural` — take the clip the next
|
|
25372
|
+
* time the camera is awake for its own reasons — is deliberately not a member:
|
|
25373
|
+
* it was proposed, it is free on the battery, and the operator declined it on
|
|
25374
|
+
* 2026-09-20 (*"Quando un export viene richiesto si sveglia la camera."*,
|
|
25375
|
+
* D558 "Considered and not taken").
|
|
25376
|
+
*/
|
|
25377
|
+
var ClipWakeSchema = _enum(["authorised"]);
|
|
25378
|
+
/**
|
|
25379
|
+
* Hard ceiling on ONE {@link videoclipsCapability.methods.readClipBytes} — the
|
|
25380
|
+
* same 50 MiB `RECORDING_EXPORT_MAX_READ_BYTES` uses, and for the same second
|
|
25381
|
+
* reason: the envelope is unary, so a base64 payload is held whole (~1.33× its
|
|
25382
|
+
* size) in the provider AND in the caller, on a hub this repo has already
|
|
25383
|
+
* OOM'd once (D9/D18).
|
|
25384
|
+
*
|
|
25385
|
+
* Measured clips sit far below it — 92 KB–2.29 MB for a sub twin, 455 KB for a
|
|
25386
|
+
* 16 s main clip — so the bound bites rarely. "Rarely" is not "never": a long
|
|
25387
|
+
* 4K main twin can exceed it, and above the bound the provider REFUSES with
|
|
25388
|
+
* the size in the message, never truncates. Half a video is worse than an
|
|
25389
|
+
* honest refusal.
|
|
25390
|
+
*
|
|
25391
|
+
* The clean follow-on is a CHUNKED read so a `high` twin of a long clip stops
|
|
25392
|
+
* being refusable at all. That is a later slice, named here so the bound is
|
|
25393
|
+
* not mistaken for a design ceiling.
|
|
25394
|
+
*/
|
|
25395
|
+
var VIDEOCLIPS_MAX_READ_BYTES = 50 * 1024 * 1024;
|
|
25396
|
+
/**
|
|
25397
|
+
* A clip's finished bytes, inline — the twin of `recordingExport.readExportBytes`.
|
|
25398
|
+
*
|
|
25399
|
+
* `bytes` is the DECODED length, so nobody infers it from the base64 length,
|
|
25400
|
+
* and `served` says which twin the caller actually got.
|
|
25401
|
+
*/
|
|
25402
|
+
var ClipBytesSchema = object({
|
|
25403
|
+
base64: string(),
|
|
25404
|
+
contentType: string(),
|
|
25405
|
+
/** Suggested filename, extension included. */
|
|
25406
|
+
name: string(),
|
|
25407
|
+
bytes: number().int().nonnegative(),
|
|
25408
|
+
/**
|
|
25409
|
+
* Which twin was actually served — the same contract
|
|
25410
|
+
* {@link ClipPlaybackSchema.served} carries, and REQUIRED here because the
|
|
25411
|
+
* export record persists it: a row read a week later must say the same thing
|
|
25412
|
+
* the panel said at the moment of the tap. A missing main twin is never
|
|
25413
|
+
* served silently as if it were the asked-for quality (D549 15).
|
|
25414
|
+
*/
|
|
25415
|
+
served: CamProfileSchema,
|
|
25416
|
+
/**
|
|
25417
|
+
* The DECODED duration of the delivered file, when the fetch measured one.
|
|
25418
|
+
*
|
|
25419
|
+
* A clip fetch verifies its own completion against the catalog row and
|
|
25420
|
+
* retries a materially short pass (D568); this is that measurement, carried
|
|
25421
|
+
* so a consumer can say the same thing rather than re-deriving it. Absent
|
|
25422
|
+
* when the producer did not measure — never zero, which would say the file
|
|
25423
|
+
* is empty.
|
|
25424
|
+
*/
|
|
25425
|
+
durationMs: number().positive().optional()
|
|
25426
|
+
});
|
|
25344
25427
|
var ClipSourceAvailabilitySchema = object({
|
|
25345
25428
|
state: _enum([
|
|
25346
25429
|
"ok",
|
|
@@ -25512,6 +25595,68 @@ var videoclipsCapability = {
|
|
|
25512
25595
|
}), ClipPlaybackSchema, {
|
|
25513
25596
|
kind: "query",
|
|
25514
25597
|
auth: "protected"
|
|
25598
|
+
}),
|
|
25599
|
+
/**
|
|
25600
|
+
* This clip's BYTES, base64, bounded — the by-handle read a clip EXPORT
|
|
25601
|
+
* pulls once (D558).
|
|
25602
|
+
*
|
|
25603
|
+
* `getClipPlayback` is the right answer for a player: it hands back a URL
|
|
25604
|
+
* on a plane the hub serves `access:'authenticated'`, which a browser and a
|
|
25605
|
+
* viewer session satisfy. It is the wrong answer for another ADDON. There
|
|
25606
|
+
* is no addon→addon byte transport in this framework — `AddonDataPlane`
|
|
25607
|
+
* only lets an addon SERVE, on `127.0.0.1` behind a per-listener secret
|
|
25608
|
+
* only the hub may present — so a recorder that wants a camera's clip
|
|
25609
|
+
* cannot fetch that URL. This method is the one seam that exists for it,
|
|
25610
|
+
* and it is deliberately the same shape (and the same bound) as
|
|
25611
|
+
* `recordingExport.readExportBytes`, which exists for the mirror-image
|
|
25612
|
+
* reason.
|
|
25613
|
+
*
|
|
25614
|
+
* Routing needs no `provider` pin: the id is source-prefixed and
|
|
25615
|
+
* self-contained, so `device-collection-dispatch.ts` rule 3 hands the call
|
|
25616
|
+
* to the source that claims it — and an id nobody claims is REFUSED rather
|
|
25617
|
+
* than answered by another source.
|
|
25618
|
+
*
|
|
25619
|
+
* The producer reuses the fetch path it already has, completion rules
|
|
25620
|
+
* included: a clip is taken by cmd 5 and finished on a short idle window
|
|
25621
|
+
* whose result is PROVED against the catalog row's own span, retried once
|
|
25622
|
+
* when it comes up materially short, and served-and-named when it is still
|
|
25623
|
+
* short (D568). A second fetch with different completion rules is exactly
|
|
25624
|
+
* the second authority D558 refuses to create.
|
|
25625
|
+
*
|
|
25626
|
+
* Every refusal THROWS with its reason and none of them is silent — the
|
|
25627
|
+
* sleep gate (decided before `getApi()`, liftable only by
|
|
25628
|
+
* {@link ClipWakeSchema}), a catalog row nobody claims, a clip with no
|
|
25629
|
+
* bytes behind it, a mux that failed, and the size bound. The caller turns
|
|
25630
|
+
* that reason into an operator-facing one; a truncated file is never an
|
|
25631
|
+
* answer.
|
|
25632
|
+
*/
|
|
25633
|
+
readClipBytes: optionalMethod(object({
|
|
25634
|
+
deviceId: number(),
|
|
25635
|
+
clipId: string().min(1),
|
|
25636
|
+
/**
|
|
25637
|
+
* Which twin to fetch, on the mapping D549 15 already fixed:
|
|
25638
|
+
* `low | mid` → the sub file, `high` → the main twin. `auto` is not
|
|
25639
|
+
* accepted here for the same reason it is not accepted by
|
|
25640
|
+
* `getClipPlayback` — a stored file has no broker session, so the
|
|
25641
|
+
* adaptive tier cannot be resolved for it.
|
|
25642
|
+
*/
|
|
25643
|
+
profile: CamProfileSchema.optional(),
|
|
25644
|
+
/**
|
|
25645
|
+
* The CALLER's byte bound, so an over-size clip is refused before it is
|
|
25646
|
+
* read and encoded rather than after. Capped by
|
|
25647
|
+
* {@link VIDEOCLIPS_MAX_READ_BYTES} whatever is passed; absent means
|
|
25648
|
+
* that ceiling.
|
|
25649
|
+
*/
|
|
25650
|
+
maxBytes: number().int().positive().optional(),
|
|
25651
|
+
/**
|
|
25652
|
+
* The operator's authorisation to wake a sleeping camera for this
|
|
25653
|
+
* read. Absent — the default — means a sleeping standalone battery
|
|
25654
|
+
* camera is REFUSED by name, before any session is opened.
|
|
25655
|
+
*/
|
|
25656
|
+
wake: ClipWakeSchema.optional()
|
|
25657
|
+
}), ClipBytesSchema, {
|
|
25658
|
+
kind: "query",
|
|
25659
|
+
auth: "protected"
|
|
25515
25660
|
})
|
|
25516
25661
|
}
|
|
25517
25662
|
};
|
|
@@ -33465,13 +33610,101 @@ var ExportStateSchema = _enum([
|
|
|
33465
33610
|
"expired",
|
|
33466
33611
|
"deleted"
|
|
33467
33612
|
]);
|
|
33468
|
-
/**
|
|
33613
|
+
/**
|
|
33614
|
+
* WHAT an export is — the authority, as opposed to the four top-level fields
|
|
33615
|
+
* the Library sorts and labels on (D558 § 2.2).
|
|
33616
|
+
*
|
|
33617
|
+
* Read it through {@link exportSubjectOf}, never off the record directly: the
|
|
33618
|
+
* field is optional for the history rows written before it existed, and that
|
|
33619
|
+
* absence has exactly one interpreter.
|
|
33620
|
+
*/
|
|
33621
|
+
var ExportSubjectSchema = discriminatedUnion("kind", [object({
|
|
33622
|
+
kind: literal("footage"),
|
|
33623
|
+
deviceId: number(),
|
|
33624
|
+
profiles: array(string()).min(1),
|
|
33625
|
+
fromMs: number(),
|
|
33626
|
+
toMs: number()
|
|
33627
|
+
}), object({
|
|
33628
|
+
kind: literal("clip"),
|
|
33629
|
+
deviceId: number(),
|
|
33630
|
+
provider: string().min(1),
|
|
33631
|
+
source: string().min(1),
|
|
33632
|
+
sourceLabel: string().min(1),
|
|
33633
|
+
clipId: string().min(1),
|
|
33634
|
+
/**
|
|
33635
|
+
* WHERE IN THE CATALOG to confirm this clip — the day window the surface was
|
|
33636
|
+
* already listing when the operator picked the segment.
|
|
33637
|
+
*
|
|
33638
|
+
* It is **not** a time range control and it never becomes one: the record's
|
|
33639
|
+
* `fromMs`/`toMs` come from the catalog ROW and from nothing a caller
|
|
33640
|
+
* supplied (D558 § 5.4.3), and a window that does not contain the clip is a
|
|
33641
|
+
* `catalog-miss`, not a silently wider search. It exists because
|
|
33642
|
+
* `videoclips.listClips` takes `since`/`until` and has no by-handle twin:
|
|
33643
|
+
* the catalog check D558 asks for is literally that call, and a call needs a
|
|
33644
|
+
* window. The surface has one — `ClipsBrowser`'s `dayWindow`, one local
|
|
33645
|
+
* wall-clock day, which is also the only width measured to be cheap (one
|
|
33646
|
+
* day on 592 lists 171 clips in 712 ms, a busy day 546 in 2.0 s; twenty days
|
|
33647
|
+
* of one child's events took 3.6–5.4 s).
|
|
33648
|
+
*/
|
|
33649
|
+
catalogWindow: object({
|
|
33650
|
+
sinceMs: number(),
|
|
33651
|
+
untilMs: number()
|
|
33652
|
+
}),
|
|
33653
|
+
profile: _enum([
|
|
33654
|
+
"high",
|
|
33655
|
+
"mid",
|
|
33656
|
+
"low"
|
|
33657
|
+
]),
|
|
33658
|
+
/**
|
|
33659
|
+
* The operator's authorisation to wake a sleeping camera for this export.
|
|
33660
|
+
* ONE definition, in the cap that owns the clip read ({@link ClipWakeSchema}),
|
|
33661
|
+
* because the gate that honours it is the clip provider's sleep gate — a
|
|
33662
|
+
* second enum here would be a second contract. Absent by default; never
|
|
33663
|
+
* settable by a scheduler or a retry.
|
|
33664
|
+
*
|
|
33665
|
+
* **One authorised yes is ONE wake.** A failed clip export is retried only by
|
|
33666
|
+
* an operator act that asks again; a queued job that outlived its wake fails
|
|
33667
|
+
* with a reason rather than waking on its turn; and this subject carries
|
|
33668
|
+
* exactly one profile precisely so one tap is never two fetches (D558 § 5.2).
|
|
33669
|
+
*/
|
|
33670
|
+
wake: ClipWakeSchema.optional()
|
|
33671
|
+
})]);
|
|
33672
|
+
/**
|
|
33673
|
+
* One export job / history row.
|
|
33674
|
+
*
|
|
33675
|
+
* **`subject` is the AUTHORITY on what was exported. `deviceId`, `profile`,
|
|
33676
|
+
* `fromMs` and `toMs` are its PROJECTION** — kept top-level because the whole
|
|
33677
|
+
* Library sorts and labels on them (`library-items.ts` orders an export by
|
|
33678
|
+
* `fromMs`; `export-format.ts` draws `rangeLabel` from the pair), and a row
|
|
33679
|
+
* that did not fill them would sort under the epoch and render a blank range.
|
|
33680
|
+
* Write to the subject and read from the projection and the two will disagree;
|
|
33681
|
+
* the projection is derived at creation and never edited afterwards.
|
|
33682
|
+
*
|
|
33683
|
+
* And they mean DIFFERENT FACTS for the two kinds, which is the part a reader
|
|
33684
|
+
* who knows only the recording export will get wrong:
|
|
33685
|
+
*
|
|
33686
|
+
* | field | `kind:'footage'` | `kind:'clip'` |
|
|
33687
|
+
* | --- | --- | --- |
|
|
33688
|
+
* | `fromMs`/`toMs` | the stretch the operator ASKED for | the camera's own boundaries, always `clip.timeRange`, never anything a caller supplied |
|
|
33689
|
+
* | `profile` | the stream rendered | the twin actually SERVED (`subject.profile` is the one asked for) |
|
|
33690
|
+
*
|
|
33691
|
+
* Same type, different fact — the shape this repo keeps getting wrong (D385's
|
|
33692
|
+
* two authorities, D224's second copy).
|
|
33693
|
+
*/
|
|
33469
33694
|
var ExportRecordSchema = object({
|
|
33470
33695
|
id: string(),
|
|
33471
33696
|
deviceId: number(),
|
|
33472
33697
|
profile: string(),
|
|
33473
33698
|
fromMs: number(),
|
|
33474
33699
|
toMs: number(),
|
|
33700
|
+
/**
|
|
33701
|
+
* What this export IS. Optional ONLY for the rows written before D558: the
|
|
33702
|
+
* store parses every row through this schema on every read, so a required
|
|
33703
|
+
* field would make the export AUDIT — which is the whole reason rows survive
|
|
33704
|
+
* file deletion — unreadable in one release. Absence means `footage`, and
|
|
33705
|
+
* {@link exportSubjectOf} is the one place that says so.
|
|
33706
|
+
*/
|
|
33707
|
+
subject: ExportSubjectSchema.optional(),
|
|
33475
33708
|
options: ExportOptionsSchema,
|
|
33476
33709
|
state: ExportStateSchema,
|
|
33477
33710
|
/** 0–100 while rendering; null otherwise. */
|
|
@@ -33488,6 +33721,22 @@ var ExportRecordSchema = object({
|
|
|
33488
33721
|
/** Failure reason when state is 'failed'; null otherwise. */
|
|
33489
33722
|
error: string().nullable()
|
|
33490
33723
|
});
|
|
33724
|
+
_enum([
|
|
33725
|
+
"catalog-miss",
|
|
33726
|
+
"catalog-unreachable",
|
|
33727
|
+
"no-file-for-window",
|
|
33728
|
+
"clip-in-progress",
|
|
33729
|
+
"unsupported-option",
|
|
33730
|
+
"sleeping",
|
|
33731
|
+
"camera-refused",
|
|
33732
|
+
"fetch-failed",
|
|
33733
|
+
"too-large-to-transfer",
|
|
33734
|
+
"wake-expired"
|
|
33735
|
+
]);
|
|
33736
|
+
/** `<token>: <prose>` — the ONE composition of a clip export's failure string. */
|
|
33737
|
+
function clipExportFailure(code, detail) {
|
|
33738
|
+
return detail.length > 0 ? `${code}: ${detail}` : code;
|
|
33739
|
+
}
|
|
33491
33740
|
/** Candidate download URLs (LAN first, then operator extra hosts). */
|
|
33492
33741
|
var ExportDownloadSchema = object({
|
|
33493
33742
|
url: string(),
|
|
@@ -33506,16 +33755,50 @@ var ExportBytesSchema = object({
|
|
|
33506
33755
|
name: string(),
|
|
33507
33756
|
bytes: number().int().nonnegative()
|
|
33508
33757
|
});
|
|
33758
|
+
/** Canonical `profiles[]`, falling back to the legacy singular `profile`. */
|
|
33759
|
+
function resolveExportProfiles(input) {
|
|
33760
|
+
if (input.profiles !== void 0 && input.profiles.length > 0) return [...input.profiles];
|
|
33761
|
+
if (typeof input.profile === "string" && input.profile.length > 0) return [input.profile];
|
|
33762
|
+
return [];
|
|
33763
|
+
}
|
|
33509
33764
|
method(object({
|
|
33510
33765
|
deviceId: number(),
|
|
33511
33766
|
/** @deprecated Prefer `profiles`. Kept so timelapse/notifiers keep working. */
|
|
33512
33767
|
profile: string().optional(),
|
|
33513
33768
|
profiles: array(string()).min(1).optional(),
|
|
33514
|
-
|
|
33515
|
-
|
|
33769
|
+
/** Footage only — a clip's boundaries are the camera's. */
|
|
33770
|
+
fromMs: number().optional(),
|
|
33771
|
+
toMs: number().optional(),
|
|
33772
|
+
/** What to export. Absent means the legacy flat footage request. */
|
|
33773
|
+
subject: ExportSubjectSchema.optional(),
|
|
33516
33774
|
options: ExportOptionsSchema
|
|
33517
33775
|
}).superRefine((v, ctx) => {
|
|
33518
|
-
if (
|
|
33776
|
+
if (v.subject?.kind === "clip") {
|
|
33777
|
+
if (v.subject.deviceId !== v.deviceId) ctx.addIssue({
|
|
33778
|
+
code: ZodIssueCode.custom,
|
|
33779
|
+
message: `subject.deviceId (${v.subject.deviceId}) must equal deviceId (${v.deviceId}) — the top-level field is what per-device scope enforcement reads`,
|
|
33780
|
+
path: ["subject", "deviceId"]
|
|
33781
|
+
});
|
|
33782
|
+
if (v.fromMs !== void 0 || v.toMs !== void 0) ctx.addIssue({
|
|
33783
|
+
code: ZodIssueCode.custom,
|
|
33784
|
+
message: "a clip export asks for no time range: the camera chose the boundaries and they are read from the catalog row",
|
|
33785
|
+
path: ["fromMs"]
|
|
33786
|
+
});
|
|
33787
|
+
return;
|
|
33788
|
+
}
|
|
33789
|
+
if (v.subject?.kind === "footage" && v.subject.deviceId !== v.deviceId) ctx.addIssue({
|
|
33790
|
+
code: ZodIssueCode.custom,
|
|
33791
|
+
message: `subject.deviceId (${v.subject.deviceId}) must equal deviceId (${v.deviceId})`,
|
|
33792
|
+
path: ["subject", "deviceId"]
|
|
33793
|
+
});
|
|
33794
|
+
const fromMs = v.subject?.kind === "footage" ? v.subject.fromMs : v.fromMs;
|
|
33795
|
+
const toMs = v.subject?.kind === "footage" ? v.subject.toMs : v.toMs;
|
|
33796
|
+
if (typeof fromMs !== "number" || typeof toMs !== "number") ctx.addIssue({
|
|
33797
|
+
code: ZodIssueCode.custom,
|
|
33798
|
+
message: "a footage export needs fromMs and toMs",
|
|
33799
|
+
path: ["fromMs"]
|
|
33800
|
+
});
|
|
33801
|
+
if ((v.subject?.kind === "footage" ? [...v.subject.profiles] : resolveExportProfiles(v)).length < 1) ctx.addIssue({
|
|
33519
33802
|
code: ZodIssueCode.custom,
|
|
33520
33803
|
message: "pass profiles[] (min 1) or legacy profile",
|
|
33521
33804
|
path: ["profiles"]
|
|
@@ -44057,6 +44340,12 @@ Object.freeze({
|
|
|
44057
44340
|
addonId: null,
|
|
44058
44341
|
access: "view"
|
|
44059
44342
|
},
|
|
44343
|
+
"videoclips.readClipBytes": {
|
|
44344
|
+
capName: "videoclips",
|
|
44345
|
+
capScope: "device",
|
|
44346
|
+
addonId: null,
|
|
44347
|
+
access: "view"
|
|
44348
|
+
},
|
|
44060
44349
|
"viewerUi.getStaticDir": {
|
|
44061
44350
|
capName: "viewer-ui",
|
|
44062
44351
|
capScope: "system",
|
|
@@ -46075,6 +46364,11 @@ Object.freeze({
|
|
|
46075
46364
|
form: "single",
|
|
46076
46365
|
optional: false
|
|
46077
46366
|
}],
|
|
46367
|
+
"videoclips.readClipBytes": [{
|
|
46368
|
+
name: "deviceId",
|
|
46369
|
+
form: "single",
|
|
46370
|
+
optional: false
|
|
46371
|
+
}],
|
|
46078
46372
|
"waterHeater.setAway": [{
|
|
46079
46373
|
name: "deviceId",
|
|
46080
46374
|
form: "single",
|
|
@@ -147640,6 +147934,21 @@ var ClipArtifactStore = class {
|
|
|
147640
147934
|
};
|
|
147641
147935
|
//#endregion
|
|
147642
147936
|
//#region src/clips/clip-addressing.ts
|
|
147937
|
+
/**
|
|
147938
|
+
* The camera's uid, from the fresh copy where there is one.
|
|
147939
|
+
*
|
|
147940
|
+
* An empty or whitespace-only value is ABSENT, never a uid: it is how a
|
|
147941
|
+
* cleared settings field arrives, and passed on it addresses no camera at all
|
|
147942
|
+
* while making the refusal name the wrong cause.
|
|
147943
|
+
*/
|
|
147944
|
+
function resolveCameraUid(sources) {
|
|
147945
|
+
return usable(sources.metadataUid) ?? usable(sources.configUid);
|
|
147946
|
+
}
|
|
147947
|
+
function usable(value) {
|
|
147948
|
+
if (typeof value !== "string") return void 0;
|
|
147949
|
+
const trimmed = value.trim();
|
|
147950
|
+
return trimmed.length === 0 ? void 0 : trimmed;
|
|
147951
|
+
}
|
|
147643
147952
|
/** Does addressing this camera's catalog REQUIRE a persisted uid? */
|
|
147644
147953
|
function uidIsRequired(subject) {
|
|
147645
147954
|
return subject.isHubChild;
|
|
@@ -148434,6 +148743,43 @@ var ClipThumbQueue = class {
|
|
|
148434
148743
|
}
|
|
148435
148744
|
};
|
|
148436
148745
|
//#endregion
|
|
148746
|
+
//#region src/clips/clip-prefetch.ts
|
|
148747
|
+
/** The longest a device may stay quiet after refusals, whatever its interval. */
|
|
148748
|
+
var PREFETCH_QUIET_MAX_MS = 720 * 6e4;
|
|
148749
|
+
/**
|
|
148750
|
+
* How long a device that refused stays un-asked, in INTERVALS rather than
|
|
148751
|
+
* wall-clock: the refresh interval is an operator setting (5 min – 24 h), and
|
|
148752
|
+
* a quiet period in minutes would be either no gap at all at one end or a day
|
|
148753
|
+
* at the other. One refusal skips the next two passes, two skips four, and so
|
|
148754
|
+
* on, capped.
|
|
148755
|
+
*/
|
|
148756
|
+
function prefetchQuietMs(consecutiveRefusals, intervalMs) {
|
|
148757
|
+
if (consecutiveRefusals <= 0) return 0;
|
|
148758
|
+
const doubled = intervalMs * 2 ** consecutiveRefusals;
|
|
148759
|
+
return Number.isFinite(doubled) ? Math.min(doubled, PREFETCH_QUIET_MAX_MS) : PREFETCH_QUIET_MAX_MS;
|
|
148760
|
+
}
|
|
148761
|
+
/**
|
|
148762
|
+
* May this camera's stills be prefetched right now?
|
|
148763
|
+
*
|
|
148764
|
+
* The topology comes first and is absolute: no amount of idle host or empty
|
|
148765
|
+
* ladder makes a still on a standalone battery camera free.
|
|
148766
|
+
*/
|
|
148767
|
+
function decideClipPrefetch(input) {
|
|
148768
|
+
if (input.mode === "forced-wake") return {
|
|
148769
|
+
kind: "skip",
|
|
148770
|
+
reason: "battery-wake-cost"
|
|
148771
|
+
};
|
|
148772
|
+
if (input.quiet) return {
|
|
148773
|
+
kind: "skip",
|
|
148774
|
+
reason: "quiet-after-refusal"
|
|
148775
|
+
};
|
|
148776
|
+
if (input.hostBusy) return {
|
|
148777
|
+
kind: "skip",
|
|
148778
|
+
reason: "host-busy"
|
|
148779
|
+
};
|
|
148780
|
+
return { kind: "run" };
|
|
148781
|
+
}
|
|
148782
|
+
//#endregion
|
|
148437
148783
|
//#region src/clips/clip-identity.ts
|
|
148438
148784
|
/**
|
|
148439
148785
|
* A Reolink clip's IDENTITY — the id the operator's surface carries around and
|
|
@@ -149025,6 +149371,18 @@ function normaliseHour(hour) {
|
|
|
149025
149371
|
}
|
|
149026
149372
|
//#endregion
|
|
149027
149373
|
//#region src/clips/reolink-videoclips-provider.ts
|
|
149374
|
+
/**
|
|
149375
|
+
* The filename an export carries away, from the camera's own handle.
|
|
149376
|
+
*
|
|
149377
|
+
* A hub child's handle is a full path (`/mnt/sda/U10…/RecS02_….mp4`) and a
|
|
149378
|
+
* standalone's is a bare name, so only the last segment is a name; the
|
|
149379
|
+
* extension is re-stated because what we produce is an MP4 whatever the
|
|
149380
|
+
* camera called its file.
|
|
149381
|
+
*/
|
|
149382
|
+
function clipFileLabel(fileName) {
|
|
149383
|
+
const stem = (fileName.split("/").at(-1) ?? fileName).replace(/\.[^.]+$/, "");
|
|
149384
|
+
return `${stem === "" ? "clip" : stem}.mp4`;
|
|
149385
|
+
}
|
|
149028
149386
|
function createReolinkVideoclipsProvider(deps) {
|
|
149029
149387
|
/** Last known availability per `deviceId|source`, written by every read. */
|
|
149030
149388
|
const health = /* @__PURE__ */ new Map();
|
|
@@ -149345,6 +149703,120 @@ function createReolinkVideoclipsProvider(deps) {
|
|
|
149345
149703
|
format: "mp4",
|
|
149346
149704
|
served: prepared.served
|
|
149347
149705
|
};
|
|
149706
|
+
},
|
|
149707
|
+
/**
|
|
149708
|
+
* This clip's BYTES, base64, bounded — the producing half of a clip
|
|
149709
|
+
* export (D558 § 3, D572).
|
|
149710
|
+
*
|
|
149711
|
+
* ## What it refuses, and in whose words
|
|
149712
|
+
*
|
|
149713
|
+
* Every exit throws `clipExportFailure(<token>, <prose>)`. The engine
|
|
149714
|
+
* recovers the token with `clipExportFailureOf` and BELIEVES it; anything
|
|
149715
|
+
* that does not parse becomes `fetch-failed` with the prose kept verbatim.
|
|
149716
|
+
* So a refusal this side can name is named here — a `sleeping` that
|
|
149717
|
+
* arrives as prose is a `sleeping` the modal cannot render.
|
|
149718
|
+
*
|
|
149719
|
+
* ## The order of the questions, and why it is this order
|
|
149720
|
+
*
|
|
149721
|
+
* The cheap ones come first and none of them touches the camera: the id,
|
|
149722
|
+
* the row, whether the file is still being written, which twin exists, and
|
|
149723
|
+
* the SIZE the catalog already declared for it. A main twin over the bound
|
|
149724
|
+
* is refused for nothing — no session, no transfer, no mux — which is the
|
|
149725
|
+
* rule bulk work over stored media already follows (D54). Only then does
|
|
149726
|
+
* `prepareBytes` reach a camera, behind the sleep gate that has to sit in
|
|
149727
|
+
* front of the login.
|
|
149728
|
+
*
|
|
149729
|
+
* ## `high` against a 50 MiB ceiling
|
|
149730
|
+
*
|
|
149731
|
+
* A missing main twin is a DIVERGENCE, not a refusal: the sub is served
|
|
149732
|
+
* and `served` says `low`, exactly as the player does (D549 15), because
|
|
149733
|
+
* 17 of 546 clips on 592 have no main copy and an export of the copy that
|
|
149734
|
+
* exists beats no export. A main twin that exists and is too BIG is the
|
|
149735
|
+
* other case and is refused by name — the cap's own docblock settles it
|
|
149736
|
+
* ("above the bound the provider REFUSES with the size in the message,
|
|
149737
|
+
* never truncates"), the operator keeps the unbounded playback route for
|
|
149738
|
+
* that file, and the chunked read the cap names is what removes the
|
|
149739
|
+
* refusal rather than a silent 33× quality substitution.
|
|
149740
|
+
*/
|
|
149741
|
+
readClipBytes: async ({ deviceId, clipId, profile, maxBytes, wake }) => {
|
|
149742
|
+
const tags = { deviceId };
|
|
149743
|
+
const refuse = (code, detail, meta) => {
|
|
149744
|
+
deps.logger.warn("videoclips: refusing a clip byte read", {
|
|
149745
|
+
tags,
|
|
149746
|
+
meta: {
|
|
149747
|
+
clipId,
|
|
149748
|
+
branch: code,
|
|
149749
|
+
...meta
|
|
149750
|
+
}
|
|
149751
|
+
});
|
|
149752
|
+
throw new Error(clipExportFailure(code, detail));
|
|
149753
|
+
};
|
|
149754
|
+
const parsed = parseClipId(clipId);
|
|
149755
|
+
if (parsed === null) return refuse("catalog-miss", `clip id "${clipId}" was not minted by the Reolink provider`, {});
|
|
149756
|
+
const clipKey = clipKeyFor(parsed.channel, parsed.fileName);
|
|
149757
|
+
const row = rowsByKey.get(`${deviceId}|${clipKey}`);
|
|
149758
|
+
if (row === void 0) return refuse("catalog-miss", `clip "${clipId}" is not in this node's catalog for device ${deviceId} — list the day that holds it first`, { clipKey });
|
|
149759
|
+
if (row.inProgress === true) return refuse("clip-in-progress", `clip "${clipId}" is still being written, so it has no end to export`, { clipKey });
|
|
149760
|
+
const mainFileName = profile === "high" ? row.mainFileName : void 0;
|
|
149761
|
+
if (profile === "high" && mainFileName === void 0) deps.logger.warn("videoclips: no main twin for this clip — serving the sub copy", {
|
|
149762
|
+
tags,
|
|
149763
|
+
meta: {
|
|
149764
|
+
clipId,
|
|
149765
|
+
clipKey,
|
|
149766
|
+
branch: "no-main-twin",
|
|
149767
|
+
asked: profile
|
|
149768
|
+
}
|
|
149769
|
+
});
|
|
149770
|
+
const twin = mainFileName === void 0 ? "sub" : "main";
|
|
149771
|
+
const fileName = mainFileName ?? row.subFileName;
|
|
149772
|
+
if (fileName === "") return refuse("no-file-for-window", `clip "${clipId}" is listed with no byte handle behind it`, {
|
|
149773
|
+
clipKey,
|
|
149774
|
+
twin
|
|
149775
|
+
});
|
|
149776
|
+
const served = twin === "main" ? "high" : "low";
|
|
149777
|
+
const bound = Math.min(maxBytes ?? 52428800, VIDEOCLIPS_MAX_READ_BYTES);
|
|
149778
|
+
const declaredBytes = twin === "main" ? row.mainBytes : row.subBytes;
|
|
149779
|
+
if (declaredBytes !== void 0 && declaredBytes > bound) return refuse("too-large-to-transfer", `the camera lists the ${twin} file of clip "${clipId}" as ${declaredBytes} bytes, over the ${bound}-byte bound for an inline read — play it from its playback URL instead`, {
|
|
149780
|
+
clipKey,
|
|
149781
|
+
twin,
|
|
149782
|
+
declaredBytes,
|
|
149783
|
+
bound
|
|
149784
|
+
});
|
|
149785
|
+
const outcome = await deps.prepareBytes({
|
|
149786
|
+
deviceId,
|
|
149787
|
+
row,
|
|
149788
|
+
fileName,
|
|
149789
|
+
twin,
|
|
149790
|
+
...wake !== void 0 ? { wake } : {}
|
|
149791
|
+
});
|
|
149792
|
+
if (outcome.kind === "refused") throw new Error(clipExportFailure(outcome.code, outcome.detail));
|
|
149793
|
+
if (outcome.bytes.byteLength > bound) return refuse("too-large-to-transfer", `clip "${clipId}" muxed to ${outcome.bytes.byteLength} bytes, over the ${bound}-byte bound for an inline read`, {
|
|
149794
|
+
clipKey,
|
|
149795
|
+
twin,
|
|
149796
|
+
bytes: outcome.bytes.byteLength,
|
|
149797
|
+
bound
|
|
149798
|
+
});
|
|
149799
|
+
deps.logger.info("videoclips: served a Reolink clip inline", {
|
|
149800
|
+
tags,
|
|
149801
|
+
meta: {
|
|
149802
|
+
clipId,
|
|
149803
|
+
clipKey,
|
|
149804
|
+
twin,
|
|
149805
|
+
served,
|
|
149806
|
+
asked: profile ?? null,
|
|
149807
|
+
bytes: outcome.bytes.byteLength,
|
|
149808
|
+
durationMs: outcome.durationMs,
|
|
149809
|
+
wake: wake ?? "none"
|
|
149810
|
+
}
|
|
149811
|
+
});
|
|
149812
|
+
return {
|
|
149813
|
+
base64: outcome.bytes.toString("base64"),
|
|
149814
|
+
contentType: "video/mp4",
|
|
149815
|
+
name: clipFileLabel(fileName),
|
|
149816
|
+
bytes: outcome.bytes.byteLength,
|
|
149817
|
+
served,
|
|
149818
|
+
...outcome.durationMs !== null ? { durationMs: outcome.durationMs } : {}
|
|
149819
|
+
};
|
|
149348
149820
|
}
|
|
149349
149821
|
};
|
|
149350
149822
|
/**
|
|
@@ -149606,6 +150078,12 @@ var ClipCatalogRefreshScheduler = class {
|
|
|
149606
150078
|
lastRunAt = /* @__PURE__ */ new Map();
|
|
149607
150079
|
/** Cameras whose refresh has not come back yet. */
|
|
149608
150080
|
inFlight = /* @__PURE__ */ new Set();
|
|
150081
|
+
/** Consecutive prefetch passes this camera stopped on a refusal. Cleared by
|
|
150082
|
+
* the first pass that lands, so a camera that recovers is asked again on
|
|
150083
|
+
* the very next tick. */
|
|
150084
|
+
prefetchRefusals = /* @__PURE__ */ new Map();
|
|
150085
|
+
/** Until when this camera's prefetch stays un-asked. */
|
|
150086
|
+
prefetchQuietUntil = /* @__PURE__ */ new Map();
|
|
149609
150087
|
constructor(deps) {
|
|
149610
150088
|
this.deps = deps;
|
|
149611
150089
|
}
|
|
@@ -149675,6 +150153,7 @@ var ClipCatalogRefreshScheduler = class {
|
|
|
149675
150153
|
elapsedMs: this.deps.now() - now
|
|
149676
150154
|
}
|
|
149677
150155
|
});
|
|
150156
|
+
await this.prefetch(target, mode);
|
|
149678
150157
|
} catch (err) {
|
|
149679
150158
|
this.deps.markStale(target.deviceId);
|
|
149680
150159
|
this.deps.logger.warn("videoclips: catalog refresh failed — the catalog stays as it was", {
|
|
@@ -149689,10 +150168,92 @@ var ClipCatalogRefreshScheduler = class {
|
|
|
149689
150168
|
this.inFlight.delete(target.deviceId);
|
|
149690
150169
|
}
|
|
149691
150170
|
}
|
|
150171
|
+
/**
|
|
150172
|
+
* The still prefetch for a camera whose catalog was just re-read.
|
|
150173
|
+
*
|
|
150174
|
+
* It NEVER throws — a prefetch is an enhancement to a refresh that already
|
|
150175
|
+
* landed, and letting it reach the refresh's own catch would mark a catalog
|
|
150176
|
+
* stale that is not. Every exit says which branch it took, per camera.
|
|
150177
|
+
*/
|
|
150178
|
+
async prefetch(target, mode) {
|
|
150179
|
+
const deviceId = target.deviceId;
|
|
150180
|
+
const tags = { deviceId };
|
|
150181
|
+
const quietUntil = this.prefetchQuietUntil.get(deviceId) ?? 0;
|
|
150182
|
+
const decision = decideClipPrefetch({
|
|
150183
|
+
mode,
|
|
150184
|
+
hostBusy: this.deps.hostBusy(target.hostKey),
|
|
150185
|
+
quiet: quietUntil > this.deps.now()
|
|
150186
|
+
});
|
|
150187
|
+
if (decision.kind === "skip") {
|
|
150188
|
+
this.deps.logger.info("videoclips: still prefetch skipped", {
|
|
150189
|
+
tags,
|
|
150190
|
+
meta: {
|
|
150191
|
+
branch: `prefetch-${decision.reason}`,
|
|
150192
|
+
mode,
|
|
150193
|
+
host: target.hostKey,
|
|
150194
|
+
quietForMs: Math.max(0, quietUntil - this.deps.now())
|
|
150195
|
+
}
|
|
150196
|
+
});
|
|
150197
|
+
return;
|
|
150198
|
+
}
|
|
150199
|
+
try {
|
|
150200
|
+
const outcome = await this.deps.prefetchStills(deviceId);
|
|
150201
|
+
if (outcome.stop === "refused") {
|
|
150202
|
+
this.quieten(target, {
|
|
150203
|
+
branch: "prefetch-refused",
|
|
150204
|
+
mode,
|
|
150205
|
+
minted: outcome.minted,
|
|
150206
|
+
scanned: outcome.scanned,
|
|
150207
|
+
alreadyHeld: outcome.alreadyHeld,
|
|
150208
|
+
code: outcome.refusal?.code ?? null,
|
|
150209
|
+
disposition: outcome.refusal?.disposition ?? null,
|
|
150210
|
+
clipKey: outcome.refusal?.clipKey ?? null
|
|
150211
|
+
});
|
|
150212
|
+
return;
|
|
150213
|
+
}
|
|
150214
|
+
this.prefetchRefusals.delete(deviceId);
|
|
150215
|
+
this.prefetchQuietUntil.delete(deviceId);
|
|
150216
|
+
this.deps.logger.info("videoclips: stills prefetched", {
|
|
150217
|
+
tags,
|
|
150218
|
+
meta: {
|
|
150219
|
+
branch: `prefetch-${outcome.stop}`,
|
|
150220
|
+
mode,
|
|
150221
|
+
minted: outcome.minted,
|
|
150222
|
+
scanned: outcome.scanned,
|
|
150223
|
+
alreadyHeld: outcome.alreadyHeld
|
|
150224
|
+
}
|
|
150225
|
+
});
|
|
150226
|
+
} catch (err) {
|
|
150227
|
+
this.quieten(target, {
|
|
150228
|
+
branch: "prefetch-failed",
|
|
150229
|
+
mode,
|
|
150230
|
+
error: errMessage$1(err)
|
|
150231
|
+
});
|
|
150232
|
+
}
|
|
150233
|
+
}
|
|
150234
|
+
/** Arm the doubling quiet period and say so, with what the pass reported. */
|
|
150235
|
+
quieten(target, meta) {
|
|
150236
|
+
const deviceId = target.deviceId;
|
|
150237
|
+
const refusals = (this.prefetchRefusals.get(deviceId) ?? 0) + 1;
|
|
150238
|
+
this.prefetchRefusals.set(deviceId, refusals);
|
|
150239
|
+
const quietForMs = prefetchQuietMs(refusals, target.intervalMinutes * 6e4);
|
|
150240
|
+
this.prefetchQuietUntil.set(deviceId, this.deps.now() + quietForMs);
|
|
150241
|
+
this.deps.logger.warn("videoclips: still prefetch stopped — the host is not serving stills", {
|
|
150242
|
+
tags: { deviceId },
|
|
150243
|
+
meta: {
|
|
150244
|
+
...meta,
|
|
150245
|
+
host: target.hostKey,
|
|
150246
|
+
consecutiveRefusals: refusals,
|
|
150247
|
+
quietForMs
|
|
150248
|
+
}
|
|
150249
|
+
});
|
|
150250
|
+
}
|
|
149692
150251
|
};
|
|
149693
150252
|
function errMessage$1(err) {
|
|
149694
150253
|
return err instanceof Error ? err.message : String(err);
|
|
149695
150254
|
}
|
|
150255
|
+
//#endregion
|
|
150256
|
+
//#region src/clips/clip-service.ts
|
|
149696
150257
|
function createClipService(deps) {
|
|
149697
150258
|
const now = deps.now ?? (() => Date.now());
|
|
149698
150259
|
const cache = new ClipCatalogCache({ now });
|
|
@@ -149715,8 +150276,15 @@ function createClipService(deps) {
|
|
|
149715
150276
|
ffmpegBinaryPath: deps.ffmpegBinaryPath ?? "ffmpeg",
|
|
149716
150277
|
spawnFn: spawn$1
|
|
149717
150278
|
});
|
|
149718
|
-
/**
|
|
149719
|
-
|
|
150279
|
+
/**
|
|
150280
|
+
* One production per `(device, clip, twin)`: two clicks on one row — or a
|
|
150281
|
+
* click and an EXPORT of the same row — must not pay cmd 5 twice. It is
|
|
150282
|
+
* keyed by the twin because the two files are different bytes, and it is
|
|
150283
|
+
* shared by the player and the byte read because those two are the only
|
|
150284
|
+
* callers there are: an in-flight map per caller would be a second wake on
|
|
150285
|
+
* a battery camera the operator authorised once.
|
|
150286
|
+
*/
|
|
150287
|
+
const producing = /* @__PURE__ */ new Map();
|
|
149720
150288
|
const rowFor = (deviceId, clipKey) => {
|
|
149721
150289
|
return cache.findBy(deviceId, (row) => row.clipKey === clipKey);
|
|
149722
150290
|
};
|
|
@@ -149783,14 +150351,14 @@ function createClipService(deps) {
|
|
|
149783
150351
|
* transfer, and that window is short. What makes it safe is not the window,
|
|
149784
150352
|
* it is the decoded duration judged against the row that asked for it.
|
|
149785
150353
|
*/
|
|
149786
|
-
const fetchVerifiedClipBytes = async (device, row, clipKey) => {
|
|
150354
|
+
const fetchVerifiedClipBytes = async (device, row, clipKey, fileName) => {
|
|
149787
150355
|
const deviceId = device.deviceId;
|
|
149788
150356
|
const api = await device.getApi();
|
|
149789
150357
|
const fetchPass = (idleTimeoutMs) => fetchClipBytes({
|
|
149790
150358
|
download: () => api.downloadRecordingDemuxed({
|
|
149791
150359
|
channel: device.channel,
|
|
149792
150360
|
...device.uid !== void 0 ? { uid: device.uid } : {},
|
|
149793
|
-
fileName
|
|
150361
|
+
fileName,
|
|
149794
150362
|
idleTimeoutMs
|
|
149795
150363
|
}),
|
|
149796
150364
|
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
@@ -149865,43 +150433,100 @@ function createClipService(deps) {
|
|
|
149865
150433
|
});
|
|
149866
150434
|
return kept;
|
|
149867
150435
|
};
|
|
149868
|
-
|
|
149869
|
-
|
|
149870
|
-
|
|
149871
|
-
|
|
149872
|
-
|
|
149873
|
-
|
|
149874
|
-
|
|
149875
|
-
|
|
149876
|
-
|
|
149877
|
-
|
|
149878
|
-
|
|
149879
|
-
|
|
149880
|
-
|
|
150436
|
+
/**
|
|
150437
|
+
* ONE production of one twin's MP4 — the only place a clip's bytes are made.
|
|
150438
|
+
*
|
|
150439
|
+
* The player and `readClipBytes` are both served from here, which is the
|
|
150440
|
+
* whole point: D568's completion rules (the 300 ms window, the decoded
|
|
150441
|
+
* duration proved against the row, the single retry on 2 000 ms) and D567's
|
|
150442
|
+
* mux (the MEASURED rate, the AAC copy, `+faststart`) exist once. A byte
|
|
150443
|
+
* read with its own fetch would be the second authority those records were
|
|
150444
|
+
* written to prevent.
|
|
150445
|
+
*
|
|
150446
|
+
* It never throws for a gated branch: every exit is a NAMED refusal in the
|
|
150447
|
+
* clip-export vocabulary, so the provider can hand the engine a token it
|
|
150448
|
+
* believes rather than prose it has to guess at (D572).
|
|
150449
|
+
*/
|
|
150450
|
+
const produceTwin = async (input) => {
|
|
150451
|
+
const { deviceId, row, fileName, twin } = input;
|
|
150452
|
+
const clipKey = row.clipKey;
|
|
150453
|
+
const tags = { deviceId };
|
|
149881
150454
|
const device = await deps.resolveDevice(deviceId);
|
|
149882
|
-
if (device === null)
|
|
150455
|
+
if (device === null) {
|
|
150456
|
+
deps.logger.warn("videoclips: no Reolink camera here to fetch this clip from", {
|
|
150457
|
+
tags,
|
|
150458
|
+
meta: {
|
|
150459
|
+
clipKey,
|
|
150460
|
+
twin,
|
|
150461
|
+
branch: "unknown-device"
|
|
150462
|
+
}
|
|
150463
|
+
});
|
|
150464
|
+
return {
|
|
150465
|
+
kind: "refused",
|
|
150466
|
+
code: "catalog-unreachable",
|
|
150467
|
+
detail: `device ${deviceId} is not a Reolink camera on this node`
|
|
150468
|
+
};
|
|
150469
|
+
}
|
|
149883
150470
|
if (device.isBattery && device.sleeping && !device.isHubChild) {
|
|
149884
|
-
|
|
149885
|
-
|
|
150471
|
+
if (input.wake !== "authorised") {
|
|
150472
|
+
deps.logger.warn("videoclips: refusing to fetch a clip from a sleeping camera", {
|
|
150473
|
+
tags,
|
|
150474
|
+
meta: {
|
|
150475
|
+
clipKey,
|
|
150476
|
+
twin,
|
|
150477
|
+
branch: "sleeping"
|
|
150478
|
+
}
|
|
150479
|
+
});
|
|
150480
|
+
return {
|
|
150481
|
+
kind: "refused",
|
|
150482
|
+
code: "sleeping",
|
|
150483
|
+
detail: `device ${deviceId} is a standalone battery camera and is sleeping — fetching a clip would wake it, and no operator authorisation was carried`
|
|
150484
|
+
};
|
|
150485
|
+
}
|
|
150486
|
+
deps.logger.warn("videoclips: waking a sleeping battery camera on an authorised clip read", {
|
|
150487
|
+
tags,
|
|
149886
150488
|
meta: {
|
|
149887
150489
|
clipKey,
|
|
149888
|
-
|
|
150490
|
+
twin,
|
|
150491
|
+
branch: "wake-authorised"
|
|
149889
150492
|
}
|
|
149890
150493
|
});
|
|
149891
|
-
return null;
|
|
149892
150494
|
}
|
|
149893
|
-
|
|
149894
|
-
|
|
149895
|
-
|
|
149896
|
-
tags: { deviceId },
|
|
150495
|
+
if (uidIsMissing(device)) {
|
|
150496
|
+
deps.logger.warn("videoclips: no uid for this camera — its clip cannot be addressed", {
|
|
150497
|
+
tags,
|
|
149897
150498
|
meta: {
|
|
149898
150499
|
clipKey,
|
|
149899
|
-
|
|
150500
|
+
twin,
|
|
150501
|
+
branch: "uid-missing"
|
|
149900
150502
|
}
|
|
149901
150503
|
});
|
|
149902
|
-
return
|
|
150504
|
+
return {
|
|
150505
|
+
kind: "refused",
|
|
150506
|
+
code: "catalog-unreachable",
|
|
150507
|
+
detail: UID_MISSING_REASON
|
|
150508
|
+
};
|
|
150509
|
+
}
|
|
150510
|
+
let downloaded;
|
|
150511
|
+
try {
|
|
150512
|
+
downloaded = await fetchVerifiedClipBytes(device, row, clipKey, fileName);
|
|
150513
|
+
} catch (err) {
|
|
150514
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
150515
|
+
deps.logger.warn("videoclips: the camera never delivered this clip", {
|
|
150516
|
+
tags,
|
|
150517
|
+
meta: {
|
|
150518
|
+
clipKey,
|
|
150519
|
+
twin,
|
|
150520
|
+
branch: "camera-refused",
|
|
150521
|
+
error: reason
|
|
150522
|
+
}
|
|
150523
|
+
});
|
|
150524
|
+
return {
|
|
150525
|
+
kind: "refused",
|
|
150526
|
+
code: "camera-refused",
|
|
150527
|
+
detail: reason
|
|
150528
|
+
};
|
|
149903
150529
|
}
|
|
149904
|
-
const downloaded = await fetchVerifiedClipBytes(device, row, clipKey);
|
|
149905
150530
|
const audio = decideClipAudio(downloaded.audio);
|
|
149906
150531
|
if (audio.kind === "silent") deps.logger.warn("videoclips: serving a clip with no sound", {
|
|
149907
150532
|
tags: { deviceId },
|
|
@@ -149945,14 +150570,24 @@ function createClipService(deps) {
|
|
|
149945
150570
|
tags: { deviceId },
|
|
149946
150571
|
meta: {
|
|
149947
150572
|
clipKey,
|
|
150573
|
+
twin,
|
|
149948
150574
|
branch: "mux-failed",
|
|
149949
150575
|
error: failure
|
|
149950
150576
|
}
|
|
149951
150577
|
});
|
|
149952
|
-
return
|
|
150578
|
+
return {
|
|
150579
|
+
kind: "refused",
|
|
150580
|
+
code: "fetch-failed",
|
|
150581
|
+
detail: failure
|
|
150582
|
+
};
|
|
149953
150583
|
}
|
|
149954
150584
|
const muxed = await readFile(outPath);
|
|
149955
|
-
|
|
150585
|
+
const decoded = downloaded.stats.durationSeconds;
|
|
150586
|
+
return {
|
|
150587
|
+
kind: "ok",
|
|
150588
|
+
bytes: muxed,
|
|
150589
|
+
durationMs: decoded !== null && Number.isFinite(decoded) && decoded > 0 ? Math.round(decoded * 1e3) : null
|
|
150590
|
+
};
|
|
149956
150591
|
} finally {
|
|
149957
150592
|
await rm(scratch, {
|
|
149958
150593
|
recursive: true,
|
|
@@ -149960,6 +150595,85 @@ function createClipService(deps) {
|
|
|
149960
150595
|
});
|
|
149961
150596
|
}
|
|
149962
150597
|
};
|
|
150598
|
+
/** {@link produceTwin}, deduplicated per `(device, clip, twin)`. */
|
|
150599
|
+
const produceOnce = (input) => {
|
|
150600
|
+
const key = `${input.deviceId}|${input.row.clipKey}|${input.twin}`;
|
|
150601
|
+
const inFlight = producing.get(key);
|
|
150602
|
+
if (inFlight !== void 0) return inFlight;
|
|
150603
|
+
const run = produceTwin(input).finally(() => {
|
|
150604
|
+
producing.delete(key);
|
|
150605
|
+
});
|
|
150606
|
+
producing.set(key, run);
|
|
150607
|
+
return run;
|
|
150608
|
+
};
|
|
150609
|
+
/**
|
|
150610
|
+
* The PLAYER's path: the sub twin, filed in the scratch, served by URL.
|
|
150611
|
+
*
|
|
150612
|
+
* `null` for every refusal — the playback route answers a status code and
|
|
150613
|
+
* has no vocabulary to carry a token; the named reason is already in the log
|
|
150614
|
+
* line `produceTwin` wrote.
|
|
150615
|
+
*/
|
|
150616
|
+
const prepareClip = async (deviceId, clipKey) => {
|
|
150617
|
+
const ready = await media.pathIfPresent(deviceId, clipKey);
|
|
150618
|
+
if (ready !== null) return ready;
|
|
150619
|
+
const row = rowFor(deviceId, clipKey);
|
|
150620
|
+
if (row === null) {
|
|
150621
|
+
deps.logger.warn("videoclips: no catalog row for this clip", {
|
|
150622
|
+
tags: { deviceId },
|
|
150623
|
+
meta: {
|
|
150624
|
+
clipKey,
|
|
150625
|
+
branch: "no-catalog-row"
|
|
150626
|
+
}
|
|
150627
|
+
});
|
|
150628
|
+
return null;
|
|
150629
|
+
}
|
|
150630
|
+
const outcome = await produceOnce({
|
|
150631
|
+
deviceId,
|
|
150632
|
+
row,
|
|
150633
|
+
fileName: row.subFileName,
|
|
150634
|
+
twin: "sub"
|
|
150635
|
+
});
|
|
150636
|
+
if (outcome.kind !== "ok") return null;
|
|
150637
|
+
return media.put(deviceId, clipKey, outcome.bytes);
|
|
150638
|
+
};
|
|
150639
|
+
/**
|
|
150640
|
+
* The EXPORT's path: the asked twin's bytes, in memory, once.
|
|
150641
|
+
*
|
|
150642
|
+
* The scratch is the PLAYER's cache and its key
|
|
150643
|
+
* (`clipKeyFor(channel, subFileName)`) carries no twin, so it holds exactly
|
|
150644
|
+
* one thing: the sub file. A `sub` read therefore reuses it and warms it — a
|
|
150645
|
+
* clip the operator just watched costs no second cmd 5, and one he exports
|
|
150646
|
+
* first is already there when he plays it. A `main` read BYPASSES it in both
|
|
150647
|
+
* directions: writing a main file under that key would serve 33× the bytes
|
|
150648
|
+
* to every `low` playback of the clip, and filing it under a second key
|
|
150649
|
+
* would evict the sub clips the player really does re-read (10 files /
|
|
150650
|
+
* 200 MiB per device) to cache a one-shot export nobody reads twice.
|
|
150651
|
+
*/
|
|
150652
|
+
const prepareBytes = async (input) => {
|
|
150653
|
+
const { deviceId, row, twin } = input;
|
|
150654
|
+
if (twin === "sub") {
|
|
150655
|
+
const cached = await media.read(deviceId, row.clipKey);
|
|
150656
|
+
if (cached !== null) {
|
|
150657
|
+
deps.logger.info("videoclips: a clip byte read was served from the scratch", {
|
|
150658
|
+
tags: { deviceId },
|
|
150659
|
+
meta: {
|
|
150660
|
+
clipKey: row.clipKey,
|
|
150661
|
+
twin,
|
|
150662
|
+
branch: "scratch-hit",
|
|
150663
|
+
bytes: cached.byteLength
|
|
150664
|
+
}
|
|
150665
|
+
});
|
|
150666
|
+
return {
|
|
150667
|
+
kind: "ok",
|
|
150668
|
+
bytes: cached,
|
|
150669
|
+
durationMs: null
|
|
150670
|
+
};
|
|
150671
|
+
}
|
|
150672
|
+
}
|
|
150673
|
+
const outcome = await produceOnce(input);
|
|
150674
|
+
if (outcome.kind === "ok" && twin === "sub") await media.put(deviceId, row.clipKey, outcome.bytes);
|
|
150675
|
+
return outcome;
|
|
150676
|
+
};
|
|
149963
150677
|
const provider = createReolinkVideoclipsProvider({
|
|
149964
150678
|
now,
|
|
149965
150679
|
cache,
|
|
@@ -149971,6 +150685,7 @@ function createClipService(deps) {
|
|
|
149971
150685
|
playbackUrl: `/addon/${REOLINK_ADDON_ID}/${CLIP_MEDIA_PREFIX}/${device.deviceId}/${clipKey}.mp4`,
|
|
149972
150686
|
served: profile === "high" ? "high" : "low"
|
|
149973
150687
|
}),
|
|
150688
|
+
prepareBytes,
|
|
149974
150689
|
logger: deps.logger
|
|
149975
150690
|
});
|
|
149976
150691
|
return {
|
|
@@ -149997,15 +150712,36 @@ function createClipService(deps) {
|
|
|
149997
150712
|
resolvePath: (deviceId, clipKey, _req) => prepareClip(deviceId, clipKey),
|
|
149998
150713
|
logger: deps.logger
|
|
149999
150714
|
}),
|
|
150000
|
-
prefetchThumbnails: async (deviceId, limit =
|
|
150001
|
-
const rows = cache.allRows(deviceId).toSorted((a, b) => b.startMs - a.startMs)
|
|
150715
|
+
prefetchThumbnails: async (deviceId, limit = 60) => {
|
|
150716
|
+
const rows = cache.allRows(deviceId).toSorted((a, b) => b.startMs - a.startMs);
|
|
150002
150717
|
let minted = 0;
|
|
150718
|
+
let scanned = 0;
|
|
150719
|
+
let alreadyHeld = 0;
|
|
150720
|
+
const outcome = (stop, refusal = null) => ({
|
|
150721
|
+
minted,
|
|
150722
|
+
scanned,
|
|
150723
|
+
alreadyHeld,
|
|
150724
|
+
stop,
|
|
150725
|
+
refusal
|
|
150726
|
+
});
|
|
150727
|
+
if (!await thumbs.hasHeadroomForPrefetch(deviceId)) return outcome("no-headroom");
|
|
150003
150728
|
for (const row of rows) {
|
|
150004
|
-
|
|
150005
|
-
if (await thumbs.has(deviceId, row.clipKey))
|
|
150006
|
-
|
|
150729
|
+
scanned += 1;
|
|
150730
|
+
if (await thumbs.has(deviceId, row.clipKey)) {
|
|
150731
|
+
alreadyHeld += 1;
|
|
150732
|
+
continue;
|
|
150733
|
+
}
|
|
150734
|
+
if (minted >= limit) return outcome("budget");
|
|
150735
|
+
const result = await mintThumbnail(deviceId, row.clipKey, "prefetch");
|
|
150736
|
+
if (!result.ok) return outcome("refused", {
|
|
150737
|
+
code: result.code,
|
|
150738
|
+
disposition: result.disposition,
|
|
150739
|
+
clipKey: row.clipKey
|
|
150740
|
+
});
|
|
150741
|
+
minted += 1;
|
|
150742
|
+
if (minted % 16 === 0 && !await thumbs.hasHeadroomForPrefetch(deviceId)) return outcome("no-headroom");
|
|
150007
150743
|
}
|
|
150008
|
-
return
|
|
150744
|
+
return outcome("rows-exhausted");
|
|
150009
150745
|
}
|
|
150010
150746
|
};
|
|
150011
150747
|
}
|
|
@@ -150790,6 +151526,32 @@ var reolinkDebugActions = defineCustomActions({ debugRawRead: customAction(RawRe
|
|
|
150790
151526
|
auth: "admin"
|
|
150791
151527
|
}) });
|
|
150792
151528
|
//#endregion
|
|
151529
|
+
//#region src/device-meta-uid.ts
|
|
151530
|
+
function asDeviceMetaApi(api) {
|
|
151531
|
+
return typeof api === "object" && api !== null ? api : void 0;
|
|
151532
|
+
}
|
|
151533
|
+
function metadataUidOf(device) {
|
|
151534
|
+
if (typeof device !== "object" || device === null) return void 0;
|
|
151535
|
+
const metadata = device.metadata;
|
|
151536
|
+
if (typeof metadata !== "object" || metadata === null) return void 0;
|
|
151537
|
+
const uid = metadata.uid;
|
|
151538
|
+
return typeof uid === "string" ? uid : void 0;
|
|
151539
|
+
}
|
|
151540
|
+
/**
|
|
151541
|
+
* This device's `metadata.uid`, or `undefined` for every way of not having
|
|
151542
|
+
* one — absent, not a string, the RPC refused, the route missing. Never
|
|
151543
|
+
* throws.
|
|
151544
|
+
*/
|
|
151545
|
+
async function readDeviceMetaUid(api, deviceId) {
|
|
151546
|
+
const query = asDeviceMetaApi(api)?.deviceManager?.getDevice?.query;
|
|
151547
|
+
if (query === void 0) return void 0;
|
|
151548
|
+
try {
|
|
151549
|
+
return metadataUidOf(await query({ deviceId }));
|
|
151550
|
+
} catch {
|
|
151551
|
+
return;
|
|
151552
|
+
}
|
|
151553
|
+
}
|
|
151554
|
+
//#endregion
|
|
150793
151555
|
//#region src/battery-charging.ts
|
|
150794
151556
|
/**
|
|
150795
151557
|
* Da `adapterStatus` + `chargeStatus` alla sorgente di alimentazione.
|
|
@@ -154779,6 +155541,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
|
|
|
154779
155541
|
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
154780
155542
|
});
|
|
154781
155543
|
});
|
|
155544
|
+
this.metadataUid = await readDeviceMetaUid(this.ctx.api, this.id);
|
|
154782
155545
|
await this.refreshNetworkLinkFromApi(api, "probe");
|
|
154783
155546
|
}
|
|
154784
155547
|
/**
|
|
@@ -155227,12 +155990,24 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
|
|
|
155227
155990
|
async wakeForClipCatalogRefresh() {
|
|
155228
155991
|
if (!await this.wakeIfSleeping()) throw new Error(`ReolinkCamera ${this.id}: the authorised clip-refresh wake did not bring the camera up`);
|
|
155229
155992
|
}
|
|
155993
|
+
/**
|
|
155994
|
+
* `deviceMeta.metadata.uid`, read once per addon start in {@link onProbe}.
|
|
155995
|
+
*
|
|
155996
|
+
* In memory, never persisted: a third copy of a fact the device manager
|
|
155997
|
+
* already owns is the very thing that produced this defect (D224). A
|
|
155998
|
+
* physical camera's uid does not change, so one read per process is enough,
|
|
155999
|
+
* and until it lands the adoption copy is what answers.
|
|
156000
|
+
*/
|
|
156001
|
+
metadataUid = void 0;
|
|
155230
156002
|
getClipDeviceRef() {
|
|
155231
|
-
const
|
|
156003
|
+
const configUid = this.config.get("uid");
|
|
155232
156004
|
return {
|
|
155233
156005
|
deviceId: this.id,
|
|
155234
156006
|
channel: this.getChannel(),
|
|
155235
|
-
uid:
|
|
156007
|
+
uid: resolveCameraUid({
|
|
156008
|
+
metadataUid: this.metadataUid,
|
|
156009
|
+
configUid: typeof configUid === "string" ? configUid : void 0
|
|
156010
|
+
}),
|
|
155236
156011
|
isHubChild: this.isHubChild(),
|
|
155237
156012
|
isBattery: this.isBattery,
|
|
155238
156013
|
sleeping: this.sleeping,
|
|
@@ -164144,6 +164919,7 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
|
|
|
164144
164919
|
if (!(device instanceof ReolinkCamera)) throw new Error(`clip refresh: device ${String(deviceId)} is not a Reolink camera here`);
|
|
164145
164920
|
await device.wakeForClipCatalogRefresh();
|
|
164146
164921
|
},
|
|
164922
|
+
prefetchStills: async (deviceId) => service.prefetchThumbnails(deviceId),
|
|
164147
164923
|
hostBusy: (hostKey) => service.hostBusy(hostKey),
|
|
164148
164924
|
logger: this.ctx.logger
|
|
164149
164925
|
});
|