@air-jam/sdk 0.9.1 → 0.9.3
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 +25 -45
- package/dist/{agent-tooling-BSMGBix9.d.cts → agent-contract-CD2QnbBJ.d.cts} +1 -1
- package/dist/{agent-tooling-BSMGBix9.d.ts → agent-contract-CD2QnbBJ.d.ts} +1 -1
- package/dist/agent-tooling.cjs +139 -0
- package/dist/agent-tooling.cjs.map +1 -1
- package/dist/agent-tooling.d.cts +25 -1
- package/dist/agent-tooling.d.ts +25 -1
- package/dist/agent-tooling.js +138 -0
- package/dist/agent-tooling.js.map +1 -1
- package/dist/air-jam-context-BlLPvCup.d.cts +175 -0
- package/dist/air-jam-context-DTsxF-tP.d.ts +175 -0
- package/dist/arcade/bridge/controller.cjs +214 -194
- package/dist/arcade/bridge/controller.cjs.map +1 -1
- package/dist/arcade/bridge/controller.d.cts +2 -2
- package/dist/arcade/bridge/controller.d.ts +2 -2
- package/dist/arcade/bridge/controller.js +6 -4
- package/dist/arcade/bridge/host.cjs +1 -1
- package/dist/arcade/bridge/host.cjs.map +1 -1
- package/dist/arcade/bridge/host.d.cts +3 -3
- package/dist/arcade/bridge/host.d.ts +3 -3
- package/dist/arcade/bridge/host.js +4 -3
- package/dist/arcade/bridge/iframe.cjs +1 -1
- package/dist/arcade/bridge/iframe.cjs.map +1 -1
- package/dist/arcade/bridge/iframe.d.cts +2 -2
- package/dist/arcade/bridge/iframe.d.ts +2 -2
- package/dist/arcade/bridge/iframe.js +4 -4
- package/dist/arcade/bridge.cjs +251 -231
- package/dist/arcade/bridge.cjs.map +1 -1
- package/dist/arcade/bridge.d.cts +4 -4
- package/dist/arcade/bridge.d.ts +4 -4
- package/dist/arcade/bridge.js +9 -7
- package/dist/arcade/host.cjs +145 -122
- package/dist/arcade/host.cjs.map +1 -1
- package/dist/arcade/host.d.cts +5 -4
- package/dist/arcade/host.d.ts +5 -4
- package/dist/arcade/host.js +6 -5
- package/dist/arcade/runtime.cjs +6499 -0
- package/dist/arcade/runtime.cjs.map +1 -0
- package/dist/arcade/runtime.d.cts +22 -0
- package/dist/arcade/runtime.d.ts +22 -0
- package/dist/arcade/runtime.js +32 -0
- package/dist/arcade/runtime.js.map +1 -0
- package/dist/arcade/surface.cjs +9 -0
- package/dist/arcade/surface.cjs.map +1 -1
- package/dist/arcade/surface.d.cts +6 -1
- package/dist/arcade/surface.d.ts +6 -1
- package/dist/arcade/surface.js +6 -2
- package/dist/arcade/url.d.cts +4 -4
- package/dist/arcade/url.d.ts +4 -4
- package/dist/arcade/url.js +5 -5
- package/dist/arcade.cjs +322 -292
- package/dist/arcade.cjs.map +1 -1
- package/dist/arcade.d.cts +6 -6
- package/dist/arcade.d.ts +6 -6
- package/dist/arcade.js +35 -29
- package/dist/{chunk-CEJ5RFSG.js → chunk-2SZ2YYGJ.js} +8 -16
- package/dist/chunk-2SZ2YYGJ.js.map +1 -0
- package/dist/{chunk-VKBMZHMQ.js → chunk-32RSSFSF.js} +10 -12
- package/dist/chunk-32RSSFSF.js.map +1 -0
- package/dist/chunk-3YMUAKPU.js +10 -0
- package/dist/chunk-3YMUAKPU.js.map +1 -0
- package/dist/chunk-56DM2KEW.js +14 -0
- package/dist/chunk-56DM2KEW.js.map +1 -0
- package/dist/chunk-CM53YLT5.js +59 -0
- package/dist/chunk-CM53YLT5.js.map +1 -0
- package/dist/{chunk-JEHV5C2X.js → chunk-CV3PBXPT.js} +3 -3
- package/dist/chunk-D4VDEVTZ.js +80 -0
- package/dist/chunk-D4VDEVTZ.js.map +1 -0
- package/dist/{chunk-W3YA5BWR.js → chunk-FUA6EMSJ.js} +24 -60
- package/dist/chunk-FUA6EMSJ.js.map +1 -0
- package/dist/chunk-GMLU7RI5.js +70 -0
- package/dist/chunk-GMLU7RI5.js.map +1 -0
- package/dist/{chunk-NCL6WJCL.js → chunk-IG6GZZSS.js} +32 -1
- package/dist/chunk-IG6GZZSS.js.map +1 -0
- package/dist/{chunk-EDRQIOCV.js → chunk-ITMQSBTH.js} +3 -2
- package/dist/chunk-ITMQSBTH.js.map +1 -0
- package/dist/{chunk-32NYL7XI.js → chunk-J5MCII33.js} +189 -108
- package/dist/chunk-J5MCII33.js.map +1 -0
- package/dist/{chunk-ZLPL2R3R.js → chunk-K4OZ54UD.js} +7 -34
- package/dist/chunk-K4OZ54UD.js.map +1 -0
- package/dist/{chunk-KXAFI5OP.js → chunk-LIHEEAVE.js} +9 -11
- package/dist/chunk-LIHEEAVE.js.map +1 -0
- package/dist/{chunk-FAT2KJ3K.js → chunk-MIMPMB7O.js} +2 -2
- package/dist/{chunk-NUJBMV3O.js → chunk-O6X7FJ6N.js} +29 -32
- package/dist/chunk-O6X7FJ6N.js.map +1 -0
- package/dist/chunk-PSUYTD2L.js +16 -0
- package/dist/chunk-PSUYTD2L.js.map +1 -0
- package/dist/{chunk-7UXSWCZZ.js → chunk-QO4KFUEI.js} +2 -2
- package/dist/chunk-QTLYZADF.js +125 -0
- package/dist/chunk-QTLYZADF.js.map +1 -0
- package/dist/chunk-TTQDHKXL.js +3017 -0
- package/dist/chunk-TTQDHKXL.js.map +1 -0
- package/dist/chunk-UCPY7UJC.js +8 -0
- package/dist/chunk-UCPY7UJC.js.map +1 -0
- package/dist/{chunk-JO2HR5PV.js → chunk-UPV6YWT5.js} +4 -4
- package/dist/chunk-X35LLCWV.js +65 -0
- package/dist/chunk-X35LLCWV.js.map +1 -0
- package/dist/{controller-DxVchfiA.d.ts → controller-PZEM_1cH.d.ts} +6 -2
- package/dist/{controller-Bod8YYr1.d.cts → controller-vj82tKm4.d.cts} +6 -2
- package/dist/{dev-log-events-CVAM29hx.d.cts → dev-log-events-BCJKmygo.d.cts} +0 -3
- package/dist/{dev-log-events-CVAM29hx.d.ts → dev-log-events-BCJKmygo.d.ts} +0 -3
- package/dist/{host-8hmq_Sgc.d.cts → host-B9pRy0Aa.d.cts} +20 -7
- package/dist/{host-Cw-N6e-5.d.ts → host-DylGsX7p.d.ts} +20 -7
- package/dist/index.cjs +4275 -3813
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -642
- package/dist/index.d.ts +40 -642
- package/dist/index.js +1032 -3658
- package/dist/index.js.map +1 -1
- package/dist/metadata.cjs.map +1 -1
- package/dist/metadata.d.cts +2 -3
- package/dist/metadata.d.ts +2 -3
- package/dist/metadata.js.map +1 -1
- package/dist/{notices-CnGaaS8B.d.ts → notices-C4bao3oi.d.ts} +1 -1
- package/dist/{notices-NyDM5Mtz.d.cts → notices-DNdOjwtj.d.cts} +1 -1
- package/dist/platform-machine.cjs +115 -15
- package/dist/platform-machine.cjs.map +1 -1
- package/dist/platform-machine.d.cts +1338 -65
- package/dist/platform-machine.d.ts +1338 -65
- package/dist/platform-machine.js +88 -15
- package/dist/platform-machine.js.map +1 -1
- package/dist/{platform-settings-cuor3i11.d.cts → platform-settings-DUWs4JTy.d.cts} +1 -1
- package/dist/{platform-settings-cuor3i11.d.ts → platform-settings-DUWs4JTy.d.ts} +1 -1
- package/dist/preview.cjs +301 -253
- package/dist/preview.cjs.map +1 -1
- package/dist/preview.d.cts +6 -4
- package/dist/preview.d.ts +6 -4
- package/dist/preview.js +31 -21
- package/dist/preview.js.map +1 -1
- package/dist/protocol.cjs +282 -167
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +74 -21
- package/dist/protocol.d.ts +74 -21
- package/dist/protocol.js +28 -10
- package/dist/release.cjs +37 -0
- package/dist/release.cjs.map +1 -1
- package/dist/release.d.cts +27 -1
- package/dist/release.d.ts +27 -1
- package/dist/release.js +13 -1
- package/dist/runtime-control.cjs +46 -0
- package/dist/runtime-control.cjs.map +1 -0
- package/dist/runtime-control.d.cts +17 -0
- package/dist/runtime-control.d.ts +17 -0
- package/dist/runtime-control.js +8 -0
- package/dist/runtime-control.js.map +1 -0
- package/dist/runtime-inspection.cjs +655 -0
- package/dist/runtime-inspection.cjs.map +1 -0
- package/dist/runtime-inspection.d.cts +47 -0
- package/dist/runtime-inspection.d.ts +47 -0
- package/dist/runtime-inspection.js +30 -0
- package/dist/runtime-inspection.js.map +1 -0
- package/dist/runtime-reporting-pe-eryVz.d.cts +27 -0
- package/dist/runtime-reporting-pe-eryVz.d.ts +27 -0
- package/dist/signals-ZHftIKuc.d.cts +33 -0
- package/dist/signals-ZHftIKuc.d.ts +33 -0
- package/dist/{standard-match-phase-BucA5dYo.d.ts → standard-match-phase-BzSgBYFg.d.ts} +2 -2
- package/dist/{standard-match-phase-U2ra8J-0.d.cts → standard-match-phase-CvJUW8Oe.d.cts} +2 -2
- package/dist/{sync-B6QsNrXz.d.cts → sync-xtPfWhif.d.cts} +1 -45
- package/dist/{sync-B6QsNrXz.d.ts → sync-xtPfWhif.d.ts} +1 -45
- package/dist/ui.cjs +689 -629
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.cts +14 -4
- package/dist/ui.d.ts +14 -4
- package/dist/ui.js +117 -35
- package/dist/ui.js.map +1 -1
- package/dist/use-air-jam-host-COLy8t4s.d.ts +403 -0
- package/dist/use-air-jam-host-DM-ybB3C.d.cts +403 -0
- package/package.json +55 -21
- package/src/agent/agent-contract-conformance.ts +201 -0
- package/src/agent-tooling.ts +5 -0
- package/src/arcade/runtime.ts +6 -0
- package/src/arcade/surface.ts +1 -0
- package/src/components/join-qr-overlay.tsx +115 -31
- package/src/context/air-jam-context.tsx +8 -8
- package/src/context/socket-manager.ts +0 -7
- package/src/dev/browser-log-sink.ts +12 -15
- package/src/events.ts +0 -5
- package/src/hooks/internal/use-controller-runtime-api.ts +110 -21
- package/src/hooks/internal/use-host-runtime-api.ts +306 -49
- package/src/hooks/use-air-jam-controller.ts +9 -9
- package/src/hooks/use-air-jam-host.ts +7 -7
- package/src/hooks/use-get-input.ts +1 -1
- package/src/hooks/use-host-arcade-restore.ts +6 -1
- package/src/hooks/use-host-audio-mute-preference.ts +99 -0
- package/src/index.ts +6 -21
- package/src/metadata/manifest.ts +2 -3
- package/src/platform-machine.ts +109 -12
- package/src/preview/workspace.tsx +48 -29
- package/src/protocol/arcade-platform-actions.ts +19 -1
- package/src/protocol/controller.ts +8 -2
- package/src/protocol/dev-log-events.ts +0 -3
- package/src/protocol/host-grant.ts +58 -140
- package/src/protocol/host.ts +21 -9
- package/src/protocol/runtime-reporting.ts +32 -0
- package/src/protocol/signed-envelope.ts +176 -0
- package/src/protocol/socket-events.ts +8 -10
- package/src/protocol/sync.ts +0 -16
- package/src/protocol.ts +2 -0
- package/src/release.ts +32 -0
- package/src/runtime/admission-retry.ts +62 -0
- package/src/runtime/air-jam-config.ts +6 -16
- package/src/runtime/air-jam-error-boundary.tsx +46 -2
- package/src/runtime/bridge-envelope-args.ts +21 -0
- package/src/runtime/connected-runtime-error-boundary.tsx +31 -0
- package/src/runtime/contracts/control.ts +107 -59
- package/src/runtime/controller-bridge.ts +12 -24
- package/src/runtime/controller-identity.ts +55 -27
- package/src/runtime/controller-realtime-client.ts +8 -47
- package/src/runtime/create-air-jam-app.tsx +21 -13
- package/src/runtime/host-bridge.ts +16 -24
- package/src/runtime/local-reference-game-identity.ts +13 -0
- package/src/runtime/runtime-session-params.ts +4 -64
- package/src/runtime-control.ts +3 -8
- package/src/settings/platform-settings-runtime.tsx +1 -6
- package/src/settings/platform-settings.ts +7 -38
- package/src/state/connection-store.ts +13 -6
- package/src/store/create-air-jam-store.ts +59 -7
- package/src/utils/ids.ts +32 -5
- package/dist/capabilities.cjs +0 -39
- package/dist/capabilities.cjs.map +0 -1
- package/dist/capabilities.d.cts +0 -31
- package/dist/capabilities.d.ts +0 -31
- package/dist/capabilities.js +0 -12
- package/dist/capabilities.js.map +0 -1
- package/dist/chunk-32NYL7XI.js.map +0 -1
- package/dist/chunk-CABEUV65.js +0 -184
- package/dist/chunk-CABEUV65.js.map +0 -1
- package/dist/chunk-CEJ5RFSG.js.map +0 -1
- package/dist/chunk-EDRQIOCV.js.map +0 -1
- package/dist/chunk-KXAFI5OP.js.map +0 -1
- package/dist/chunk-NCL6WJCL.js.map +0 -1
- package/dist/chunk-NUJBMV3O.js.map +0 -1
- package/dist/chunk-VKBMZHMQ.js.map +0 -1
- package/dist/chunk-W3YA5BWR.js.map +0 -1
- package/dist/chunk-ZLPL2R3R.js.map +0 -1
- package/dist/chunk-ZTQ5SP4H.js +0 -9
- package/dist/chunk-ZTQ5SP4H.js.map +0 -1
- package/src/capabilities/manifest.ts +0 -71
- package/src/capabilities.ts +0 -12
- package/src/hooks/internal/use-runtime-control-contract.ts +0 -15
- package/src/hooks/internal/use-runtime-observability-contract.ts +0 -24
- package/src/runtime/contracts/observability.ts +0 -94
- package/src/runtime-observability.ts +0 -9
- /package/dist/{chunk-JEHV5C2X.js.map → chunk-CV3PBXPT.js.map} +0 -0
- /package/dist/{chunk-FAT2KJ3K.js.map → chunk-MIMPMB7O.js.map} +0 -0
- /package/dist/{chunk-7UXSWCZZ.js.map → chunk-QO4KFUEI.js.map} +0 -0
- /package/dist/{chunk-JO2HR5PV.js.map → chunk-UPV6YWT5.js.map} +0 -0
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { AirJamSocket } from "../context/socket-manager";
|
|
2
|
-
import {
|
|
3
|
-
AIRJAM_DEV_LOG_EVENTS,
|
|
4
|
-
type ControllerActionRpcPayload,
|
|
5
|
-
type RoomCode,
|
|
6
|
-
} from "../protocol";
|
|
2
|
+
import { AIRJAM_DEV_LOG_EVENTS, type RoomCode } from "../protocol";
|
|
7
3
|
import {
|
|
8
4
|
createControllerBridgeCloseMessage,
|
|
9
5
|
createControllerBridgeEmitMessage,
|
|
@@ -32,34 +28,6 @@ const CONTROLLER_BRIDGE_RUNTIME_KIND = "arcade-controller-runtime";
|
|
|
32
28
|
const BRIDGE_TRANSIENT_CLOSE_REASONS = new Set(["game_unloaded", "replaced"]);
|
|
33
29
|
const BRIDGE_TRANSIENT_FAILURE_REASONS = new Set(["handshake_timeout"]);
|
|
34
30
|
|
|
35
|
-
type LegacyControllerActionRpcPayload = Omit<
|
|
36
|
-
ControllerActionRpcPayload,
|
|
37
|
-
"payload"
|
|
38
|
-
> & {
|
|
39
|
-
payload: ControllerActionRpcPayload["payload"] | null;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const normalizeControllerEmitArgs = (
|
|
43
|
-
event: string,
|
|
44
|
-
args: unknown[],
|
|
45
|
-
): unknown[] => {
|
|
46
|
-
if (event !== "controller:action_rpc") {
|
|
47
|
-
return args;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const [payload, ...rest] = args;
|
|
51
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
52
|
-
return args;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const actionPayload = payload as LegacyControllerActionRpcPayload;
|
|
56
|
-
if (actionPayload.payload !== null) {
|
|
57
|
-
return args;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return [{ ...actionPayload, payload: undefined }, ...rest];
|
|
61
|
-
};
|
|
62
|
-
|
|
63
31
|
class DirectControllerRealtimeClient implements AirJamRealtimeClient {
|
|
64
32
|
constructor(private readonly socket: AirJamSocket) {}
|
|
65
33
|
|
|
@@ -103,7 +71,7 @@ class DirectControllerRealtimeClient implements AirJamRealtimeClient {
|
|
|
103
71
|
event: string,
|
|
104
72
|
...args: unknown[]
|
|
105
73
|
) => void
|
|
106
|
-
).call(this.socket, event, ...
|
|
74
|
+
).call(this.socket, event, ...args);
|
|
107
75
|
return this;
|
|
108
76
|
}
|
|
109
77
|
|
|
@@ -123,15 +91,10 @@ class DirectControllerRealtimeClient implements AirJamRealtimeClient {
|
|
|
123
91
|
event: string,
|
|
124
92
|
...args: unknown[]
|
|
125
93
|
) => void
|
|
126
|
-
).call(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
(ack: TAck) => {
|
|
131
|
-
clearTimeout(timeoutId);
|
|
132
|
-
resolve(ack);
|
|
133
|
-
},
|
|
134
|
-
);
|
|
94
|
+
).call(this.socket, event, ...args, (ack: TAck) => {
|
|
95
|
+
clearTimeout(timeoutId);
|
|
96
|
+
resolve(ack);
|
|
97
|
+
});
|
|
135
98
|
});
|
|
136
99
|
}
|
|
137
100
|
}
|
|
@@ -255,11 +218,10 @@ class EmbeddedControllerBridgeClient implements AirJamRealtimeClient {
|
|
|
255
218
|
}
|
|
256
219
|
|
|
257
220
|
const bridgeEvent = event as ControllerBridgeClientEventName;
|
|
258
|
-
const normalizedArgs = normalizeControllerEmitArgs(event, args);
|
|
259
221
|
this.port.postMessage(
|
|
260
222
|
createControllerBridgeEmitMessage(
|
|
261
223
|
bridgeEvent,
|
|
262
|
-
...(
|
|
224
|
+
...(args as ControllerBridgeClientEventArgs[typeof bridgeEvent]),
|
|
263
225
|
),
|
|
264
226
|
);
|
|
265
227
|
return this;
|
|
@@ -295,11 +257,10 @@ class EmbeddedControllerBridgeClient implements AirJamRealtimeClient {
|
|
|
295
257
|
});
|
|
296
258
|
|
|
297
259
|
const bridgeEvent = event as ControllerBridgeClientEventName;
|
|
298
|
-
const normalizedArgs = normalizeControllerEmitArgs(event, args);
|
|
299
260
|
this.port?.postMessage(
|
|
300
261
|
createControllerBridgeEmitMessage(
|
|
301
262
|
bridgeEvent,
|
|
302
|
-
...(
|
|
263
|
+
...(args as ControllerBridgeClientEventArgs[typeof bridgeEvent]),
|
|
303
264
|
{ requestId },
|
|
304
265
|
),
|
|
305
266
|
);
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type { ResolvedAirJamRuntimeTopology } from "../runtime-topology";
|
|
2
|
-
import { resolveProjectRuntimeTopology } from "../runtime-topology";
|
|
3
1
|
import type { JSX, ReactNode } from "react";
|
|
4
2
|
import type { z } from "zod";
|
|
5
3
|
import type { AirJamAgentContract } from "../agent/agent-contract";
|
|
6
|
-
import type { AirJamGameCapabilityManifest } from "../capabilities/manifest";
|
|
7
4
|
import { CONTROLLER_PATH } from "../constants";
|
|
8
5
|
import { type AirJamProviderProps } from "../context/session-providers";
|
|
9
6
|
import type { AirJamControllerOptions } from "../hooks/use-air-jam-controller";
|
|
10
7
|
import type { AirJamHostOptions } from "../hooks/use-air-jam-host";
|
|
11
8
|
import type { AirJamGameMetadata } from "../metadata/manifest";
|
|
9
|
+
import type { ResolvedAirJamRuntimeTopology } from "../runtime-topology";
|
|
10
|
+
import { resolveProjectRuntimeTopology } from "../runtime-topology";
|
|
12
11
|
import { type ResolveAirJamConfigInput } from "./air-jam-config";
|
|
13
12
|
import {
|
|
14
13
|
AirJamErrorBoundary,
|
|
15
14
|
type AirJamErrorBoundaryProps,
|
|
16
15
|
type AirJamErrorFallbackRenderer,
|
|
17
16
|
} from "./air-jam-error-boundary";
|
|
17
|
+
import { ConnectedRuntimeErrorBoundary } from "./connected-runtime-error-boundary";
|
|
18
18
|
import { AirJamControllerRuntime, AirJamHostRuntime } from "./session-runtimes";
|
|
19
19
|
|
|
20
20
|
type HostSessionProps<TSchema extends z.ZodSchema> = Omit<
|
|
@@ -44,11 +44,6 @@ export interface CreateAirJamAppOptions<
|
|
|
44
44
|
* Defaults to "/controller".
|
|
45
45
|
*/
|
|
46
46
|
controllerPath?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Experimental capability metadata for future agent-facing control,
|
|
49
|
-
* inspection, and evaluation workflows.
|
|
50
|
-
*/
|
|
51
|
-
capabilities?: AirJamGameCapabilityManifest;
|
|
52
47
|
/**
|
|
53
48
|
* Optional semantic agent contract published by the app.
|
|
54
49
|
*/
|
|
@@ -72,7 +67,6 @@ export interface AirJamApp<TSchema extends z.ZodSchema = z.ZodSchema> {
|
|
|
72
67
|
runtime: ResolveAirJamConfigInput;
|
|
73
68
|
metadata?: AirJamGameMetadata;
|
|
74
69
|
controllerPath: string;
|
|
75
|
-
capabilities?: AirJamGameCapabilityManifest;
|
|
76
70
|
agent?: AirJamAgentContract;
|
|
77
71
|
}
|
|
78
72
|
|
|
@@ -179,7 +173,6 @@ export const createAirJamApp = <TSchema extends z.ZodSchema = z.ZodSchema>({
|
|
|
179
173
|
runtime = {},
|
|
180
174
|
metadata,
|
|
181
175
|
controllerPath: requestedControllerPath,
|
|
182
|
-
capabilities,
|
|
183
176
|
agent,
|
|
184
177
|
input,
|
|
185
178
|
errorBoundary,
|
|
@@ -215,7 +208,15 @@ export const createAirJamApp = <TSchema extends z.ZodSchema = z.ZodSchema>({
|
|
|
215
208
|
onError={hostErrorBoundary?.onError}
|
|
216
209
|
>
|
|
217
210
|
<AirJamHostRuntime<TSchema> {...hostSession} {...runtimeOptions}>
|
|
218
|
-
|
|
211
|
+
<ConnectedRuntimeErrorBoundary
|
|
212
|
+
role="host"
|
|
213
|
+
roomId={runtimeOptions.roomId}
|
|
214
|
+
appId={hostSession.appId}
|
|
215
|
+
renderFallback={hostErrorBoundary?.renderFallback}
|
|
216
|
+
onError={hostErrorBoundary?.onError}
|
|
217
|
+
>
|
|
218
|
+
{children}
|
|
219
|
+
</ConnectedRuntimeErrorBoundary>
|
|
219
220
|
</AirJamHostRuntime>
|
|
220
221
|
</AirJamErrorBoundary>
|
|
221
222
|
);
|
|
@@ -235,7 +236,15 @@ export const createAirJamApp = <TSchema extends z.ZodSchema = z.ZodSchema>({
|
|
|
235
236
|
onError={controllerErrorBoundary?.onError}
|
|
236
237
|
>
|
|
237
238
|
<AirJamControllerRuntime {...controllerSession} {...runtimeOptions}>
|
|
238
|
-
|
|
239
|
+
<ConnectedRuntimeErrorBoundary
|
|
240
|
+
role="controller"
|
|
241
|
+
roomId={runtimeOptions.roomId}
|
|
242
|
+
appId={controllerSession.appId}
|
|
243
|
+
renderFallback={controllerErrorBoundary?.renderFallback}
|
|
244
|
+
onError={controllerErrorBoundary?.onError}
|
|
245
|
+
>
|
|
246
|
+
{children}
|
|
247
|
+
</ConnectedRuntimeErrorBoundary>
|
|
239
248
|
</AirJamControllerRuntime>
|
|
240
249
|
</AirJamErrorBoundary>
|
|
241
250
|
);
|
|
@@ -254,7 +263,6 @@ export const createAirJamApp = <TSchema extends z.ZodSchema = z.ZodSchema>({
|
|
|
254
263
|
runtime,
|
|
255
264
|
metadata,
|
|
256
265
|
controllerPath,
|
|
257
|
-
capabilities,
|
|
258
266
|
agent,
|
|
259
267
|
};
|
|
260
268
|
};
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
arcadeSurfaceRuntimeIdentitySchema,
|
|
22
22
|
type ArcadeSurfaceRuntimeIdentity,
|
|
23
23
|
} from "./arcade-surface-identity";
|
|
24
|
+
import { splitBridgeEnvelopeArgs } from "./bridge-envelope-args";
|
|
24
25
|
import { createBridgeHandshake } from "./iframe-bridge";
|
|
25
26
|
import { AIR_JAM_SDK_VERSION } from "./sdk-version";
|
|
26
27
|
|
|
@@ -59,6 +60,13 @@ export const hostBridgeServerEvents = [
|
|
|
59
60
|
export type HostBridgeClientEventName = (typeof hostBridgeClientEvents)[number];
|
|
60
61
|
export type HostBridgeServerEventName = (typeof hostBridgeServerEvents)[number];
|
|
61
62
|
|
|
63
|
+
const HOST_BRIDGE_ZERO_REQUIRED_ARGS_EVENTS =
|
|
64
|
+
new Set<HostBridgeServerEventName>([
|
|
65
|
+
"connect",
|
|
66
|
+
"disconnect",
|
|
67
|
+
"server:closeChild",
|
|
68
|
+
]);
|
|
69
|
+
|
|
62
70
|
export type HostBridgeClientEventArgs = {
|
|
63
71
|
"host:state": [payload: ControllerStateMessage];
|
|
64
72
|
"host:signal": [payload: SignalPayload];
|
|
@@ -269,35 +277,16 @@ export const createHostBridgeAttachMessage = (
|
|
|
269
277
|
},
|
|
270
278
|
});
|
|
271
279
|
|
|
272
|
-
const splitHostBridgeArgs = (
|
|
273
|
-
args: unknown[],
|
|
274
|
-
): {
|
|
275
|
-
eventArgs: unknown[];
|
|
276
|
-
requestId?: string;
|
|
277
|
-
} => {
|
|
278
|
-
const maybeOptions = args[args.length - 1] as
|
|
279
|
-
| { requestId?: string }
|
|
280
|
-
| undefined;
|
|
281
|
-
const hasOptions =
|
|
282
|
-
typeof maybeOptions === "object" &&
|
|
283
|
-
maybeOptions !== null &&
|
|
284
|
-
"requestId" in maybeOptions;
|
|
285
|
-
|
|
286
|
-
return {
|
|
287
|
-
eventArgs: hasOptions ? args.slice(0, -1) : args,
|
|
288
|
-
...(hasOptions && maybeOptions.requestId
|
|
289
|
-
? { requestId: maybeOptions.requestId }
|
|
290
|
-
: {}),
|
|
291
|
-
};
|
|
292
|
-
};
|
|
293
|
-
|
|
294
280
|
export const createHostBridgeEventMessage = <
|
|
295
281
|
TEvent extends HostBridgeServerEventName,
|
|
296
282
|
>(
|
|
297
283
|
event: TEvent,
|
|
298
284
|
...args: [...HostBridgeServerEventArgs[TEvent], { requestId?: string }?]
|
|
299
285
|
): HostBridgeEventMessage => {
|
|
300
|
-
const { eventArgs, requestId } =
|
|
286
|
+
const { eventArgs, requestId } = splitBridgeEnvelopeArgs(
|
|
287
|
+
args as unknown[],
|
|
288
|
+
HOST_BRIDGE_ZERO_REQUIRED_ARGS_EVENTS.has(event) ? 0 : 1,
|
|
289
|
+
);
|
|
301
290
|
return {
|
|
302
291
|
type: AIRJAM_HOST_BRIDGE_EVENT,
|
|
303
292
|
payload: {
|
|
@@ -314,7 +303,10 @@ export const createHostBridgeEmitMessage = <
|
|
|
314
303
|
event: TEvent,
|
|
315
304
|
...args: [...HostBridgeClientEventArgs[TEvent], { requestId?: string }?]
|
|
316
305
|
): HostBridgeEmitMessage => {
|
|
317
|
-
const { eventArgs, requestId } =
|
|
306
|
+
const { eventArgs, requestId } = splitBridgeEnvelopeArgs(
|
|
307
|
+
args as unknown[],
|
|
308
|
+
1,
|
|
309
|
+
);
|
|
318
310
|
return {
|
|
319
311
|
type: AIRJAM_HOST_BRIDGE_EMIT,
|
|
320
312
|
payload: {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const LOCAL_REFERENCE_GAME_PREFIX = "local-reference-";
|
|
2
|
+
|
|
3
|
+
/** Namespaces a local workspace game in the development Arcade catalog. */
|
|
4
|
+
export const localReferenceGameId = (sourceGameId: string): string =>
|
|
5
|
+
`${LOCAL_REFERENCE_GAME_PREFIX}${sourceGameId}`;
|
|
6
|
+
|
|
7
|
+
/** Returns the workspace game ID only for a local-reference catalog identity. */
|
|
8
|
+
export const localReferenceSourceGameId = (
|
|
9
|
+
runtimeGameId: string,
|
|
10
|
+
): string | null =>
|
|
11
|
+
runtimeGameId.startsWith(LOCAL_REFERENCE_GAME_PREFIX)
|
|
12
|
+
? runtimeGameId.slice(LOCAL_REFERENCE_GAME_PREFIX.length) || null
|
|
13
|
+
: null;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type { ResolvedAirJamRuntimeTopology } from "../runtime-topology";
|
|
2
|
-
import {
|
|
3
|
-
parseRuntimeTopologyFromSearchParams,
|
|
4
|
-
resolveRuntimeTopology,
|
|
5
|
-
} from "../runtime-topology";
|
|
6
1
|
import type { PlayerProfile } from "../protocol";
|
|
7
2
|
import { normalizeRuntimeUrl } from "../protocol/url-policy";
|
|
3
|
+
import type { ResolvedAirJamRuntimeTopology } from "../runtime-topology";
|
|
4
|
+
import { parseRuntimeTopologyFromSearchParams } from "../runtime-topology";
|
|
8
5
|
import { parseOptionalArcadeSurfaceFromSearchParams } from "./arcade-runtime-url";
|
|
9
6
|
import type { ArcadeSurfaceRuntimeIdentity } from "./arcade-surface-identity";
|
|
10
7
|
|
|
@@ -28,54 +25,6 @@ export interface EmbeddedControllerRuntimeParams {
|
|
|
28
25
|
};
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
const parseOrigin = (value: string | null | undefined): string | null => {
|
|
32
|
-
if (!value) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
return new URL(value).origin;
|
|
38
|
-
} catch {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const resolveLegacyEmbeddedTopology = ({
|
|
44
|
-
surfaceRole,
|
|
45
|
-
joinUrl,
|
|
46
|
-
}: {
|
|
47
|
-
surfaceRole: "host" | "controller";
|
|
48
|
-
joinUrl?: string;
|
|
49
|
-
}): ResolvedAirJamRuntimeTopology | null => {
|
|
50
|
-
if (typeof window === "undefined") {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const appOrigin = window.location.origin;
|
|
55
|
-
const joinUrlOrigin = parseOrigin(joinUrl);
|
|
56
|
-
const referrerOrigin = parseOrigin(document.referrer);
|
|
57
|
-
const embedParentOrigin = joinUrlOrigin ?? referrerOrigin ?? appOrigin;
|
|
58
|
-
const publicHost = joinUrlOrigin ?? appOrigin;
|
|
59
|
-
const secureTransport =
|
|
60
|
-
appOrigin.startsWith("https://") &&
|
|
61
|
-
publicHost.startsWith("https://") &&
|
|
62
|
-
embedParentOrigin.startsWith("https://");
|
|
63
|
-
|
|
64
|
-
return resolveRuntimeTopology({
|
|
65
|
-
runtimeMode: "arcade-live",
|
|
66
|
-
surfaceRole,
|
|
67
|
-
appOrigin,
|
|
68
|
-
backendOrigin: appOrigin,
|
|
69
|
-
socketOrigin: appOrigin,
|
|
70
|
-
publicHost,
|
|
71
|
-
assetBasePath: "/",
|
|
72
|
-
secureTransport,
|
|
73
|
-
embedded: true,
|
|
74
|
-
embedParentOrigin,
|
|
75
|
-
proxyStrategy: "none",
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
28
|
export const readChildHostRuntimeParams = (): ChildHostRuntimeParams | null => {
|
|
80
29
|
if (typeof window === "undefined") {
|
|
81
30
|
return null;
|
|
@@ -95,12 +44,7 @@ export const readChildHostRuntimeParams = (): ChildHostRuntimeParams | null => {
|
|
|
95
44
|
|
|
96
45
|
const joinUrl = params.get("aj_join_url");
|
|
97
46
|
const normalizedJoinUrl = joinUrl ? normalizeRuntimeUrl(joinUrl) : null;
|
|
98
|
-
const topology =
|
|
99
|
-
parseRuntimeTopologyFromSearchParams(params) ??
|
|
100
|
-
resolveLegacyEmbeddedTopology({
|
|
101
|
-
surfaceRole: "host",
|
|
102
|
-
joinUrl: normalizedJoinUrl ?? undefined,
|
|
103
|
-
});
|
|
47
|
+
const topology = parseRuntimeTopologyFromSearchParams(params);
|
|
104
48
|
if (!topology) {
|
|
105
49
|
return null;
|
|
106
50
|
}
|
|
@@ -135,11 +79,7 @@ export const readEmbeddedControllerRuntimeParams =
|
|
|
135
79
|
return null;
|
|
136
80
|
}
|
|
137
81
|
|
|
138
|
-
const topology =
|
|
139
|
-
parseRuntimeTopologyFromSearchParams(params) ??
|
|
140
|
-
resolveLegacyEmbeddedTopology({
|
|
141
|
-
surfaceRole: "controller",
|
|
142
|
-
});
|
|
82
|
+
const topology = parseRuntimeTopologyFromSearchParams(params);
|
|
143
83
|
if (!topology) {
|
|
144
84
|
return null;
|
|
145
85
|
}
|
package/src/runtime-control.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
createControllerRuntimeControlContract,
|
|
7
|
-
createHostRuntimeControlContract,
|
|
8
|
-
type ControllerRuntimeControlContract,
|
|
9
|
-
type HostRuntimeControlContract,
|
|
2
|
+
AIR_JAM_RUNTIME_CONTROL_KEY,
|
|
3
|
+
type HostRuntimeActionRequest,
|
|
4
|
+
type HostRuntimeControl,
|
|
10
5
|
} from "./runtime/contracts/control";
|
|
@@ -12,7 +12,6 @@ import { emitAirJamDevRuntimeEvent } from "../runtime/dev-runtime-events";
|
|
|
12
12
|
import {
|
|
13
13
|
DEFAULT_PLATFORM_SETTINGS,
|
|
14
14
|
getEffectiveAudioVolume,
|
|
15
|
-
LEGACY_AUDIO_SETTINGS_STORAGE_KEY,
|
|
16
15
|
mergePlatformSettings,
|
|
17
16
|
persistPlatformSettings,
|
|
18
17
|
PLATFORM_SETTINGS_STORAGE_KEY,
|
|
@@ -153,11 +152,7 @@ export function PlatformSettingsRuntime({
|
|
|
153
152
|
return;
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
if (
|
|
157
|
-
event.key !== null &&
|
|
158
|
-
event.key !== PLATFORM_SETTINGS_STORAGE_KEY &&
|
|
159
|
-
event.key !== LEGACY_AUDIO_SETTINGS_STORAGE_KEY
|
|
160
|
-
) {
|
|
155
|
+
if (event.key !== null && event.key !== PLATFORM_SETTINGS_STORAGE_KEY) {
|
|
161
156
|
return;
|
|
162
157
|
}
|
|
163
158
|
|
|
@@ -38,7 +38,6 @@ export interface PartialRoomPlatformSettingsPatch {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export const PLATFORM_SETTINGS_STORAGE_KEY = "air-jam-platform-settings";
|
|
41
|
-
export const LEGACY_AUDIO_SETTINGS_STORAGE_KEY = "air-jam-volume-settings";
|
|
42
41
|
|
|
43
42
|
export const DEFAULT_PLATFORM_SETTINGS: PlatformSettingsSnapshot = {
|
|
44
43
|
audio: {
|
|
@@ -221,53 +220,23 @@ const tryParseJson = (raw: string | null): unknown => {
|
|
|
221
220
|
}
|
|
222
221
|
};
|
|
223
222
|
|
|
224
|
-
const readLegacyAudioSettings = (): PlatformSettingsSnapshot | null => {
|
|
225
|
-
const parsed = tryParseJson(
|
|
226
|
-
window.localStorage.getItem(LEGACY_AUDIO_SETTINGS_STORAGE_KEY),
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
if (!isRecord(parsed)) {
|
|
230
|
-
return null;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return normalizePlatformSettings({
|
|
234
|
-
...DEFAULT_PLATFORM_SETTINGS,
|
|
235
|
-
audio: {
|
|
236
|
-
masterVolume: parsed.masterVolume,
|
|
237
|
-
musicVolume: parsed.musicVolume,
|
|
238
|
-
sfxVolume: parsed.sfxVolume,
|
|
239
|
-
},
|
|
240
|
-
});
|
|
241
|
-
};
|
|
242
|
-
|
|
243
223
|
export const readPersistedPlatformSettings = (): PlatformSettingsSnapshot => {
|
|
244
224
|
if (typeof window === "undefined") {
|
|
245
225
|
return DEFAULT_PLATFORM_SETTINGS;
|
|
246
226
|
}
|
|
247
227
|
|
|
248
|
-
const current = tryParseJson(
|
|
249
|
-
window.localStorage.getItem(PLATFORM_SETTINGS_STORAGE_KEY),
|
|
250
|
-
);
|
|
251
|
-
if (current) {
|
|
252
|
-
return normalizePlatformSettings(current);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const migrated = readLegacyAudioSettings();
|
|
256
|
-
if (!migrated) {
|
|
257
|
-
return DEFAULT_PLATFORM_SETTINGS;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
228
|
try {
|
|
261
|
-
|
|
262
|
-
PLATFORM_SETTINGS_STORAGE_KEY,
|
|
263
|
-
JSON.stringify(migrated),
|
|
229
|
+
const current = tryParseJson(
|
|
230
|
+
window.localStorage.getItem(PLATFORM_SETTINGS_STORAGE_KEY),
|
|
264
231
|
);
|
|
265
|
-
|
|
232
|
+
if (current) {
|
|
233
|
+
return normalizePlatformSettings(current);
|
|
234
|
+
}
|
|
266
235
|
} catch {
|
|
267
|
-
//
|
|
236
|
+
// Browser policy may deny storage entirely; settings remain usable in memory.
|
|
268
237
|
}
|
|
269
238
|
|
|
270
|
-
return
|
|
239
|
+
return DEFAULT_PLATFORM_SETTINGS;
|
|
271
240
|
};
|
|
272
241
|
|
|
273
242
|
export const persistPlatformSettings = (
|
|
@@ -6,16 +6,21 @@ import type {
|
|
|
6
6
|
ControllerOrientation,
|
|
7
7
|
ControllerPresenceNotice,
|
|
8
8
|
ControllerRoomSettingsState,
|
|
9
|
+
HostArcadeSurfaceCheckpoint,
|
|
9
10
|
HostArcadeSessionSnapshot,
|
|
10
11
|
PlayerProfile,
|
|
11
12
|
RunMode,
|
|
12
13
|
RuntimeState,
|
|
13
14
|
} from "../protocol";
|
|
14
15
|
|
|
15
|
-
export
|
|
16
|
-
phase: "idle"
|
|
17
|
-
session:
|
|
18
|
-
|
|
16
|
+
export type HostArcadeRestoreState =
|
|
17
|
+
| { phase: "idle"; session: null; surfaceCheckpoint: null }
|
|
18
|
+
| { phase: "awaiting_ack"; session: null; surfaceCheckpoint: null }
|
|
19
|
+
| {
|
|
20
|
+
phase: "pending_restore";
|
|
21
|
+
session: HostArcadeSessionSnapshot | null;
|
|
22
|
+
surfaceCheckpoint: HostArcadeSurfaceCheckpoint;
|
|
23
|
+
};
|
|
19
24
|
|
|
20
25
|
export interface AirJamStore {
|
|
21
26
|
role: ConnectionRole | null;
|
|
@@ -34,8 +39,8 @@ export interface AirJamStore {
|
|
|
34
39
|
/**
|
|
35
40
|
* Host-only reconnect restore seam used during `host:reconnect`.
|
|
36
41
|
* - `awaiting_ack`: reconnect ack is in flight, so arcade shell broadcast must stay suppressed
|
|
37
|
-
* - `pending_restore`: reconnect ack returned
|
|
38
|
-
*
|
|
42
|
+
* - `pending_restore`: reconnect ack returned Arcade counter continuity and the platform has not
|
|
43
|
+
* reconciled it with the route/session yet
|
|
39
44
|
* - `idle`: no reconnect restoration is in progress
|
|
40
45
|
*/
|
|
41
46
|
hostArcadeRestore: HostArcadeRestoreState;
|
|
@@ -83,6 +88,7 @@ export const createAirJamStore = (): StoreApi<AirJamStore> =>
|
|
|
83
88
|
hostArcadeRestore: {
|
|
84
89
|
phase: "idle",
|
|
85
90
|
session: null,
|
|
91
|
+
surfaceCheckpoint: null,
|
|
86
92
|
},
|
|
87
93
|
setHostArcadeRestore: (next) => set({ hostArcadeRestore: next }),
|
|
88
94
|
clearHostArcadeRestore: () =>
|
|
@@ -90,6 +96,7 @@ export const createAirJamStore = (): StoreApi<AirJamStore> =>
|
|
|
90
96
|
hostArcadeRestore: {
|
|
91
97
|
phase: "idle",
|
|
92
98
|
session: null,
|
|
99
|
+
surfaceCheckpoint: null,
|
|
93
100
|
},
|
|
94
101
|
}),
|
|
95
102
|
setRole: (role) => set({ role }),
|
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
AirJamStateSyncPayload,
|
|
12
12
|
} from "../protocol";
|
|
13
13
|
import { resolveImplicitReplicatedStoreDomainFromWindow } from "../runtime/arcade-runtime-url";
|
|
14
|
+
import { registerHostRuntimeActionStore } from "../runtime/contracts/control";
|
|
14
15
|
import { getControllerRealtimeClient } from "../runtime/controller-realtime-client";
|
|
15
16
|
import { getHostRealtimeClient } from "../runtime/host-realtime-client";
|
|
16
17
|
import type { AirJamRealtimeClient } from "../runtime/realtime-client";
|
|
@@ -157,6 +158,8 @@ interface StoreRuntimeSnapshot {
|
|
|
157
158
|
resolvedStoreDomain: string;
|
|
158
159
|
connectionStatus: string | null;
|
|
159
160
|
canBroadcastHostState: boolean;
|
|
161
|
+
hostStateSyncBlocked: boolean;
|
|
162
|
+
hostStateRevisionFloor: number;
|
|
160
163
|
connectedPlayerIds: string[];
|
|
161
164
|
}
|
|
162
165
|
|
|
@@ -363,6 +366,8 @@ export function createAirJamStore<T extends AirJamNetworkedState>(
|
|
|
363
366
|
resolvedStoreDomain: AIR_JAM_DEFAULT_STORE_DOMAIN,
|
|
364
367
|
connectionStatus: null,
|
|
365
368
|
canBroadcastHostState: false,
|
|
369
|
+
hostStateSyncBlocked: false,
|
|
370
|
+
hostStateRevisionFloor: 0,
|
|
366
371
|
connectedPlayerIds: [],
|
|
367
372
|
},
|
|
368
373
|
};
|
|
@@ -673,7 +678,7 @@ export function createAirJamStore<T extends AirJamNetworkedState>(
|
|
|
673
678
|
if (role === "host") {
|
|
674
679
|
let syncedStateData = stripActionsFromState(store.getState());
|
|
675
680
|
let syncedStateSignature = JSON.stringify(syncedStateData);
|
|
676
|
-
let syncRevision =
|
|
681
|
+
let syncRevision = runtimeSnapshotRef.current.hostStateRevisionFloor;
|
|
677
682
|
|
|
678
683
|
const emitHostStateSync = (requestId?: string): void => {
|
|
679
684
|
const runtime = runtimeSnapshotRef.current;
|
|
@@ -687,6 +692,8 @@ export function createAirJamStore<T extends AirJamNetworkedState>(
|
|
|
687
692
|
return;
|
|
688
693
|
}
|
|
689
694
|
|
|
695
|
+
syncRevision = Math.max(syncRevision, runtime.hostStateRevisionFloor);
|
|
696
|
+
|
|
690
697
|
runtime.socket.emit("host:state_sync", {
|
|
691
698
|
roomId,
|
|
692
699
|
data: syncedStateData,
|
|
@@ -709,9 +716,7 @@ export function createAirJamStore<T extends AirJamNetworkedState>(
|
|
|
709
716
|
if (
|
|
710
717
|
runtime.role !== "host" ||
|
|
711
718
|
runtime.roomId !== roomId ||
|
|
712
|
-
runtime.resolvedStoreDomain !== resolvedStoreDomain
|
|
713
|
-
!runtime.canBroadcastHostState ||
|
|
714
|
-
!runtime.socket
|
|
719
|
+
runtime.resolvedStoreDomain !== resolvedStoreDomain
|
|
715
720
|
) {
|
|
716
721
|
return;
|
|
717
722
|
}
|
|
@@ -724,8 +729,11 @@ export function createAirJamStore<T extends AirJamNetworkedState>(
|
|
|
724
729
|
|
|
725
730
|
syncedStateData = stateData;
|
|
726
731
|
syncedStateSignature = nextSignature;
|
|
732
|
+
syncRevision = Math.max(syncRevision, runtime.hostStateRevisionFloor);
|
|
727
733
|
syncRevision += 1;
|
|
728
|
-
|
|
734
|
+
if (runtime.canBroadcastHostState && runtime.socket) {
|
|
735
|
+
emitHostStateSync();
|
|
736
|
+
}
|
|
729
737
|
});
|
|
730
738
|
|
|
731
739
|
const handleAction = (
|
|
@@ -821,6 +829,9 @@ export function createAirJamStore<T extends AirJamNetworkedState>(
|
|
|
821
829
|
if (payload.storeDomain !== resolvedStoreDomain) {
|
|
822
830
|
return;
|
|
823
831
|
}
|
|
832
|
+
if (runtimeSnapshotRef.current.hostStateSyncBlocked) {
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
824
835
|
if (payload.revision < syncRevision) {
|
|
825
836
|
return;
|
|
826
837
|
}
|
|
@@ -846,10 +857,45 @@ export function createAirJamStore<T extends AirJamNetworkedState>(
|
|
|
846
857
|
socket.on("airjam:state_sync_request", handleStateSyncRequest);
|
|
847
858
|
socket.on("airjam:action_rpc", handleAction);
|
|
848
859
|
|
|
860
|
+
const unregisterControl =
|
|
861
|
+
typeof window === "undefined"
|
|
862
|
+
? undefined
|
|
863
|
+
: registerHostRuntimeActionStore(window, {
|
|
864
|
+
roomId,
|
|
865
|
+
storeDomain: resolvedStoreDomain,
|
|
866
|
+
invoke: async ({ actionName, payload }) => {
|
|
867
|
+
const runtime = runtimeSnapshotRef.current;
|
|
868
|
+
if (
|
|
869
|
+
runtime.role !== "host" ||
|
|
870
|
+
runtime.roomId !== roomId ||
|
|
871
|
+
runtime.resolvedStoreDomain !== resolvedStoreDomain ||
|
|
872
|
+
runtime.socket !== socket ||
|
|
873
|
+
!runtime.canBroadcastHostState
|
|
874
|
+
) {
|
|
875
|
+
return createClientRejectedActionResult(
|
|
876
|
+
"host_runtime_not_ready",
|
|
877
|
+
"The owning host runtime is not ready for actions.",
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
const actions = createDispatchedActions({ kind: "default" });
|
|
881
|
+
if (!Object.hasOwn(actions, actionName)) {
|
|
882
|
+
return createClientRejectedActionResult(
|
|
883
|
+
"action_not_found",
|
|
884
|
+
"The requested public action is not registered on this host store.",
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
const invoke = actions[actionName] as (
|
|
888
|
+
payload: unknown,
|
|
889
|
+
) => Promise<AirJamActionInvocationResult>;
|
|
890
|
+
return invoke(payload);
|
|
891
|
+
},
|
|
892
|
+
});
|
|
893
|
+
|
|
849
894
|
return {
|
|
850
895
|
refCount: 0,
|
|
851
896
|
flushHostStateSync,
|
|
852
897
|
cleanup: () => {
|
|
898
|
+
unregisterControl?.();
|
|
853
899
|
unsubscribe();
|
|
854
900
|
socket.off("server:controllerJoined", handleControllerJoined);
|
|
855
901
|
socket.off("airjam:state_sync", handleSync);
|
|
@@ -917,14 +963,18 @@ export function createAirJamStore<T extends AirJamNetworkedState>(
|
|
|
917
963
|
const hostArcadeRestore = useAirJamState(
|
|
918
964
|
(state) => state.hostArcadeRestore,
|
|
919
965
|
);
|
|
920
|
-
const
|
|
966
|
+
const blockArcadeShellHostStateSync =
|
|
921
967
|
resolvedStoreDomain === AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN &&
|
|
922
968
|
hostArcadeRestore.phase !== "idle";
|
|
969
|
+
const hostStateRevisionFloor =
|
|
970
|
+
resolvedStoreDomain === AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN
|
|
971
|
+
? (hostArcadeRestore.surfaceCheckpoint?.revision ?? 0)
|
|
972
|
+
: 0;
|
|
923
973
|
const canBroadcastHostState =
|
|
924
974
|
role === "host" &&
|
|
925
975
|
!!roomId &&
|
|
926
976
|
registeredRoomId === roomId &&
|
|
927
|
-
!
|
|
977
|
+
!blockArcadeShellHostStateSync;
|
|
928
978
|
const connectedPlayerIds = useMemo(
|
|
929
979
|
() => Array.from(new Set(players.map((player) => player.id))).sort(),
|
|
930
980
|
[players],
|
|
@@ -949,6 +999,8 @@ export function createAirJamStore<T extends AirJamNetworkedState>(
|
|
|
949
999
|
resolvedStoreDomain,
|
|
950
1000
|
connectionStatus,
|
|
951
1001
|
canBroadcastHostState,
|
|
1002
|
+
hostStateSyncBlocked: blockArcadeShellHostStateSync,
|
|
1003
|
+
hostStateRevisionFloor,
|
|
952
1004
|
connectedPlayerIds,
|
|
953
1005
|
};
|
|
954
1006
|
|