@camstack/server 1.2.806 → 1.2.808
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/CHANGELOG.md +12 -0
- package/package.json +8 -6
- package/system/dist/addon-runner.js +6 -1
- package/system/dist/addon-runner.mjs +6 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +10 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +173 -11
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +174 -12
- package/system/dist/builtins/core-blocks/remote-service.d.ts +43 -0
- package/system/dist/builtins/core-blocks/remote-wiring.d.ts +19 -1
- package/system/dist/builtins/system-config/system-config.addon.mjs +277 -277
- package/system/dist/index.js +2 -2
- package/system/dist/index.mjs +3 -3
- package/system/dist/kernel/moleculer/child-addon-call-dispatch.d.ts +2 -0
- package/system/dist/{restore-archive-BcsSlHR8.mjs → restore-archive-D_191hoC.mjs} +77 -77
- package/system/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.808] - 2026-11-08
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- An infrared TV (media-player with a remote) now publishes its assumed power state as its own state, so the hero no longer shows State unknown and the power button is enabled
|
|
15
|
+
|
|
16
|
+
## [1.2.807] - 2026-11-08
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Rebuilt against updated dependencies.
|
|
21
|
+
|
|
10
22
|
## [1.2.806] - 2026-11-08
|
|
11
23
|
|
|
12
24
|
### Changed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camstack/server",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.808",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -65,7 +65,9 @@
|
|
|
65
65
|
"@camstack/addon-agent-ui"
|
|
66
66
|
],
|
|
67
67
|
"requires": {
|
|
68
|
-
"addons": {
|
|
68
|
+
"addons": {
|
|
69
|
+
"@camstack/addon-terminal": ">=0.1.162"
|
|
70
|
+
},
|
|
69
71
|
"wrapper": {
|
|
70
72
|
"desktop": ">=0.0.1",
|
|
71
73
|
"image": ">=0.0.1"
|
|
@@ -73,19 +75,19 @@
|
|
|
73
75
|
}
|
|
74
76
|
},
|
|
75
77
|
"dependencies": {
|
|
76
|
-
"@camstack/addon-admin-ui": "1.2.
|
|
77
|
-
"@camstack/addon-agent-ui": "1.2.
|
|
78
|
+
"@camstack/addon-admin-ui": "1.2.615",
|
|
79
|
+
"@camstack/addon-agent-ui": "1.2.343",
|
|
78
80
|
"@camstack/addon-auth": "1.2.179",
|
|
79
81
|
"@camstack/addon-benchmark": "1.2.312",
|
|
80
82
|
"@camstack/addon-decoder-nodeav": "1.2.149",
|
|
81
83
|
"@camstack/addon-notifiers": "1.2.633",
|
|
82
84
|
"@camstack/addon-pipeline": "1.2.648",
|
|
83
|
-
"@camstack/addon-pipeline-orchestrator": "1.2.
|
|
85
|
+
"@camstack/addon-pipeline-orchestrator": "1.2.670",
|
|
84
86
|
"@camstack/addon-post-analysis": "1.2.685",
|
|
85
87
|
"@camstack/develop": "0.1.50",
|
|
86
88
|
"@camstack/sdk": "1.2.157",
|
|
87
89
|
"@camstack/types": "1.2.524",
|
|
88
|
-
"@camstack/ui-library": "1.2.
|
|
90
|
+
"@camstack/ui-library": "1.2.402",
|
|
89
91
|
"@fastify/compress": "^9.0.0",
|
|
90
92
|
"@fastify/cookie": "^11.0.2",
|
|
91
93
|
"@fastify/cors": "^11.2.0",
|
|
@@ -11527,7 +11527,11 @@ function createChildAddonCallDispatch(deps) {
|
|
|
11527
11527
|
const method = call.method;
|
|
11528
11528
|
if (method == null) throw new Error(`child-addon-call: addon "${addonId}" settings call missing method`);
|
|
11529
11529
|
const addon = deps.getAddonInstance(addonId);
|
|
11530
|
-
if (addon == null)
|
|
11530
|
+
if (addon == null) {
|
|
11531
|
+
const hosted = deps.listAddonIds?.() ?? [];
|
|
11532
|
+
const hostedText = hosted.length > 0 ? ` (this runner hosts: ${hosted.join(", ")})` : "";
|
|
11533
|
+
throw new Error(`child-addon-call: addon "${addonId}" is not loaded in this runner${hostedText} — address an addon by its own id, not its execution group`);
|
|
11534
|
+
}
|
|
11531
11535
|
return dispatchSettings(addon, addonId, method, call.args ?? {});
|
|
11532
11536
|
}
|
|
11533
11537
|
case "data-planes": return deps.getDataPlanes(addonId);
|
|
@@ -12066,6 +12070,7 @@ async function main() {
|
|
|
12066
12070
|
getRouteProvider: (addonId) => addonRouteProviders.get(addonId) ?? null,
|
|
12067
12071
|
customActions: customActionRegistry,
|
|
12068
12072
|
getAddonInstance: (addonId) => loadedAddonInstances.get(addonId) ?? null,
|
|
12073
|
+
listAddonIds: () => [...loadedAddonInstances.keys()],
|
|
12069
12074
|
getDataPlanes: (addonId) => addonDataPlanes.get(addonId) ?? [],
|
|
12070
12075
|
resolveSecretViews: (addonId, args) => (0, _camstack_types_addon.resolveSecretViewsIn)(args, addonSecrets.get(addonId))
|
|
12071
12076
|
}));
|
|
@@ -11472,7 +11472,11 @@ function createChildAddonCallDispatch(deps) {
|
|
|
11472
11472
|
const method = call.method;
|
|
11473
11473
|
if (method == null) throw new Error(`child-addon-call: addon "${addonId}" settings call missing method`);
|
|
11474
11474
|
const addon = deps.getAddonInstance(addonId);
|
|
11475
|
-
if (addon == null)
|
|
11475
|
+
if (addon == null) {
|
|
11476
|
+
const hosted = deps.listAddonIds?.() ?? [];
|
|
11477
|
+
const hostedText = hosted.length > 0 ? ` (this runner hosts: ${hosted.join(", ")})` : "";
|
|
11478
|
+
throw new Error(`child-addon-call: addon "${addonId}" is not loaded in this runner${hostedText} — address an addon by its own id, not its execution group`);
|
|
11479
|
+
}
|
|
11476
11480
|
return dispatchSettings(addon, addonId, method, call.args ?? {});
|
|
11477
11481
|
}
|
|
11478
11482
|
case "data-planes": return deps.getDataPlanes(addonId);
|
|
@@ -12011,6 +12015,7 @@ async function main() {
|
|
|
12011
12015
|
getRouteProvider: (addonId) => addonRouteProviders.get(addonId) ?? null,
|
|
12012
12016
|
customActions: customActionRegistry,
|
|
12013
12017
|
getAddonInstance: (addonId) => loadedAddonInstances.get(addonId) ?? null,
|
|
12018
|
+
listAddonIds: () => [...loadedAddonInstances.keys()],
|
|
12014
12019
|
getDataPlanes: (addonId) => addonDataPlanes.get(addonId) ?? [],
|
|
12015
12020
|
resolveSecretViews: (addonId, args) => resolveSecretViewsIn(args, addonSecrets.get(addonId))
|
|
12016
12021
|
}));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ec as toNodeId, Ic as EventCategory, Ko as BaseAddon, dc as nodePin, wn as backupCapability, yi as mayWriteToLocation, za as storageOccupancyCapability } from "../../dist-CogtCQxu.mjs";
|
|
2
2
|
import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
|
|
3
|
-
import { _ as backupRecordStoresOf, a as BackupSnapshotRefusedError, d as ENCRYPTED_BACKUP_SUFFIX, f as generateBackupKeyPair, g as backupOrchestratorRecordKinds, i as BackupCancelledError, l as BackupKeyFormatError, m as parseBackupSecretKey, n as precheckRestoreKey, o as DEFAULT_BACKUP_DATABASES, p as parseBackupPublicKey, r as prepareRestoreArchive, s as SystemBackupService } from "../../restore-archive-
|
|
3
|
+
import { _ as backupRecordStoresOf, a as BackupSnapshotRefusedError, d as ENCRYPTED_BACKUP_SUFFIX, f as generateBackupKeyPair, g as backupOrchestratorRecordKinds, i as BackupCancelledError, l as BackupKeyFormatError, m as parseBackupSecretKey, n as precheckRestoreKey, o as DEFAULT_BACKUP_DATABASES, p as parseBackupPublicKey, r as prepareRestoreArchive, s as SystemBackupService } from "../../restore-archive-D_191hoC.mjs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import * as fs$1 from "node:fs";
|
|
6
6
|
import * as path$1 from "node:path";
|
|
@@ -34,12 +34,22 @@ export declare class CoreBlocksAddon extends BaseAddon {
|
|
|
34
34
|
private buildPowerSource;
|
|
35
35
|
private powerSourceDevices;
|
|
36
36
|
private buildRemote;
|
|
37
|
+
/** A driver's native media-player cap reads the device; the composer's own native holds no reading. */
|
|
38
|
+
private hasNativeMediaPlayer;
|
|
37
39
|
/**
|
|
38
40
|
* Precedence at DISPATCH (D963, D984): the redirect lives in the registry, so it
|
|
39
41
|
* holds for every caller. ONE slot, so the authorities compose: the remote's
|
|
40
42
|
* media-player redirect (when the remote runs) and the lock's door gate.
|
|
41
43
|
*/
|
|
42
44
|
private installDeviceCallRedirect;
|
|
45
|
+
/**
|
|
46
|
+
* The remote writes each of its devices' `media-player` slice itself: seeded
|
|
47
|
+
* once at boot (never awaited), refreshed when a device registers, a config
|
|
48
|
+
* is saved, a send lands, or a device that feeds the assumed state changes (its
|
|
49
|
+
* running-state, or the switch of its linked plug). Our own slice write is a
|
|
50
|
+
* `media-player` event, not one of those inputs, so it cannot loop.
|
|
51
|
+
*/
|
|
52
|
+
private armRemoteSlices;
|
|
43
53
|
private seedGate;
|
|
44
54
|
private deviceNames;
|
|
45
55
|
/** The linked door sensor's name, read from the stored customization on a refusal only. */
|
|
@@ -5653,6 +5653,10 @@ var RemoteService = class {
|
|
|
5653
5653
|
deps;
|
|
5654
5654
|
now;
|
|
5655
5655
|
sleep;
|
|
5656
|
+
/** Remote devices seen so far, and the plug each one waits on: who an input event affects. */
|
|
5657
|
+
plugOf = /* @__PURE__ */ new Map();
|
|
5658
|
+
sliceRuns = /* @__PURE__ */ new Map();
|
|
5659
|
+
slicePending = /* @__PURE__ */ new Set();
|
|
5656
5660
|
constructor(deps) {
|
|
5657
5661
|
this.deps = deps;
|
|
5658
5662
|
this.now = deps.now ?? Date.now;
|
|
@@ -5671,6 +5675,7 @@ var RemoteService = class {
|
|
|
5671
5675
|
detail: `no template "${config.layoutTemplateId}"`
|
|
5672
5676
|
};
|
|
5673
5677
|
await this.deps.store.write(deviceId, config);
|
|
5678
|
+
await this.refreshSlice(deviceId);
|
|
5674
5679
|
return { status: "saved" };
|
|
5675
5680
|
};
|
|
5676
5681
|
listCommands = async ({ deviceId }) => {
|
|
@@ -5703,6 +5708,60 @@ var RemoteService = class {
|
|
|
5703
5708
|
return this.run(deviceId, config, role, repeat);
|
|
5704
5709
|
};
|
|
5705
5710
|
/**
|
|
5711
|
+
* Writes the device's `media-player` slice from `assumedStatus`, but only
|
|
5712
|
+
* when the remote is what answers for it: a media player, no native source
|
|
5713
|
+
* (`hasNative`), and a power state the remote knows. Overlapping calls for a
|
|
5714
|
+
* device coalesce: one run in flight, one more pending. A failed write is
|
|
5715
|
+
* logged, never thrown — the next input change or send is the retry (D3).
|
|
5716
|
+
*/
|
|
5717
|
+
refreshSlice(deviceId) {
|
|
5718
|
+
const running = this.sliceRuns.get(deviceId);
|
|
5719
|
+
if (running !== void 0) {
|
|
5720
|
+
this.slicePending.add(deviceId);
|
|
5721
|
+
return running;
|
|
5722
|
+
}
|
|
5723
|
+
const run = this.drainSlice(deviceId).finally(() => {
|
|
5724
|
+
this.sliceRuns.delete(deviceId);
|
|
5725
|
+
});
|
|
5726
|
+
this.sliceRuns.set(deviceId, run);
|
|
5727
|
+
return run;
|
|
5728
|
+
}
|
|
5729
|
+
async drainSlice(deviceId) {
|
|
5730
|
+
do {
|
|
5731
|
+
this.slicePending.delete(deviceId);
|
|
5732
|
+
await this.writeSlice(deviceId);
|
|
5733
|
+
} while (this.slicePending.has(deviceId));
|
|
5734
|
+
}
|
|
5735
|
+
async writeSlice(deviceId) {
|
|
5736
|
+
try {
|
|
5737
|
+
if (this.deps.hasNative(deviceId)) return;
|
|
5738
|
+
if (!await this.deps.isMediaPlayer(deviceId)) return;
|
|
5739
|
+
this.plugOf.set(deviceId, await this.deps.plugDeviceOf(deviceId));
|
|
5740
|
+
const status = await this.statusOf(deviceId, false);
|
|
5741
|
+
if (status === null) return;
|
|
5742
|
+
await this.deps.slice.publish(deviceId, status);
|
|
5743
|
+
} catch (err) {
|
|
5744
|
+
this.deps.logger.warn("remote: the media-player slice could not be written", {
|
|
5745
|
+
tags: { deviceId },
|
|
5746
|
+
meta: { error: errorText(err) }
|
|
5747
|
+
});
|
|
5748
|
+
}
|
|
5749
|
+
}
|
|
5750
|
+
/** Boot: every remote device. */
|
|
5751
|
+
async refreshSlices() {
|
|
5752
|
+
for (const deviceId of await this.deps.slice.devices()) await this.refreshSlice(deviceId);
|
|
5753
|
+
}
|
|
5754
|
+
/**
|
|
5755
|
+
* A device's state changed: refresh the remote devices it feeds — the TV
|
|
5756
|
+
* itself (its running-state) and every TV whose linked plug it is. Any other
|
|
5757
|
+
* device costs no read.
|
|
5758
|
+
*/
|
|
5759
|
+
async onInputChanged(deviceId) {
|
|
5760
|
+
const affected = [];
|
|
5761
|
+
for (const [tv, plug] of this.plugOf) if (tv === deviceId || plug === deviceId) affected.push(tv);
|
|
5762
|
+
await Promise.all(affected.map((tv) => this.refreshSlice(tv)));
|
|
5763
|
+
}
|
|
5764
|
+
/**
|
|
5706
5765
|
* What the remote ASSUMES (the last power and mute it sent), or null when it
|
|
5707
5766
|
* knows neither. No plug, no running-state: that is `assumedStatus`.
|
|
5708
5767
|
*/
|
|
@@ -5713,7 +5772,7 @@ var RemoteService = class {
|
|
|
5713
5772
|
const assumedFields = [];
|
|
5714
5773
|
if (kept.power !== null) assumedFields.push("state");
|
|
5715
5774
|
if (kept.muted !== null) assumedFields.push("isMuted");
|
|
5716
|
-
return this.
|
|
5775
|
+
return this.buildStatus({
|
|
5717
5776
|
state: kept.power?.state ?? "standby",
|
|
5718
5777
|
assumedFields,
|
|
5719
5778
|
muted: kept.muted?.value ?? null,
|
|
@@ -5729,8 +5788,12 @@ var RemoteService = class {
|
|
|
5729
5788
|
* the assumption, and only while the device may be on.
|
|
5730
5789
|
*/
|
|
5731
5790
|
async assumedStatus(deviceId) {
|
|
5791
|
+
return this.statusOf(deviceId, true);
|
|
5792
|
+
}
|
|
5793
|
+
/** `forget`: whether a plug that is off drops the kept power guess (a read's side effect). */
|
|
5794
|
+
async statusOf(deviceId, forget) {
|
|
5732
5795
|
const kept = await this.readAssumed(deviceId);
|
|
5733
|
-
const truth = await this.powerTruth(deviceId);
|
|
5796
|
+
const truth = await this.powerTruth(deviceId, forget);
|
|
5734
5797
|
if (truth === null) return null;
|
|
5735
5798
|
const assumedFields = truth.assumed ? ["state"] : [];
|
|
5736
5799
|
const state = truth.state;
|
|
@@ -5738,7 +5801,7 @@ var RemoteService = class {
|
|
|
5738
5801
|
const mute = state === "off" ? null : kept.muted ?? null;
|
|
5739
5802
|
if (mute !== null) assumedFields.push("isMuted");
|
|
5740
5803
|
const config = await this.deps.store.read(deviceId);
|
|
5741
|
-
return this.
|
|
5804
|
+
return this.buildStatus({
|
|
5742
5805
|
state,
|
|
5743
5806
|
assumedFields,
|
|
5744
5807
|
muted: mute?.value ?? null,
|
|
@@ -5746,7 +5809,7 @@ var RemoteService = class {
|
|
|
5746
5809
|
sources: config.customButtons.map((b) => b.name)
|
|
5747
5810
|
});
|
|
5748
5811
|
}
|
|
5749
|
-
|
|
5812
|
+
buildStatus(input) {
|
|
5750
5813
|
return {
|
|
5751
5814
|
state: input.state,
|
|
5752
5815
|
stateSource: input.assumedFields.length > 0 ? "assumed" : "reported",
|
|
@@ -5796,7 +5859,7 @@ var RemoteService = class {
|
|
|
5796
5859
|
* standby; on contradicts an assumed `off`, which is dropped); then the
|
|
5797
5860
|
* remote's own assumption; a plug on with nothing sent is `standby`.
|
|
5798
5861
|
*/
|
|
5799
|
-
async powerTruth(deviceId) {
|
|
5862
|
+
async powerTruth(deviceId, forget = true) {
|
|
5800
5863
|
const running = await this.deps.runningState(deviceId);
|
|
5801
5864
|
if (running !== null) return {
|
|
5802
5865
|
state: running ? "on" : "off",
|
|
@@ -5806,7 +5869,7 @@ var RemoteService = class {
|
|
|
5806
5869
|
const plug = await this.deps.plugOn(deviceId);
|
|
5807
5870
|
const kept = await this.readAssumed(deviceId);
|
|
5808
5871
|
if (plug === false) {
|
|
5809
|
-
if (kept.power !== null) await this.deps.assumptions.write(deviceId, {
|
|
5872
|
+
if (forget && kept.power !== null) await this.deps.assumptions.write(deviceId, {
|
|
5810
5873
|
...kept,
|
|
5811
5874
|
power: null
|
|
5812
5875
|
});
|
|
@@ -5864,6 +5927,7 @@ var RemoteService = class {
|
|
|
5864
5927
|
at: this.now()
|
|
5865
5928
|
}
|
|
5866
5929
|
});
|
|
5930
|
+
await this.refreshSlice(deviceId);
|
|
5867
5931
|
}
|
|
5868
5932
|
return result;
|
|
5869
5933
|
}
|
|
@@ -5916,6 +5980,7 @@ var RemoteService = class {
|
|
|
5916
5980
|
}
|
|
5917
5981
|
}
|
|
5918
5982
|
await this.moveAssumption(deviceId, role, wantsState);
|
|
5983
|
+
await this.refreshSlice(deviceId);
|
|
5919
5984
|
return {
|
|
5920
5985
|
status: "sent",
|
|
5921
5986
|
sends: times
|
|
@@ -6232,6 +6297,76 @@ function reportedStatusOver(api, logger) {
|
|
|
6232
6297
|
}
|
|
6233
6298
|
};
|
|
6234
6299
|
}
|
|
6300
|
+
/** The cap whose runtime slice the remote writes for a device no native source reads. */
|
|
6301
|
+
var MEDIA_PLAYER_CAP = "media-player";
|
|
6302
|
+
/** A slice says the same when only its change stamp moved. */
|
|
6303
|
+
function sameStatus(a, b) {
|
|
6304
|
+
return JSON.stringify({
|
|
6305
|
+
...a,
|
|
6306
|
+
lastChangedAt: 0
|
|
6307
|
+
}) === JSON.stringify({
|
|
6308
|
+
...b,
|
|
6309
|
+
lastChangedAt: 0
|
|
6310
|
+
});
|
|
6311
|
+
}
|
|
6312
|
+
/**
|
|
6313
|
+
* The standard runtime-state path (`deviceState.setCapSlice`, the entry every
|
|
6314
|
+
* `setCapState` reaches). The current slice is read back from the hub, never
|
|
6315
|
+
* kept here, so a write that would change nothing is skipped without a cache.
|
|
6316
|
+
*/
|
|
6317
|
+
function remoteSliceWriterOver(settings, api) {
|
|
6318
|
+
return {
|
|
6319
|
+
devices: async () => {
|
|
6320
|
+
const ids = await settings.listDeviceStoreIds();
|
|
6321
|
+
if (ids.length === 0) return [];
|
|
6322
|
+
const rows = await settings.readDeviceStoreBatch(ids);
|
|
6323
|
+
const carrying = [];
|
|
6324
|
+
for (const [deviceId, row] of rows) if (require_dist.RemoteConfigSchema.safeParse(row["remote"]).success) carrying.push(deviceId);
|
|
6325
|
+
return carrying;
|
|
6326
|
+
},
|
|
6327
|
+
publish: async (deviceId, status) => {
|
|
6328
|
+
const current = api();
|
|
6329
|
+
if (current === void 0) throw new Error("no ctx.api on this node");
|
|
6330
|
+
const kept = require_dist.MediaPlayerStatusSchema.safeParse(await current.deviceState.getCapSlice.query({
|
|
6331
|
+
deviceId,
|
|
6332
|
+
capName: MEDIA_PLAYER_CAP
|
|
6333
|
+
}));
|
|
6334
|
+
if (kept.success && sameStatus(kept.data, status)) return;
|
|
6335
|
+
await current.deviceState.setCapSlice.mutate({
|
|
6336
|
+
deviceId,
|
|
6337
|
+
capName: MEDIA_PLAYER_CAP,
|
|
6338
|
+
slice: { ...status }
|
|
6339
|
+
});
|
|
6340
|
+
}
|
|
6341
|
+
};
|
|
6342
|
+
}
|
|
6343
|
+
/** The device of the linked plug (`power-source`), null when none is linked or it errors. */
|
|
6344
|
+
function plugDeviceOver(api) {
|
|
6345
|
+
return async (deviceId) => {
|
|
6346
|
+
const current = api();
|
|
6347
|
+
if (current === void 0) return null;
|
|
6348
|
+
try {
|
|
6349
|
+
const parsed = require_dist.PowerSourceInfoSchema.safeParse(await current.powerSource.getStatus.query({ deviceId }));
|
|
6350
|
+
return parsed.success && parsed.data.linked ? parsed.data.switchDeviceId : null;
|
|
6351
|
+
} catch {
|
|
6352
|
+
return null;
|
|
6353
|
+
}
|
|
6354
|
+
};
|
|
6355
|
+
}
|
|
6356
|
+
/** The caps whose change can move the assumed state: the plug's switch and a running-state. */
|
|
6357
|
+
var REMOTE_SLICE_INPUT_CAPS = new Set(["switch", "running-state"]);
|
|
6358
|
+
/**
|
|
6359
|
+
* Seeds every remote device's slice ONCE at boot. No retry timer (D3): a read
|
|
6360
|
+
* that fails changes nothing, and `DeviceRegistered` and the input events
|
|
6361
|
+
* re-drive the refresh.
|
|
6362
|
+
*/
|
|
6363
|
+
async function seedRemoteSlices(remote, logger) {
|
|
6364
|
+
try {
|
|
6365
|
+
await remote.refreshSlices();
|
|
6366
|
+
} catch (error) {
|
|
6367
|
+
logger.warn("remote: the media-player slices could not be seeded at boot", { meta: { error: error instanceof Error ? error.message : String(error) } });
|
|
6368
|
+
}
|
|
6369
|
+
}
|
|
6235
6370
|
function buildRemoteRuntime(deps) {
|
|
6236
6371
|
const templateRows = deps.records.kind(coreBlocksRecordKinds.templates);
|
|
6237
6372
|
return {
|
|
@@ -6251,6 +6386,9 @@ function buildRemoteRuntime(deps) {
|
|
|
6251
6386
|
runningState: runningStateOver(deps.api, deps.logger.child("remote")),
|
|
6252
6387
|
plugOn: plugOnOver(deps.api, deps.logger.child("remote")),
|
|
6253
6388
|
assumptions: remoteAssumptionStoreOver(deps.settings, deps.logger.child("remote")),
|
|
6389
|
+
slice: remoteSliceWriterOver(deps.settings, deps.api),
|
|
6390
|
+
hasNative: deps.hasNative,
|
|
6391
|
+
plugDeviceOf: plugDeviceOver(deps.api),
|
|
6254
6392
|
logger: deps.logger.child("remote"),
|
|
6255
6393
|
...deps.sleep === void 0 ? {} : { sleep: deps.sleep },
|
|
6256
6394
|
...deps.now === void 0 ? {} : { now: deps.now }
|
|
@@ -7686,6 +7824,7 @@ var CoreBlocksAddon = class extends require_dist.BaseAddon {
|
|
|
7686
7824
|
this.remoteRuntime = this.buildRemote(records);
|
|
7687
7825
|
this.fanPresets = this.buildFanPresets();
|
|
7688
7826
|
this.installDeviceCallRedirect();
|
|
7827
|
+
this.armRemoteSlices();
|
|
7689
7828
|
const timedRun = buildTimedRunService({
|
|
7690
7829
|
records,
|
|
7691
7830
|
settings: () => this.ctx.settings,
|
|
@@ -7794,9 +7933,15 @@ var CoreBlocksAddon = class extends require_dist.BaseAddon {
|
|
|
7794
7933
|
records,
|
|
7795
7934
|
settings,
|
|
7796
7935
|
api: () => this.ctx.api,
|
|
7797
|
-
logger: this.ctx.logger
|
|
7936
|
+
logger: this.ctx.logger,
|
|
7937
|
+
hasNative: (deviceId) => this.hasNativeMediaPlayer(deviceId)
|
|
7798
7938
|
});
|
|
7799
7939
|
}
|
|
7940
|
+
/** A driver's native media-player cap reads the device; the composer's own native holds no reading. */
|
|
7941
|
+
hasNativeMediaPlayer(deviceId) {
|
|
7942
|
+
const owner = this.ctx.kernel?.capabilityRegistry?.getNativeAddonId("media-player", deviceId);
|
|
7943
|
+
return owner !== void 0 && owner !== null && owner !== "composer";
|
|
7944
|
+
}
|
|
7800
7945
|
/**
|
|
7801
7946
|
* Precedence at DISPATCH (D963, D984): the redirect lives in the registry, so it
|
|
7802
7947
|
* holds for every caller. ONE slot, so the authorities compose: the remote's
|
|
@@ -7818,13 +7963,30 @@ var CoreBlocksAddon = class extends require_dist.BaseAddon {
|
|
|
7818
7963
|
const runtime = this.remoteRuntime;
|
|
7819
7964
|
registry.setDeviceCallRedirect(composeRedirects([...runtime === null ? [] : [remoteCallRedirect({
|
|
7820
7965
|
remote: runtime.remote,
|
|
7821
|
-
hasNative: (deviceId) =>
|
|
7822
|
-
const owner = registry.getNativeAddonId("media-player", deviceId);
|
|
7823
|
-
return owner !== null && owner !== "composer";
|
|
7824
|
-
},
|
|
7966
|
+
hasNative: (deviceId) => this.hasNativeMediaPlayer(deviceId),
|
|
7825
7967
|
logger: this.ctx.logger.child("remote")
|
|
7826
7968
|
})], gate.redirect()]));
|
|
7827
7969
|
}
|
|
7970
|
+
/**
|
|
7971
|
+
* The remote writes each of its devices' `media-player` slice itself: seeded
|
|
7972
|
+
* once at boot (never awaited), refreshed when a device registers, a config
|
|
7973
|
+
* is saved, a send lands, or a device that feeds the assumed state changes (its
|
|
7974
|
+
* running-state, or the switch of its linked plug). Our own slice write is a
|
|
7975
|
+
* `media-player` event, not one of those inputs, so it cannot loop.
|
|
7976
|
+
*/
|
|
7977
|
+
armRemoteSlices() {
|
|
7978
|
+
const remote = this.remoteRuntime?.remote;
|
|
7979
|
+
if (remote === void 0) return;
|
|
7980
|
+
seedRemoteSlices(remote, this.ctx.logger.child("remote"));
|
|
7981
|
+
this.subscribe({ category: require_dist.EventCategory.DeviceRegistered }, (event) => {
|
|
7982
|
+
const deviceId = require_composition_sources.isRecord(event.data) ? event.data["deviceId"] : void 0;
|
|
7983
|
+
if (typeof deviceId === "number") remote.refreshSlice(deviceId);
|
|
7984
|
+
});
|
|
7985
|
+
this.subscribe({ category: require_dist.EventCategory.DeviceStateChanged }, (event) => {
|
|
7986
|
+
const data = require_composition_sources.parseDeviceStateChanged(event.data);
|
|
7987
|
+
if (data !== null && REMOTE_SLICE_INPUT_CAPS.has(data.capName)) remote.onInputChanged(data.deviceId);
|
|
7988
|
+
});
|
|
7989
|
+
}
|
|
7828
7990
|
seedGate(gate) {
|
|
7829
7991
|
const api = this.ctx.api;
|
|
7830
7992
|
if (!api) return;
|