@camstack/addon-export-alexa 1.2.106 → 1.2.108
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 +1073 -523
- package/dist/export-alexa.addon.mjs +1073 -523
- package/package.json +1 -1
|
@@ -5373,7 +5373,7 @@ var ZodIssueCode = {
|
|
|
5373
5373
|
var ZodFirstPartyTypeKind;
|
|
5374
5374
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5375
5375
|
//#endregion
|
|
5376
|
-
//#region ../types/dist/sleep-
|
|
5376
|
+
//#region ../types/dist/sleep-DBKu2-U5.mjs
|
|
5377
5377
|
/**
|
|
5378
5378
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5379
5379
|
* window to float samples (D455).
|
|
@@ -7515,7 +7515,23 @@ var EncodeProfileSchema = object({
|
|
|
7515
7515
|
"zerolatency",
|
|
7516
7516
|
"film",
|
|
7517
7517
|
"animation"
|
|
7518
|
-
]).optional()
|
|
7518
|
+
]).optional(),
|
|
7519
|
+
/**
|
|
7520
|
+
* ONE slice per access unit.
|
|
7521
|
+
*
|
|
7522
|
+
* `-tune zerolatency` turns on x264's sliced threads, and a frame then leaves
|
|
7523
|
+
* the encoder as five NAL slices that share one RTP timestamp and carry one
|
|
7524
|
+
* marker bit. A libwebrtc depacketiser sees five frame-starts and one
|
|
7525
|
+
* frame-end per frame: the first pictures render and the video then freezes
|
|
7526
|
+
* for good while the audio, on its own plane, plays on. Measured on this hub
|
|
7527
|
+
* 2026-09-13 against the Echo, and reduced to one slice by this flag alone.
|
|
7528
|
+
*
|
|
7529
|
+
* A NAMED field and not a raw flag, because {@link EgressEncodeSchema} omits
|
|
7530
|
+
* `outputArgs` on purpose: an opaque array is part of the sharing key, so two
|
|
7531
|
+
* consumers meaning the same thing spelled differently would stop sharing one
|
|
7532
|
+
* child. Absent means "whatever the encoder does" — today's behaviour.
|
|
7533
|
+
*/
|
|
7534
|
+
singleSlicePerFrame: boolean().optional()
|
|
7519
7535
|
}),
|
|
7520
7536
|
audio: union([literal("passthrough"), object({
|
|
7521
7537
|
codec: _enum([
|
|
@@ -7590,7 +7606,11 @@ var BASE_LIVE_EGRESS_PROFILE = {
|
|
|
7590
7606
|
*/
|
|
7591
7607
|
var ALEXA_EGRESS_PROFILE = {
|
|
7592
7608
|
...BASE_LIVE_EGRESS_PROFILE,
|
|
7593
|
-
audio: { codec: "opus" }
|
|
7609
|
+
audio: { codec: "opus" },
|
|
7610
|
+
video: {
|
|
7611
|
+
...BASE_LIVE_EGRESS_PROFILE.video,
|
|
7612
|
+
singleSlicePerFrame: true
|
|
7613
|
+
}
|
|
7594
7614
|
};
|
|
7595
7615
|
/**
|
|
7596
7616
|
* Deep wiring healthcheck — snapshot of active reachability probes across
|
|
@@ -16478,7 +16498,7 @@ var AlarmArmModeSchema = _enum([
|
|
|
16478
16498
|
"vacation",
|
|
16479
16499
|
"custom_bypass"
|
|
16480
16500
|
]);
|
|
16481
|
-
object({
|
|
16501
|
+
var AlarmPanelStatusSchema = object({
|
|
16482
16502
|
/** Current lifecycle state. */
|
|
16483
16503
|
state: AlarmStateSchema,
|
|
16484
16504
|
/** Subset of arm modes the panel accepts. UI renders one button per
|
|
@@ -20071,13 +20091,109 @@ var SummariesQueryInput = object({
|
|
|
20071
20091
|
deviceIds: array(number()).min(1),
|
|
20072
20092
|
since: number().optional(),
|
|
20073
20093
|
until: number().optional(),
|
|
20074
|
-
limit: number().int().min(1).max(200).default(50)
|
|
20094
|
+
limit: number().int().min(1).max(200).default(50),
|
|
20095
|
+
/** The same member-wise filter {@link listRecentSummaries} takes — one
|
|
20096
|
+
* meaning of "dog" on every summary surface. */
|
|
20097
|
+
classes: array(string().min(1).max(60)).max(40).optional()
|
|
20075
20098
|
});
|
|
20076
|
-
var SummariesPageSchema = object({ summaries: array(SummarySchema).readonly() });
|
|
20077
20099
|
var SummaryDetailSchema = object({
|
|
20078
20100
|
summary: SummarySchema,
|
|
20079
|
-
/**
|
|
20080
|
-
|
|
20101
|
+
/** Members in absorption order, oldest join first. */
|
|
20102
|
+
members: array(object({
|
|
20103
|
+
trackId: string(),
|
|
20104
|
+
/**
|
|
20105
|
+
* The track's class at the time it JOINED, or `null` when it was unresolved
|
|
20106
|
+
* and the track no longer exists to fill it.
|
|
20107
|
+
*
|
|
20108
|
+
* The join, not the latest opinion: class voting can re-decide a track's
|
|
20109
|
+
* class afterwards, and a group's composition is the history of who came
|
|
20110
|
+
* together. A consumer counts these to badge a thumbnail — "two people and a
|
|
20111
|
+
* dog" — rather than being handed a second, denormalised tally that would
|
|
20112
|
+
* drift from the members it claims to describe.
|
|
20113
|
+
*/
|
|
20114
|
+
className: string().nullable(),
|
|
20115
|
+
/** `primary` is the one member that carries the group's identity. */
|
|
20116
|
+
role: _enum([
|
|
20117
|
+
"primary",
|
|
20118
|
+
"sibling",
|
|
20119
|
+
"child"
|
|
20120
|
+
]).nullable(),
|
|
20121
|
+
joinedAt: number(),
|
|
20122
|
+
/** Tier 1 — the sub-class (`dog`, `van`), resolved from the member's track
|
|
20123
|
+
* at read time. Absent when nothing resolved, never an empty string. */
|
|
20124
|
+
label: string().optional(),
|
|
20125
|
+
/** Tier 2 — the instance: a person's name, a plate. Absent when the pipeline
|
|
20126
|
+
* recognised nobody, and absent for a member whose track has been pruned —
|
|
20127
|
+
* a thumbnail that names the wrong person is worse than one naming nobody. */
|
|
20128
|
+
subLabel: string().optional()
|
|
20129
|
+
})).readonly()
|
|
20130
|
+
});
|
|
20131
|
+
/**
|
|
20132
|
+
* What a LIST of groups carries: the envelope plus what it is MADE OF.
|
|
20133
|
+
*
|
|
20134
|
+
* Coarse on purpose — the operator's rule is "only the rough data on the list,
|
|
20135
|
+
* we extend when we notice we need more". Enough to draw the card ("two people
|
|
20136
|
+
* and a dog") and no more. The MEMBERS, their names and the per-member links
|
|
20137
|
+
* are on {@link getSummary}: shipping every member of every group so a client
|
|
20138
|
+
* can count them turns a page of two hundred groups into a thousand records to
|
|
20139
|
+
* draw two hundred badges.
|
|
20140
|
+
*/
|
|
20141
|
+
var SummaryListItemSchema = object({
|
|
20142
|
+
summary: SummarySchema,
|
|
20143
|
+
/** Class counts, most numerous first; `className: null` is a member whose
|
|
20144
|
+
* class never resolved, counted so the counts add up to `memberCount`. */
|
|
20145
|
+
classes: array(object({
|
|
20146
|
+
className: string().nullable(),
|
|
20147
|
+
count: number().int().positive()
|
|
20148
|
+
})).readonly()
|
|
20149
|
+
});
|
|
20150
|
+
var SummariesPageSchema = object({ summaries: array(SummaryListItemSchema).readonly() });
|
|
20151
|
+
/**
|
|
20152
|
+
* The paged feed, deliberately the SAME shape as {@link RecentTracksQueryInput}.
|
|
20153
|
+
*
|
|
20154
|
+
* The reel on the cameras page and the Events gallery both ride a cursor, so a
|
|
20155
|
+
* summaries feed that could only answer "the last N for these cameras"
|
|
20156
|
+
* (`listSummaries`) would make groups available in the timeline and nowhere
|
|
20157
|
+
* else. Two feeds with different ordering contracts would be two ideas of what
|
|
20158
|
+
* "newest" means, on one screen.
|
|
20159
|
+
*/
|
|
20160
|
+
var RecentSummariesQueryInput = object({
|
|
20161
|
+
/** Devices to merge. An empty array yields an empty page. */
|
|
20162
|
+
deviceIds: array(number()),
|
|
20163
|
+
/** Window lower bound on `lastActiveAt` (inclusive). */
|
|
20164
|
+
since: number().optional(),
|
|
20165
|
+
/** Window upper bound on `lastActiveAt` (inclusive). */
|
|
20166
|
+
until: number().optional(),
|
|
20167
|
+
limit: number().int().min(1).max(500).default(100),
|
|
20168
|
+
/** Opaque continuation cursor from a previous page's `nextCursor`. */
|
|
20169
|
+
cursor: string().optional(),
|
|
20170
|
+
/**
|
|
20171
|
+
* Restrict to these classes — THE SAME FIELD `listRecentTracks` takes, and
|
|
20172
|
+
* deliberately the same name: the events filter tree emits one list of ticked
|
|
20173
|
+
* taxonomy nodes, and a summaries feed that called it something else would
|
|
20174
|
+
* make the operator's one filter component produce two shapes.
|
|
20175
|
+
*
|
|
20176
|
+
* A question about the MEMBERS: a group matches when ANY of them does. "Show
|
|
20177
|
+
* me the arrivals with a dog" has to return the group of four people who had
|
|
20178
|
+
* one with them; a filter on the group's own fields could only ever answer
|
|
20179
|
+
* about its primary.
|
|
20180
|
+
*
|
|
20181
|
+
* Matched against all THREE tiers of a member — the class (`animal`), the
|
|
20182
|
+
* sub-class (`dog`) and the instance (a name, a plate) — because which tier a
|
|
20183
|
+
* ticked node lives on is the taxonomy's business, not the caller's. `dog` is
|
|
20184
|
+
* an event kind in the tree and a tier-1 label on an `animal` track; a filter
|
|
20185
|
+
* that read only the class would answer "animal" and never "dog".
|
|
20186
|
+
*
|
|
20187
|
+
* ABSENT or EMPTY means no filter — absent is not a selection of none.
|
|
20188
|
+
*/
|
|
20189
|
+
classes: array(string().min(1).max(60)).max(40).optional()
|
|
20190
|
+
});
|
|
20191
|
+
var RecentSummariesPageSchema = object({
|
|
20192
|
+
/** Ordered by (`lastActiveAt` DESC, id DESC). Same light item as
|
|
20193
|
+
* {@link listSummaries} — one list shape, so a card renders the same
|
|
20194
|
+
* whichever feed drew it. */
|
|
20195
|
+
summaries: array(SummaryListItemSchema).readonly(),
|
|
20196
|
+
nextCursor: string().nullable()
|
|
20081
20197
|
});
|
|
20082
20198
|
var RecentTracksPageSchema = object({
|
|
20083
20199
|
/** Merged page, ordered by (`lastSeen` DESC, `trackId` DESC). */
|
|
@@ -20491,7 +20607,7 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
|
|
|
20491
20607
|
classes: array(string()).optional(),
|
|
20492
20608
|
/** See {@link ExcludeSourcesDoc}. */
|
|
20493
20609
|
excludeSources: array(TrackSourceSchema).optional()
|
|
20494
|
-
}), array(TrackSchema).readonly()), method(RecentTracksQueryInput, RecentTracksPageSchema), method(SummariesQueryInput, SummariesPageSchema), method(object({ id: string() }), SummaryDetailSchema.nullable()), method(object({ deviceId: number() }), _void(), {
|
|
20610
|
+
}), array(TrackSchema).readonly()), method(RecentTracksQueryInput, RecentTracksPageSchema), method(SummariesQueryInput, SummariesPageSchema), method(RecentSummariesQueryInput, RecentSummariesPageSchema), method(object({ id: string() }), SummaryDetailSchema.nullable()), method(object({ deviceId: number() }), _void(), {
|
|
20495
20611
|
kind: "mutation",
|
|
20496
20612
|
auth: "admin"
|
|
20497
20613
|
}), method(DeviceEventQueryInput, array(MotionEventSchema).readonly()), method(ObjectEventQueryInput, array(ObjectEventSchema).readonly()), method(DeviceEventQueryInput, array(AudioEventSchema).readonly()), method(object({ deviceId: number() }), array(EventKindDescriptorSchema).readonly()), method(object({ deviceIds: array(number()).min(1).max(200) }), array(EventKindsForDeviceSchema).readonly()), method(object({
|
|
@@ -30097,7 +30213,29 @@ var LoggingSettingsPatchSchema = object({
|
|
|
30097
30213
|
* disarmed the channels it did not mention would make the Levels page and
|
|
30098
30214
|
* the Diagnostics page fight over the same value.
|
|
30099
30215
|
*/
|
|
30100
|
-
channels: array(LogChannelWindowPatchSchema).readonly().optional()
|
|
30216
|
+
channels: array(LogChannelWindowPatchSchema).readonly().optional(),
|
|
30217
|
+
/**
|
|
30218
|
+
* How many days the analytics OPS LOG is kept — the audit trail of what
|
|
30219
|
+
* retention actually deleted.
|
|
30220
|
+
*
|
|
30221
|
+
* It lives HERE, on the logging document, and not on the analytics addon's
|
|
30222
|
+
* settings form, on the operator's instruction: every other log-ish window in
|
|
30223
|
+
* this system is configured through this one document, and a retention audit
|
|
30224
|
+
* configured somewhere else is a second place to look when the question is
|
|
30225
|
+
* "what happened to my data".
|
|
30226
|
+
*
|
|
30227
|
+
* That placement has a cost worth stating: this document ships in the
|
|
30228
|
+
* framework closure, so this knob needs a published `@camstack/server` while
|
|
30229
|
+
* the four windows beside it (D485) reach a node on `camstack deploy`.
|
|
30230
|
+
*
|
|
30231
|
+
* `retention-model.ts` argued this one must NOT follow a device window,
|
|
30232
|
+
* because the audit trail is the history of the SWEEP and not of the camera.
|
|
30233
|
+
* That argument stands and is untouched — what changes is that 30 days stops
|
|
30234
|
+
* being a constant nobody can reach. `0` keeps it forever. The floor is 1 day
|
|
30235
|
+
* rather than 0-as-delete: an audit log truncated to nothing is precisely the
|
|
30236
|
+
* state in which the next 9.5 GiB leak cannot be explained.
|
|
30237
|
+
*/
|
|
30238
|
+
opsLogRetentionDays: number().int().min(0).max(3650).optional()
|
|
30101
30239
|
});
|
|
30102
30240
|
/**
|
|
30103
30241
|
* Which LAYER of the hierarchy is addressed. Absent = the cluster layer.
|
|
@@ -30170,6 +30308,14 @@ var LoggingSettingsStateSchema = object({
|
|
|
30170
30308
|
channels: array(LogChannelDescriptorSchema).readonly(),
|
|
30171
30309
|
/** The channels ARMED right now, each with its deadline. */
|
|
30172
30310
|
activeChannels: array(LogChannelWindowStateSchema).readonly(),
|
|
30311
|
+
/**
|
|
30312
|
+
* The ops-log window in days, as it is in force. `0` = kept forever.
|
|
30313
|
+
*
|
|
30314
|
+
* Reported rather than left to the caller's memory of what it wrote: this is
|
|
30315
|
+
* the value the analytics sweep will actually use, and an operator asking how
|
|
30316
|
+
* long their audit trail lives should not have to infer it from a default.
|
|
30317
|
+
*/
|
|
30318
|
+
opsLogRetentionDays: number().int().min(0),
|
|
30173
30319
|
persisted: boolean()
|
|
30174
30320
|
});
|
|
30175
30321
|
method(_void(), FeatureManifestSchema), method(_void(), HealthStatusSchema), method(_void(), FeatureManifestSchema), method(_void(), array(NetworkAddressSchema).readonly()), method(_void(), unknown().nullable(), { auth: "admin" }), method(record(string(), unknown()), _null(), {
|
|
@@ -34329,6 +34475,12 @@ Object.freeze({
|
|
|
34329
34475
|
addonId: null,
|
|
34330
34476
|
access: "view"
|
|
34331
34477
|
},
|
|
34478
|
+
"pipelineAnalytics.listRecentSummaries": {
|
|
34479
|
+
capName: "pipeline-analytics",
|
|
34480
|
+
capScope: "device",
|
|
34481
|
+
addonId: null,
|
|
34482
|
+
access: "view"
|
|
34483
|
+
},
|
|
34332
34484
|
"pipelineAnalytics.listRecentTracks": {
|
|
34333
34485
|
capName: "pipeline-analytics",
|
|
34334
34486
|
capScope: "device",
|
|
@@ -38156,6 +38308,11 @@ Object.freeze({
|
|
|
38156
38308
|
form: "single",
|
|
38157
38309
|
optional: true
|
|
38158
38310
|
}],
|
|
38311
|
+
"pipelineAnalytics.listRecentSummaries": [{
|
|
38312
|
+
name: "deviceIds",
|
|
38313
|
+
form: "array",
|
|
38314
|
+
optional: false
|
|
38315
|
+
}],
|
|
38159
38316
|
"pipelineAnalytics.listRecentTracks": [{
|
|
38160
38317
|
name: "deviceIds",
|
|
38161
38318
|
form: "array",
|
|
@@ -39629,66 +39786,65 @@ async function releaseAlexaEgress(input) {
|
|
|
39629
39786
|
}
|
|
39630
39787
|
}
|
|
39631
39788
|
//#endregion
|
|
39632
|
-
//#region src/handlers/
|
|
39789
|
+
//#region src/handlers/security-panel-arm-state.ts
|
|
39633
39790
|
/**
|
|
39634
|
-
*
|
|
39635
|
-
*
|
|
39636
|
-
*
|
|
39637
|
-
*
|
|
39791
|
+
* The panel modes behind each Alexa arm state, PRIMARY first — the mirror of
|
|
39792
|
+
* `MODES_BY_TARGET` in the HomeKit exporter, and for the same reason: one
|
|
39793
|
+
* Alexa state stands for two panel modes, so a panel offering only the
|
|
39794
|
+
* secondary would otherwise be sent a mode it refuses.
|
|
39795
|
+
*/
|
|
39796
|
+
var MODES_BY_ARM_STATE = {
|
|
39797
|
+
ARMED_STAY: ["home", "custom_bypass"],
|
|
39798
|
+
ARMED_AWAY: ["away", "vacation"],
|
|
39799
|
+
ARMED_NIGHT: ["night"]
|
|
39800
|
+
};
|
|
39801
|
+
var ARM_STATES = [
|
|
39802
|
+
"ARMED_STAY",
|
|
39803
|
+
"ARMED_AWAY",
|
|
39804
|
+
"ARMED_NIGHT"
|
|
39805
|
+
];
|
|
39806
|
+
/** The panel's state as Alexa's `armState` property. */
|
|
39807
|
+
function alexaArmStateFor(state) {
|
|
39808
|
+
switch (state) {
|
|
39809
|
+
case "armed_home":
|
|
39810
|
+
case "armed_custom_bypass": return "ARMED_STAY";
|
|
39811
|
+
case "armed_night": return "ARMED_NIGHT";
|
|
39812
|
+
case "armed_away":
|
|
39813
|
+
case "armed_vacation":
|
|
39814
|
+
case "pending":
|
|
39815
|
+
case "triggered": return "ARMED_AWAY";
|
|
39816
|
+
default: return "DISARMED";
|
|
39817
|
+
}
|
|
39818
|
+
}
|
|
39819
|
+
/** `burglaryAlarm`, the only alarm property this cap can honestly fill. */
|
|
39820
|
+
function burglaryAlarmFor(state) {
|
|
39821
|
+
return { value: state === "triggered" ? "ALARM" : "OK" };
|
|
39822
|
+
}
|
|
39823
|
+
/**
|
|
39824
|
+
* The `supportedArmStates` for discovery.
|
|
39638
39825
|
*
|
|
39639
|
-
*
|
|
39826
|
+
* `DISARMED` is always present: disarming is not one of the panel's arm modes.
|
|
39827
|
+
* An EMPTY `availableModes` is unknown, not "none" — a provider that never
|
|
39828
|
+
* populated the list looks identical to one that accepts nothing, and
|
|
39829
|
+
* publishing a panel that can only be disarmed on that guess takes the
|
|
39830
|
+
* controls off a working alarm. The caller logs it.
|
|
39640
39831
|
*/
|
|
39641
|
-
|
|
39642
|
-
|
|
39643
|
-
|
|
39644
|
-
|
|
39645
|
-
|
|
39646
|
-
|
|
39647
|
-
|
|
39648
|
-
|
|
39649
|
-
|
|
39650
|
-
|
|
39651
|
-
|
|
39652
|
-
|
|
39653
|
-
|
|
39654
|
-
|
|
39655
|
-
|
|
39656
|
-
|
|
39657
|
-
scope: BearerScopeSchema.optional(),
|
|
39658
|
-
cookie: record(string(), string()).optional()
|
|
39659
|
-
});
|
|
39660
|
-
var DiscoveryDirectiveSchema = object({
|
|
39661
|
-
header: DirectiveHeaderSchema.extend({
|
|
39662
|
-
namespace: literal("Alexa.Discovery"),
|
|
39663
|
-
name: literal("Discover")
|
|
39664
|
-
}),
|
|
39665
|
-
payload: object({ scope: BearerScopeSchema })
|
|
39666
|
-
});
|
|
39667
|
-
/** Envelope wrapping a directive on the Alexa→skill wire. */
|
|
39668
|
-
var DirectiveRequestSchema = object({ directive: object({
|
|
39669
|
-
header: DirectiveHeaderSchema,
|
|
39670
|
-
endpoint: EndpointRefSchema.optional(),
|
|
39671
|
-
payload: unknown().optional()
|
|
39672
|
-
}) });
|
|
39673
|
-
var InitializeCameraStreamsPayloadSchema = object({ cameraStreams: array(object({
|
|
39674
|
-
protocol: string(),
|
|
39675
|
-
resolution: object({
|
|
39676
|
-
width: number(),
|
|
39677
|
-
height: number()
|
|
39678
|
-
}).optional(),
|
|
39679
|
-
authorizationType: string().optional(),
|
|
39680
|
-
videoCodec: string().optional(),
|
|
39681
|
-
audioCodec: string().optional()
|
|
39682
|
-
})).optional() });
|
|
39683
|
-
var InitiateSessionWithOfferPayloadSchema = object({
|
|
39684
|
-
sessionId: string(),
|
|
39685
|
-
offer: object({
|
|
39686
|
-
format: string().optional(),
|
|
39687
|
-
value: string()
|
|
39688
|
-
})
|
|
39689
|
-
});
|
|
39690
|
-
var SessionDisconnectedPayloadSchema = object({ sessionId: string() });
|
|
39691
|
-
var SetModePayloadSchema = object({ mode: string() });
|
|
39832
|
+
function supportedArmStatesFor(availableModes) {
|
|
39833
|
+
return [...availableModes.length === 0 ? ARM_STATES : ARM_STATES.filter((armState) => MODES_BY_ARM_STATE[armState].some((mode) => availableModes.includes(mode))), "DISARMED"];
|
|
39834
|
+
}
|
|
39835
|
+
/**
|
|
39836
|
+
* The arm mode to send for an Alexa arm state, or `null` when there is none.
|
|
39837
|
+
*
|
|
39838
|
+
* `null` is not a shrug: `DISARMED` is the Disarm DIRECTIVE, a different call,
|
|
39839
|
+
* and an arm state the panel accepts no mode for is a directive the handler
|
|
39840
|
+
* refuses with `NOT_READY_FOR_ARM` rather than translating into a guess.
|
|
39841
|
+
*/
|
|
39842
|
+
function alarmArmModeForAlexa(armState, availableModes) {
|
|
39843
|
+
if (armState === "DISARMED") return null;
|
|
39844
|
+
const candidates = MODES_BY_ARM_STATE[armState];
|
|
39845
|
+
if (availableModes.length === 0) return candidates[0] ?? null;
|
|
39846
|
+
return candidates.find((mode) => availableModes.includes(mode)) ?? null;
|
|
39847
|
+
}
|
|
39692
39848
|
//#endregion
|
|
39693
39849
|
//#region src/endpoints/builder.ts
|
|
39694
39850
|
var DEFAULT_RESOLUTIONS = [{
|
|
@@ -40012,6 +40168,53 @@ function buildPrivacyEndpoint(input) {
|
|
|
40012
40168
|
}
|
|
40013
40169
|
};
|
|
40014
40170
|
}
|
|
40171
|
+
/**
|
|
40172
|
+
* An `alarm-panel` device as an `Alexa.SecurityPanelController` endpoint.
|
|
40173
|
+
*
|
|
40174
|
+
* It is its OWN endpoint, not a child of a camera: a panel is a standalone
|
|
40175
|
+
* device and has no stream, no doorbell and no PTZ. The `__alarm` suffix on
|
|
40176
|
+
* the endpoint id is a routing tag (see `handlers/endpoint-id.ts`).
|
|
40177
|
+
*
|
|
40178
|
+
* ## What is declared, and what is deliberately not
|
|
40179
|
+
*
|
|
40180
|
+
* - `armState` and `burglaryAlarm` are the two properties this cap can fill
|
|
40181
|
+
* honestly. `fireAlarm` / `carbonMonoxideAlarm` / `waterAlarm` are NOT
|
|
40182
|
+
* declared: `alarm-panel` has no field saying WHICH alarm is sounding, and
|
|
40183
|
+
* declaring a property we would always answer `OK` on is a claim with no
|
|
40184
|
+
* basis behind it. The reasoning is in `security-panel-arm-state.ts`.
|
|
40185
|
+
* - `proactivelyReported: false`. This addon's Event Gateway pushes
|
|
40186
|
+
* ChangeReports for camera motion only; a panel state change is not wired
|
|
40187
|
+
* to it, and promising a report nothing sends is how an endpoint ends up
|
|
40188
|
+
* looking broken. `retrievable: true` — `Alexa/ReportState` answers.
|
|
40189
|
+
* - `supportedAuthorizationTypes` appears only for a panel that requires a
|
|
40190
|
+
* code. Alexa's Disarm directive can carry a PIN; its **Arm directive
|
|
40191
|
+
* cannot**, which is why a PIN-gated arm is refused by the handler with
|
|
40192
|
+
* `AUTHORIZATION_REQUIRED` rather than attempted.
|
|
40193
|
+
*/
|
|
40194
|
+
function buildAlarmPanelEndpoint(input) {
|
|
40195
|
+
const configuration = { supportedArmStates: supportedArmStatesFor(input.availableModes).map((value) => ({ value })) };
|
|
40196
|
+
if (input.requiresCode) configuration.supportedAuthorizationTypes = [{ type: "FOUR_DIGIT_PIN" }];
|
|
40197
|
+
const securityPanelController = {
|
|
40198
|
+
type: "AlexaInterface",
|
|
40199
|
+
interface: "Alexa.SecurityPanelController",
|
|
40200
|
+
version: "3",
|
|
40201
|
+
properties: {
|
|
40202
|
+
supported: [{ name: "armState" }, { name: "burglaryAlarm" }],
|
|
40203
|
+
proactivelyReported: false,
|
|
40204
|
+
retrievable: true
|
|
40205
|
+
},
|
|
40206
|
+
configuration
|
|
40207
|
+
};
|
|
40208
|
+
return {
|
|
40209
|
+
endpointId: `${input.deviceId}__alarm`,
|
|
40210
|
+
manufacturerName: "camstack",
|
|
40211
|
+
description: "CamStack alarm panel",
|
|
40212
|
+
friendlyName: input.friendlyName.trim().length > 0 ? input.friendlyName.trim() : `Alarm ${input.deviceId}`,
|
|
40213
|
+
displayCategories: ["SECURITY_PANEL"],
|
|
40214
|
+
capabilities: [ALEXA_BASE_CAPABILITY, securityPanelController],
|
|
40215
|
+
cookie: { stableId: input.stableId }
|
|
40216
|
+
};
|
|
40217
|
+
}
|
|
40015
40218
|
//#endregion
|
|
40016
40219
|
//#region src/handlers/error-envelope.ts
|
|
40017
40220
|
/**
|
|
@@ -40047,20 +40250,68 @@ function errorEnvelope(header, type, message) {
|
|
|
40047
40250
|
} };
|
|
40048
40251
|
}
|
|
40049
40252
|
//#endregion
|
|
40050
|
-
//#region src/handlers/
|
|
40253
|
+
//#region src/handlers/types.ts
|
|
40051
40254
|
/**
|
|
40052
|
-
*
|
|
40053
|
-
*
|
|
40054
|
-
*
|
|
40055
|
-
*
|
|
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`.
|
|
40056
40259
|
*
|
|
40057
|
-
*
|
|
40058
|
-
* `DeviceInfo.features` + bound caps (from `device-manager.getBindings`)
|
|
40059
|
-
* and emit only the Alexa capabilities backed by something on our side.
|
|
40060
|
-
* Child accessories (siren/floodlight/PIR/…) become SEPARATE endpoints
|
|
40061
|
-
* with `endpointId = ${parent}__${child}` so directive handlers can
|
|
40062
|
-
* route to the right cap on the right device.
|
|
40260
|
+
* Reference: https://developer.amazon.com/en-US/docs/alexa/smarthome/smart-home-skill-api-message-reference.html
|
|
40063
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
|
+
//#region src/handlers/discovery.ts
|
|
40064
40315
|
var discoveryPayloadSchema = DiscoveryDirectiveSchema.shape.payload;
|
|
40065
40316
|
/** Devices built at once in `handleDiscovery` — latency-bound tRPC reads, so
|
|
40066
40317
|
* six lanes hide the round-trips without stampeding a booting hub. */
|
|
@@ -40074,6 +40325,7 @@ var CAP_SWITCH = "switch";
|
|
|
40074
40325
|
var CAP_BRIGHTNESS = "brightness";
|
|
40075
40326
|
var CAP_BATTERY = "battery";
|
|
40076
40327
|
var CAP_PRIVACY_MASK = "privacy-mask";
|
|
40328
|
+
var CAP_ALARM_PANEL = "alarm-panel";
|
|
40077
40329
|
async function handleDiscovery(header, payloadRaw, deps, callerIdentity) {
|
|
40078
40330
|
if (!discoveryPayloadSchema.safeParse(payloadRaw).success) return errorEnvelope(header, "INVALID_DIRECTIVE", "Discovery payload shape unexpected");
|
|
40079
40331
|
const exposed = await deps.listExposed();
|
|
@@ -40113,6 +40365,7 @@ async function buildEndpointsForExposedDevice(deviceId, deps) {
|
|
|
40113
40365
|
return [];
|
|
40114
40366
|
}
|
|
40115
40367
|
const parentInfo = await loadBoundDeviceInfo(device, api);
|
|
40368
|
+
if (parentInfo.capNames.includes(CAP_ALARM_PANEL)) return [await buildAlarmPanelEndpointFor(parentInfo, api, deps)];
|
|
40116
40369
|
const children = await api.deviceManager.getChildren.query({ parentDeviceId: deviceId }).catch((err) => {
|
|
40117
40370
|
deps.logger.warn("alexa discovery: getChildren failed", {
|
|
40118
40371
|
tags: { deviceId },
|
|
@@ -40192,6 +40445,47 @@ async function buildEndpointsForExposedDevice(deviceId, deps) {
|
|
|
40192
40445
|
}
|
|
40193
40446
|
return out;
|
|
40194
40447
|
}
|
|
40448
|
+
/**
|
|
40449
|
+
* The panel endpoint, with what the panel says it accepts.
|
|
40450
|
+
*
|
|
40451
|
+
* A `getStatus` that fails leaves `availableModes` empty and `requiresCode`
|
|
40452
|
+
* false, and those are the UNKNOWN readings, not assertions: an empty mode
|
|
40453
|
+
* list makes discovery declare all three arm states (`supportedArmStatesFor`)
|
|
40454
|
+
* rather than publishing a panel that can only be disarmed, and the directive
|
|
40455
|
+
* handler re-reads the panel before it commands anything, so a PIN discovered
|
|
40456
|
+
* later is still honoured. The blind read is logged against the device id.
|
|
40457
|
+
*/
|
|
40458
|
+
async function buildAlarmPanelEndpointFor(info, api, deps) {
|
|
40459
|
+
const status = await api.alarmPanel.getStatus.query({ deviceId: info.id }).catch((err) => {
|
|
40460
|
+
deps.logger.warn("alexa discovery: alarmPanel.getStatus failed — declaring every arm state", {
|
|
40461
|
+
tags: { deviceId: info.id },
|
|
40462
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
40463
|
+
});
|
|
40464
|
+
return null;
|
|
40465
|
+
});
|
|
40466
|
+
const parsed = AlarmPanelStatusSchema.pick({
|
|
40467
|
+
availableModes: true,
|
|
40468
|
+
requiresCode: true
|
|
40469
|
+
}).safeParse(status);
|
|
40470
|
+
if (!parsed.success && status !== null) deps.logger.warn("alexa discovery: panel status did not match the cap schema", { tags: { deviceId: info.id } });
|
|
40471
|
+
const availableModes = parsed.success ? parsed.data.availableModes : [];
|
|
40472
|
+
const requiresCode = parsed.success ? parsed.data.requiresCode : false;
|
|
40473
|
+
deps.logger.info("alexa discovery: built alarm panel endpoint", {
|
|
40474
|
+
tags: { deviceId: info.id },
|
|
40475
|
+
meta: {
|
|
40476
|
+
name: info.name,
|
|
40477
|
+
availableModes: [...availableModes],
|
|
40478
|
+
requiresCode
|
|
40479
|
+
}
|
|
40480
|
+
});
|
|
40481
|
+
return buildAlarmPanelEndpoint({
|
|
40482
|
+
deviceId: info.id,
|
|
40483
|
+
stableId: info.stableId,
|
|
40484
|
+
friendlyName: info.name,
|
|
40485
|
+
availableModes,
|
|
40486
|
+
requiresCode
|
|
40487
|
+
});
|
|
40488
|
+
}
|
|
40195
40489
|
async function loadBoundDeviceInfo(device, api) {
|
|
40196
40490
|
const capNames = (await api.deviceManager.getBindings.query({ deviceId: device.id })).entries.map((e) => e.capName);
|
|
40197
40491
|
return {
|
|
@@ -40257,10 +40551,14 @@ function parseCameraEndpointId(raw) {
|
|
|
40257
40551
|
kind: "privacy",
|
|
40258
40552
|
parentDeviceId: parent
|
|
40259
40553
|
};
|
|
40554
|
+
if (tail === "alarm") return {
|
|
40555
|
+
kind: "alarm-panel",
|
|
40556
|
+
deviceId: parent
|
|
40557
|
+
};
|
|
40260
40558
|
const child = parseNonNegativeInt(tail);
|
|
40261
40559
|
if (child === null) return {
|
|
40262
40560
|
kind: "invalid",
|
|
40263
|
-
reason: `child segment not numeric and not 'autotrack'/'privacy': ${raw}`
|
|
40561
|
+
reason: `child segment not numeric and not 'autotrack'/'privacy'/'alarm': ${raw}`
|
|
40264
40562
|
};
|
|
40265
40563
|
return {
|
|
40266
40564
|
kind: "child",
|
|
@@ -40275,6 +40573,68 @@ function parseNonNegativeInt(s) {
|
|
|
40275
40573
|
return n;
|
|
40276
40574
|
}
|
|
40277
40575
|
//#endregion
|
|
40576
|
+
//#region src/handlers/brightness-controller.ts
|
|
40577
|
+
var SetBrightnessDirectiveSchema = object({
|
|
40578
|
+
header: object({
|
|
40579
|
+
namespace: literal("Alexa.BrightnessController"),
|
|
40580
|
+
name: literal("SetBrightness")
|
|
40581
|
+
}),
|
|
40582
|
+
endpoint: EndpointRefSchema,
|
|
40583
|
+
payload: object({ brightness: number().min(0).max(100) })
|
|
40584
|
+
});
|
|
40585
|
+
async function handleSetBrightness(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40586
|
+
const parsed = SetBrightnessDirectiveSchema.safeParse({
|
|
40587
|
+
header: {
|
|
40588
|
+
namespace: header.namespace,
|
|
40589
|
+
name: header.name
|
|
40590
|
+
},
|
|
40591
|
+
endpoint: endpointRaw,
|
|
40592
|
+
payload: payloadRaw ?? {}
|
|
40593
|
+
});
|
|
40594
|
+
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40595
|
+
const endpointId = parsed.data.endpoint.endpointId;
|
|
40596
|
+
const parsedId = parseCameraEndpointId(endpointId);
|
|
40597
|
+
if (parsedId.kind === "autotrack" || parsedId.kind === "privacy" || parsedId.kind === "alarm-panel") return errorEnvelope(header, "INVALID_DIRECTIVE", `BrightnessController is not exposed on the ${parsedId.kind} endpoint`);
|
|
40598
|
+
if (parsedId.kind === "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", "BrightnessController is not exposed on camera endpoints — direct the directive at the dimmable child accessory");
|
|
40599
|
+
if (parsedId.kind === "invalid") return errorEnvelope(header, "INVALID_DIRECTIVE", parsedId.reason);
|
|
40600
|
+
const percentage = parsed.data.payload.brightness;
|
|
40601
|
+
const api = deps.ctx.api;
|
|
40602
|
+
try {
|
|
40603
|
+
await api.brightness.setBrightness.mutate({
|
|
40604
|
+
deviceId: parsedId.childDeviceId,
|
|
40605
|
+
percentage
|
|
40606
|
+
});
|
|
40607
|
+
} catch (err) {
|
|
40608
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
40609
|
+
deps.logger.warn("alexa brightness-controller: setBrightness failed", { meta: {
|
|
40610
|
+
deviceId: parsedId.childDeviceId,
|
|
40611
|
+
percentage,
|
|
40612
|
+
error: message
|
|
40613
|
+
} });
|
|
40614
|
+
return errorEnvelope(header, "INTERNAL_ERROR", `brightness.setBrightness failed: ${message}`);
|
|
40615
|
+
}
|
|
40616
|
+
return {
|
|
40617
|
+
event: {
|
|
40618
|
+
header: {
|
|
40619
|
+
namespace: "Alexa",
|
|
40620
|
+
name: "Response",
|
|
40621
|
+
messageId: header.messageId,
|
|
40622
|
+
correlationToken: header.correlationToken,
|
|
40623
|
+
payloadVersion: "3"
|
|
40624
|
+
},
|
|
40625
|
+
endpoint: { endpointId },
|
|
40626
|
+
payload: {}
|
|
40627
|
+
},
|
|
40628
|
+
context: { properties: [{
|
|
40629
|
+
namespace: "Alexa.BrightnessController",
|
|
40630
|
+
name: "brightness",
|
|
40631
|
+
value: percentage,
|
|
40632
|
+
timeOfSample: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40633
|
+
uncertaintyInMilliseconds: 500
|
|
40634
|
+
}] }
|
|
40635
|
+
};
|
|
40636
|
+
}
|
|
40637
|
+
//#endregion
|
|
40278
40638
|
//#region src/handlers/camera-stream.ts
|
|
40279
40639
|
/**
|
|
40280
40640
|
* `Alexa.CameraStreamController/InitializeCameraStreams` handler.
|
|
@@ -40357,347 +40717,42 @@ async function handleInitializeCameraStreams(header, endpointRaw, payloadRaw, de
|
|
|
40357
40717
|
} };
|
|
40358
40718
|
}
|
|
40359
40719
|
//#endregion
|
|
40360
|
-
//#region src/handlers/
|
|
40361
|
-
var
|
|
40362
|
-
endpoint: EndpointRefSchema,
|
|
40363
|
-
payload: InitiateSessionWithOfferPayloadSchema
|
|
40364
|
-
});
|
|
40365
|
-
var SessionDisconnectedDirectiveSchema = object({
|
|
40366
|
-
endpoint: EndpointRefSchema,
|
|
40367
|
-
payload: SessionDisconnectedPayloadSchema
|
|
40368
|
-
});
|
|
40369
|
-
/**
|
|
40370
|
-
* Live egress handles, keyed by `<deviceId>/<sessionId>`.
|
|
40371
|
-
*
|
|
40372
|
-
* The primitive's refcount has no lease TTL: a holder that vanishes without
|
|
40373
|
-
* releasing leaks a child until the broker restarts (D67). This handler is a
|
|
40374
|
-
* holder, so it keeps the one piece of state that lets it not be that holder —
|
|
40375
|
-
* the `pipelineKey` its `SessionDisconnected` has to release.
|
|
40376
|
-
*
|
|
40377
|
-
* A module-level map is right here because the directive handlers are free
|
|
40378
|
-
* functions called per directive; the entry is written on a successful acquire
|
|
40379
|
-
* and deleted on the release path, both of which are the same tick as the
|
|
40380
|
-
* directive that owns it.
|
|
40381
|
-
*/
|
|
40382
|
-
var EGRESS_HANDLES = /* @__PURE__ */ new Map();
|
|
40383
|
-
function egressHandleKey(deviceId, sessionId) {
|
|
40384
|
-
return `${deviceId}/${sessionId}`;
|
|
40385
|
-
}
|
|
40386
|
-
var WEBRTC_PROFILE_NAMES = [
|
|
40387
|
-
"high",
|
|
40388
|
-
"mid",
|
|
40389
|
-
"low"
|
|
40390
|
-
];
|
|
40391
|
-
function resolveWebrtcTarget(pref) {
|
|
40392
|
-
if (pref === "auto") return void 0;
|
|
40393
|
-
if (WEBRTC_PROFILE_NAMES.includes(pref)) return {
|
|
40394
|
-
kind: "profile",
|
|
40395
|
-
profile: pref
|
|
40396
|
-
};
|
|
40397
|
-
return {
|
|
40398
|
-
kind: "cam-stream",
|
|
40399
|
-
camStreamId: pref
|
|
40400
|
-
};
|
|
40401
|
-
}
|
|
40402
|
-
async function handleInitiateSessionWithOffer(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40403
|
-
const parsed = InitiateSessionWithOfferDirectiveSchema.safeParse({
|
|
40404
|
-
endpoint: endpointRaw,
|
|
40405
|
-
payload: payloadRaw ?? {}
|
|
40406
|
-
});
|
|
40407
|
-
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40408
|
-
const endpoint = parsed.data.endpoint;
|
|
40409
|
-
const payload = parsed.data.payload;
|
|
40410
|
-
const parsedId = parseCameraEndpointId(endpoint.endpointId);
|
|
40411
|
-
if (parsedId.kind !== "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", `endpointId ${endpoint.endpointId} is not a camera`);
|
|
40412
|
-
const deviceId = parsedId.deviceId;
|
|
40413
|
-
const sessionId = payload.sessionId;
|
|
40414
|
-
const log = deps.logger.withTags({
|
|
40415
|
-
deviceId,
|
|
40416
|
-
sessionId
|
|
40417
|
-
});
|
|
40418
|
-
const sdpOffer = payload.offer.value;
|
|
40419
|
-
if (sdpOffer.length === 0) return errorEnvelope(header, "INVALID_DIRECTIVE", "offer.value is empty");
|
|
40420
|
-
const api = deps.ctx.api;
|
|
40421
|
-
const exposedEntry = deps.listExposed().find((e) => e.deviceId === deviceId);
|
|
40422
|
-
const explicitSourceProfile = exposedEntry?.settings?.sourceProfile;
|
|
40423
|
-
const mappedFromPreference = (() => {
|
|
40424
|
-
const pref = exposedEntry?.settings?.streamPreference;
|
|
40425
|
-
if (pref === "low" || pref === "mid" || pref === "high") return pref;
|
|
40426
|
-
})();
|
|
40427
|
-
const sourceProfile = explicitSourceProfile ?? mappedFromPreference ?? "high";
|
|
40428
|
-
let derivedTarget;
|
|
40429
|
-
/**
|
|
40430
|
-
* The primitive's release handle, when this session acquired one. Recorded so
|
|
40431
|
-
* `SessionDisconnected` can release it: a refcount whose holder disappears is
|
|
40432
|
-
* the one gap D67 leaves open, and the least this handler can do is not BE
|
|
40433
|
-
* that holder.
|
|
40434
|
-
*/
|
|
40435
|
-
let egressPipelineKey = null;
|
|
40436
|
-
const picked = await api.cameraStreams.pickStream.query({
|
|
40437
|
-
deviceId,
|
|
40438
|
-
requirements: {
|
|
40439
|
-
acceptCodecs: ["h264"],
|
|
40440
|
-
minHeight: 480,
|
|
40441
|
-
excludeDerived: true,
|
|
40442
|
-
requireSiblingCodec: ["h265", "hevc"]
|
|
40443
|
-
}
|
|
40444
|
-
}).catch((err) => {
|
|
40445
|
-
log.warn("alexa rtc-session: cameraStreams.pickStream threw — falling back to transcode", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
40446
|
-
return null;
|
|
40447
|
-
});
|
|
40448
|
-
if (picked) {
|
|
40449
|
-
log.info("alexa rtc-session: bypassing transcode via cameraStreams.pickStream", { meta: {
|
|
40450
|
-
sourceProfile,
|
|
40451
|
-
selectedCamStreamId: picked.camStreamId,
|
|
40452
|
-
reason: picked.reason
|
|
40453
|
-
} });
|
|
40454
|
-
derivedTarget = {
|
|
40455
|
-
kind: "cam-stream",
|
|
40456
|
-
camStreamId: picked.camStreamId
|
|
40457
|
-
};
|
|
40458
|
-
} else try {
|
|
40459
|
-
const acquired = await acquireAlexaEgress({
|
|
40460
|
-
api,
|
|
40461
|
-
deviceId,
|
|
40462
|
-
sourceProfile,
|
|
40463
|
-
sessionId,
|
|
40464
|
-
logger: log
|
|
40465
|
-
});
|
|
40466
|
-
egressPipelineKey = acquired.pipelineKey;
|
|
40467
|
-
EGRESS_HANDLES.set(egressHandleKey(deviceId, sessionId), acquired.pipelineKey);
|
|
40468
|
-
derivedTarget = {
|
|
40469
|
-
kind: "cam-stream",
|
|
40470
|
-
camStreamId: acquired.camStreamId
|
|
40471
|
-
};
|
|
40472
|
-
} catch (err) {
|
|
40473
|
-
log.warn("alexa rtc-session: egress acquire failed, falling back to streamPreference target", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
40474
|
-
derivedTarget = resolveWebrtcTarget(exposedEntry?.settings?.streamPreference ?? "auto");
|
|
40475
|
-
}
|
|
40476
|
-
try {
|
|
40477
|
-
const result = await api.webrtcSession.handleOffer.mutate({
|
|
40478
|
-
deviceId,
|
|
40479
|
-
sdpOffer,
|
|
40480
|
-
sessionId,
|
|
40481
|
-
target: derivedTarget,
|
|
40482
|
-
relayOnly: false,
|
|
40483
|
-
nonTrickle: true,
|
|
40484
|
-
disableTurn: true,
|
|
40485
|
-
disableIpv6: true,
|
|
40486
|
-
consumerAttribution: {
|
|
40487
|
-
kind: "alexa",
|
|
40488
|
-
sessionId
|
|
40489
|
-
}
|
|
40490
|
-
});
|
|
40491
|
-
log.info("alexa rtc-session: AnswerGenerated", { meta: {
|
|
40492
|
-
returnedSessionId: result.sessionId,
|
|
40493
|
-
sdpAnswerLen: result.sdpAnswer.length
|
|
40494
|
-
} });
|
|
40495
|
-
return { event: {
|
|
40496
|
-
header: {
|
|
40497
|
-
namespace: "Alexa.RTCSessionController",
|
|
40498
|
-
name: "AnswerGeneratedForSession",
|
|
40499
|
-
messageId: header.messageId,
|
|
40500
|
-
correlationToken: header.correlationToken,
|
|
40501
|
-
payloadVersion: "3"
|
|
40502
|
-
},
|
|
40503
|
-
endpoint: { endpointId: endpoint.endpointId },
|
|
40504
|
-
payload: { answer: {
|
|
40505
|
-
format: payload.offer.format ?? "SDP",
|
|
40506
|
-
value: result.sdpAnswer
|
|
40507
|
-
} }
|
|
40508
|
-
} };
|
|
40509
|
-
} catch (err) {
|
|
40510
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
40511
|
-
const mSectionSummary = (() => {
|
|
40512
|
-
const lines = sdpOffer.split(/\r?\n/);
|
|
40513
|
-
const sections = [];
|
|
40514
|
-
let current = null;
|
|
40515
|
-
for (const raw of lines) {
|
|
40516
|
-
const line = raw.trim();
|
|
40517
|
-
if (line.startsWith("m=")) {
|
|
40518
|
-
if (current) sections.push(current);
|
|
40519
|
-
current = {
|
|
40520
|
-
mid: null,
|
|
40521
|
-
kind: line.split(" ")[0]?.slice(2) ?? "unknown",
|
|
40522
|
-
direction: null,
|
|
40523
|
-
codecs: []
|
|
40524
|
-
};
|
|
40525
|
-
} else if (current) {
|
|
40526
|
-
if (line.startsWith("a=mid:")) current.mid = line.slice(6);
|
|
40527
|
-
else if (/^a=(sendonly|recvonly|sendrecv|inactive)$/.test(line)) current.direction = line.slice(2);
|
|
40528
|
-
else if (line.startsWith("a=rtpmap:")) current.codecs.push(line.slice(9));
|
|
40529
|
-
}
|
|
40530
|
-
}
|
|
40531
|
-
if (current) sections.push(current);
|
|
40532
|
-
return sections;
|
|
40533
|
-
})();
|
|
40534
|
-
log.warn("alexa rtc-session: handleOffer failed", { meta: {
|
|
40535
|
-
error: message,
|
|
40536
|
-
offerLen: sdpOffer.length,
|
|
40537
|
-
mSections: mSectionSummary,
|
|
40538
|
-
offerSdp: sdpOffer
|
|
40539
|
-
} });
|
|
40540
|
-
if (egressPipelineKey !== null) {
|
|
40541
|
-
EGRESS_HANDLES.delete(egressHandleKey(deviceId, sessionId));
|
|
40542
|
-
await releaseAlexaEgress({
|
|
40543
|
-
api,
|
|
40544
|
-
deviceId,
|
|
40545
|
-
pipelineKey: egressPipelineKey,
|
|
40546
|
-
logger: log
|
|
40547
|
-
});
|
|
40548
|
-
}
|
|
40549
|
-
return errorEnvelope(header, "INTERNAL_ERROR", `webrtc-session.handleOffer failed: ${message}`);
|
|
40550
|
-
}
|
|
40551
|
-
}
|
|
40552
|
-
async function handleSessionDisconnected(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40553
|
-
const parsed = SessionDisconnectedDirectiveSchema.safeParse({
|
|
40554
|
-
endpoint: endpointRaw,
|
|
40555
|
-
payload: payloadRaw ?? {}
|
|
40556
|
-
});
|
|
40557
|
-
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40558
|
-
const endpoint = parsed.data.endpoint;
|
|
40559
|
-
const parsedId = parseCameraEndpointId(endpoint.endpointId);
|
|
40560
|
-
if (parsedId.kind === "camera") {
|
|
40561
|
-
const handleKey = egressHandleKey(parsedId.deviceId, parsed.data.payload.sessionId);
|
|
40562
|
-
const pipelineKey = EGRESS_HANDLES.get(handleKey);
|
|
40563
|
-
if (pipelineKey !== void 0) {
|
|
40564
|
-
EGRESS_HANDLES.delete(handleKey);
|
|
40565
|
-
await releaseAlexaEgress({
|
|
40566
|
-
api: deps.ctx.api,
|
|
40567
|
-
deviceId: parsedId.deviceId,
|
|
40568
|
-
pipelineKey,
|
|
40569
|
-
logger: deps.logger
|
|
40570
|
-
});
|
|
40571
|
-
}
|
|
40572
|
-
try {
|
|
40573
|
-
await deps.ctx.api.webrtcSession.closeSession.mutate({
|
|
40574
|
-
deviceId: parsedId.deviceId,
|
|
40575
|
-
sessionId: parsed.data.payload.sessionId
|
|
40576
|
-
});
|
|
40577
|
-
} catch (err) {
|
|
40578
|
-
deps.logger.warn("alexa rtc-session: closeSession threw on disconnect (continuing to ack)", {
|
|
40579
|
-
tags: {
|
|
40580
|
-
deviceId: parsedId.deviceId,
|
|
40581
|
-
sessionId: parsed.data.payload.sessionId
|
|
40582
|
-
},
|
|
40583
|
-
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
40584
|
-
});
|
|
40585
|
-
}
|
|
40586
|
-
}
|
|
40587
|
-
const disconnectedDeviceId = parsedId.kind === "camera" ? parsedId.deviceId : void 0;
|
|
40588
|
-
deps.logger.info("alexa rtc-session: SessionDisconnected", {
|
|
40589
|
-
tags: {
|
|
40590
|
-
sessionId: parsed.data.payload.sessionId,
|
|
40591
|
-
...disconnectedDeviceId !== void 0 ? { deviceId: disconnectedDeviceId } : {}
|
|
40592
|
-
},
|
|
40593
|
-
meta: { endpointId: endpoint.endpointId }
|
|
40594
|
-
});
|
|
40595
|
-
return { event: {
|
|
40596
|
-
header: {
|
|
40597
|
-
namespace: "Alexa",
|
|
40598
|
-
name: "Response",
|
|
40599
|
-
messageId: header.messageId,
|
|
40600
|
-
correlationToken: header.correlationToken,
|
|
40601
|
-
payloadVersion: "3"
|
|
40602
|
-
},
|
|
40603
|
-
endpoint: { endpointId: endpoint.endpointId },
|
|
40604
|
-
payload: {}
|
|
40605
|
-
} };
|
|
40606
|
-
}
|
|
40607
|
-
//#endregion
|
|
40608
|
-
//#region src/handlers/ptz-preset.ts
|
|
40609
|
-
/**
|
|
40610
|
-
* `Alexa.ModeController/SetMode` handler — dispatches three PTZ instances:
|
|
40611
|
-
*
|
|
40612
|
-
* `ptz.preset` — preset-recall. Decodes the preset name from the mode
|
|
40613
|
-
* value and calls `ptz.goToPreset({deviceId, presetId})`.
|
|
40614
|
-
*
|
|
40615
|
-
* `ptz.pan` — momentary pan. `ptz.pan.left|right|center` issues a
|
|
40616
|
-
* continuousMove pulse stopped on a timer; the dropdown reverts to
|
|
40617
|
-
* `center` server-side so subsequent picks re-trigger the move.
|
|
40618
|
-
*
|
|
40619
|
-
* `ptz.tilt` — momentary tilt. Mirrors ptz.pan with up|down|center.
|
|
40620
|
-
*/
|
|
40621
|
-
var SetModeDirectiveSchema = object({
|
|
40720
|
+
//#region src/handlers/power-controller.ts
|
|
40721
|
+
var PowerDirectiveSchema = object({
|
|
40622
40722
|
header: object({
|
|
40623
|
-
namespace: literal("Alexa.
|
|
40624
|
-
name:
|
|
40625
|
-
instance: string().optional()
|
|
40723
|
+
namespace: literal("Alexa.PowerController"),
|
|
40724
|
+
name: _enum(["TurnOn", "TurnOff"])
|
|
40626
40725
|
}),
|
|
40627
|
-
endpoint: EndpointRefSchema
|
|
40628
|
-
payload: SetModePayloadSchema
|
|
40726
|
+
endpoint: EndpointRefSchema
|
|
40629
40727
|
});
|
|
40630
|
-
|
|
40631
|
-
|
|
40632
|
-
var PTZ_PAN_MOVES = {
|
|
40633
|
-
"ptz.pan.left": { pan: -1 },
|
|
40634
|
-
"ptz.pan.right": { pan: 1 },
|
|
40635
|
-
"ptz.pan.center": {}
|
|
40636
|
-
};
|
|
40637
|
-
var PTZ_TILT_MOVES = {
|
|
40638
|
-
"ptz.tilt.up": { tilt: 1 },
|
|
40639
|
-
"ptz.tilt.down": { tilt: -1 },
|
|
40640
|
-
"ptz.tilt.center": {}
|
|
40641
|
-
};
|
|
40642
|
-
async function handleSetMode(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40643
|
-
const parsed = SetModeDirectiveSchema.safeParse({
|
|
40728
|
+
async function handlePower(header, endpointRaw, deps, _callerIdentity) {
|
|
40729
|
+
const parsed = PowerDirectiveSchema.safeParse({
|
|
40644
40730
|
header: {
|
|
40645
40731
|
namespace: header.namespace,
|
|
40646
|
-
name: header.name
|
|
40647
|
-
instance: header.instance
|
|
40732
|
+
name: header.name
|
|
40648
40733
|
},
|
|
40649
|
-
endpoint: endpointRaw
|
|
40650
|
-
payload: payloadRaw ?? {}
|
|
40734
|
+
endpoint: endpointRaw
|
|
40651
40735
|
});
|
|
40652
40736
|
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40653
|
-
const instance = parsed.data.header.instance;
|
|
40654
|
-
if (instance !== "ptz.preset" && instance !== "ptz.pan" && instance !== "ptz.tilt") return errorEnvelope(header, "INVALID_DIRECTIVE", `ModeController instance not supported: ${instance ?? "(missing)"}`);
|
|
40655
40737
|
const endpointId = parsed.data.endpoint.endpointId;
|
|
40656
40738
|
const parsedId = parseCameraEndpointId(endpointId);
|
|
40657
|
-
|
|
40658
|
-
const mode = parsed.data.payload.mode;
|
|
40739
|
+
const on = parsed.data.header.name === "TurnOn";
|
|
40659
40740
|
const api = deps.ctx.api;
|
|
40660
|
-
if (
|
|
40661
|
-
|
|
40662
|
-
|
|
40663
|
-
if (Object.keys(move).length === 0) await api.ptz.stop.mutate({ deviceId: parsedId.deviceId }).catch((err) => {
|
|
40664
|
-
deps.logger.debug("alexa ptz-mode: stop (center) failed (non-fatal)", { meta: {
|
|
40665
|
-
deviceId: parsedId.deviceId,
|
|
40666
|
-
instance,
|
|
40667
|
-
error: err instanceof Error ? err.message : String(err)
|
|
40668
|
-
} });
|
|
40669
|
-
});
|
|
40670
|
-
else try {
|
|
40671
|
-
await api.ptz.continuousMove.mutate({
|
|
40672
|
-
deviceId: parsedId.deviceId,
|
|
40673
|
-
...move
|
|
40674
|
-
});
|
|
40675
|
-
setTimeout(() => {
|
|
40676
|
-
api.ptz.stop.mutate({ deviceId: parsedId.deviceId }).catch((err) => {
|
|
40677
|
-
deps.logger.debug("alexa ptz-mode: stop after pulse failed (non-fatal)", { meta: {
|
|
40678
|
-
deviceId: parsedId.deviceId,
|
|
40679
|
-
instance,
|
|
40680
|
-
error: err instanceof Error ? err.message : String(err)
|
|
40681
|
-
} });
|
|
40682
|
-
});
|
|
40683
|
-
}, PTZ_DIRECTION_PULSE_MS);
|
|
40684
|
-
} catch (err) {
|
|
40685
|
-
return errorEnvelope(header, "INTERNAL_ERROR", `ptz.continuousMove failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
40686
|
-
}
|
|
40687
|
-
return modeSuccessResponse(header, endpointId, instance, instance === "ptz.pan" ? "ptz.pan.center" : "ptz.tilt.center");
|
|
40688
|
-
}
|
|
40689
|
-
if (!mode.startsWith(PTZ_PRESET_MODE_PREFIX)) return errorEnvelope(header, "INVALID_DIRECTIVE", `mode '${mode}' is not a ptz.preset mode`);
|
|
40690
|
-
const presetName = mode.slice(11);
|
|
40691
|
-
if (presetName.length === 0) return errorEnvelope(header, "INVALID_DIRECTIVE", "preset name missing after prefix");
|
|
40692
|
-
const preset = (await api.ptz.getPresets.query({ deviceId: parsedId.deviceId })).find((p) => p.name === presetName);
|
|
40693
|
-
if (!preset) return errorEnvelope(header, "INVALID_DIRECTIVE", `preset '${presetName}' not found on device ${parsedId.deviceId}`);
|
|
40694
|
-
await api.ptz.goToPreset.mutate({
|
|
40695
|
-
deviceId: parsedId.deviceId,
|
|
40696
|
-
presetId: preset.id
|
|
40741
|
+
if (parsedId.kind === "autotrack") await api.ptzAutotrack.setEnabled.mutate({
|
|
40742
|
+
deviceId: parsedId.parentDeviceId,
|
|
40743
|
+
enabled: on
|
|
40697
40744
|
});
|
|
40698
|
-
|
|
40699
|
-
|
|
40700
|
-
|
|
40745
|
+
else if (parsedId.kind === "privacy") await api.privacyMask.setMask.mutate({
|
|
40746
|
+
deviceId: parsedId.parentDeviceId,
|
|
40747
|
+
patch: { enabled: on }
|
|
40748
|
+
});
|
|
40749
|
+
else if (parsedId.kind === "child") await api.switch.setState.mutate({
|
|
40750
|
+
deviceId: parsedId.childDeviceId,
|
|
40751
|
+
on
|
|
40752
|
+
});
|
|
40753
|
+
else if (parsedId.kind === "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", "PowerController is not exposed on camera endpoints — direct the directive at the child accessory");
|
|
40754
|
+
else if (parsedId.kind === "alarm-panel") return errorEnvelope(header, "INVALID_DIRECTIVE", "PowerController is not exposed on alarm-panel endpoints — use Alexa.SecurityPanelController");
|
|
40755
|
+
else return errorEnvelope(header, "INVALID_DIRECTIVE", parsedId.reason);
|
|
40701
40756
|
return {
|
|
40702
40757
|
event: {
|
|
40703
40758
|
header: {
|
|
@@ -40711,10 +40766,9 @@ function modeSuccessResponse(header, endpointId, instance, mode) {
|
|
|
40711
40766
|
payload: {}
|
|
40712
40767
|
},
|
|
40713
40768
|
context: { properties: [{
|
|
40714
|
-
namespace: "Alexa.
|
|
40715
|
-
|
|
40716
|
-
|
|
40717
|
-
value: mode,
|
|
40769
|
+
namespace: "Alexa.PowerController",
|
|
40770
|
+
name: "powerState",
|
|
40771
|
+
value: on ? "ON" : "OFF",
|
|
40718
40772
|
timeOfSample: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40719
40773
|
uncertaintyInMilliseconds: 500
|
|
40720
40774
|
}] }
|
|
@@ -40814,133 +40868,99 @@ function successResponse(header, endpointId, toggleState, instance) {
|
|
|
40814
40868
|
};
|
|
40815
40869
|
}
|
|
40816
40870
|
//#endregion
|
|
40817
|
-
//#region src/handlers/
|
|
40818
|
-
/**
|
|
40819
|
-
* `Alexa.PowerController/{TurnOn,TurnOff}` handler.
|
|
40820
|
-
*
|
|
40821
|
-
* Routing decodes the endpoint id:
|
|
40822
|
-
* - `${parent}__${child}` → call `switch.setState({deviceId: child, on})`
|
|
40823
|
-
* - `${parent}__autotrack` → call `ptzAutotrack.setEnabled({deviceId: parent, enabled})`
|
|
40824
|
-
* - `${parent}__privacy` → call `privacyMask.setMask({deviceId: parent, patch: { enabled } })`
|
|
40825
|
-
* - `${deviceId}` (bare parent camera) → reject with INVALID_DIRECTIVE
|
|
40826
|
-
* (we never expose PowerController on the camera itself).
|
|
40827
|
-
*
|
|
40828
|
-
* Auth: verify the directive's scope token (same as every other
|
|
40829
|
-
* controller).
|
|
40830
|
-
*/
|
|
40831
|
-
var PowerDirectiveSchema = object({
|
|
40832
|
-
header: object({
|
|
40833
|
-
namespace: literal("Alexa.PowerController"),
|
|
40834
|
-
name: _enum(["TurnOn", "TurnOff"])
|
|
40835
|
-
}),
|
|
40836
|
-
endpoint: EndpointRefSchema
|
|
40837
|
-
});
|
|
40838
|
-
async function handlePower(header, endpointRaw, deps, _callerIdentity) {
|
|
40839
|
-
const parsed = PowerDirectiveSchema.safeParse({
|
|
40840
|
-
header: {
|
|
40841
|
-
namespace: header.namespace,
|
|
40842
|
-
name: header.name
|
|
40843
|
-
},
|
|
40844
|
-
endpoint: endpointRaw
|
|
40845
|
-
});
|
|
40846
|
-
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40847
|
-
const endpointId = parsed.data.endpoint.endpointId;
|
|
40848
|
-
const parsedId = parseCameraEndpointId(endpointId);
|
|
40849
|
-
const on = parsed.data.header.name === "TurnOn";
|
|
40850
|
-
const api = deps.ctx.api;
|
|
40851
|
-
if (parsedId.kind === "autotrack") await api.ptzAutotrack.setEnabled.mutate({
|
|
40852
|
-
deviceId: parsedId.parentDeviceId,
|
|
40853
|
-
enabled: on
|
|
40854
|
-
});
|
|
40855
|
-
else if (parsedId.kind === "privacy") await api.privacyMask.setMask.mutate({
|
|
40856
|
-
deviceId: parsedId.parentDeviceId,
|
|
40857
|
-
patch: { enabled: on }
|
|
40858
|
-
});
|
|
40859
|
-
else if (parsedId.kind === "child") await api.switch.setState.mutate({
|
|
40860
|
-
deviceId: parsedId.childDeviceId,
|
|
40861
|
-
on
|
|
40862
|
-
});
|
|
40863
|
-
else if (parsedId.kind === "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", "PowerController is not exposed on camera endpoints — direct the directive at the child accessory");
|
|
40864
|
-
else return errorEnvelope(header, "INVALID_DIRECTIVE", parsedId.reason);
|
|
40865
|
-
return {
|
|
40866
|
-
event: {
|
|
40867
|
-
header: {
|
|
40868
|
-
namespace: "Alexa",
|
|
40869
|
-
name: "Response",
|
|
40870
|
-
messageId: header.messageId,
|
|
40871
|
-
correlationToken: header.correlationToken,
|
|
40872
|
-
payloadVersion: "3"
|
|
40873
|
-
},
|
|
40874
|
-
endpoint: { endpointId },
|
|
40875
|
-
payload: {}
|
|
40876
|
-
},
|
|
40877
|
-
context: { properties: [{
|
|
40878
|
-
namespace: "Alexa.PowerController",
|
|
40879
|
-
name: "powerState",
|
|
40880
|
-
value: on ? "ON" : "OFF",
|
|
40881
|
-
timeOfSample: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40882
|
-
uncertaintyInMilliseconds: 500
|
|
40883
|
-
}] }
|
|
40884
|
-
};
|
|
40885
|
-
}
|
|
40886
|
-
//#endregion
|
|
40887
|
-
//#region src/handlers/brightness-controller.ts
|
|
40871
|
+
//#region src/handlers/ptz-preset.ts
|
|
40888
40872
|
/**
|
|
40889
|
-
* `Alexa.
|
|
40873
|
+
* `Alexa.ModeController/SetMode` handler — dispatches three PTZ instances:
|
|
40890
40874
|
*
|
|
40891
|
-
*
|
|
40892
|
-
*
|
|
40893
|
-
* Reolink floodlights, Hikvision supplemental lights). Brightness is
|
|
40894
|
-
* NEVER exposed on the parent camera endpoint or on the synthetic
|
|
40895
|
-
* autotrack endpoint — both reject INVALID_DIRECTIVE here.
|
|
40875
|
+
* `ptz.preset` — preset-recall. Decodes the preset name from the mode
|
|
40876
|
+
* value and calls `ptz.goToPreset({deviceId, presetId})`.
|
|
40896
40877
|
*
|
|
40897
|
-
*
|
|
40898
|
-
*
|
|
40878
|
+
* `ptz.pan` — momentary pan. `ptz.pan.left|right|center` issues a
|
|
40879
|
+
* continuousMove pulse stopped on a timer; the dropdown reverts to
|
|
40880
|
+
* `center` server-side so subsequent picks re-trigger the move.
|
|
40899
40881
|
*
|
|
40900
|
-
*
|
|
40901
|
-
* The response carries the `Alexa.BrightnessController.brightness`
|
|
40902
|
-
* property echoing the new level so the Echo updates its UI without an
|
|
40903
|
-
* extra ReportState round-trip.
|
|
40882
|
+
* `ptz.tilt` — momentary tilt. Mirrors ptz.pan with up|down|center.
|
|
40904
40883
|
*/
|
|
40905
|
-
var
|
|
40884
|
+
var SetModeDirectiveSchema = object({
|
|
40906
40885
|
header: object({
|
|
40907
|
-
namespace: literal("Alexa.
|
|
40908
|
-
name: literal("
|
|
40886
|
+
namespace: literal("Alexa.ModeController"),
|
|
40887
|
+
name: literal("SetMode"),
|
|
40888
|
+
instance: string().optional()
|
|
40909
40889
|
}),
|
|
40910
40890
|
endpoint: EndpointRefSchema,
|
|
40911
|
-
payload:
|
|
40891
|
+
payload: SetModePayloadSchema
|
|
40912
40892
|
});
|
|
40913
|
-
|
|
40914
|
-
|
|
40893
|
+
var PTZ_PRESET_MODE_PREFIX = "ptz.preset.";
|
|
40894
|
+
var PTZ_DIRECTION_PULSE_MS = 1e3;
|
|
40895
|
+
var PTZ_PAN_MOVES = {
|
|
40896
|
+
"ptz.pan.left": { pan: -1 },
|
|
40897
|
+
"ptz.pan.right": { pan: 1 },
|
|
40898
|
+
"ptz.pan.center": {}
|
|
40899
|
+
};
|
|
40900
|
+
var PTZ_TILT_MOVES = {
|
|
40901
|
+
"ptz.tilt.up": { tilt: 1 },
|
|
40902
|
+
"ptz.tilt.down": { tilt: -1 },
|
|
40903
|
+
"ptz.tilt.center": {}
|
|
40904
|
+
};
|
|
40905
|
+
async function handleSetMode(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40906
|
+
const parsed = SetModeDirectiveSchema.safeParse({
|
|
40915
40907
|
header: {
|
|
40916
40908
|
namespace: header.namespace,
|
|
40917
|
-
name: header.name
|
|
40909
|
+
name: header.name,
|
|
40910
|
+
instance: header.instance
|
|
40918
40911
|
},
|
|
40919
40912
|
endpoint: endpointRaw,
|
|
40920
40913
|
payload: payloadRaw ?? {}
|
|
40921
40914
|
});
|
|
40922
40915
|
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40916
|
+
const instance = parsed.data.header.instance;
|
|
40917
|
+
if (instance !== "ptz.preset" && instance !== "ptz.pan" && instance !== "ptz.tilt") return errorEnvelope(header, "INVALID_DIRECTIVE", `ModeController instance not supported: ${instance ?? "(missing)"}`);
|
|
40923
40918
|
const endpointId = parsed.data.endpoint.endpointId;
|
|
40924
40919
|
const parsedId = parseCameraEndpointId(endpointId);
|
|
40925
|
-
if (parsedId.kind
|
|
40926
|
-
|
|
40927
|
-
if (parsedId.kind === "invalid") return errorEnvelope(header, "INVALID_DIRECTIVE", parsedId.reason);
|
|
40928
|
-
const percentage = parsed.data.payload.brightness;
|
|
40920
|
+
if (parsedId.kind !== "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", `ModeController only supported on camera endpoints — got ${endpointId}`);
|
|
40921
|
+
const mode = parsed.data.payload.mode;
|
|
40929
40922
|
const api = deps.ctx.api;
|
|
40930
|
-
|
|
40931
|
-
|
|
40932
|
-
|
|
40933
|
-
|
|
40923
|
+
if (instance === "ptz.pan" || instance === "ptz.tilt") {
|
|
40924
|
+
const move = (instance === "ptz.pan" ? PTZ_PAN_MOVES : PTZ_TILT_MOVES)[mode];
|
|
40925
|
+
if (!move) return errorEnvelope(header, "INVALID_DIRECTIVE", `mode '${mode}' is not a valid ${instance} mode`);
|
|
40926
|
+
if (Object.keys(move).length === 0) await api.ptz.stop.mutate({ deviceId: parsedId.deviceId }).catch((err) => {
|
|
40927
|
+
deps.logger.debug("alexa ptz-mode: stop (center) failed (non-fatal)", { meta: {
|
|
40928
|
+
deviceId: parsedId.deviceId,
|
|
40929
|
+
instance,
|
|
40930
|
+
error: err instanceof Error ? err.message : String(err)
|
|
40931
|
+
} });
|
|
40934
40932
|
});
|
|
40935
|
-
|
|
40936
|
-
|
|
40937
|
-
|
|
40938
|
-
|
|
40939
|
-
|
|
40940
|
-
|
|
40941
|
-
|
|
40942
|
-
|
|
40933
|
+
else try {
|
|
40934
|
+
await api.ptz.continuousMove.mutate({
|
|
40935
|
+
deviceId: parsedId.deviceId,
|
|
40936
|
+
...move
|
|
40937
|
+
});
|
|
40938
|
+
setTimeout(() => {
|
|
40939
|
+
api.ptz.stop.mutate({ deviceId: parsedId.deviceId }).catch((err) => {
|
|
40940
|
+
deps.logger.debug("alexa ptz-mode: stop after pulse failed (non-fatal)", { meta: {
|
|
40941
|
+
deviceId: parsedId.deviceId,
|
|
40942
|
+
instance,
|
|
40943
|
+
error: err instanceof Error ? err.message : String(err)
|
|
40944
|
+
} });
|
|
40945
|
+
});
|
|
40946
|
+
}, PTZ_DIRECTION_PULSE_MS);
|
|
40947
|
+
} catch (err) {
|
|
40948
|
+
return errorEnvelope(header, "INTERNAL_ERROR", `ptz.continuousMove failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
40949
|
+
}
|
|
40950
|
+
return modeSuccessResponse(header, endpointId, instance, instance === "ptz.pan" ? "ptz.pan.center" : "ptz.tilt.center");
|
|
40943
40951
|
}
|
|
40952
|
+
if (!mode.startsWith(PTZ_PRESET_MODE_PREFIX)) return errorEnvelope(header, "INVALID_DIRECTIVE", `mode '${mode}' is not a ptz.preset mode`);
|
|
40953
|
+
const presetName = mode.slice(11);
|
|
40954
|
+
if (presetName.length === 0) return errorEnvelope(header, "INVALID_DIRECTIVE", "preset name missing after prefix");
|
|
40955
|
+
const preset = (await api.ptz.getPresets.query({ deviceId: parsedId.deviceId })).find((p) => p.name === presetName);
|
|
40956
|
+
if (!preset) return errorEnvelope(header, "INVALID_DIRECTIVE", `preset '${presetName}' not found on device ${parsedId.deviceId}`);
|
|
40957
|
+
await api.ptz.goToPreset.mutate({
|
|
40958
|
+
deviceId: parsedId.deviceId,
|
|
40959
|
+
presetId: preset.id
|
|
40960
|
+
});
|
|
40961
|
+
return modeSuccessResponse(header, endpointId, "ptz.preset", mode);
|
|
40962
|
+
}
|
|
40963
|
+
function modeSuccessResponse(header, endpointId, instance, mode) {
|
|
40944
40964
|
return {
|
|
40945
40965
|
event: {
|
|
40946
40966
|
header: {
|
|
@@ -40954,9 +40974,10 @@ async function handleSetBrightness(header, endpointRaw, payloadRaw, deps, _calle
|
|
|
40954
40974
|
payload: {}
|
|
40955
40975
|
},
|
|
40956
40976
|
context: { properties: [{
|
|
40957
|
-
namespace: "Alexa.
|
|
40958
|
-
|
|
40959
|
-
|
|
40977
|
+
namespace: "Alexa.ModeController",
|
|
40978
|
+
instance,
|
|
40979
|
+
name: "mode",
|
|
40980
|
+
value: mode,
|
|
40960
40981
|
timeOfSample: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40961
40982
|
uncertaintyInMilliseconds: 500
|
|
40962
40983
|
}] }
|
|
@@ -40977,6 +40998,7 @@ async function handleReportState(header, endpointRaw, deps, _callerIdentity) {
|
|
|
40977
40998
|
else if (parsed.kind === "privacy") await collectPrivacyProperties(api, parsed.parentDeviceId, properties, nowIso, deps.logger);
|
|
40978
40999
|
else if (parsed.kind === "autotrack") await collectAutotrackProperties(api, parsed.parentDeviceId, properties, nowIso, deps.logger);
|
|
40979
41000
|
else if (parsed.kind === "child") await collectChildProperties(api, parsed.childDeviceId, properties, nowIso, deps.logger);
|
|
41001
|
+
else if (parsed.kind === "alarm-panel") await collectAlarmPanelProperties(api, parsed.deviceId, properties, nowIso, deps.logger);
|
|
40980
41002
|
} catch (err) {
|
|
40981
41003
|
deps.logger.warn("alexa report-state: collection failed", { meta: {
|
|
40982
41004
|
endpointId,
|
|
@@ -41038,6 +41060,42 @@ async function collectCameraProperties(api, deviceId, properties, timeOfSample,
|
|
|
41038
41060
|
uncertaintyInMilliseconds: 0
|
|
41039
41061
|
});
|
|
41040
41062
|
}
|
|
41063
|
+
/**
|
|
41064
|
+
* The panel's two declared properties.
|
|
41065
|
+
*
|
|
41066
|
+
* Both are omitted when the panel cannot be read — an `armState` we guessed
|
|
41067
|
+
* would be a claim about whether a house is locked, and Alexa rendering the
|
|
41068
|
+
* endpoint as unavailable is the truthful outcome of a panel nobody reached.
|
|
41069
|
+
* The failure is logged with the device id, never swallowed.
|
|
41070
|
+
*/
|
|
41071
|
+
async function collectAlarmPanelProperties(api, deviceId, properties, timeOfSample, logger) {
|
|
41072
|
+
const status = await api.alarmPanel.getStatus.query({ deviceId }).catch((err) => {
|
|
41073
|
+
logger.warn("alexa report-state: alarmPanel.getStatus FAILED — Alexa will show the panel as unavailable", {
|
|
41074
|
+
tags: { deviceId },
|
|
41075
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
41076
|
+
});
|
|
41077
|
+
return null;
|
|
41078
|
+
});
|
|
41079
|
+
const parsed = AlarmPanelStatusSchema.pick({ state: true }).safeParse(status);
|
|
41080
|
+
if (!parsed.success) {
|
|
41081
|
+
if (status !== null) logger.warn("alexa report-state: panel status did not match the cap schema — omitting", { tags: { deviceId } });
|
|
41082
|
+
return;
|
|
41083
|
+
}
|
|
41084
|
+
properties.push({
|
|
41085
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41086
|
+
name: "armState",
|
|
41087
|
+
value: alexaArmStateFor(parsed.data.state),
|
|
41088
|
+
timeOfSample,
|
|
41089
|
+
uncertaintyInMilliseconds: 0
|
|
41090
|
+
});
|
|
41091
|
+
properties.push({
|
|
41092
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41093
|
+
name: "burglaryAlarm",
|
|
41094
|
+
value: burglaryAlarmFor(parsed.data.state),
|
|
41095
|
+
timeOfSample,
|
|
41096
|
+
uncertaintyInMilliseconds: 0
|
|
41097
|
+
});
|
|
41098
|
+
}
|
|
41041
41099
|
async function collectPrivacyProperties(api, parentDeviceId, properties, timeOfSample, _logger) {
|
|
41042
41100
|
const status = await api.privacyMask.getStatus.query({ deviceId: parentDeviceId }).catch(() => null);
|
|
41043
41101
|
const enabled = Boolean(status?.enabled);
|
|
@@ -41091,6 +41149,478 @@ async function collectChildProperties(api, childDeviceId, properties, timeOfSamp
|
|
|
41091
41149
|
});
|
|
41092
41150
|
}
|
|
41093
41151
|
//#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
|
+
//#region src/handlers/security-panel.ts
|
|
41401
|
+
var ArmPayloadSchema = object({ armState: _enum([
|
|
41402
|
+
"ARMED_STAY",
|
|
41403
|
+
"ARMED_AWAY",
|
|
41404
|
+
"ARMED_NIGHT"
|
|
41405
|
+
]) });
|
|
41406
|
+
var DisarmPayloadSchema = object({ authorization: object({
|
|
41407
|
+
type: literal("FOUR_DIGIT_PIN"),
|
|
41408
|
+
value: string().min(1)
|
|
41409
|
+
}).optional() });
|
|
41410
|
+
/** The subset of the panel status the directives read. */
|
|
41411
|
+
var PanelReadSchema = AlarmPanelStatusSchema.pick({
|
|
41412
|
+
state: true,
|
|
41413
|
+
availableModes: true,
|
|
41414
|
+
requiresCode: true
|
|
41415
|
+
});
|
|
41416
|
+
/**
|
|
41417
|
+
* `Alexa.SecurityPanelController.ErrorResponse`.
|
|
41418
|
+
*
|
|
41419
|
+
* A namespace of its own, because the four types that matter here
|
|
41420
|
+
* (`AUTHORIZATION_REQUIRED`, `UNAUTHORIZED`, `NOT_READY_FOR_ARM`,
|
|
41421
|
+
* `BYPASS_NEEDED`) are only understood under it — the generic `Alexa`
|
|
41422
|
+
* `ErrorResponse` from `error-envelope.ts` carries none of them, and a PIN
|
|
41423
|
+
* problem reported there is a message the Alexa app cannot act on.
|
|
41424
|
+
*/
|
|
41425
|
+
function securityPanelError(header, type, message) {
|
|
41426
|
+
return { event: {
|
|
41427
|
+
header: {
|
|
41428
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41429
|
+
name: "ErrorResponse",
|
|
41430
|
+
messageId: header.messageId,
|
|
41431
|
+
correlationToken: header.correlationToken,
|
|
41432
|
+
payloadVersion: "3"
|
|
41433
|
+
},
|
|
41434
|
+
payload: {
|
|
41435
|
+
type,
|
|
41436
|
+
message
|
|
41437
|
+
}
|
|
41438
|
+
} };
|
|
41439
|
+
}
|
|
41440
|
+
/** Resolve the alarm panel this directive targets, or the refusal to send. */
|
|
41441
|
+
function resolveDeviceId(endpointRaw) {
|
|
41442
|
+
const parsedEndpoint = EndpointRefSchema.safeParse(endpointRaw);
|
|
41443
|
+
if (!parsedEndpoint.success) return { reason: "missing or malformed endpoint" };
|
|
41444
|
+
const parsedId = parseCameraEndpointId(parsedEndpoint.data.endpointId);
|
|
41445
|
+
if (parsedId.kind === "alarm-panel") return { deviceId: parsedId.deviceId };
|
|
41446
|
+
return { reason: `SecurityPanelController is only exposed on alarm-panel endpoints — got '${parsedEndpoint.data.endpointId}'` };
|
|
41447
|
+
}
|
|
41448
|
+
/**
|
|
41449
|
+
* What the panel currently accepts, or `null` when it could not be read.
|
|
41450
|
+
*
|
|
41451
|
+
* `null` is the honest answer and the callers treat it as unknown; nothing
|
|
41452
|
+
* here substitutes a default that would read as "accepts nothing, needs no
|
|
41453
|
+
* PIN".
|
|
41454
|
+
*/
|
|
41455
|
+
async function readPanel(api, deviceId, logger, phase) {
|
|
41456
|
+
const raw = await api.alarmPanel.getStatus.query({ deviceId }).catch((err) => {
|
|
41457
|
+
logger.warn("alexa security-panel: alarmPanel.getStatus failed — proceeding without it", {
|
|
41458
|
+
tags: { deviceId },
|
|
41459
|
+
meta: {
|
|
41460
|
+
phase,
|
|
41461
|
+
error: err instanceof Error ? err.message : String(err)
|
|
41462
|
+
}
|
|
41463
|
+
});
|
|
41464
|
+
return null;
|
|
41465
|
+
});
|
|
41466
|
+
const parsed = PanelReadSchema.safeParse(raw);
|
|
41467
|
+
if (!parsed.success) {
|
|
41468
|
+
if (raw !== null) logger.warn("alexa security-panel: panel status did not match the cap schema", {
|
|
41469
|
+
tags: { deviceId },
|
|
41470
|
+
meta: { phase }
|
|
41471
|
+
});
|
|
41472
|
+
return null;
|
|
41473
|
+
}
|
|
41474
|
+
return parsed.data;
|
|
41475
|
+
}
|
|
41476
|
+
/** The `context.properties` block for a panel whose state we re-read. */
|
|
41477
|
+
function panelProperties(facts, fallback) {
|
|
41478
|
+
const timeOfSample = (/* @__PURE__ */ new Date()).toISOString();
|
|
41479
|
+
const parsedState = facts === null ? null : AlarmPanelStatusSchema.shape.state.parse(facts.state);
|
|
41480
|
+
const armState = parsedState === null ? fallback : alexaArmStateFor(parsedState);
|
|
41481
|
+
const burglary = parsedState === null ? { value: "OK" } : burglaryAlarmFor(parsedState);
|
|
41482
|
+
return [{
|
|
41483
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41484
|
+
name: "armState",
|
|
41485
|
+
value: armState,
|
|
41486
|
+
timeOfSample,
|
|
41487
|
+
uncertaintyInMilliseconds: 0
|
|
41488
|
+
}, {
|
|
41489
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41490
|
+
name: "burglaryAlarm",
|
|
41491
|
+
value: burglary,
|
|
41492
|
+
timeOfSample,
|
|
41493
|
+
uncertaintyInMilliseconds: 0
|
|
41494
|
+
}];
|
|
41495
|
+
}
|
|
41496
|
+
async function handleArm(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
41497
|
+
const target = resolveDeviceId(endpointRaw);
|
|
41498
|
+
if (!("deviceId" in target)) return errorEnvelope(header, "INVALID_DIRECTIVE", target.reason);
|
|
41499
|
+
const { deviceId } = target;
|
|
41500
|
+
const payload = ArmPayloadSchema.safeParse(payloadRaw);
|
|
41501
|
+
if (!payload.success) {
|
|
41502
|
+
deps.logger.warn("alexa security-panel: Arm payload is not an arm state Alexa defines", {
|
|
41503
|
+
tags: { deviceId },
|
|
41504
|
+
meta: { error: payload.error.message }
|
|
41505
|
+
});
|
|
41506
|
+
return errorEnvelope(header, "INVALID_DIRECTIVE", `Arm payload unexpected: ${payload.error.message}`);
|
|
41507
|
+
}
|
|
41508
|
+
const requested = payload.data.armState;
|
|
41509
|
+
const api = deps.ctx.api;
|
|
41510
|
+
const facts = await readPanel(api, deviceId, deps.logger, "arm");
|
|
41511
|
+
if (facts?.requiresCode === true) {
|
|
41512
|
+
deps.logger.warn("alexa security-panel: panel requires a PIN and the Arm directive carries none — REFUSED", {
|
|
41513
|
+
tags: { deviceId },
|
|
41514
|
+
meta: { requested }
|
|
41515
|
+
});
|
|
41516
|
+
return securityPanelError(header, "AUTHORIZATION_REQUIRED", "this panel requires a PIN to arm, and Alexa cannot supply one on an Arm directive");
|
|
41517
|
+
}
|
|
41518
|
+
const mode = alarmArmModeForAlexa(requested, facts?.availableModes ?? []);
|
|
41519
|
+
if (mode === null) {
|
|
41520
|
+
deps.logger.warn("alexa security-panel: panel accepts no mode for this arm state — REFUSED", {
|
|
41521
|
+
tags: { deviceId },
|
|
41522
|
+
meta: {
|
|
41523
|
+
requested,
|
|
41524
|
+
availableModes: facts?.availableModes ?? null
|
|
41525
|
+
}
|
|
41526
|
+
});
|
|
41527
|
+
return securityPanelError(header, "NOT_READY_FOR_ARM", `panel does not accept ${requested}`);
|
|
41528
|
+
}
|
|
41529
|
+
try {
|
|
41530
|
+
await api.alarmPanel.arm.mutate({
|
|
41531
|
+
deviceId,
|
|
41532
|
+
mode
|
|
41533
|
+
});
|
|
41534
|
+
} catch (err) {
|
|
41535
|
+
deps.logger.warn("alexa security-panel: arm command failed", {
|
|
41536
|
+
tags: { deviceId },
|
|
41537
|
+
meta: {
|
|
41538
|
+
requested,
|
|
41539
|
+
mode,
|
|
41540
|
+
error: err instanceof Error ? err.message : String(err)
|
|
41541
|
+
}
|
|
41542
|
+
});
|
|
41543
|
+
return securityPanelError(header, "NOT_READY_FOR_ARM", err instanceof Error ? err.message : String(err));
|
|
41544
|
+
}
|
|
41545
|
+
deps.logger.info("alexa security-panel: armed", {
|
|
41546
|
+
tags: { deviceId },
|
|
41547
|
+
meta: {
|
|
41548
|
+
requested,
|
|
41549
|
+
mode
|
|
41550
|
+
}
|
|
41551
|
+
});
|
|
41552
|
+
const after = await readPanel(api, deviceId, deps.logger, "arm-confirm");
|
|
41553
|
+
if (after?.state === "arming") deps.logger.info("alexa security-panel: panel is in its exit delay — reporting DISARMED until it is set", {
|
|
41554
|
+
tags: { deviceId },
|
|
41555
|
+
meta: {
|
|
41556
|
+
requested,
|
|
41557
|
+
mode
|
|
41558
|
+
}
|
|
41559
|
+
});
|
|
41560
|
+
return {
|
|
41561
|
+
event: {
|
|
41562
|
+
header: {
|
|
41563
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41564
|
+
name: "Arm.Response",
|
|
41565
|
+
messageId: header.messageId,
|
|
41566
|
+
correlationToken: header.correlationToken,
|
|
41567
|
+
payloadVersion: "3"
|
|
41568
|
+
},
|
|
41569
|
+
endpoint: { endpointId: `${deviceId}__alarm` },
|
|
41570
|
+
payload: {}
|
|
41571
|
+
},
|
|
41572
|
+
context: { properties: panelProperties(after, requested) }
|
|
41573
|
+
};
|
|
41574
|
+
}
|
|
41575
|
+
async function handleDisarm(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
41576
|
+
const target = resolveDeviceId(endpointRaw);
|
|
41577
|
+
if (!("deviceId" in target)) return errorEnvelope(header, "INVALID_DIRECTIVE", target.reason);
|
|
41578
|
+
const { deviceId } = target;
|
|
41579
|
+
const payload = DisarmPayloadSchema.safeParse(payloadRaw ?? {});
|
|
41580
|
+
if (!payload.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `Disarm payload unexpected: ${payload.error.message}`);
|
|
41581
|
+
const code = payload.data.authorization?.value;
|
|
41582
|
+
const api = deps.ctx.api;
|
|
41583
|
+
if ((await readPanel(api, deviceId, deps.logger, "disarm"))?.requiresCode === true && code === void 0) {
|
|
41584
|
+
deps.logger.warn("alexa security-panel: panel requires a PIN and the Disarm directive carried none — REFUSED", { tags: { deviceId } });
|
|
41585
|
+
return securityPanelError(header, "AUTHORIZATION_REQUIRED", "this panel requires a PIN to disarm");
|
|
41586
|
+
}
|
|
41587
|
+
try {
|
|
41588
|
+
await api.alarmPanel.disarm.mutate(code === void 0 ? { deviceId } : {
|
|
41589
|
+
deviceId,
|
|
41590
|
+
code
|
|
41591
|
+
});
|
|
41592
|
+
} catch (err) {
|
|
41593
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
41594
|
+
deps.logger.warn("alexa security-panel: disarm command failed", {
|
|
41595
|
+
tags: { deviceId },
|
|
41596
|
+
meta: {
|
|
41597
|
+
codeSupplied: code !== void 0,
|
|
41598
|
+
error: message
|
|
41599
|
+
}
|
|
41600
|
+
});
|
|
41601
|
+
return code === void 0 ? errorEnvelope(header, "INTERNAL_ERROR", message) : securityPanelError(header, "UNAUTHORIZED", message);
|
|
41602
|
+
}
|
|
41603
|
+
deps.logger.info("alexa security-panel: disarmed", {
|
|
41604
|
+
tags: { deviceId },
|
|
41605
|
+
meta: { codeSupplied: code !== void 0 }
|
|
41606
|
+
});
|
|
41607
|
+
const after = await readPanel(api, deviceId, deps.logger, "disarm-confirm");
|
|
41608
|
+
return {
|
|
41609
|
+
event: {
|
|
41610
|
+
header: {
|
|
41611
|
+
namespace: "Alexa",
|
|
41612
|
+
name: "Response",
|
|
41613
|
+
messageId: header.messageId,
|
|
41614
|
+
correlationToken: header.correlationToken,
|
|
41615
|
+
payloadVersion: "3"
|
|
41616
|
+
},
|
|
41617
|
+
endpoint: { endpointId: `${deviceId}__alarm` },
|
|
41618
|
+
payload: {}
|
|
41619
|
+
},
|
|
41620
|
+
context: { properties: panelProperties(after, "DISARMED") }
|
|
41621
|
+
};
|
|
41622
|
+
}
|
|
41623
|
+
//#endregion
|
|
41094
41624
|
//#region src/handlers/stubs.ts
|
|
41095
41625
|
/**
|
|
41096
41626
|
* Stub responder for namespaces not yet implemented (CameraStream /
|
|
@@ -41170,7 +41700,9 @@ async function dispatchDirective(rawBody, deps, callerIdentity) {
|
|
|
41170
41700
|
"Alexa.ModeController/SetMode": "create",
|
|
41171
41701
|
"Alexa.ToggleController/TurnOn": "create",
|
|
41172
41702
|
"Alexa.ToggleController/TurnOff": "create",
|
|
41173
|
-
"Alexa/ReportState": "view"
|
|
41703
|
+
"Alexa/ReportState": "view",
|
|
41704
|
+
"Alexa.SecurityPanelController/Arm": "create",
|
|
41705
|
+
"Alexa.SecurityPanelController/Disarm": "create"
|
|
41174
41706
|
};
|
|
41175
41707
|
try {
|
|
41176
41708
|
const key = `${header.namespace}/${header.name}`;
|
|
@@ -41215,6 +41747,14 @@ async function dispatchDirective(rawBody, deps, callerIdentity) {
|
|
|
41215
41747
|
status: 200,
|
|
41216
41748
|
body: await handlePtzDirection(header, endpoint, deps.ptzDirection, callerIdentity)
|
|
41217
41749
|
};
|
|
41750
|
+
if (key === "Alexa.SecurityPanelController/Arm") return {
|
|
41751
|
+
status: 200,
|
|
41752
|
+
body: await handleArm(header, endpoint, payload, deps.securityPanel, callerIdentity)
|
|
41753
|
+
};
|
|
41754
|
+
if (key === "Alexa.SecurityPanelController/Disarm") return {
|
|
41755
|
+
status: 200,
|
|
41756
|
+
body: await handleDisarm(header, endpoint, payload, deps.securityPanel, callerIdentity)
|
|
41757
|
+
};
|
|
41218
41758
|
if (key === "Alexa/ReportState") return {
|
|
41219
41759
|
status: 200,
|
|
41220
41760
|
body: await handleReportState(header, endpoint, deps.reportState, callerIdentity)
|
|
@@ -42771,7 +43311,13 @@ var DEFAULT_CONFIG = {
|
|
|
42771
43311
|
enforceIngressToken: false,
|
|
42772
43312
|
staleEndpointPurgeInput: ""
|
|
42773
43313
|
};
|
|
42774
|
-
|
|
43314
|
+
/** UI filter for the Export picker. `alarm-panel` publishes an
|
|
43315
|
+
* `Alexa.SecurityPanelController` endpoint (`endpoints/builder.ts`). */
|
|
43316
|
+
var SUPPORTED_KINDS = [
|
|
43317
|
+
"camera",
|
|
43318
|
+
"doorbell",
|
|
43319
|
+
DeviceType.AlarmPanel
|
|
43320
|
+
];
|
|
42775
43321
|
var ExportAlexaAddon = class extends BaseAddon {
|
|
42776
43322
|
lwaGateway = null;
|
|
42777
43323
|
syncEngine = null;
|
|
@@ -42840,6 +43386,10 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
42840
43386
|
reportState: {
|
|
42841
43387
|
ctx: this.ctx,
|
|
42842
43388
|
logger: this.ctx.logger
|
|
43389
|
+
},
|
|
43390
|
+
securityPanel: {
|
|
43391
|
+
ctx: this.ctx,
|
|
43392
|
+
logger: this.ctx.logger
|
|
42843
43393
|
}
|
|
42844
43394
|
},
|
|
42845
43395
|
lwaTokensCallbackDeps: {
|