@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
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
controllerJoinSchema,
|
|
27
27
|
controllerLeaveSchema,
|
|
28
28
|
controllerSystemSchema,
|
|
29
|
+
ErrorCode,
|
|
29
30
|
playerProfilePatchSchema,
|
|
30
31
|
roomCodeSchema,
|
|
31
32
|
} from "../../protocol";
|
|
@@ -35,11 +36,16 @@ import type {
|
|
|
35
36
|
ControllerWelcomePayload,
|
|
36
37
|
PlayerUpdatedNotice,
|
|
37
38
|
} from "../../protocol/notices";
|
|
39
|
+
import {
|
|
40
|
+
resolveAdmissionRetry,
|
|
41
|
+
type AdmissionRetryDecision,
|
|
42
|
+
} from "../../runtime/admission-retry";
|
|
38
43
|
import {
|
|
39
44
|
clearControllerRoomBinding,
|
|
40
45
|
getOrCreateControllerDeviceId,
|
|
41
46
|
readControllerRoomBinding,
|
|
42
47
|
writeControllerRoomBinding,
|
|
48
|
+
type ControllerRoomBinding,
|
|
43
49
|
} from "../../runtime/controller-identity";
|
|
44
50
|
import { getControllerRealtimeClient } from "../../runtime/controller-realtime-client";
|
|
45
51
|
import { emitAirJamDevRuntimeEvent } from "../../runtime/dev-runtime-events";
|
|
@@ -169,14 +175,21 @@ export const useControllerRuntimeApi = (
|
|
|
169
175
|
if (urlControllerId) return urlControllerId;
|
|
170
176
|
}
|
|
171
177
|
if (parsedRoomId) {
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
return
|
|
178
|
+
const persistedBinding = readControllerRoomBinding(parsedRoomId);
|
|
179
|
+
if (persistedBinding) {
|
|
180
|
+
return persistedBinding.controllerId;
|
|
175
181
|
}
|
|
176
182
|
}
|
|
177
183
|
return generateControllerId();
|
|
178
184
|
}, [options.controllerId, embeddedController, parsedRoomId]);
|
|
179
185
|
|
|
186
|
+
// Keep recovery authority even when browser storage is unavailable. Never pass
|
|
187
|
+
// it through the embedded game bridge, public player state, or runtime logs.
|
|
188
|
+
const resumeBindingRef = useRef<{
|
|
189
|
+
roomId: string;
|
|
190
|
+
binding: ControllerRoomBinding;
|
|
191
|
+
} | null>(null);
|
|
192
|
+
|
|
180
193
|
const onStateRef = useRef<AirJamControllerOptions["onState"]>(
|
|
181
194
|
options.onState,
|
|
182
195
|
);
|
|
@@ -463,6 +476,17 @@ export const useControllerRuntimeApi = (
|
|
|
463
476
|
return;
|
|
464
477
|
}
|
|
465
478
|
|
|
479
|
+
let disposed = false;
|
|
480
|
+
let joinEpoch = 0;
|
|
481
|
+
let joinRetryTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
482
|
+
const clearJoinRetryTimeout = (): void => {
|
|
483
|
+
if (!joinRetryTimeout) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
clearTimeout(joinRetryTimeout);
|
|
487
|
+
joinRetryTimeout = null;
|
|
488
|
+
};
|
|
489
|
+
|
|
466
490
|
storeState.setControllerId(controllerId);
|
|
467
491
|
if (
|
|
468
492
|
embeddedController?.playerProfile?.label ||
|
|
@@ -483,22 +507,24 @@ export const useControllerRuntimeApi = (
|
|
|
483
507
|
storeState.upsertPlayer(fallbackPlayer);
|
|
484
508
|
}
|
|
485
509
|
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
if (embeddedController) {
|
|
510
|
+
const attemptJoin = (
|
|
511
|
+
completedRetries: number,
|
|
512
|
+
operationEpoch: number,
|
|
513
|
+
retry?: AdmissionRetryDecision,
|
|
514
|
+
): void => {
|
|
515
|
+
if (
|
|
516
|
+
disposed ||
|
|
517
|
+
operationEpoch !== joinEpoch ||
|
|
518
|
+
!socket.connected ||
|
|
519
|
+
embeddedController
|
|
520
|
+
) {
|
|
499
521
|
return;
|
|
500
522
|
}
|
|
501
523
|
|
|
524
|
+
const resumeBinding =
|
|
525
|
+
resumeBindingRef.current?.roomId === parsedRoomId
|
|
526
|
+
? resumeBindingRef.current.binding
|
|
527
|
+
: readControllerRoomBinding(parsedRoomId);
|
|
502
528
|
const payload = controllerJoinSchema.parse({
|
|
503
529
|
roomId: parsedRoomId,
|
|
504
530
|
controllerId,
|
|
@@ -506,10 +532,17 @@ export const useControllerRuntimeApi = (
|
|
|
506
532
|
nickname: nicknameRef.current || undefined,
|
|
507
533
|
avatarId: avatarIdRef.current || undefined,
|
|
508
534
|
capabilityToken: capabilityToken ?? undefined,
|
|
535
|
+
resumeCapabilityToken:
|
|
536
|
+
resumeBinding?.controllerId === controllerId
|
|
537
|
+
? resumeBinding.resumeCapabilityToken
|
|
538
|
+
: undefined,
|
|
509
539
|
});
|
|
510
540
|
emitControllerRuntimeEvent({
|
|
511
541
|
event: AIRJAM_DEV_LOG_EVENTS.runtime.controllerJoinRequested,
|
|
512
|
-
message:
|
|
542
|
+
message:
|
|
543
|
+
completedRetries === 0
|
|
544
|
+
? "Controller requested room join"
|
|
545
|
+
: "Controller retried room join after admission denial",
|
|
513
546
|
roomId: payload.roomId,
|
|
514
547
|
data: {
|
|
515
548
|
joinSource,
|
|
@@ -517,28 +550,82 @@ export const useControllerRuntimeApi = (
|
|
|
517
550
|
hasNickname: Boolean(payload.nickname),
|
|
518
551
|
hasAvatarId: Boolean(payload.avatarId),
|
|
519
552
|
hasCapabilityToken: Boolean(payload.capabilityToken),
|
|
553
|
+
admissionAttempt: completedRetries + 1,
|
|
554
|
+
...(retry
|
|
555
|
+
? {
|
|
556
|
+
retryReasonCode: retry.code,
|
|
557
|
+
retryAfterSeconds: retry.retryAfterSeconds,
|
|
558
|
+
}
|
|
559
|
+
: {}),
|
|
520
560
|
},
|
|
521
561
|
});
|
|
522
562
|
socket.emit("controller:join", payload, (ack: ControllerJoinAck) => {
|
|
563
|
+
if (disposed || operationEpoch !== joinEpoch) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
|
|
523
567
|
const latestState = store.getState();
|
|
524
568
|
if (!ack.ok) {
|
|
525
|
-
if (ack.code ===
|
|
569
|
+
if (ack.code === ErrorCode.ROOM_NOT_FOUND) {
|
|
526
570
|
clearControllerRoomBinding(parsedRoomId);
|
|
527
571
|
}
|
|
528
572
|
latestState.setError(ack.message ?? "Unable to join room");
|
|
529
|
-
latestState.setStatus("disconnected");
|
|
530
573
|
latestState.resetRuntimeState();
|
|
574
|
+
|
|
575
|
+
const retryDecision = resolveAdmissionRetry(ack, completedRetries);
|
|
576
|
+
if (retryDecision) {
|
|
577
|
+
latestState.setStatus("connecting");
|
|
578
|
+
clearJoinRetryTimeout();
|
|
579
|
+
joinRetryTimeout = setTimeout(() => {
|
|
580
|
+
joinRetryTimeout = null;
|
|
581
|
+
attemptJoin(completedRetries + 1, operationEpoch, retryDecision);
|
|
582
|
+
}, retryDecision.delayMs);
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
latestState.setStatus("disconnected");
|
|
531
587
|
return;
|
|
532
588
|
}
|
|
533
589
|
if (ack.controllerId) {
|
|
534
590
|
latestState.setControllerId(ack.controllerId);
|
|
535
|
-
|
|
591
|
+
if (ack.resumeCapabilityToken) {
|
|
592
|
+
const binding = {
|
|
593
|
+
controllerId: ack.controllerId,
|
|
594
|
+
resumeCapabilityToken: ack.resumeCapabilityToken,
|
|
595
|
+
};
|
|
596
|
+
resumeBindingRef.current = { roomId: parsedRoomId, binding };
|
|
597
|
+
writeControllerRoomBinding(parsedRoomId, binding);
|
|
598
|
+
}
|
|
536
599
|
}
|
|
600
|
+
latestState.setError(undefined);
|
|
537
601
|
latestState.setStatus("connected");
|
|
538
602
|
});
|
|
539
603
|
};
|
|
540
604
|
|
|
605
|
+
const handleConnect = (): void => {
|
|
606
|
+
clearJoinRetryTimeout();
|
|
607
|
+
joinEpoch += 1;
|
|
608
|
+
const operationEpoch = joinEpoch;
|
|
609
|
+
emitControllerRuntimeEvent({
|
|
610
|
+
event: AIRJAM_DEV_LOG_EVENTS.runtime.socketConnected,
|
|
611
|
+
message: "Controller socket connected",
|
|
612
|
+
roomId: parsedRoomId ?? undefined,
|
|
613
|
+
data: {
|
|
614
|
+
socketId: socket.id,
|
|
615
|
+
connected: socket.connected,
|
|
616
|
+
},
|
|
617
|
+
});
|
|
618
|
+
store.getState().setStatus("connected");
|
|
619
|
+
|
|
620
|
+
if (embeddedController) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
attemptJoin(0, operationEpoch);
|
|
624
|
+
};
|
|
625
|
+
|
|
541
626
|
const handleDisconnect = (reason?: string): void => {
|
|
627
|
+
joinEpoch += 1;
|
|
628
|
+
clearJoinRetryTimeout();
|
|
542
629
|
emitControllerRuntimeEvent({
|
|
543
630
|
event: AIRJAM_DEV_LOG_EVENTS.runtime.socketDisconnected,
|
|
544
631
|
message: "Controller socket disconnected",
|
|
@@ -582,7 +669,6 @@ export const useControllerRuntimeApi = (
|
|
|
582
669
|
if (!storeRoomId && payload.roomId) {
|
|
583
670
|
latestState.setRoomId(payload.roomId);
|
|
584
671
|
}
|
|
585
|
-
writeControllerRoomBinding(payload.roomId, payload.controllerId);
|
|
586
672
|
if (Array.isArray(payload.players)) {
|
|
587
673
|
latestState.resetPlayers();
|
|
588
674
|
payload.players.forEach((player) => {
|
|
@@ -756,6 +842,9 @@ export const useControllerRuntimeApi = (
|
|
|
756
842
|
}
|
|
757
843
|
|
|
758
844
|
return () => {
|
|
845
|
+
disposed = true;
|
|
846
|
+
joinEpoch += 1;
|
|
847
|
+
clearJoinRetryTimeout();
|
|
759
848
|
socket.off("connect", handleConnect);
|
|
760
849
|
socket.off("disconnect", handleDisconnect);
|
|
761
850
|
socket.off("connect_error", handleConnectError);
|