@air-jam/devtools 0.9.3 → 1.0.0-beta.1
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/README.md +60 -0
- package/dist/{chunk-VKMJO6VN.js → chunk-2O67AXCU.js} +150 -40
- package/dist/chunk-2O67AXCU.js.map +1 -0
- package/dist/chunk-AO3ZDXF6.js +142 -0
- package/dist/chunk-AO3ZDXF6.js.map +1 -0
- package/dist/chunk-ART5TEYT.js +472 -0
- package/dist/chunk-ART5TEYT.js.map +1 -0
- package/dist/chunk-ASC2CK2R.js +77 -0
- package/dist/chunk-ASC2CK2R.js.map +1 -0
- package/dist/chunk-E3UZZGAV.js +50 -0
- package/dist/chunk-E3UZZGAV.js.map +1 -0
- package/dist/chunk-EJTE7UKX.js +64 -0
- package/dist/chunk-EJTE7UKX.js.map +1 -0
- package/dist/chunk-ESFKNN75.js +110 -0
- package/dist/chunk-ESFKNN75.js.map +1 -0
- package/dist/chunk-EU7A6PXW.js +1339 -0
- package/dist/chunk-EU7A6PXW.js.map +1 -0
- package/dist/chunk-FN7E6EA7.js +549 -0
- package/dist/chunk-FN7E6EA7.js.map +1 -0
- package/dist/chunk-GDFAWHGA.js +190 -0
- package/dist/chunk-GDFAWHGA.js.map +1 -0
- package/dist/chunk-HZUGBH4Y.js +347 -0
- package/dist/chunk-HZUGBH4Y.js.map +1 -0
- package/dist/chunk-ITKAOEGX.js +93 -0
- package/dist/chunk-ITKAOEGX.js.map +1 -0
- package/dist/chunk-JBCUTWRI.js +897 -0
- package/dist/chunk-JBCUTWRI.js.map +1 -0
- package/dist/chunk-JSI5S4WP.js +1174 -0
- package/dist/chunk-JSI5S4WP.js.map +1 -0
- package/dist/chunk-L4D675BG.js +97 -0
- package/dist/chunk-L4D675BG.js.map +1 -0
- package/dist/chunk-M6CJ7GQC.js +133 -0
- package/dist/chunk-M6CJ7GQC.js.map +1 -0
- package/dist/{chunk-CKFT2ZJE.js → chunk-MEIMOSZC.js} +53 -105
- package/dist/chunk-MEIMOSZC.js.map +1 -0
- package/dist/{chunk-GUEZP773.js → chunk-O3XG3FNL.js} +204 -41
- package/dist/chunk-O3XG3FNL.js.map +1 -0
- package/dist/chunk-OM6SCJ7H.js +18 -0
- package/dist/chunk-OM6SCJ7H.js.map +1 -0
- package/dist/chunk-PKD4WVX5.js +63 -0
- package/dist/chunk-PKD4WVX5.js.map +1 -0
- package/dist/chunk-PMBLXGFM.js +3384 -0
- package/dist/chunk-PMBLXGFM.js.map +1 -0
- package/dist/chunk-PMNE5GIN.js +279 -0
- package/dist/chunk-PMNE5GIN.js.map +1 -0
- package/dist/chunk-QAWI64VR.js +148 -0
- package/dist/chunk-QAWI64VR.js.map +1 -0
- package/dist/chunk-QGADSPHZ.js +449 -0
- package/dist/chunk-QGADSPHZ.js.map +1 -0
- package/dist/chunk-SPYN66UV.js +338 -0
- package/dist/chunk-SPYN66UV.js.map +1 -0
- package/dist/context.d.ts +9 -3
- package/dist/context.js +2 -1
- package/dist/controller.d.ts +33 -7
- package/dist/controller.js +18 -8
- package/dist/dependencies.d.ts +44 -0
- package/dist/dependencies.js +10 -0
- package/dist/dev.d.ts +9 -3
- package/dist/dev.js +3 -4
- package/dist/game-builds.d.ts +200 -0
- package/dist/game-builds.js +16 -0
- package/dist/game-builds.js.map +1 -0
- package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
- package/dist/game-runs.d.ts +1452 -0
- package/dist/game-runs.js +76 -0
- package/dist/game-runs.js.map +1 -0
- package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
- package/dist/game-session-broker.d.ts +4 -57
- package/dist/game-session-broker.js +33 -228
- package/dist/game-session-broker.js.map +1 -1
- package/dist/game-session.d.ts +3931 -10
- package/dist/game-session.js +186 -15
- package/dist/game-session.js.map +1 -1
- package/dist/game-settings.d.ts +16 -0
- package/dist/game-settings.js +237 -0
- package/dist/game-settings.js.map +1 -0
- package/dist/games.d.ts +11 -4
- package/dist/games.js +4 -2
- package/dist/harness/visual.d.ts +34 -151
- package/dist/harness/visual.js +6 -1
- package/dist/logs.d.ts +8 -2
- package/dist/logs.js +3 -4
- package/dist/logs.js.map +1 -1
- package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
- package/dist/mcp-config.js +2 -1
- package/dist/mcp-config.js.map +1 -1
- package/dist/platform-auth.d.ts +8 -111
- package/dist/platform-auth.js +9 -1
- package/dist/platform-game-analytics.d.ts +51 -0
- package/dist/platform-game-analytics.js +49 -0
- package/dist/platform-game-analytics.js.map +1 -0
- package/dist/platform-game-app-id.d.ts +46 -0
- package/dist/platform-game-app-id.js +93 -0
- package/dist/platform-game-app-id.js.map +1 -0
- package/dist/platform-game-media.d.ts +40 -2
- package/dist/platform-game-media.js +1 -1
- package/dist/platform-games.d.ts +24 -2
- package/dist/platform-games.js +16 -84
- package/dist/platform-games.js.map +1 -1
- package/dist/quality.d.ts +9 -3
- package/dist/quality.js +3 -4
- package/dist/quality.js.map +1 -1
- package/dist/release.d.ts +226 -16
- package/dist/release.js +18 -1331
- package/dist/release.js.map +1 -1
- package/dist/rooms-check.d.ts +90 -0
- package/dist/rooms-check.js +717 -0
- package/dist/rooms-check.js.map +1 -0
- package/dist/source-tree-contract.d.ts +16 -0
- package/dist/source-tree-contract.js +13 -0
- package/dist/source-tree-contract.js.map +1 -0
- package/dist/testing.d.ts +464 -0
- package/dist/testing.js +27 -0
- package/dist/testing.js.map +1 -0
- package/dist/tooling/describe-game.js +54 -0
- package/dist/tooling/describe-game.js.map +1 -0
- package/dist/tooling/game-session-broker.js +28 -0
- package/dist/tooling/game-session-broker.js.map +1 -0
- package/dist/tooling/hold-runtime-host.js +769 -67
- package/dist/tooling/hold-runtime-host.js.map +1 -1
- package/dist/tooling/list-visual-scenarios.js +18 -55
- package/dist/tooling/list-visual-scenarios.js.map +1 -1
- package/dist/tooling/process-scope-bootstrap.mjs +24 -0
- package/dist/tooling/process-scope-guard.d.ts +2 -0
- package/dist/tooling/process-scope-guard.js +388 -0
- package/dist/tooling/process-scope-guard.js.map +1 -0
- package/dist/tooling/process-scope-windows.ps1 +148 -0
- package/dist/tooling/rooms-check-device.d.ts +2 -0
- package/dist/tooling/rooms-check-device.js +498 -0
- package/dist/tooling/rooms-check-device.js.map +1 -0
- package/dist/tooling/run-headless-room.d.ts +2 -0
- package/dist/tooling/run-headless-room.js +287 -0
- package/dist/tooling/run-headless-room.js.map +1 -0
- package/dist/tooling/run-test-profile.d.ts +2 -0
- package/dist/tooling/run-test-profile.js +181 -0
- package/dist/tooling/run-test-profile.js.map +1 -0
- package/dist/tooling/run-visual-capture.js +70 -34
- package/dist/tooling/run-visual-capture.js.map +1 -1
- package/dist/tooling/seal-game-build.d.ts +2 -0
- package/dist/tooling/seal-game-build.js +120 -0
- package/dist/tooling/seal-game-build.js.map +1 -0
- package/dist/{types-C6NrHt88.d.ts → types-CdYrgrG_.d.ts} +337 -76
- package/dist/types-DyRD-ym1.d.ts +141 -0
- package/dist/visual.d.ts +9 -3
- package/dist/visual.js +24 -68
- package/dist/visual.js.map +1 -1
- package/package.json +51 -14
- package/src/bounded-response.ts +28 -0
- package/src/built-game-runtime.ts +152 -0
- package/src/context.ts +2 -13
- package/src/controller-protocol.ts +22 -0
- package/src/controller.ts +747 -597
- package/src/current-room-host.ts +166 -0
- package/src/decision-provider.ts +102 -0
- package/src/dependencies.ts +176 -0
- package/src/dependency-install-contract.ts +12 -0
- package/src/dev.ts +46 -50
- package/src/game-action-observation.ts +11 -1
- package/src/game-build-protocol.ts +72 -0
- package/src/game-build.ts +483 -0
- package/src/game-run-owner.ts +2358 -0
- package/src/game-run-protocol.ts +448 -0
- package/src/game-run-record.ts +92 -0
- package/src/game-run-replay.ts +95 -0
- package/src/game-run-watch.ts +155 -0
- package/src/game-session-broker.ts +689 -197
- package/src/game-session-operations.ts +61 -0
- package/src/game-session-protocol.ts +180 -0
- package/src/game-session-runtime.ts +861 -0
- package/src/game-session.ts +164 -417
- package/src/game-settings.ts +295 -0
- package/src/games.ts +88 -92
- package/src/harness/visual/browser.ts +100 -0
- package/src/harness/visual/controller-observation.ts +181 -0
- package/src/harness/visual/runner.ts +24 -21
- package/src/harness/visual/runtime-controller-observations.ts +151 -0
- package/src/harness/visual/scenario-contract.ts +1 -2
- package/src/harness/visual/scenario-helpers.ts +5 -1
- package/src/harness/visual/screencast.ts +155 -0
- package/src/harness/visual/session.ts +72 -41
- package/src/harness/visual/types.ts +8 -5
- package/src/headless-room-protocol.ts +112 -0
- package/src/headless-room.ts +222 -0
- package/src/helper-channel.ts +229 -0
- package/src/helper-scripts.ts +25 -5
- package/src/installed-dependencies.ts +74 -0
- package/src/managed-process-scope.ts +481 -0
- package/src/node-process-environment.ts +10 -0
- package/src/platform-auth.ts +194 -55
- package/src/platform-game-analytics.ts +50 -0
- package/src/platform-game-app-id.ts +99 -0
- package/src/platform-games.ts +13 -111
- package/src/policy-artifact-contract.ts +52 -0
- package/src/policy-artifacts.ts +134 -0
- package/src/process-scope-admission.ts +50 -0
- package/src/process-scope-protocol.ts +66 -0
- package/src/process-scope.ts +327 -0
- package/src/release.ts +28 -42
- package/src/rooms-check-fleet.ts +194 -0
- package/src/rooms-check-link.ts +138 -0
- package/src/rooms-check-protocol.ts +244 -0
- package/src/rooms-check.ts +797 -0
- package/src/runtime-owner-protocol.ts +106 -18
- package/src/source-tree-contract.ts +70 -0
- package/src/source-tree.ts +84 -0
- package/src/test-profile-process.ts +153 -0
- package/src/test-profile-protocol.ts +116 -0
- package/src/testing.ts +430 -0
- package/src/tooling/declaration-hook.ts +52 -0
- package/src/tooling/describe-game.ts +49 -0
- package/src/tooling/game-session-broker.ts +7 -0
- package/src/tooling/hold-runtime-host.ts +255 -38
- package/src/tooling/list-visual-scenarios.ts +19 -62
- package/src/tooling/load-game.ts +79 -0
- package/src/tooling/process-scope-bootstrap.mjs +24 -0
- package/src/tooling/process-scope-guard.ts +213 -0
- package/src/tooling/process-scope-windows.ps1 +148 -0
- package/src/tooling/rooms-check-device.ts +493 -0
- package/src/tooling/run-headless-room.ts +326 -0
- package/src/tooling/run-test-profile.ts +190 -0
- package/src/tooling/run-visual-capture.ts +37 -23
- package/src/tooling/runtime-owner-actions.ts +23 -0
- package/src/tooling/seal-game-build.ts +118 -0
- package/src/tooling/visual-pack.ts +10 -45
- package/src/types.ts +54 -77
- package/src/visual.ts +14 -22
- package/src/windows-process-scopes.ts +189 -0
- package/dist/agent.d.ts +0 -15
- package/dist/agent.js +0 -19
- package/dist/chunk-5YAARMW5.js +0 -36
- package/dist/chunk-5YAARMW5.js.map +0 -1
- package/dist/chunk-6WQODT37.js +0 -1019
- package/dist/chunk-6WQODT37.js.map +0 -1
- package/dist/chunk-CKFT2ZJE.js.map +0 -1
- package/dist/chunk-ER3Q2C4G.js +0 -358
- package/dist/chunk-ER3Q2C4G.js.map +0 -1
- package/dist/chunk-GUEZP773.js.map +0 -1
- package/dist/chunk-HIDNI56E.js +0 -33
- package/dist/chunk-HIDNI56E.js.map +0 -1
- package/dist/chunk-QKXS5D35.js +0 -43
- package/dist/chunk-QKXS5D35.js.map +0 -1
- package/dist/chunk-S4LSCEVE.js +0 -261
- package/dist/chunk-S4LSCEVE.js.map +0 -1
- package/dist/chunk-VKMJO6VN.js.map +0 -1
- package/dist/chunk-WFUR3MXY.js +0 -67
- package/dist/chunk-WFUR3MXY.js.map +0 -1
- package/dist/chunk-XEMR7KUE.js +0 -361
- package/dist/chunk-XEMR7KUE.js.map +0 -1
- package/dist/chunk-ZLPD7FY5.js +0 -191
- package/dist/chunk-ZLPD7FY5.js.map +0 -1
- package/dist/tooling/agent-contract.js +0 -193
- package/dist/tooling/agent-contract.js.map +0 -1
- package/dist/tooling/inspect-airjam-agent.js +0 -37
- package/dist/tooling/inspect-airjam-agent.js.map +0 -1
- package/src/agent.ts +0 -380
- package/src/tooling/agent-contract.ts +0 -232
- package/src/tooling/agent-declaration.ts +0 -36
- package/src/tooling/airjam-agent-inspection.ts +0 -45
- package/src/tooling/airjam-agent.ts +0 -118
- package/src/tooling/inspect-airjam-agent.ts +0 -20
- /package/dist/{agent.js.map → dependencies.js.map} +0 -0
- /package/dist/tooling/{agent-contract.d.ts → describe-game.d.ts} +0 -0
- /package/dist/tooling/{inspect-airjam-agent.d.ts → game-session-broker.d.ts} +0 -0
package/src/controller.ts
CHANGED
|
@@ -5,44 +5,79 @@ import {
|
|
|
5
5
|
embeddedReplicatedStoreDomainFromArcadeIdentity,
|
|
6
6
|
localReferenceSourceGameId,
|
|
7
7
|
} from "@air-jam/sdk/arcade/surface";
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
ServerToClientEvents,
|
|
20
|
-
SignalPayload,
|
|
8
|
+
import {
|
|
9
|
+
agentValuesToInputState,
|
|
10
|
+
airJamActionResultOf,
|
|
11
|
+
type AirJamInput,
|
|
12
|
+
type AirJamInputState,
|
|
13
|
+
} from "@air-jam/sdk/core";
|
|
14
|
+
import {
|
|
15
|
+
controllerLeasedControlAckSchema,
|
|
16
|
+
leasedControlRequestSchema,
|
|
17
|
+
type ControllerLeasedControlAck,
|
|
18
|
+
type LeasedControlRequest,
|
|
21
19
|
} from "@air-jam/sdk/protocol";
|
|
22
|
-
import
|
|
23
|
-
|
|
20
|
+
import {
|
|
21
|
+
AIRJAM_CONTROL_CHANNEL,
|
|
22
|
+
AIRJAM_LEASED_CONTROL_REQUEST,
|
|
23
|
+
AIRJAM_PRESENTATION_CHANNEL,
|
|
24
|
+
encodeInputPayload,
|
|
25
|
+
encodePhoneInputFrame,
|
|
26
|
+
type RoomLink,
|
|
27
|
+
type StateDocument,
|
|
28
|
+
} from "@air-jam/sdk/room-protocol";
|
|
29
|
+
import {
|
|
30
|
+
createRoomKey,
|
|
31
|
+
createScopedPhoneConnector,
|
|
32
|
+
createWebSocketConnector,
|
|
33
|
+
PhoneRoomSession,
|
|
34
|
+
serveRoomPort,
|
|
35
|
+
type RoomSessionStatus,
|
|
36
|
+
} from "@air-jam/sdk/room-session";
|
|
37
|
+
import type {
|
|
38
|
+
HostAgentRequest,
|
|
39
|
+
HostAgentResponse,
|
|
40
|
+
HostRuntimeActionRequest,
|
|
41
|
+
} from "@air-jam/sdk/runtime-control";
|
|
42
|
+
import {
|
|
43
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY,
|
|
44
|
+
readRuntimeInspectionContract,
|
|
45
|
+
type HostRuntimeInspectionContract,
|
|
46
|
+
} from "@air-jam/sdk/runtime-inspection";
|
|
47
|
+
import { parseRuntimeTopologyFromSearchParams } from "@air-jam/sdk/runtime-topology";
|
|
24
48
|
import type { ChildProcess } from "node:child_process";
|
|
25
|
-
import { spawn } from "node:child_process";
|
|
26
49
|
import { randomUUID } from "node:crypto";
|
|
27
|
-
import {
|
|
50
|
+
import { z } from "zod";
|
|
28
51
|
import { detectProjectContext } from "./context.js";
|
|
29
52
|
import { getTopology } from "./dev.js";
|
|
53
|
+
import type { PinnedGameBuild } from "./game-build-protocol.js";
|
|
54
|
+
import type { GameSurfaceWatchEvent } from "./game-run-watch.js";
|
|
30
55
|
import { inspectGame } from "./games.js";
|
|
31
56
|
import {
|
|
32
57
|
resolveDevtoolsHelperArgs,
|
|
33
58
|
resolveDevtoolsHelperScript,
|
|
59
|
+
resolveProjectDevtoolsHelperScript,
|
|
34
60
|
} from "./helper-scripts.js";
|
|
61
|
+
import {
|
|
62
|
+
closeScopedProcess,
|
|
63
|
+
spawnScopedProcess,
|
|
64
|
+
type ProcessScopeObserver,
|
|
65
|
+
} from "./managed-process-scope.js";
|
|
35
66
|
import {
|
|
36
67
|
AIR_JAM_RUNTIME_OWNER_ACTION_REQUEST,
|
|
68
|
+
AIR_JAM_RUNTIME_OWNER_CAPTURE_PORT,
|
|
37
69
|
AIR_JAM_RUNTIME_OWNER_CAPTURE_REQUEST,
|
|
38
70
|
isRuntimeOwnerActionResult,
|
|
39
71
|
isRuntimeOwnerCaptureResult,
|
|
72
|
+
runtimeOwnerAgentResultSchema,
|
|
73
|
+
runtimeOwnerCaptureFrameSchema,
|
|
74
|
+
runtimeOwnerWatchEventSchema,
|
|
40
75
|
type AirJamRuntimeOwnerCaptureResult,
|
|
41
76
|
} from "./runtime-owner-protocol.js";
|
|
42
77
|
import type {
|
|
78
|
+
AirJamGameInspection,
|
|
43
79
|
AirJamProjectMode,
|
|
44
80
|
AirJamRuntimeSnapshotInspection,
|
|
45
|
-
AirJamRuntimeStoreSnapshot,
|
|
46
81
|
AirJamVirtualControllerSession,
|
|
47
82
|
AirJamVirtualControllerSessionSummary,
|
|
48
83
|
ConnectControllerOptions,
|
|
@@ -72,28 +107,22 @@ export type {
|
|
|
72
107
|
SendControllerInputResult,
|
|
73
108
|
} from "./types.js";
|
|
74
109
|
|
|
75
|
-
type ControllerSocket = Socket<ServerToClientEvents, ClientToServerEvents>;
|
|
76
|
-
|
|
77
|
-
type PendingStateSyncWaiter = {
|
|
78
|
-
requestId: string;
|
|
79
|
-
minimumRevision: number;
|
|
80
|
-
resolve: (snapshot: AirJamRuntimeStoreSnapshot | null) => void;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
110
|
type InternalControllerSession = {
|
|
84
111
|
cwd: string;
|
|
85
112
|
summary: AirJamVirtualControllerSessionSummary;
|
|
86
|
-
|
|
113
|
+
room: PhoneRoomSession;
|
|
87
114
|
projectMode: AirJamProjectMode;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
players: JsonObject[];
|
|
91
|
-
storeSnapshots: Map<string, AirJamRuntimeStoreSnapshot>;
|
|
92
|
-
pendingSyncWaiters: Map<string, Set<PendingStateSyncWaiter>>;
|
|
115
|
+
/** When each channel this phone mirrors last changed, and how many times. */
|
|
116
|
+
storeUpdates: Map<string, { revision: number; updatedAt: string }>;
|
|
93
117
|
lastSignal: JsonObject | null;
|
|
94
118
|
lastError: JsonObject | null;
|
|
95
119
|
isolatedRuntimeOwner: ChildProcess | null;
|
|
96
|
-
|
|
120
|
+
participantLeaseId: string | null;
|
|
121
|
+
participantLastCommand: LeasedControlRequest | null;
|
|
122
|
+
/** The controls this session last sent, so buttons count presses. */
|
|
123
|
+
inputState: AirJamInputState | null;
|
|
124
|
+
/** The game's declared controls, read once the first input is sent; null when the game declares none. */
|
|
125
|
+
inputLayout: AirJamInput | null | undefined;
|
|
97
126
|
};
|
|
98
127
|
|
|
99
128
|
const DEFAULT_TIMEOUT_MS = 5_000;
|
|
@@ -112,47 +141,6 @@ const toJsonObject = (value: unknown): JsonObject | null => {
|
|
|
112
141
|
return { ...value };
|
|
113
142
|
};
|
|
114
143
|
|
|
115
|
-
const toJsonObjectArray = (value: unknown): JsonObject[] => {
|
|
116
|
-
if (!Array.isArray(value)) {
|
|
117
|
-
return [];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return value.flatMap((entry) => {
|
|
121
|
-
const objectValue = toJsonObject(entry);
|
|
122
|
-
return objectValue ? [objectValue] : [];
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const upsertPlayer = (
|
|
127
|
-
players: JsonObject[],
|
|
128
|
-
incoming: PlayerProfile | JsonObject | null,
|
|
129
|
-
): JsonObject[] => {
|
|
130
|
-
const nextPlayer = toJsonObject(incoming);
|
|
131
|
-
const playerId =
|
|
132
|
-
typeof nextPlayer?.id === "string" && nextPlayer.id ? nextPlayer.id : null;
|
|
133
|
-
if (!nextPlayer || !playerId) {
|
|
134
|
-
return players;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const nextPlayers = players.slice();
|
|
138
|
-
const existingIndex = nextPlayers.findIndex((entry) => entry.id === playerId);
|
|
139
|
-
if (existingIndex === -1) {
|
|
140
|
-
nextPlayers.push(nextPlayer);
|
|
141
|
-
return nextPlayers;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
nextPlayers[existingIndex] = {
|
|
145
|
-
...nextPlayers[existingIndex],
|
|
146
|
-
...nextPlayer,
|
|
147
|
-
};
|
|
148
|
-
return nextPlayers;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const removePlayer = (
|
|
152
|
-
players: JsonObject[],
|
|
153
|
-
controllerId: string,
|
|
154
|
-
): JsonObject[] => players.filter((entry) => entry.id !== controllerId);
|
|
155
|
-
|
|
156
144
|
const nowIso = (): string => new Date().toISOString();
|
|
157
145
|
|
|
158
146
|
const waitForCondition = async ({
|
|
@@ -171,114 +159,45 @@ const waitForCondition = async ({
|
|
|
171
159
|
}
|
|
172
160
|
};
|
|
173
161
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
await new Promise<void>((resolve, reject) => {
|
|
183
|
-
const timeout = setTimeout(() => {
|
|
184
|
-
cleanup();
|
|
185
|
-
reject(new Error("Timed out waiting for controller socket connect."));
|
|
186
|
-
}, timeoutMs);
|
|
187
|
-
|
|
188
|
-
const onConnect = () => {
|
|
189
|
-
cleanup();
|
|
190
|
-
resolve();
|
|
162
|
+
/** Waits until the phone's room welcomes it, or ends with why it could not join. */
|
|
163
|
+
const waitForWelcome = (room: PhoneRoomSession, timeoutMs: number) =>
|
|
164
|
+
new Promise<void>((resolve, reject) => {
|
|
165
|
+
const settle = (status: RoomSessionStatus) => {
|
|
166
|
+
if (status.phase === "open") finish();
|
|
167
|
+
else if (status.phase === "closed")
|
|
168
|
+
finish(new Error(`Controller join was refused (${status.reason}).`));
|
|
191
169
|
};
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
reject(error);
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const cleanup = () => {
|
|
199
|
-
clearTimeout(timeout);
|
|
200
|
-
socket.off("connect", onConnect);
|
|
201
|
-
socket.off("connect_error", onConnectError);
|
|
170
|
+
const finish = (error?: Error) => {
|
|
171
|
+
clearTimeout(timer);
|
|
172
|
+
stop();
|
|
173
|
+
if (error) reject(error);
|
|
174
|
+
else resolve();
|
|
202
175
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
socket: ControllerSocket;
|
|
215
|
-
payload: Parameters<ClientToServerEvents["controller:join"]>[0];
|
|
216
|
-
timeoutMs: number;
|
|
217
|
-
}): Promise<ControllerJoinAck> =>
|
|
218
|
-
await new Promise<ControllerJoinAck>((resolve, reject) => {
|
|
219
|
-
const timeout = setTimeout(() => {
|
|
220
|
-
reject(
|
|
221
|
-
new Error("Timed out waiting for controller join acknowledgement."),
|
|
222
|
-
);
|
|
223
|
-
}, timeoutMs);
|
|
224
|
-
|
|
225
|
-
socket.emit("controller:join", payload, (ack) => {
|
|
226
|
-
clearTimeout(timeout);
|
|
227
|
-
resolve(ack);
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
const emitLeaveWithAck = async ({
|
|
232
|
-
socket,
|
|
233
|
-
payload,
|
|
234
|
-
timeoutMs,
|
|
235
|
-
}: {
|
|
236
|
-
socket: ControllerSocket;
|
|
237
|
-
payload: Parameters<ClientToServerEvents["controller:leave"]>[0];
|
|
238
|
-
timeoutMs: number;
|
|
239
|
-
}): Promise<ControllerLeaveAck> =>
|
|
240
|
-
await new Promise<ControllerLeaveAck>((resolve, reject) => {
|
|
241
|
-
const timeout = setTimeout(() => {
|
|
242
|
-
reject(
|
|
243
|
-
new Error("Timed out waiting for controller leave acknowledgement."),
|
|
244
|
-
);
|
|
245
|
-
}, timeoutMs);
|
|
246
|
-
|
|
247
|
-
(
|
|
248
|
-
socket as unknown as {
|
|
249
|
-
emit: (event: string, ...args: unknown[]) => void;
|
|
250
|
-
}
|
|
251
|
-
).emit("controller:leave", payload, (ack: ControllerLeaveAck) => {
|
|
252
|
-
clearTimeout(timeout);
|
|
253
|
-
resolve(ack);
|
|
254
|
-
});
|
|
176
|
+
const timer = setTimeout(
|
|
177
|
+
() =>
|
|
178
|
+
finish(
|
|
179
|
+
new Error(
|
|
180
|
+
"Timed out waiting for the room to welcome the controller.",
|
|
181
|
+
),
|
|
182
|
+
),
|
|
183
|
+
timeoutMs,
|
|
184
|
+
);
|
|
185
|
+
const stop = room.on("status", settle);
|
|
186
|
+
settle(room.status);
|
|
255
187
|
});
|
|
256
188
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
Parameters<
|
|
267
|
-
NonNullable<Parameters<ClientToServerEvents["controller:action_rpc"]>[1]>
|
|
268
|
-
>[0]
|
|
269
|
-
> =>
|
|
270
|
-
await new Promise((resolve, reject) => {
|
|
271
|
-
const timeout = setTimeout(() => {
|
|
272
|
-
reject(
|
|
273
|
-
new Error("Timed out waiting for controller action acknowledgement."),
|
|
274
|
-
);
|
|
275
|
-
}, timeoutMs);
|
|
276
|
-
|
|
277
|
-
socket.emit("controller:action_rpc", payload, (ack) => {
|
|
278
|
-
clearTimeout(timeout);
|
|
279
|
-
resolve(ack);
|
|
280
|
-
});
|
|
189
|
+
/** A channel's copy as this phone mirrors it, waiting up to `timeoutMs` for its first. */
|
|
190
|
+
const waitForChannel = async (
|
|
191
|
+
room: PhoneRoomSession,
|
|
192
|
+
channel: string,
|
|
193
|
+
timeoutMs: number,
|
|
194
|
+
): Promise<StateDocument | null> => {
|
|
195
|
+
await waitForCondition({
|
|
196
|
+
timeoutMs,
|
|
197
|
+
predicate: () => room.channel(channel) !== undefined,
|
|
281
198
|
});
|
|
199
|
+
return room.channel(channel) ?? null;
|
|
200
|
+
};
|
|
282
201
|
|
|
283
202
|
const requestOwnedHostAction = async ({
|
|
284
203
|
owner,
|
|
@@ -351,48 +270,7 @@ const parseJoinRoomId = (joinUrl: URL): string | null => {
|
|
|
351
270
|
return roomId?.trim().toUpperCase() || null;
|
|
352
271
|
};
|
|
353
272
|
|
|
354
|
-
const
|
|
355
|
-
joinUrl.searchParams.get("aj_controller_cap")?.trim() ||
|
|
356
|
-
joinUrl.searchParams.get("cap")?.trim() ||
|
|
357
|
-
null;
|
|
358
|
-
|
|
359
|
-
const parseJoinControllerId = (joinUrl: URL): string | null =>
|
|
360
|
-
joinUrl.searchParams.get("controllerId")?.trim() ||
|
|
361
|
-
joinUrl.searchParams.get("aj_controller_id")?.trim() ||
|
|
362
|
-
null;
|
|
363
|
-
|
|
364
|
-
const parseHelperJson = <T>(output: string): T => {
|
|
365
|
-
const startIndex = output.indexOf("{");
|
|
366
|
-
const endIndex = output.lastIndexOf("}");
|
|
367
|
-
if (startIndex === -1 || endIndex === -1 || endIndex < startIndex) {
|
|
368
|
-
throw new Error(`Expected JSON helper output but received:\n${output}`);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return JSON.parse(output.slice(startIndex, endIndex + 1)) as T;
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
const terminateIsolatedRuntimeOwner = async (
|
|
375
|
-
process: ChildProcess | null,
|
|
376
|
-
): Promise<void> => {
|
|
377
|
-
if (!process || process.killed || process.exitCode !== null) {
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
await new Promise<void>((resolve) => {
|
|
382
|
-
const onExit = () => {
|
|
383
|
-
process.off("exit", onExit);
|
|
384
|
-
resolve();
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
process.once("exit", onExit);
|
|
388
|
-
process.kill("SIGTERM");
|
|
389
|
-
|
|
390
|
-
setTimeout(() => {
|
|
391
|
-
process.off("exit", onExit);
|
|
392
|
-
resolve();
|
|
393
|
-
}, 1_000).unref();
|
|
394
|
-
});
|
|
395
|
-
};
|
|
273
|
+
const terminateIsolatedRuntimeOwner = closeScopedProcess;
|
|
396
274
|
|
|
397
275
|
const resolveSocketOriginFromTopology = async (
|
|
398
276
|
options: GetTopologyOptions,
|
|
@@ -434,14 +312,12 @@ const resolveControllerJoinUrlFromTopology = async ({
|
|
|
434
312
|
mode,
|
|
435
313
|
secure,
|
|
436
314
|
roomId,
|
|
437
|
-
capabilityToken,
|
|
438
315
|
}: {
|
|
439
316
|
cwd: string;
|
|
440
317
|
gameId?: string;
|
|
441
318
|
mode: NonNullable<ConnectControllerOptions["mode"]>;
|
|
442
319
|
secure: boolean;
|
|
443
320
|
roomId?: string;
|
|
444
|
-
capabilityToken?: string;
|
|
445
321
|
}): Promise<string | null> => {
|
|
446
322
|
if (!roomId) {
|
|
447
323
|
return null;
|
|
@@ -459,10 +335,6 @@ const resolveControllerJoinUrlFromTopology = async ({
|
|
|
459
335
|
|
|
460
336
|
const joinUrl = new URL(topology.urls.controllerBaseUrl);
|
|
461
337
|
joinUrl.searchParams.set("room", roomId);
|
|
462
|
-
if (capabilityToken?.trim()) {
|
|
463
|
-
joinUrl.searchParams.set("aj_controller_cap", capabilityToken.trim());
|
|
464
|
-
}
|
|
465
|
-
|
|
466
338
|
return joinUrl.toString();
|
|
467
339
|
};
|
|
468
340
|
|
|
@@ -472,8 +344,14 @@ const startIsolatedRuntimeOwner = async ({
|
|
|
472
344
|
mode,
|
|
473
345
|
secure,
|
|
474
346
|
timeoutMs,
|
|
347
|
+
build,
|
|
348
|
+
settings,
|
|
349
|
+
onScope,
|
|
475
350
|
}: {
|
|
351
|
+
settings?: Record<string, number | boolean | string>;
|
|
476
352
|
cwd: string;
|
|
353
|
+
onScope?: ProcessScopeObserver;
|
|
354
|
+
build?: PinnedGameBuild;
|
|
477
355
|
gameId?: string;
|
|
478
356
|
mode: NonNullable<ConnectControllerOptions["mode"]>;
|
|
479
357
|
secure: boolean;
|
|
@@ -484,52 +362,54 @@ const startIsolatedRuntimeOwner = async ({
|
|
|
484
362
|
controllerJoinUrl: string | null;
|
|
485
363
|
inspection: HostRuntimeInspectionContract | null;
|
|
486
364
|
}> => {
|
|
487
|
-
const topology =
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
365
|
+
const topology = build
|
|
366
|
+
? null
|
|
367
|
+
: await getTopology({
|
|
368
|
+
cwd,
|
|
369
|
+
gameId,
|
|
370
|
+
mode,
|
|
371
|
+
secure,
|
|
372
|
+
});
|
|
493
373
|
|
|
494
|
-
const appOrigin = topology
|
|
495
|
-
const hostUrl = topology
|
|
496
|
-
const controllerBaseUrl = topology
|
|
497
|
-
const publicHost = topology
|
|
498
|
-
if (!appOrigin || !hostUrl || !controllerBaseUrl || !publicHost) {
|
|
374
|
+
const appOrigin = topology?.urls.appOrigin;
|
|
375
|
+
const hostUrl = topology?.urls.hostUrl;
|
|
376
|
+
const controllerBaseUrl = topology?.urls.controllerBaseUrl;
|
|
377
|
+
const publicHost = topology?.urls.publicHost;
|
|
378
|
+
if (!build && (!appOrigin || !hostUrl || !controllerBaseUrl || !publicHost)) {
|
|
499
379
|
throw new Error(
|
|
500
380
|
"Unable to start an isolated runtime owner because the resolved topology is incomplete.",
|
|
501
381
|
);
|
|
502
382
|
}
|
|
503
383
|
|
|
504
|
-
const helperFile =
|
|
384
|
+
const helperFile = build
|
|
385
|
+
? resolveProjectDevtoolsHelperScript(build.rootDir, "hold-runtime-host.ts")
|
|
386
|
+
: resolveDevtoolsHelperScript("hold-runtime-host.ts");
|
|
505
387
|
const args = [
|
|
506
388
|
...resolveDevtoolsHelperArgs(helperFile),
|
|
507
|
-
"--app-origin",
|
|
508
|
-
appOrigin,
|
|
509
|
-
"--host-url",
|
|
510
|
-
hostUrl,
|
|
511
|
-
"--controller-base-url",
|
|
512
|
-
controllerBaseUrl,
|
|
513
|
-
"--public-host",
|
|
514
|
-
publicHost,
|
|
515
389
|
"--mode",
|
|
516
390
|
mode,
|
|
517
391
|
"--timeout-ms",
|
|
518
392
|
String(timeoutMs),
|
|
519
393
|
];
|
|
520
|
-
if (
|
|
521
|
-
|
|
394
|
+
if (settings) args.push("--settings", JSON.stringify(settings));
|
|
395
|
+
if (build) args.push("--pinned-build", build.manifestPath);
|
|
396
|
+
else {
|
|
397
|
+
for (const [flag, value] of [
|
|
398
|
+
["--app-origin", appOrigin],
|
|
399
|
+
["--host-url", hostUrl],
|
|
400
|
+
["--controller-base-url", controllerBaseUrl],
|
|
401
|
+
["--public-host", publicHost],
|
|
402
|
+
["--local-build-url", topology?.urls.localBuildUrl],
|
|
403
|
+
["--browser-build-url", topology?.urls.browserBuildUrl],
|
|
404
|
+
] as const)
|
|
405
|
+
if (value) args.push(flag, value);
|
|
522
406
|
}
|
|
523
|
-
|
|
524
|
-
args.push("--browser-build-url", topology.urls.browserBuildUrl);
|
|
525
|
-
}
|
|
526
|
-
const helperProcess = spawn(process.execPath, args, {
|
|
407
|
+
const helperProcess = await spawnScopedProcess(args, {
|
|
527
408
|
cwd,
|
|
528
|
-
|
|
409
|
+
onScope,
|
|
529
410
|
});
|
|
530
411
|
|
|
531
412
|
return await new Promise((resolve, reject) => {
|
|
532
|
-
let stdoutBuffer = "";
|
|
533
413
|
let stderrBuffer = "";
|
|
534
414
|
let settled = false;
|
|
535
415
|
const timeout = setTimeout(() => {
|
|
@@ -550,39 +430,50 @@ const startIsolatedRuntimeOwner = async ({
|
|
|
550
430
|
|
|
551
431
|
const cleanup = () => {
|
|
552
432
|
clearTimeout(timeout);
|
|
553
|
-
helperProcess.
|
|
433
|
+
helperProcess.off("message", onReady);
|
|
554
434
|
helperProcess.stderr?.off("data", onStderr);
|
|
555
435
|
helperProcess.off("exit", onExit);
|
|
556
436
|
helperProcess.off("error", onError);
|
|
557
437
|
};
|
|
558
438
|
|
|
559
|
-
const
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
439
|
+
const onReady = (message: unknown) => {
|
|
440
|
+
const result = z
|
|
441
|
+
.object({
|
|
442
|
+
type: z.literal("air-jam-runtime-owner.ready/v1"),
|
|
443
|
+
roomId: z.string().nullable(),
|
|
444
|
+
controllerJoinUrl: z.string().nullable(),
|
|
445
|
+
inspection: z.unknown(),
|
|
446
|
+
})
|
|
447
|
+
.safeParse(message);
|
|
448
|
+
if (!result.success) return;
|
|
449
|
+
const inspection = readRuntimeInspectionContract({
|
|
450
|
+
[AIR_JAM_RUNTIME_INSPECTION_KEY]: result.data.inspection,
|
|
451
|
+
});
|
|
452
|
+
if (inspection?.role !== "host") {
|
|
567
453
|
cleanup();
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
454
|
+
void terminateIsolatedRuntimeOwner(helperProcess).then(
|
|
455
|
+
() =>
|
|
456
|
+
reject(
|
|
457
|
+
new Error(
|
|
458
|
+
"Isolated runtime owner returned an invalid host inspection.",
|
|
459
|
+
),
|
|
460
|
+
),
|
|
461
|
+
reject,
|
|
462
|
+
);
|
|
463
|
+
return;
|
|
576
464
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
465
|
+
settled = true;
|
|
466
|
+
cleanup();
|
|
467
|
+
resolve({
|
|
468
|
+
process: helperProcess,
|
|
469
|
+
roomId: result.data.roomId,
|
|
470
|
+
controllerJoinUrl: result.data.controllerJoinUrl,
|
|
471
|
+
inspection,
|
|
472
|
+
});
|
|
582
473
|
};
|
|
583
474
|
|
|
584
475
|
const onStderr = (chunk: Buffer | string) => {
|
|
585
|
-
stderrBuffer
|
|
476
|
+
stderrBuffer = (stderrBuffer + chunk.toString()).slice(-262144);
|
|
586
477
|
};
|
|
587
478
|
|
|
588
479
|
const onError = (error: Error) => {
|
|
@@ -611,13 +502,72 @@ const startIsolatedRuntimeOwner = async ({
|
|
|
611
502
|
);
|
|
612
503
|
};
|
|
613
504
|
|
|
614
|
-
helperProcess.stdout?.
|
|
505
|
+
helperProcess.stdout?.resume();
|
|
506
|
+
helperProcess.on("message", onReady);
|
|
615
507
|
helperProcess.stderr?.on("data", onStderr);
|
|
616
508
|
helperProcess.once("error", onError);
|
|
617
509
|
helperProcess.once("exit", onExit);
|
|
618
510
|
});
|
|
619
511
|
};
|
|
620
512
|
|
|
513
|
+
/**
|
|
514
|
+
* Serves the observed controller page the acting phone's room, read-only:
|
|
515
|
+
* the owner relays the page's room port here over IPC, and this side serves
|
|
516
|
+
* it as a view of the acting phone's session. The page sees what the phone
|
|
517
|
+
* sees; nothing it sends reaches the room.
|
|
518
|
+
*/
|
|
519
|
+
function relayControllerObservation(
|
|
520
|
+
session: InternalControllerSession,
|
|
521
|
+
owner: ChildProcess,
|
|
522
|
+
requestId: string,
|
|
523
|
+
onError: (error: Error) => void,
|
|
524
|
+
) {
|
|
525
|
+
const listeners = new Set<(event: MessageEvent) => void>();
|
|
526
|
+
const fromOwner = (message: unknown) => {
|
|
527
|
+
const frame = runtimeOwnerCaptureFrameSchema.safeParse(message);
|
|
528
|
+
if (!frame.success || frame.data.requestId !== requestId) return;
|
|
529
|
+
for (const listener of listeners)
|
|
530
|
+
listener({ data: frame.data.message } as MessageEvent);
|
|
531
|
+
};
|
|
532
|
+
const port = {
|
|
533
|
+
addEventListener: (_: "message", listener: (event: MessageEvent) => void) =>
|
|
534
|
+
listeners.add(listener),
|
|
535
|
+
removeEventListener: (
|
|
536
|
+
_: "message",
|
|
537
|
+
listener: (event: MessageEvent) => void,
|
|
538
|
+
) => listeners.delete(listener),
|
|
539
|
+
start: () => {},
|
|
540
|
+
postMessage: (message: unknown) =>
|
|
541
|
+
owner.send(
|
|
542
|
+
{ type: AIR_JAM_RUNTIME_OWNER_CAPTURE_PORT, requestId, message },
|
|
543
|
+
(error) => {
|
|
544
|
+
if (error) onError(error);
|
|
545
|
+
},
|
|
546
|
+
),
|
|
547
|
+
} as unknown as MessagePort;
|
|
548
|
+
const scoped = createScopedPhoneConnector(session.room, () => true);
|
|
549
|
+
const stopServing = serveRoomPort(port, (address, handlers) => {
|
|
550
|
+
const link = scoped.connector(address, handlers);
|
|
551
|
+
let greeted = false;
|
|
552
|
+
const readOnly: RoomLink = {
|
|
553
|
+
...link,
|
|
554
|
+
send: (data) => {
|
|
555
|
+
if (!greeted || data === "ping") link.send(data);
|
|
556
|
+
greeted = true;
|
|
557
|
+
},
|
|
558
|
+
};
|
|
559
|
+
return readOnly;
|
|
560
|
+
});
|
|
561
|
+
owner.on("message", fromOwner);
|
|
562
|
+
return {
|
|
563
|
+
close() {
|
|
564
|
+
stopServing();
|
|
565
|
+
scoped.close();
|
|
566
|
+
owner.off("message", fromOwner);
|
|
567
|
+
},
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
621
571
|
export const captureControllerSessionVisuals = async ({
|
|
622
572
|
controllerSessionId,
|
|
623
573
|
relativeDir,
|
|
@@ -629,6 +579,10 @@ export const captureControllerSessionVisuals = async ({
|
|
|
629
579
|
}) => {
|
|
630
580
|
const session = getRequiredSession(controllerSessionId);
|
|
631
581
|
const owner = session.isolatedRuntimeOwner;
|
|
582
|
+
if (!session.summary.connected)
|
|
583
|
+
throw new Error(
|
|
584
|
+
"The acting controller must be connected for visual capture.",
|
|
585
|
+
);
|
|
632
586
|
if (!owner?.connected) {
|
|
633
587
|
throw new Error(
|
|
634
588
|
`Air Jam controller session "${controllerSessionId}" does not own a capturable host runtime. Capture from the first game session opened for the room.`,
|
|
@@ -644,6 +598,8 @@ export const captureControllerSessionVisuals = async ({
|
|
|
644
598
|
}, timeoutMs);
|
|
645
599
|
const cleanup = () => {
|
|
646
600
|
clearTimeout(timeout);
|
|
601
|
+
relay.close();
|
|
602
|
+
stopFollowing();
|
|
647
603
|
owner.off("message", onMessage);
|
|
648
604
|
owner.off("error", onError);
|
|
649
605
|
owner.off("exit", onExit);
|
|
@@ -666,6 +622,15 @@ export const captureControllerSessionVisuals = async ({
|
|
|
666
622
|
cleanup();
|
|
667
623
|
reject(error);
|
|
668
624
|
};
|
|
625
|
+
const stopFollowing = session.room.on("status", (status) => {
|
|
626
|
+
if (status.phase === "open") return;
|
|
627
|
+
cleanup();
|
|
628
|
+
reject(
|
|
629
|
+
new Error(
|
|
630
|
+
"Acting controller disconnected before visual capture completed.",
|
|
631
|
+
),
|
|
632
|
+
);
|
|
633
|
+
});
|
|
669
634
|
const onExit = (code: number | null) => {
|
|
670
635
|
cleanup();
|
|
671
636
|
reject(
|
|
@@ -675,6 +640,12 @@ export const captureControllerSessionVisuals = async ({
|
|
|
675
640
|
);
|
|
676
641
|
};
|
|
677
642
|
|
|
643
|
+
const relay = relayControllerObservation(
|
|
644
|
+
session,
|
|
645
|
+
owner,
|
|
646
|
+
requestId,
|
|
647
|
+
onError,
|
|
648
|
+
);
|
|
678
649
|
owner.on("message", onMessage);
|
|
679
650
|
owner.once("error", onError);
|
|
680
651
|
owner.once("exit", onExit);
|
|
@@ -683,6 +654,8 @@ export const captureControllerSessionVisuals = async ({
|
|
|
683
654
|
type: AIR_JAM_RUNTIME_OWNER_CAPTURE_REQUEST,
|
|
684
655
|
requestId,
|
|
685
656
|
relativeDir,
|
|
657
|
+
harnessSessionId: session.summary.controllerSessionId,
|
|
658
|
+
roomId: session.summary.roomId,
|
|
686
659
|
},
|
|
687
660
|
(error) => {
|
|
688
661
|
if (error) onError(error);
|
|
@@ -705,19 +678,36 @@ const buildRuntimeSnapshot = ({
|
|
|
705
678
|
session: InternalControllerSession;
|
|
706
679
|
requestedStoreDomains?: string[];
|
|
707
680
|
missingStoreDomains?: string[];
|
|
708
|
-
}): AirJamRuntimeSnapshotInspection =>
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
681
|
+
}): AirJamRuntimeSnapshotInspection => {
|
|
682
|
+
const room = session.room;
|
|
683
|
+
return {
|
|
684
|
+
...session.summary,
|
|
685
|
+
welcome: room.instance
|
|
686
|
+
? {
|
|
687
|
+
roomId: room.code,
|
|
688
|
+
instance: room.instance,
|
|
689
|
+
controllerId: room.seat,
|
|
690
|
+
}
|
|
691
|
+
: null,
|
|
692
|
+
controllerState: (room.channel(AIRJAM_PRESENTATION_CHANNEL) ??
|
|
693
|
+
null) as JsonObject | null,
|
|
694
|
+
players: room.seats.map((seat) => ({ ...seat })),
|
|
695
|
+
storeSnapshots: [...room.documents()]
|
|
696
|
+
.map(([storeDomain, data]) => ({
|
|
697
|
+
storeDomain,
|
|
698
|
+
data: data as JsonObject,
|
|
699
|
+
revision: session.storeUpdates.get(storeDomain)?.revision ?? 0,
|
|
700
|
+
updatedAt:
|
|
701
|
+
session.storeUpdates.get(storeDomain)?.updatedAt ??
|
|
702
|
+
session.summary.connectedAt,
|
|
703
|
+
}))
|
|
704
|
+
.sort((left, right) => left.storeDomain.localeCompare(right.storeDomain)),
|
|
705
|
+
lastSignal: session.lastSignal,
|
|
706
|
+
lastError: session.lastError,
|
|
707
|
+
requestedStoreDomains: [...requestedStoreDomains],
|
|
708
|
+
missingStoreDomains: [...missingStoreDomains],
|
|
709
|
+
};
|
|
710
|
+
};
|
|
721
711
|
|
|
722
712
|
const buildSessionSummary = (
|
|
723
713
|
session: InternalControllerSession,
|
|
@@ -764,10 +754,12 @@ export const inspectControllerSessionContext = (
|
|
|
764
754
|
|
|
765
755
|
export const resolveControllerSessionGameRuntime = async ({
|
|
766
756
|
controllerSessionId,
|
|
757
|
+
game,
|
|
767
758
|
timeoutMs = DEFAULT_TIMEOUT_MS,
|
|
768
759
|
}: {
|
|
769
760
|
controllerSessionId: string;
|
|
770
761
|
timeoutMs?: number;
|
|
762
|
+
game?: AirJamGameInspection;
|
|
771
763
|
}): Promise<{
|
|
772
764
|
gameId: string | null;
|
|
773
765
|
defaultStoreDomain: string;
|
|
@@ -786,18 +778,13 @@ export const resolveControllerSessionGameRuntime = async ({
|
|
|
786
778
|
};
|
|
787
779
|
}
|
|
788
780
|
|
|
789
|
-
const
|
|
790
|
-
session.
|
|
791
|
-
|
|
792
|
-
const surfaceSnapshot = await waitForStateSync({
|
|
793
|
-
session,
|
|
794
|
-
storeDomain: AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN,
|
|
795
|
-
minimumRevision,
|
|
781
|
+
const surfaceData = (await waitForChannel(
|
|
782
|
+
session.room,
|
|
783
|
+
AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN,
|
|
796
784
|
timeoutMs,
|
|
797
|
-
|
|
785
|
+
)) as Record<string, unknown> | null;
|
|
798
786
|
// Replicated surface state also contains presentation fields. Validate its
|
|
799
787
|
// identity projection without weakening the strict bridge identity contract.
|
|
800
|
-
const surfaceData = surfaceSnapshot?.data;
|
|
801
788
|
const parsedSurface = arcadeSurfaceRuntimeIdentitySchema.safeParse({
|
|
802
789
|
epoch: surfaceData?.epoch,
|
|
803
790
|
kind: surfaceData?.kind,
|
|
@@ -819,7 +806,7 @@ export const resolveControllerSessionGameRuntime = async ({
|
|
|
819
806
|
|
|
820
807
|
const sourceGameId =
|
|
821
808
|
session.projectMode === "standalone-game"
|
|
822
|
-
? (await inspectGame({ cwd: session.cwd })).id
|
|
809
|
+
? (game ?? (await inspectGame({ cwd: session.cwd }))).id
|
|
823
810
|
: (localReferenceSourceGameId(parsedSurface.data.gameId) ??
|
|
824
811
|
parsedSurface.data.gameId);
|
|
825
812
|
session.summary.gameId = sourceGameId;
|
|
@@ -832,171 +819,67 @@ export const resolveControllerSessionGameRuntime = async ({
|
|
|
832
819
|
};
|
|
833
820
|
};
|
|
834
821
|
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
minimumRevision: number;
|
|
844
|
-
timeoutMs: number;
|
|
845
|
-
}): Promise<AirJamRuntimeStoreSnapshot | null> =>
|
|
846
|
-
await new Promise<AirJamRuntimeStoreSnapshot | null>((resolve) => {
|
|
847
|
-
const requestId = randomUUID();
|
|
848
|
-
const waiters = session.pendingSyncWaiters.get(storeDomain) ?? new Set();
|
|
849
|
-
const timeout = setTimeout(() => {
|
|
850
|
-
waiters.delete(waiter);
|
|
851
|
-
if (waiters.size === 0) {
|
|
852
|
-
session.pendingSyncWaiters.delete(storeDomain);
|
|
853
|
-
}
|
|
854
|
-
resolve(null);
|
|
855
|
-
}, timeoutMs);
|
|
856
|
-
|
|
857
|
-
const waiter: PendingStateSyncWaiter = {
|
|
858
|
-
requestId,
|
|
859
|
-
minimumRevision,
|
|
860
|
-
resolve: (snapshot) => {
|
|
861
|
-
clearTimeout(timeout);
|
|
862
|
-
waiters.delete(waiter);
|
|
863
|
-
if (waiters.size === 0) {
|
|
864
|
-
session.pendingSyncWaiters.delete(storeDomain);
|
|
865
|
-
}
|
|
866
|
-
resolve(snapshot);
|
|
867
|
-
},
|
|
868
|
-
};
|
|
869
|
-
|
|
870
|
-
waiters.add(waiter);
|
|
871
|
-
session.pendingSyncWaiters.set(storeDomain, waiters);
|
|
872
|
-
session.socket.emit("controller:state_sync_request", {
|
|
873
|
-
roomId: session.summary.roomId,
|
|
874
|
-
storeDomain,
|
|
875
|
-
requestId,
|
|
876
|
-
});
|
|
877
|
-
});
|
|
878
|
-
|
|
879
|
-
const resolvePendingStateSyncWaiters = ({
|
|
880
|
-
session,
|
|
881
|
-
snapshot,
|
|
882
|
-
requestId,
|
|
883
|
-
}: {
|
|
884
|
-
session: InternalControllerSession;
|
|
885
|
-
snapshot: AirJamRuntimeStoreSnapshot;
|
|
886
|
-
requestId?: string;
|
|
887
|
-
}): void => {
|
|
888
|
-
const waiters = session.pendingSyncWaiters.get(snapshot.storeDomain);
|
|
889
|
-
if (!waiters) {
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
for (const waiter of Array.from(waiters)) {
|
|
894
|
-
if (requestId !== waiter.requestId) {
|
|
895
|
-
continue;
|
|
896
|
-
}
|
|
897
|
-
if (snapshot.revision < waiter.minimumRevision) {
|
|
898
|
-
continue;
|
|
899
|
-
}
|
|
900
|
-
waiter.resolve(snapshot);
|
|
901
|
-
}
|
|
902
|
-
};
|
|
903
|
-
|
|
904
|
-
const attachSocketListeners = (session: InternalControllerSession): void => {
|
|
905
|
-
session.socket.on("server:welcome", (payload: ControllerWelcomePayload) => {
|
|
906
|
-
session.welcome = {
|
|
907
|
-
...payload,
|
|
908
|
-
};
|
|
909
|
-
session.players = toJsonObjectArray(payload.players);
|
|
910
|
-
});
|
|
911
|
-
|
|
912
|
-
session.socket.on("server:state", (payload: ControllerStateMessage) => {
|
|
913
|
-
session.controllerState = toJsonObject(payload.state);
|
|
914
|
-
});
|
|
915
|
-
|
|
916
|
-
session.socket.on(
|
|
917
|
-
"server:controllerJoined",
|
|
918
|
-
(payload: ControllerJoinedNotice) => {
|
|
919
|
-
const fallbackPlayer =
|
|
920
|
-
payload.player ??
|
|
921
|
-
({
|
|
922
|
-
id: payload.controllerId,
|
|
923
|
-
label: payload.nickname ?? payload.controllerId,
|
|
924
|
-
} satisfies JsonObject);
|
|
925
|
-
session.players = upsertPlayer(session.players, fallbackPlayer);
|
|
926
|
-
},
|
|
927
|
-
);
|
|
928
|
-
|
|
929
|
-
session.socket.on("server:controllerLeft", (payload) => {
|
|
930
|
-
session.players = removePlayer(session.players, payload.controllerId);
|
|
931
|
-
});
|
|
932
|
-
|
|
933
|
-
session.socket.on("server:playerUpdated", (payload: PlayerUpdatedNotice) => {
|
|
934
|
-
session.players = upsertPlayer(session.players, payload.player);
|
|
935
|
-
});
|
|
936
|
-
|
|
937
|
-
session.socket.on("server:signal", (payload: SignalPayload) => {
|
|
938
|
-
session.lastSignal = toJsonObject(payload);
|
|
939
|
-
});
|
|
940
|
-
|
|
941
|
-
session.socket.on("server:error", (payload: ServerErrorPayload) => {
|
|
942
|
-
session.lastError = toJsonObject(payload);
|
|
943
|
-
});
|
|
944
|
-
|
|
945
|
-
session.socket.on("airjam:state_sync", (payload: AirJamStateSyncPayload) => {
|
|
946
|
-
const previousSnapshot = session.storeSnapshots.get(payload.storeDomain);
|
|
947
|
-
if (previousSnapshot && payload.revision < previousSnapshot.revision) {
|
|
822
|
+
/** Follows the phone's room: its status, its channels' changes and its signals. */
|
|
823
|
+
const followRoom = (session: InternalControllerSession): void => {
|
|
824
|
+
const room = session.room;
|
|
825
|
+
room.on("status", (status) => {
|
|
826
|
+
// Connected means the room link is open now; a reconnecting phone is not.
|
|
827
|
+
session.summary.connected = status.phase === "open";
|
|
828
|
+
if (status.phase === "open") {
|
|
829
|
+
session.summary.controllerId = room.seat ?? session.summary.controllerId;
|
|
948
830
|
return;
|
|
949
831
|
}
|
|
950
|
-
|
|
951
|
-
const snapshot: AirJamRuntimeStoreSnapshot = {
|
|
952
|
-
storeDomain: payload.storeDomain,
|
|
953
|
-
data: { ...payload.data },
|
|
954
|
-
updatedAt: nowIso(),
|
|
955
|
-
revision: payload.revision,
|
|
956
|
-
};
|
|
957
|
-
session.storeSnapshots.set(payload.storeDomain, snapshot);
|
|
958
|
-
resolvePendingStateSyncWaiters({
|
|
959
|
-
session,
|
|
960
|
-
snapshot,
|
|
961
|
-
requestId: payload.requestId,
|
|
962
|
-
});
|
|
963
|
-
});
|
|
964
|
-
|
|
965
|
-
session.socket.on("disconnect", (reason) => {
|
|
966
|
-
session.summary.connected = false;
|
|
832
|
+
if (status.phase !== "closed") return;
|
|
967
833
|
session.summary.disconnectedAt = nowIso();
|
|
968
|
-
session.summary.disconnectReason = reason
|
|
969
|
-
|
|
834
|
+
session.summary.disconnectReason = status.reason;
|
|
835
|
+
if (status.reason !== "owner" && status.reason !== "left")
|
|
836
|
+
session.lastError = { reason: status.reason };
|
|
837
|
+
void terminateIsolatedRuntimeOwner(session.isolatedRuntimeOwner).then(
|
|
970
838
|
() => {
|
|
971
839
|
session.isolatedRuntimeOwner = null;
|
|
972
840
|
},
|
|
841
|
+
(error) => console.error(error),
|
|
973
842
|
);
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
843
|
+
});
|
|
844
|
+
room.on("state", ({ channel }) => {
|
|
845
|
+
const previous = session.storeUpdates.get(channel)?.revision ?? 0;
|
|
846
|
+
session.storeUpdates.set(channel, {
|
|
847
|
+
revision: previous + 1,
|
|
848
|
+
updatedAt: nowIso(),
|
|
849
|
+
});
|
|
850
|
+
});
|
|
851
|
+
room.on("signal", (signal) => {
|
|
852
|
+
session.lastSignal = {
|
|
853
|
+
kind: signal.kind,
|
|
854
|
+
payload: signal.payload,
|
|
855
|
+
} as JsonObject;
|
|
980
856
|
});
|
|
981
857
|
};
|
|
982
858
|
|
|
983
|
-
export const connectController = async (
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
859
|
+
export const connectController = async (
|
|
860
|
+
{
|
|
861
|
+
cwd = process.cwd(),
|
|
862
|
+
gameId,
|
|
863
|
+
mode = "standalone-dev",
|
|
864
|
+
secure = false,
|
|
865
|
+
roomId,
|
|
866
|
+
controllerJoinUrl,
|
|
867
|
+
nickname,
|
|
868
|
+
avatarId,
|
|
869
|
+
timeoutMs = DEFAULT_TIMEOUT_MS,
|
|
870
|
+
}: ConnectControllerOptions = {},
|
|
871
|
+
{
|
|
872
|
+
build,
|
|
873
|
+
onScope,
|
|
874
|
+
settings,
|
|
875
|
+
}: {
|
|
876
|
+
build?: PinnedGameBuild;
|
|
877
|
+
onScope?: ProcessScopeObserver;
|
|
878
|
+
settings?: Record<string, number | boolean | string>;
|
|
879
|
+
} = {},
|
|
880
|
+
): Promise<AirJamVirtualControllerSession> => {
|
|
997
881
|
const context = await detectProjectContext({ cwd });
|
|
998
882
|
const normalizedRequestedRoomId = roomId?.trim().toUpperCase() || undefined;
|
|
999
|
-
const normalizedCapabilityToken = capabilityToken?.trim() || undefined;
|
|
1000
883
|
const canUseIsolatedOwner =
|
|
1001
884
|
!normalizedRequestedRoomId &&
|
|
1002
885
|
!controllerJoinUrl &&
|
|
@@ -1018,38 +901,40 @@ export const connectController = async ({
|
|
|
1018
901
|
);
|
|
1019
902
|
}
|
|
1020
903
|
|
|
1021
|
-
const
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
`ctrl_mcp_${randomUUID().replace(/-/g, "").slice(0, 12)}`;
|
|
1025
|
-
const resolvedDeviceId =
|
|
1026
|
-
deviceId?.trim() || `aj-mcp-device-${randomUUID()}`;
|
|
1027
|
-
const topology = await getTopology({
|
|
1028
|
-
cwd,
|
|
1029
|
-
gameId,
|
|
1030
|
-
mode,
|
|
1031
|
-
secure,
|
|
1032
|
-
}).catch(() => null);
|
|
904
|
+
const topology = controllerJoinUrl
|
|
905
|
+
? null
|
|
906
|
+
: await getTopology({ cwd, gameId, mode, secure }).catch(() => null);
|
|
1033
907
|
const resolvedGameId = gameId ?? topology?.gameId ?? null;
|
|
1034
|
-
const resolvedSocketOrigin =
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
undefined;
|
|
908
|
+
const resolvedSocketOrigin =
|
|
909
|
+
parseRuntimeTopologyFromSearchParams(joinUrl.searchParams)
|
|
910
|
+
?.socketOrigin ??
|
|
911
|
+
(controllerJoinUrl
|
|
912
|
+
? joinUrl.origin
|
|
913
|
+
: ((await resolveSocketOriginFromTopology({
|
|
914
|
+
cwd,
|
|
915
|
+
gameId: resolvedGameId ?? undefined,
|
|
916
|
+
mode,
|
|
917
|
+
secure,
|
|
918
|
+
})) ?? joinUrl.origin));
|
|
1046
919
|
const controllerSessionId = randomUUID();
|
|
1047
|
-
|
|
1048
|
-
const
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
920
|
+
const label = nickname?.trim().slice(0, 24);
|
|
921
|
+
const avatar = avatarId?.trim();
|
|
922
|
+
|
|
923
|
+
const room = new PhoneRoomSession({
|
|
924
|
+
connector: createWebSocketConnector(resolvedSocketOrigin),
|
|
925
|
+
key: createRoomKey(),
|
|
926
|
+
code: resolvedRoomId,
|
|
927
|
+
kind: "agent",
|
|
928
|
+
deviceWakeEvents: null,
|
|
929
|
+
...(label || avatar
|
|
930
|
+
? {
|
|
931
|
+
profile: {
|
|
932
|
+
...(label ? { label } : {}),
|
|
933
|
+
...(avatar ? { avatarId: avatar } : {}),
|
|
934
|
+
},
|
|
935
|
+
}
|
|
936
|
+
: {}),
|
|
937
|
+
});
|
|
1053
938
|
|
|
1054
939
|
const internalSession: InternalControllerSession = {
|
|
1055
940
|
cwd,
|
|
@@ -1058,12 +943,13 @@ export const connectController = async ({
|
|
|
1058
943
|
gameId: resolvedGameId,
|
|
1059
944
|
projectMode: context.mode,
|
|
1060
945
|
mode,
|
|
1061
|
-
topologyMode:
|
|
946
|
+
topologyMode: build
|
|
947
|
+
? "self-hosted-production"
|
|
948
|
+
: (topology?.topologyMode ?? null),
|
|
1062
949
|
secure,
|
|
1063
950
|
process: topology?.process ?? null,
|
|
1064
951
|
roomId: resolvedRoomId,
|
|
1065
|
-
controllerId:
|
|
1066
|
-
deviceId: resolvedDeviceId,
|
|
952
|
+
controllerId: "",
|
|
1067
953
|
controllerJoinUrl: joinUrlString,
|
|
1068
954
|
socketOrigin: resolvedSocketOrigin,
|
|
1069
955
|
connected: false,
|
|
@@ -1071,77 +957,48 @@ export const connectController = async ({
|
|
|
1071
957
|
disconnectedAt: null,
|
|
1072
958
|
disconnectReason: null,
|
|
1073
959
|
},
|
|
1074
|
-
|
|
960
|
+
room,
|
|
1075
961
|
projectMode: context.mode,
|
|
1076
|
-
|
|
1077
|
-
controllerState: null,
|
|
1078
|
-
players: [],
|
|
1079
|
-
storeSnapshots: new Map(),
|
|
1080
|
-
pendingSyncWaiters: new Map(),
|
|
962
|
+
storeUpdates: new Map(),
|
|
1081
963
|
lastSignal: null,
|
|
1082
964
|
lastError: null,
|
|
1083
965
|
isolatedRuntimeOwner: ownedRuntimeProcess,
|
|
1084
|
-
|
|
966
|
+
participantLeaseId: null,
|
|
967
|
+
participantLastCommand: null,
|
|
968
|
+
inputState: null,
|
|
969
|
+
inputLayout: undefined,
|
|
1085
970
|
};
|
|
1086
971
|
|
|
1087
|
-
|
|
972
|
+
followRoom(internalSession);
|
|
1088
973
|
|
|
1089
974
|
try {
|
|
1090
|
-
await
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
avatarId: avatarId?.trim() || undefined,
|
|
1099
|
-
capabilityToken: resolvedCapabilityToken,
|
|
1100
|
-
resumeCapabilityToken:
|
|
1101
|
-
internalSession.resumeCapabilityToken ?? undefined,
|
|
1102
|
-
},
|
|
1103
|
-
timeoutMs,
|
|
1104
|
-
});
|
|
1105
|
-
|
|
1106
|
-
if (!ack.ok) {
|
|
1107
|
-
throw new Error(
|
|
1108
|
-
ack.message ??
|
|
1109
|
-
`Controller join was rejected${ack.code ? ` (${ack.code})` : ""}.`,
|
|
1110
|
-
);
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
internalSession.resumeCapabilityToken =
|
|
1114
|
-
ack.resumeCapabilityToken ?? internalSession.resumeCapabilityToken;
|
|
1115
|
-
|
|
1116
|
-
internalSession.summary.connected = true;
|
|
1117
|
-
internalSession.summary.roomId = ack.roomId ?? resolvedRoomId;
|
|
1118
|
-
internalSession.summary.controllerId =
|
|
1119
|
-
ack.controllerId ?? resolvedControllerId;
|
|
1120
|
-
await waitForCondition({
|
|
1121
|
-
timeoutMs: Math.min(timeoutMs, 500),
|
|
1122
|
-
predicate: () =>
|
|
1123
|
-
internalSession.welcome !== null &&
|
|
1124
|
-
internalSession.controllerState !== null,
|
|
1125
|
-
});
|
|
975
|
+
await waitForWelcome(room, timeoutMs);
|
|
976
|
+
// A host in the room publishes its presentation at once; a summary
|
|
977
|
+
// without it reads as a room whose host is away.
|
|
978
|
+
await waitForChannel(
|
|
979
|
+
room,
|
|
980
|
+
AIRJAM_PRESENTATION_CHANNEL,
|
|
981
|
+
Math.min(timeoutMs, 500),
|
|
982
|
+
);
|
|
1126
983
|
virtualControllerSessions.set(controllerSessionId, internalSession);
|
|
1127
984
|
return buildRuntimeSnapshot({ session: internalSession });
|
|
1128
985
|
} catch (error) {
|
|
1129
|
-
|
|
986
|
+
room.close();
|
|
1130
987
|
await terminateIsolatedRuntimeOwner(ownedRuntimeProcess);
|
|
1131
988
|
throw error;
|
|
1132
989
|
}
|
|
1133
990
|
};
|
|
1134
991
|
|
|
1135
|
-
const resolvedJoinUrl =
|
|
1136
|
-
|
|
1137
|
-
(
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
992
|
+
const resolvedJoinUrl = build
|
|
993
|
+
? null
|
|
994
|
+
: (controllerJoinUrl ??
|
|
995
|
+
(await resolveControllerJoinUrlFromTopology({
|
|
996
|
+
cwd,
|
|
997
|
+
gameId,
|
|
998
|
+
mode,
|
|
999
|
+
secure,
|
|
1000
|
+
roomId: normalizedRequestedRoomId,
|
|
1001
|
+
})));
|
|
1145
1002
|
if (!resolvedJoinUrl) {
|
|
1146
1003
|
if (!canUseIsolatedOwner) {
|
|
1147
1004
|
throw new Error(
|
|
@@ -1155,6 +1012,9 @@ export const connectController = async ({
|
|
|
1155
1012
|
mode,
|
|
1156
1013
|
secure,
|
|
1157
1014
|
timeoutMs,
|
|
1015
|
+
build,
|
|
1016
|
+
settings,
|
|
1017
|
+
onScope,
|
|
1158
1018
|
});
|
|
1159
1019
|
if (!owner.controllerJoinUrl) {
|
|
1160
1020
|
await terminateIsolatedRuntimeOwner(owner.process);
|
|
@@ -1186,12 +1046,32 @@ export const sendControllerInput = async ({
|
|
|
1186
1046
|
);
|
|
1187
1047
|
}
|
|
1188
1048
|
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1049
|
+
if (session.participantLeaseId)
|
|
1050
|
+
throw new Error(
|
|
1051
|
+
"participant_control_leased: Use the leased control path for this player.",
|
|
1052
|
+
);
|
|
1053
|
+
session.inputLayout ??=
|
|
1054
|
+
(await inspectGame({
|
|
1055
|
+
cwd: session.cwd,
|
|
1056
|
+
...(session.summary.gameId ? { gameId: session.summary.gameId } : {}),
|
|
1057
|
+
}).then(
|
|
1058
|
+
(game) => game.declaration.input,
|
|
1059
|
+
() => null,
|
|
1060
|
+
)) ?? null;
|
|
1061
|
+
const layout = session.inputLayout;
|
|
1062
|
+
if (!layout)
|
|
1063
|
+
throw new Error(
|
|
1064
|
+
"input_unavailable: This controller's game declares no controls it can read.",
|
|
1065
|
+
);
|
|
1066
|
+
// An agent sends values; a button turns into a press each time it goes down.
|
|
1067
|
+
const payload = {
|
|
1068
|
+
...session.inputState,
|
|
1069
|
+
...agentValuesToInputState(session.inputState, input),
|
|
1070
|
+
};
|
|
1071
|
+
session.inputState = payload;
|
|
1072
|
+
session.room.sendInputFrame(
|
|
1073
|
+
encodePhoneInputFrame(encodeInputPayload(layout, payload)),
|
|
1074
|
+
);
|
|
1195
1075
|
|
|
1196
1076
|
return {
|
|
1197
1077
|
...buildSessionSummary(session),
|
|
@@ -1200,11 +1080,56 @@ export const sendControllerInput = async ({
|
|
|
1200
1080
|
};
|
|
1201
1081
|
};
|
|
1202
1082
|
|
|
1083
|
+
export async function controlControllerParticipant({
|
|
1084
|
+
controllerSessionId,
|
|
1085
|
+
...input
|
|
1086
|
+
}: {
|
|
1087
|
+
controllerSessionId: string;
|
|
1088
|
+
} & LeasedControlRequest): Promise<ControllerLeasedControlAck> {
|
|
1089
|
+
const session = getRequiredSession(controllerSessionId);
|
|
1090
|
+
const request = leasedControlRequestSchema.parse(input);
|
|
1091
|
+
if (!session.summary.connected)
|
|
1092
|
+
return { status: "rejected", reason: "unauthorized" };
|
|
1093
|
+
if (
|
|
1094
|
+
session.participantLeaseId &&
|
|
1095
|
+
session.participantLeaseId !== request.lease.id
|
|
1096
|
+
)
|
|
1097
|
+
return { status: "rejected", reason: "lease_conflict" };
|
|
1098
|
+
session.participantLeaseId = request.lease.id;
|
|
1099
|
+
if (
|
|
1100
|
+
!session.participantLastCommand ||
|
|
1101
|
+
request.lease.sequence > session.participantLastCommand.lease.sequence
|
|
1102
|
+
)
|
|
1103
|
+
session.participantLastCommand = request;
|
|
1104
|
+
const outcome = await session.room.request(
|
|
1105
|
+
AIRJAM_CONTROL_CHANNEL,
|
|
1106
|
+
AIRJAM_LEASED_CONTROL_REQUEST,
|
|
1107
|
+
request,
|
|
1108
|
+
{ exclusive: true, timeoutMs: 2000 },
|
|
1109
|
+
);
|
|
1110
|
+
if (outcome.status === "busy") return { status: "rejected", reason: "busy" };
|
|
1111
|
+
if (outcome.status === "refused")
|
|
1112
|
+
return { status: "rejected", reason: "active_host_missing" };
|
|
1113
|
+
if (outcome.status === "unconfirmed")
|
|
1114
|
+
return { status: "unconfirmed", reason: "transport_ack_unavailable" };
|
|
1115
|
+
const parsed = controllerLeasedControlAckSchema.safeParse(outcome.result);
|
|
1116
|
+
if (
|
|
1117
|
+
!parsed.success ||
|
|
1118
|
+
(parsed.data.status === "applied" &&
|
|
1119
|
+
(parsed.data.leaseId !== request.lease.id ||
|
|
1120
|
+
parsed.data.sequence !== request.lease.sequence ||
|
|
1121
|
+
parsed.data.operation.kind !== request.operation.kind))
|
|
1122
|
+
)
|
|
1123
|
+
return { status: "unconfirmed", reason: "invalid_acknowledgement" };
|
|
1124
|
+
return parsed.data;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1203
1127
|
export const invokeControllerAction = async ({
|
|
1204
1128
|
controllerSessionId,
|
|
1205
1129
|
actionName,
|
|
1206
1130
|
storeDomain,
|
|
1207
1131
|
payload,
|
|
1132
|
+
timeoutMs = DEFAULT_TIMEOUT_MS,
|
|
1208
1133
|
}: InvokeControllerActionOptions): Promise<InvokeControllerActionResult> => {
|
|
1209
1134
|
const session = getRequiredSession(controllerSessionId);
|
|
1210
1135
|
if (!session.summary.connected) {
|
|
@@ -1213,17 +1138,16 @@ export const invokeControllerAction = async ({
|
|
|
1213
1138
|
);
|
|
1214
1139
|
}
|
|
1215
1140
|
|
|
1141
|
+
if (session.participantLeaseId)
|
|
1142
|
+
throw new Error(
|
|
1143
|
+
"participant_control_leased: Use the leased control path for this player.",
|
|
1144
|
+
);
|
|
1216
1145
|
const normalizedPayload = payload ? { ...payload } : undefined;
|
|
1217
|
-
const acknowledgement =
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
payload: normalizedPayload,
|
|
1223
|
-
storeDomain,
|
|
1224
|
-
},
|
|
1225
|
-
timeoutMs: DEFAULT_TIMEOUT_MS,
|
|
1226
|
-
});
|
|
1146
|
+
const acknowledgement = airJamActionResultOf(
|
|
1147
|
+
await session.room.request(storeDomain, actionName, normalizedPayload, {
|
|
1148
|
+
timeoutMs,
|
|
1149
|
+
}),
|
|
1150
|
+
);
|
|
1227
1151
|
|
|
1228
1152
|
return {
|
|
1229
1153
|
...buildSessionSummary(session),
|
|
@@ -1306,20 +1230,11 @@ export const readRuntimeSnapshot = async ({
|
|
|
1306
1230
|
const missingStoreDomains: string[] = [];
|
|
1307
1231
|
if (requestSync && normalizedStoreDomains.length > 0) {
|
|
1308
1232
|
const syncResults = await Promise.all(
|
|
1309
|
-
normalizedStoreDomains.map(async (storeDomain) => {
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
storeDomain,
|
|
1315
|
-
minimumRevision,
|
|
1316
|
-
timeoutMs,
|
|
1317
|
-
});
|
|
1318
|
-
return {
|
|
1319
|
-
storeDomain,
|
|
1320
|
-
ok: result !== null,
|
|
1321
|
-
};
|
|
1322
|
-
}),
|
|
1233
|
+
normalizedStoreDomains.map(async (storeDomain) => ({
|
|
1234
|
+
storeDomain,
|
|
1235
|
+
ok:
|
|
1236
|
+
(await waitForChannel(session.room, storeDomain, timeoutMs)) !== null,
|
|
1237
|
+
})),
|
|
1323
1238
|
);
|
|
1324
1239
|
|
|
1325
1240
|
for (const result of syncResults) {
|
|
@@ -1336,41 +1251,276 @@ export const readRuntimeSnapshot = async ({
|
|
|
1336
1251
|
});
|
|
1337
1252
|
};
|
|
1338
1253
|
|
|
1254
|
+
async function disposeControllerSession(session: InternalControllerSession) {
|
|
1255
|
+
const owner = session.isolatedRuntimeOwner;
|
|
1256
|
+
session.room.close();
|
|
1257
|
+
session.summary.connected = false;
|
|
1258
|
+
session.summary.disconnectedAt ??= nowIso();
|
|
1259
|
+
session.summary.disconnectReason ??= "manual_disconnect";
|
|
1260
|
+
await terminateIsolatedRuntimeOwner(owner);
|
|
1261
|
+
session.isolatedRuntimeOwner = null;
|
|
1262
|
+
virtualControllerSessions.delete(session.summary.controllerSessionId);
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
export async function forceDisconnectController({
|
|
1266
|
+
controllerSessionId,
|
|
1267
|
+
}: DisconnectControllerOptions): Promise<DisconnectControllerResult> {
|
|
1268
|
+
const session = getRequiredSession(controllerSessionId);
|
|
1269
|
+
await disposeControllerSession(session);
|
|
1270
|
+
return {
|
|
1271
|
+
disconnected: true,
|
|
1272
|
+
release: { status: "unconfirmed", reason: "runtime_unavailable" },
|
|
1273
|
+
leave: {
|
|
1274
|
+
status: "unconfirmed",
|
|
1275
|
+
message:
|
|
1276
|
+
"Forced local transport/runtime teardown; server leave was not confirmed.",
|
|
1277
|
+
},
|
|
1278
|
+
session: buildSessionSummary(session),
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1339
1282
|
export const disconnectController = async ({
|
|
1340
1283
|
controllerSessionId,
|
|
1341
1284
|
}: DisconnectControllerOptions): Promise<DisconnectControllerResult> => {
|
|
1342
1285
|
const session = getRequiredSession(controllerSessionId);
|
|
1286
|
+
const last = session.participantLastCommand;
|
|
1287
|
+
const release: DisconnectControllerResult["release"] = last
|
|
1288
|
+
? last.lease.sequence === Number.MAX_SAFE_INTEGER
|
|
1289
|
+
? { status: "rejected", reason: "invalid_request" }
|
|
1290
|
+
: await controlControllerParticipant({
|
|
1291
|
+
controllerSessionId,
|
|
1292
|
+
expected: last.expected,
|
|
1293
|
+
lease: { id: last.lease.id, sequence: last.lease.sequence + 1 },
|
|
1294
|
+
operation: { kind: "release" },
|
|
1295
|
+
})
|
|
1296
|
+
: { status: "not-leased" };
|
|
1297
|
+
let leave: DisconnectControllerResult["leave"] = { status: "not-connected" };
|
|
1343
1298
|
if (session.summary.connected) {
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
}
|
|
1358
|
-
} catch {
|
|
1359
|
-
// Fall back to socket disconnect. Manual devtools teardown should not hang
|
|
1360
|
-
// forever when the room is already gone or the socket is mid-teardown.
|
|
1361
|
-
}
|
|
1299
|
+
session.room.leave();
|
|
1300
|
+
await waitForCondition({
|
|
1301
|
+
timeoutMs: DEFAULT_TIMEOUT_MS,
|
|
1302
|
+
predicate: () => session.room.status.phase === "closed",
|
|
1303
|
+
});
|
|
1304
|
+
const status = session.room.status;
|
|
1305
|
+
leave =
|
|
1306
|
+
status.phase === "closed" && status.reason === "left"
|
|
1307
|
+
? { status: "acknowledged" }
|
|
1308
|
+
: {
|
|
1309
|
+
status: "unconfirmed",
|
|
1310
|
+
message: "The room did not confirm the seat was given up.",
|
|
1311
|
+
};
|
|
1362
1312
|
}
|
|
1363
|
-
session
|
|
1364
|
-
session.summary.connected = false;
|
|
1365
|
-
session.summary.disconnectedAt = session.summary.disconnectedAt ?? nowIso();
|
|
1366
|
-
session.summary.disconnectReason =
|
|
1367
|
-
session.summary.disconnectReason ?? "manual_disconnect";
|
|
1368
|
-
await terminateIsolatedRuntimeOwner(session.isolatedRuntimeOwner);
|
|
1369
|
-
session.isolatedRuntimeOwner = null;
|
|
1370
|
-
virtualControllerSessions.delete(controllerSessionId);
|
|
1313
|
+
await disposeControllerSession(session);
|
|
1371
1314
|
|
|
1372
1315
|
return {
|
|
1373
1316
|
disconnected: true,
|
|
1317
|
+
leave,
|
|
1318
|
+
release,
|
|
1374
1319
|
session: buildSessionSummary(session),
|
|
1375
1320
|
};
|
|
1376
1321
|
};
|
|
1322
|
+
|
|
1323
|
+
export async function requestControllerHostAgent(
|
|
1324
|
+
controllerSessionId: string,
|
|
1325
|
+
request: HostAgentRequest,
|
|
1326
|
+
timeoutMs: number,
|
|
1327
|
+
signal?: AbortSignal,
|
|
1328
|
+
): Promise<HostAgentResponse> {
|
|
1329
|
+
const owner = getRequiredSession(controllerSessionId).isolatedRuntimeOwner;
|
|
1330
|
+
if (!owner || !ownsControllerSessionHost(controllerSessionId))
|
|
1331
|
+
throw new Error(
|
|
1332
|
+
"contract_runtime_not_owned: Semantic testing requires an owned host. Open a game session without an explicit room or join URL.",
|
|
1333
|
+
);
|
|
1334
|
+
return new Promise((resolve, reject) => {
|
|
1335
|
+
const requestId = randomUUID();
|
|
1336
|
+
let settled = false;
|
|
1337
|
+
const finish = (error?: Error, result?: HostAgentResponse) => {
|
|
1338
|
+
if (settled) return;
|
|
1339
|
+
settled = true;
|
|
1340
|
+
clearTimeout(timer);
|
|
1341
|
+
owner.off("message", onMessage);
|
|
1342
|
+
owner.off("error", onError);
|
|
1343
|
+
owner.off("exit", onExit);
|
|
1344
|
+
owner.off("disconnect", onExit);
|
|
1345
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1346
|
+
if (error) reject(error);
|
|
1347
|
+
else if (result) resolve(result);
|
|
1348
|
+
};
|
|
1349
|
+
const onMessage = (message: unknown) => {
|
|
1350
|
+
if (
|
|
1351
|
+
!message ||
|
|
1352
|
+
typeof message !== "object" ||
|
|
1353
|
+
!("type" in message) ||
|
|
1354
|
+
message.type !== "air-jam-runtime-owner.agent-result/v1" ||
|
|
1355
|
+
!("requestId" in message) ||
|
|
1356
|
+
message.requestId !== requestId
|
|
1357
|
+
)
|
|
1358
|
+
return;
|
|
1359
|
+
const parsed = runtimeOwnerAgentResultSchema.safeParse(message);
|
|
1360
|
+
if (!parsed.success) {
|
|
1361
|
+
finish(
|
|
1362
|
+
new Error(
|
|
1363
|
+
"invalid_runtime_response: Owned host returned an invalid agent response.",
|
|
1364
|
+
),
|
|
1365
|
+
);
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
if (parsed.data.ok) finish(undefined, parsed.data.result);
|
|
1369
|
+
else finish(new Error(parsed.data.error));
|
|
1370
|
+
};
|
|
1371
|
+
const onError = (error: Error) => finish(error);
|
|
1372
|
+
const onExit = () =>
|
|
1373
|
+
finish(
|
|
1374
|
+
new Error("runtime_disconnected: Owned host exited during evaluation."),
|
|
1375
|
+
);
|
|
1376
|
+
const onAbort = () =>
|
|
1377
|
+
finish(new Error("session_closed: Evaluation was cancelled."));
|
|
1378
|
+
const timer = setTimeout(
|
|
1379
|
+
() =>
|
|
1380
|
+
finish(
|
|
1381
|
+
new Error("evaluation_timeout: Owned game evaluation timed out."),
|
|
1382
|
+
),
|
|
1383
|
+
timeoutMs,
|
|
1384
|
+
);
|
|
1385
|
+
owner.on("message", onMessage);
|
|
1386
|
+
owner.once("error", onError);
|
|
1387
|
+
owner.once("exit", onExit);
|
|
1388
|
+
owner.once("disconnect", onExit);
|
|
1389
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1390
|
+
if (signal?.aborted) {
|
|
1391
|
+
onAbort();
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
try {
|
|
1395
|
+
owner.send(
|
|
1396
|
+
{ type: "air-jam-runtime-owner.agent/v1", requestId, request },
|
|
1397
|
+
(error) => {
|
|
1398
|
+
if (error) onError(error);
|
|
1399
|
+
},
|
|
1400
|
+
);
|
|
1401
|
+
} catch (error) {
|
|
1402
|
+
onError(error instanceof Error ? error : new Error(String(error)));
|
|
1403
|
+
}
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
export async function watchControllerSessionVisuals({
|
|
1408
|
+
ownerControllerSessionId,
|
|
1409
|
+
controllerSessionId,
|
|
1410
|
+
onEvent,
|
|
1411
|
+
signal,
|
|
1412
|
+
}: {
|
|
1413
|
+
ownerControllerSessionId: string;
|
|
1414
|
+
controllerSessionId?: string;
|
|
1415
|
+
onEvent: (event: GameSurfaceWatchEvent) => void;
|
|
1416
|
+
signal: AbortSignal;
|
|
1417
|
+
}): Promise<void> {
|
|
1418
|
+
signal.throwIfAborted();
|
|
1419
|
+
const session = getRequiredSession(ownerControllerSessionId);
|
|
1420
|
+
const owner = session.isolatedRuntimeOwner;
|
|
1421
|
+
if (!owner?.connected)
|
|
1422
|
+
throw new Error("Run watch requires its owned host runtime.");
|
|
1423
|
+
const target = controllerSessionId
|
|
1424
|
+
? getRequiredSession(controllerSessionId)
|
|
1425
|
+
: undefined;
|
|
1426
|
+
if (
|
|
1427
|
+
target &&
|
|
1428
|
+
(!target.summary.connected ||
|
|
1429
|
+
target.summary.roomId !== session.summary.roomId)
|
|
1430
|
+
)
|
|
1431
|
+
throw new Error("Run watch controller is not connected to the owned room.");
|
|
1432
|
+
const watchId = randomUUID();
|
|
1433
|
+
await new Promise<void>((resolve, reject) => {
|
|
1434
|
+
let stopping = false;
|
|
1435
|
+
let failed: Error | undefined;
|
|
1436
|
+
const cleanup = () => {
|
|
1437
|
+
clearTimeout(timeout);
|
|
1438
|
+
owner.off("message", message);
|
|
1439
|
+
owner.off("error", error);
|
|
1440
|
+
owner.off("exit", exit);
|
|
1441
|
+
signal.removeEventListener("abort", stop);
|
|
1442
|
+
relay?.close();
|
|
1443
|
+
};
|
|
1444
|
+
const settle = (failure?: Error) => {
|
|
1445
|
+
cleanup();
|
|
1446
|
+
if (failure) reject(failure);
|
|
1447
|
+
else resolve();
|
|
1448
|
+
};
|
|
1449
|
+
let timeout = setTimeout(
|
|
1450
|
+
() => error(new Error("Timed out starting the game watch.")),
|
|
1451
|
+
DEFAULT_VISUAL_CAPTURE_TIMEOUT_MS,
|
|
1452
|
+
);
|
|
1453
|
+
const stop = () => {
|
|
1454
|
+
if (stopping) return;
|
|
1455
|
+
stopping = true;
|
|
1456
|
+
clearTimeout(timeout);
|
|
1457
|
+
timeout = setTimeout(
|
|
1458
|
+
() => settle(new Error("Timed out closing the game watch.")),
|
|
1459
|
+
DEFAULT_VISUAL_CAPTURE_TIMEOUT_MS,
|
|
1460
|
+
);
|
|
1461
|
+
owner.send(
|
|
1462
|
+
{ type: "air-jam-runtime-owner.watch-stop/v1", watchId },
|
|
1463
|
+
(failure) => {
|
|
1464
|
+
if (failure) settle(failure);
|
|
1465
|
+
},
|
|
1466
|
+
);
|
|
1467
|
+
};
|
|
1468
|
+
const error = (failure: Error) => {
|
|
1469
|
+
failed ??= failure;
|
|
1470
|
+
stop();
|
|
1471
|
+
};
|
|
1472
|
+
const exit = () =>
|
|
1473
|
+
settle(new Error("Game watch owner exited before its stream closed."));
|
|
1474
|
+
const message = (value: unknown) => {
|
|
1475
|
+
const parsed = runtimeOwnerWatchEventSchema.safeParse(value);
|
|
1476
|
+
if (!parsed.success || parsed.data.watchId !== watchId) return;
|
|
1477
|
+
const event = parsed.data.event;
|
|
1478
|
+
if (event.type === "closed") {
|
|
1479
|
+
settle(failed);
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
if (event.type === "error") {
|
|
1483
|
+
if (stopping) {
|
|
1484
|
+
settle(new Error(event.message));
|
|
1485
|
+
return;
|
|
1486
|
+
}
|
|
1487
|
+
error(new Error(event.message));
|
|
1488
|
+
return;
|
|
1489
|
+
}
|
|
1490
|
+
if (stopping) return;
|
|
1491
|
+
if (event.type === "ready") clearTimeout(timeout);
|
|
1492
|
+
try {
|
|
1493
|
+
onEvent(event);
|
|
1494
|
+
} catch (failure) {
|
|
1495
|
+
error(failure instanceof Error ? failure : new Error(String(failure)));
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
const relay = target
|
|
1499
|
+
? relayControllerObservation(target, owner, watchId, error)
|
|
1500
|
+
: undefined;
|
|
1501
|
+
owner.on("message", message);
|
|
1502
|
+
owner.once("error", error);
|
|
1503
|
+
owner.once("exit", exit);
|
|
1504
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
1505
|
+
if (signal.aborted) {
|
|
1506
|
+
stop();
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
owner.send(
|
|
1510
|
+
{
|
|
1511
|
+
type: "air-jam-runtime-owner.watch/v1",
|
|
1512
|
+
watchId,
|
|
1513
|
+
surface: target ? "controller" : "host",
|
|
1514
|
+
...(target
|
|
1515
|
+
? {
|
|
1516
|
+
harnessSessionId: target.summary.controllerSessionId,
|
|
1517
|
+
roomId: target.summary.roomId,
|
|
1518
|
+
}
|
|
1519
|
+
: {}),
|
|
1520
|
+
},
|
|
1521
|
+
(failure) => {
|
|
1522
|
+
if (failure) error(failure);
|
|
1523
|
+
},
|
|
1524
|
+
);
|
|
1525
|
+
});
|
|
1526
|
+
}
|