@camstack/addon-export-alexa 1.2.108 → 1.2.110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/export-alexa.addon.js +1123 -475
- package/dist/export-alexa.addon.mjs +1123 -475
- package/package.json +1 -1
|
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
//#endregion
|
|
27
27
|
let node_crypto = require("node:crypto");
|
|
28
28
|
node_crypto = __toESM(node_crypto);
|
|
29
|
-
//#region ../types/dist/event-category-
|
|
29
|
+
//#region ../types/dist/event-category-BVDXG4tB.mjs
|
|
30
30
|
var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
31
31
|
EventCategory["SystemBoot"] = "system.boot";
|
|
32
32
|
EventCategory["SystemAddonsReady"] = "system.addons-ready";
|
|
@@ -643,6 +643,20 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
|
643
643
|
* pull-reconcile from the provider's `getStatus` on reconnect. */
|
|
644
644
|
EventCategory["MeshNetworkChanged"] = "network.mesh.changed";
|
|
645
645
|
EventCategory["BackupCompleted"] = "backup.completed";
|
|
646
|
+
/**
|
|
647
|
+
* A whole backup RUN finished — every destination attempted, win or lose.
|
|
648
|
+
*
|
|
649
|
+
* `backup.completed` fires once per DESTINATION, which is the right grain for
|
|
650
|
+
* a progress UI and the wrong one for a notification: an operator with three
|
|
651
|
+
* destinations would be told three times. And a run where two of three
|
|
652
|
+
* destinations succeeded is not a clean success — a single "backup
|
|
653
|
+
* completed" that hid the failed one would be a lie, so the count of each is
|
|
654
|
+
* carried here and the message says both.
|
|
655
|
+
*
|
|
656
|
+
* Emitted by the backup orchestrator only after the destination loop, so a
|
|
657
|
+
* run that dies during the BUILD phase produces no completion at all.
|
|
658
|
+
*/
|
|
659
|
+
EventCategory["BackupRunCompleted"] = "backup.run-completed";
|
|
646
660
|
EventCategory["BackupRestored"] = "backup.restored";
|
|
647
661
|
EventCategory["NotificationDispatched"] = "notification.dispatched";
|
|
648
662
|
EventCategory["NotificationFailed"] = "notification.failed";
|
|
@@ -5373,7 +5387,7 @@ var ZodIssueCode = {
|
|
|
5373
5387
|
var ZodFirstPartyTypeKind;
|
|
5374
5388
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5375
5389
|
//#endregion
|
|
5376
|
-
//#region ../types/dist/sleep-
|
|
5390
|
+
//#region ../types/dist/sleep-BDR76Ykr.mjs
|
|
5377
5391
|
/**
|
|
5378
5392
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5379
5393
|
* window to float samples (D455).
|
|
@@ -7254,6 +7268,28 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
|
|
|
7254
7268
|
DeviceRole["GenericNotifier"] = "generic-notifier";
|
|
7255
7269
|
return DeviceRole;
|
|
7256
7270
|
}({});
|
|
7271
|
+
/**
|
|
7272
|
+
* Identity — preserves literal types for downstream inference.
|
|
7273
|
+
*
|
|
7274
|
+
* The constraint is `Record<string, unknown>` (not `CustomActionsSpec`) so
|
|
7275
|
+
* TypeScript does not widen each entry's literal `kind`/`auth` fields to
|
|
7276
|
+
* the broader unions declared on `CustomActionSpec`'s default generics.
|
|
7277
|
+
* Shape validity is enforced separately by the `customAction(...)` helper
|
|
7278
|
+
* whose return type is already a `CustomActionSpec<...>`.
|
|
7279
|
+
*/
|
|
7280
|
+
function defineCustomActions(spec) {
|
|
7281
|
+
return spec;
|
|
7282
|
+
}
|
|
7283
|
+
function customAction(input, output, options) {
|
|
7284
|
+
return {
|
|
7285
|
+
input,
|
|
7286
|
+
output,
|
|
7287
|
+
kind: options?.kind ?? "query",
|
|
7288
|
+
auth: options?.auth ?? "protected",
|
|
7289
|
+
scope: options?.scope ?? { kind: "system" },
|
|
7290
|
+
...options?.caller ? { caller: "required" } : {}
|
|
7291
|
+
};
|
|
7292
|
+
}
|
|
7257
7293
|
var StaticDirOutputSchema = object({ staticDir: string() });
|
|
7258
7294
|
var VersionOutputSchema = object({ version: string() });
|
|
7259
7295
|
method(_void(), StaticDirOutputSchema, { auth: "admin" }), method(_void(), VersionOutputSchema, { auth: "admin" });
|
|
@@ -7560,6 +7596,28 @@ var EncodeProfileSchema = object({
|
|
|
7560
7596
|
outputArgs: array(string()).optional()
|
|
7561
7597
|
});
|
|
7562
7598
|
/**
|
|
7599
|
+
* THE target rule: which of two sizes serves a consumer better.
|
|
7600
|
+
*
|
|
7601
|
+
* "Prefer at or above the target so the consumer downscales instead of
|
|
7602
|
+
* upscaling; among those the SMALLEST, because the extra pixels are thrown
|
|
7603
|
+
* away and the decode is not; among the rest the LARGEST, because it is the
|
|
7604
|
+
* closest we can get." One sentence, and until now it was written twice — once
|
|
7605
|
+
* here in lines, once in `stream-selection.ts` in pixels, for the same two
|
|
7606
|
+
* exporters. The two agreed, which is luck, not a property.
|
|
7607
|
+
*
|
|
7608
|
+
* The `size` is whatever measure the caller ranks by: the cap ranks by LINES
|
|
7609
|
+
* (a consumer's requirement is stated in p), the RTSP picker by PIXELS (it
|
|
7610
|
+
* compares entries of possibly different aspect). The rule is the same either
|
|
7611
|
+
* way and the measure is the caller's business.
|
|
7612
|
+
*
|
|
7613
|
+
* Returns a sort delta: negative when `a` should come first.
|
|
7614
|
+
*/
|
|
7615
|
+
function compareToTarget(a, b, target) {
|
|
7616
|
+
const aReaches = a >= target;
|
|
7617
|
+
if (aReaches !== b >= target) return aReaches ? -1 : 1;
|
|
7618
|
+
return aReaches ? a - b : b - a;
|
|
7619
|
+
}
|
|
7620
|
+
/**
|
|
7563
7621
|
* The shape every live egress starts from: H.264 Baseline 3.1 at 720p25.
|
|
7564
7622
|
* Baseline because it is the one profile every consumer in this repo decodes
|
|
7565
7623
|
* (Echo, iOS, an old browser); 3.1 because that is what the SDPs advertise.
|
|
@@ -9474,6 +9532,47 @@ var LogChannelWindowSchema = object({
|
|
|
9474
9532
|
/** `null` = every camera. A non-empty list narrows to those numeric ids. */
|
|
9475
9533
|
deviceIds: array(number().int()).readonly().nullable()
|
|
9476
9534
|
});
|
|
9535
|
+
/**
|
|
9536
|
+
* Shared stream-selection picker for export addons.
|
|
9537
|
+
*
|
|
9538
|
+
* Both `addon-export-alexa` and `addon-export-hap` resolve the
|
|
9539
|
+
* operator's `streamPreference` setting against the broker's RTSP
|
|
9540
|
+
* entries before dialling a camera. Each addon used to roll its own:
|
|
9541
|
+
* Alexa had `pickPreferredRtspEntry` under `handlers/`, HAP had an
|
|
9542
|
+
* inline `"prefer /mid, then /high, then first"` chain inside its
|
|
9543
|
+
* camera-streams mapper. The chains drifted (Alexa honoured
|
|
9544
|
+
* `streamPreference`, HAP didn't; only Alexa got the smart
|
|
9545
|
+
* resolution-targeted auto-pick) and the cross-addon import rule
|
|
9546
|
+
* blocks deduping in either direction.
|
|
9547
|
+
*
|
|
9548
|
+
* Lifting the picker into `@camstack/types` lets every exporter call
|
|
9549
|
+
* the same code path with the consumer's target resolution baked into
|
|
9550
|
+
* the call site — Alexa passes 1280×720, HomeKit passes 1920×1080,
|
|
9551
|
+
* the picker handles the rest.
|
|
9552
|
+
*
|
|
9553
|
+
* Selection algorithm:
|
|
9554
|
+
* - pref === '<profile>' → profile-keyed entries (from
|
|
9555
|
+
* `getProfileRtspEntries`) match on `e.profile`;
|
|
9556
|
+
* legacy raw entries match on the brokerId
|
|
9557
|
+
* suffix (`brokerId` ENDS WITH `/${pref}`, shape
|
|
9558
|
+
* `${deviceId}/${camStreamId}`). Addons store the
|
|
9559
|
+
* bare profile/camStream id in their
|
|
9560
|
+
* `ExportDeviceSettings.streamPreference`. Falls
|
|
9561
|
+
* back to 'auto' when no enabled entry matches
|
|
9562
|
+
* either way.
|
|
9563
|
+
* - pref === 'auto' → when `targetResolution` is given, pick the
|
|
9564
|
+
* entry whose source resolution is closest to
|
|
9565
|
+
* it (prefer ≥ target so the consumer
|
|
9566
|
+
* downscales instead of upscaling). Without a
|
|
9567
|
+
* target, fall back to first-enabled. If no
|
|
9568
|
+
* entry advertises a resolution at all
|
|
9569
|
+
* (broker hasn't probed yet), also fall back
|
|
9570
|
+
* to first-enabled so cold start still serves.
|
|
9571
|
+
*
|
|
9572
|
+
* Returns `null` when nothing is publishable — callers fold that into
|
|
9573
|
+
* the consumer's "no stream" error (Alexa: STREAM_TYPE_UNSUPPORTED;
|
|
9574
|
+
* HAP: a thrown error inside `startFfmpegForSession`).
|
|
9575
|
+
*/
|
|
9477
9576
|
function pickPreferredRtspEntry(entries, pref, deviceId, options = {}) {
|
|
9478
9577
|
if (entries.length === 0) return null;
|
|
9479
9578
|
const prefix = `${deviceId}/`;
|
|
@@ -9503,30 +9602,23 @@ function pickPreferredRtspEntry(entries, pref, deviceId, options = {}) {
|
|
|
9503
9602
|
return toPicked(eligible[0]);
|
|
9504
9603
|
}
|
|
9505
9604
|
/**
|
|
9506
|
-
* Pick the entry whose `resolution` is closest to `target
|
|
9507
|
-
*
|
|
9508
|
-
*
|
|
9509
|
-
*
|
|
9510
|
-
*
|
|
9605
|
+
* Pick the entry whose `resolution` is closest to `target`, by the ONE target
|
|
9606
|
+
* rule ({@link compareToTarget}): prefer at or above the target so the consumer
|
|
9607
|
+
* downscales instead of upscaling; among those the smallest; among the rest the
|
|
9608
|
+
* largest.
|
|
9609
|
+
*
|
|
9610
|
+
* This function used to implement that rule itself, in pixels, while
|
|
9611
|
+
* `rankStreams` implemented it again in lines — the same sentence written twice
|
|
9612
|
+
* for the same two exporters, agreeing by luck rather than by construction.
|
|
9613
|
+
* Only the MEASURE is this picker's own: it compares whole pixel counts because
|
|
9614
|
+
* its entries can differ in aspect, where the cap's requirement is stated in p.
|
|
9511
9615
|
*/
|
|
9512
9616
|
function pickClosestResolution(entries, target) {
|
|
9513
9617
|
const targetPixels = target.width * target.height;
|
|
9514
|
-
|
|
9515
|
-
|
|
9516
|
-
|
|
9517
|
-
|
|
9518
|
-
const pixels = e.resolution.width * e.resolution.height;
|
|
9519
|
-
if (pixels >= targetPixels) {
|
|
9520
|
-
if (!bestAbove || pixels < bestAbove.pixels) bestAbove = {
|
|
9521
|
-
entry: e,
|
|
9522
|
-
pixels
|
|
9523
|
-
};
|
|
9524
|
-
} else if (!bestBelow || pixels > bestBelow.pixels) bestBelow = {
|
|
9525
|
-
entry: e,
|
|
9526
|
-
pixels
|
|
9527
|
-
};
|
|
9528
|
-
}
|
|
9529
|
-
return bestAbove?.entry ?? bestBelow?.entry;
|
|
9618
|
+
return [...entries.flatMap((entry) => entry.resolution === void 0 ? [] : [{
|
|
9619
|
+
entry,
|
|
9620
|
+
pixels: entry.resolution.width * entry.resolution.height
|
|
9621
|
+
}])].sort((a, b) => compareToTarget(a.pixels, b.pixels, targetPixels))[0]?.entry;
|
|
9530
9622
|
}
|
|
9531
9623
|
var MODEL_FORMATS = [
|
|
9532
9624
|
"onnx",
|
|
@@ -11740,6 +11832,58 @@ method(ListInputSchema, array(BrokerInfoSchema$1)), method(GetInputSchema, Broke
|
|
|
11740
11832
|
auth: "admin"
|
|
11741
11833
|
}), method(GetStateInputSchema, unknown().nullable()), method(_void(), RegistryStatusSchema);
|
|
11742
11834
|
DeviceType.Camera;
|
|
11835
|
+
/**
|
|
11836
|
+
* The signals a device can emit to WAKE its own stream.
|
|
11837
|
+
*
|
|
11838
|
+
* A camera whose stream is built on demand sleeps until something asks for it,
|
|
11839
|
+
* and "something" cannot be a consumer that is merely attached — a Frigate-style
|
|
11840
|
+
* puller holds a session open for ever, and treating that as demand would keep
|
|
11841
|
+
* a battery camera awake for ever, which is the whole thing the battery is for
|
|
11842
|
+
* (D173). So the wake has to come from the CAMERA: an event it noticed by
|
|
11843
|
+
* itself, with no stream running.
|
|
11844
|
+
*
|
|
11845
|
+
* ## The vocabulary is the PROVIDER'S, not ours
|
|
11846
|
+
*
|
|
11847
|
+
* Like `consumables`, this cap declares no vocabulary of its own. A provider
|
|
11848
|
+
* names each signal with a `code` it chooses and a `label` an operator reads.
|
|
11849
|
+
* Reolink offers motion and camera-native detection; another provider may offer
|
|
11850
|
+
* a tamper, a doorbell press, a PIR, or something no camera in this fleet has
|
|
11851
|
+
* yet. A fixed enum here would mean every new signal is a framework release.
|
|
11852
|
+
*
|
|
11853
|
+
* It is deliberately NOT derived from the caps a device already binds. Whether
|
|
11854
|
+
* a camera CAN push firmware motion is expressed by `motionSources` containing
|
|
11855
|
+
* `'onboard'`, and whether it does AI on-camera by the `native-object-detection`
|
|
11856
|
+
* binding — but both answer "what drives the detection pipeline", which is a
|
|
11857
|
+
* different question from "what may wake a sleeping stream". A camera can do
|
|
11858
|
+
* the first and not be trusted with the second, and the operator picks per
|
|
11859
|
+
* camera. Two questions, two authorities.
|
|
11860
|
+
*
|
|
11861
|
+
* ## Availability is not permission
|
|
11862
|
+
*
|
|
11863
|
+
* `listSignals` says what the device CAN emit. Whether a given signal actually
|
|
11864
|
+
* wakes the stream is the operator's per-camera choice, held by the broker
|
|
11865
|
+
* alongside the cooldown — see the stream-broker cap's wake settings. A
|
|
11866
|
+
* provider declaring a signal is not a provider enabling it.
|
|
11867
|
+
*/
|
|
11868
|
+
/** One signal a device can emit. */
|
|
11869
|
+
var StreamSignalSchema = object({
|
|
11870
|
+
/** Stable id chosen by the provider, e.g. `'motion'`, `'person'`, `'tamper'`. */
|
|
11871
|
+
code: string().min(1),
|
|
11872
|
+
/** What an operator reads in the picker. The provider's own wording. */
|
|
11873
|
+
label: string().min(1),
|
|
11874
|
+
/**
|
|
11875
|
+
* Whether the provider recommends this signal ON when a camera is first set
|
|
11876
|
+
* up. A provider knows which of its signals are cheap and reliable; an
|
|
11877
|
+
* operator should not have to discover that by trial. Reolink recommends
|
|
11878
|
+
* both of its own.
|
|
11879
|
+
*/
|
|
11880
|
+
recommended: boolean()
|
|
11881
|
+
});
|
|
11882
|
+
object({
|
|
11883
|
+
signals: array(StreamSignalSchema),
|
|
11884
|
+
lastFetchedAt: number()
|
|
11885
|
+
});
|
|
11886
|
+
Object.values(DeviceType), method(_void(), array(StreamSignalSchema).readonly());
|
|
11743
11887
|
/** Stream delivery format. (Relocated from the retired `streaming-engine` cap.) */
|
|
11744
11888
|
var StreamFormatSchema = _enum([
|
|
11745
11889
|
"webrtc",
|
|
@@ -12136,6 +12280,22 @@ var EgressTranscodeSchema = object({
|
|
|
12136
12280
|
camStreamId: string().nullable()
|
|
12137
12281
|
});
|
|
12138
12282
|
method(object({
|
|
12283
|
+
deviceId: number().int().nonnegative(),
|
|
12284
|
+
/** The provider's signal code. */
|
|
12285
|
+
code: string().min(1),
|
|
12286
|
+
/** Ms epoch. Absent ⇒ now. */
|
|
12287
|
+
at: number().optional()
|
|
12288
|
+
}), object({
|
|
12289
|
+
/** Whether the broker acted on it, and if not, why. */
|
|
12290
|
+
accepted: boolean(),
|
|
12291
|
+
reason: _enum([
|
|
12292
|
+
"woke",
|
|
12293
|
+
"hold-extended",
|
|
12294
|
+
"not-enabled",
|
|
12295
|
+
"no-consumer",
|
|
12296
|
+
"unknown-code"
|
|
12297
|
+
])
|
|
12298
|
+
}), { kind: "mutation" }), method(object({
|
|
12139
12299
|
deviceId: number().int().nonnegative(),
|
|
12140
12300
|
camStreamId: string().min(1),
|
|
12141
12301
|
kind: CamStreamKindSchema,
|
|
@@ -12390,6 +12550,16 @@ var PickStreamRequirementsSchema = object({
|
|
|
12390
12550
|
acceptCodecs: array(StreamCodecSchema).readonly().optional(),
|
|
12391
12551
|
/** Minimum vertical resolution. Streams shorter than this are dropped. */
|
|
12392
12552
|
minHeight: number().int().positive().optional(),
|
|
12553
|
+
/**
|
|
12554
|
+
* Maximum vertical resolution. Streams TALLER than this are dropped.
|
|
12555
|
+
*
|
|
12556
|
+
* A consumer can have a ceiling as real as its floor: Alexa documents
|
|
12557
|
+
* 480p to 1080p, and a 4K stream is as unusable to an Echo as a 360p one.
|
|
12558
|
+
* Without this the ceiling had to be re-implemented by every caller — and
|
|
12559
|
+
* one caller implementing it privately is how a second scoring authority
|
|
12560
|
+
* gets born.
|
|
12561
|
+
*/
|
|
12562
|
+
maxHeight: number().int().positive().optional(),
|
|
12393
12563
|
/** Minimum horizontal resolution. */
|
|
12394
12564
|
minWidth: number().int().positive().optional(),
|
|
12395
12565
|
/**
|
|
@@ -12406,7 +12576,22 @@ var PickStreamRequirementsSchema = object({
|
|
|
12406
12576
|
* transcoded" guard: if the device is already serving the consumer's
|
|
12407
12577
|
* codec end-to-end, there's nothing to optimise.
|
|
12408
12578
|
*/
|
|
12409
|
-
requireSiblingCodec: array(StreamCodecSchema).readonly().optional()
|
|
12579
|
+
requireSiblingCodec: array(StreamCodecSchema).readonly().optional(),
|
|
12580
|
+
/**
|
|
12581
|
+
* Whether a stream the consumer CANNOT decode may still be picked, on the
|
|
12582
|
+
* understanding that it will be transcoded.
|
|
12583
|
+
*
|
|
12584
|
+
* Default `false` — today's behaviour, and the right one for a bypass
|
|
12585
|
+
* question ("is there a stream I can forward untouched?"). Set `true` to
|
|
12586
|
+
* ask the larger question: "what is the best stream for me, transcoding if
|
|
12587
|
+
* I must?" A stream that satisfies `acceptCodecs` always outranks one that
|
|
12588
|
+
* does not, so a passthrough is never lost to a transcode; the answer says
|
|
12589
|
+
* which it is in {@link PickedCamStreamSchema.transcodes}.
|
|
12590
|
+
*
|
|
12591
|
+
* This is what lets one picker serve both the bypass and the full source
|
|
12592
|
+
* choice, instead of a consumer scoring privately when the bypass misses.
|
|
12593
|
+
*/
|
|
12594
|
+
allowTranscode: boolean().optional()
|
|
12410
12595
|
}).readonly();
|
|
12411
12596
|
var PickStreamPreferencesSchema = object({
|
|
12412
12597
|
/**
|
|
@@ -12420,12 +12605,32 @@ var PickStreamPreferencesSchema = object({
|
|
|
12420
12605
|
* picks the tallest stream; `'lowest'` picks the shortest (used by
|
|
12421
12606
|
* memory-constrained consumers / Apple Home guest sessions).
|
|
12422
12607
|
*/
|
|
12423
|
-
resolutionPreference: _enum(["highest", "lowest"]).optional()
|
|
12608
|
+
resolutionPreference: _enum(["highest", "lowest"]).optional(),
|
|
12609
|
+
/**
|
|
12610
|
+
* The height the consumer actually wants to DELIVER.
|
|
12611
|
+
*
|
|
12612
|
+
* Not a constraint — an ordering. With it set, the SMALLEST stream at or
|
|
12613
|
+
* above the target wins, and only if nothing reaches it does the tallest
|
|
12614
|
+
* take over. Pulling 1296 lines to draw 720 on a 1280x800 Echo panel costs
|
|
12615
|
+
* a decode and buys nothing, and `resolutionPreference: 'highest'` cannot
|
|
12616
|
+
* express that: it says "as big as possible", which is a different wish.
|
|
12617
|
+
*
|
|
12618
|
+
* Ignored when absent, so every existing caller keeps its ordering.
|
|
12619
|
+
*/
|
|
12620
|
+
targetHeight: number().int().positive().optional()
|
|
12424
12621
|
}).readonly();
|
|
12425
12622
|
var PickedCamStreamSchema = object({
|
|
12426
12623
|
camStreamId: string(),
|
|
12427
12624
|
codec: string().optional(),
|
|
12428
12625
|
resolution: CamStreamResolutionSchema.optional(),
|
|
12626
|
+
/**
|
|
12627
|
+
* Whether serving this stream requires a decode + re-encode.
|
|
12628
|
+
*
|
|
12629
|
+
* `false` is a stream the consumer can take as it stands. Only ever `true`
|
|
12630
|
+
* when the caller asked for it with `allowTranscode`, so a caller that did
|
|
12631
|
+
* not ask cannot be handed a cost it never agreed to pay.
|
|
12632
|
+
*/
|
|
12633
|
+
transcodes: boolean(),
|
|
12429
12634
|
/** One-line explanation of why this stream won — for logs / debug UI. */
|
|
12430
12635
|
reason: string()
|
|
12431
12636
|
});
|
|
@@ -12543,28 +12748,6 @@ method(object({}), object({ blocks: array(CoreBlockSchema) }), { auth: "admin" }
|
|
|
12543
12748
|
content: string()
|
|
12544
12749
|
})) }), { auth: "admin" });
|
|
12545
12750
|
/**
|
|
12546
|
-
* Identity — preserves literal types for downstream inference.
|
|
12547
|
-
*
|
|
12548
|
-
* The constraint is `Record<string, unknown>` (not `CustomActionsSpec`) so
|
|
12549
|
-
* TypeScript does not widen each entry's literal `kind`/`auth` fields to
|
|
12550
|
-
* the broader unions declared on `CustomActionSpec`'s default generics.
|
|
12551
|
-
* Shape validity is enforced separately by the `customAction(...)` helper
|
|
12552
|
-
* whose return type is already a `CustomActionSpec<...>`.
|
|
12553
|
-
*/
|
|
12554
|
-
function defineCustomActions(spec) {
|
|
12555
|
-
return spec;
|
|
12556
|
-
}
|
|
12557
|
-
function customAction(input, output, options) {
|
|
12558
|
-
return {
|
|
12559
|
-
input,
|
|
12560
|
-
output,
|
|
12561
|
-
kind: options?.kind ?? "query",
|
|
12562
|
-
auth: options?.auth ?? "protected",
|
|
12563
|
-
scope: options?.scope ?? { kind: "system" },
|
|
12564
|
-
...options?.caller ? { caller: "required" } : {}
|
|
12565
|
-
};
|
|
12566
|
-
}
|
|
12567
|
-
/**
|
|
12568
12751
|
* `custom-model-registry` — collection cap exposing operator-registered
|
|
12569
12752
|
* custom detection models. Each provider (today: `addon-model-studio`)
|
|
12570
12753
|
* contributes a list of `CustomModelDescriptor`s; the hub auto-concatenates
|
|
@@ -16661,6 +16844,8 @@ var NcSystemEventKindSchema = _enum([
|
|
|
16661
16844
|
"device-enabled",
|
|
16662
16845
|
"device-battery-low",
|
|
16663
16846
|
"device-battery-normal",
|
|
16847
|
+
"device-consumable-low",
|
|
16848
|
+
"device-consumable-normal",
|
|
16664
16849
|
"stream-online",
|
|
16665
16850
|
"stream-offline",
|
|
16666
16851
|
"node-online",
|
|
@@ -16679,6 +16864,7 @@ var NcSystemEventKindSchema = _enum([
|
|
|
16679
16864
|
"addon-updated",
|
|
16680
16865
|
"server-updated",
|
|
16681
16866
|
"export-completed",
|
|
16867
|
+
"backup-completed",
|
|
16682
16868
|
"camera-online",
|
|
16683
16869
|
"camera-offline",
|
|
16684
16870
|
"camera-disabled",
|
|
@@ -18001,6 +18187,48 @@ var NcAlarmConfigSchema = object({
|
|
|
18001
18187
|
settings: NcAlarmSettingsSchema,
|
|
18002
18188
|
coverage: array(NcAlarmModeCoverageSchema)
|
|
18003
18189
|
});
|
|
18190
|
+
/**
|
|
18191
|
+
* ONE rule's demand on ONE camera's clip ring.
|
|
18192
|
+
*
|
|
18193
|
+
* A rule, not a camera: the broker takes the MAX over the asks that reach a
|
|
18194
|
+
* camera, so the answer stays a faithful description of the rules and the
|
|
18195
|
+
* bounding (the byte budget, the broker's own ceiling) stays where the cost
|
|
18196
|
+
* lives. A camera that appears in no ask is being told **nothing** — which is
|
|
18197
|
+
* a different thing from never having been told, and only the envelope
|
|
18198
|
+
* (`rulesLoaded`) can tell those apart.
|
|
18199
|
+
*/
|
|
18200
|
+
var NcClipRetentionAskSchema = object({
|
|
18201
|
+
/**
|
|
18202
|
+
* The camera this ask is about. **Absent = every camera**, which is what a
|
|
18203
|
+
* rule with no `conditions.devices` means: it can fire anywhere, so it is
|
|
18204
|
+
* asking everywhere.
|
|
18205
|
+
*/
|
|
18206
|
+
deviceId: number().int().nonnegative().optional(),
|
|
18207
|
+
/** Seconds of history the rule needs held for it. Never zero — a rule that
|
|
18208
|
+
* needs nothing produces no ask at all. */
|
|
18209
|
+
seconds: number().min(0).max(60),
|
|
18210
|
+
/** The profile the rule cuts from, when it named one. Absent = the cheapest
|
|
18211
|
+
* assigned, which is what the cut defaults to. */
|
|
18212
|
+
profile: CamProfileSchema.optional(),
|
|
18213
|
+
/** Who is asking — so a retention the operator did not expect names a rule. */
|
|
18214
|
+
ruleId: string(),
|
|
18215
|
+
ruleName: string(),
|
|
18216
|
+
/** Why this many seconds: the rule's own window, or the occupancy ceiling. */
|
|
18217
|
+
reason: _enum(["window", "occupancy"])
|
|
18218
|
+
});
|
|
18219
|
+
/**
|
|
18220
|
+
* The whole answer, with the one bit that keeps absence from reading as zero.
|
|
18221
|
+
*
|
|
18222
|
+
* `rulesLoaded` is false until the rule ledger has completed a load at least
|
|
18223
|
+
* once. A centre that is up but has not read its rules yet answers with an
|
|
18224
|
+
* empty ask list that means nothing at all — applying it would drop every
|
|
18225
|
+
* camera's ring to zero for the first events after a restart, which is the
|
|
18226
|
+
* footage this mechanism exists to keep.
|
|
18227
|
+
*/
|
|
18228
|
+
var NcClipRetentionPlanSchema = object({
|
|
18229
|
+
rulesLoaded: boolean(),
|
|
18230
|
+
asks: array(NcClipRetentionAskSchema).readonly()
|
|
18231
|
+
});
|
|
18004
18232
|
method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), method(object({ ruleId: string() }), object({ rule: NcRuleSchema.nullable() }), { auth: "admin" }), method(object({ rule: NcRuleInputSchema }), object({ rule: NcRuleSchema }), {
|
|
18005
18233
|
kind: "mutation",
|
|
18006
18234
|
auth: "admin",
|
|
@@ -18021,7 +18249,7 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
|
|
|
18021
18249
|
}), object({ success: literal(true) }), {
|
|
18022
18250
|
kind: "mutation",
|
|
18023
18251
|
auth: "admin"
|
|
18024
|
-
}), method(object({}), object({ mutedDeviceIds: array(number().int()).readonly() }), { auth: "admin" }), method(object({
|
|
18252
|
+
}), method(object({}), NcClipRetentionPlanSchema, { auth: "admin" }), method(object({}), object({ mutedDeviceIds: array(number().int()).readonly() }), { auth: "admin" }), method(object({
|
|
18025
18253
|
deviceId: number().int(),
|
|
18026
18254
|
muted: boolean()
|
|
18027
18255
|
}), object({ success: literal(true) }), {
|
|
@@ -20571,6 +20799,33 @@ var RunReplayFrameProcessorResultSchema = object({ tracks: array(object({
|
|
|
20571
20799
|
* solid is this track", cheaper than re-deriving it from a trajectory. */
|
|
20572
20800
|
framesMatched: number().int()
|
|
20573
20801
|
})).readonly() });
|
|
20802
|
+
/**
|
|
20803
|
+
* The long-term series a camera produces. A closed union so a typo cannot
|
|
20804
|
+
* invent one, and the ONE declaration of it — the addon's `AnalyticsLtsSeries`
|
|
20805
|
+
* is an alias of this, not a second list.
|
|
20806
|
+
*/
|
|
20807
|
+
var AnalyticsLtsSeriesSchema = _enum([
|
|
20808
|
+
"motion",
|
|
20809
|
+
"audio-dbfs",
|
|
20810
|
+
"battery",
|
|
20811
|
+
"occupancy"
|
|
20812
|
+
]);
|
|
20813
|
+
/**
|
|
20814
|
+
* One closed 5-minute bucket of a long-term series.
|
|
20815
|
+
*
|
|
20816
|
+
* `samples` is how many readings the bucket folded — it is the ACTIVITY for a
|
|
20817
|
+
* series like `motion`, and the confidence for one like `occupancy`. A bucket
|
|
20818
|
+
* that exists at all was measured; a bucket that is absent was not, which is a
|
|
20819
|
+
* different claim from zero and the reason this is a sparse series.
|
|
20820
|
+
*/
|
|
20821
|
+
var LtsBucketSchema = object({
|
|
20822
|
+
scope: string(),
|
|
20823
|
+
bucketStart: number().int(),
|
|
20824
|
+
samples: number().int().nonnegative(),
|
|
20825
|
+
sum: number(),
|
|
20826
|
+
min: number(),
|
|
20827
|
+
max: number()
|
|
20828
|
+
});
|
|
20574
20829
|
DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).readonly()), method(object({
|
|
20575
20830
|
deviceId: number(),
|
|
20576
20831
|
trackId: string()
|
|
@@ -20617,6 +20872,14 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
|
|
|
20617
20872
|
kinds: array(string()).optional(),
|
|
20618
20873
|
limit: number().int().min(1).max(MAX_EVENT_QUERY_LIMIT).default(DEFAULT_EVENT_QUERY_LIMIT)
|
|
20619
20874
|
}), array(SensorEventSchema).readonly()), method(KeyEventQueryInput, array(KeyEventSchema).readonly()), method(KeyEventBatchQueryInput, array(KeyEventsForDeviceSchema).readonly()), method(object({
|
|
20875
|
+
deviceId: number(),
|
|
20876
|
+
series: AnalyticsLtsSeriesSchema,
|
|
20877
|
+
/** Omit for EVERY scope of this series in the range. */
|
|
20878
|
+
scope: string().optional(),
|
|
20879
|
+
from: number(),
|
|
20880
|
+
to: number(),
|
|
20881
|
+
limit: number().int().positive().optional()
|
|
20882
|
+
}), array(LtsBucketSchema).readonly()), method(object({
|
|
20620
20883
|
deviceId: number(),
|
|
20621
20884
|
since: number(),
|
|
20622
20885
|
until: number(),
|
|
@@ -21235,6 +21498,14 @@ var MotionSourceEnum = _enum([
|
|
|
21235
21498
|
*/
|
|
21236
21499
|
var MotionSourcesSchema = array(MotionSourceEnum);
|
|
21237
21500
|
/**
|
|
21501
|
+
* Which root detectors a camera runs. Deliberately the SAME vocabulary
|
|
21502
|
+
* post-analysis already tags every detection with (`DetectionSource`) rather
|
|
21503
|
+
* than a second spelling of the same two ideas — the value an operator picks
|
|
21504
|
+
* here is the value that comes back on the track, the overlay and the debug
|
|
21505
|
+
* row.
|
|
21506
|
+
*/
|
|
21507
|
+
var DetectionSourcesSchema = array(DetectionSourceSchema);
|
|
21508
|
+
/**
|
|
21238
21509
|
* Input shape for `pipeline-runner.reportMotion` cap method. Exported
|
|
21239
21510
|
* so cap-side consumers (the orchestrator forward, the runner addon's
|
|
21240
21511
|
* cap implementation, tests) can reuse the type instead of redeclaring
|
|
@@ -21385,6 +21656,35 @@ var RunnerCameraConfigSchema = object({
|
|
|
21385
21656
|
* events; the orchestrator forwards to `reportMotion`.
|
|
21386
21657
|
*/
|
|
21387
21658
|
motionSources: MotionSourcesSchema.default(["analyzer"]),
|
|
21659
|
+
/**
|
|
21660
|
+
* WHICH root detector runs for this camera. The detection counterpart of
|
|
21661
|
+
* {@link motionSources}, same shape and same discipline: a per-camera list
|
|
21662
|
+
* of sources the system understands, vendor-agnostic, owned here.
|
|
21663
|
+
*
|
|
21664
|
+
* - `pipeline` — this runner's own root step on decoded pixels (`steps`).
|
|
21665
|
+
* - `onboard` — the CAMERA's own detector, admitted only when it is named
|
|
21666
|
+
* here. Its boxes reach post-analysis on the same
|
|
21667
|
+
* `PipelineInferenceResult` payload as the pipeline's, so an onboard-born
|
|
21668
|
+
* track gets the same tracker, the same overlay and the same detail
|
|
21669
|
+
* subtree (face / plate / embedding).
|
|
21670
|
+
*
|
|
21671
|
+
* `['onboard']` alone is the REPLACEMENT: this runner's root step does not
|
|
21672
|
+
* run, and that is where a camera with a usable onboard detector buys back
|
|
21673
|
+
* its share of the accelerator. It saves the root inference, not the decode
|
|
21674
|
+
* — the detail subtree still needs pixels to cut crops from.
|
|
21675
|
+
*
|
|
21676
|
+
* A camera whose onboard detections carry no geometry cannot serve as a root
|
|
21677
|
+
* step at all (there is nothing to track), and the cap that knows this says
|
|
21678
|
+
* so on `native-object-detection.getOptions().geometry`. On Reolink that is
|
|
21679
|
+
* every battery camera: the boxes ride a sub-stream a battery camera never
|
|
21680
|
+
* attaches, so such a camera stays on `['pipeline']` and its onboard AI is
|
|
21681
|
+
* worth exactly what it already is — a wake signal with a class.
|
|
21682
|
+
*
|
|
21683
|
+
* Defaults to `['pipeline']`, which is byte-for-byte today's behaviour: a
|
|
21684
|
+
* vendor never turns a detector on for the operator, and neither does a
|
|
21685
|
+
* default.
|
|
21686
|
+
*/
|
|
21687
|
+
detectionSources: DetectionSourcesSchema.default(["pipeline"]),
|
|
21388
21688
|
pipelineEnabled: boolean().default(true),
|
|
21389
21689
|
/** Ordered tree of video steps. Absent → runner skips video detection. */
|
|
21390
21690
|
steps: array(PipelineStepInputSchema).readonly().optional(),
|
|
@@ -21566,7 +21866,47 @@ var RunnerLocalMetricsSchema = object({
|
|
|
21566
21866
|
queueDepth: number(),
|
|
21567
21867
|
frameLazy: FrameLazyMetricsSchema.optional()
|
|
21568
21868
|
});
|
|
21869
|
+
/**
|
|
21870
|
+
* Pipeline Runner capability — runtime detection workhorse.
|
|
21871
|
+
*
|
|
21872
|
+
* One instance per node. Receives camera assignments from
|
|
21873
|
+
* `addon-pipeline-orchestrator`, subscribes to the local stream-broker for
|
|
21874
|
+
* decoded frames, drains motion + detection queues, calls the local
|
|
21875
|
+
* `motion-detection` and `pipeline-executor` capabilities, and emits typed
|
|
21876
|
+
* `pipeline.inference-result` and `detection.motion-analysis` events on
|
|
21877
|
+
* the bus.
|
|
21878
|
+
*
|
|
21879
|
+
* Distinct from `pipeline-orchestrator` (the hub-side load balancer) — the
|
|
21880
|
+
* runner has zero knowledge of other agents, no global state, and never
|
|
21881
|
+
* makes assignment decisions itself.
|
|
21882
|
+
*/
|
|
21883
|
+
/**
|
|
21884
|
+
* Why a runner declined to look at a camera out of band. Named rather than a
|
|
21885
|
+
* bare `false`: a camera asleep on battery (D173), one attached elsewhere, one
|
|
21886
|
+
* already mid-session and one already bursting are four different facts, and a
|
|
21887
|
+
* caller told only "no" cannot tell a protection from a bug.
|
|
21888
|
+
*/
|
|
21889
|
+
var OccupancyBurstRefusalSchema = _enum([
|
|
21890
|
+
"not-attached",
|
|
21891
|
+
"battery-asleep",
|
|
21892
|
+
"not-watching",
|
|
21893
|
+
"already-bursting"
|
|
21894
|
+
]);
|
|
21569
21895
|
method(RunnerCameraConfigSchema, object({ success: literal(true) }), { kind: "mutation" }), method(object({ deviceId: number() }), object({ success: literal(true) }), { kind: "mutation" }), method(ReportMotionInputSchema, object({ success: literal(true) }), { kind: "mutation" }), method(_void(), RunnerLocalLoadSchema), method(_void(), RunnerLocalMetricsSchema), method(object({ deviceId: number() }), CameraMetricsSchema.nullable()), method(_void(), array(CameraMetricsWithDeviceIdSchema).readonly()), method(_void(), array(number()).readonly()), method(object({
|
|
21896
|
+
deviceId: number(),
|
|
21897
|
+
/** How many frames to collect. The caller sizes this against what its
|
|
21898
|
+
* own confirmation needs; the runner clamps it to the field's range. */
|
|
21899
|
+
frames: number().int().positive().optional(),
|
|
21900
|
+
/** Why, for the log. A burst nobody can attribute is a cost nobody can
|
|
21901
|
+
* defend — the periodic one at least has a timer to point at. */
|
|
21902
|
+
reason: string()
|
|
21903
|
+
}), object({
|
|
21904
|
+
started: boolean(),
|
|
21905
|
+
refusedBecause: OccupancyBurstRefusalSchema.optional()
|
|
21906
|
+
}), {
|
|
21907
|
+
auth: "admin",
|
|
21908
|
+
kind: "mutation"
|
|
21909
|
+
}), method(object({
|
|
21570
21910
|
handle: FrameHandleSchema,
|
|
21571
21911
|
bbox: NativeCropBboxSchema,
|
|
21572
21912
|
maxWidth: number().int().positive().optional(),
|
|
@@ -23936,10 +24276,28 @@ DeviceType.Camera, method(object({ deviceId: number().int().nonnegative() }), ar
|
|
|
23936
24276
|
}), boolean()), method(object({
|
|
23937
24277
|
deviceId: number().int().nonnegative(),
|
|
23938
24278
|
sessionId: string()
|
|
23939
|
-
}), object({
|
|
23940
|
-
|
|
23941
|
-
|
|
23942
|
-
|
|
24279
|
+
}), object({
|
|
24280
|
+
pendingRenegotiation: object({
|
|
24281
|
+
target: WebrtcStreamTargetSchema,
|
|
24282
|
+
epoch: number()
|
|
24283
|
+
}).nullable(),
|
|
24284
|
+
/**
|
|
24285
|
+
* Whether the session still EXISTS.
|
|
24286
|
+
*
|
|
24287
|
+
* A consumer that holds a resource for the life of a session needs to
|
|
24288
|
+
* be able to ask, because a session does not always end the way it
|
|
24289
|
+
* began. Measured on this hub 2026-09-13: an Echo that got stuck never
|
|
24290
|
+
* sent `SessionDisconnected`, so the Alexa exporter's
|
|
24291
|
+
* `releaseEgressTranscode` never ran, and a 2304x1296 HEVC to 720p
|
|
24292
|
+
* H.264 transcode kept running for NOBODY for more than twenty
|
|
24293
|
+
* minutes. The WebRTC session had logged `WebRTC session closed`
|
|
24294
|
+
* minutes earlier — the broker knew; the holder had no way to ask.
|
|
24295
|
+
*
|
|
24296
|
+
* `false` for a session id the provider has never heard of, which is
|
|
24297
|
+
* the same answer as "it ended": either way nothing is holding it up.
|
|
24298
|
+
*/
|
|
24299
|
+
alive: boolean()
|
|
24300
|
+
}));
|
|
23943
24301
|
object({
|
|
23944
24302
|
/** All accessory children of the parent. */
|
|
23945
24303
|
childDeviceIds: array(number()).readonly(),
|
|
@@ -27017,7 +27375,7 @@ var NativeDetectionSchema = object({
|
|
|
27017
27375
|
/** Firmware-provided confidence [0..1]. Reolink pushes don't carry it → undefined. */
|
|
27018
27376
|
confidence: number().min(0).max(1).optional()
|
|
27019
27377
|
});
|
|
27020
|
-
object({
|
|
27378
|
+
var NativeObjectDetectionStatusSchema = object({
|
|
27021
27379
|
/**
|
|
27022
27380
|
* Last observed instance per class. Missing entries mean the class
|
|
27023
27381
|
* is supported but nothing has been seen since the provider started.
|
|
@@ -27034,14 +27392,56 @@ object({
|
|
|
27034
27392
|
supportedClasses: array(NativeObjectClassEnum).readonly(),
|
|
27035
27393
|
/**
|
|
27036
27394
|
* Whether forwarding of onboard AI detections is enabled for this device.
|
|
27037
|
-
*
|
|
27038
|
-
*
|
|
27395
|
+
*
|
|
27396
|
+
* Cold-start OFF on every camera. A vendor does not decide which detector a
|
|
27397
|
+
* camera runs — that is the operator's choice, and it is made where every
|
|
27398
|
+
* other detection choice is made. `geometry` on
|
|
27399
|
+
* {@link NativeObjectDetectionOptionsSchema} is how the form says what the
|
|
27400
|
+
* choice would buy this particular camera.
|
|
27039
27401
|
*/
|
|
27040
27402
|
enabled: boolean()
|
|
27041
|
-
})
|
|
27403
|
+
});
|
|
27404
|
+
/**
|
|
27405
|
+
* WHEN a camera's onboard detections carry geometry.
|
|
27406
|
+
*
|
|
27407
|
+
* - `boxed` — always. The provider holds a standing channel for the boxes, so
|
|
27408
|
+
* a detection is a trackable subject whenever the camera sees one.
|
|
27409
|
+
* - `while-streaming` — only while some stream of this camera is already open.
|
|
27410
|
+
* The boxes ride the video's own side-channel rather than a feed of their
|
|
27411
|
+
* own, so they cost nothing and they exist only when something is pulling.
|
|
27412
|
+
* On Reolink this is every BATTERY camera: a persistent second feed is real
|
|
27413
|
+
* radio drain, but a camera that is awake is awake precisely because
|
|
27414
|
+
* something is in front of it, and its stream is already being pulled.
|
|
27415
|
+
* - `flag-only` — never. The firmware ships the class and nothing else; the
|
|
27416
|
+
* pipeline needs geometry to make a subject, so such a push reaches the
|
|
27417
|
+
* tracker as motion and no further.
|
|
27418
|
+
*
|
|
27419
|
+
* Reported and not inferred, because the operator's question in front of the
|
|
27420
|
+
* picker is "what do I get", and these are three different answers (D14: the
|
|
27421
|
+
* derived form is only as honest as `getOptions`).
|
|
27422
|
+
*/
|
|
27423
|
+
var NativeObjectGeometryEnum = _enum([
|
|
27424
|
+
"boxed",
|
|
27425
|
+
"while-streaming",
|
|
27426
|
+
"flag-only"
|
|
27427
|
+
]);
|
|
27428
|
+
var NativeObjectDetectionOptionsSchema = object({
|
|
27429
|
+
/** Classes this firmware can detect — the same list the status reports. */
|
|
27430
|
+
supportedClasses: array(NativeObjectClassEnum).readonly(),
|
|
27431
|
+
/** What a detection from this camera carries. */
|
|
27432
|
+
geometry: NativeObjectGeometryEnum
|
|
27433
|
+
});
|
|
27434
|
+
var NativeObjectDetectionSettingsPatchSchema = object({ enabled: boolean().optional() });
|
|
27435
|
+
NativeObjectDetectionStatusSchema.extend({
|
|
27042
27436
|
/** Required by createRuntimeStateBridge — epoch ms of last refresh. */
|
|
27043
27437
|
lastFetchedAt: number() });
|
|
27044
|
-
DeviceType.Camera, method(object({
|
|
27438
|
+
DeviceType.Camera, method(object({ deviceId: number() }), NativeObjectDetectionOptionsSchema), method(object({
|
|
27439
|
+
deviceId: number(),
|
|
27440
|
+
settings: NativeObjectDetectionSettingsPatchSchema
|
|
27441
|
+
}), _void(), {
|
|
27442
|
+
kind: "mutation",
|
|
27443
|
+
auth: "admin"
|
|
27444
|
+
}), method(object({
|
|
27045
27445
|
deviceId: number(),
|
|
27046
27446
|
enabled: boolean()
|
|
27047
27447
|
}), _void(), {
|
|
@@ -30840,7 +31240,28 @@ var PerScopeBreakdownSchema = object({
|
|
|
30840
31240
|
/** Total tracked objects in this scope (frame / zone / unzoned). */
|
|
30841
31241
|
totalObjects: number().int().nonnegative(),
|
|
30842
31242
|
/** Per-class count. Keys are macro class names (e.g. `person`, `car`). */
|
|
30843
|
-
byClass: record(string(), number().int().nonnegative())
|
|
31243
|
+
byClass: record(string(), number().int().nonnegative()),
|
|
31244
|
+
/**
|
|
31245
|
+
* Of `totalObjects`, how many are STANDING — objects the census holds,
|
|
31246
|
+
* present but not going anywhere (a parked car, a bin, a statue).
|
|
31247
|
+
*
|
|
31248
|
+
* The operator's question about a scene has two halves and they answer
|
|
31249
|
+
* different things: "what is parked here" is stable for hours and must not
|
|
31250
|
+
* flap, while "who is walking through" is the thing an alert is about. One
|
|
31251
|
+
* number could only serve one of them, and `totalObjects` served the first
|
|
31252
|
+
* badly — a passer-by moved it and every occupancy rule saw a change.
|
|
31253
|
+
*
|
|
31254
|
+
* `standing + transient === totalObjects`, always. The total keeps its old
|
|
31255
|
+
* meaning exactly, so no rule written against it changes behaviour.
|
|
31256
|
+
*
|
|
31257
|
+
* ABSENT means UNKNOWN, never zero (D393): a snapshot from a node older than
|
|
31258
|
+
* this field cannot say, and a reader that folds absence in as 0 reports "no
|
|
31259
|
+
* parked objects here" about a camera whose lot is full.
|
|
31260
|
+
*/
|
|
31261
|
+
standingObjects: number().int().nonnegative().optional(),
|
|
31262
|
+
/** Of `totalObjects`, how many are passing through. See `standingObjects` —
|
|
31263
|
+
* same absence rule. */
|
|
31264
|
+
transientObjects: number().int().nonnegative().optional()
|
|
30844
31265
|
});
|
|
30845
31266
|
var ZoneScopeBreakdownSchema = PerScopeBreakdownSchema.extend({
|
|
30846
31267
|
zoneId: string(),
|
|
@@ -33779,12 +34200,24 @@ Object.freeze({
|
|
|
33779
34200
|
addonId: null,
|
|
33780
34201
|
access: "create"
|
|
33781
34202
|
},
|
|
34203
|
+
"nativeObjectDetection.getOptions": {
|
|
34204
|
+
capName: "native-object-detection",
|
|
34205
|
+
capScope: "device",
|
|
34206
|
+
addonId: null,
|
|
34207
|
+
access: "view"
|
|
34208
|
+
},
|
|
33782
34209
|
"nativeObjectDetection.setEnabled": {
|
|
33783
34210
|
capName: "native-object-detection",
|
|
33784
34211
|
capScope: "device",
|
|
33785
34212
|
addonId: null,
|
|
33786
34213
|
access: "create"
|
|
33787
34214
|
},
|
|
34215
|
+
"nativeObjectDetection.setSettings": {
|
|
34216
|
+
capName: "native-object-detection",
|
|
34217
|
+
capScope: "device",
|
|
34218
|
+
addonId: null,
|
|
34219
|
+
access: "create"
|
|
34220
|
+
},
|
|
33788
34221
|
"navigation.getFeatures": {
|
|
33789
34222
|
capName: "navigation",
|
|
33790
34223
|
capScope: "device",
|
|
@@ -34049,6 +34482,12 @@ Object.freeze({
|
|
|
34049
34482
|
addonId: null,
|
|
34050
34483
|
access: "view"
|
|
34051
34484
|
},
|
|
34485
|
+
"notificationRules.getClipRetentionAsks": {
|
|
34486
|
+
capName: "notification-rules",
|
|
34487
|
+
capScope: "system",
|
|
34488
|
+
addonId: null,
|
|
34489
|
+
access: "view"
|
|
34490
|
+
},
|
|
34052
34491
|
"notificationRules.getConditionCatalog": {
|
|
34053
34492
|
capName: "notification-rules",
|
|
34054
34493
|
capScope: "system",
|
|
@@ -34559,6 +34998,12 @@ Object.freeze({
|
|
|
34559
34998
|
addonId: null,
|
|
34560
34999
|
access: "create"
|
|
34561
35000
|
},
|
|
35001
|
+
"pipelineAnalytics.readLongTermSeries": {
|
|
35002
|
+
capName: "pipeline-analytics",
|
|
35003
|
+
capScope: "device",
|
|
35004
|
+
addonId: null,
|
|
35005
|
+
access: "view"
|
|
35006
|
+
},
|
|
34562
35007
|
"pipelineAnalytics.rebuildObjectEmbeddings": {
|
|
34563
35008
|
capName: "pipeline-analytics",
|
|
34564
35009
|
capScope: "device",
|
|
@@ -35231,6 +35676,12 @@ Object.freeze({
|
|
|
35231
35676
|
addonId: null,
|
|
35232
35677
|
access: "create"
|
|
35233
35678
|
},
|
|
35679
|
+
"pipelineRunner.requestOccupancyBurst": {
|
|
35680
|
+
capName: "pipeline-runner",
|
|
35681
|
+
capScope: "system",
|
|
35682
|
+
addonId: null,
|
|
35683
|
+
access: "create"
|
|
35684
|
+
},
|
|
35234
35685
|
"pipelineRunner.runDetailSubtree": {
|
|
35235
35686
|
capName: "pipeline-runner",
|
|
35236
35687
|
capScope: "system",
|
|
@@ -36443,6 +36894,12 @@ Object.freeze({
|
|
|
36443
36894
|
addonId: null,
|
|
36444
36895
|
access: "create"
|
|
36445
36896
|
},
|
|
36897
|
+
"streamBroker.reportStreamSignal": {
|
|
36898
|
+
capName: "stream-broker",
|
|
36899
|
+
capScope: "system",
|
|
36900
|
+
addonId: null,
|
|
36901
|
+
access: "create"
|
|
36902
|
+
},
|
|
36446
36903
|
"streamBroker.restartProfile": {
|
|
36447
36904
|
capName: "stream-broker",
|
|
36448
36905
|
capScope: "system",
|
|
@@ -36527,6 +36984,12 @@ Object.freeze({
|
|
|
36527
36984
|
addonId: null,
|
|
36528
36985
|
access: "create"
|
|
36529
36986
|
},
|
|
36987
|
+
"streamSignals.listSignals": {
|
|
36988
|
+
capName: "stream-signals",
|
|
36989
|
+
capScope: "device",
|
|
36990
|
+
addonId: null,
|
|
36991
|
+
access: "view"
|
|
36992
|
+
},
|
|
36530
36993
|
"switch.setState": {
|
|
36531
36994
|
capName: "switch",
|
|
36532
36995
|
capScope: "device",
|
|
@@ -37999,11 +38462,21 @@ Object.freeze({
|
|
|
37999
38462
|
form: "single",
|
|
38000
38463
|
optional: false
|
|
38001
38464
|
}],
|
|
38465
|
+
"nativeObjectDetection.getOptions": [{
|
|
38466
|
+
name: "deviceId",
|
|
38467
|
+
form: "single",
|
|
38468
|
+
optional: false
|
|
38469
|
+
}],
|
|
38002
38470
|
"nativeObjectDetection.setEnabled": [{
|
|
38003
38471
|
name: "deviceId",
|
|
38004
38472
|
form: "single",
|
|
38005
38473
|
optional: false
|
|
38006
38474
|
}],
|
|
38475
|
+
"nativeObjectDetection.setSettings": [{
|
|
38476
|
+
name: "deviceId",
|
|
38477
|
+
form: "single",
|
|
38478
|
+
optional: false
|
|
38479
|
+
}],
|
|
38007
38480
|
"navigation.getFeatures": [{
|
|
38008
38481
|
name: "deviceId",
|
|
38009
38482
|
form: "single",
|
|
@@ -38353,6 +38826,11 @@ Object.freeze({
|
|
|
38353
38826
|
form: "single",
|
|
38354
38827
|
optional: false
|
|
38355
38828
|
}],
|
|
38829
|
+
"pipelineAnalytics.readLongTermSeries": [{
|
|
38830
|
+
name: "deviceId",
|
|
38831
|
+
form: "single",
|
|
38832
|
+
optional: false
|
|
38833
|
+
}],
|
|
38356
38834
|
"pipelineAnalytics.rebuildObjectEmbeddings": [{
|
|
38357
38835
|
name: "deviceId",
|
|
38358
38836
|
form: "single",
|
|
@@ -38543,6 +39021,11 @@ Object.freeze({
|
|
|
38543
39021
|
form: "single",
|
|
38544
39022
|
optional: false
|
|
38545
39023
|
}],
|
|
39024
|
+
"pipelineRunner.requestOccupancyBurst": [{
|
|
39025
|
+
name: "deviceId",
|
|
39026
|
+
form: "single",
|
|
39027
|
+
optional: false
|
|
39028
|
+
}],
|
|
38546
39029
|
"pipelineRunner.runDetailSubtree": [{
|
|
38547
39030
|
name: "deviceId",
|
|
38548
39031
|
form: "single",
|
|
@@ -38899,6 +39382,11 @@ Object.freeze({
|
|
|
38899
39382
|
form: "single",
|
|
38900
39383
|
optional: false
|
|
38901
39384
|
}],
|
|
39385
|
+
"streamBroker.reportStreamSignal": [{
|
|
39386
|
+
name: "deviceId",
|
|
39387
|
+
form: "single",
|
|
39388
|
+
optional: false
|
|
39389
|
+
}],
|
|
38902
39390
|
"streamBroker.restartProfile": [{
|
|
38903
39391
|
name: "deviceId",
|
|
38904
39392
|
form: "single",
|
|
@@ -39729,7 +40217,7 @@ async function acquireAlexaEgress(input) {
|
|
|
39729
40217
|
profile: sourceProfile
|
|
39730
40218
|
},
|
|
39731
40219
|
encode: ALEXA_EGRESS_PROFILE,
|
|
39732
|
-
rateControl: "
|
|
40220
|
+
rateControl: "tight",
|
|
39733
40221
|
publishLocally: true,
|
|
39734
40222
|
tag: `alexa/${sessionId}`
|
|
39735
40223
|
});
|
|
@@ -39753,6 +40241,7 @@ async function acquireAlexaEgress(input) {
|
|
|
39753
40241
|
meta: {
|
|
39754
40242
|
pipelineKey: transcode.pipelineKey,
|
|
39755
40243
|
camStreamId,
|
|
40244
|
+
sourceProfile: input.sourceProfile,
|
|
39756
40245
|
encoder: transcode.encoder,
|
|
39757
40246
|
decodeHwAccel: transcode.decodeHwAccel ?? "software"
|
|
39758
40247
|
}
|
|
@@ -39786,6 +40275,512 @@ async function releaseAlexaEgress(input) {
|
|
|
39786
40275
|
}
|
|
39787
40276
|
}
|
|
39788
40277
|
//#endregion
|
|
40278
|
+
//#region src/egress/egress-handle-reaper.ts
|
|
40279
|
+
/**
|
|
40280
|
+
* Which handles should be released now.
|
|
40281
|
+
*
|
|
40282
|
+
* A session the broker says is GONE is reclaimed. A session it could not be
|
|
40283
|
+
* asked about is KEPT — a read that failed is not evidence of death, and
|
|
40284
|
+
* releasing a live session's transcode would black out a working stream to
|
|
40285
|
+
* save a process (D393, read in the direction that destroys work).
|
|
40286
|
+
*/
|
|
40287
|
+
async function reapDeadEgressHandles(input) {
|
|
40288
|
+
const dead = [];
|
|
40289
|
+
for (const handle of input.held) if (await input.isAlive(handle) === false) dead.push(handle);
|
|
40290
|
+
return dead;
|
|
40291
|
+
}
|
|
40292
|
+
/** How often the sweep runs. Well under the minute Amazon requires a session
|
|
40293
|
+
* to survive, so a genuinely dead one is not transcoding for long. */
|
|
40294
|
+
var EGRESS_REAP_INTERVAL_MS = 3e4;
|
|
40295
|
+
function logReaped(logger, handle) {
|
|
40296
|
+
logger?.warn("alexa egress: session is GONE — reclaiming the transcode it still held", {
|
|
40297
|
+
tags: { deviceId: handle.deviceId },
|
|
40298
|
+
meta: {
|
|
40299
|
+
sessionId: handle.sessionId,
|
|
40300
|
+
pipelineKey: handle.pipelineKey,
|
|
40301
|
+
reason: "no SessionDisconnected directive"
|
|
40302
|
+
}
|
|
40303
|
+
});
|
|
40304
|
+
}
|
|
40305
|
+
//#endregion
|
|
40306
|
+
//#region src/egress/alexa-source-pick.ts
|
|
40307
|
+
/** Amazon's documented ceiling. */
|
|
40308
|
+
var ALEXA_MAX_LINES = 1080;
|
|
40309
|
+
/**
|
|
40310
|
+
* Which profile slot serves `camStreamId`, or `null` when none does — a read
|
|
40311
|
+
* that failed is `null` too, and the caller keeps its previous behaviour
|
|
40312
|
+
* rather than guessing a slot from an error (D393).
|
|
40313
|
+
*/
|
|
40314
|
+
async function profileForCamStream(input) {
|
|
40315
|
+
try {
|
|
40316
|
+
const slots = await input.api.streamBroker.listAllProfileSlots.query();
|
|
40317
|
+
for (const slot of slots) {
|
|
40318
|
+
if (slot.deviceId !== input.deviceId) continue;
|
|
40319
|
+
if (slot.sourceCamStreamId !== input.camStreamId) continue;
|
|
40320
|
+
if (slot.profile === "high" || slot.profile === "mid" || slot.profile === "low") return slot.profile;
|
|
40321
|
+
}
|
|
40322
|
+
return null;
|
|
40323
|
+
} catch (err) {
|
|
40324
|
+
input.logger?.warn("alexa rtc-session: could not read the profile slots", {
|
|
40325
|
+
tags: { deviceId: input.deviceId },
|
|
40326
|
+
meta: { error: errMsg(err) }
|
|
40327
|
+
});
|
|
40328
|
+
return null;
|
|
40329
|
+
}
|
|
40330
|
+
}
|
|
40331
|
+
//#endregion
|
|
40332
|
+
//#region src/handlers/endpoint-id.ts
|
|
40333
|
+
var SEPARATOR = "__";
|
|
40334
|
+
function parseCameraEndpointId(raw) {
|
|
40335
|
+
if (!raw.includes(SEPARATOR)) {
|
|
40336
|
+
const id = parseNonNegativeInt(raw);
|
|
40337
|
+
if (id === null) return {
|
|
40338
|
+
kind: "invalid",
|
|
40339
|
+
reason: `not a numeric deviceId: ${raw}`
|
|
40340
|
+
};
|
|
40341
|
+
return {
|
|
40342
|
+
kind: "camera",
|
|
40343
|
+
deviceId: id
|
|
40344
|
+
};
|
|
40345
|
+
}
|
|
40346
|
+
const [head, tail, ...rest] = raw.split(SEPARATOR);
|
|
40347
|
+
if (head === void 0 || tail === void 0 || rest.length > 0) return {
|
|
40348
|
+
kind: "invalid",
|
|
40349
|
+
reason: `unexpected segments in endpointId: ${raw}`
|
|
40350
|
+
};
|
|
40351
|
+
const parent = parseNonNegativeInt(head);
|
|
40352
|
+
if (parent === null) return {
|
|
40353
|
+
kind: "invalid",
|
|
40354
|
+
reason: `parent segment not numeric: ${raw}`
|
|
40355
|
+
};
|
|
40356
|
+
if (tail === "autotrack") return {
|
|
40357
|
+
kind: "autotrack",
|
|
40358
|
+
parentDeviceId: parent
|
|
40359
|
+
};
|
|
40360
|
+
if (tail === "privacy") return {
|
|
40361
|
+
kind: "privacy",
|
|
40362
|
+
parentDeviceId: parent
|
|
40363
|
+
};
|
|
40364
|
+
if (tail === "alarm") return {
|
|
40365
|
+
kind: "alarm-panel",
|
|
40366
|
+
deviceId: parent
|
|
40367
|
+
};
|
|
40368
|
+
const child = parseNonNegativeInt(tail);
|
|
40369
|
+
if (child === null) return {
|
|
40370
|
+
kind: "invalid",
|
|
40371
|
+
reason: `child segment not numeric and not 'autotrack'/'privacy'/'alarm': ${raw}`
|
|
40372
|
+
};
|
|
40373
|
+
return {
|
|
40374
|
+
kind: "child",
|
|
40375
|
+
parentDeviceId: parent,
|
|
40376
|
+
childDeviceId: child
|
|
40377
|
+
};
|
|
40378
|
+
}
|
|
40379
|
+
function parseNonNegativeInt(s) {
|
|
40380
|
+
if (!/^\d+$/.test(s)) return null;
|
|
40381
|
+
const n = Number.parseInt(s, 10);
|
|
40382
|
+
if (!Number.isFinite(n) || n < 0) return null;
|
|
40383
|
+
return n;
|
|
40384
|
+
}
|
|
40385
|
+
//#endregion
|
|
40386
|
+
//#region src/handlers/error-envelope.ts
|
|
40387
|
+
/**
|
|
40388
|
+
* Shared Alexa `Alexa/ErrorResponse` envelope builder.
|
|
40389
|
+
*
|
|
40390
|
+
* Lives in its own module so every handler (and the directive router)
|
|
40391
|
+
* can emit its own namespace-appropriate error without circular imports.
|
|
40392
|
+
*/
|
|
40393
|
+
object({ event: object({
|
|
40394
|
+
header: object({
|
|
40395
|
+
namespace: literal("Alexa"),
|
|
40396
|
+
name: literal("ErrorResponse"),
|
|
40397
|
+
messageId: string(),
|
|
40398
|
+
payloadVersion: literal("3")
|
|
40399
|
+
}),
|
|
40400
|
+
payload: object({
|
|
40401
|
+
type: string(),
|
|
40402
|
+
message: string()
|
|
40403
|
+
})
|
|
40404
|
+
}) });
|
|
40405
|
+
function errorEnvelope(header, type, message) {
|
|
40406
|
+
return { event: {
|
|
40407
|
+
header: {
|
|
40408
|
+
namespace: "Alexa",
|
|
40409
|
+
name: "ErrorResponse",
|
|
40410
|
+
messageId: header.messageId,
|
|
40411
|
+
payloadVersion: "3"
|
|
40412
|
+
},
|
|
40413
|
+
payload: {
|
|
40414
|
+
type,
|
|
40415
|
+
message
|
|
40416
|
+
}
|
|
40417
|
+
} };
|
|
40418
|
+
}
|
|
40419
|
+
//#endregion
|
|
40420
|
+
//#region src/handlers/types.ts
|
|
40421
|
+
/**
|
|
40422
|
+
* Zod schemas for the subset of the Alexa Smart Home directive surface
|
|
40423
|
+
* that we actually parse hub-side. The Smart Home Skill API ships
|
|
40424
|
+
* thousands of optional fields per namespace — we only validate what
|
|
40425
|
+
* we read; everything else passes through as `unknown`.
|
|
40426
|
+
*
|
|
40427
|
+
* Reference: https://developer.amazon.com/en-US/docs/alexa/smarthome/smart-home-skill-api-message-reference.html
|
|
40428
|
+
*/
|
|
40429
|
+
/** A directive header carries namespace + name + token + correlation id. */
|
|
40430
|
+
var DirectiveHeaderSchema = object({
|
|
40431
|
+
namespace: string(),
|
|
40432
|
+
name: string(),
|
|
40433
|
+
payloadVersion: string(),
|
|
40434
|
+
messageId: string(),
|
|
40435
|
+
correlationToken: string().optional()
|
|
40436
|
+
});
|
|
40437
|
+
/** Scope carries the bearer token Alexa minted via our OAuth provider. */
|
|
40438
|
+
var BearerScopeSchema = object({
|
|
40439
|
+
type: literal("BearerToken"),
|
|
40440
|
+
token: string()
|
|
40441
|
+
});
|
|
40442
|
+
/** Endpoint reference inside a directive payload. */
|
|
40443
|
+
var EndpointRefSchema = object({
|
|
40444
|
+
endpointId: string(),
|
|
40445
|
+
scope: BearerScopeSchema.optional(),
|
|
40446
|
+
cookie: record(string(), string()).optional()
|
|
40447
|
+
});
|
|
40448
|
+
var DiscoveryDirectiveSchema = object({
|
|
40449
|
+
header: DirectiveHeaderSchema.extend({
|
|
40450
|
+
namespace: literal("Alexa.Discovery"),
|
|
40451
|
+
name: literal("Discover")
|
|
40452
|
+
}),
|
|
40453
|
+
payload: object({ scope: BearerScopeSchema })
|
|
40454
|
+
});
|
|
40455
|
+
/** Envelope wrapping a directive on the Alexa→skill wire. */
|
|
40456
|
+
var DirectiveRequestSchema = object({ directive: object({
|
|
40457
|
+
header: DirectiveHeaderSchema,
|
|
40458
|
+
endpoint: EndpointRefSchema.optional(),
|
|
40459
|
+
payload: unknown().optional()
|
|
40460
|
+
}) });
|
|
40461
|
+
var InitializeCameraStreamsPayloadSchema = object({ cameraStreams: array(object({
|
|
40462
|
+
protocol: string(),
|
|
40463
|
+
resolution: object({
|
|
40464
|
+
width: number(),
|
|
40465
|
+
height: number()
|
|
40466
|
+
}).optional(),
|
|
40467
|
+
authorizationType: string().optional(),
|
|
40468
|
+
videoCodec: string().optional(),
|
|
40469
|
+
audioCodec: string().optional()
|
|
40470
|
+
})).optional() });
|
|
40471
|
+
var InitiateSessionWithOfferPayloadSchema = object({
|
|
40472
|
+
sessionId: string(),
|
|
40473
|
+
offer: object({
|
|
40474
|
+
format: string().optional(),
|
|
40475
|
+
value: string()
|
|
40476
|
+
})
|
|
40477
|
+
});
|
|
40478
|
+
var SessionDisconnectedPayloadSchema = object({ sessionId: string() });
|
|
40479
|
+
var SetModePayloadSchema = object({ mode: string() });
|
|
40480
|
+
//#endregion
|
|
40481
|
+
//#region src/handlers/rtc-session.ts
|
|
40482
|
+
var InitiateSessionWithOfferDirectiveSchema = object({
|
|
40483
|
+
endpoint: EndpointRefSchema,
|
|
40484
|
+
payload: InitiateSessionWithOfferPayloadSchema
|
|
40485
|
+
});
|
|
40486
|
+
var SessionDisconnectedDirectiveSchema = object({
|
|
40487
|
+
endpoint: EndpointRefSchema,
|
|
40488
|
+
payload: SessionDisconnectedPayloadSchema
|
|
40489
|
+
});
|
|
40490
|
+
/**
|
|
40491
|
+
* Live egress handles, keyed by `<deviceId>/<sessionId>`.
|
|
40492
|
+
*
|
|
40493
|
+
* The primitive's refcount has no lease TTL: a holder that vanishes without
|
|
40494
|
+
* releasing leaks a child until the broker restarts (D67). This handler is a
|
|
40495
|
+
* holder, so it keeps the one piece of state that lets it not be that holder —
|
|
40496
|
+
* the `pipelineKey` its `SessionDisconnected` has to release.
|
|
40497
|
+
*
|
|
40498
|
+
* A module-level map is right here because the directive handlers are free
|
|
40499
|
+
* functions called per directive; the entry is written on a successful acquire
|
|
40500
|
+
* and deleted on the release path, both of which are the same tick as the
|
|
40501
|
+
* directive that owns it.
|
|
40502
|
+
*/
|
|
40503
|
+
var EGRESS_HANDLES = /* @__PURE__ */ new Map();
|
|
40504
|
+
function egressHandleKey(deviceId, sessionId) {
|
|
40505
|
+
return `${deviceId}/${sessionId}`;
|
|
40506
|
+
}
|
|
40507
|
+
/** Every handle currently held, for the sweep. */
|
|
40508
|
+
function heldEgressHandles() {
|
|
40509
|
+
const held = [];
|
|
40510
|
+
for (const [key, pipelineKey] of EGRESS_HANDLES) {
|
|
40511
|
+
const slash = key.indexOf("/");
|
|
40512
|
+
if (slash <= 0) continue;
|
|
40513
|
+
const deviceId = Number.parseInt(key.slice(0, slash), 10);
|
|
40514
|
+
if (!Number.isFinite(deviceId)) continue;
|
|
40515
|
+
held.push({
|
|
40516
|
+
deviceId,
|
|
40517
|
+
sessionId: key.slice(slash + 1),
|
|
40518
|
+
pipelineKey
|
|
40519
|
+
});
|
|
40520
|
+
}
|
|
40521
|
+
return held;
|
|
40522
|
+
}
|
|
40523
|
+
/** Drop a handle the sweep reclaimed, so it is not reaped twice. */
|
|
40524
|
+
function forgetEgressHandle(handle) {
|
|
40525
|
+
EGRESS_HANDLES.delete(egressHandleKey(handle.deviceId, handle.sessionId));
|
|
40526
|
+
}
|
|
40527
|
+
var WEBRTC_PROFILE_NAMES = [
|
|
40528
|
+
"high",
|
|
40529
|
+
"mid",
|
|
40530
|
+
"low"
|
|
40531
|
+
];
|
|
40532
|
+
function resolveWebrtcTarget(pref) {
|
|
40533
|
+
if (pref === "auto") return void 0;
|
|
40534
|
+
if (WEBRTC_PROFILE_NAMES.includes(pref)) return {
|
|
40535
|
+
kind: "profile",
|
|
40536
|
+
profile: pref
|
|
40537
|
+
};
|
|
40538
|
+
return {
|
|
40539
|
+
kind: "cam-stream",
|
|
40540
|
+
camStreamId: pref
|
|
40541
|
+
};
|
|
40542
|
+
}
|
|
40543
|
+
async function handleInitiateSessionWithOffer(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40544
|
+
const parsed = InitiateSessionWithOfferDirectiveSchema.safeParse({
|
|
40545
|
+
endpoint: endpointRaw,
|
|
40546
|
+
payload: payloadRaw ?? {}
|
|
40547
|
+
});
|
|
40548
|
+
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40549
|
+
const endpoint = parsed.data.endpoint;
|
|
40550
|
+
const payload = parsed.data.payload;
|
|
40551
|
+
const parsedId = parseCameraEndpointId(endpoint.endpointId);
|
|
40552
|
+
if (parsedId.kind !== "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", `endpointId ${endpoint.endpointId} is not a camera`);
|
|
40553
|
+
const deviceId = parsedId.deviceId;
|
|
40554
|
+
const sessionId = payload.sessionId;
|
|
40555
|
+
const log = deps.logger.withTags({
|
|
40556
|
+
deviceId,
|
|
40557
|
+
sessionId
|
|
40558
|
+
});
|
|
40559
|
+
const sdpOffer = payload.offer.value;
|
|
40560
|
+
if (sdpOffer.length === 0) return errorEnvelope(header, "INVALID_DIRECTIVE", "offer.value is empty");
|
|
40561
|
+
const api = deps.ctx.api;
|
|
40562
|
+
const exposedEntry = deps.listExposed().find((e) => e.deviceId === deviceId);
|
|
40563
|
+
const pinnedProfile = (() => {
|
|
40564
|
+
const pref = exposedEntry?.settings?.streamPreference;
|
|
40565
|
+
if (pref === "low" || pref === "mid" || pref === "high") return pref;
|
|
40566
|
+
})();
|
|
40567
|
+
const allowTranscode = exposedEntry?.settings?.allowTranscode !== false;
|
|
40568
|
+
const scored = pinnedProfile === void 0 ? await api.cameraStreams.pickStream.query({
|
|
40569
|
+
deviceId,
|
|
40570
|
+
requirements: {
|
|
40571
|
+
acceptCodecs: ["h264"],
|
|
40572
|
+
minHeight: 480,
|
|
40573
|
+
maxHeight: ALEXA_MAX_LINES,
|
|
40574
|
+
excludeDerived: true,
|
|
40575
|
+
allowTranscode
|
|
40576
|
+
},
|
|
40577
|
+
preferences: { targetHeight: 720 }
|
|
40578
|
+
}).catch((err) => {
|
|
40579
|
+
log.warn("alexa rtc-session: pickStream threw — falling back to the high slot", {
|
|
40580
|
+
tags: { deviceId },
|
|
40581
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
40582
|
+
});
|
|
40583
|
+
return null;
|
|
40584
|
+
}) : null;
|
|
40585
|
+
const scoredProfile = scored === null ? null : await profileForCamStream({
|
|
40586
|
+
api,
|
|
40587
|
+
deviceId,
|
|
40588
|
+
camStreamId: scored.camStreamId,
|
|
40589
|
+
logger: log
|
|
40590
|
+
});
|
|
40591
|
+
const sourceProfile = pinnedProfile ?? scoredProfile ?? "high";
|
|
40592
|
+
if (pinnedProfile === void 0) log.info("alexa rtc-session: source scored against the Echo requirements", {
|
|
40593
|
+
tags: { deviceId },
|
|
40594
|
+
meta: {
|
|
40595
|
+
chosen: sourceProfile,
|
|
40596
|
+
scored: scored === null ? "none-eligible" : scored.reason,
|
|
40597
|
+
camStreamId: scored?.camStreamId ?? null,
|
|
40598
|
+
slot: scoredProfile ?? (scored === null ? null : "no-slot"),
|
|
40599
|
+
height: scored?.resolution?.height ?? null,
|
|
40600
|
+
transcodes: scored?.transcodes ?? null,
|
|
40601
|
+
allowTranscode
|
|
40602
|
+
}
|
|
40603
|
+
});
|
|
40604
|
+
let derivedTarget;
|
|
40605
|
+
/**
|
|
40606
|
+
* The primitive's release handle, when this session acquired one. Recorded so
|
|
40607
|
+
* `SessionDisconnected` can release it: a refcount whose holder disappears is
|
|
40608
|
+
* the one gap D67 leaves open, and the least this handler can do is not BE
|
|
40609
|
+
* that holder.
|
|
40610
|
+
*/
|
|
40611
|
+
let egressPipelineKey = null;
|
|
40612
|
+
const picked = await api.cameraStreams.pickStream.query({
|
|
40613
|
+
deviceId,
|
|
40614
|
+
requirements: {
|
|
40615
|
+
acceptCodecs: ["h264"],
|
|
40616
|
+
minHeight: 480,
|
|
40617
|
+
excludeDerived: true,
|
|
40618
|
+
requireSiblingCodec: ["h265", "hevc"]
|
|
40619
|
+
}
|
|
40620
|
+
}).catch((err) => {
|
|
40621
|
+
log.warn("alexa rtc-session: cameraStreams.pickStream threw — falling back to transcode", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
40622
|
+
return null;
|
|
40623
|
+
});
|
|
40624
|
+
if (picked) {
|
|
40625
|
+
log.info("alexa rtc-session: bypassing transcode via cameraStreams.pickStream", { meta: {
|
|
40626
|
+
sourceProfile,
|
|
40627
|
+
selectedCamStreamId: picked.camStreamId,
|
|
40628
|
+
reason: picked.reason
|
|
40629
|
+
} });
|
|
40630
|
+
derivedTarget = {
|
|
40631
|
+
kind: "cam-stream",
|
|
40632
|
+
camStreamId: picked.camStreamId
|
|
40633
|
+
};
|
|
40634
|
+
} else try {
|
|
40635
|
+
const acquired = await acquireAlexaEgress({
|
|
40636
|
+
api,
|
|
40637
|
+
deviceId,
|
|
40638
|
+
sourceProfile,
|
|
40639
|
+
sessionId,
|
|
40640
|
+
logger: log
|
|
40641
|
+
});
|
|
40642
|
+
egressPipelineKey = acquired.pipelineKey;
|
|
40643
|
+
EGRESS_HANDLES.set(egressHandleKey(deviceId, sessionId), acquired.pipelineKey);
|
|
40644
|
+
derivedTarget = {
|
|
40645
|
+
kind: "cam-stream",
|
|
40646
|
+
camStreamId: acquired.camStreamId
|
|
40647
|
+
};
|
|
40648
|
+
} catch (err) {
|
|
40649
|
+
log.warn("alexa rtc-session: egress acquire failed, falling back to streamPreference target", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
40650
|
+
derivedTarget = resolveWebrtcTarget(exposedEntry?.settings?.streamPreference ?? "auto");
|
|
40651
|
+
}
|
|
40652
|
+
try {
|
|
40653
|
+
const result = await api.webrtcSession.handleOffer.mutate({
|
|
40654
|
+
deviceId,
|
|
40655
|
+
sdpOffer,
|
|
40656
|
+
sessionId,
|
|
40657
|
+
target: derivedTarget,
|
|
40658
|
+
relayOnly: false,
|
|
40659
|
+
nonTrickle: true,
|
|
40660
|
+
disableTurn: true,
|
|
40661
|
+
disableIpv6: true,
|
|
40662
|
+
consumerAttribution: {
|
|
40663
|
+
kind: "alexa",
|
|
40664
|
+
sessionId
|
|
40665
|
+
}
|
|
40666
|
+
});
|
|
40667
|
+
log.info("alexa rtc-session: AnswerGenerated", { meta: {
|
|
40668
|
+
returnedSessionId: result.sessionId,
|
|
40669
|
+
sdpAnswerLen: result.sdpAnswer.length
|
|
40670
|
+
} });
|
|
40671
|
+
return { event: {
|
|
40672
|
+
header: {
|
|
40673
|
+
namespace: "Alexa.RTCSessionController",
|
|
40674
|
+
name: "AnswerGeneratedForSession",
|
|
40675
|
+
messageId: header.messageId,
|
|
40676
|
+
correlationToken: header.correlationToken,
|
|
40677
|
+
payloadVersion: "3"
|
|
40678
|
+
},
|
|
40679
|
+
endpoint: { endpointId: endpoint.endpointId },
|
|
40680
|
+
payload: { answer: {
|
|
40681
|
+
format: payload.offer.format ?? "SDP",
|
|
40682
|
+
value: result.sdpAnswer
|
|
40683
|
+
} }
|
|
40684
|
+
} };
|
|
40685
|
+
} catch (err) {
|
|
40686
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
40687
|
+
const mSectionSummary = (() => {
|
|
40688
|
+
const lines = sdpOffer.split(/\r?\n/);
|
|
40689
|
+
const sections = [];
|
|
40690
|
+
let current = null;
|
|
40691
|
+
for (const raw of lines) {
|
|
40692
|
+
const line = raw.trim();
|
|
40693
|
+
if (line.startsWith("m=")) {
|
|
40694
|
+
if (current) sections.push(current);
|
|
40695
|
+
current = {
|
|
40696
|
+
mid: null,
|
|
40697
|
+
kind: line.split(" ")[0]?.slice(2) ?? "unknown",
|
|
40698
|
+
direction: null,
|
|
40699
|
+
codecs: []
|
|
40700
|
+
};
|
|
40701
|
+
} else if (current) {
|
|
40702
|
+
if (line.startsWith("a=mid:")) current.mid = line.slice(6);
|
|
40703
|
+
else if (/^a=(sendonly|recvonly|sendrecv|inactive)$/.test(line)) current.direction = line.slice(2);
|
|
40704
|
+
else if (line.startsWith("a=rtpmap:")) current.codecs.push(line.slice(9));
|
|
40705
|
+
}
|
|
40706
|
+
}
|
|
40707
|
+
if (current) sections.push(current);
|
|
40708
|
+
return sections;
|
|
40709
|
+
})();
|
|
40710
|
+
log.warn("alexa rtc-session: handleOffer failed", { meta: {
|
|
40711
|
+
error: message,
|
|
40712
|
+
offerLen: sdpOffer.length,
|
|
40713
|
+
mSections: mSectionSummary,
|
|
40714
|
+
offerSdp: sdpOffer
|
|
40715
|
+
} });
|
|
40716
|
+
if (egressPipelineKey !== null) {
|
|
40717
|
+
EGRESS_HANDLES.delete(egressHandleKey(deviceId, sessionId));
|
|
40718
|
+
await releaseAlexaEgress({
|
|
40719
|
+
api,
|
|
40720
|
+
deviceId,
|
|
40721
|
+
pipelineKey: egressPipelineKey,
|
|
40722
|
+
logger: log
|
|
40723
|
+
});
|
|
40724
|
+
}
|
|
40725
|
+
return errorEnvelope(header, "INTERNAL_ERROR", `webrtc-session.handleOffer failed: ${message}`);
|
|
40726
|
+
}
|
|
40727
|
+
}
|
|
40728
|
+
async function handleSessionDisconnected(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40729
|
+
const parsed = SessionDisconnectedDirectiveSchema.safeParse({
|
|
40730
|
+
endpoint: endpointRaw,
|
|
40731
|
+
payload: payloadRaw ?? {}
|
|
40732
|
+
});
|
|
40733
|
+
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40734
|
+
const endpoint = parsed.data.endpoint;
|
|
40735
|
+
const parsedId = parseCameraEndpointId(endpoint.endpointId);
|
|
40736
|
+
if (parsedId.kind === "camera") {
|
|
40737
|
+
const handleKey = egressHandleKey(parsedId.deviceId, parsed.data.payload.sessionId);
|
|
40738
|
+
const pipelineKey = EGRESS_HANDLES.get(handleKey);
|
|
40739
|
+
if (pipelineKey !== void 0) {
|
|
40740
|
+
EGRESS_HANDLES.delete(handleKey);
|
|
40741
|
+
await releaseAlexaEgress({
|
|
40742
|
+
api: deps.ctx.api,
|
|
40743
|
+
deviceId: parsedId.deviceId,
|
|
40744
|
+
pipelineKey,
|
|
40745
|
+
logger: deps.logger
|
|
40746
|
+
});
|
|
40747
|
+
}
|
|
40748
|
+
try {
|
|
40749
|
+
await deps.ctx.api.webrtcSession.closeSession.mutate({
|
|
40750
|
+
deviceId: parsedId.deviceId,
|
|
40751
|
+
sessionId: parsed.data.payload.sessionId
|
|
40752
|
+
});
|
|
40753
|
+
} catch (err) {
|
|
40754
|
+
deps.logger.warn("alexa rtc-session: closeSession threw on disconnect (continuing to ack)", {
|
|
40755
|
+
tags: {
|
|
40756
|
+
deviceId: parsedId.deviceId,
|
|
40757
|
+
sessionId: parsed.data.payload.sessionId
|
|
40758
|
+
},
|
|
40759
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
40760
|
+
});
|
|
40761
|
+
}
|
|
40762
|
+
}
|
|
40763
|
+
const disconnectedDeviceId = parsedId.kind === "camera" ? parsedId.deviceId : void 0;
|
|
40764
|
+
deps.logger.info("alexa rtc-session: SessionDisconnected", {
|
|
40765
|
+
tags: {
|
|
40766
|
+
sessionId: parsed.data.payload.sessionId,
|
|
40767
|
+
...disconnectedDeviceId !== void 0 ? { deviceId: disconnectedDeviceId } : {}
|
|
40768
|
+
},
|
|
40769
|
+
meta: { endpointId: endpoint.endpointId }
|
|
40770
|
+
});
|
|
40771
|
+
return { event: {
|
|
40772
|
+
header: {
|
|
40773
|
+
namespace: "Alexa",
|
|
40774
|
+
name: "Response",
|
|
40775
|
+
messageId: header.messageId,
|
|
40776
|
+
correlationToken: header.correlationToken,
|
|
40777
|
+
payloadVersion: "3"
|
|
40778
|
+
},
|
|
40779
|
+
endpoint: { endpointId: endpoint.endpointId },
|
|
40780
|
+
payload: {}
|
|
40781
|
+
} };
|
|
40782
|
+
}
|
|
40783
|
+
//#endregion
|
|
39789
40784
|
//#region src/handlers/security-panel-arm-state.ts
|
|
39790
40785
|
/**
|
|
39791
40786
|
* The panel modes behind each Alexa arm state, PRIMARY first — the mirror of
|
|
@@ -40216,101 +41211,6 @@ function buildAlarmPanelEndpoint(input) {
|
|
|
40216
41211
|
};
|
|
40217
41212
|
}
|
|
40218
41213
|
//#endregion
|
|
40219
|
-
//#region src/handlers/error-envelope.ts
|
|
40220
|
-
/**
|
|
40221
|
-
* Shared Alexa `Alexa/ErrorResponse` envelope builder.
|
|
40222
|
-
*
|
|
40223
|
-
* Lives in its own module so every handler (and the directive router)
|
|
40224
|
-
* can emit its own namespace-appropriate error without circular imports.
|
|
40225
|
-
*/
|
|
40226
|
-
object({ event: object({
|
|
40227
|
-
header: object({
|
|
40228
|
-
namespace: literal("Alexa"),
|
|
40229
|
-
name: literal("ErrorResponse"),
|
|
40230
|
-
messageId: string(),
|
|
40231
|
-
payloadVersion: literal("3")
|
|
40232
|
-
}),
|
|
40233
|
-
payload: object({
|
|
40234
|
-
type: string(),
|
|
40235
|
-
message: string()
|
|
40236
|
-
})
|
|
40237
|
-
}) });
|
|
40238
|
-
function errorEnvelope(header, type, message) {
|
|
40239
|
-
return { event: {
|
|
40240
|
-
header: {
|
|
40241
|
-
namespace: "Alexa",
|
|
40242
|
-
name: "ErrorResponse",
|
|
40243
|
-
messageId: header.messageId,
|
|
40244
|
-
payloadVersion: "3"
|
|
40245
|
-
},
|
|
40246
|
-
payload: {
|
|
40247
|
-
type,
|
|
40248
|
-
message
|
|
40249
|
-
}
|
|
40250
|
-
} };
|
|
40251
|
-
}
|
|
40252
|
-
//#endregion
|
|
40253
|
-
//#region src/handlers/types.ts
|
|
40254
|
-
/**
|
|
40255
|
-
* Zod schemas for the subset of the Alexa Smart Home directive surface
|
|
40256
|
-
* that we actually parse hub-side. The Smart Home Skill API ships
|
|
40257
|
-
* thousands of optional fields per namespace — we only validate what
|
|
40258
|
-
* we read; everything else passes through as `unknown`.
|
|
40259
|
-
*
|
|
40260
|
-
* Reference: https://developer.amazon.com/en-US/docs/alexa/smarthome/smart-home-skill-api-message-reference.html
|
|
40261
|
-
*/
|
|
40262
|
-
/** A directive header carries namespace + name + token + correlation id. */
|
|
40263
|
-
var DirectiveHeaderSchema = object({
|
|
40264
|
-
namespace: string(),
|
|
40265
|
-
name: string(),
|
|
40266
|
-
payloadVersion: string(),
|
|
40267
|
-
messageId: string(),
|
|
40268
|
-
correlationToken: string().optional()
|
|
40269
|
-
});
|
|
40270
|
-
/** Scope carries the bearer token Alexa minted via our OAuth provider. */
|
|
40271
|
-
var BearerScopeSchema = object({
|
|
40272
|
-
type: literal("BearerToken"),
|
|
40273
|
-
token: string()
|
|
40274
|
-
});
|
|
40275
|
-
/** Endpoint reference inside a directive payload. */
|
|
40276
|
-
var EndpointRefSchema = object({
|
|
40277
|
-
endpointId: string(),
|
|
40278
|
-
scope: BearerScopeSchema.optional(),
|
|
40279
|
-
cookie: record(string(), string()).optional()
|
|
40280
|
-
});
|
|
40281
|
-
var DiscoveryDirectiveSchema = object({
|
|
40282
|
-
header: DirectiveHeaderSchema.extend({
|
|
40283
|
-
namespace: literal("Alexa.Discovery"),
|
|
40284
|
-
name: literal("Discover")
|
|
40285
|
-
}),
|
|
40286
|
-
payload: object({ scope: BearerScopeSchema })
|
|
40287
|
-
});
|
|
40288
|
-
/** Envelope wrapping a directive on the Alexa→skill wire. */
|
|
40289
|
-
var DirectiveRequestSchema = object({ directive: object({
|
|
40290
|
-
header: DirectiveHeaderSchema,
|
|
40291
|
-
endpoint: EndpointRefSchema.optional(),
|
|
40292
|
-
payload: unknown().optional()
|
|
40293
|
-
}) });
|
|
40294
|
-
var InitializeCameraStreamsPayloadSchema = object({ cameraStreams: array(object({
|
|
40295
|
-
protocol: string(),
|
|
40296
|
-
resolution: object({
|
|
40297
|
-
width: number(),
|
|
40298
|
-
height: number()
|
|
40299
|
-
}).optional(),
|
|
40300
|
-
authorizationType: string().optional(),
|
|
40301
|
-
videoCodec: string().optional(),
|
|
40302
|
-
audioCodec: string().optional()
|
|
40303
|
-
})).optional() });
|
|
40304
|
-
var InitiateSessionWithOfferPayloadSchema = object({
|
|
40305
|
-
sessionId: string(),
|
|
40306
|
-
offer: object({
|
|
40307
|
-
format: string().optional(),
|
|
40308
|
-
value: string()
|
|
40309
|
-
})
|
|
40310
|
-
});
|
|
40311
|
-
var SessionDisconnectedPayloadSchema = object({ sessionId: string() });
|
|
40312
|
-
var SetModePayloadSchema = object({ mode: string() });
|
|
40313
|
-
//#endregion
|
|
40314
41214
|
//#region src/handlers/discovery.ts
|
|
40315
41215
|
var discoveryPayloadSchema = DiscoveryDirectiveSchema.shape.payload;
|
|
40316
41216
|
/** Devices built at once in `handleDiscovery` — latency-bound tRPC reads, so
|
|
@@ -40519,60 +41419,6 @@ function discoveryResponse(header, endpoints) {
|
|
|
40519
41419
|
} };
|
|
40520
41420
|
}
|
|
40521
41421
|
//#endregion
|
|
40522
|
-
//#region src/handlers/endpoint-id.ts
|
|
40523
|
-
var SEPARATOR = "__";
|
|
40524
|
-
function parseCameraEndpointId(raw) {
|
|
40525
|
-
if (!raw.includes(SEPARATOR)) {
|
|
40526
|
-
const id = parseNonNegativeInt(raw);
|
|
40527
|
-
if (id === null) return {
|
|
40528
|
-
kind: "invalid",
|
|
40529
|
-
reason: `not a numeric deviceId: ${raw}`
|
|
40530
|
-
};
|
|
40531
|
-
return {
|
|
40532
|
-
kind: "camera",
|
|
40533
|
-
deviceId: id
|
|
40534
|
-
};
|
|
40535
|
-
}
|
|
40536
|
-
const [head, tail, ...rest] = raw.split(SEPARATOR);
|
|
40537
|
-
if (head === void 0 || tail === void 0 || rest.length > 0) return {
|
|
40538
|
-
kind: "invalid",
|
|
40539
|
-
reason: `unexpected segments in endpointId: ${raw}`
|
|
40540
|
-
};
|
|
40541
|
-
const parent = parseNonNegativeInt(head);
|
|
40542
|
-
if (parent === null) return {
|
|
40543
|
-
kind: "invalid",
|
|
40544
|
-
reason: `parent segment not numeric: ${raw}`
|
|
40545
|
-
};
|
|
40546
|
-
if (tail === "autotrack") return {
|
|
40547
|
-
kind: "autotrack",
|
|
40548
|
-
parentDeviceId: parent
|
|
40549
|
-
};
|
|
40550
|
-
if (tail === "privacy") return {
|
|
40551
|
-
kind: "privacy",
|
|
40552
|
-
parentDeviceId: parent
|
|
40553
|
-
};
|
|
40554
|
-
if (tail === "alarm") return {
|
|
40555
|
-
kind: "alarm-panel",
|
|
40556
|
-
deviceId: parent
|
|
40557
|
-
};
|
|
40558
|
-
const child = parseNonNegativeInt(tail);
|
|
40559
|
-
if (child === null) return {
|
|
40560
|
-
kind: "invalid",
|
|
40561
|
-
reason: `child segment not numeric and not 'autotrack'/'privacy'/'alarm': ${raw}`
|
|
40562
|
-
};
|
|
40563
|
-
return {
|
|
40564
|
-
kind: "child",
|
|
40565
|
-
parentDeviceId: parent,
|
|
40566
|
-
childDeviceId: child
|
|
40567
|
-
};
|
|
40568
|
-
}
|
|
40569
|
-
function parseNonNegativeInt(s) {
|
|
40570
|
-
if (!/^\d+$/.test(s)) return null;
|
|
40571
|
-
const n = Number.parseInt(s, 10);
|
|
40572
|
-
if (!Number.isFinite(n) || n < 0) return null;
|
|
40573
|
-
return n;
|
|
40574
|
-
}
|
|
40575
|
-
//#endregion
|
|
40576
41422
|
//#region src/handlers/brightness-controller.ts
|
|
40577
41423
|
var SetBrightnessDirectiveSchema = object({
|
|
40578
41424
|
header: object({
|
|
@@ -41149,254 +41995,6 @@ async function collectChildProperties(api, childDeviceId, properties, timeOfSamp
|
|
|
41149
41995
|
});
|
|
41150
41996
|
}
|
|
41151
41997
|
//#endregion
|
|
41152
|
-
//#region src/handlers/rtc-session.ts
|
|
41153
|
-
var InitiateSessionWithOfferDirectiveSchema = object({
|
|
41154
|
-
endpoint: EndpointRefSchema,
|
|
41155
|
-
payload: InitiateSessionWithOfferPayloadSchema
|
|
41156
|
-
});
|
|
41157
|
-
var SessionDisconnectedDirectiveSchema = object({
|
|
41158
|
-
endpoint: EndpointRefSchema,
|
|
41159
|
-
payload: SessionDisconnectedPayloadSchema
|
|
41160
|
-
});
|
|
41161
|
-
/**
|
|
41162
|
-
* Live egress handles, keyed by `<deviceId>/<sessionId>`.
|
|
41163
|
-
*
|
|
41164
|
-
* The primitive's refcount has no lease TTL: a holder that vanishes without
|
|
41165
|
-
* releasing leaks a child until the broker restarts (D67). This handler is a
|
|
41166
|
-
* holder, so it keeps the one piece of state that lets it not be that holder —
|
|
41167
|
-
* the `pipelineKey` its `SessionDisconnected` has to release.
|
|
41168
|
-
*
|
|
41169
|
-
* A module-level map is right here because the directive handlers are free
|
|
41170
|
-
* functions called per directive; the entry is written on a successful acquire
|
|
41171
|
-
* and deleted on the release path, both of which are the same tick as the
|
|
41172
|
-
* directive that owns it.
|
|
41173
|
-
*/
|
|
41174
|
-
var EGRESS_HANDLES = /* @__PURE__ */ new Map();
|
|
41175
|
-
function egressHandleKey(deviceId, sessionId) {
|
|
41176
|
-
return `${deviceId}/${sessionId}`;
|
|
41177
|
-
}
|
|
41178
|
-
var WEBRTC_PROFILE_NAMES = [
|
|
41179
|
-
"high",
|
|
41180
|
-
"mid",
|
|
41181
|
-
"low"
|
|
41182
|
-
];
|
|
41183
|
-
function resolveWebrtcTarget(pref) {
|
|
41184
|
-
if (pref === "auto") return void 0;
|
|
41185
|
-
if (WEBRTC_PROFILE_NAMES.includes(pref)) return {
|
|
41186
|
-
kind: "profile",
|
|
41187
|
-
profile: pref
|
|
41188
|
-
};
|
|
41189
|
-
return {
|
|
41190
|
-
kind: "cam-stream",
|
|
41191
|
-
camStreamId: pref
|
|
41192
|
-
};
|
|
41193
|
-
}
|
|
41194
|
-
async function handleInitiateSessionWithOffer(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
41195
|
-
const parsed = InitiateSessionWithOfferDirectiveSchema.safeParse({
|
|
41196
|
-
endpoint: endpointRaw,
|
|
41197
|
-
payload: payloadRaw ?? {}
|
|
41198
|
-
});
|
|
41199
|
-
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
41200
|
-
const endpoint = parsed.data.endpoint;
|
|
41201
|
-
const payload = parsed.data.payload;
|
|
41202
|
-
const parsedId = parseCameraEndpointId(endpoint.endpointId);
|
|
41203
|
-
if (parsedId.kind !== "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", `endpointId ${endpoint.endpointId} is not a camera`);
|
|
41204
|
-
const deviceId = parsedId.deviceId;
|
|
41205
|
-
const sessionId = payload.sessionId;
|
|
41206
|
-
const log = deps.logger.withTags({
|
|
41207
|
-
deviceId,
|
|
41208
|
-
sessionId
|
|
41209
|
-
});
|
|
41210
|
-
const sdpOffer = payload.offer.value;
|
|
41211
|
-
if (sdpOffer.length === 0) return errorEnvelope(header, "INVALID_DIRECTIVE", "offer.value is empty");
|
|
41212
|
-
const api = deps.ctx.api;
|
|
41213
|
-
const exposedEntry = deps.listExposed().find((e) => e.deviceId === deviceId);
|
|
41214
|
-
const explicitSourceProfile = exposedEntry?.settings?.sourceProfile;
|
|
41215
|
-
const mappedFromPreference = (() => {
|
|
41216
|
-
const pref = exposedEntry?.settings?.streamPreference;
|
|
41217
|
-
if (pref === "low" || pref === "mid" || pref === "high") return pref;
|
|
41218
|
-
})();
|
|
41219
|
-
const sourceProfile = explicitSourceProfile ?? mappedFromPreference ?? "high";
|
|
41220
|
-
let derivedTarget;
|
|
41221
|
-
/**
|
|
41222
|
-
* The primitive's release handle, when this session acquired one. Recorded so
|
|
41223
|
-
* `SessionDisconnected` can release it: a refcount whose holder disappears is
|
|
41224
|
-
* the one gap D67 leaves open, and the least this handler can do is not BE
|
|
41225
|
-
* that holder.
|
|
41226
|
-
*/
|
|
41227
|
-
let egressPipelineKey = null;
|
|
41228
|
-
const picked = await api.cameraStreams.pickStream.query({
|
|
41229
|
-
deviceId,
|
|
41230
|
-
requirements: {
|
|
41231
|
-
acceptCodecs: ["h264"],
|
|
41232
|
-
minHeight: 480,
|
|
41233
|
-
excludeDerived: true,
|
|
41234
|
-
requireSiblingCodec: ["h265", "hevc"]
|
|
41235
|
-
}
|
|
41236
|
-
}).catch((err) => {
|
|
41237
|
-
log.warn("alexa rtc-session: cameraStreams.pickStream threw — falling back to transcode", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
41238
|
-
return null;
|
|
41239
|
-
});
|
|
41240
|
-
if (picked) {
|
|
41241
|
-
log.info("alexa rtc-session: bypassing transcode via cameraStreams.pickStream", { meta: {
|
|
41242
|
-
sourceProfile,
|
|
41243
|
-
selectedCamStreamId: picked.camStreamId,
|
|
41244
|
-
reason: picked.reason
|
|
41245
|
-
} });
|
|
41246
|
-
derivedTarget = {
|
|
41247
|
-
kind: "cam-stream",
|
|
41248
|
-
camStreamId: picked.camStreamId
|
|
41249
|
-
};
|
|
41250
|
-
} else try {
|
|
41251
|
-
const acquired = await acquireAlexaEgress({
|
|
41252
|
-
api,
|
|
41253
|
-
deviceId,
|
|
41254
|
-
sourceProfile,
|
|
41255
|
-
sessionId,
|
|
41256
|
-
logger: log
|
|
41257
|
-
});
|
|
41258
|
-
egressPipelineKey = acquired.pipelineKey;
|
|
41259
|
-
EGRESS_HANDLES.set(egressHandleKey(deviceId, sessionId), acquired.pipelineKey);
|
|
41260
|
-
derivedTarget = {
|
|
41261
|
-
kind: "cam-stream",
|
|
41262
|
-
camStreamId: acquired.camStreamId
|
|
41263
|
-
};
|
|
41264
|
-
} catch (err) {
|
|
41265
|
-
log.warn("alexa rtc-session: egress acquire failed, falling back to streamPreference target", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
41266
|
-
derivedTarget = resolveWebrtcTarget(exposedEntry?.settings?.streamPreference ?? "auto");
|
|
41267
|
-
}
|
|
41268
|
-
try {
|
|
41269
|
-
const result = await api.webrtcSession.handleOffer.mutate({
|
|
41270
|
-
deviceId,
|
|
41271
|
-
sdpOffer,
|
|
41272
|
-
sessionId,
|
|
41273
|
-
target: derivedTarget,
|
|
41274
|
-
relayOnly: false,
|
|
41275
|
-
nonTrickle: true,
|
|
41276
|
-
disableTurn: true,
|
|
41277
|
-
disableIpv6: true,
|
|
41278
|
-
consumerAttribution: {
|
|
41279
|
-
kind: "alexa",
|
|
41280
|
-
sessionId
|
|
41281
|
-
}
|
|
41282
|
-
});
|
|
41283
|
-
log.info("alexa rtc-session: AnswerGenerated", { meta: {
|
|
41284
|
-
returnedSessionId: result.sessionId,
|
|
41285
|
-
sdpAnswerLen: result.sdpAnswer.length
|
|
41286
|
-
} });
|
|
41287
|
-
return { event: {
|
|
41288
|
-
header: {
|
|
41289
|
-
namespace: "Alexa.RTCSessionController",
|
|
41290
|
-
name: "AnswerGeneratedForSession",
|
|
41291
|
-
messageId: header.messageId,
|
|
41292
|
-
correlationToken: header.correlationToken,
|
|
41293
|
-
payloadVersion: "3"
|
|
41294
|
-
},
|
|
41295
|
-
endpoint: { endpointId: endpoint.endpointId },
|
|
41296
|
-
payload: { answer: {
|
|
41297
|
-
format: payload.offer.format ?? "SDP",
|
|
41298
|
-
value: result.sdpAnswer
|
|
41299
|
-
} }
|
|
41300
|
-
} };
|
|
41301
|
-
} catch (err) {
|
|
41302
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
41303
|
-
const mSectionSummary = (() => {
|
|
41304
|
-
const lines = sdpOffer.split(/\r?\n/);
|
|
41305
|
-
const sections = [];
|
|
41306
|
-
let current = null;
|
|
41307
|
-
for (const raw of lines) {
|
|
41308
|
-
const line = raw.trim();
|
|
41309
|
-
if (line.startsWith("m=")) {
|
|
41310
|
-
if (current) sections.push(current);
|
|
41311
|
-
current = {
|
|
41312
|
-
mid: null,
|
|
41313
|
-
kind: line.split(" ")[0]?.slice(2) ?? "unknown",
|
|
41314
|
-
direction: null,
|
|
41315
|
-
codecs: []
|
|
41316
|
-
};
|
|
41317
|
-
} else if (current) {
|
|
41318
|
-
if (line.startsWith("a=mid:")) current.mid = line.slice(6);
|
|
41319
|
-
else if (/^a=(sendonly|recvonly|sendrecv|inactive)$/.test(line)) current.direction = line.slice(2);
|
|
41320
|
-
else if (line.startsWith("a=rtpmap:")) current.codecs.push(line.slice(9));
|
|
41321
|
-
}
|
|
41322
|
-
}
|
|
41323
|
-
if (current) sections.push(current);
|
|
41324
|
-
return sections;
|
|
41325
|
-
})();
|
|
41326
|
-
log.warn("alexa rtc-session: handleOffer failed", { meta: {
|
|
41327
|
-
error: message,
|
|
41328
|
-
offerLen: sdpOffer.length,
|
|
41329
|
-
mSections: mSectionSummary,
|
|
41330
|
-
offerSdp: sdpOffer
|
|
41331
|
-
} });
|
|
41332
|
-
if (egressPipelineKey !== null) {
|
|
41333
|
-
EGRESS_HANDLES.delete(egressHandleKey(deviceId, sessionId));
|
|
41334
|
-
await releaseAlexaEgress({
|
|
41335
|
-
api,
|
|
41336
|
-
deviceId,
|
|
41337
|
-
pipelineKey: egressPipelineKey,
|
|
41338
|
-
logger: log
|
|
41339
|
-
});
|
|
41340
|
-
}
|
|
41341
|
-
return errorEnvelope(header, "INTERNAL_ERROR", `webrtc-session.handleOffer failed: ${message}`);
|
|
41342
|
-
}
|
|
41343
|
-
}
|
|
41344
|
-
async function handleSessionDisconnected(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
41345
|
-
const parsed = SessionDisconnectedDirectiveSchema.safeParse({
|
|
41346
|
-
endpoint: endpointRaw,
|
|
41347
|
-
payload: payloadRaw ?? {}
|
|
41348
|
-
});
|
|
41349
|
-
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
41350
|
-
const endpoint = parsed.data.endpoint;
|
|
41351
|
-
const parsedId = parseCameraEndpointId(endpoint.endpointId);
|
|
41352
|
-
if (parsedId.kind === "camera") {
|
|
41353
|
-
const handleKey = egressHandleKey(parsedId.deviceId, parsed.data.payload.sessionId);
|
|
41354
|
-
const pipelineKey = EGRESS_HANDLES.get(handleKey);
|
|
41355
|
-
if (pipelineKey !== void 0) {
|
|
41356
|
-
EGRESS_HANDLES.delete(handleKey);
|
|
41357
|
-
await releaseAlexaEgress({
|
|
41358
|
-
api: deps.ctx.api,
|
|
41359
|
-
deviceId: parsedId.deviceId,
|
|
41360
|
-
pipelineKey,
|
|
41361
|
-
logger: deps.logger
|
|
41362
|
-
});
|
|
41363
|
-
}
|
|
41364
|
-
try {
|
|
41365
|
-
await deps.ctx.api.webrtcSession.closeSession.mutate({
|
|
41366
|
-
deviceId: parsedId.deviceId,
|
|
41367
|
-
sessionId: parsed.data.payload.sessionId
|
|
41368
|
-
});
|
|
41369
|
-
} catch (err) {
|
|
41370
|
-
deps.logger.warn("alexa rtc-session: closeSession threw on disconnect (continuing to ack)", {
|
|
41371
|
-
tags: {
|
|
41372
|
-
deviceId: parsedId.deviceId,
|
|
41373
|
-
sessionId: parsed.data.payload.sessionId
|
|
41374
|
-
},
|
|
41375
|
-
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
41376
|
-
});
|
|
41377
|
-
}
|
|
41378
|
-
}
|
|
41379
|
-
const disconnectedDeviceId = parsedId.kind === "camera" ? parsedId.deviceId : void 0;
|
|
41380
|
-
deps.logger.info("alexa rtc-session: SessionDisconnected", {
|
|
41381
|
-
tags: {
|
|
41382
|
-
sessionId: parsed.data.payload.sessionId,
|
|
41383
|
-
...disconnectedDeviceId !== void 0 ? { deviceId: disconnectedDeviceId } : {}
|
|
41384
|
-
},
|
|
41385
|
-
meta: { endpointId: endpoint.endpointId }
|
|
41386
|
-
});
|
|
41387
|
-
return { event: {
|
|
41388
|
-
header: {
|
|
41389
|
-
namespace: "Alexa",
|
|
41390
|
-
name: "Response",
|
|
41391
|
-
messageId: header.messageId,
|
|
41392
|
-
correlationToken: header.correlationToken,
|
|
41393
|
-
payloadVersion: "3"
|
|
41394
|
-
},
|
|
41395
|
-
endpoint: { endpointId: endpoint.endpointId },
|
|
41396
|
-
payload: {}
|
|
41397
|
-
} };
|
|
41398
|
-
}
|
|
41399
|
-
//#endregion
|
|
41400
41998
|
//#region src/handlers/security-panel.ts
|
|
41401
41999
|
var ArmPayloadSchema = object({ armState: _enum([
|
|
41402
42000
|
"ARMED_STAY",
|
|
@@ -43444,6 +44042,11 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
43444
44042
|
});
|
|
43445
44043
|
});
|
|
43446
44044
|
this.ctx.addDisposer(async () => offTunnelStarted());
|
|
44045
|
+
const reaper = setInterval(() => {
|
|
44046
|
+
this.reapDeadEgressHandles();
|
|
44047
|
+
}, EGRESS_REAP_INTERVAL_MS);
|
|
44048
|
+
reaper.unref?.();
|
|
44049
|
+
this.ctx.addDisposer(async () => clearInterval(reaper));
|
|
43447
44050
|
this.ctx.logger.info("export-alexa: initialized", { meta: {
|
|
43448
44051
|
exposedCount: this.config.exposed.length,
|
|
43449
44052
|
skillMode: this.config.skillMode,
|
|
@@ -44098,6 +44701,37 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
44098
44701
|
]
|
|
44099
44702
|
}] });
|
|
44100
44703
|
}
|
|
44704
|
+
/**
|
|
44705
|
+
* One sweep: ask the broker which held sessions are still alive, and release
|
|
44706
|
+
* the transcodes the dead ones are still holding.
|
|
44707
|
+
*/
|
|
44708
|
+
async reapDeadEgressHandles() {
|
|
44709
|
+
const held = heldEgressHandles();
|
|
44710
|
+
if (held.length === 0) return;
|
|
44711
|
+
const dead = await reapDeadEgressHandles({
|
|
44712
|
+
held,
|
|
44713
|
+
isAlive: async (handle) => {
|
|
44714
|
+
try {
|
|
44715
|
+
return (await this.ctx.api.webrtcSession.getSessionState.query({
|
|
44716
|
+
deviceId: handle.deviceId,
|
|
44717
|
+
sessionId: handle.sessionId
|
|
44718
|
+
})).alive;
|
|
44719
|
+
} catch {
|
|
44720
|
+
return null;
|
|
44721
|
+
}
|
|
44722
|
+
}
|
|
44723
|
+
});
|
|
44724
|
+
for (const handle of dead) {
|
|
44725
|
+
logReaped(this.ctx.logger, handle);
|
|
44726
|
+
forgetEgressHandle(handle);
|
|
44727
|
+
await releaseAlexaEgress({
|
|
44728
|
+
api: this.ctx.api,
|
|
44729
|
+
deviceId: handle.deviceId,
|
|
44730
|
+
pipelineKey: handle.pipelineKey,
|
|
44731
|
+
logger: this.ctx.logger
|
|
44732
|
+
}).catch(() => {});
|
|
44733
|
+
}
|
|
44734
|
+
}
|
|
44101
44735
|
async buildDeviceSettingsContribution(deviceId) {
|
|
44102
44736
|
if (!await this.isCameraDevice(deviceId)) return null;
|
|
44103
44737
|
const entry = this.findEntry(deviceId);
|
|
@@ -44105,6 +44739,7 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
44105
44739
|
const enabled = entry !== null;
|
|
44106
44740
|
const enabledKey = `alexa:${deviceId}:enabled`;
|
|
44107
44741
|
const streamPreferenceKey = `alexa:${deviceId}:streamPreference`;
|
|
44742
|
+
const allowTranscodeKey = `alexa:${deviceId}:allowTranscode`;
|
|
44108
44743
|
const linkedCount = this.config.linkedAccounts.length;
|
|
44109
44744
|
return {
|
|
44110
44745
|
tabs: [{
|
|
@@ -44150,6 +44785,19 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
44150
44785
|
equals: true
|
|
44151
44786
|
},
|
|
44152
44787
|
immediate: true
|
|
44788
|
+
},
|
|
44789
|
+
{
|
|
44790
|
+
type: "boolean",
|
|
44791
|
+
key: allowTranscodeKey,
|
|
44792
|
+
label: "Allow transcoding for Alexa",
|
|
44793
|
+
description: "Let the hub re-encode this camera for the Echo when no stream is directly usable. Off means only a stream Alexa can take as-is (H.264, 480p-1080p) is offered — cheaper, but a camera that publishes only H.265, or only a small sub-stream, will not be streamable to Alexa at all.",
|
|
44794
|
+
style: "switch",
|
|
44795
|
+
value: settings.allowTranscode !== false,
|
|
44796
|
+
showWhen: {
|
|
44797
|
+
field: enabledKey,
|
|
44798
|
+
equals: true
|
|
44799
|
+
},
|
|
44800
|
+
immediate: true
|
|
44153
44801
|
}
|
|
44154
44802
|
]
|
|
44155
44803
|
}]
|
|
@@ -44169,26 +44817,17 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
44169
44817
|
const idStr = String(deviceId);
|
|
44170
44818
|
const current = this.findEntry(deviceId);
|
|
44171
44819
|
const wasEnabled = current !== null;
|
|
44172
|
-
const sourceProfileKey = `alexa:${deviceId}:sourceProfile`;
|
|
44173
|
-
if (sourceProfileKey in patch) {
|
|
44174
|
-
if (!wasEnabled) return { success: true };
|
|
44175
|
-
const currentSettings = current?.settings ?? DEFAULT_DEVICE_SETTINGS;
|
|
44176
|
-
const sourceProfileRaw = patch[sourceProfileKey];
|
|
44177
|
-
const sourceProfile = sourceProfileRaw === "mid" ? "mid" : sourceProfileRaw === "low" ? "low" : "high";
|
|
44178
|
-
await this.patchEntrySettings(deviceId, {
|
|
44179
|
-
...currentSettings,
|
|
44180
|
-
sourceProfile
|
|
44181
|
-
});
|
|
44182
|
-
return { success: true };
|
|
44183
|
-
}
|
|
44184
44820
|
const enabledKey = `alexa:${deviceId}:enabled`;
|
|
44185
44821
|
const streamPreferenceKey = `alexa:${deviceId}:streamPreference`;
|
|
44822
|
+
const allowTranscodeKey = `alexa:${deviceId}:allowTranscode`;
|
|
44186
44823
|
const enabledValue = enabledKey in patch ? Boolean(patch[enabledKey]) : wasEnabled;
|
|
44187
44824
|
const streamPreferenceRaw = streamPreferenceKey in patch ? patch[streamPreferenceKey] : current?.settings?.streamPreference;
|
|
44188
44825
|
const streamPreference = typeof streamPreferenceRaw === "string" && streamPreferenceRaw.trim().length > 0 ? streamPreferenceRaw : "auto";
|
|
44826
|
+
const allowTranscode = allowTranscodeKey in patch ? Boolean(patch[allowTranscodeKey]) : current?.settings?.allowTranscode !== false;
|
|
44189
44827
|
const nextSettings = {
|
|
44190
44828
|
...current?.settings ?? DEFAULT_DEVICE_SETTINGS,
|
|
44191
|
-
streamPreference
|
|
44829
|
+
streamPreference,
|
|
44830
|
+
allowTranscode
|
|
44192
44831
|
};
|
|
44193
44832
|
if (!enabledValue) {
|
|
44194
44833
|
if (wasEnabled) await this.unexposeDevice(idStr);
|
|
@@ -44200,13 +44839,22 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
44200
44839
|
return { success: true };
|
|
44201
44840
|
}
|
|
44202
44841
|
const currentPref = current?.settings?.streamPreference ?? "auto";
|
|
44842
|
+
const currentAllow = current?.settings?.allowTranscode !== false;
|
|
44203
44843
|
await this.patchEntrySettings(deviceId, nextSettings);
|
|
44204
|
-
if (currentPref !== streamPreference) {
|
|
44205
|
-
this.ctx.logger.info("export-alexa:
|
|
44206
|
-
deviceId,
|
|
44207
|
-
|
|
44208
|
-
|
|
44209
|
-
|
|
44844
|
+
if (currentPref !== streamPreference || currentAllow !== allowTranscode) {
|
|
44845
|
+
this.ctx.logger.info("export-alexa: source settings changed — refreshing exposure", {
|
|
44846
|
+
tags: { deviceId },
|
|
44847
|
+
meta: {
|
|
44848
|
+
streamPreference: {
|
|
44849
|
+
from: currentPref,
|
|
44850
|
+
to: streamPreference
|
|
44851
|
+
},
|
|
44852
|
+
allowTranscode: {
|
|
44853
|
+
from: currentAllow,
|
|
44854
|
+
to: allowTranscode
|
|
44855
|
+
}
|
|
44856
|
+
}
|
|
44857
|
+
});
|
|
44210
44858
|
try {
|
|
44211
44859
|
await this.unexposeDevice(idStr);
|
|
44212
44860
|
await this.exposeDevice(idStr);
|