@air-jam/sdk 0.9.2 → 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-Q4UALQO4.js → chunk-2SZ2YYGJ.js} +8 -16
- package/dist/chunk-2SZ2YYGJ.js.map +1 -0
- package/dist/{chunk-KOB73SPD.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-DY67S3LR.js → chunk-CV3PBXPT.js} +3 -3
- package/dist/chunk-D4VDEVTZ.js +80 -0
- package/dist/chunk-D4VDEVTZ.js.map +1 -0
- package/dist/{chunk-E5PVHEAX.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-6CMB356F.js → chunk-LIHEEAVE.js} +9 -11
- package/dist/chunk-LIHEEAVE.js.map +1 -0
- package/dist/{chunk-7OTQTT6H.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-M4DKOI42.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 +4260 -3870
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -649
- package/dist/index.d.ts +40 -649
- package/dist/index.js +1030 -3727
- 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 +593 -610
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.cts +3 -3
- package/dist/ui.d.ts +3 -3
- package/dist/ui.js +16 -11
- 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/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/index.ts +6 -25
- 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-6CMB356F.js.map +0 -1
- package/dist/chunk-CVYR5RJT.js +0 -184
- package/dist/chunk-CVYR5RJT.js.map +0 -1
- package/dist/chunk-E5PVHEAX.js.map +0 -1
- package/dist/chunk-EDRQIOCV.js.map +0 -1
- package/dist/chunk-KOB73SPD.js.map +0 -1
- package/dist/chunk-NCL6WJCL.js.map +0 -1
- package/dist/chunk-NUJBMV3O.js.map +0 -1
- package/dist/chunk-Q4UALQO4.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-DY67S3LR.js.map → chunk-CV3PBXPT.js.map} +0 -0
- /package/dist/{chunk-7OTQTT6H.js.map → chunk-MIMPMB7O.js.map} +0 -0
- /package/dist/{chunk-M4DKOI42.js.map → chunk-QO4KFUEI.js.map} +0 -0
- /package/dist/{chunk-JO2HR5PV.js.map → chunk-UPV6YWT5.js.map} +0 -0
|
@@ -39,6 +39,10 @@ import {
|
|
|
39
39
|
roomCodeSchema,
|
|
40
40
|
} from "../../protocol";
|
|
41
41
|
import type { PlayerUpdatedNotice } from "../../protocol/notices";
|
|
42
|
+
import {
|
|
43
|
+
resolveAdmissionRetry,
|
|
44
|
+
type AdmissionRetryDecision,
|
|
45
|
+
} from "../../runtime/admission-retry";
|
|
42
46
|
import { emitAirJamDevRuntimeEvent } from "../../runtime/dev-runtime-events";
|
|
43
47
|
import { readEmbeddedHostChildSession } from "../../runtime/embedded-runtime-adapters";
|
|
44
48
|
import { getHostRealtimeClient } from "../../runtime/host-realtime-client";
|
|
@@ -54,6 +58,43 @@ import type {
|
|
|
54
58
|
|
|
55
59
|
const HOST_BOOTSTRAP_TIMEOUT_MESSAGE =
|
|
56
60
|
"Host bootstrap timed out. The deployed Air Jam server may be out of sync with this client.";
|
|
61
|
+
const HOST_ROOM_SESSION_STORAGE_KEY = "airjam_room_id";
|
|
62
|
+
const HOST_RESUME_CAPABILITY_SESSION_STORAGE_KEY =
|
|
63
|
+
"airjam_host_resume_capability";
|
|
64
|
+
const HOST_RESET_CANCELLED_MESSAGE =
|
|
65
|
+
"Host room reset was cancelled because the host session changed.";
|
|
66
|
+
|
|
67
|
+
interface PendingHostResetOperation {
|
|
68
|
+
roomId: RoomCode;
|
|
69
|
+
retryTimeout: ReturnType<typeof setTimeout> | null;
|
|
70
|
+
resolve: (ack: HostRegistrationAck) => void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const clearPersistedHostSession = (): void => {
|
|
74
|
+
if (typeof window === "undefined") {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
sessionStorage.removeItem(HOST_ROOM_SESSION_STORAGE_KEY);
|
|
79
|
+
sessionStorage.removeItem(HOST_RESUME_CAPABILITY_SESSION_STORAGE_KEY);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const persistHostSession = (ack: HostRegistrationAck): void => {
|
|
83
|
+
if (typeof window === "undefined") {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!ack.roomId || !ack.hostResumeCapability) {
|
|
88
|
+
clearPersistedHostSession();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
sessionStorage.setItem(HOST_ROOM_SESSION_STORAGE_KEY, ack.roomId);
|
|
93
|
+
sessionStorage.setItem(
|
|
94
|
+
HOST_RESUME_CAPABILITY_SESSION_STORAGE_KEY,
|
|
95
|
+
ack.hostResumeCapability.token,
|
|
96
|
+
);
|
|
97
|
+
};
|
|
57
98
|
|
|
58
99
|
export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
59
100
|
options: AirJamHostOptions,
|
|
@@ -101,9 +142,9 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
101
142
|
const joinUrlBuildKey = useMemo(
|
|
102
143
|
() =>
|
|
103
144
|
parsedRoomId
|
|
104
|
-
? `${parsedRoomId}\0${config.publicHost
|
|
145
|
+
? `${parsedRoomId}\0${config.topology.publicHost}\0${controllerCapability?.token ?? ""}`
|
|
105
146
|
: null,
|
|
106
|
-
[config.publicHost, controllerCapability?.token, parsedRoomId],
|
|
147
|
+
[config.topology.publicHost, controllerCapability?.token, parsedRoomId],
|
|
107
148
|
);
|
|
108
149
|
const [computedJoinUrl, setComputedJoinUrl] = useState<{
|
|
109
150
|
key: string | null;
|
|
@@ -134,6 +175,30 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
134
175
|
[shouldConnect, getSocket],
|
|
135
176
|
);
|
|
136
177
|
const setRegisteredRoomId = useStore(store, (s) => s.setRegisteredRoomId);
|
|
178
|
+
const pendingHostResetRef = useRef<PendingHostResetOperation | null>(null);
|
|
179
|
+
const cancelPendingHostReset = useCallback((): void => {
|
|
180
|
+
const pendingReset = pendingHostResetRef.current;
|
|
181
|
+
if (!pendingReset) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
pendingHostResetRef.current = null;
|
|
186
|
+
if (pendingReset.retryTimeout) {
|
|
187
|
+
clearTimeout(pendingReset.retryTimeout);
|
|
188
|
+
}
|
|
189
|
+
pendingReset.resolve({
|
|
190
|
+
ok: false,
|
|
191
|
+
code: ErrorCode.CONNECTION_FAILED,
|
|
192
|
+
message: HOST_RESET_CANCELLED_MESSAGE,
|
|
193
|
+
});
|
|
194
|
+
}, []);
|
|
195
|
+
|
|
196
|
+
useEffect(
|
|
197
|
+
() => () => {
|
|
198
|
+
cancelPendingHostReset();
|
|
199
|
+
},
|
|
200
|
+
[cancelPendingHostReset, parsedRoomId, socket],
|
|
201
|
+
);
|
|
137
202
|
|
|
138
203
|
const hydrateHostRoster = useCallback(
|
|
139
204
|
(players?: PlayerProfile[], controllers?: ControllerPresenceNotice[]) => {
|
|
@@ -317,50 +382,144 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
317
382
|
[socket],
|
|
318
383
|
);
|
|
319
384
|
|
|
320
|
-
const resetRoom = useCallback(
|
|
385
|
+
const resetRoom = useCallback((): Promise<HostRegistrationAck> => {
|
|
321
386
|
const activeRoomId = parsedRoomIdRef.current;
|
|
322
|
-
if (!socket || !activeRoomId) {
|
|
323
|
-
return {
|
|
387
|
+
if (!socket || !socket.connected || !activeRoomId) {
|
|
388
|
+
return Promise.resolve({
|
|
324
389
|
ok: false,
|
|
390
|
+
code: ErrorCode.CONNECTION_FAILED,
|
|
325
391
|
message: "Host is not connected to a room.",
|
|
326
|
-
};
|
|
392
|
+
});
|
|
327
393
|
}
|
|
328
394
|
|
|
329
395
|
const payload = hostResetRoomSchema.parse({
|
|
330
396
|
roomId: activeRoomId,
|
|
331
397
|
});
|
|
332
398
|
|
|
333
|
-
|
|
334
|
-
event: AIRJAM_DEV_LOG_EVENTS.runtime.hostResetRoomRequested,
|
|
335
|
-
message: "Host requested local room reset",
|
|
336
|
-
roomId: activeRoomId,
|
|
337
|
-
});
|
|
399
|
+
cancelPendingHostReset();
|
|
338
400
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
401
|
+
return new Promise<HostRegistrationAck>((resolve) => {
|
|
402
|
+
const operation: PendingHostResetOperation = {
|
|
403
|
+
roomId: activeRoomId,
|
|
404
|
+
retryTimeout: null,
|
|
405
|
+
resolve,
|
|
406
|
+
};
|
|
407
|
+
pendingHostResetRef.current = operation;
|
|
343
408
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
409
|
+
const isCurrentOperation = (): boolean =>
|
|
410
|
+
pendingHostResetRef.current === operation &&
|
|
411
|
+
parsedRoomIdRef.current === operation.roomId &&
|
|
412
|
+
socket.connected;
|
|
347
413
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
latestState.resetRuntimeState();
|
|
354
|
-
hydrateHostRoster(ack.players, ack.controllers);
|
|
355
|
-
setRegisteredRoomId(ack.roomId);
|
|
356
|
-
setControllerCapability(ack.controllerCapability ?? null);
|
|
414
|
+
const cancelOperationIfOwned = (): void => {
|
|
415
|
+
if (pendingHostResetRef.current === operation) {
|
|
416
|
+
cancelPendingHostReset();
|
|
417
|
+
}
|
|
418
|
+
};
|
|
357
419
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
420
|
+
const finish = (ack: HostRegistrationAck): void => {
|
|
421
|
+
if (pendingHostResetRef.current !== operation) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
pendingHostResetRef.current = null;
|
|
425
|
+
if (operation.retryTimeout) {
|
|
426
|
+
clearTimeout(operation.retryTimeout);
|
|
427
|
+
operation.retryTimeout = null;
|
|
428
|
+
}
|
|
429
|
+
resolve(ack);
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
const attemptReset = (
|
|
433
|
+
completedRetries = 0,
|
|
434
|
+
retry?: AdmissionRetryDecision,
|
|
435
|
+
): void => {
|
|
436
|
+
if (!isCurrentOperation()) {
|
|
437
|
+
cancelOperationIfOwned();
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
emitHostRuntimeEvent({
|
|
442
|
+
event: AIRJAM_DEV_LOG_EVENTS.runtime.hostResetRoomRequested,
|
|
443
|
+
message:
|
|
444
|
+
completedRetries === 0
|
|
445
|
+
? "Host requested local room reset"
|
|
446
|
+
: "Host retried local room reset after admission denial",
|
|
447
|
+
roomId: activeRoomId,
|
|
448
|
+
data: {
|
|
449
|
+
admissionAttempt: completedRetries + 1,
|
|
450
|
+
...(retry
|
|
451
|
+
? {
|
|
452
|
+
retryReasonCode: retry.code,
|
|
453
|
+
retryAfterSeconds: retry.retryAfterSeconds,
|
|
454
|
+
}
|
|
455
|
+
: {}),
|
|
456
|
+
},
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
void socket
|
|
460
|
+
.emitWithAck<HostRegistrationAck>("host:resetRoom", payload)
|
|
461
|
+
.then(
|
|
462
|
+
(ack) => {
|
|
463
|
+
if (!isCurrentOperation()) {
|
|
464
|
+
cancelOperationIfOwned();
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (!ack.ok) {
|
|
469
|
+
const retryDecision = resolveAdmissionRetry(
|
|
470
|
+
ack,
|
|
471
|
+
completedRetries,
|
|
472
|
+
);
|
|
473
|
+
if (retryDecision) {
|
|
474
|
+
operation.retryTimeout = setTimeout(() => {
|
|
475
|
+
operation.retryTimeout = null;
|
|
476
|
+
attemptReset(completedRetries + 1, retryDecision);
|
|
477
|
+
}, retryDecision.delayMs);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
361
480
|
|
|
362
|
-
|
|
481
|
+
finish(ack);
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (!ack.roomId) {
|
|
486
|
+
finish(ack);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
const latestState = store.getState();
|
|
491
|
+
latestState.setStatus("connected");
|
|
492
|
+
latestState.setRoomId(ack.roomId);
|
|
493
|
+
latestState.setError(undefined);
|
|
494
|
+
latestState.clearHostArcadeRestore();
|
|
495
|
+
latestState.resetRuntimeState();
|
|
496
|
+
hydrateHostRoster(ack.players, ack.controllers);
|
|
497
|
+
setRegisteredRoomId(ack.roomId);
|
|
498
|
+
setControllerCapability(ack.controllerCapability ?? null);
|
|
499
|
+
persistHostSession(ack);
|
|
500
|
+
finish(ack);
|
|
501
|
+
},
|
|
502
|
+
(error: unknown) => {
|
|
503
|
+
if (!isCurrentOperation()) {
|
|
504
|
+
cancelOperationIfOwned();
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
finish({
|
|
508
|
+
ok: false,
|
|
509
|
+
code: ErrorCode.CONNECTION_FAILED,
|
|
510
|
+
message:
|
|
511
|
+
error instanceof Error
|
|
512
|
+
? error.message
|
|
513
|
+
: "Host room reset failed because the realtime connection was interrupted.",
|
|
514
|
+
});
|
|
515
|
+
},
|
|
516
|
+
);
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
attemptReset();
|
|
520
|
+
});
|
|
363
521
|
}, [
|
|
522
|
+
cancelPendingHostReset,
|
|
364
523
|
emitHostRuntimeEvent,
|
|
365
524
|
hydrateHostRoster,
|
|
366
525
|
setRegisteredRoomId,
|
|
@@ -381,7 +540,7 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
381
540
|
void (async () => {
|
|
382
541
|
try {
|
|
383
542
|
const url = await urlBuilder.buildControllerUrl(parsedRoomId, {
|
|
384
|
-
host: config.publicHost,
|
|
543
|
+
host: config.topology.publicHost,
|
|
385
544
|
capabilityToken: controllerCapability?.token,
|
|
386
545
|
});
|
|
387
546
|
if (!cancelled) {
|
|
@@ -408,7 +567,7 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
408
567
|
}, [
|
|
409
568
|
parsedRoomId,
|
|
410
569
|
embeddedHost?.joinUrl,
|
|
411
|
-
config.publicHost,
|
|
570
|
+
config.topology.publicHost,
|
|
412
571
|
controllerCapability?.token,
|
|
413
572
|
joinUrlBuildKey,
|
|
414
573
|
]);
|
|
@@ -465,6 +624,19 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
465
624
|
);
|
|
466
625
|
|
|
467
626
|
useEffect(() => {
|
|
627
|
+
let disposed = false;
|
|
628
|
+
let hostAdmissionEpoch = 0;
|
|
629
|
+
const isStaleHostAdmissionOperation = (operationEpoch: number): boolean =>
|
|
630
|
+
disposed || operationEpoch !== hostAdmissionEpoch;
|
|
631
|
+
let admissionRetryTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
632
|
+
const clearAdmissionRetryTimeout = (): void => {
|
|
633
|
+
if (!admissionRetryTimeout) {
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
clearTimeout(admissionRetryTimeout);
|
|
637
|
+
admissionRetryTimeout = null;
|
|
638
|
+
};
|
|
639
|
+
|
|
468
640
|
const storeState = store.getState();
|
|
469
641
|
const initialRoomId = parsedRoomIdRef.current;
|
|
470
642
|
storeState.setMode(detectRunMode());
|
|
@@ -482,7 +654,7 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
482
654
|
return;
|
|
483
655
|
}
|
|
484
656
|
|
|
485
|
-
const registerHost = async () => {
|
|
657
|
+
const registerHost = async (operationEpoch: number) => {
|
|
486
658
|
if (embeddedHost) {
|
|
487
659
|
const childRoomId = embeddedHost.roomId;
|
|
488
660
|
const latestState = store.getState();
|
|
@@ -533,6 +705,9 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
533
705
|
try {
|
|
534
706
|
bootstrapPayload = await resolveBootstrapPayload();
|
|
535
707
|
} catch (error) {
|
|
708
|
+
if (isStaleHostAdmissionOperation(operationEpoch)) {
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
536
711
|
const latestState = store.getState();
|
|
537
712
|
const message =
|
|
538
713
|
error instanceof Error
|
|
@@ -557,6 +732,10 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
557
732
|
return;
|
|
558
733
|
}
|
|
559
734
|
|
|
735
|
+
if (isStaleHostAdmissionOperation(operationEpoch) || !socket.connected) {
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
|
|
560
739
|
let bootstrapAck: HostBootstrapAck;
|
|
561
740
|
try {
|
|
562
741
|
bootstrapAck = await socket.emitWithAck<HostBootstrapAck>(
|
|
@@ -564,6 +743,9 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
564
743
|
bootstrapPayload,
|
|
565
744
|
);
|
|
566
745
|
} catch (error) {
|
|
746
|
+
if (isStaleHostAdmissionOperation(operationEpoch)) {
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
567
749
|
const latestState = store.getState();
|
|
568
750
|
const message =
|
|
569
751
|
error instanceof Error &&
|
|
@@ -593,6 +775,10 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
593
775
|
return;
|
|
594
776
|
}
|
|
595
777
|
|
|
778
|
+
if (isStaleHostAdmissionOperation(operationEpoch) || !socket.connected) {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
|
|
596
782
|
if (!bootstrapAck.ok) {
|
|
597
783
|
const latestState = store.getState();
|
|
598
784
|
const message = bootstrapAck.message ?? "Failed to authorize host";
|
|
@@ -621,7 +807,16 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
621
807
|
const createNewRoom = (
|
|
622
808
|
reason: "bootstrap" | "reconnect_fallback" = "bootstrap",
|
|
623
809
|
details?: Record<string, unknown>,
|
|
624
|
-
|
|
810
|
+
completedRetries = 0,
|
|
811
|
+
retry?: AdmissionRetryDecision,
|
|
812
|
+
): void => {
|
|
813
|
+
if (
|
|
814
|
+
isStaleHostAdmissionOperation(operationEpoch) ||
|
|
815
|
+
!socket.connected
|
|
816
|
+
) {
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
|
|
625
820
|
const latestState = store.getState();
|
|
626
821
|
latestState.clearHostArcadeRestore();
|
|
627
822
|
latestState.resetPlayers();
|
|
@@ -632,36 +827,66 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
632
827
|
});
|
|
633
828
|
emitHostRuntimeEvent({
|
|
634
829
|
event: AIRJAM_DEV_LOG_EVENTS.runtime.hostCreateRoomRequested,
|
|
635
|
-
message:
|
|
830
|
+
message:
|
|
831
|
+
completedRetries === 0
|
|
832
|
+
? "Host requested room creation"
|
|
833
|
+
: "Host retried room creation after admission denial",
|
|
636
834
|
data: {
|
|
637
835
|
reason,
|
|
638
836
|
maxPlayers: payload.maxPlayers,
|
|
837
|
+
admissionAttempt: completedRetries + 1,
|
|
838
|
+
...(retry
|
|
839
|
+
? {
|
|
840
|
+
retryReasonCode: retry.code,
|
|
841
|
+
retryAfterSeconds: retry.retryAfterSeconds,
|
|
842
|
+
}
|
|
843
|
+
: {}),
|
|
639
844
|
...details,
|
|
640
845
|
},
|
|
641
846
|
});
|
|
642
847
|
|
|
643
848
|
socket.emit("host:createRoom", payload, (ack: HostRegistrationAck) => {
|
|
849
|
+
if (isStaleHostAdmissionOperation(operationEpoch)) {
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
|
|
644
853
|
const latestState = store.getState();
|
|
645
854
|
if (!ack.ok) {
|
|
646
855
|
latestState.setError(ack.message ?? "Failed to create room");
|
|
647
|
-
latestState.setStatus("disconnected");
|
|
648
856
|
setRegisteredRoomId(null);
|
|
649
|
-
setDevHostTraceId(undefined);
|
|
650
857
|
setControllerCapability(null);
|
|
858
|
+
|
|
859
|
+
const retryDecision = resolveAdmissionRetry(ack, completedRetries);
|
|
860
|
+
if (retryDecision) {
|
|
861
|
+
latestState.setStatus("connecting");
|
|
862
|
+
clearAdmissionRetryTimeout();
|
|
863
|
+
admissionRetryTimeout = setTimeout(() => {
|
|
864
|
+
admissionRetryTimeout = null;
|
|
865
|
+
createNewRoom(
|
|
866
|
+
reason,
|
|
867
|
+
details,
|
|
868
|
+
completedRetries + 1,
|
|
869
|
+
retryDecision,
|
|
870
|
+
);
|
|
871
|
+
}, retryDecision.delayMs);
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
latestState.setStatus("disconnected");
|
|
876
|
+
setDevHostTraceId(undefined);
|
|
651
877
|
return;
|
|
652
878
|
}
|
|
653
879
|
|
|
654
880
|
if (ack.roomId) {
|
|
655
881
|
latestState.setStatus("connected");
|
|
656
882
|
latestState.setRoomId(ack.roomId);
|
|
883
|
+
latestState.setError(undefined);
|
|
657
884
|
latestState.clearHostArcadeRestore();
|
|
658
885
|
hydrateHostRoster(ack.players, ack.controllers);
|
|
659
886
|
setRegisteredRoomId(ack.roomId);
|
|
660
887
|
setControllerCapability(ack.controllerCapability ?? null);
|
|
661
888
|
|
|
662
|
-
|
|
663
|
-
sessionStorage.setItem("airjam_room_id", ack.roomId);
|
|
664
|
-
}
|
|
889
|
+
persistHostSession(ack);
|
|
665
890
|
return;
|
|
666
891
|
}
|
|
667
892
|
|
|
@@ -673,19 +898,32 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
673
898
|
};
|
|
674
899
|
|
|
675
900
|
if (typeof window !== "undefined") {
|
|
676
|
-
const savedRoomId = sessionStorage.getItem(
|
|
677
|
-
|
|
901
|
+
const savedRoomId = sessionStorage.getItem(
|
|
902
|
+
HOST_ROOM_SESSION_STORAGE_KEY,
|
|
903
|
+
);
|
|
904
|
+
const savedResumeCapabilityToken = sessionStorage.getItem(
|
|
905
|
+
HOST_RESUME_CAPABILITY_SESSION_STORAGE_KEY,
|
|
906
|
+
);
|
|
907
|
+
if (savedRoomId && savedResumeCapabilityToken) {
|
|
678
908
|
const reconnectPayload = hostReconnectSchema.parse({
|
|
679
909
|
roomId: savedRoomId,
|
|
910
|
+
resumeCapabilityToken: savedResumeCapabilityToken,
|
|
680
911
|
});
|
|
681
912
|
|
|
682
913
|
const maxReconnectAttempts = 12;
|
|
683
914
|
const reconnectRetryDelayMs = 250;
|
|
684
915
|
|
|
685
916
|
const attemptReconnect = (attempt: number) => {
|
|
917
|
+
if (
|
|
918
|
+
isStaleHostAdmissionOperation(operationEpoch) ||
|
|
919
|
+
!socket.connected
|
|
920
|
+
) {
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
686
923
|
store.getState().setHostArcadeRestore({
|
|
687
924
|
phase: "awaiting_ack",
|
|
688
925
|
session: null,
|
|
926
|
+
surfaceCheckpoint: null,
|
|
689
927
|
});
|
|
690
928
|
emitHostRuntimeEvent({
|
|
691
929
|
event: AIRJAM_DEV_LOG_EVENTS.runtime.hostReconnectRequested,
|
|
@@ -700,24 +938,33 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
700
938
|
"host:reconnect",
|
|
701
939
|
reconnectPayload,
|
|
702
940
|
(ack: HostRegistrationAck) => {
|
|
941
|
+
if (isStaleHostAdmissionOperation(operationEpoch)) {
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
703
944
|
const latestState = store.getState();
|
|
704
945
|
if (ack.ok && ack.roomId) {
|
|
705
946
|
latestState.setStatus("connected");
|
|
706
947
|
latestState.setRoomId(ack.roomId);
|
|
707
948
|
hydrateHostRoster(ack.players, ack.controllers);
|
|
708
949
|
setControllerCapability(ack.controllerCapability ?? null);
|
|
950
|
+
const surfaceCheckpoint =
|
|
951
|
+
ack.arcadeSurfaceCheckpoint ??
|
|
952
|
+
(ack.arcadeSession ? { epoch: 1, revision: 0 } : null);
|
|
709
953
|
latestState.setHostArcadeRestore(
|
|
710
|
-
|
|
954
|
+
surfaceCheckpoint
|
|
711
955
|
? {
|
|
712
956
|
phase: "pending_restore",
|
|
713
|
-
session: ack.arcadeSession,
|
|
957
|
+
session: ack.arcadeSession ?? null,
|
|
958
|
+
surfaceCheckpoint,
|
|
714
959
|
}
|
|
715
960
|
: {
|
|
716
961
|
phase: "idle",
|
|
717
962
|
session: null,
|
|
963
|
+
surfaceCheckpoint: null,
|
|
718
964
|
},
|
|
719
965
|
);
|
|
720
966
|
setRegisteredRoomId(ack.roomId);
|
|
967
|
+
persistHostSession(ack);
|
|
721
968
|
return;
|
|
722
969
|
}
|
|
723
970
|
|
|
@@ -745,9 +992,7 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
745
992
|
}
|
|
746
993
|
|
|
747
994
|
latestState.clearHostArcadeRestore();
|
|
748
|
-
|
|
749
|
-
sessionStorage.removeItem("airjam_room_id");
|
|
750
|
-
}
|
|
995
|
+
clearPersistedHostSession();
|
|
751
996
|
setControllerCapability(null);
|
|
752
997
|
createNewRoom("reconnect_fallback", {
|
|
753
998
|
attempt,
|
|
@@ -761,12 +1006,19 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
761
1006
|
attemptReconnect(0);
|
|
762
1007
|
return;
|
|
763
1008
|
}
|
|
1009
|
+
|
|
1010
|
+
if (savedRoomId || savedResumeCapabilityToken) {
|
|
1011
|
+
clearPersistedHostSession();
|
|
1012
|
+
}
|
|
764
1013
|
}
|
|
765
1014
|
|
|
766
1015
|
createNewRoom();
|
|
767
1016
|
};
|
|
768
1017
|
|
|
769
1018
|
const handleConnect = (): void => {
|
|
1019
|
+
clearAdmissionRetryTimeout();
|
|
1020
|
+
hostAdmissionEpoch += 1;
|
|
1021
|
+
const operationEpoch = hostAdmissionEpoch;
|
|
770
1022
|
emitHostRuntimeEvent({
|
|
771
1023
|
event: AIRJAM_DEV_LOG_EVENTS.runtime.socketConnected,
|
|
772
1024
|
message: "Host socket connected",
|
|
@@ -777,10 +1029,12 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
777
1029
|
},
|
|
778
1030
|
});
|
|
779
1031
|
store.getState().setStatus("connecting");
|
|
780
|
-
void registerHost();
|
|
1032
|
+
void registerHost(operationEpoch);
|
|
781
1033
|
};
|
|
782
1034
|
|
|
783
1035
|
const handleDisconnect = (reason: string): void => {
|
|
1036
|
+
hostAdmissionEpoch += 1;
|
|
1037
|
+
clearAdmissionRetryTimeout();
|
|
784
1038
|
emitHostRuntimeEvent({
|
|
785
1039
|
event: AIRJAM_DEV_LOG_EVENTS.runtime.socketDisconnected,
|
|
786
1040
|
message: "Host socket disconnected",
|
|
@@ -970,6 +1224,9 @@ export const useHostRuntimeApi = <TSchema extends z.ZodSchema = z.ZodSchema>(
|
|
|
970
1224
|
}
|
|
971
1225
|
|
|
972
1226
|
return () => {
|
|
1227
|
+
disposed = true;
|
|
1228
|
+
hostAdmissionEpoch += 1;
|
|
1229
|
+
clearAdmissionRetryTimeout();
|
|
973
1230
|
if (reconnectRetryTimeoutRef.current) {
|
|
974
1231
|
clearTimeout(reconnectRetryTimeoutRef.current);
|
|
975
1232
|
reconnectRetryTimeoutRef.current = null;
|
|
@@ -46,21 +46,21 @@ import type { AirJamStore } from "../state/connection-store";
|
|
|
46
46
|
* @example Basic runtime boundary usage (room from URL)
|
|
47
47
|
* ```tsx
|
|
48
48
|
* // URL: https://yourgame.com/controller?room=ABCD
|
|
49
|
-
* <
|
|
49
|
+
* <airjam.Controller>
|
|
50
50
|
* <ControllerView />
|
|
51
|
-
* </
|
|
51
|
+
* </airjam.Controller>
|
|
52
52
|
* ```
|
|
53
53
|
*
|
|
54
54
|
* @example With nickname
|
|
55
55
|
* ```tsx
|
|
56
|
-
* <
|
|
56
|
+
* <airjam.Controller
|
|
57
57
|
* nickname={playerName}
|
|
58
58
|
* onState={(state) => {
|
|
59
59
|
* if (state.runtimeState === "playing") startGame();
|
|
60
60
|
* }}
|
|
61
61
|
* >
|
|
62
62
|
* <ControllerView />
|
|
63
|
-
* </
|
|
63
|
+
* </airjam.Controller>
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
66
|
export interface AirJamControllerOptions {
|
|
@@ -201,8 +201,8 @@ const toControllerState = (state: AirJamStore): AirJamControllerState => {
|
|
|
201
201
|
/**
|
|
202
202
|
* Read the mounted controller runtime API.
|
|
203
203
|
*
|
|
204
|
-
* Use this inside `
|
|
205
|
-
*
|
|
204
|
+
* Use this inside the explicit `airjam.Controller` runtime boundary. Runtime
|
|
205
|
+
* ownership is mounted once at the
|
|
206
206
|
* boundary; child code reads from that runtime through this hook.
|
|
207
207
|
*
|
|
208
208
|
* **Typical usage flow:**
|
|
@@ -234,7 +234,7 @@ const toControllerState = (state: AirJamStore): AirJamControllerState => {
|
|
|
234
234
|
*
|
|
235
235
|
* @example With state callback
|
|
236
236
|
* ```tsx
|
|
237
|
-
* <
|
|
237
|
+
* <airjam.Controller
|
|
238
238
|
* onState={(state) => {
|
|
239
239
|
* if (state.message) {
|
|
240
240
|
* showNotification(state.message);
|
|
@@ -242,7 +242,7 @@ const toControllerState = (state: AirJamStore): AirJamControllerState => {
|
|
|
242
242
|
* }}
|
|
243
243
|
* >
|
|
244
244
|
* <ControllerView />
|
|
245
|
-
* </
|
|
245
|
+
* </airjam.Controller>
|
|
246
246
|
* ```
|
|
247
247
|
*/
|
|
248
248
|
export function useAirJamController(): AirJamControllerApi;
|
|
@@ -268,7 +268,7 @@ export function useAirJamController<TSelected>(
|
|
|
268
268
|
if (!runtime) {
|
|
269
269
|
throw createAirJamDiagnosticError(
|
|
270
270
|
"AJ_SCOPE_MISMATCH",
|
|
271
|
-
"useAirJamController requires a mounted controller runtime boundary. Wrap the controller tree with <
|
|
271
|
+
"useAirJamController requires a mounted controller runtime boundary. Wrap the controller tree with <airjam.Controller> before reading controller state.",
|
|
272
272
|
{
|
|
273
273
|
hookName: "useAirJamController",
|
|
274
274
|
expectedScope: "controller",
|
|
@@ -47,7 +47,7 @@ export type JoinUrlStatus = "loading" | "ready" | "unavailable";
|
|
|
47
47
|
*
|
|
48
48
|
* @example Runtime boundary usage with callbacks
|
|
49
49
|
* ```tsx
|
|
50
|
-
* <
|
|
50
|
+
* <airjam.Host
|
|
51
51
|
* onPlayerJoin={(player) => {
|
|
52
52
|
* console.log(`${player.label} joined!`);
|
|
53
53
|
* spawnPlayerShip(player.id);
|
|
@@ -58,14 +58,14 @@ export type JoinUrlStatus = "loading" | "ready" | "unavailable";
|
|
|
58
58
|
* }}
|
|
59
59
|
* >
|
|
60
60
|
* <HostView />
|
|
61
|
-
* </
|
|
61
|
+
* </airjam.Host>
|
|
62
62
|
* ```
|
|
63
63
|
*
|
|
64
64
|
* @example With custom room ID
|
|
65
65
|
* ```tsx
|
|
66
|
-
* <
|
|
66
|
+
* <airjam.Host roomId="GAME1">
|
|
67
67
|
* <HostView />
|
|
68
|
-
* </
|
|
68
|
+
* </airjam.Host>
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
export interface AirJamHostOptions {
|
|
@@ -217,8 +217,8 @@ const toHostState = (state: AirJamStore): AirJamHostState => ({
|
|
|
217
217
|
/**
|
|
218
218
|
* Read the mounted host runtime API.
|
|
219
219
|
*
|
|
220
|
-
* Use this inside
|
|
221
|
-
*
|
|
220
|
+
* Use this inside the explicit `airjam.Host` runtime boundary. Runtime ownership
|
|
221
|
+
* is mounted once at the boundary; child
|
|
222
222
|
* code reads from that runtime through this hook.
|
|
223
223
|
*
|
|
224
224
|
* This hook is runtime-aware:
|
|
@@ -320,7 +320,7 @@ export function useAirJamHost<
|
|
|
320
320
|
if (!runtime) {
|
|
321
321
|
throw createAirJamDiagnosticError(
|
|
322
322
|
"AJ_SCOPE_MISMATCH",
|
|
323
|
-
"useAirJamHost requires a mounted host runtime boundary. Wrap the host tree with <
|
|
323
|
+
"useAirJamHost requires a mounted host runtime boundary. Wrap the host tree with <airjam.Host> before reading host state.",
|
|
324
324
|
{
|
|
325
325
|
hookName: "useAirJamHost",
|
|
326
326
|
expectedScope: "host",
|
|
@@ -28,7 +28,7 @@ import { useAssertSessionScope } from "../context/session-scope";
|
|
|
28
28
|
* to host session state, so it won't cause re-renders when connection state changes.
|
|
29
29
|
*
|
|
30
30
|
* **Requirements:**
|
|
31
|
-
* - Must be used within `
|
|
31
|
+
* - Must be used within `airjam.Host` or the underlying scoped host runtime
|
|
32
32
|
* - Input configuration must be provided to the provider
|
|
33
33
|
*
|
|
34
34
|
* @template TSchema - Zod schema type for input (from provider)
|