@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
|
@@ -5346,7 +5346,7 @@ var ZodIssueCode = {
|
|
|
5346
5346
|
var ZodFirstPartyTypeKind;
|
|
5347
5347
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5348
5348
|
//#endregion
|
|
5349
|
-
//#region ../types/dist/sleep-
|
|
5349
|
+
//#region ../types/dist/sleep-DBKu2-U5.mjs
|
|
5350
5350
|
/**
|
|
5351
5351
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5352
5352
|
* window to float samples (D455).
|
|
@@ -7488,7 +7488,23 @@ var EncodeProfileSchema = object({
|
|
|
7488
7488
|
"zerolatency",
|
|
7489
7489
|
"film",
|
|
7490
7490
|
"animation"
|
|
7491
|
-
]).optional()
|
|
7491
|
+
]).optional(),
|
|
7492
|
+
/**
|
|
7493
|
+
* ONE slice per access unit.
|
|
7494
|
+
*
|
|
7495
|
+
* `-tune zerolatency` turns on x264's sliced threads, and a frame then leaves
|
|
7496
|
+
* the encoder as five NAL slices that share one RTP timestamp and carry one
|
|
7497
|
+
* marker bit. A libwebrtc depacketiser sees five frame-starts and one
|
|
7498
|
+
* frame-end per frame: the first pictures render and the video then freezes
|
|
7499
|
+
* for good while the audio, on its own plane, plays on. Measured on this hub
|
|
7500
|
+
* 2026-09-13 against the Echo, and reduced to one slice by this flag alone.
|
|
7501
|
+
*
|
|
7502
|
+
* A NAMED field and not a raw flag, because {@link EgressEncodeSchema} omits
|
|
7503
|
+
* `outputArgs` on purpose: an opaque array is part of the sharing key, so two
|
|
7504
|
+
* consumers meaning the same thing spelled differently would stop sharing one
|
|
7505
|
+
* child. Absent means "whatever the encoder does" — today's behaviour.
|
|
7506
|
+
*/
|
|
7507
|
+
singleSlicePerFrame: boolean().optional()
|
|
7492
7508
|
}),
|
|
7493
7509
|
audio: union([literal("passthrough"), object({
|
|
7494
7510
|
codec: _enum([
|
|
@@ -7563,7 +7579,11 @@ var BASE_LIVE_EGRESS_PROFILE = {
|
|
|
7563
7579
|
*/
|
|
7564
7580
|
var ALEXA_EGRESS_PROFILE = {
|
|
7565
7581
|
...BASE_LIVE_EGRESS_PROFILE,
|
|
7566
|
-
audio: { codec: "opus" }
|
|
7582
|
+
audio: { codec: "opus" },
|
|
7583
|
+
video: {
|
|
7584
|
+
...BASE_LIVE_EGRESS_PROFILE.video,
|
|
7585
|
+
singleSlicePerFrame: true
|
|
7586
|
+
}
|
|
7567
7587
|
};
|
|
7568
7588
|
/**
|
|
7569
7589
|
* Deep wiring healthcheck — snapshot of active reachability probes across
|
|
@@ -16451,7 +16471,7 @@ var AlarmArmModeSchema = _enum([
|
|
|
16451
16471
|
"vacation",
|
|
16452
16472
|
"custom_bypass"
|
|
16453
16473
|
]);
|
|
16454
|
-
object({
|
|
16474
|
+
var AlarmPanelStatusSchema = object({
|
|
16455
16475
|
/** Current lifecycle state. */
|
|
16456
16476
|
state: AlarmStateSchema,
|
|
16457
16477
|
/** Subset of arm modes the panel accepts. UI renders one button per
|
|
@@ -20044,13 +20064,109 @@ var SummariesQueryInput = object({
|
|
|
20044
20064
|
deviceIds: array(number()).min(1),
|
|
20045
20065
|
since: number().optional(),
|
|
20046
20066
|
until: number().optional(),
|
|
20047
|
-
limit: number().int().min(1).max(200).default(50)
|
|
20067
|
+
limit: number().int().min(1).max(200).default(50),
|
|
20068
|
+
/** The same member-wise filter {@link listRecentSummaries} takes — one
|
|
20069
|
+
* meaning of "dog" on every summary surface. */
|
|
20070
|
+
classes: array(string().min(1).max(60)).max(40).optional()
|
|
20048
20071
|
});
|
|
20049
|
-
var SummariesPageSchema = object({ summaries: array(SummarySchema).readonly() });
|
|
20050
20072
|
var SummaryDetailSchema = object({
|
|
20051
20073
|
summary: SummarySchema,
|
|
20052
|
-
/**
|
|
20053
|
-
|
|
20074
|
+
/** Members in absorption order, oldest join first. */
|
|
20075
|
+
members: array(object({
|
|
20076
|
+
trackId: string(),
|
|
20077
|
+
/**
|
|
20078
|
+
* The track's class at the time it JOINED, or `null` when it was unresolved
|
|
20079
|
+
* and the track no longer exists to fill it.
|
|
20080
|
+
*
|
|
20081
|
+
* The join, not the latest opinion: class voting can re-decide a track's
|
|
20082
|
+
* class afterwards, and a group's composition is the history of who came
|
|
20083
|
+
* together. A consumer counts these to badge a thumbnail — "two people and a
|
|
20084
|
+
* dog" — rather than being handed a second, denormalised tally that would
|
|
20085
|
+
* drift from the members it claims to describe.
|
|
20086
|
+
*/
|
|
20087
|
+
className: string().nullable(),
|
|
20088
|
+
/** `primary` is the one member that carries the group's identity. */
|
|
20089
|
+
role: _enum([
|
|
20090
|
+
"primary",
|
|
20091
|
+
"sibling",
|
|
20092
|
+
"child"
|
|
20093
|
+
]).nullable(),
|
|
20094
|
+
joinedAt: number(),
|
|
20095
|
+
/** Tier 1 — the sub-class (`dog`, `van`), resolved from the member's track
|
|
20096
|
+
* at read time. Absent when nothing resolved, never an empty string. */
|
|
20097
|
+
label: string().optional(),
|
|
20098
|
+
/** Tier 2 — the instance: a person's name, a plate. Absent when the pipeline
|
|
20099
|
+
* recognised nobody, and absent for a member whose track has been pruned —
|
|
20100
|
+
* a thumbnail that names the wrong person is worse than one naming nobody. */
|
|
20101
|
+
subLabel: string().optional()
|
|
20102
|
+
})).readonly()
|
|
20103
|
+
});
|
|
20104
|
+
/**
|
|
20105
|
+
* What a LIST of groups carries: the envelope plus what it is MADE OF.
|
|
20106
|
+
*
|
|
20107
|
+
* Coarse on purpose — the operator's rule is "only the rough data on the list,
|
|
20108
|
+
* we extend when we notice we need more". Enough to draw the card ("two people
|
|
20109
|
+
* and a dog") and no more. The MEMBERS, their names and the per-member links
|
|
20110
|
+
* are on {@link getSummary}: shipping every member of every group so a client
|
|
20111
|
+
* can count them turns a page of two hundred groups into a thousand records to
|
|
20112
|
+
* draw two hundred badges.
|
|
20113
|
+
*/
|
|
20114
|
+
var SummaryListItemSchema = object({
|
|
20115
|
+
summary: SummarySchema,
|
|
20116
|
+
/** Class counts, most numerous first; `className: null` is a member whose
|
|
20117
|
+
* class never resolved, counted so the counts add up to `memberCount`. */
|
|
20118
|
+
classes: array(object({
|
|
20119
|
+
className: string().nullable(),
|
|
20120
|
+
count: number().int().positive()
|
|
20121
|
+
})).readonly()
|
|
20122
|
+
});
|
|
20123
|
+
var SummariesPageSchema = object({ summaries: array(SummaryListItemSchema).readonly() });
|
|
20124
|
+
/**
|
|
20125
|
+
* The paged feed, deliberately the SAME shape as {@link RecentTracksQueryInput}.
|
|
20126
|
+
*
|
|
20127
|
+
* The reel on the cameras page and the Events gallery both ride a cursor, so a
|
|
20128
|
+
* summaries feed that could only answer "the last N for these cameras"
|
|
20129
|
+
* (`listSummaries`) would make groups available in the timeline and nowhere
|
|
20130
|
+
* else. Two feeds with different ordering contracts would be two ideas of what
|
|
20131
|
+
* "newest" means, on one screen.
|
|
20132
|
+
*/
|
|
20133
|
+
var RecentSummariesQueryInput = object({
|
|
20134
|
+
/** Devices to merge. An empty array yields an empty page. */
|
|
20135
|
+
deviceIds: array(number()),
|
|
20136
|
+
/** Window lower bound on `lastActiveAt` (inclusive). */
|
|
20137
|
+
since: number().optional(),
|
|
20138
|
+
/** Window upper bound on `lastActiveAt` (inclusive). */
|
|
20139
|
+
until: number().optional(),
|
|
20140
|
+
limit: number().int().min(1).max(500).default(100),
|
|
20141
|
+
/** Opaque continuation cursor from a previous page's `nextCursor`. */
|
|
20142
|
+
cursor: string().optional(),
|
|
20143
|
+
/**
|
|
20144
|
+
* Restrict to these classes — THE SAME FIELD `listRecentTracks` takes, and
|
|
20145
|
+
* deliberately the same name: the events filter tree emits one list of ticked
|
|
20146
|
+
* taxonomy nodes, and a summaries feed that called it something else would
|
|
20147
|
+
* make the operator's one filter component produce two shapes.
|
|
20148
|
+
*
|
|
20149
|
+
* A question about the MEMBERS: a group matches when ANY of them does. "Show
|
|
20150
|
+
* me the arrivals with a dog" has to return the group of four people who had
|
|
20151
|
+
* one with them; a filter on the group's own fields could only ever answer
|
|
20152
|
+
* about its primary.
|
|
20153
|
+
*
|
|
20154
|
+
* Matched against all THREE tiers of a member — the class (`animal`), the
|
|
20155
|
+
* sub-class (`dog`) and the instance (a name, a plate) — because which tier a
|
|
20156
|
+
* ticked node lives on is the taxonomy's business, not the caller's. `dog` is
|
|
20157
|
+
* an event kind in the tree and a tier-1 label on an `animal` track; a filter
|
|
20158
|
+
* that read only the class would answer "animal" and never "dog".
|
|
20159
|
+
*
|
|
20160
|
+
* ABSENT or EMPTY means no filter — absent is not a selection of none.
|
|
20161
|
+
*/
|
|
20162
|
+
classes: array(string().min(1).max(60)).max(40).optional()
|
|
20163
|
+
});
|
|
20164
|
+
var RecentSummariesPageSchema = object({
|
|
20165
|
+
/** Ordered by (`lastActiveAt` DESC, id DESC). Same light item as
|
|
20166
|
+
* {@link listSummaries} — one list shape, so a card renders the same
|
|
20167
|
+
* whichever feed drew it. */
|
|
20168
|
+
summaries: array(SummaryListItemSchema).readonly(),
|
|
20169
|
+
nextCursor: string().nullable()
|
|
20054
20170
|
});
|
|
20055
20171
|
var RecentTracksPageSchema = object({
|
|
20056
20172
|
/** Merged page, ordered by (`lastSeen` DESC, `trackId` DESC). */
|
|
@@ -20464,7 +20580,7 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
|
|
|
20464
20580
|
classes: array(string()).optional(),
|
|
20465
20581
|
/** See {@link ExcludeSourcesDoc}. */
|
|
20466
20582
|
excludeSources: array(TrackSourceSchema).optional()
|
|
20467
|
-
}), array(TrackSchema).readonly()), method(RecentTracksQueryInput, RecentTracksPageSchema), method(SummariesQueryInput, SummariesPageSchema), method(object({ id: string() }), SummaryDetailSchema.nullable()), method(object({ deviceId: number() }), _void(), {
|
|
20583
|
+
}), array(TrackSchema).readonly()), method(RecentTracksQueryInput, RecentTracksPageSchema), method(SummariesQueryInput, SummariesPageSchema), method(RecentSummariesQueryInput, RecentSummariesPageSchema), method(object({ id: string() }), SummaryDetailSchema.nullable()), method(object({ deviceId: number() }), _void(), {
|
|
20468
20584
|
kind: "mutation",
|
|
20469
20585
|
auth: "admin"
|
|
20470
20586
|
}), 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({
|
|
@@ -30070,7 +30186,29 @@ var LoggingSettingsPatchSchema = object({
|
|
|
30070
30186
|
* disarmed the channels it did not mention would make the Levels page and
|
|
30071
30187
|
* the Diagnostics page fight over the same value.
|
|
30072
30188
|
*/
|
|
30073
|
-
channels: array(LogChannelWindowPatchSchema).readonly().optional()
|
|
30189
|
+
channels: array(LogChannelWindowPatchSchema).readonly().optional(),
|
|
30190
|
+
/**
|
|
30191
|
+
* How many days the analytics OPS LOG is kept — the audit trail of what
|
|
30192
|
+
* retention actually deleted.
|
|
30193
|
+
*
|
|
30194
|
+
* It lives HERE, on the logging document, and not on the analytics addon's
|
|
30195
|
+
* settings form, on the operator's instruction: every other log-ish window in
|
|
30196
|
+
* this system is configured through this one document, and a retention audit
|
|
30197
|
+
* configured somewhere else is a second place to look when the question is
|
|
30198
|
+
* "what happened to my data".
|
|
30199
|
+
*
|
|
30200
|
+
* That placement has a cost worth stating: this document ships in the
|
|
30201
|
+
* framework closure, so this knob needs a published `@camstack/server` while
|
|
30202
|
+
* the four windows beside it (D485) reach a node on `camstack deploy`.
|
|
30203
|
+
*
|
|
30204
|
+
* `retention-model.ts` argued this one must NOT follow a device window,
|
|
30205
|
+
* because the audit trail is the history of the SWEEP and not of the camera.
|
|
30206
|
+
* That argument stands and is untouched — what changes is that 30 days stops
|
|
30207
|
+
* being a constant nobody can reach. `0` keeps it forever. The floor is 1 day
|
|
30208
|
+
* rather than 0-as-delete: an audit log truncated to nothing is precisely the
|
|
30209
|
+
* state in which the next 9.5 GiB leak cannot be explained.
|
|
30210
|
+
*/
|
|
30211
|
+
opsLogRetentionDays: number().int().min(0).max(3650).optional()
|
|
30074
30212
|
});
|
|
30075
30213
|
/**
|
|
30076
30214
|
* Which LAYER of the hierarchy is addressed. Absent = the cluster layer.
|
|
@@ -30143,6 +30281,14 @@ var LoggingSettingsStateSchema = object({
|
|
|
30143
30281
|
channels: array(LogChannelDescriptorSchema).readonly(),
|
|
30144
30282
|
/** The channels ARMED right now, each with its deadline. */
|
|
30145
30283
|
activeChannels: array(LogChannelWindowStateSchema).readonly(),
|
|
30284
|
+
/**
|
|
30285
|
+
* The ops-log window in days, as it is in force. `0` = kept forever.
|
|
30286
|
+
*
|
|
30287
|
+
* Reported rather than left to the caller's memory of what it wrote: this is
|
|
30288
|
+
* the value the analytics sweep will actually use, and an operator asking how
|
|
30289
|
+
* long their audit trail lives should not have to infer it from a default.
|
|
30290
|
+
*/
|
|
30291
|
+
opsLogRetentionDays: number().int().min(0),
|
|
30146
30292
|
persisted: boolean()
|
|
30147
30293
|
});
|
|
30148
30294
|
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(), {
|
|
@@ -34302,6 +34448,12 @@ Object.freeze({
|
|
|
34302
34448
|
addonId: null,
|
|
34303
34449
|
access: "view"
|
|
34304
34450
|
},
|
|
34451
|
+
"pipelineAnalytics.listRecentSummaries": {
|
|
34452
|
+
capName: "pipeline-analytics",
|
|
34453
|
+
capScope: "device",
|
|
34454
|
+
addonId: null,
|
|
34455
|
+
access: "view"
|
|
34456
|
+
},
|
|
34305
34457
|
"pipelineAnalytics.listRecentTracks": {
|
|
34306
34458
|
capName: "pipeline-analytics",
|
|
34307
34459
|
capScope: "device",
|
|
@@ -38129,6 +38281,11 @@ Object.freeze({
|
|
|
38129
38281
|
form: "single",
|
|
38130
38282
|
optional: true
|
|
38131
38283
|
}],
|
|
38284
|
+
"pipelineAnalytics.listRecentSummaries": [{
|
|
38285
|
+
name: "deviceIds",
|
|
38286
|
+
form: "array",
|
|
38287
|
+
optional: false
|
|
38288
|
+
}],
|
|
38132
38289
|
"pipelineAnalytics.listRecentTracks": [{
|
|
38133
38290
|
name: "deviceIds",
|
|
38134
38291
|
form: "array",
|
|
@@ -39602,66 +39759,65 @@ async function releaseAlexaEgress(input) {
|
|
|
39602
39759
|
}
|
|
39603
39760
|
}
|
|
39604
39761
|
//#endregion
|
|
39605
|
-
//#region src/handlers/
|
|
39762
|
+
//#region src/handlers/security-panel-arm-state.ts
|
|
39606
39763
|
/**
|
|
39607
|
-
*
|
|
39608
|
-
*
|
|
39609
|
-
*
|
|
39610
|
-
*
|
|
39764
|
+
* The panel modes behind each Alexa arm state, PRIMARY first — the mirror of
|
|
39765
|
+
* `MODES_BY_TARGET` in the HomeKit exporter, and for the same reason: one
|
|
39766
|
+
* Alexa state stands for two panel modes, so a panel offering only the
|
|
39767
|
+
* secondary would otherwise be sent a mode it refuses.
|
|
39768
|
+
*/
|
|
39769
|
+
var MODES_BY_ARM_STATE = {
|
|
39770
|
+
ARMED_STAY: ["home", "custom_bypass"],
|
|
39771
|
+
ARMED_AWAY: ["away", "vacation"],
|
|
39772
|
+
ARMED_NIGHT: ["night"]
|
|
39773
|
+
};
|
|
39774
|
+
var ARM_STATES = [
|
|
39775
|
+
"ARMED_STAY",
|
|
39776
|
+
"ARMED_AWAY",
|
|
39777
|
+
"ARMED_NIGHT"
|
|
39778
|
+
];
|
|
39779
|
+
/** The panel's state as Alexa's `armState` property. */
|
|
39780
|
+
function alexaArmStateFor(state) {
|
|
39781
|
+
switch (state) {
|
|
39782
|
+
case "armed_home":
|
|
39783
|
+
case "armed_custom_bypass": return "ARMED_STAY";
|
|
39784
|
+
case "armed_night": return "ARMED_NIGHT";
|
|
39785
|
+
case "armed_away":
|
|
39786
|
+
case "armed_vacation":
|
|
39787
|
+
case "pending":
|
|
39788
|
+
case "triggered": return "ARMED_AWAY";
|
|
39789
|
+
default: return "DISARMED";
|
|
39790
|
+
}
|
|
39791
|
+
}
|
|
39792
|
+
/** `burglaryAlarm`, the only alarm property this cap can honestly fill. */
|
|
39793
|
+
function burglaryAlarmFor(state) {
|
|
39794
|
+
return { value: state === "triggered" ? "ALARM" : "OK" };
|
|
39795
|
+
}
|
|
39796
|
+
/**
|
|
39797
|
+
* The `supportedArmStates` for discovery.
|
|
39611
39798
|
*
|
|
39612
|
-
*
|
|
39799
|
+
* `DISARMED` is always present: disarming is not one of the panel's arm modes.
|
|
39800
|
+
* An EMPTY `availableModes` is unknown, not "none" — a provider that never
|
|
39801
|
+
* populated the list looks identical to one that accepts nothing, and
|
|
39802
|
+
* publishing a panel that can only be disarmed on that guess takes the
|
|
39803
|
+
* controls off a working alarm. The caller logs it.
|
|
39613
39804
|
*/
|
|
39614
|
-
|
|
39615
|
-
|
|
39616
|
-
|
|
39617
|
-
|
|
39618
|
-
|
|
39619
|
-
|
|
39620
|
-
|
|
39621
|
-
|
|
39622
|
-
|
|
39623
|
-
|
|
39624
|
-
|
|
39625
|
-
|
|
39626
|
-
|
|
39627
|
-
|
|
39628
|
-
|
|
39629
|
-
|
|
39630
|
-
scope: BearerScopeSchema.optional(),
|
|
39631
|
-
cookie: record(string(), string()).optional()
|
|
39632
|
-
});
|
|
39633
|
-
var DiscoveryDirectiveSchema = object({
|
|
39634
|
-
header: DirectiveHeaderSchema.extend({
|
|
39635
|
-
namespace: literal("Alexa.Discovery"),
|
|
39636
|
-
name: literal("Discover")
|
|
39637
|
-
}),
|
|
39638
|
-
payload: object({ scope: BearerScopeSchema })
|
|
39639
|
-
});
|
|
39640
|
-
/** Envelope wrapping a directive on the Alexa→skill wire. */
|
|
39641
|
-
var DirectiveRequestSchema = object({ directive: object({
|
|
39642
|
-
header: DirectiveHeaderSchema,
|
|
39643
|
-
endpoint: EndpointRefSchema.optional(),
|
|
39644
|
-
payload: unknown().optional()
|
|
39645
|
-
}) });
|
|
39646
|
-
var InitializeCameraStreamsPayloadSchema = object({ cameraStreams: array(object({
|
|
39647
|
-
protocol: string(),
|
|
39648
|
-
resolution: object({
|
|
39649
|
-
width: number(),
|
|
39650
|
-
height: number()
|
|
39651
|
-
}).optional(),
|
|
39652
|
-
authorizationType: string().optional(),
|
|
39653
|
-
videoCodec: string().optional(),
|
|
39654
|
-
audioCodec: string().optional()
|
|
39655
|
-
})).optional() });
|
|
39656
|
-
var InitiateSessionWithOfferPayloadSchema = object({
|
|
39657
|
-
sessionId: string(),
|
|
39658
|
-
offer: object({
|
|
39659
|
-
format: string().optional(),
|
|
39660
|
-
value: string()
|
|
39661
|
-
})
|
|
39662
|
-
});
|
|
39663
|
-
var SessionDisconnectedPayloadSchema = object({ sessionId: string() });
|
|
39664
|
-
var SetModePayloadSchema = object({ mode: string() });
|
|
39805
|
+
function supportedArmStatesFor(availableModes) {
|
|
39806
|
+
return [...availableModes.length === 0 ? ARM_STATES : ARM_STATES.filter((armState) => MODES_BY_ARM_STATE[armState].some((mode) => availableModes.includes(mode))), "DISARMED"];
|
|
39807
|
+
}
|
|
39808
|
+
/**
|
|
39809
|
+
* The arm mode to send for an Alexa arm state, or `null` when there is none.
|
|
39810
|
+
*
|
|
39811
|
+
* `null` is not a shrug: `DISARMED` is the Disarm DIRECTIVE, a different call,
|
|
39812
|
+
* and an arm state the panel accepts no mode for is a directive the handler
|
|
39813
|
+
* refuses with `NOT_READY_FOR_ARM` rather than translating into a guess.
|
|
39814
|
+
*/
|
|
39815
|
+
function alarmArmModeForAlexa(armState, availableModes) {
|
|
39816
|
+
if (armState === "DISARMED") return null;
|
|
39817
|
+
const candidates = MODES_BY_ARM_STATE[armState];
|
|
39818
|
+
if (availableModes.length === 0) return candidates[0] ?? null;
|
|
39819
|
+
return candidates.find((mode) => availableModes.includes(mode)) ?? null;
|
|
39820
|
+
}
|
|
39665
39821
|
//#endregion
|
|
39666
39822
|
//#region src/endpoints/builder.ts
|
|
39667
39823
|
var DEFAULT_RESOLUTIONS = [{
|
|
@@ -39985,6 +40141,53 @@ function buildPrivacyEndpoint(input) {
|
|
|
39985
40141
|
}
|
|
39986
40142
|
};
|
|
39987
40143
|
}
|
|
40144
|
+
/**
|
|
40145
|
+
* An `alarm-panel` device as an `Alexa.SecurityPanelController` endpoint.
|
|
40146
|
+
*
|
|
40147
|
+
* It is its OWN endpoint, not a child of a camera: a panel is a standalone
|
|
40148
|
+
* device and has no stream, no doorbell and no PTZ. The `__alarm` suffix on
|
|
40149
|
+
* the endpoint id is a routing tag (see `handlers/endpoint-id.ts`).
|
|
40150
|
+
*
|
|
40151
|
+
* ## What is declared, and what is deliberately not
|
|
40152
|
+
*
|
|
40153
|
+
* - `armState` and `burglaryAlarm` are the two properties this cap can fill
|
|
40154
|
+
* honestly. `fireAlarm` / `carbonMonoxideAlarm` / `waterAlarm` are NOT
|
|
40155
|
+
* declared: `alarm-panel` has no field saying WHICH alarm is sounding, and
|
|
40156
|
+
* declaring a property we would always answer `OK` on is a claim with no
|
|
40157
|
+
* basis behind it. The reasoning is in `security-panel-arm-state.ts`.
|
|
40158
|
+
* - `proactivelyReported: false`. This addon's Event Gateway pushes
|
|
40159
|
+
* ChangeReports for camera motion only; a panel state change is not wired
|
|
40160
|
+
* to it, and promising a report nothing sends is how an endpoint ends up
|
|
40161
|
+
* looking broken. `retrievable: true` — `Alexa/ReportState` answers.
|
|
40162
|
+
* - `supportedAuthorizationTypes` appears only for a panel that requires a
|
|
40163
|
+
* code. Alexa's Disarm directive can carry a PIN; its **Arm directive
|
|
40164
|
+
* cannot**, which is why a PIN-gated arm is refused by the handler with
|
|
40165
|
+
* `AUTHORIZATION_REQUIRED` rather than attempted.
|
|
40166
|
+
*/
|
|
40167
|
+
function buildAlarmPanelEndpoint(input) {
|
|
40168
|
+
const configuration = { supportedArmStates: supportedArmStatesFor(input.availableModes).map((value) => ({ value })) };
|
|
40169
|
+
if (input.requiresCode) configuration.supportedAuthorizationTypes = [{ type: "FOUR_DIGIT_PIN" }];
|
|
40170
|
+
const securityPanelController = {
|
|
40171
|
+
type: "AlexaInterface",
|
|
40172
|
+
interface: "Alexa.SecurityPanelController",
|
|
40173
|
+
version: "3",
|
|
40174
|
+
properties: {
|
|
40175
|
+
supported: [{ name: "armState" }, { name: "burglaryAlarm" }],
|
|
40176
|
+
proactivelyReported: false,
|
|
40177
|
+
retrievable: true
|
|
40178
|
+
},
|
|
40179
|
+
configuration
|
|
40180
|
+
};
|
|
40181
|
+
return {
|
|
40182
|
+
endpointId: `${input.deviceId}__alarm`,
|
|
40183
|
+
manufacturerName: "camstack",
|
|
40184
|
+
description: "CamStack alarm panel",
|
|
40185
|
+
friendlyName: input.friendlyName.trim().length > 0 ? input.friendlyName.trim() : `Alarm ${input.deviceId}`,
|
|
40186
|
+
displayCategories: ["SECURITY_PANEL"],
|
|
40187
|
+
capabilities: [ALEXA_BASE_CAPABILITY, securityPanelController],
|
|
40188
|
+
cookie: { stableId: input.stableId }
|
|
40189
|
+
};
|
|
40190
|
+
}
|
|
39988
40191
|
//#endregion
|
|
39989
40192
|
//#region src/handlers/error-envelope.ts
|
|
39990
40193
|
/**
|
|
@@ -40020,20 +40223,68 @@ function errorEnvelope(header, type, message) {
|
|
|
40020
40223
|
} };
|
|
40021
40224
|
}
|
|
40022
40225
|
//#endregion
|
|
40023
|
-
//#region src/handlers/
|
|
40226
|
+
//#region src/handlers/types.ts
|
|
40024
40227
|
/**
|
|
40025
|
-
*
|
|
40026
|
-
*
|
|
40027
|
-
*
|
|
40028
|
-
*
|
|
40228
|
+
* Zod schemas for the subset of the Alexa Smart Home directive surface
|
|
40229
|
+
* that we actually parse hub-side. The Smart Home Skill API ships
|
|
40230
|
+
* thousands of optional fields per namespace — we only validate what
|
|
40231
|
+
* we read; everything else passes through as `unknown`.
|
|
40029
40232
|
*
|
|
40030
|
-
*
|
|
40031
|
-
* `DeviceInfo.features` + bound caps (from `device-manager.getBindings`)
|
|
40032
|
-
* and emit only the Alexa capabilities backed by something on our side.
|
|
40033
|
-
* Child accessories (siren/floodlight/PIR/…) become SEPARATE endpoints
|
|
40034
|
-
* with `endpointId = ${parent}__${child}` so directive handlers can
|
|
40035
|
-
* route to the right cap on the right device.
|
|
40233
|
+
* Reference: https://developer.amazon.com/en-US/docs/alexa/smarthome/smart-home-skill-api-message-reference.html
|
|
40036
40234
|
*/
|
|
40235
|
+
/** A directive header carries namespace + name + token + correlation id. */
|
|
40236
|
+
var DirectiveHeaderSchema = object({
|
|
40237
|
+
namespace: string(),
|
|
40238
|
+
name: string(),
|
|
40239
|
+
payloadVersion: string(),
|
|
40240
|
+
messageId: string(),
|
|
40241
|
+
correlationToken: string().optional()
|
|
40242
|
+
});
|
|
40243
|
+
/** Scope carries the bearer token Alexa minted via our OAuth provider. */
|
|
40244
|
+
var BearerScopeSchema = object({
|
|
40245
|
+
type: literal("BearerToken"),
|
|
40246
|
+
token: string()
|
|
40247
|
+
});
|
|
40248
|
+
/** Endpoint reference inside a directive payload. */
|
|
40249
|
+
var EndpointRefSchema = object({
|
|
40250
|
+
endpointId: string(),
|
|
40251
|
+
scope: BearerScopeSchema.optional(),
|
|
40252
|
+
cookie: record(string(), string()).optional()
|
|
40253
|
+
});
|
|
40254
|
+
var DiscoveryDirectiveSchema = object({
|
|
40255
|
+
header: DirectiveHeaderSchema.extend({
|
|
40256
|
+
namespace: literal("Alexa.Discovery"),
|
|
40257
|
+
name: literal("Discover")
|
|
40258
|
+
}),
|
|
40259
|
+
payload: object({ scope: BearerScopeSchema })
|
|
40260
|
+
});
|
|
40261
|
+
/** Envelope wrapping a directive on the Alexa→skill wire. */
|
|
40262
|
+
var DirectiveRequestSchema = object({ directive: object({
|
|
40263
|
+
header: DirectiveHeaderSchema,
|
|
40264
|
+
endpoint: EndpointRefSchema.optional(),
|
|
40265
|
+
payload: unknown().optional()
|
|
40266
|
+
}) });
|
|
40267
|
+
var InitializeCameraStreamsPayloadSchema = object({ cameraStreams: array(object({
|
|
40268
|
+
protocol: string(),
|
|
40269
|
+
resolution: object({
|
|
40270
|
+
width: number(),
|
|
40271
|
+
height: number()
|
|
40272
|
+
}).optional(),
|
|
40273
|
+
authorizationType: string().optional(),
|
|
40274
|
+
videoCodec: string().optional(),
|
|
40275
|
+
audioCodec: string().optional()
|
|
40276
|
+
})).optional() });
|
|
40277
|
+
var InitiateSessionWithOfferPayloadSchema = object({
|
|
40278
|
+
sessionId: string(),
|
|
40279
|
+
offer: object({
|
|
40280
|
+
format: string().optional(),
|
|
40281
|
+
value: string()
|
|
40282
|
+
})
|
|
40283
|
+
});
|
|
40284
|
+
var SessionDisconnectedPayloadSchema = object({ sessionId: string() });
|
|
40285
|
+
var SetModePayloadSchema = object({ mode: string() });
|
|
40286
|
+
//#endregion
|
|
40287
|
+
//#region src/handlers/discovery.ts
|
|
40037
40288
|
var discoveryPayloadSchema = DiscoveryDirectiveSchema.shape.payload;
|
|
40038
40289
|
/** Devices built at once in `handleDiscovery` — latency-bound tRPC reads, so
|
|
40039
40290
|
* six lanes hide the round-trips without stampeding a booting hub. */
|
|
@@ -40047,6 +40298,7 @@ var CAP_SWITCH = "switch";
|
|
|
40047
40298
|
var CAP_BRIGHTNESS = "brightness";
|
|
40048
40299
|
var CAP_BATTERY = "battery";
|
|
40049
40300
|
var CAP_PRIVACY_MASK = "privacy-mask";
|
|
40301
|
+
var CAP_ALARM_PANEL = "alarm-panel";
|
|
40050
40302
|
async function handleDiscovery(header, payloadRaw, deps, callerIdentity) {
|
|
40051
40303
|
if (!discoveryPayloadSchema.safeParse(payloadRaw).success) return errorEnvelope(header, "INVALID_DIRECTIVE", "Discovery payload shape unexpected");
|
|
40052
40304
|
const exposed = await deps.listExposed();
|
|
@@ -40086,6 +40338,7 @@ async function buildEndpointsForExposedDevice(deviceId, deps) {
|
|
|
40086
40338
|
return [];
|
|
40087
40339
|
}
|
|
40088
40340
|
const parentInfo = await loadBoundDeviceInfo(device, api);
|
|
40341
|
+
if (parentInfo.capNames.includes(CAP_ALARM_PANEL)) return [await buildAlarmPanelEndpointFor(parentInfo, api, deps)];
|
|
40089
40342
|
const children = await api.deviceManager.getChildren.query({ parentDeviceId: deviceId }).catch((err) => {
|
|
40090
40343
|
deps.logger.warn("alexa discovery: getChildren failed", {
|
|
40091
40344
|
tags: { deviceId },
|
|
@@ -40165,6 +40418,47 @@ async function buildEndpointsForExposedDevice(deviceId, deps) {
|
|
|
40165
40418
|
}
|
|
40166
40419
|
return out;
|
|
40167
40420
|
}
|
|
40421
|
+
/**
|
|
40422
|
+
* The panel endpoint, with what the panel says it accepts.
|
|
40423
|
+
*
|
|
40424
|
+
* A `getStatus` that fails leaves `availableModes` empty and `requiresCode`
|
|
40425
|
+
* false, and those are the UNKNOWN readings, not assertions: an empty mode
|
|
40426
|
+
* list makes discovery declare all three arm states (`supportedArmStatesFor`)
|
|
40427
|
+
* rather than publishing a panel that can only be disarmed, and the directive
|
|
40428
|
+
* handler re-reads the panel before it commands anything, so a PIN discovered
|
|
40429
|
+
* later is still honoured. The blind read is logged against the device id.
|
|
40430
|
+
*/
|
|
40431
|
+
async function buildAlarmPanelEndpointFor(info, api, deps) {
|
|
40432
|
+
const status = await api.alarmPanel.getStatus.query({ deviceId: info.id }).catch((err) => {
|
|
40433
|
+
deps.logger.warn("alexa discovery: alarmPanel.getStatus failed — declaring every arm state", {
|
|
40434
|
+
tags: { deviceId: info.id },
|
|
40435
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
40436
|
+
});
|
|
40437
|
+
return null;
|
|
40438
|
+
});
|
|
40439
|
+
const parsed = AlarmPanelStatusSchema.pick({
|
|
40440
|
+
availableModes: true,
|
|
40441
|
+
requiresCode: true
|
|
40442
|
+
}).safeParse(status);
|
|
40443
|
+
if (!parsed.success && status !== null) deps.logger.warn("alexa discovery: panel status did not match the cap schema", { tags: { deviceId: info.id } });
|
|
40444
|
+
const availableModes = parsed.success ? parsed.data.availableModes : [];
|
|
40445
|
+
const requiresCode = parsed.success ? parsed.data.requiresCode : false;
|
|
40446
|
+
deps.logger.info("alexa discovery: built alarm panel endpoint", {
|
|
40447
|
+
tags: { deviceId: info.id },
|
|
40448
|
+
meta: {
|
|
40449
|
+
name: info.name,
|
|
40450
|
+
availableModes: [...availableModes],
|
|
40451
|
+
requiresCode
|
|
40452
|
+
}
|
|
40453
|
+
});
|
|
40454
|
+
return buildAlarmPanelEndpoint({
|
|
40455
|
+
deviceId: info.id,
|
|
40456
|
+
stableId: info.stableId,
|
|
40457
|
+
friendlyName: info.name,
|
|
40458
|
+
availableModes,
|
|
40459
|
+
requiresCode
|
|
40460
|
+
});
|
|
40461
|
+
}
|
|
40168
40462
|
async function loadBoundDeviceInfo(device, api) {
|
|
40169
40463
|
const capNames = (await api.deviceManager.getBindings.query({ deviceId: device.id })).entries.map((e) => e.capName);
|
|
40170
40464
|
return {
|
|
@@ -40230,10 +40524,14 @@ function parseCameraEndpointId(raw) {
|
|
|
40230
40524
|
kind: "privacy",
|
|
40231
40525
|
parentDeviceId: parent
|
|
40232
40526
|
};
|
|
40527
|
+
if (tail === "alarm") return {
|
|
40528
|
+
kind: "alarm-panel",
|
|
40529
|
+
deviceId: parent
|
|
40530
|
+
};
|
|
40233
40531
|
const child = parseNonNegativeInt(tail);
|
|
40234
40532
|
if (child === null) return {
|
|
40235
40533
|
kind: "invalid",
|
|
40236
|
-
reason: `child segment not numeric and not 'autotrack'/'privacy': ${raw}`
|
|
40534
|
+
reason: `child segment not numeric and not 'autotrack'/'privacy'/'alarm': ${raw}`
|
|
40237
40535
|
};
|
|
40238
40536
|
return {
|
|
40239
40537
|
kind: "child",
|
|
@@ -40248,6 +40546,68 @@ function parseNonNegativeInt(s) {
|
|
|
40248
40546
|
return n;
|
|
40249
40547
|
}
|
|
40250
40548
|
//#endregion
|
|
40549
|
+
//#region src/handlers/brightness-controller.ts
|
|
40550
|
+
var SetBrightnessDirectiveSchema = object({
|
|
40551
|
+
header: object({
|
|
40552
|
+
namespace: literal("Alexa.BrightnessController"),
|
|
40553
|
+
name: literal("SetBrightness")
|
|
40554
|
+
}),
|
|
40555
|
+
endpoint: EndpointRefSchema,
|
|
40556
|
+
payload: object({ brightness: number().min(0).max(100) })
|
|
40557
|
+
});
|
|
40558
|
+
async function handleSetBrightness(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40559
|
+
const parsed = SetBrightnessDirectiveSchema.safeParse({
|
|
40560
|
+
header: {
|
|
40561
|
+
namespace: header.namespace,
|
|
40562
|
+
name: header.name
|
|
40563
|
+
},
|
|
40564
|
+
endpoint: endpointRaw,
|
|
40565
|
+
payload: payloadRaw ?? {}
|
|
40566
|
+
});
|
|
40567
|
+
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40568
|
+
const endpointId = parsed.data.endpoint.endpointId;
|
|
40569
|
+
const parsedId = parseCameraEndpointId(endpointId);
|
|
40570
|
+
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`);
|
|
40571
|
+
if (parsedId.kind === "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", "BrightnessController is not exposed on camera endpoints — direct the directive at the dimmable child accessory");
|
|
40572
|
+
if (parsedId.kind === "invalid") return errorEnvelope(header, "INVALID_DIRECTIVE", parsedId.reason);
|
|
40573
|
+
const percentage = parsed.data.payload.brightness;
|
|
40574
|
+
const api = deps.ctx.api;
|
|
40575
|
+
try {
|
|
40576
|
+
await api.brightness.setBrightness.mutate({
|
|
40577
|
+
deviceId: parsedId.childDeviceId,
|
|
40578
|
+
percentage
|
|
40579
|
+
});
|
|
40580
|
+
} catch (err) {
|
|
40581
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
40582
|
+
deps.logger.warn("alexa brightness-controller: setBrightness failed", { meta: {
|
|
40583
|
+
deviceId: parsedId.childDeviceId,
|
|
40584
|
+
percentage,
|
|
40585
|
+
error: message
|
|
40586
|
+
} });
|
|
40587
|
+
return errorEnvelope(header, "INTERNAL_ERROR", `brightness.setBrightness failed: ${message}`);
|
|
40588
|
+
}
|
|
40589
|
+
return {
|
|
40590
|
+
event: {
|
|
40591
|
+
header: {
|
|
40592
|
+
namespace: "Alexa",
|
|
40593
|
+
name: "Response",
|
|
40594
|
+
messageId: header.messageId,
|
|
40595
|
+
correlationToken: header.correlationToken,
|
|
40596
|
+
payloadVersion: "3"
|
|
40597
|
+
},
|
|
40598
|
+
endpoint: { endpointId },
|
|
40599
|
+
payload: {}
|
|
40600
|
+
},
|
|
40601
|
+
context: { properties: [{
|
|
40602
|
+
namespace: "Alexa.BrightnessController",
|
|
40603
|
+
name: "brightness",
|
|
40604
|
+
value: percentage,
|
|
40605
|
+
timeOfSample: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40606
|
+
uncertaintyInMilliseconds: 500
|
|
40607
|
+
}] }
|
|
40608
|
+
};
|
|
40609
|
+
}
|
|
40610
|
+
//#endregion
|
|
40251
40611
|
//#region src/handlers/camera-stream.ts
|
|
40252
40612
|
/**
|
|
40253
40613
|
* `Alexa.CameraStreamController/InitializeCameraStreams` handler.
|
|
@@ -40330,347 +40690,42 @@ async function handleInitializeCameraStreams(header, endpointRaw, payloadRaw, de
|
|
|
40330
40690
|
} };
|
|
40331
40691
|
}
|
|
40332
40692
|
//#endregion
|
|
40333
|
-
//#region src/handlers/
|
|
40334
|
-
var
|
|
40335
|
-
endpoint: EndpointRefSchema,
|
|
40336
|
-
payload: InitiateSessionWithOfferPayloadSchema
|
|
40337
|
-
});
|
|
40338
|
-
var SessionDisconnectedDirectiveSchema = object({
|
|
40339
|
-
endpoint: EndpointRefSchema,
|
|
40340
|
-
payload: SessionDisconnectedPayloadSchema
|
|
40341
|
-
});
|
|
40342
|
-
/**
|
|
40343
|
-
* Live egress handles, keyed by `<deviceId>/<sessionId>`.
|
|
40344
|
-
*
|
|
40345
|
-
* The primitive's refcount has no lease TTL: a holder that vanishes without
|
|
40346
|
-
* releasing leaks a child until the broker restarts (D67). This handler is a
|
|
40347
|
-
* holder, so it keeps the one piece of state that lets it not be that holder —
|
|
40348
|
-
* the `pipelineKey` its `SessionDisconnected` has to release.
|
|
40349
|
-
*
|
|
40350
|
-
* A module-level map is right here because the directive handlers are free
|
|
40351
|
-
* functions called per directive; the entry is written on a successful acquire
|
|
40352
|
-
* and deleted on the release path, both of which are the same tick as the
|
|
40353
|
-
* directive that owns it.
|
|
40354
|
-
*/
|
|
40355
|
-
var EGRESS_HANDLES = /* @__PURE__ */ new Map();
|
|
40356
|
-
function egressHandleKey(deviceId, sessionId) {
|
|
40357
|
-
return `${deviceId}/${sessionId}`;
|
|
40358
|
-
}
|
|
40359
|
-
var WEBRTC_PROFILE_NAMES = [
|
|
40360
|
-
"high",
|
|
40361
|
-
"mid",
|
|
40362
|
-
"low"
|
|
40363
|
-
];
|
|
40364
|
-
function resolveWebrtcTarget(pref) {
|
|
40365
|
-
if (pref === "auto") return void 0;
|
|
40366
|
-
if (WEBRTC_PROFILE_NAMES.includes(pref)) return {
|
|
40367
|
-
kind: "profile",
|
|
40368
|
-
profile: pref
|
|
40369
|
-
};
|
|
40370
|
-
return {
|
|
40371
|
-
kind: "cam-stream",
|
|
40372
|
-
camStreamId: pref
|
|
40373
|
-
};
|
|
40374
|
-
}
|
|
40375
|
-
async function handleInitiateSessionWithOffer(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40376
|
-
const parsed = InitiateSessionWithOfferDirectiveSchema.safeParse({
|
|
40377
|
-
endpoint: endpointRaw,
|
|
40378
|
-
payload: payloadRaw ?? {}
|
|
40379
|
-
});
|
|
40380
|
-
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40381
|
-
const endpoint = parsed.data.endpoint;
|
|
40382
|
-
const payload = parsed.data.payload;
|
|
40383
|
-
const parsedId = parseCameraEndpointId(endpoint.endpointId);
|
|
40384
|
-
if (parsedId.kind !== "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", `endpointId ${endpoint.endpointId} is not a camera`);
|
|
40385
|
-
const deviceId = parsedId.deviceId;
|
|
40386
|
-
const sessionId = payload.sessionId;
|
|
40387
|
-
const log = deps.logger.withTags({
|
|
40388
|
-
deviceId,
|
|
40389
|
-
sessionId
|
|
40390
|
-
});
|
|
40391
|
-
const sdpOffer = payload.offer.value;
|
|
40392
|
-
if (sdpOffer.length === 0) return errorEnvelope(header, "INVALID_DIRECTIVE", "offer.value is empty");
|
|
40393
|
-
const api = deps.ctx.api;
|
|
40394
|
-
const exposedEntry = deps.listExposed().find((e) => e.deviceId === deviceId);
|
|
40395
|
-
const explicitSourceProfile = exposedEntry?.settings?.sourceProfile;
|
|
40396
|
-
const mappedFromPreference = (() => {
|
|
40397
|
-
const pref = exposedEntry?.settings?.streamPreference;
|
|
40398
|
-
if (pref === "low" || pref === "mid" || pref === "high") return pref;
|
|
40399
|
-
})();
|
|
40400
|
-
const sourceProfile = explicitSourceProfile ?? mappedFromPreference ?? "high";
|
|
40401
|
-
let derivedTarget;
|
|
40402
|
-
/**
|
|
40403
|
-
* The primitive's release handle, when this session acquired one. Recorded so
|
|
40404
|
-
* `SessionDisconnected` can release it: a refcount whose holder disappears is
|
|
40405
|
-
* the one gap D67 leaves open, and the least this handler can do is not BE
|
|
40406
|
-
* that holder.
|
|
40407
|
-
*/
|
|
40408
|
-
let egressPipelineKey = null;
|
|
40409
|
-
const picked = await api.cameraStreams.pickStream.query({
|
|
40410
|
-
deviceId,
|
|
40411
|
-
requirements: {
|
|
40412
|
-
acceptCodecs: ["h264"],
|
|
40413
|
-
minHeight: 480,
|
|
40414
|
-
excludeDerived: true,
|
|
40415
|
-
requireSiblingCodec: ["h265", "hevc"]
|
|
40416
|
-
}
|
|
40417
|
-
}).catch((err) => {
|
|
40418
|
-
log.warn("alexa rtc-session: cameraStreams.pickStream threw — falling back to transcode", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
40419
|
-
return null;
|
|
40420
|
-
});
|
|
40421
|
-
if (picked) {
|
|
40422
|
-
log.info("alexa rtc-session: bypassing transcode via cameraStreams.pickStream", { meta: {
|
|
40423
|
-
sourceProfile,
|
|
40424
|
-
selectedCamStreamId: picked.camStreamId,
|
|
40425
|
-
reason: picked.reason
|
|
40426
|
-
} });
|
|
40427
|
-
derivedTarget = {
|
|
40428
|
-
kind: "cam-stream",
|
|
40429
|
-
camStreamId: picked.camStreamId
|
|
40430
|
-
};
|
|
40431
|
-
} else try {
|
|
40432
|
-
const acquired = await acquireAlexaEgress({
|
|
40433
|
-
api,
|
|
40434
|
-
deviceId,
|
|
40435
|
-
sourceProfile,
|
|
40436
|
-
sessionId,
|
|
40437
|
-
logger: log
|
|
40438
|
-
});
|
|
40439
|
-
egressPipelineKey = acquired.pipelineKey;
|
|
40440
|
-
EGRESS_HANDLES.set(egressHandleKey(deviceId, sessionId), acquired.pipelineKey);
|
|
40441
|
-
derivedTarget = {
|
|
40442
|
-
kind: "cam-stream",
|
|
40443
|
-
camStreamId: acquired.camStreamId
|
|
40444
|
-
};
|
|
40445
|
-
} catch (err) {
|
|
40446
|
-
log.warn("alexa rtc-session: egress acquire failed, falling back to streamPreference target", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
40447
|
-
derivedTarget = resolveWebrtcTarget(exposedEntry?.settings?.streamPreference ?? "auto");
|
|
40448
|
-
}
|
|
40449
|
-
try {
|
|
40450
|
-
const result = await api.webrtcSession.handleOffer.mutate({
|
|
40451
|
-
deviceId,
|
|
40452
|
-
sdpOffer,
|
|
40453
|
-
sessionId,
|
|
40454
|
-
target: derivedTarget,
|
|
40455
|
-
relayOnly: false,
|
|
40456
|
-
nonTrickle: true,
|
|
40457
|
-
disableTurn: true,
|
|
40458
|
-
disableIpv6: true,
|
|
40459
|
-
consumerAttribution: {
|
|
40460
|
-
kind: "alexa",
|
|
40461
|
-
sessionId
|
|
40462
|
-
}
|
|
40463
|
-
});
|
|
40464
|
-
log.info("alexa rtc-session: AnswerGenerated", { meta: {
|
|
40465
|
-
returnedSessionId: result.sessionId,
|
|
40466
|
-
sdpAnswerLen: result.sdpAnswer.length
|
|
40467
|
-
} });
|
|
40468
|
-
return { event: {
|
|
40469
|
-
header: {
|
|
40470
|
-
namespace: "Alexa.RTCSessionController",
|
|
40471
|
-
name: "AnswerGeneratedForSession",
|
|
40472
|
-
messageId: header.messageId,
|
|
40473
|
-
correlationToken: header.correlationToken,
|
|
40474
|
-
payloadVersion: "3"
|
|
40475
|
-
},
|
|
40476
|
-
endpoint: { endpointId: endpoint.endpointId },
|
|
40477
|
-
payload: { answer: {
|
|
40478
|
-
format: payload.offer.format ?? "SDP",
|
|
40479
|
-
value: result.sdpAnswer
|
|
40480
|
-
} }
|
|
40481
|
-
} };
|
|
40482
|
-
} catch (err) {
|
|
40483
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
40484
|
-
const mSectionSummary = (() => {
|
|
40485
|
-
const lines = sdpOffer.split(/\r?\n/);
|
|
40486
|
-
const sections = [];
|
|
40487
|
-
let current = null;
|
|
40488
|
-
for (const raw of lines) {
|
|
40489
|
-
const line = raw.trim();
|
|
40490
|
-
if (line.startsWith("m=")) {
|
|
40491
|
-
if (current) sections.push(current);
|
|
40492
|
-
current = {
|
|
40493
|
-
mid: null,
|
|
40494
|
-
kind: line.split(" ")[0]?.slice(2) ?? "unknown",
|
|
40495
|
-
direction: null,
|
|
40496
|
-
codecs: []
|
|
40497
|
-
};
|
|
40498
|
-
} else if (current) {
|
|
40499
|
-
if (line.startsWith("a=mid:")) current.mid = line.slice(6);
|
|
40500
|
-
else if (/^a=(sendonly|recvonly|sendrecv|inactive)$/.test(line)) current.direction = line.slice(2);
|
|
40501
|
-
else if (line.startsWith("a=rtpmap:")) current.codecs.push(line.slice(9));
|
|
40502
|
-
}
|
|
40503
|
-
}
|
|
40504
|
-
if (current) sections.push(current);
|
|
40505
|
-
return sections;
|
|
40506
|
-
})();
|
|
40507
|
-
log.warn("alexa rtc-session: handleOffer failed", { meta: {
|
|
40508
|
-
error: message,
|
|
40509
|
-
offerLen: sdpOffer.length,
|
|
40510
|
-
mSections: mSectionSummary,
|
|
40511
|
-
offerSdp: sdpOffer
|
|
40512
|
-
} });
|
|
40513
|
-
if (egressPipelineKey !== null) {
|
|
40514
|
-
EGRESS_HANDLES.delete(egressHandleKey(deviceId, sessionId));
|
|
40515
|
-
await releaseAlexaEgress({
|
|
40516
|
-
api,
|
|
40517
|
-
deviceId,
|
|
40518
|
-
pipelineKey: egressPipelineKey,
|
|
40519
|
-
logger: log
|
|
40520
|
-
});
|
|
40521
|
-
}
|
|
40522
|
-
return errorEnvelope(header, "INTERNAL_ERROR", `webrtc-session.handleOffer failed: ${message}`);
|
|
40523
|
-
}
|
|
40524
|
-
}
|
|
40525
|
-
async function handleSessionDisconnected(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40526
|
-
const parsed = SessionDisconnectedDirectiveSchema.safeParse({
|
|
40527
|
-
endpoint: endpointRaw,
|
|
40528
|
-
payload: payloadRaw ?? {}
|
|
40529
|
-
});
|
|
40530
|
-
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40531
|
-
const endpoint = parsed.data.endpoint;
|
|
40532
|
-
const parsedId = parseCameraEndpointId(endpoint.endpointId);
|
|
40533
|
-
if (parsedId.kind === "camera") {
|
|
40534
|
-
const handleKey = egressHandleKey(parsedId.deviceId, parsed.data.payload.sessionId);
|
|
40535
|
-
const pipelineKey = EGRESS_HANDLES.get(handleKey);
|
|
40536
|
-
if (pipelineKey !== void 0) {
|
|
40537
|
-
EGRESS_HANDLES.delete(handleKey);
|
|
40538
|
-
await releaseAlexaEgress({
|
|
40539
|
-
api: deps.ctx.api,
|
|
40540
|
-
deviceId: parsedId.deviceId,
|
|
40541
|
-
pipelineKey,
|
|
40542
|
-
logger: deps.logger
|
|
40543
|
-
});
|
|
40544
|
-
}
|
|
40545
|
-
try {
|
|
40546
|
-
await deps.ctx.api.webrtcSession.closeSession.mutate({
|
|
40547
|
-
deviceId: parsedId.deviceId,
|
|
40548
|
-
sessionId: parsed.data.payload.sessionId
|
|
40549
|
-
});
|
|
40550
|
-
} catch (err) {
|
|
40551
|
-
deps.logger.warn("alexa rtc-session: closeSession threw on disconnect (continuing to ack)", {
|
|
40552
|
-
tags: {
|
|
40553
|
-
deviceId: parsedId.deviceId,
|
|
40554
|
-
sessionId: parsed.data.payload.sessionId
|
|
40555
|
-
},
|
|
40556
|
-
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
40557
|
-
});
|
|
40558
|
-
}
|
|
40559
|
-
}
|
|
40560
|
-
const disconnectedDeviceId = parsedId.kind === "camera" ? parsedId.deviceId : void 0;
|
|
40561
|
-
deps.logger.info("alexa rtc-session: SessionDisconnected", {
|
|
40562
|
-
tags: {
|
|
40563
|
-
sessionId: parsed.data.payload.sessionId,
|
|
40564
|
-
...disconnectedDeviceId !== void 0 ? { deviceId: disconnectedDeviceId } : {}
|
|
40565
|
-
},
|
|
40566
|
-
meta: { endpointId: endpoint.endpointId }
|
|
40567
|
-
});
|
|
40568
|
-
return { event: {
|
|
40569
|
-
header: {
|
|
40570
|
-
namespace: "Alexa",
|
|
40571
|
-
name: "Response",
|
|
40572
|
-
messageId: header.messageId,
|
|
40573
|
-
correlationToken: header.correlationToken,
|
|
40574
|
-
payloadVersion: "3"
|
|
40575
|
-
},
|
|
40576
|
-
endpoint: { endpointId: endpoint.endpointId },
|
|
40577
|
-
payload: {}
|
|
40578
|
-
} };
|
|
40579
|
-
}
|
|
40580
|
-
//#endregion
|
|
40581
|
-
//#region src/handlers/ptz-preset.ts
|
|
40582
|
-
/**
|
|
40583
|
-
* `Alexa.ModeController/SetMode` handler — dispatches three PTZ instances:
|
|
40584
|
-
*
|
|
40585
|
-
* `ptz.preset` — preset-recall. Decodes the preset name from the mode
|
|
40586
|
-
* value and calls `ptz.goToPreset({deviceId, presetId})`.
|
|
40587
|
-
*
|
|
40588
|
-
* `ptz.pan` — momentary pan. `ptz.pan.left|right|center` issues a
|
|
40589
|
-
* continuousMove pulse stopped on a timer; the dropdown reverts to
|
|
40590
|
-
* `center` server-side so subsequent picks re-trigger the move.
|
|
40591
|
-
*
|
|
40592
|
-
* `ptz.tilt` — momentary tilt. Mirrors ptz.pan with up|down|center.
|
|
40593
|
-
*/
|
|
40594
|
-
var SetModeDirectiveSchema = object({
|
|
40693
|
+
//#region src/handlers/power-controller.ts
|
|
40694
|
+
var PowerDirectiveSchema = object({
|
|
40595
40695
|
header: object({
|
|
40596
|
-
namespace: literal("Alexa.
|
|
40597
|
-
name:
|
|
40598
|
-
instance: string().optional()
|
|
40696
|
+
namespace: literal("Alexa.PowerController"),
|
|
40697
|
+
name: _enum(["TurnOn", "TurnOff"])
|
|
40599
40698
|
}),
|
|
40600
|
-
endpoint: EndpointRefSchema
|
|
40601
|
-
payload: SetModePayloadSchema
|
|
40699
|
+
endpoint: EndpointRefSchema
|
|
40602
40700
|
});
|
|
40603
|
-
|
|
40604
|
-
|
|
40605
|
-
var PTZ_PAN_MOVES = {
|
|
40606
|
-
"ptz.pan.left": { pan: -1 },
|
|
40607
|
-
"ptz.pan.right": { pan: 1 },
|
|
40608
|
-
"ptz.pan.center": {}
|
|
40609
|
-
};
|
|
40610
|
-
var PTZ_TILT_MOVES = {
|
|
40611
|
-
"ptz.tilt.up": { tilt: 1 },
|
|
40612
|
-
"ptz.tilt.down": { tilt: -1 },
|
|
40613
|
-
"ptz.tilt.center": {}
|
|
40614
|
-
};
|
|
40615
|
-
async function handleSetMode(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40616
|
-
const parsed = SetModeDirectiveSchema.safeParse({
|
|
40701
|
+
async function handlePower(header, endpointRaw, deps, _callerIdentity) {
|
|
40702
|
+
const parsed = PowerDirectiveSchema.safeParse({
|
|
40617
40703
|
header: {
|
|
40618
40704
|
namespace: header.namespace,
|
|
40619
|
-
name: header.name
|
|
40620
|
-
instance: header.instance
|
|
40705
|
+
name: header.name
|
|
40621
40706
|
},
|
|
40622
|
-
endpoint: endpointRaw
|
|
40623
|
-
payload: payloadRaw ?? {}
|
|
40707
|
+
endpoint: endpointRaw
|
|
40624
40708
|
});
|
|
40625
40709
|
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40626
|
-
const instance = parsed.data.header.instance;
|
|
40627
|
-
if (instance !== "ptz.preset" && instance !== "ptz.pan" && instance !== "ptz.tilt") return errorEnvelope(header, "INVALID_DIRECTIVE", `ModeController instance not supported: ${instance ?? "(missing)"}`);
|
|
40628
40710
|
const endpointId = parsed.data.endpoint.endpointId;
|
|
40629
40711
|
const parsedId = parseCameraEndpointId(endpointId);
|
|
40630
|
-
|
|
40631
|
-
const mode = parsed.data.payload.mode;
|
|
40712
|
+
const on = parsed.data.header.name === "TurnOn";
|
|
40632
40713
|
const api = deps.ctx.api;
|
|
40633
|
-
if (
|
|
40634
|
-
|
|
40635
|
-
|
|
40636
|
-
if (Object.keys(move).length === 0) await api.ptz.stop.mutate({ deviceId: parsedId.deviceId }).catch((err) => {
|
|
40637
|
-
deps.logger.debug("alexa ptz-mode: stop (center) failed (non-fatal)", { meta: {
|
|
40638
|
-
deviceId: parsedId.deviceId,
|
|
40639
|
-
instance,
|
|
40640
|
-
error: err instanceof Error ? err.message : String(err)
|
|
40641
|
-
} });
|
|
40642
|
-
});
|
|
40643
|
-
else try {
|
|
40644
|
-
await api.ptz.continuousMove.mutate({
|
|
40645
|
-
deviceId: parsedId.deviceId,
|
|
40646
|
-
...move
|
|
40647
|
-
});
|
|
40648
|
-
setTimeout(() => {
|
|
40649
|
-
api.ptz.stop.mutate({ deviceId: parsedId.deviceId }).catch((err) => {
|
|
40650
|
-
deps.logger.debug("alexa ptz-mode: stop after pulse failed (non-fatal)", { meta: {
|
|
40651
|
-
deviceId: parsedId.deviceId,
|
|
40652
|
-
instance,
|
|
40653
|
-
error: err instanceof Error ? err.message : String(err)
|
|
40654
|
-
} });
|
|
40655
|
-
});
|
|
40656
|
-
}, PTZ_DIRECTION_PULSE_MS);
|
|
40657
|
-
} catch (err) {
|
|
40658
|
-
return errorEnvelope(header, "INTERNAL_ERROR", `ptz.continuousMove failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
40659
|
-
}
|
|
40660
|
-
return modeSuccessResponse(header, endpointId, instance, instance === "ptz.pan" ? "ptz.pan.center" : "ptz.tilt.center");
|
|
40661
|
-
}
|
|
40662
|
-
if (!mode.startsWith(PTZ_PRESET_MODE_PREFIX)) return errorEnvelope(header, "INVALID_DIRECTIVE", `mode '${mode}' is not a ptz.preset mode`);
|
|
40663
|
-
const presetName = mode.slice(11);
|
|
40664
|
-
if (presetName.length === 0) return errorEnvelope(header, "INVALID_DIRECTIVE", "preset name missing after prefix");
|
|
40665
|
-
const preset = (await api.ptz.getPresets.query({ deviceId: parsedId.deviceId })).find((p) => p.name === presetName);
|
|
40666
|
-
if (!preset) return errorEnvelope(header, "INVALID_DIRECTIVE", `preset '${presetName}' not found on device ${parsedId.deviceId}`);
|
|
40667
|
-
await api.ptz.goToPreset.mutate({
|
|
40668
|
-
deviceId: parsedId.deviceId,
|
|
40669
|
-
presetId: preset.id
|
|
40714
|
+
if (parsedId.kind === "autotrack") await api.ptzAutotrack.setEnabled.mutate({
|
|
40715
|
+
deviceId: parsedId.parentDeviceId,
|
|
40716
|
+
enabled: on
|
|
40670
40717
|
});
|
|
40671
|
-
|
|
40672
|
-
|
|
40673
|
-
|
|
40718
|
+
else if (parsedId.kind === "privacy") await api.privacyMask.setMask.mutate({
|
|
40719
|
+
deviceId: parsedId.parentDeviceId,
|
|
40720
|
+
patch: { enabled: on }
|
|
40721
|
+
});
|
|
40722
|
+
else if (parsedId.kind === "child") await api.switch.setState.mutate({
|
|
40723
|
+
deviceId: parsedId.childDeviceId,
|
|
40724
|
+
on
|
|
40725
|
+
});
|
|
40726
|
+
else if (parsedId.kind === "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", "PowerController is not exposed on camera endpoints — direct the directive at the child accessory");
|
|
40727
|
+
else if (parsedId.kind === "alarm-panel") return errorEnvelope(header, "INVALID_DIRECTIVE", "PowerController is not exposed on alarm-panel endpoints — use Alexa.SecurityPanelController");
|
|
40728
|
+
else return errorEnvelope(header, "INVALID_DIRECTIVE", parsedId.reason);
|
|
40674
40729
|
return {
|
|
40675
40730
|
event: {
|
|
40676
40731
|
header: {
|
|
@@ -40684,10 +40739,9 @@ function modeSuccessResponse(header, endpointId, instance, mode) {
|
|
|
40684
40739
|
payload: {}
|
|
40685
40740
|
},
|
|
40686
40741
|
context: { properties: [{
|
|
40687
|
-
namespace: "Alexa.
|
|
40688
|
-
|
|
40689
|
-
|
|
40690
|
-
value: mode,
|
|
40742
|
+
namespace: "Alexa.PowerController",
|
|
40743
|
+
name: "powerState",
|
|
40744
|
+
value: on ? "ON" : "OFF",
|
|
40691
40745
|
timeOfSample: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40692
40746
|
uncertaintyInMilliseconds: 500
|
|
40693
40747
|
}] }
|
|
@@ -40787,133 +40841,99 @@ function successResponse(header, endpointId, toggleState, instance) {
|
|
|
40787
40841
|
};
|
|
40788
40842
|
}
|
|
40789
40843
|
//#endregion
|
|
40790
|
-
//#region src/handlers/
|
|
40791
|
-
/**
|
|
40792
|
-
* `Alexa.PowerController/{TurnOn,TurnOff}` handler.
|
|
40793
|
-
*
|
|
40794
|
-
* Routing decodes the endpoint id:
|
|
40795
|
-
* - `${parent}__${child}` → call `switch.setState({deviceId: child, on})`
|
|
40796
|
-
* - `${parent}__autotrack` → call `ptzAutotrack.setEnabled({deviceId: parent, enabled})`
|
|
40797
|
-
* - `${parent}__privacy` → call `privacyMask.setMask({deviceId: parent, patch: { enabled } })`
|
|
40798
|
-
* - `${deviceId}` (bare parent camera) → reject with INVALID_DIRECTIVE
|
|
40799
|
-
* (we never expose PowerController on the camera itself).
|
|
40800
|
-
*
|
|
40801
|
-
* Auth: verify the directive's scope token (same as every other
|
|
40802
|
-
* controller).
|
|
40803
|
-
*/
|
|
40804
|
-
var PowerDirectiveSchema = object({
|
|
40805
|
-
header: object({
|
|
40806
|
-
namespace: literal("Alexa.PowerController"),
|
|
40807
|
-
name: _enum(["TurnOn", "TurnOff"])
|
|
40808
|
-
}),
|
|
40809
|
-
endpoint: EndpointRefSchema
|
|
40810
|
-
});
|
|
40811
|
-
async function handlePower(header, endpointRaw, deps, _callerIdentity) {
|
|
40812
|
-
const parsed = PowerDirectiveSchema.safeParse({
|
|
40813
|
-
header: {
|
|
40814
|
-
namespace: header.namespace,
|
|
40815
|
-
name: header.name
|
|
40816
|
-
},
|
|
40817
|
-
endpoint: endpointRaw
|
|
40818
|
-
});
|
|
40819
|
-
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40820
|
-
const endpointId = parsed.data.endpoint.endpointId;
|
|
40821
|
-
const parsedId = parseCameraEndpointId(endpointId);
|
|
40822
|
-
const on = parsed.data.header.name === "TurnOn";
|
|
40823
|
-
const api = deps.ctx.api;
|
|
40824
|
-
if (parsedId.kind === "autotrack") await api.ptzAutotrack.setEnabled.mutate({
|
|
40825
|
-
deviceId: parsedId.parentDeviceId,
|
|
40826
|
-
enabled: on
|
|
40827
|
-
});
|
|
40828
|
-
else if (parsedId.kind === "privacy") await api.privacyMask.setMask.mutate({
|
|
40829
|
-
deviceId: parsedId.parentDeviceId,
|
|
40830
|
-
patch: { enabled: on }
|
|
40831
|
-
});
|
|
40832
|
-
else if (parsedId.kind === "child") await api.switch.setState.mutate({
|
|
40833
|
-
deviceId: parsedId.childDeviceId,
|
|
40834
|
-
on
|
|
40835
|
-
});
|
|
40836
|
-
else if (parsedId.kind === "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", "PowerController is not exposed on camera endpoints — direct the directive at the child accessory");
|
|
40837
|
-
else return errorEnvelope(header, "INVALID_DIRECTIVE", parsedId.reason);
|
|
40838
|
-
return {
|
|
40839
|
-
event: {
|
|
40840
|
-
header: {
|
|
40841
|
-
namespace: "Alexa",
|
|
40842
|
-
name: "Response",
|
|
40843
|
-
messageId: header.messageId,
|
|
40844
|
-
correlationToken: header.correlationToken,
|
|
40845
|
-
payloadVersion: "3"
|
|
40846
|
-
},
|
|
40847
|
-
endpoint: { endpointId },
|
|
40848
|
-
payload: {}
|
|
40849
|
-
},
|
|
40850
|
-
context: { properties: [{
|
|
40851
|
-
namespace: "Alexa.PowerController",
|
|
40852
|
-
name: "powerState",
|
|
40853
|
-
value: on ? "ON" : "OFF",
|
|
40854
|
-
timeOfSample: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40855
|
-
uncertaintyInMilliseconds: 500
|
|
40856
|
-
}] }
|
|
40857
|
-
};
|
|
40858
|
-
}
|
|
40859
|
-
//#endregion
|
|
40860
|
-
//#region src/handlers/brightness-controller.ts
|
|
40844
|
+
//#region src/handlers/ptz-preset.ts
|
|
40861
40845
|
/**
|
|
40862
|
-
* `Alexa.
|
|
40846
|
+
* `Alexa.ModeController/SetMode` handler — dispatches three PTZ instances:
|
|
40863
40847
|
*
|
|
40864
|
-
*
|
|
40865
|
-
*
|
|
40866
|
-
* Reolink floodlights, Hikvision supplemental lights). Brightness is
|
|
40867
|
-
* NEVER exposed on the parent camera endpoint or on the synthetic
|
|
40868
|
-
* autotrack endpoint — both reject INVALID_DIRECTIVE here.
|
|
40848
|
+
* `ptz.preset` — preset-recall. Decodes the preset name from the mode
|
|
40849
|
+
* value and calls `ptz.goToPreset({deviceId, presetId})`.
|
|
40869
40850
|
*
|
|
40870
|
-
*
|
|
40871
|
-
*
|
|
40851
|
+
* `ptz.pan` — momentary pan. `ptz.pan.left|right|center` issues a
|
|
40852
|
+
* continuousMove pulse stopped on a timer; the dropdown reverts to
|
|
40853
|
+
* `center` server-side so subsequent picks re-trigger the move.
|
|
40872
40854
|
*
|
|
40873
|
-
*
|
|
40874
|
-
* The response carries the `Alexa.BrightnessController.brightness`
|
|
40875
|
-
* property echoing the new level so the Echo updates its UI without an
|
|
40876
|
-
* extra ReportState round-trip.
|
|
40855
|
+
* `ptz.tilt` — momentary tilt. Mirrors ptz.pan with up|down|center.
|
|
40877
40856
|
*/
|
|
40878
|
-
var
|
|
40857
|
+
var SetModeDirectiveSchema = object({
|
|
40879
40858
|
header: object({
|
|
40880
|
-
namespace: literal("Alexa.
|
|
40881
|
-
name: literal("
|
|
40859
|
+
namespace: literal("Alexa.ModeController"),
|
|
40860
|
+
name: literal("SetMode"),
|
|
40861
|
+
instance: string().optional()
|
|
40882
40862
|
}),
|
|
40883
40863
|
endpoint: EndpointRefSchema,
|
|
40884
|
-
payload:
|
|
40864
|
+
payload: SetModePayloadSchema
|
|
40885
40865
|
});
|
|
40886
|
-
|
|
40887
|
-
|
|
40866
|
+
var PTZ_PRESET_MODE_PREFIX = "ptz.preset.";
|
|
40867
|
+
var PTZ_DIRECTION_PULSE_MS = 1e3;
|
|
40868
|
+
var PTZ_PAN_MOVES = {
|
|
40869
|
+
"ptz.pan.left": { pan: -1 },
|
|
40870
|
+
"ptz.pan.right": { pan: 1 },
|
|
40871
|
+
"ptz.pan.center": {}
|
|
40872
|
+
};
|
|
40873
|
+
var PTZ_TILT_MOVES = {
|
|
40874
|
+
"ptz.tilt.up": { tilt: 1 },
|
|
40875
|
+
"ptz.tilt.down": { tilt: -1 },
|
|
40876
|
+
"ptz.tilt.center": {}
|
|
40877
|
+
};
|
|
40878
|
+
async function handleSetMode(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
40879
|
+
const parsed = SetModeDirectiveSchema.safeParse({
|
|
40888
40880
|
header: {
|
|
40889
40881
|
namespace: header.namespace,
|
|
40890
|
-
name: header.name
|
|
40882
|
+
name: header.name,
|
|
40883
|
+
instance: header.instance
|
|
40891
40884
|
},
|
|
40892
40885
|
endpoint: endpointRaw,
|
|
40893
40886
|
payload: payloadRaw ?? {}
|
|
40894
40887
|
});
|
|
40895
40888
|
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
40889
|
+
const instance = parsed.data.header.instance;
|
|
40890
|
+
if (instance !== "ptz.preset" && instance !== "ptz.pan" && instance !== "ptz.tilt") return errorEnvelope(header, "INVALID_DIRECTIVE", `ModeController instance not supported: ${instance ?? "(missing)"}`);
|
|
40896
40891
|
const endpointId = parsed.data.endpoint.endpointId;
|
|
40897
40892
|
const parsedId = parseCameraEndpointId(endpointId);
|
|
40898
|
-
if (parsedId.kind
|
|
40899
|
-
|
|
40900
|
-
if (parsedId.kind === "invalid") return errorEnvelope(header, "INVALID_DIRECTIVE", parsedId.reason);
|
|
40901
|
-
const percentage = parsed.data.payload.brightness;
|
|
40893
|
+
if (parsedId.kind !== "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", `ModeController only supported on camera endpoints — got ${endpointId}`);
|
|
40894
|
+
const mode = parsed.data.payload.mode;
|
|
40902
40895
|
const api = deps.ctx.api;
|
|
40903
|
-
|
|
40904
|
-
|
|
40905
|
-
|
|
40906
|
-
|
|
40896
|
+
if (instance === "ptz.pan" || instance === "ptz.tilt") {
|
|
40897
|
+
const move = (instance === "ptz.pan" ? PTZ_PAN_MOVES : PTZ_TILT_MOVES)[mode];
|
|
40898
|
+
if (!move) return errorEnvelope(header, "INVALID_DIRECTIVE", `mode '${mode}' is not a valid ${instance} mode`);
|
|
40899
|
+
if (Object.keys(move).length === 0) await api.ptz.stop.mutate({ deviceId: parsedId.deviceId }).catch((err) => {
|
|
40900
|
+
deps.logger.debug("alexa ptz-mode: stop (center) failed (non-fatal)", { meta: {
|
|
40901
|
+
deviceId: parsedId.deviceId,
|
|
40902
|
+
instance,
|
|
40903
|
+
error: err instanceof Error ? err.message : String(err)
|
|
40904
|
+
} });
|
|
40907
40905
|
});
|
|
40908
|
-
|
|
40909
|
-
|
|
40910
|
-
|
|
40911
|
-
|
|
40912
|
-
|
|
40913
|
-
|
|
40914
|
-
|
|
40915
|
-
|
|
40906
|
+
else try {
|
|
40907
|
+
await api.ptz.continuousMove.mutate({
|
|
40908
|
+
deviceId: parsedId.deviceId,
|
|
40909
|
+
...move
|
|
40910
|
+
});
|
|
40911
|
+
setTimeout(() => {
|
|
40912
|
+
api.ptz.stop.mutate({ deviceId: parsedId.deviceId }).catch((err) => {
|
|
40913
|
+
deps.logger.debug("alexa ptz-mode: stop after pulse failed (non-fatal)", { meta: {
|
|
40914
|
+
deviceId: parsedId.deviceId,
|
|
40915
|
+
instance,
|
|
40916
|
+
error: err instanceof Error ? err.message : String(err)
|
|
40917
|
+
} });
|
|
40918
|
+
});
|
|
40919
|
+
}, PTZ_DIRECTION_PULSE_MS);
|
|
40920
|
+
} catch (err) {
|
|
40921
|
+
return errorEnvelope(header, "INTERNAL_ERROR", `ptz.continuousMove failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
40922
|
+
}
|
|
40923
|
+
return modeSuccessResponse(header, endpointId, instance, instance === "ptz.pan" ? "ptz.pan.center" : "ptz.tilt.center");
|
|
40916
40924
|
}
|
|
40925
|
+
if (!mode.startsWith(PTZ_PRESET_MODE_PREFIX)) return errorEnvelope(header, "INVALID_DIRECTIVE", `mode '${mode}' is not a ptz.preset mode`);
|
|
40926
|
+
const presetName = mode.slice(11);
|
|
40927
|
+
if (presetName.length === 0) return errorEnvelope(header, "INVALID_DIRECTIVE", "preset name missing after prefix");
|
|
40928
|
+
const preset = (await api.ptz.getPresets.query({ deviceId: parsedId.deviceId })).find((p) => p.name === presetName);
|
|
40929
|
+
if (!preset) return errorEnvelope(header, "INVALID_DIRECTIVE", `preset '${presetName}' not found on device ${parsedId.deviceId}`);
|
|
40930
|
+
await api.ptz.goToPreset.mutate({
|
|
40931
|
+
deviceId: parsedId.deviceId,
|
|
40932
|
+
presetId: preset.id
|
|
40933
|
+
});
|
|
40934
|
+
return modeSuccessResponse(header, endpointId, "ptz.preset", mode);
|
|
40935
|
+
}
|
|
40936
|
+
function modeSuccessResponse(header, endpointId, instance, mode) {
|
|
40917
40937
|
return {
|
|
40918
40938
|
event: {
|
|
40919
40939
|
header: {
|
|
@@ -40927,9 +40947,10 @@ async function handleSetBrightness(header, endpointRaw, payloadRaw, deps, _calle
|
|
|
40927
40947
|
payload: {}
|
|
40928
40948
|
},
|
|
40929
40949
|
context: { properties: [{
|
|
40930
|
-
namespace: "Alexa.
|
|
40931
|
-
|
|
40932
|
-
|
|
40950
|
+
namespace: "Alexa.ModeController",
|
|
40951
|
+
instance,
|
|
40952
|
+
name: "mode",
|
|
40953
|
+
value: mode,
|
|
40933
40954
|
timeOfSample: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40934
40955
|
uncertaintyInMilliseconds: 500
|
|
40935
40956
|
}] }
|
|
@@ -40950,6 +40971,7 @@ async function handleReportState(header, endpointRaw, deps, _callerIdentity) {
|
|
|
40950
40971
|
else if (parsed.kind === "privacy") await collectPrivacyProperties(api, parsed.parentDeviceId, properties, nowIso, deps.logger);
|
|
40951
40972
|
else if (parsed.kind === "autotrack") await collectAutotrackProperties(api, parsed.parentDeviceId, properties, nowIso, deps.logger);
|
|
40952
40973
|
else if (parsed.kind === "child") await collectChildProperties(api, parsed.childDeviceId, properties, nowIso, deps.logger);
|
|
40974
|
+
else if (parsed.kind === "alarm-panel") await collectAlarmPanelProperties(api, parsed.deviceId, properties, nowIso, deps.logger);
|
|
40953
40975
|
} catch (err) {
|
|
40954
40976
|
deps.logger.warn("alexa report-state: collection failed", { meta: {
|
|
40955
40977
|
endpointId,
|
|
@@ -41011,6 +41033,42 @@ async function collectCameraProperties(api, deviceId, properties, timeOfSample,
|
|
|
41011
41033
|
uncertaintyInMilliseconds: 0
|
|
41012
41034
|
});
|
|
41013
41035
|
}
|
|
41036
|
+
/**
|
|
41037
|
+
* The panel's two declared properties.
|
|
41038
|
+
*
|
|
41039
|
+
* Both are omitted when the panel cannot be read — an `armState` we guessed
|
|
41040
|
+
* would be a claim about whether a house is locked, and Alexa rendering the
|
|
41041
|
+
* endpoint as unavailable is the truthful outcome of a panel nobody reached.
|
|
41042
|
+
* The failure is logged with the device id, never swallowed.
|
|
41043
|
+
*/
|
|
41044
|
+
async function collectAlarmPanelProperties(api, deviceId, properties, timeOfSample, logger) {
|
|
41045
|
+
const status = await api.alarmPanel.getStatus.query({ deviceId }).catch((err) => {
|
|
41046
|
+
logger.warn("alexa report-state: alarmPanel.getStatus FAILED — Alexa will show the panel as unavailable", {
|
|
41047
|
+
tags: { deviceId },
|
|
41048
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
41049
|
+
});
|
|
41050
|
+
return null;
|
|
41051
|
+
});
|
|
41052
|
+
const parsed = AlarmPanelStatusSchema.pick({ state: true }).safeParse(status);
|
|
41053
|
+
if (!parsed.success) {
|
|
41054
|
+
if (status !== null) logger.warn("alexa report-state: panel status did not match the cap schema — omitting", { tags: { deviceId } });
|
|
41055
|
+
return;
|
|
41056
|
+
}
|
|
41057
|
+
properties.push({
|
|
41058
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41059
|
+
name: "armState",
|
|
41060
|
+
value: alexaArmStateFor(parsed.data.state),
|
|
41061
|
+
timeOfSample,
|
|
41062
|
+
uncertaintyInMilliseconds: 0
|
|
41063
|
+
});
|
|
41064
|
+
properties.push({
|
|
41065
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41066
|
+
name: "burglaryAlarm",
|
|
41067
|
+
value: burglaryAlarmFor(parsed.data.state),
|
|
41068
|
+
timeOfSample,
|
|
41069
|
+
uncertaintyInMilliseconds: 0
|
|
41070
|
+
});
|
|
41071
|
+
}
|
|
41014
41072
|
async function collectPrivacyProperties(api, parentDeviceId, properties, timeOfSample, _logger) {
|
|
41015
41073
|
const status = await api.privacyMask.getStatus.query({ deviceId: parentDeviceId }).catch(() => null);
|
|
41016
41074
|
const enabled = Boolean(status?.enabled);
|
|
@@ -41064,6 +41122,478 @@ async function collectChildProperties(api, childDeviceId, properties, timeOfSamp
|
|
|
41064
41122
|
});
|
|
41065
41123
|
}
|
|
41066
41124
|
//#endregion
|
|
41125
|
+
//#region src/handlers/rtc-session.ts
|
|
41126
|
+
var InitiateSessionWithOfferDirectiveSchema = object({
|
|
41127
|
+
endpoint: EndpointRefSchema,
|
|
41128
|
+
payload: InitiateSessionWithOfferPayloadSchema
|
|
41129
|
+
});
|
|
41130
|
+
var SessionDisconnectedDirectiveSchema = object({
|
|
41131
|
+
endpoint: EndpointRefSchema,
|
|
41132
|
+
payload: SessionDisconnectedPayloadSchema
|
|
41133
|
+
});
|
|
41134
|
+
/**
|
|
41135
|
+
* Live egress handles, keyed by `<deviceId>/<sessionId>`.
|
|
41136
|
+
*
|
|
41137
|
+
* The primitive's refcount has no lease TTL: a holder that vanishes without
|
|
41138
|
+
* releasing leaks a child until the broker restarts (D67). This handler is a
|
|
41139
|
+
* holder, so it keeps the one piece of state that lets it not be that holder —
|
|
41140
|
+
* the `pipelineKey` its `SessionDisconnected` has to release.
|
|
41141
|
+
*
|
|
41142
|
+
* A module-level map is right here because the directive handlers are free
|
|
41143
|
+
* functions called per directive; the entry is written on a successful acquire
|
|
41144
|
+
* and deleted on the release path, both of which are the same tick as the
|
|
41145
|
+
* directive that owns it.
|
|
41146
|
+
*/
|
|
41147
|
+
var EGRESS_HANDLES = /* @__PURE__ */ new Map();
|
|
41148
|
+
function egressHandleKey(deviceId, sessionId) {
|
|
41149
|
+
return `${deviceId}/${sessionId}`;
|
|
41150
|
+
}
|
|
41151
|
+
var WEBRTC_PROFILE_NAMES = [
|
|
41152
|
+
"high",
|
|
41153
|
+
"mid",
|
|
41154
|
+
"low"
|
|
41155
|
+
];
|
|
41156
|
+
function resolveWebrtcTarget(pref) {
|
|
41157
|
+
if (pref === "auto") return void 0;
|
|
41158
|
+
if (WEBRTC_PROFILE_NAMES.includes(pref)) return {
|
|
41159
|
+
kind: "profile",
|
|
41160
|
+
profile: pref
|
|
41161
|
+
};
|
|
41162
|
+
return {
|
|
41163
|
+
kind: "cam-stream",
|
|
41164
|
+
camStreamId: pref
|
|
41165
|
+
};
|
|
41166
|
+
}
|
|
41167
|
+
async function handleInitiateSessionWithOffer(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
41168
|
+
const parsed = InitiateSessionWithOfferDirectiveSchema.safeParse({
|
|
41169
|
+
endpoint: endpointRaw,
|
|
41170
|
+
payload: payloadRaw ?? {}
|
|
41171
|
+
});
|
|
41172
|
+
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
41173
|
+
const endpoint = parsed.data.endpoint;
|
|
41174
|
+
const payload = parsed.data.payload;
|
|
41175
|
+
const parsedId = parseCameraEndpointId(endpoint.endpointId);
|
|
41176
|
+
if (parsedId.kind !== "camera") return errorEnvelope(header, "INVALID_DIRECTIVE", `endpointId ${endpoint.endpointId} is not a camera`);
|
|
41177
|
+
const deviceId = parsedId.deviceId;
|
|
41178
|
+
const sessionId = payload.sessionId;
|
|
41179
|
+
const log = deps.logger.withTags({
|
|
41180
|
+
deviceId,
|
|
41181
|
+
sessionId
|
|
41182
|
+
});
|
|
41183
|
+
const sdpOffer = payload.offer.value;
|
|
41184
|
+
if (sdpOffer.length === 0) return errorEnvelope(header, "INVALID_DIRECTIVE", "offer.value is empty");
|
|
41185
|
+
const api = deps.ctx.api;
|
|
41186
|
+
const exposedEntry = deps.listExposed().find((e) => e.deviceId === deviceId);
|
|
41187
|
+
const explicitSourceProfile = exposedEntry?.settings?.sourceProfile;
|
|
41188
|
+
const mappedFromPreference = (() => {
|
|
41189
|
+
const pref = exposedEntry?.settings?.streamPreference;
|
|
41190
|
+
if (pref === "low" || pref === "mid" || pref === "high") return pref;
|
|
41191
|
+
})();
|
|
41192
|
+
const sourceProfile = explicitSourceProfile ?? mappedFromPreference ?? "high";
|
|
41193
|
+
let derivedTarget;
|
|
41194
|
+
/**
|
|
41195
|
+
* The primitive's release handle, when this session acquired one. Recorded so
|
|
41196
|
+
* `SessionDisconnected` can release it: a refcount whose holder disappears is
|
|
41197
|
+
* the one gap D67 leaves open, and the least this handler can do is not BE
|
|
41198
|
+
* that holder.
|
|
41199
|
+
*/
|
|
41200
|
+
let egressPipelineKey = null;
|
|
41201
|
+
const picked = await api.cameraStreams.pickStream.query({
|
|
41202
|
+
deviceId,
|
|
41203
|
+
requirements: {
|
|
41204
|
+
acceptCodecs: ["h264"],
|
|
41205
|
+
minHeight: 480,
|
|
41206
|
+
excludeDerived: true,
|
|
41207
|
+
requireSiblingCodec: ["h265", "hevc"]
|
|
41208
|
+
}
|
|
41209
|
+
}).catch((err) => {
|
|
41210
|
+
log.warn("alexa rtc-session: cameraStreams.pickStream threw — falling back to transcode", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
41211
|
+
return null;
|
|
41212
|
+
});
|
|
41213
|
+
if (picked) {
|
|
41214
|
+
log.info("alexa rtc-session: bypassing transcode via cameraStreams.pickStream", { meta: {
|
|
41215
|
+
sourceProfile,
|
|
41216
|
+
selectedCamStreamId: picked.camStreamId,
|
|
41217
|
+
reason: picked.reason
|
|
41218
|
+
} });
|
|
41219
|
+
derivedTarget = {
|
|
41220
|
+
kind: "cam-stream",
|
|
41221
|
+
camStreamId: picked.camStreamId
|
|
41222
|
+
};
|
|
41223
|
+
} else try {
|
|
41224
|
+
const acquired = await acquireAlexaEgress({
|
|
41225
|
+
api,
|
|
41226
|
+
deviceId,
|
|
41227
|
+
sourceProfile,
|
|
41228
|
+
sessionId,
|
|
41229
|
+
logger: log
|
|
41230
|
+
});
|
|
41231
|
+
egressPipelineKey = acquired.pipelineKey;
|
|
41232
|
+
EGRESS_HANDLES.set(egressHandleKey(deviceId, sessionId), acquired.pipelineKey);
|
|
41233
|
+
derivedTarget = {
|
|
41234
|
+
kind: "cam-stream",
|
|
41235
|
+
camStreamId: acquired.camStreamId
|
|
41236
|
+
};
|
|
41237
|
+
} catch (err) {
|
|
41238
|
+
log.warn("alexa rtc-session: egress acquire failed, falling back to streamPreference target", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
41239
|
+
derivedTarget = resolveWebrtcTarget(exposedEntry?.settings?.streamPreference ?? "auto");
|
|
41240
|
+
}
|
|
41241
|
+
try {
|
|
41242
|
+
const result = await api.webrtcSession.handleOffer.mutate({
|
|
41243
|
+
deviceId,
|
|
41244
|
+
sdpOffer,
|
|
41245
|
+
sessionId,
|
|
41246
|
+
target: derivedTarget,
|
|
41247
|
+
relayOnly: false,
|
|
41248
|
+
nonTrickle: true,
|
|
41249
|
+
disableTurn: true,
|
|
41250
|
+
disableIpv6: true,
|
|
41251
|
+
consumerAttribution: {
|
|
41252
|
+
kind: "alexa",
|
|
41253
|
+
sessionId
|
|
41254
|
+
}
|
|
41255
|
+
});
|
|
41256
|
+
log.info("alexa rtc-session: AnswerGenerated", { meta: {
|
|
41257
|
+
returnedSessionId: result.sessionId,
|
|
41258
|
+
sdpAnswerLen: result.sdpAnswer.length
|
|
41259
|
+
} });
|
|
41260
|
+
return { event: {
|
|
41261
|
+
header: {
|
|
41262
|
+
namespace: "Alexa.RTCSessionController",
|
|
41263
|
+
name: "AnswerGeneratedForSession",
|
|
41264
|
+
messageId: header.messageId,
|
|
41265
|
+
correlationToken: header.correlationToken,
|
|
41266
|
+
payloadVersion: "3"
|
|
41267
|
+
},
|
|
41268
|
+
endpoint: { endpointId: endpoint.endpointId },
|
|
41269
|
+
payload: { answer: {
|
|
41270
|
+
format: payload.offer.format ?? "SDP",
|
|
41271
|
+
value: result.sdpAnswer
|
|
41272
|
+
} }
|
|
41273
|
+
} };
|
|
41274
|
+
} catch (err) {
|
|
41275
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
41276
|
+
const mSectionSummary = (() => {
|
|
41277
|
+
const lines = sdpOffer.split(/\r?\n/);
|
|
41278
|
+
const sections = [];
|
|
41279
|
+
let current = null;
|
|
41280
|
+
for (const raw of lines) {
|
|
41281
|
+
const line = raw.trim();
|
|
41282
|
+
if (line.startsWith("m=")) {
|
|
41283
|
+
if (current) sections.push(current);
|
|
41284
|
+
current = {
|
|
41285
|
+
mid: null,
|
|
41286
|
+
kind: line.split(" ")[0]?.slice(2) ?? "unknown",
|
|
41287
|
+
direction: null,
|
|
41288
|
+
codecs: []
|
|
41289
|
+
};
|
|
41290
|
+
} else if (current) {
|
|
41291
|
+
if (line.startsWith("a=mid:")) current.mid = line.slice(6);
|
|
41292
|
+
else if (/^a=(sendonly|recvonly|sendrecv|inactive)$/.test(line)) current.direction = line.slice(2);
|
|
41293
|
+
else if (line.startsWith("a=rtpmap:")) current.codecs.push(line.slice(9));
|
|
41294
|
+
}
|
|
41295
|
+
}
|
|
41296
|
+
if (current) sections.push(current);
|
|
41297
|
+
return sections;
|
|
41298
|
+
})();
|
|
41299
|
+
log.warn("alexa rtc-session: handleOffer failed", { meta: {
|
|
41300
|
+
error: message,
|
|
41301
|
+
offerLen: sdpOffer.length,
|
|
41302
|
+
mSections: mSectionSummary,
|
|
41303
|
+
offerSdp: sdpOffer
|
|
41304
|
+
} });
|
|
41305
|
+
if (egressPipelineKey !== null) {
|
|
41306
|
+
EGRESS_HANDLES.delete(egressHandleKey(deviceId, sessionId));
|
|
41307
|
+
await releaseAlexaEgress({
|
|
41308
|
+
api,
|
|
41309
|
+
deviceId,
|
|
41310
|
+
pipelineKey: egressPipelineKey,
|
|
41311
|
+
logger: log
|
|
41312
|
+
});
|
|
41313
|
+
}
|
|
41314
|
+
return errorEnvelope(header, "INTERNAL_ERROR", `webrtc-session.handleOffer failed: ${message}`);
|
|
41315
|
+
}
|
|
41316
|
+
}
|
|
41317
|
+
async function handleSessionDisconnected(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
41318
|
+
const parsed = SessionDisconnectedDirectiveSchema.safeParse({
|
|
41319
|
+
endpoint: endpointRaw,
|
|
41320
|
+
payload: payloadRaw ?? {}
|
|
41321
|
+
});
|
|
41322
|
+
if (!parsed.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `payload validation failed: ${parsed.error.message}`);
|
|
41323
|
+
const endpoint = parsed.data.endpoint;
|
|
41324
|
+
const parsedId = parseCameraEndpointId(endpoint.endpointId);
|
|
41325
|
+
if (parsedId.kind === "camera") {
|
|
41326
|
+
const handleKey = egressHandleKey(parsedId.deviceId, parsed.data.payload.sessionId);
|
|
41327
|
+
const pipelineKey = EGRESS_HANDLES.get(handleKey);
|
|
41328
|
+
if (pipelineKey !== void 0) {
|
|
41329
|
+
EGRESS_HANDLES.delete(handleKey);
|
|
41330
|
+
await releaseAlexaEgress({
|
|
41331
|
+
api: deps.ctx.api,
|
|
41332
|
+
deviceId: parsedId.deviceId,
|
|
41333
|
+
pipelineKey,
|
|
41334
|
+
logger: deps.logger
|
|
41335
|
+
});
|
|
41336
|
+
}
|
|
41337
|
+
try {
|
|
41338
|
+
await deps.ctx.api.webrtcSession.closeSession.mutate({
|
|
41339
|
+
deviceId: parsedId.deviceId,
|
|
41340
|
+
sessionId: parsed.data.payload.sessionId
|
|
41341
|
+
});
|
|
41342
|
+
} catch (err) {
|
|
41343
|
+
deps.logger.warn("alexa rtc-session: closeSession threw on disconnect (continuing to ack)", {
|
|
41344
|
+
tags: {
|
|
41345
|
+
deviceId: parsedId.deviceId,
|
|
41346
|
+
sessionId: parsed.data.payload.sessionId
|
|
41347
|
+
},
|
|
41348
|
+
meta: { error: err instanceof Error ? err.message : String(err) }
|
|
41349
|
+
});
|
|
41350
|
+
}
|
|
41351
|
+
}
|
|
41352
|
+
const disconnectedDeviceId = parsedId.kind === "camera" ? parsedId.deviceId : void 0;
|
|
41353
|
+
deps.logger.info("alexa rtc-session: SessionDisconnected", {
|
|
41354
|
+
tags: {
|
|
41355
|
+
sessionId: parsed.data.payload.sessionId,
|
|
41356
|
+
...disconnectedDeviceId !== void 0 ? { deviceId: disconnectedDeviceId } : {}
|
|
41357
|
+
},
|
|
41358
|
+
meta: { endpointId: endpoint.endpointId }
|
|
41359
|
+
});
|
|
41360
|
+
return { event: {
|
|
41361
|
+
header: {
|
|
41362
|
+
namespace: "Alexa",
|
|
41363
|
+
name: "Response",
|
|
41364
|
+
messageId: header.messageId,
|
|
41365
|
+
correlationToken: header.correlationToken,
|
|
41366
|
+
payloadVersion: "3"
|
|
41367
|
+
},
|
|
41368
|
+
endpoint: { endpointId: endpoint.endpointId },
|
|
41369
|
+
payload: {}
|
|
41370
|
+
} };
|
|
41371
|
+
}
|
|
41372
|
+
//#endregion
|
|
41373
|
+
//#region src/handlers/security-panel.ts
|
|
41374
|
+
var ArmPayloadSchema = object({ armState: _enum([
|
|
41375
|
+
"ARMED_STAY",
|
|
41376
|
+
"ARMED_AWAY",
|
|
41377
|
+
"ARMED_NIGHT"
|
|
41378
|
+
]) });
|
|
41379
|
+
var DisarmPayloadSchema = object({ authorization: object({
|
|
41380
|
+
type: literal("FOUR_DIGIT_PIN"),
|
|
41381
|
+
value: string().min(1)
|
|
41382
|
+
}).optional() });
|
|
41383
|
+
/** The subset of the panel status the directives read. */
|
|
41384
|
+
var PanelReadSchema = AlarmPanelStatusSchema.pick({
|
|
41385
|
+
state: true,
|
|
41386
|
+
availableModes: true,
|
|
41387
|
+
requiresCode: true
|
|
41388
|
+
});
|
|
41389
|
+
/**
|
|
41390
|
+
* `Alexa.SecurityPanelController.ErrorResponse`.
|
|
41391
|
+
*
|
|
41392
|
+
* A namespace of its own, because the four types that matter here
|
|
41393
|
+
* (`AUTHORIZATION_REQUIRED`, `UNAUTHORIZED`, `NOT_READY_FOR_ARM`,
|
|
41394
|
+
* `BYPASS_NEEDED`) are only understood under it — the generic `Alexa`
|
|
41395
|
+
* `ErrorResponse` from `error-envelope.ts` carries none of them, and a PIN
|
|
41396
|
+
* problem reported there is a message the Alexa app cannot act on.
|
|
41397
|
+
*/
|
|
41398
|
+
function securityPanelError(header, type, message) {
|
|
41399
|
+
return { event: {
|
|
41400
|
+
header: {
|
|
41401
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41402
|
+
name: "ErrorResponse",
|
|
41403
|
+
messageId: header.messageId,
|
|
41404
|
+
correlationToken: header.correlationToken,
|
|
41405
|
+
payloadVersion: "3"
|
|
41406
|
+
},
|
|
41407
|
+
payload: {
|
|
41408
|
+
type,
|
|
41409
|
+
message
|
|
41410
|
+
}
|
|
41411
|
+
} };
|
|
41412
|
+
}
|
|
41413
|
+
/** Resolve the alarm panel this directive targets, or the refusal to send. */
|
|
41414
|
+
function resolveDeviceId(endpointRaw) {
|
|
41415
|
+
const parsedEndpoint = EndpointRefSchema.safeParse(endpointRaw);
|
|
41416
|
+
if (!parsedEndpoint.success) return { reason: "missing or malformed endpoint" };
|
|
41417
|
+
const parsedId = parseCameraEndpointId(parsedEndpoint.data.endpointId);
|
|
41418
|
+
if (parsedId.kind === "alarm-panel") return { deviceId: parsedId.deviceId };
|
|
41419
|
+
return { reason: `SecurityPanelController is only exposed on alarm-panel endpoints — got '${parsedEndpoint.data.endpointId}'` };
|
|
41420
|
+
}
|
|
41421
|
+
/**
|
|
41422
|
+
* What the panel currently accepts, or `null` when it could not be read.
|
|
41423
|
+
*
|
|
41424
|
+
* `null` is the honest answer and the callers treat it as unknown; nothing
|
|
41425
|
+
* here substitutes a default that would read as "accepts nothing, needs no
|
|
41426
|
+
* PIN".
|
|
41427
|
+
*/
|
|
41428
|
+
async function readPanel(api, deviceId, logger, phase) {
|
|
41429
|
+
const raw = await api.alarmPanel.getStatus.query({ deviceId }).catch((err) => {
|
|
41430
|
+
logger.warn("alexa security-panel: alarmPanel.getStatus failed — proceeding without it", {
|
|
41431
|
+
tags: { deviceId },
|
|
41432
|
+
meta: {
|
|
41433
|
+
phase,
|
|
41434
|
+
error: err instanceof Error ? err.message : String(err)
|
|
41435
|
+
}
|
|
41436
|
+
});
|
|
41437
|
+
return null;
|
|
41438
|
+
});
|
|
41439
|
+
const parsed = PanelReadSchema.safeParse(raw);
|
|
41440
|
+
if (!parsed.success) {
|
|
41441
|
+
if (raw !== null) logger.warn("alexa security-panel: panel status did not match the cap schema", {
|
|
41442
|
+
tags: { deviceId },
|
|
41443
|
+
meta: { phase }
|
|
41444
|
+
});
|
|
41445
|
+
return null;
|
|
41446
|
+
}
|
|
41447
|
+
return parsed.data;
|
|
41448
|
+
}
|
|
41449
|
+
/** The `context.properties` block for a panel whose state we re-read. */
|
|
41450
|
+
function panelProperties(facts, fallback) {
|
|
41451
|
+
const timeOfSample = (/* @__PURE__ */ new Date()).toISOString();
|
|
41452
|
+
const parsedState = facts === null ? null : AlarmPanelStatusSchema.shape.state.parse(facts.state);
|
|
41453
|
+
const armState = parsedState === null ? fallback : alexaArmStateFor(parsedState);
|
|
41454
|
+
const burglary = parsedState === null ? { value: "OK" } : burglaryAlarmFor(parsedState);
|
|
41455
|
+
return [{
|
|
41456
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41457
|
+
name: "armState",
|
|
41458
|
+
value: armState,
|
|
41459
|
+
timeOfSample,
|
|
41460
|
+
uncertaintyInMilliseconds: 0
|
|
41461
|
+
}, {
|
|
41462
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41463
|
+
name: "burglaryAlarm",
|
|
41464
|
+
value: burglary,
|
|
41465
|
+
timeOfSample,
|
|
41466
|
+
uncertaintyInMilliseconds: 0
|
|
41467
|
+
}];
|
|
41468
|
+
}
|
|
41469
|
+
async function handleArm(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
41470
|
+
const target = resolveDeviceId(endpointRaw);
|
|
41471
|
+
if (!("deviceId" in target)) return errorEnvelope(header, "INVALID_DIRECTIVE", target.reason);
|
|
41472
|
+
const { deviceId } = target;
|
|
41473
|
+
const payload = ArmPayloadSchema.safeParse(payloadRaw);
|
|
41474
|
+
if (!payload.success) {
|
|
41475
|
+
deps.logger.warn("alexa security-panel: Arm payload is not an arm state Alexa defines", {
|
|
41476
|
+
tags: { deviceId },
|
|
41477
|
+
meta: { error: payload.error.message }
|
|
41478
|
+
});
|
|
41479
|
+
return errorEnvelope(header, "INVALID_DIRECTIVE", `Arm payload unexpected: ${payload.error.message}`);
|
|
41480
|
+
}
|
|
41481
|
+
const requested = payload.data.armState;
|
|
41482
|
+
const api = deps.ctx.api;
|
|
41483
|
+
const facts = await readPanel(api, deviceId, deps.logger, "arm");
|
|
41484
|
+
if (facts?.requiresCode === true) {
|
|
41485
|
+
deps.logger.warn("alexa security-panel: panel requires a PIN and the Arm directive carries none — REFUSED", {
|
|
41486
|
+
tags: { deviceId },
|
|
41487
|
+
meta: { requested }
|
|
41488
|
+
});
|
|
41489
|
+
return securityPanelError(header, "AUTHORIZATION_REQUIRED", "this panel requires a PIN to arm, and Alexa cannot supply one on an Arm directive");
|
|
41490
|
+
}
|
|
41491
|
+
const mode = alarmArmModeForAlexa(requested, facts?.availableModes ?? []);
|
|
41492
|
+
if (mode === null) {
|
|
41493
|
+
deps.logger.warn("alexa security-panel: panel accepts no mode for this arm state — REFUSED", {
|
|
41494
|
+
tags: { deviceId },
|
|
41495
|
+
meta: {
|
|
41496
|
+
requested,
|
|
41497
|
+
availableModes: facts?.availableModes ?? null
|
|
41498
|
+
}
|
|
41499
|
+
});
|
|
41500
|
+
return securityPanelError(header, "NOT_READY_FOR_ARM", `panel does not accept ${requested}`);
|
|
41501
|
+
}
|
|
41502
|
+
try {
|
|
41503
|
+
await api.alarmPanel.arm.mutate({
|
|
41504
|
+
deviceId,
|
|
41505
|
+
mode
|
|
41506
|
+
});
|
|
41507
|
+
} catch (err) {
|
|
41508
|
+
deps.logger.warn("alexa security-panel: arm command failed", {
|
|
41509
|
+
tags: { deviceId },
|
|
41510
|
+
meta: {
|
|
41511
|
+
requested,
|
|
41512
|
+
mode,
|
|
41513
|
+
error: err instanceof Error ? err.message : String(err)
|
|
41514
|
+
}
|
|
41515
|
+
});
|
|
41516
|
+
return securityPanelError(header, "NOT_READY_FOR_ARM", err instanceof Error ? err.message : String(err));
|
|
41517
|
+
}
|
|
41518
|
+
deps.logger.info("alexa security-panel: armed", {
|
|
41519
|
+
tags: { deviceId },
|
|
41520
|
+
meta: {
|
|
41521
|
+
requested,
|
|
41522
|
+
mode
|
|
41523
|
+
}
|
|
41524
|
+
});
|
|
41525
|
+
const after = await readPanel(api, deviceId, deps.logger, "arm-confirm");
|
|
41526
|
+
if (after?.state === "arming") deps.logger.info("alexa security-panel: panel is in its exit delay — reporting DISARMED until it is set", {
|
|
41527
|
+
tags: { deviceId },
|
|
41528
|
+
meta: {
|
|
41529
|
+
requested,
|
|
41530
|
+
mode
|
|
41531
|
+
}
|
|
41532
|
+
});
|
|
41533
|
+
return {
|
|
41534
|
+
event: {
|
|
41535
|
+
header: {
|
|
41536
|
+
namespace: "Alexa.SecurityPanelController",
|
|
41537
|
+
name: "Arm.Response",
|
|
41538
|
+
messageId: header.messageId,
|
|
41539
|
+
correlationToken: header.correlationToken,
|
|
41540
|
+
payloadVersion: "3"
|
|
41541
|
+
},
|
|
41542
|
+
endpoint: { endpointId: `${deviceId}__alarm` },
|
|
41543
|
+
payload: {}
|
|
41544
|
+
},
|
|
41545
|
+
context: { properties: panelProperties(after, requested) }
|
|
41546
|
+
};
|
|
41547
|
+
}
|
|
41548
|
+
async function handleDisarm(header, endpointRaw, payloadRaw, deps, _callerIdentity) {
|
|
41549
|
+
const target = resolveDeviceId(endpointRaw);
|
|
41550
|
+
if (!("deviceId" in target)) return errorEnvelope(header, "INVALID_DIRECTIVE", target.reason);
|
|
41551
|
+
const { deviceId } = target;
|
|
41552
|
+
const payload = DisarmPayloadSchema.safeParse(payloadRaw ?? {});
|
|
41553
|
+
if (!payload.success) return errorEnvelope(header, "INVALID_DIRECTIVE", `Disarm payload unexpected: ${payload.error.message}`);
|
|
41554
|
+
const code = payload.data.authorization?.value;
|
|
41555
|
+
const api = deps.ctx.api;
|
|
41556
|
+
if ((await readPanel(api, deviceId, deps.logger, "disarm"))?.requiresCode === true && code === void 0) {
|
|
41557
|
+
deps.logger.warn("alexa security-panel: panel requires a PIN and the Disarm directive carried none — REFUSED", { tags: { deviceId } });
|
|
41558
|
+
return securityPanelError(header, "AUTHORIZATION_REQUIRED", "this panel requires a PIN to disarm");
|
|
41559
|
+
}
|
|
41560
|
+
try {
|
|
41561
|
+
await api.alarmPanel.disarm.mutate(code === void 0 ? { deviceId } : {
|
|
41562
|
+
deviceId,
|
|
41563
|
+
code
|
|
41564
|
+
});
|
|
41565
|
+
} catch (err) {
|
|
41566
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
41567
|
+
deps.logger.warn("alexa security-panel: disarm command failed", {
|
|
41568
|
+
tags: { deviceId },
|
|
41569
|
+
meta: {
|
|
41570
|
+
codeSupplied: code !== void 0,
|
|
41571
|
+
error: message
|
|
41572
|
+
}
|
|
41573
|
+
});
|
|
41574
|
+
return code === void 0 ? errorEnvelope(header, "INTERNAL_ERROR", message) : securityPanelError(header, "UNAUTHORIZED", message);
|
|
41575
|
+
}
|
|
41576
|
+
deps.logger.info("alexa security-panel: disarmed", {
|
|
41577
|
+
tags: { deviceId },
|
|
41578
|
+
meta: { codeSupplied: code !== void 0 }
|
|
41579
|
+
});
|
|
41580
|
+
const after = await readPanel(api, deviceId, deps.logger, "disarm-confirm");
|
|
41581
|
+
return {
|
|
41582
|
+
event: {
|
|
41583
|
+
header: {
|
|
41584
|
+
namespace: "Alexa",
|
|
41585
|
+
name: "Response",
|
|
41586
|
+
messageId: header.messageId,
|
|
41587
|
+
correlationToken: header.correlationToken,
|
|
41588
|
+
payloadVersion: "3"
|
|
41589
|
+
},
|
|
41590
|
+
endpoint: { endpointId: `${deviceId}__alarm` },
|
|
41591
|
+
payload: {}
|
|
41592
|
+
},
|
|
41593
|
+
context: { properties: panelProperties(after, "DISARMED") }
|
|
41594
|
+
};
|
|
41595
|
+
}
|
|
41596
|
+
//#endregion
|
|
41067
41597
|
//#region src/handlers/stubs.ts
|
|
41068
41598
|
/**
|
|
41069
41599
|
* Stub responder for namespaces not yet implemented (CameraStream /
|
|
@@ -41143,7 +41673,9 @@ async function dispatchDirective(rawBody, deps, callerIdentity) {
|
|
|
41143
41673
|
"Alexa.ModeController/SetMode": "create",
|
|
41144
41674
|
"Alexa.ToggleController/TurnOn": "create",
|
|
41145
41675
|
"Alexa.ToggleController/TurnOff": "create",
|
|
41146
|
-
"Alexa/ReportState": "view"
|
|
41676
|
+
"Alexa/ReportState": "view",
|
|
41677
|
+
"Alexa.SecurityPanelController/Arm": "create",
|
|
41678
|
+
"Alexa.SecurityPanelController/Disarm": "create"
|
|
41147
41679
|
};
|
|
41148
41680
|
try {
|
|
41149
41681
|
const key = `${header.namespace}/${header.name}`;
|
|
@@ -41188,6 +41720,14 @@ async function dispatchDirective(rawBody, deps, callerIdentity) {
|
|
|
41188
41720
|
status: 200,
|
|
41189
41721
|
body: await handlePtzDirection(header, endpoint, deps.ptzDirection, callerIdentity)
|
|
41190
41722
|
};
|
|
41723
|
+
if (key === "Alexa.SecurityPanelController/Arm") return {
|
|
41724
|
+
status: 200,
|
|
41725
|
+
body: await handleArm(header, endpoint, payload, deps.securityPanel, callerIdentity)
|
|
41726
|
+
};
|
|
41727
|
+
if (key === "Alexa.SecurityPanelController/Disarm") return {
|
|
41728
|
+
status: 200,
|
|
41729
|
+
body: await handleDisarm(header, endpoint, payload, deps.securityPanel, callerIdentity)
|
|
41730
|
+
};
|
|
41191
41731
|
if (key === "Alexa/ReportState") return {
|
|
41192
41732
|
status: 200,
|
|
41193
41733
|
body: await handleReportState(header, endpoint, deps.reportState, callerIdentity)
|
|
@@ -42744,7 +43284,13 @@ var DEFAULT_CONFIG = {
|
|
|
42744
43284
|
enforceIngressToken: false,
|
|
42745
43285
|
staleEndpointPurgeInput: ""
|
|
42746
43286
|
};
|
|
42747
|
-
|
|
43287
|
+
/** UI filter for the Export picker. `alarm-panel` publishes an
|
|
43288
|
+
* `Alexa.SecurityPanelController` endpoint (`endpoints/builder.ts`). */
|
|
43289
|
+
var SUPPORTED_KINDS = [
|
|
43290
|
+
"camera",
|
|
43291
|
+
"doorbell",
|
|
43292
|
+
DeviceType.AlarmPanel
|
|
43293
|
+
];
|
|
42748
43294
|
var ExportAlexaAddon = class extends BaseAddon {
|
|
42749
43295
|
lwaGateway = null;
|
|
42750
43296
|
syncEngine = null;
|
|
@@ -42813,6 +43359,10 @@ var ExportAlexaAddon = class extends BaseAddon {
|
|
|
42813
43359
|
reportState: {
|
|
42814
43360
|
ctx: this.ctx,
|
|
42815
43361
|
logger: this.ctx.logger
|
|
43362
|
+
},
|
|
43363
|
+
securityPanel: {
|
|
43364
|
+
ctx: this.ctx,
|
|
43365
|
+
logger: this.ctx.logger
|
|
42816
43366
|
}
|
|
42817
43367
|
},
|
|
42818
43368
|
lwaTokensCallbackDeps: {
|