@air-jam/sdk 0.9.3 → 1.0.0-beta.2
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 +168 -205
- package/dist/actions-D4eh6Xaa.d.cts +72 -0
- package/dist/actions-D4eh6Xaa.d.ts +72 -0
- package/dist/{agent-contract-CD2QnbBJ.d.cts → agent-contract-BMvCMvhE.d.ts} +3 -19
- package/dist/{agent-contract-CD2QnbBJ.d.ts → agent-contract-DtYf3ici.d.cts} +3 -19
- package/dist/agent-tooling.cjs +135 -46
- package/dist/agent-tooling.cjs.map +1 -1
- package/dist/agent-tooling.d.cts +96 -5
- package/dist/agent-tooling.d.ts +96 -5
- package/dist/agent-tooling.js +15 -14
- package/dist/agent-tooling.js.map +1 -1
- package/dist/{use-air-jam-host-COLy8t4s.d.ts → air-jam-context-B1fQvyYY.d.ts} +121 -114
- package/dist/{use-air-jam-host-DM-ybB3C.d.cts → air-jam-context-BKg_ujpd.d.cts} +121 -114
- package/dist/arcade/bridge/controller.cjs +873 -603
- package/dist/arcade/bridge/controller.cjs.map +1 -1
- package/dist/arcade/bridge/controller.d.cts +28 -76
- package/dist/arcade/bridge/controller.d.ts +28 -76
- package/dist/arcade/bridge/controller.js +27 -28
- package/dist/arcade/bridge/controller.js.map +1 -1
- package/dist/arcade/bridge/host.cjs +1017 -252
- package/dist/arcade/bridge/host.cjs.map +1 -1
- package/dist/arcade/bridge/host.d.cts +6 -72
- package/dist/arcade/bridge/host.d.ts +6 -72
- package/dist/arcade/bridge/host.js +19 -22
- package/dist/arcade/bridge/host.js.map +1 -1
- package/dist/arcade/bridge/iframe.cjs +3 -31
- package/dist/arcade/bridge/iframe.cjs.map +1 -1
- package/dist/arcade/bridge/iframe.d.cts +4 -46
- package/dist/arcade/bridge/iframe.d.ts +4 -46
- package/dist/arcade/bridge/iframe.js +6 -18
- package/dist/arcade/bridge/iframe.js.map +1 -1
- package/dist/arcade/host.cjs +0 -502
- package/dist/arcade/host.cjs.map +1 -1
- package/dist/arcade/host.d.cts +1 -19
- package/dist/arcade/host.d.ts +1 -19
- package/dist/arcade/host.js +0 -14
- package/dist/arcade/host.js.map +1 -1
- package/dist/arcade/runtime.cjs +10373 -4688
- package/dist/arcade/runtime.cjs.map +1 -1
- package/dist/arcade/runtime.d.cts +45 -13
- package/dist/arcade/runtime.d.ts +45 -13
- package/dist/arcade/runtime.js +37 -24
- package/dist/arcade/runtime.js.map +1 -1
- package/dist/arcade/surface.cjs +3 -35
- package/dist/arcade/surface.cjs.map +1 -1
- package/dist/arcade/surface.d.cts +14 -2
- package/dist/arcade/surface.d.ts +14 -2
- package/dist/arcade/surface.js +7 -13
- package/dist/arcade/surface.js.map +1 -1
- package/dist/arcade/url.cjs +45 -283
- package/dist/arcade/url.cjs.map +1 -1
- package/dist/arcade/url.d.cts +3 -56
- package/dist/arcade/url.d.ts +3 -56
- package/dist/arcade/url.js +33 -16
- package/dist/arcade/url.js.map +1 -1
- package/dist/chunk-24NZZOIO.js +700 -0
- package/dist/chunk-24NZZOIO.js.map +1 -0
- package/dist/chunk-27QLKLZL.js +469 -0
- package/dist/chunk-27QLKLZL.js.map +1 -0
- package/dist/{chunk-UWJOIVON.js → chunk-2H2FGF3H.js} +3 -6
- package/dist/chunk-2H2FGF3H.js.map +1 -0
- package/dist/chunk-3LDQCQL2.js +307 -0
- package/dist/chunk-3LDQCQL2.js.map +1 -0
- package/dist/chunk-3M7656SU.js +389 -0
- package/dist/chunk-3M7656SU.js.map +1 -0
- package/dist/{chunk-K4OZ54UD.js → chunk-5CRZFIN6.js} +2 -55
- package/dist/chunk-5CRZFIN6.js.map +1 -0
- package/dist/chunk-5L3O3G5K.js +802 -0
- package/dist/chunk-5L3O3G5K.js.map +1 -0
- package/dist/{chunk-O6X7FJ6N.js → chunk-6PLOJMJD.js} +619 -643
- package/dist/chunk-6PLOJMJD.js.map +1 -0
- package/dist/{chunk-EVZJA6RN.js → chunk-6ZJUA63D.js} +183 -2
- package/dist/chunk-6ZJUA63D.js.map +1 -0
- package/dist/chunk-A6EOGRRG.js +49 -0
- package/dist/chunk-A6EOGRRG.js.map +1 -0
- package/dist/chunk-AXG6FA2H.js +366 -0
- package/dist/chunk-AXG6FA2H.js.map +1 -0
- package/dist/chunk-BEM77SVQ.js +57 -0
- package/dist/chunk-BEM77SVQ.js.map +1 -0
- package/dist/chunk-BQHGPXXN.js +1995 -0
- package/dist/chunk-BQHGPXXN.js.map +1 -0
- package/dist/chunk-C5722GTG.js +176 -0
- package/dist/chunk-C5722GTG.js.map +1 -0
- package/dist/{chunk-CV3PBXPT.js → chunk-C5GS2GMK.js} +99 -105
- package/dist/chunk-C5GS2GMK.js.map +1 -0
- package/dist/chunk-CDL7LYZH.js +19 -0
- package/dist/chunk-CDL7LYZH.js.map +1 -0
- package/dist/{chunk-PSUYTD2L.js → chunk-DA3TE4OP.js} +1 -1
- package/dist/chunk-DA3TE4OP.js.map +1 -0
- package/dist/chunk-DBF7NJ3S.js +72 -0
- package/dist/chunk-DBF7NJ3S.js.map +1 -0
- package/dist/chunk-DRBPVG47.js +89 -0
- package/dist/chunk-DRBPVG47.js.map +1 -0
- package/dist/chunk-FCG42U7D.js +131 -0
- package/dist/chunk-FCG42U7D.js.map +1 -0
- package/dist/chunk-FJ4J2BEC.js +26 -0
- package/dist/chunk-FJ4J2BEC.js.map +1 -0
- package/dist/chunk-H4DEVMTO.js +221 -0
- package/dist/chunk-H4DEVMTO.js.map +1 -0
- package/dist/chunk-ISQZ7F3N.js +83 -0
- package/dist/chunk-ISQZ7F3N.js.map +1 -0
- package/dist/{chunk-IG6GZZSS.js → chunk-JCGTL77W.js} +1 -1
- package/dist/chunk-JCGTL77W.js.map +1 -0
- package/dist/chunk-JJVCBUYM.js +98 -0
- package/dist/chunk-JJVCBUYM.js.map +1 -0
- package/dist/chunk-K6BJJJJM.js +138 -0
- package/dist/chunk-K6BJJJJM.js.map +1 -0
- package/dist/{chunk-MIMPMB7O.js → chunk-KGY4PV2A.js} +24 -3
- package/dist/chunk-KGY4PV2A.js.map +1 -0
- package/dist/chunk-KKRLHT2M.js +2477 -0
- package/dist/chunk-KKRLHT2M.js.map +1 -0
- package/dist/chunk-KSYN4I5Y.js +50 -0
- package/dist/chunk-KSYN4I5Y.js.map +1 -0
- package/dist/chunk-KUGROY5S.js +265 -0
- package/dist/chunk-KUGROY5S.js.map +1 -0
- package/dist/chunk-LX6CTPDW.js +16 -0
- package/dist/chunk-LX6CTPDW.js.map +1 -0
- package/dist/{chunk-BE6Z4SIT.js → chunk-M5553I2G.js} +2 -11
- package/dist/chunk-M5553I2G.js.map +1 -0
- package/dist/{chunk-X24K52DG.js → chunk-MD25536W.js} +1 -1
- package/dist/chunk-MD25536W.js.map +1 -0
- package/dist/{chunk-3USU7GY2.js → chunk-MJAWAHLT.js} +1 -1
- package/dist/chunk-MJAWAHLT.js.map +1 -0
- package/dist/chunk-NBA7UIWG.js +921 -0
- package/dist/chunk-NBA7UIWG.js.map +1 -0
- package/dist/chunk-OAXCFPZ7.js +14 -0
- package/dist/chunk-OAXCFPZ7.js.map +1 -0
- package/dist/{chunk-D4VDEVTZ.js → chunk-QHBRHYMV.js} +18 -17
- package/dist/chunk-QHBRHYMV.js.map +1 -0
- package/dist/chunk-QTNYGAZ7.js +45 -0
- package/dist/chunk-QTNYGAZ7.js.map +1 -0
- package/dist/chunk-UC24OG4X.js +129 -0
- package/dist/chunk-UC24OG4X.js.map +1 -0
- package/dist/chunk-VN2PX2I3.js +188 -0
- package/dist/chunk-VN2PX2I3.js.map +1 -0
- package/dist/chunk-WAFGYJZN.js +1513 -0
- package/dist/chunk-WAFGYJZN.js.map +1 -0
- package/dist/chunk-WGHNGQUS.js +78 -0
- package/dist/chunk-WGHNGQUS.js.map +1 -0
- package/dist/{chunk-X35LLCWV.js → chunk-X5HZBQ6K.js} +6 -8
- package/dist/chunk-X5HZBQ6K.js.map +1 -0
- package/dist/chunk-XLY44PXZ.js +46 -0
- package/dist/chunk-XLY44PXZ.js.map +1 -0
- package/dist/chunk-YXHAWWVU.js +7 -0
- package/dist/chunk-YXHAWWVU.js.map +1 -0
- package/dist/connection-store-CqW-E7ma.d.cts +41 -0
- package/dist/connection-store-ffHWMrMe.d.ts +41 -0
- package/dist/control-Bv8dWjyp.d.ts +1400 -0
- package/dist/control-CNzybWMd.d.cts +1400 -0
- package/dist/controller-ClW0R8mZ.d.cts +26 -0
- package/dist/controller-DRKCa7uQ.d.ts +26 -0
- package/dist/controller-agent-vOiuK7T6.d.cts +130 -0
- package/dist/controller-agent-vOiuK7T6.d.ts +130 -0
- package/dist/controller-bridge.cjs +992 -0
- package/dist/controller-bridge.cjs.map +1 -0
- package/dist/controller-bridge.d.cts +52 -0
- package/dist/controller-bridge.d.ts +52 -0
- package/dist/controller-bridge.js +23 -0
- package/dist/controller-bridge.js.map +1 -0
- package/dist/controller-capture-2GKKGHJ2.js +8 -0
- package/dist/controller-capture-2GKKGHJ2.js.map +1 -0
- package/dist/controller-press-EWWIMVXP.js +231 -0
- package/dist/controller-press-EWWIMVXP.js.map +1 -0
- package/dist/core-BAO0pHrJ.d.cts +15 -0
- package/dist/core-BAO0pHrJ.d.ts +15 -0
- package/dist/core.cjs +5956 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +250 -0
- package/dist/core.d.ts +250 -0
- package/dist/core.js +910 -0
- package/dist/core.js.map +1 -0
- package/dist/dev-events-BffobOfb.d.ts +31 -0
- package/dist/dev-events-Ct7QEgKb.d.cts +31 -0
- package/dist/dev-log-events-B1_B3guZ.d.cts +47 -0
- package/dist/dev-log-events-B1_B3guZ.d.ts +47 -0
- package/dist/frames-D-xKuODS.d.cts +686 -0
- package/dist/frames-D-xKuODS.d.ts +686 -0
- package/dist/game-5n-dh5np.d.cts +77 -0
- package/dist/game-RYb97BN8.d.ts +77 -0
- package/dist/host-runtime-BRtUidEJ.d.cts +399 -0
- package/dist/host-runtime-RrO4pCXI.d.ts +399 -0
- package/dist/index.cjs +11571 -7554
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -358
- package/dist/index.d.ts +100 -358
- package/dist/index.js +414 -1903
- package/dist/index.js.map +1 -1
- package/dist/input-D7FNeehb.d.cts +92 -0
- package/dist/input-D7FNeehb.d.ts +92 -0
- package/dist/input-bindings-686sTen7.d.ts +129 -0
- package/dist/input-bindings-BRac-P0e.d.cts +129 -0
- package/dist/leased-control-BEg4JuXA.d.cts +158 -0
- package/dist/leased-control-BEg4JuXA.d.ts +158 -0
- package/dist/metadata.cjs +3 -9
- package/dist/metadata.cjs.map +1 -1
- package/dist/metadata.d.cts +6 -16
- package/dist/metadata.d.ts +6 -16
- package/dist/metadata.js +8 -76
- package/dist/metadata.js.map +1 -1
- package/dist/phone-room-session-Byomkt92.d.cts +439 -0
- package/dist/phone-room-session-D9C8cSxS.d.ts +439 -0
- package/dist/platform-machine.cjs +133 -3
- package/dist/platform-machine.cjs.map +1 -1
- package/dist/platform-machine.d.cts +525 -27
- package/dist/platform-machine.d.ts +525 -27
- package/dist/platform-machine.js +119 -4
- package/dist/platform-machine.js.map +1 -1
- package/dist/{platform-settings-DUWs4JTy.d.cts → platform-settings-Yb0fQ1dl.d.cts} +1 -3
- package/dist/{platform-settings-DUWs4JTy.d.ts → platform-settings-Yb0fQ1dl.d.ts} +1 -3
- package/dist/prefabs.cjs +134 -3
- package/dist/prefabs.cjs.map +1 -1
- package/dist/prefabs.d.cts +23 -47
- package/dist/prefabs.d.ts +23 -47
- package/dist/prefabs.js +23 -4
- package/dist/prefabs.js.map +1 -1
- package/dist/preview.cjs +2199 -767
- package/dist/preview.cjs.map +1 -1
- package/dist/preview.d.cts +193 -38
- package/dist/preview.d.ts +193 -38
- package/dist/preview.js +478 -254
- package/dist/preview.js.map +1 -1
- package/dist/protocol.cjs +585 -391
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +13 -117
- package/dist/protocol.d.ts +13 -117
- package/dist/protocol.js +43 -80
- package/dist/protocol.js.map +1 -1
- package/dist/release.cjs.map +1 -1
- package/dist/release.d.cts +2 -2
- package/dist/release.d.ts +2 -2
- package/dist/release.js +1 -1
- package/dist/release.js.map +1 -1
- package/dist/replay-input-log-D0NpnA3P.d.ts +31 -0
- package/dist/replay-input-log-bg0g-PCz.d.cts +31 -0
- package/dist/room-protocol.cjs +794 -0
- package/dist/room-protocol.cjs.map +1 -0
- package/dist/room-protocol.d.cts +63 -0
- package/dist/room-protocol.d.ts +63 -0
- package/dist/room-protocol.js +143 -0
- package/dist/room-protocol.js.map +1 -0
- package/dist/room-session.cjs +2336 -0
- package/dist/room-session.cjs.map +1 -0
- package/dist/room-session.d.cts +77 -0
- package/dist/room-session.d.ts +77 -0
- package/dist/room-session.js +103 -0
- package/dist/room-session.js.map +1 -0
- package/dist/runtime/prefab-inspection-bridge.cjs +207 -0
- package/dist/runtime/prefab-inspection-bridge.cjs.map +1 -0
- package/dist/runtime/prefab-inspection-bridge.d.cts +156 -0
- package/dist/runtime/prefab-inspection-bridge.d.ts +156 -0
- package/dist/runtime/prefab-inspection-bridge.js +22 -0
- package/dist/runtime/prefab-inspection-bridge.js.map +1 -0
- package/dist/runtime-control.cjs +2133 -8
- package/dist/runtime-control.cjs.map +1 -1
- package/dist/runtime-control.d.cts +980 -12
- package/dist/runtime-control.d.ts +980 -12
- package/dist/runtime-control.js +264 -4
- package/dist/runtime-control.js.map +1 -1
- package/dist/runtime-inspection.cjs +1222 -558
- package/dist/runtime-inspection.cjs.map +1 -1
- package/dist/runtime-inspection.d.cts +530 -22
- package/dist/runtime-inspection.d.ts +530 -22
- package/dist/runtime-inspection.js +21 -22
- package/dist/runtime-inspection.js.map +1 -1
- package/dist/runtime-reporting-K_ZXpubu.d.cts +43 -0
- package/dist/runtime-reporting-K_ZXpubu.d.ts +43 -0
- package/dist/runtime-topology.cjs +2 -5
- package/dist/runtime-topology.cjs.map +1 -1
- package/dist/runtime-topology.d.cts +1 -1
- package/dist/runtime-topology.d.ts +1 -1
- package/dist/runtime-topology.js +1 -1
- package/dist/runtime-topology.js.map +1 -1
- package/dist/scoped-connector-DEOZvCCG.d.cts +66 -0
- package/dist/scoped-connector-nTHACYTl.d.ts +66 -0
- package/dist/sdk-channels-S6j6AH8v.d.cts +103 -0
- package/dist/sdk-channels-S6j6AH8v.d.ts +103 -0
- package/dist/simulation-DL9j-ghn.d.ts +782 -0
- package/dist/simulation-HmgsvF5H.d.cts +782 -0
- package/dist/{standard-match-phase-BzSgBYFg.d.ts → standard-match-phase-D4N-AU0d.d.cts} +3 -13
- package/dist/{standard-match-phase-CvJUW8Oe.d.cts → standard-match-phase-abt8ZjCh.d.ts} +3 -13
- package/dist/transport-CWF29jU6.d.cts +173 -0
- package/dist/transport-CWF29jU6.d.ts +173 -0
- package/dist/types-p28maMEo.d.cts +102 -0
- package/dist/types-p28maMEo.d.ts +102 -0
- package/dist/ui.cjs +2167 -892
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.cts +75 -17
- package/dist/ui.d.ts +75 -17
- package/dist/ui.js +554 -393
- package/dist/ui.js.map +1 -1
- package/package.json +38 -21
- package/src/agent/agent-action.ts +0 -39
- package/src/agent/agent-contract-conformance.ts +8 -1
- package/src/agent/agent-contract.ts +2 -4
- package/src/agent/agent-evaluator.ts +95 -0
- package/src/agent/capture-canvas.ts +79 -0
- package/src/agent/host-canvas-capture.ts +189 -0
- package/src/agent-tooling.ts +5 -20
- package/src/arcade/bridge/controller.ts +8 -11
- package/src/arcade/bridge/host.ts +6 -11
- package/src/arcade/bridge/iframe.ts +1 -50
- package/src/arcade/host.ts +0 -1
- package/src/arcade/surface.ts +5 -1
- package/src/arcade/url.ts +2 -9
- package/src/audio/audio-manager.ts +23 -47
- package/src/audio/hooks.tsx +59 -72
- package/src/components/controller-player-name-field.tsx +2 -2
- package/src/components/controller-primary-action.tsx +1 -1
- package/src/components/controls.tsx +398 -0
- package/src/components/gamepad-layout.tsx +69 -0
- package/src/components/join-url-controls.tsx +5 -1
- package/src/components/lifecycle-action-group.tsx +1 -1
- package/src/components/player-avatar.tsx +50 -3
- package/src/components/room-qr-code.tsx +36 -77
- package/src/components/stage-capture-surface.tsx +91 -0
- package/src/components/surface-viewport.tsx +16 -3
- package/src/components/ui/button.tsx +1 -1
- package/src/constants.ts +0 -15
- package/src/context/air-jam-context.tsx +56 -187
- package/src/context/session-providers.tsx +13 -10
- package/src/controller-bridge.ts +7 -0
- package/src/core/assets.ts +48 -0
- package/src/core/config.ts +70 -0
- package/src/core/connection-store.ts +77 -0
- package/src/core/controller-input.ts +147 -0
- package/src/core/controller-runtime.ts +427 -0
- package/src/core/dev-events.ts +18 -0
- package/src/core/environment.ts +132 -0
- package/src/core/game-description.ts +44 -0
- package/src/core/game.ts +130 -0
- package/src/core/host-input.ts +207 -0
- package/src/core/host-runtime.ts +988 -0
- package/src/core/hosted-rooms.ts +65 -0
- package/src/core/input-bindings.ts +180 -0
- package/src/core/input-log.ts +144 -0
- package/src/core/input.ts +228 -0
- package/src/core/local-input.ts +319 -0
- package/src/core/replay-input-log.ts +298 -0
- package/src/core/replicated-store.ts +1178 -0
- package/src/core/room-action-ack.ts +43 -0
- package/src/core/settings.ts +202 -0
- package/src/core/simulation.ts +307 -0
- package/src/core/theme.ts +33 -0
- package/src/core.ts +167 -0
- package/src/dev/browser-log-sink.ts +35 -12
- package/src/diagnostics.ts +5 -6
- package/src/hooks/internal/use-controller-runtime-api.ts +58 -925
- package/src/hooks/internal/use-host-runtime-api.ts +98 -1270
- package/src/hooks/internal/use-runtime-inspection-contract.ts +14 -2
- package/src/hooks/use-air-jam-controller.ts +32 -53
- package/src/hooks/use-air-jam-host.ts +59 -100
- package/src/hooks/use-air-jam-settings.ts +27 -0
- package/src/hooks/use-controller-toasts.ts +16 -19
- package/src/hooks/use-host-agent-capture.ts +31 -0
- package/src/hooks/use-lifecycle-action-group-model.ts +1 -1
- package/src/hooks/use-send-signal.ts +23 -156
- package/src/hooks/use-simulation.ts +83 -0
- package/src/index.ts +24 -85
- package/src/lifecycle/index.ts +0 -4
- package/src/lifecycle/standard-match-phase.ts +1 -22
- package/src/metadata/manifest.ts +8 -19
- package/src/metadata.ts +1 -1
- package/src/platform-machine.ts +127 -3
- package/src/prefabs/types.ts +91 -20
- package/src/prefabs/view.ts +82 -0
- package/src/prefabs.ts +19 -0
- package/src/preview/host-workspace.tsx +4 -9
- package/src/preview/identity.ts +31 -23
- package/src/preview/layout.ts +5 -1
- package/src/preview/manager.ts +205 -78
- package/src/preview/messages.ts +47 -0
- package/src/preview/ownership.ts +6 -1
- package/src/preview/url.ts +46 -23
- package/src/preview/window.tsx +26 -69
- package/src/preview/workspace-local-seats.ts +166 -0
- package/src/preview/workspace.tsx +89 -37
- package/src/preview.ts +27 -15
- package/src/protocol/actions.ts +58 -0
- package/src/protocol/arcade-platform-actions.ts +2 -16
- package/src/protocol/controller.ts +14 -174
- package/src/protocol/core.ts +8 -15
- package/src/protocol/dev-log-events.ts +5 -81
- package/src/protocol/leased-control.ts +177 -0
- package/src/protocol/room/addressing.ts +35 -0
- package/src/protocol/room/close-codes.ts +33 -0
- package/src/protocol/room/frames.ts +343 -0
- package/src/protocol/room/input-codec.ts +182 -0
- package/src/protocol/room/limits.ts +58 -0
- package/src/protocol/room/patch.ts +135 -0
- package/src/protocol/room/sdk-channels.ts +81 -0
- package/src/protocol/room/seat-id.ts +31 -0
- package/src/protocol/room/transport.ts +63 -0
- package/src/protocol/room/weight.ts +58 -0
- package/src/protocol/runtime-reporting.ts +56 -10
- package/src/protocol.ts +2 -7
- package/src/qrcode.d.ts +3 -13
- package/src/room-protocol.ts +10 -0
- package/src/room-session/browser-wake-events.ts +14 -0
- package/src/room-session/channel-state.ts +293 -0
- package/src/room-session/clock.ts +24 -0
- package/src/room-session/host-room-session.ts +379 -0
- package/src/room-session/input-lane.ts +125 -0
- package/src/room-session/listeners.ts +22 -0
- package/src/room-session/loopback-link.ts +58 -0
- package/src/room-session/phone-room-session.ts +368 -0
- package/src/room-session/port-link.ts +116 -0
- package/src/room-session/room-key.ts +9 -0
- package/src/room-session/roster.ts +23 -0
- package/src/room-session/scoped-connector.ts +577 -0
- package/src/room-session/session-link.ts +306 -0
- package/src/room-session/web-socket-link.ts +57 -0
- package/src/room-session.ts +12 -0
- package/src/runtime/air-jam-config.ts +49 -37
- package/src/runtime/air-jam-error-boundary.tsx +9 -3
- package/src/runtime/arcade-runtime-url.ts +8 -9
- package/src/runtime/browser-controller-environment.ts +116 -0
- package/src/runtime/browser-host-environment.ts +137 -0
- package/src/runtime/browser-replay.ts +211 -0
- package/src/runtime/browser-room.ts +41 -0
- package/src/runtime/connected-runtime-error-boundary.tsx +35 -8
- package/src/runtime/contracts/agent-control.ts +195 -0
- package/src/runtime/contracts/clip.ts +169 -0
- package/src/runtime/contracts/control.ts +653 -16
- package/src/runtime/contracts/controller-agent.ts +130 -0
- package/src/runtime/contracts/input-log.ts +38 -0
- package/src/runtime/contracts/inspection.ts +25 -22
- package/src/runtime/contracts/observation.ts +186 -0
- package/src/runtime/contracts/runtime-identity.ts +43 -0
- package/src/runtime/contracts/timeline.ts +59 -0
- package/src/runtime/controller-agent-bridge.ts +152 -0
- package/src/runtime/controller-bridge-context.ts +29 -0
- package/src/runtime/controller-capture.ts +50 -0
- package/src/runtime/controller-identity.ts +53 -142
- package/src/runtime/controller-presentation.ts +47 -17
- package/src/runtime/controller-press.ts +271 -0
- package/src/runtime/create-air-jam-app.tsx +103 -74
- package/src/runtime/dev-runtime-events.ts +6 -18
- package/src/runtime/embedded-parent.ts +22 -0
- package/src/runtime/embedded-runtime-adapters.ts +10 -9
- package/src/runtime/host-agent-bridge.ts +127 -0
- package/src/runtime/host-capture-boundary.tsx +92 -0
- package/src/runtime/host-capture-context.ts +7 -0
- package/src/runtime/host-clip-reader.ts +93 -0
- package/src/runtime/host-clip-recorder.ts +342 -0
- package/src/runtime/host-input-log-reader.ts +120 -0
- package/src/runtime/host-observation.ts +207 -0
- package/src/runtime/host-pace.ts +36 -0
- package/src/runtime/host-runtime-fault.ts +51 -0
- package/src/runtime/host-timeline.ts +152 -0
- package/src/runtime/local-players.tsx +96 -0
- package/src/runtime/local-seats.ts +612 -0
- package/src/runtime/participant-control.ts +162 -0
- package/src/runtime/prefab-inspection-bridge.ts +174 -0
- package/src/runtime/prefab-inspection-clock.ts +12 -0
- package/src/runtime/prefab-inspection-context.ts +20 -0
- package/src/runtime/prefab-inspection-runtime.tsx +328 -0
- package/src/runtime/preview-inspection-bridge.ts +130 -0
- package/src/runtime/replay-runtime.tsx +101 -0
- package/src/runtime/room-bridge.ts +110 -0
- package/src/runtime/runtime-owner-contexts.tsx +9 -0
- package/src/runtime/runtime-session-params.ts +20 -23
- package/src/runtime/session-runtimes.tsx +231 -64
- package/src/runtime/stage-capture.ts +25 -0
- package/src/runtime-control.ts +41 -0
- package/src/runtime-inspection.ts +14 -7
- package/src/runtime-topology.ts +7 -8
- package/src/settings/platform-settings-runtime.tsx +47 -2
- package/src/settings/platform-settings.ts +0 -65
- package/src/store/use-air-jam-store.ts +73 -0
- package/src/ui.ts +3 -3
- package/src/utils/is-rpc-serializable.ts +11 -19
- package/src/utils/url-builder.ts +0 -7
- package/dist/air-jam-context-BlLPvCup.d.cts +0 -175
- package/dist/air-jam-context-DTsxF-tP.d.ts +0 -175
- package/dist/arcade/bridge.cjs +0 -1087
- package/dist/arcade/bridge.cjs.map +0 -1
- package/dist/arcade/bridge.d.cts +0 -11
- package/dist/arcade/bridge.d.ts +0 -11
- package/dist/arcade/bridge.js +0 -78
- package/dist/arcade/bridge.js.map +0 -1
- package/dist/arcade-runtime-url-BW-MUAOY.d.cts +0 -28
- package/dist/arcade-runtime-url-l8qj01Pg.d.ts +0 -28
- package/dist/arcade.cjs +0 -1767
- package/dist/arcade.cjs.map +0 -1
- package/dist/arcade.d.cts +0 -18
- package/dist/arcade.d.ts +0 -18
- package/dist/arcade.js +0 -129
- package/dist/arcade.js.map +0 -1
- package/dist/chunk-2SZ2YYGJ.js +0 -280
- package/dist/chunk-2SZ2YYGJ.js.map +0 -1
- package/dist/chunk-32RSSFSF.js +0 -214
- package/dist/chunk-32RSSFSF.js.map +0 -1
- package/dist/chunk-3USU7GY2.js.map +0 -1
- package/dist/chunk-3YMUAKPU.js +0 -10
- package/dist/chunk-3YMUAKPU.js.map +0 -1
- package/dist/chunk-56DM2KEW.js +0 -14
- package/dist/chunk-56DM2KEW.js.map +0 -1
- package/dist/chunk-BE6Z4SIT.js.map +0 -1
- package/dist/chunk-CM53YLT5.js +0 -59
- package/dist/chunk-CM53YLT5.js.map +0 -1
- package/dist/chunk-CV3PBXPT.js.map +0 -1
- package/dist/chunk-D4VDEVTZ.js.map +0 -1
- package/dist/chunk-EVZJA6RN.js.map +0 -1
- package/dist/chunk-FUA6EMSJ.js +0 -90
- package/dist/chunk-FUA6EMSJ.js.map +0 -1
- package/dist/chunk-GMLU7RI5.js +0 -70
- package/dist/chunk-GMLU7RI5.js.map +0 -1
- package/dist/chunk-IG6GZZSS.js.map +0 -1
- package/dist/chunk-IKKDONQL.js +0 -1
- package/dist/chunk-IKKDONQL.js.map +0 -1
- package/dist/chunk-ITMQSBTH.js +0 -26
- package/dist/chunk-ITMQSBTH.js.map +0 -1
- package/dist/chunk-J5MCII33.js +0 -620
- package/dist/chunk-J5MCII33.js.map +0 -1
- package/dist/chunk-JTF47B56.js +0 -1
- package/dist/chunk-JTF47B56.js.map +0 -1
- package/dist/chunk-K4OZ54UD.js.map +0 -1
- package/dist/chunk-LIHEEAVE.js +0 -191
- package/dist/chunk-LIHEEAVE.js.map +0 -1
- package/dist/chunk-LIXPF4P6.js +0 -22
- package/dist/chunk-LIXPF4P6.js.map +0 -1
- package/dist/chunk-MIMPMB7O.js.map +0 -1
- package/dist/chunk-MPDMJIX5.js +0 -1
- package/dist/chunk-MPDMJIX5.js.map +0 -1
- package/dist/chunk-O6X7FJ6N.js.map +0 -1
- package/dist/chunk-PSUYTD2L.js.map +0 -1
- package/dist/chunk-QO4KFUEI.js +0 -32
- package/dist/chunk-QO4KFUEI.js.map +0 -1
- package/dist/chunk-QTLYZADF.js +0 -125
- package/dist/chunk-QTLYZADF.js.map +0 -1
- package/dist/chunk-TGRTEWYV.js +0 -195
- package/dist/chunk-TGRTEWYV.js.map +0 -1
- package/dist/chunk-TTQDHKXL.js +0 -3017
- package/dist/chunk-TTQDHKXL.js.map +0 -1
- package/dist/chunk-UCPY7UJC.js +0 -8
- package/dist/chunk-UCPY7UJC.js.map +0 -1
- package/dist/chunk-UPV6YWT5.js +0 -43
- package/dist/chunk-UPV6YWT5.js.map +0 -1
- package/dist/chunk-UWJOIVON.js.map +0 -1
- package/dist/chunk-W2VK36RO.js +0 -11
- package/dist/chunk-W2VK36RO.js.map +0 -1
- package/dist/chunk-X24K52DG.js.map +0 -1
- package/dist/chunk-X35LLCWV.js.map +0 -1
- package/dist/chunk-YXHH3MQT.js +0 -230
- package/dist/chunk-YXHH3MQT.js.map +0 -1
- package/dist/controller-PZEM_1cH.d.ts +0 -176
- package/dist/controller-vj82tKm4.d.cts +0 -176
- package/dist/dev-log-events-BCJKmygo.d.cts +0 -120
- package/dist/dev-log-events-BCJKmygo.d.ts +0 -120
- package/dist/handshake-CC_LrK5g.d.cts +0 -31
- package/dist/handshake-CC_LrK5g.d.ts +0 -31
- package/dist/host-B9pRy0Aa.d.cts +0 -122
- package/dist/host-DylGsX7p.d.ts +0 -122
- package/dist/notices-C4bao3oi.d.ts +0 -38
- package/dist/notices-DNdOjwtj.d.cts +0 -38
- package/dist/realtime-client-Cu8yVJFw.d.cts +0 -15
- package/dist/realtime-client-Cu8yVJFw.d.ts +0 -15
- package/dist/runtime-reporting-pe-eryVz.d.cts +0 -27
- package/dist/runtime-reporting-pe-eryVz.d.ts +0 -27
- package/dist/signals-ZHftIKuc.d.cts +0 -33
- package/dist/signals-ZHftIKuc.d.ts +0 -33
- package/dist/sync-xtPfWhif.d.cts +0 -81
- package/dist/sync-xtPfWhif.d.ts +0 -81
- package/src/arcade/bridge.ts +0 -3
- package/src/arcade.ts +0 -4
- package/src/context/socket-manager.ts +0 -72
- package/src/events.ts +0 -119
- package/src/hooks/use-connection-status.ts +0 -8
- package/src/hooks/use-controller-tick.ts +0 -65
- package/src/hooks/use-get-input.ts +0 -100
- package/src/hooks/use-host-arcade-restore.ts +0 -35
- package/src/hooks/use-host-tick.ts +0 -171
- package/src/hooks/use-input-writer.ts +0 -83
- package/src/hooks/use-players.ts +0 -12
- package/src/internal/input-manager.ts +0 -356
- package/src/protocol/errors.ts +0 -21
- package/src/protocol/host-grant.ts +0 -103
- package/src/protocol/host.ts +0 -150
- package/src/protocol/notices.ts +0 -43
- package/src/protocol/signals.ts +0 -38
- package/src/protocol/socket-events.ts +0 -152
- package/src/protocol/sync.ts +0 -105
- package/src/runtime/admission-retry.ts +0 -62
- package/src/runtime/bridge-envelope-args.ts +0 -21
- package/src/runtime/controller-bridge.ts +0 -439
- package/src/runtime/controller-realtime-client.ts +0 -552
- package/src/runtime/host-bridge.ts +0 -380
- package/src/runtime/host-realtime-client.ts +0 -550
- package/src/runtime/realtime-client.ts +0 -20
- package/src/runtime/validate-arcade-bridge-attach.ts +0 -14
- package/src/state/connection-store.ts +0 -159
- package/src/store/create-air-jam-store.ts +0 -1193
- package/src/store/index.ts +0 -1
- package/src/utils/ids.ts +0 -58
|
@@ -1,1193 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, type MutableRefObject } from "react";
|
|
2
|
-
import { create, type StateCreator } from "zustand";
|
|
3
|
-
import type { StoreApi } from "zustand/vanilla";
|
|
4
|
-
import { useAirJamContext, useAirJamState } from "../context/air-jam-context";
|
|
5
|
-
import { emitAirJamDiagnostic } from "../diagnostics";
|
|
6
|
-
import type {
|
|
7
|
-
AirJamActionActorRole,
|
|
8
|
-
AirJamActionInvocationResult,
|
|
9
|
-
AirJamActionPayload,
|
|
10
|
-
AirJamActionRpcPayload,
|
|
11
|
-
AirJamStateSyncPayload,
|
|
12
|
-
} from "../protocol";
|
|
13
|
-
import { resolveImplicitReplicatedStoreDomainFromWindow } from "../runtime/arcade-runtime-url";
|
|
14
|
-
import { registerHostRuntimeActionStore } from "../runtime/contracts/control";
|
|
15
|
-
import { getControllerRealtimeClient } from "../runtime/controller-realtime-client";
|
|
16
|
-
import { getHostRealtimeClient } from "../runtime/host-realtime-client";
|
|
17
|
-
import type { AirJamRealtimeClient } from "../runtime/realtime-client";
|
|
18
|
-
import { isRpcSerializable } from "../utils/is-rpc-serializable";
|
|
19
|
-
import {
|
|
20
|
-
AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN,
|
|
21
|
-
AIR_JAM_DEFAULT_STORE_DOMAIN,
|
|
22
|
-
} from "./air-jam-store-domain-constants";
|
|
23
|
-
|
|
24
|
-
const INTERNAL_ACTION_PREFIX = "_";
|
|
25
|
-
const UNRESOLVED_ACTOR_ID = "unknown";
|
|
26
|
-
|
|
27
|
-
export interface CreateAirJamStoreOptions {
|
|
28
|
-
storeDomain?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const isEventLikePayload = (payload: unknown): boolean => {
|
|
32
|
-
if (payload === null || typeof payload !== "object") {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const candidate = payload as Record<string, unknown>;
|
|
37
|
-
return (
|
|
38
|
-
typeof candidate.preventDefault === "function" ||
|
|
39
|
-
typeof candidate.stopPropagation === "function" ||
|
|
40
|
-
typeof candidate.persist === "function" ||
|
|
41
|
-
("nativeEvent" in candidate &&
|
|
42
|
-
("target" in candidate || "currentTarget" in candidate))
|
|
43
|
-
);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const isPlainActionPayload = (
|
|
47
|
-
payload: unknown,
|
|
48
|
-
): payload is AirJamActionPayload => {
|
|
49
|
-
if (
|
|
50
|
-
payload === null ||
|
|
51
|
-
typeof payload !== "object" ||
|
|
52
|
-
Array.isArray(payload)
|
|
53
|
-
) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const prototype = Object.getPrototypeOf(payload);
|
|
58
|
-
return prototype === Object.prototype || prototype === null;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export interface AirJamActionContext {
|
|
62
|
-
actorId: string;
|
|
63
|
-
role: AirJamActionActorRole;
|
|
64
|
-
connectedPlayerIds: string[];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface AirJamActionRejection {
|
|
68
|
-
readonly __airJamActionRejection: true;
|
|
69
|
-
reason: string;
|
|
70
|
-
message: string;
|
|
71
|
-
details?: AirJamActionPayload;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface AirJamActionAcceptance<TResult = unknown> {
|
|
75
|
-
readonly __airJamActionAcceptance: true;
|
|
76
|
-
result?: TResult;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
type AirJamActionHandler = (
|
|
80
|
-
ctx: AirJamActionContext,
|
|
81
|
-
// Internal existential handler shape for heterogenous action maps.
|
|
82
|
-
// Store authors still get precise payload types through inference at the public API.
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
|
-
payload: any,
|
|
85
|
-
) => unknown;
|
|
86
|
-
type AirJamActionMap = Record<string, AirJamActionHandler>;
|
|
87
|
-
type AirJamActionName<TActions extends AirJamActionMap> = Extract<
|
|
88
|
-
keyof TActions,
|
|
89
|
-
string
|
|
90
|
-
>;
|
|
91
|
-
|
|
92
|
-
type IsValidActionPayloadType<TPayload> = [TPayload] extends [undefined]
|
|
93
|
-
? true
|
|
94
|
-
: TPayload extends readonly unknown[]
|
|
95
|
-
? false
|
|
96
|
-
: TPayload extends object
|
|
97
|
-
? true
|
|
98
|
-
: false;
|
|
99
|
-
|
|
100
|
-
type InvalidActionPayloadKeys<TActions extends AirJamActionMap> = {
|
|
101
|
-
[K in keyof TActions]: TActions[K] extends (
|
|
102
|
-
ctx: AirJamActionContext,
|
|
103
|
-
payload: infer TPayload,
|
|
104
|
-
) => unknown
|
|
105
|
-
? IsValidActionPayloadType<TPayload> extends true
|
|
106
|
-
? never
|
|
107
|
-
: K
|
|
108
|
-
: K;
|
|
109
|
-
}[keyof TActions];
|
|
110
|
-
|
|
111
|
-
type InvalidActionPayloadKeyNames<TActions extends AirJamActionMap> = Extract<
|
|
112
|
-
InvalidActionPayloadKeys<TActions>,
|
|
113
|
-
string
|
|
114
|
-
>;
|
|
115
|
-
|
|
116
|
-
type AirJamInvalidActionPayloadDiagnostic<TActions extends AirJamActionMap> = {
|
|
117
|
-
readonly __airJamInvalidActionPayloads__: InvalidActionPayloadKeyNames<TActions>;
|
|
118
|
-
readonly __airJamActionPayloadRule__: "Networked store action payloads must be omitted or one plain object payload. Unions like T | undefined, arrays, and primitives are not valid payload roots.";
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
type AirJamNetworkedState<TActions extends AirJamActionMap = AirJamActionMap> =
|
|
122
|
-
{
|
|
123
|
-
actions: TActions;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
type AirJamActionDispatchMap<TActions extends AirJamActionMap> = {
|
|
127
|
-
[K in keyof TActions]: TActions[K] extends (
|
|
128
|
-
ctx: AirJamActionContext,
|
|
129
|
-
payload: infer TPayload,
|
|
130
|
-
) => infer TResult
|
|
131
|
-
? [TPayload] extends [undefined]
|
|
132
|
-
? () => Promise<
|
|
133
|
-
AirJamActionInvocationResult<InferAirJamActionResult<TResult>>
|
|
134
|
-
>
|
|
135
|
-
: TPayload extends readonly unknown[]
|
|
136
|
-
? never
|
|
137
|
-
: TPayload extends object
|
|
138
|
-
? (
|
|
139
|
-
payload: TPayload,
|
|
140
|
-
) => Promise<
|
|
141
|
-
AirJamActionInvocationResult<InferAirJamActionResult<TResult>>
|
|
142
|
-
>
|
|
143
|
-
: never
|
|
144
|
-
: never;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
type InferAirJamActionResult<TResult> =
|
|
148
|
-
TResult extends AirJamActionAcceptance<infer TAccepted>
|
|
149
|
-
? TAccepted
|
|
150
|
-
: TResult extends AirJamActionRejection
|
|
151
|
-
? never
|
|
152
|
-
: TResult;
|
|
153
|
-
|
|
154
|
-
interface StoreRuntimeSnapshot {
|
|
155
|
-
socket: AirJamRealtimeClient | null;
|
|
156
|
-
role: AirJamActionActorRole | null;
|
|
157
|
-
roomId: string | null;
|
|
158
|
-
resolvedStoreDomain: string;
|
|
159
|
-
connectionStatus: string | null;
|
|
160
|
-
canBroadcastHostState: boolean;
|
|
161
|
-
hostStateSyncBlocked: boolean;
|
|
162
|
-
hostStateRevisionFloor: number;
|
|
163
|
-
connectedPlayerIds: string[];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
interface StoreRuntimeBinding {
|
|
167
|
-
refCount: number;
|
|
168
|
-
flushHostStateSync?: () => void;
|
|
169
|
-
lastHostFlushKey?: string;
|
|
170
|
-
cleanup: () => void;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export type AirJamHostActionEvent<
|
|
174
|
-
TActions extends AirJamActionMap = AirJamActionMap,
|
|
175
|
-
TActionName extends AirJamActionName<TActions> = AirJamActionName<TActions>,
|
|
176
|
-
> =
|
|
177
|
-
TActionName extends AirJamActionName<TActions>
|
|
178
|
-
? TActions[TActionName] extends (
|
|
179
|
-
ctx: AirJamActionContext,
|
|
180
|
-
payload: infer TPayload,
|
|
181
|
-
) => infer TResult
|
|
182
|
-
? {
|
|
183
|
-
actionName: TActionName;
|
|
184
|
-
payload: TPayload;
|
|
185
|
-
context: AirJamActionContext;
|
|
186
|
-
acknowledgement: AirJamActionInvocationResult<
|
|
187
|
-
InferAirJamActionResult<TResult>
|
|
188
|
-
>;
|
|
189
|
-
invocationKind: "local" | "rpc";
|
|
190
|
-
roomId: string | null;
|
|
191
|
-
storeDomain: string;
|
|
192
|
-
}
|
|
193
|
-
: never
|
|
194
|
-
: never;
|
|
195
|
-
|
|
196
|
-
export interface AirJamHostActionSubscriptionOptions<
|
|
197
|
-
TActions extends AirJamActionMap = AirJamActionMap,
|
|
198
|
-
> {
|
|
199
|
-
actionNames?: readonly AirJamActionName<TActions>[];
|
|
200
|
-
includeRejected?: boolean;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export type AirJamHostActionListener<
|
|
204
|
-
TActions extends AirJamActionMap = AirJamActionMap,
|
|
205
|
-
> = (event: AirJamHostActionEvent<TActions>) => void;
|
|
206
|
-
|
|
207
|
-
interface HostActionListenerRegistration<TActions extends AirJamActionMap> {
|
|
208
|
-
actionNames: ReadonlySet<string> | null;
|
|
209
|
-
includeRejected: boolean;
|
|
210
|
-
listener: AirJamHostActionListener<TActions>;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export type AirJamSyncedStoreHook<T extends AirJamNetworkedState> = {
|
|
214
|
-
<U>(selector?: (state: T) => U): U;
|
|
215
|
-
useActions: () => AirJamActionDispatchMap<T["actions"]>;
|
|
216
|
-
asPlayer: (controllerId: string) => AirJamActionDispatchMap<T["actions"]>;
|
|
217
|
-
getState: () => T;
|
|
218
|
-
subscribe: StoreApi<T>["subscribe"];
|
|
219
|
-
subscribeHostActions: (
|
|
220
|
-
listener: AirJamHostActionListener<T["actions"]>,
|
|
221
|
-
options?: AirJamHostActionSubscriptionOptions<T["actions"]>,
|
|
222
|
-
) => () => void;
|
|
223
|
-
useHostActionListener: (
|
|
224
|
-
listener: AirJamHostActionListener<T["actions"]>,
|
|
225
|
-
options?: AirJamHostActionSubscriptionOptions<T["actions"]>,
|
|
226
|
-
) => void;
|
|
227
|
-
useLiveStateRef: () => MutableRefObject<T>;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
export const isInternalActionName = (actionName: string): boolean =>
|
|
231
|
-
actionName.startsWith(INTERNAL_ACTION_PREFIX);
|
|
232
|
-
|
|
233
|
-
export const acceptAirJamAction = <TResult = unknown>(
|
|
234
|
-
result?: TResult,
|
|
235
|
-
): AirJamActionAcceptance<TResult> => ({
|
|
236
|
-
__airJamActionAcceptance: true,
|
|
237
|
-
...(result !== undefined ? { result } : {}),
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
export const rejectAirJamAction = (
|
|
241
|
-
reason: string,
|
|
242
|
-
message: string,
|
|
243
|
-
details?: AirJamActionPayload,
|
|
244
|
-
): AirJamActionRejection => ({
|
|
245
|
-
__airJamActionRejection: true,
|
|
246
|
-
reason,
|
|
247
|
-
message,
|
|
248
|
-
...(details ? { details } : {}),
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
const isAirJamActionAcceptance = (
|
|
252
|
-
value: unknown,
|
|
253
|
-
): value is AirJamActionAcceptance<unknown> =>
|
|
254
|
-
typeof value === "object" &&
|
|
255
|
-
value !== null &&
|
|
256
|
-
(value as { __airJamActionAcceptance?: boolean }).__airJamActionAcceptance ===
|
|
257
|
-
true;
|
|
258
|
-
|
|
259
|
-
const isAirJamActionRejection = (
|
|
260
|
-
value: unknown,
|
|
261
|
-
): value is AirJamActionRejection =>
|
|
262
|
-
typeof value === "object" &&
|
|
263
|
-
value !== null &&
|
|
264
|
-
(value as { __airJamActionRejection?: boolean }).__airJamActionRejection ===
|
|
265
|
-
true;
|
|
266
|
-
|
|
267
|
-
const createClientRejectedActionResult = (
|
|
268
|
-
reason: string,
|
|
269
|
-
message: string,
|
|
270
|
-
details?: AirJamActionPayload,
|
|
271
|
-
): AirJamActionInvocationResult => ({
|
|
272
|
-
ok: false,
|
|
273
|
-
status: "rejected",
|
|
274
|
-
source: "client",
|
|
275
|
-
reason,
|
|
276
|
-
message,
|
|
277
|
-
...(details ? { details } : {}),
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
const createServerRejectedActionResult = (
|
|
281
|
-
reason: string,
|
|
282
|
-
message: string,
|
|
283
|
-
details?: AirJamActionPayload,
|
|
284
|
-
): AirJamActionInvocationResult => ({
|
|
285
|
-
ok: false,
|
|
286
|
-
status: "rejected",
|
|
287
|
-
source: "server",
|
|
288
|
-
reason,
|
|
289
|
-
message,
|
|
290
|
-
...(details ? { details } : {}),
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
const normalizeAirJamActionInvocationResult = (
|
|
294
|
-
value: unknown,
|
|
295
|
-
source: "client" | "host",
|
|
296
|
-
): AirJamActionInvocationResult => {
|
|
297
|
-
if (isAirJamActionRejection(value)) {
|
|
298
|
-
return {
|
|
299
|
-
ok: false,
|
|
300
|
-
status: "rejected",
|
|
301
|
-
source,
|
|
302
|
-
reason: value.reason,
|
|
303
|
-
message: value.message,
|
|
304
|
-
...(value.details ? { details: value.details } : {}),
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (isAirJamActionAcceptance(value)) {
|
|
309
|
-
return {
|
|
310
|
-
ok: true,
|
|
311
|
-
status: "accepted",
|
|
312
|
-
source,
|
|
313
|
-
...(value.result !== undefined ? { result: value.result } : {}),
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return {
|
|
318
|
-
ok: true,
|
|
319
|
-
status: "accepted",
|
|
320
|
-
source,
|
|
321
|
-
...(value !== undefined ? { result: value } : {}),
|
|
322
|
-
};
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
const stripActionsFromState = <T extends AirJamNetworkedState>(
|
|
326
|
-
data: Partial<T>,
|
|
327
|
-
): Partial<T> => {
|
|
328
|
-
const { actions: _ignored, ...stateData } = data as Partial<T> & {
|
|
329
|
-
actions?: unknown;
|
|
330
|
-
};
|
|
331
|
-
return stateData as Partial<T>;
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
const toActionContext = (
|
|
335
|
-
payload: AirJamActionRpcPayload,
|
|
336
|
-
connectedPlayerIds: string[],
|
|
337
|
-
): AirJamActionContext => ({
|
|
338
|
-
actorId: payload.actor.id || UNRESOLVED_ACTOR_ID,
|
|
339
|
-
role: payload.actor.role,
|
|
340
|
-
connectedPlayerIds,
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Creates a networked Zustand store that syncs state from host to controllers.
|
|
345
|
-
*
|
|
346
|
-
* Host is the source of truth:
|
|
347
|
-
* - Host broadcasts state updates to all controllers.
|
|
348
|
-
* - Controllers invoke actions through RPC to host.
|
|
349
|
-
*
|
|
350
|
-
* `storeDomain` isolates sync and action RPC so multiple replicated stores can coexist in one room
|
|
351
|
-
* (e.g. arcade shell vs running game). When omitted, resolves from the runtime URL: explicit
|
|
352
|
-
* `aj_store_domain`, else embedded Arcade identity (`aj_arcade_*`), else the default domain.
|
|
353
|
-
*/
|
|
354
|
-
export function createAirJamStore<T extends AirJamNetworkedState>(
|
|
355
|
-
initializer: InvalidActionPayloadKeys<T["actions"]> extends never
|
|
356
|
-
? StateCreator<T>
|
|
357
|
-
: StateCreator<T> & AirJamInvalidActionPayloadDiagnostic<T["actions"]>,
|
|
358
|
-
options?: CreateAirJamStoreOptions,
|
|
359
|
-
): AirJamSyncedStoreHook<T> {
|
|
360
|
-
const store = create<T>((set, get, api) => initializer(set, get, api));
|
|
361
|
-
const runtimeSnapshotRef: { current: StoreRuntimeSnapshot } = {
|
|
362
|
-
current: {
|
|
363
|
-
socket: null,
|
|
364
|
-
role: null,
|
|
365
|
-
roomId: null,
|
|
366
|
-
resolvedStoreDomain: AIR_JAM_DEFAULT_STORE_DOMAIN,
|
|
367
|
-
connectionStatus: null,
|
|
368
|
-
canBroadcastHostState: false,
|
|
369
|
-
hostStateSyncBlocked: false,
|
|
370
|
-
hostStateRevisionFloor: 0,
|
|
371
|
-
connectedPlayerIds: [],
|
|
372
|
-
},
|
|
373
|
-
};
|
|
374
|
-
const runtimeBindings = new Map<string, StoreRuntimeBinding>();
|
|
375
|
-
const hostActionListeners = new Set<
|
|
376
|
-
HostActionListenerRegistration<T["actions"]>
|
|
377
|
-
>();
|
|
378
|
-
|
|
379
|
-
const createDispatchedActions = (
|
|
380
|
-
mode:
|
|
381
|
-
| {
|
|
382
|
-
kind: "default";
|
|
383
|
-
}
|
|
384
|
-
| {
|
|
385
|
-
kind: "player";
|
|
386
|
-
controllerId: string;
|
|
387
|
-
},
|
|
388
|
-
): AirJamActionDispatchMap<T["actions"]> => {
|
|
389
|
-
const sourceActions = store.getState().actions;
|
|
390
|
-
const actionDispatch = {} as AirJamActionDispatchMap<T["actions"]>;
|
|
391
|
-
|
|
392
|
-
for (const actionName of Object.keys(sourceActions)) {
|
|
393
|
-
if (isInternalActionName(actionName)) {
|
|
394
|
-
continue;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const sourceAction = sourceActions[actionName];
|
|
398
|
-
|
|
399
|
-
(
|
|
400
|
-
actionDispatch as unknown as Record<
|
|
401
|
-
string,
|
|
402
|
-
(payload: unknown) => Promise<AirJamActionInvocationResult>
|
|
403
|
-
>
|
|
404
|
-
)[actionName] = async (
|
|
405
|
-
payload: unknown,
|
|
406
|
-
): Promise<AirJamActionInvocationResult> => {
|
|
407
|
-
const normalizedPayload = isEventLikePayload(payload)
|
|
408
|
-
? undefined
|
|
409
|
-
: payload;
|
|
410
|
-
|
|
411
|
-
if (normalizedPayload !== payload) {
|
|
412
|
-
emitAirJamDiagnostic({
|
|
413
|
-
code: "AJ_STORE_ACTION_EVENT_PAYLOAD_DROPPED",
|
|
414
|
-
severity: "warn",
|
|
415
|
-
message: `[AirJamStore] Action "${actionName}" received an event-like payload. Dropping payload and continuing.`,
|
|
416
|
-
details: { actionName },
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
const runtime = runtimeSnapshotRef.current;
|
|
421
|
-
|
|
422
|
-
if (mode.kind === "player" && runtime.role !== "host") {
|
|
423
|
-
emitAirJamDiagnostic({
|
|
424
|
-
code: "AJ_STORE_PLAYER_ACTIONS_HOST_ONLY",
|
|
425
|
-
severity: "warn",
|
|
426
|
-
message: `[AirJamStore] Player impersonation for action "${actionName}" is host-only.`,
|
|
427
|
-
details: {
|
|
428
|
-
actionName,
|
|
429
|
-
role: runtime.role,
|
|
430
|
-
controllerId: mode.controllerId,
|
|
431
|
-
},
|
|
432
|
-
});
|
|
433
|
-
return createClientRejectedActionResult(
|
|
434
|
-
"player_actions_host_only",
|
|
435
|
-
`Store action "${actionName}" cannot impersonate a player outside the host runtime.`,
|
|
436
|
-
{
|
|
437
|
-
actionName,
|
|
438
|
-
...(runtime.role ? { role: runtime.role } : {}),
|
|
439
|
-
controllerId: mode.controllerId,
|
|
440
|
-
},
|
|
441
|
-
);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
if (mode.kind === "player") {
|
|
445
|
-
const normalizedControllerId = mode.controllerId.trim();
|
|
446
|
-
if (normalizedControllerId.length === 0) {
|
|
447
|
-
emitAirJamDiagnostic({
|
|
448
|
-
code: "AJ_STORE_PLAYER_ACTIONS_INVALID_ACTOR_ID",
|
|
449
|
-
severity: "warn",
|
|
450
|
-
message: `[AirJamStore] Player impersonation for action "${actionName}" requires a non-empty controller id.`,
|
|
451
|
-
details: {
|
|
452
|
-
actionName,
|
|
453
|
-
},
|
|
454
|
-
});
|
|
455
|
-
return createClientRejectedActionResult(
|
|
456
|
-
"player_actor_id_invalid",
|
|
457
|
-
`Store action "${actionName}" requires a non-empty controller id for player impersonation.`,
|
|
458
|
-
{
|
|
459
|
-
actionName,
|
|
460
|
-
},
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
if (!runtime.connectedPlayerIds.includes(normalizedControllerId)) {
|
|
465
|
-
emitAirJamDiagnostic({
|
|
466
|
-
code: "AJ_STORE_PLAYER_ACTIONS_PLAYER_NOT_CONNECTED",
|
|
467
|
-
severity: "warn",
|
|
468
|
-
message: `[AirJamStore] Player impersonation for action "${actionName}" requires a currently connected controller.`,
|
|
469
|
-
details: {
|
|
470
|
-
actionName,
|
|
471
|
-
controllerId: normalizedControllerId,
|
|
472
|
-
connectedPlayerIds: runtime.connectedPlayerIds,
|
|
473
|
-
},
|
|
474
|
-
});
|
|
475
|
-
return createClientRejectedActionResult(
|
|
476
|
-
"player_not_connected",
|
|
477
|
-
`Store action "${actionName}" cannot impersonate controller "${normalizedControllerId}" because it is not currently connected.`,
|
|
478
|
-
{
|
|
479
|
-
actionName,
|
|
480
|
-
controllerId: normalizedControllerId,
|
|
481
|
-
},
|
|
482
|
-
);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
if (runtime.role === "host") {
|
|
487
|
-
try {
|
|
488
|
-
const context =
|
|
489
|
-
mode.kind === "player"
|
|
490
|
-
? ({
|
|
491
|
-
actorId: mode.controllerId.trim(),
|
|
492
|
-
role: "controller",
|
|
493
|
-
connectedPlayerIds: runtime.connectedPlayerIds,
|
|
494
|
-
} satisfies AirJamActionContext)
|
|
495
|
-
: ({
|
|
496
|
-
actorId: "host",
|
|
497
|
-
role: "host",
|
|
498
|
-
connectedPlayerIds: runtime.connectedPlayerIds,
|
|
499
|
-
} satisfies AirJamActionContext);
|
|
500
|
-
const result = sourceAction(context, normalizedPayload);
|
|
501
|
-
const acknowledgement = normalizeAirJamActionInvocationResult(
|
|
502
|
-
result,
|
|
503
|
-
"host",
|
|
504
|
-
);
|
|
505
|
-
const typedActionName = actionName as AirJamActionName<
|
|
506
|
-
T["actions"]
|
|
507
|
-
>;
|
|
508
|
-
notifyHostActionListeners({
|
|
509
|
-
actionName: typedActionName,
|
|
510
|
-
payload: normalizedPayload,
|
|
511
|
-
context,
|
|
512
|
-
acknowledgement,
|
|
513
|
-
invocationKind: "local",
|
|
514
|
-
roomId: runtime.roomId,
|
|
515
|
-
storeDomain: runtime.resolvedStoreDomain,
|
|
516
|
-
} as AirJamHostActionEvent<T["actions"], typeof typedActionName>);
|
|
517
|
-
return acknowledgement;
|
|
518
|
-
} catch (error) {
|
|
519
|
-
const acknowledgement = {
|
|
520
|
-
ok: false,
|
|
521
|
-
status: "rejected",
|
|
522
|
-
source: "host",
|
|
523
|
-
reason: "handler_error",
|
|
524
|
-
message: error instanceof Error ? error.message : String(error),
|
|
525
|
-
} satisfies AirJamActionInvocationResult;
|
|
526
|
-
const typedActionName = actionName as AirJamActionName<
|
|
527
|
-
T["actions"]
|
|
528
|
-
>;
|
|
529
|
-
notifyHostActionListeners({
|
|
530
|
-
actionName: typedActionName,
|
|
531
|
-
payload: normalizedPayload,
|
|
532
|
-
context: {
|
|
533
|
-
actorId:
|
|
534
|
-
mode.kind === "player" ? mode.controllerId.trim() : "host",
|
|
535
|
-
role: mode.kind === "player" ? "controller" : "host",
|
|
536
|
-
connectedPlayerIds: runtime.connectedPlayerIds,
|
|
537
|
-
},
|
|
538
|
-
acknowledgement,
|
|
539
|
-
invocationKind: "local",
|
|
540
|
-
roomId: runtime.roomId,
|
|
541
|
-
storeDomain: runtime.resolvedStoreDomain,
|
|
542
|
-
} as AirJamHostActionEvent<T["actions"], typeof typedActionName>);
|
|
543
|
-
return acknowledgement;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
if (runtime.role !== "controller" || !runtime.roomId) {
|
|
548
|
-
emitAirJamDiagnostic({
|
|
549
|
-
code: "AJ_STORE_ACTION_SESSION_NOT_READY",
|
|
550
|
-
severity: "warn",
|
|
551
|
-
message: `[AirJamStore] Action "${actionName}" blocked: session role not ready.`,
|
|
552
|
-
details: {
|
|
553
|
-
actionName,
|
|
554
|
-
role: runtime.role,
|
|
555
|
-
roomId: runtime.roomId,
|
|
556
|
-
},
|
|
557
|
-
});
|
|
558
|
-
return createClientRejectedActionResult(
|
|
559
|
-
"session_not_ready",
|
|
560
|
-
`Store action "${actionName}" cannot run because the controller session is not ready.`,
|
|
561
|
-
{
|
|
562
|
-
actionName,
|
|
563
|
-
...(runtime.role ? { role: runtime.role } : {}),
|
|
564
|
-
...(runtime.roomId ? { roomId: runtime.roomId } : {}),
|
|
565
|
-
},
|
|
566
|
-
);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
const activeSocket = runtime.socket;
|
|
570
|
-
if (!activeSocket || !activeSocket.connected) {
|
|
571
|
-
emitAirJamDiagnostic({
|
|
572
|
-
code: "AJ_STORE_ACTION_SOCKET_DISCONNECTED",
|
|
573
|
-
severity: "warn",
|
|
574
|
-
message: `[AirJamStore] Action "${actionName}" blocked: Socket disconnected.`,
|
|
575
|
-
details: { actionName },
|
|
576
|
-
});
|
|
577
|
-
return createClientRejectedActionResult(
|
|
578
|
-
"socket_disconnected",
|
|
579
|
-
`Store action "${actionName}" cannot run because the controller socket is disconnected.`,
|
|
580
|
-
{
|
|
581
|
-
actionName,
|
|
582
|
-
},
|
|
583
|
-
);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
if (!isRpcSerializable(normalizedPayload)) {
|
|
587
|
-
emitAirJamDiagnostic({
|
|
588
|
-
code: "AJ_STORE_ACTION_PAYLOAD_NOT_SERIALIZABLE",
|
|
589
|
-
severity: "warn",
|
|
590
|
-
message: `[AirJamStore] Action "${actionName}" blocked: payload must be RPC-serializable.`,
|
|
591
|
-
details: { actionName },
|
|
592
|
-
});
|
|
593
|
-
return createClientRejectedActionResult(
|
|
594
|
-
"payload_not_serializable",
|
|
595
|
-
`Store action "${actionName}" requires an RPC-serializable payload.`,
|
|
596
|
-
{
|
|
597
|
-
actionName,
|
|
598
|
-
},
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
if (
|
|
603
|
-
normalizedPayload !== undefined &&
|
|
604
|
-
!isPlainActionPayload(normalizedPayload)
|
|
605
|
-
) {
|
|
606
|
-
emitAirJamDiagnostic({
|
|
607
|
-
code: "AJ_STORE_ACTION_PAYLOAD_INVALID_SHAPE",
|
|
608
|
-
severity: "warn",
|
|
609
|
-
message: `[AirJamStore] Action "${actionName}" blocked: payload must be omitted or a plain object.`,
|
|
610
|
-
details: { actionName },
|
|
611
|
-
});
|
|
612
|
-
return createClientRejectedActionResult(
|
|
613
|
-
"payload_invalid_shape",
|
|
614
|
-
`Store action "${actionName}" requires an omitted payload or a plain object payload.`,
|
|
615
|
-
{
|
|
616
|
-
actionName,
|
|
617
|
-
},
|
|
618
|
-
);
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
return await activeSocket.emitWithAck<AirJamActionInvocationResult>(
|
|
622
|
-
"controller:action_rpc",
|
|
623
|
-
{
|
|
624
|
-
roomId: runtime.roomId,
|
|
625
|
-
actionName,
|
|
626
|
-
payload: normalizedPayload,
|
|
627
|
-
storeDomain: runtime.resolvedStoreDomain,
|
|
628
|
-
},
|
|
629
|
-
);
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
return actionDispatch;
|
|
634
|
-
};
|
|
635
|
-
|
|
636
|
-
const notifyHostActionListeners = <
|
|
637
|
-
TActionName extends AirJamActionName<T["actions"]>,
|
|
638
|
-
>(
|
|
639
|
-
event: AirJamHostActionEvent<T["actions"], TActionName>,
|
|
640
|
-
): void => {
|
|
641
|
-
for (const registration of hostActionListeners) {
|
|
642
|
-
if (
|
|
643
|
-
registration.actionNames &&
|
|
644
|
-
!registration.actionNames.has(event.actionName)
|
|
645
|
-
) {
|
|
646
|
-
continue;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
if (
|
|
650
|
-
!registration.includeRejected &&
|
|
651
|
-
event.acknowledgement.status === "rejected"
|
|
652
|
-
) {
|
|
653
|
-
continue;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
try {
|
|
657
|
-
registration.listener(event);
|
|
658
|
-
} catch (error) {
|
|
659
|
-
console.error(
|
|
660
|
-
`[AirJamStore] Host action listener for "${event.actionName}" threw.`,
|
|
661
|
-
error,
|
|
662
|
-
);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
const createRuntimeBinding = ({
|
|
668
|
-
socket,
|
|
669
|
-
role,
|
|
670
|
-
roomId,
|
|
671
|
-
resolvedStoreDomain,
|
|
672
|
-
}: {
|
|
673
|
-
socket: AirJamRealtimeClient;
|
|
674
|
-
role: AirJamActionActorRole;
|
|
675
|
-
roomId: string;
|
|
676
|
-
resolvedStoreDomain: string;
|
|
677
|
-
}): StoreRuntimeBinding => {
|
|
678
|
-
if (role === "host") {
|
|
679
|
-
let syncedStateData = stripActionsFromState(store.getState());
|
|
680
|
-
let syncedStateSignature = JSON.stringify(syncedStateData);
|
|
681
|
-
let syncRevision = runtimeSnapshotRef.current.hostStateRevisionFloor;
|
|
682
|
-
|
|
683
|
-
const emitHostStateSync = (requestId?: string): void => {
|
|
684
|
-
const runtime = runtimeSnapshotRef.current;
|
|
685
|
-
if (
|
|
686
|
-
runtime.role !== "host" ||
|
|
687
|
-
runtime.roomId !== roomId ||
|
|
688
|
-
runtime.resolvedStoreDomain !== resolvedStoreDomain ||
|
|
689
|
-
!runtime.canBroadcastHostState ||
|
|
690
|
-
!runtime.socket
|
|
691
|
-
) {
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
syncRevision = Math.max(syncRevision, runtime.hostStateRevisionFloor);
|
|
696
|
-
|
|
697
|
-
runtime.socket.emit("host:state_sync", {
|
|
698
|
-
roomId,
|
|
699
|
-
data: syncedStateData,
|
|
700
|
-
storeDomain: resolvedStoreDomain,
|
|
701
|
-
revision: syncRevision,
|
|
702
|
-
...(requestId ? { requestId } : {}),
|
|
703
|
-
});
|
|
704
|
-
};
|
|
705
|
-
|
|
706
|
-
const flushHostStateSync = (requestId?: string): void => {
|
|
707
|
-
emitHostStateSync(requestId);
|
|
708
|
-
};
|
|
709
|
-
|
|
710
|
-
const handleControllerJoined = (): void => {
|
|
711
|
-
flushHostStateSync();
|
|
712
|
-
};
|
|
713
|
-
|
|
714
|
-
const unsubscribe = store.subscribe((newState) => {
|
|
715
|
-
const runtime = runtimeSnapshotRef.current;
|
|
716
|
-
if (
|
|
717
|
-
runtime.role !== "host" ||
|
|
718
|
-
runtime.roomId !== roomId ||
|
|
719
|
-
runtime.resolvedStoreDomain !== resolvedStoreDomain
|
|
720
|
-
) {
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
const stateData = stripActionsFromState(newState);
|
|
725
|
-
const nextSignature = JSON.stringify(stateData);
|
|
726
|
-
if (nextSignature === syncedStateSignature) {
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
syncedStateData = stateData;
|
|
731
|
-
syncedStateSignature = nextSignature;
|
|
732
|
-
syncRevision = Math.max(syncRevision, runtime.hostStateRevisionFloor);
|
|
733
|
-
syncRevision += 1;
|
|
734
|
-
if (runtime.canBroadcastHostState && runtime.socket) {
|
|
735
|
-
emitHostStateSync();
|
|
736
|
-
}
|
|
737
|
-
});
|
|
738
|
-
|
|
739
|
-
const handleAction = (
|
|
740
|
-
payload: AirJamActionRpcPayload,
|
|
741
|
-
callback?: (ack: AirJamActionInvocationResult) => void,
|
|
742
|
-
) => {
|
|
743
|
-
if (payload.storeDomain !== resolvedStoreDomain) {
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
const { actionName } = payload;
|
|
747
|
-
if (isInternalActionName(actionName)) {
|
|
748
|
-
return;
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
const runtime = runtimeSnapshotRef.current;
|
|
752
|
-
const actionFn = store.getState().actions[actionName];
|
|
753
|
-
if (typeof actionFn !== "function") {
|
|
754
|
-
callback?.(
|
|
755
|
-
createServerRejectedActionResult(
|
|
756
|
-
"action_not_found",
|
|
757
|
-
`Store action "${actionName}" is not registered on the host.`,
|
|
758
|
-
{
|
|
759
|
-
actionName,
|
|
760
|
-
storeDomain: resolvedStoreDomain,
|
|
761
|
-
},
|
|
762
|
-
),
|
|
763
|
-
);
|
|
764
|
-
return;
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
try {
|
|
768
|
-
const context = toActionContext(payload, runtime.connectedPlayerIds);
|
|
769
|
-
const result = actionFn(context, payload.payload);
|
|
770
|
-
const acknowledgement = normalizeAirJamActionInvocationResult(
|
|
771
|
-
result,
|
|
772
|
-
"host",
|
|
773
|
-
);
|
|
774
|
-
const actionName = payload.actionName as AirJamActionName<
|
|
775
|
-
T["actions"]
|
|
776
|
-
>;
|
|
777
|
-
notifyHostActionListeners({
|
|
778
|
-
actionName,
|
|
779
|
-
payload: payload.payload,
|
|
780
|
-
context,
|
|
781
|
-
acknowledgement,
|
|
782
|
-
invocationKind: "rpc",
|
|
783
|
-
roomId,
|
|
784
|
-
storeDomain: resolvedStoreDomain,
|
|
785
|
-
} as AirJamHostActionEvent<T["actions"], typeof actionName>);
|
|
786
|
-
callback?.(acknowledgement);
|
|
787
|
-
} catch (error) {
|
|
788
|
-
const acknowledgement = {
|
|
789
|
-
ok: false,
|
|
790
|
-
status: "rejected",
|
|
791
|
-
source: "host",
|
|
792
|
-
reason: "handler_error",
|
|
793
|
-
message: error instanceof Error ? error.message : String(error),
|
|
794
|
-
} satisfies AirJamActionInvocationResult;
|
|
795
|
-
const actionName = payload.actionName as AirJamActionName<
|
|
796
|
-
T["actions"]
|
|
797
|
-
>;
|
|
798
|
-
notifyHostActionListeners({
|
|
799
|
-
actionName,
|
|
800
|
-
payload: payload.payload,
|
|
801
|
-
context: toActionContext(payload, runtime.connectedPlayerIds),
|
|
802
|
-
acknowledgement,
|
|
803
|
-
invocationKind: "rpc",
|
|
804
|
-
roomId,
|
|
805
|
-
storeDomain: resolvedStoreDomain,
|
|
806
|
-
} as AirJamHostActionEvent<T["actions"], typeof actionName>);
|
|
807
|
-
callback?.(acknowledgement);
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
|
-
|
|
811
|
-
const handleStateSyncRequest = (payload: {
|
|
812
|
-
roomId: string;
|
|
813
|
-
storeDomain: string;
|
|
814
|
-
requestId?: string;
|
|
815
|
-
}): void => {
|
|
816
|
-
if (payload.roomId !== roomId) {
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
if (payload.storeDomain !== resolvedStoreDomain) {
|
|
820
|
-
return;
|
|
821
|
-
}
|
|
822
|
-
flushHostStateSync(payload.requestId);
|
|
823
|
-
};
|
|
824
|
-
|
|
825
|
-
const handleSync = (payload: AirJamStateSyncPayload) => {
|
|
826
|
-
if (payload.roomId !== roomId) {
|
|
827
|
-
return;
|
|
828
|
-
}
|
|
829
|
-
if (payload.storeDomain !== resolvedStoreDomain) {
|
|
830
|
-
return;
|
|
831
|
-
}
|
|
832
|
-
if (runtimeSnapshotRef.current.hostStateSyncBlocked) {
|
|
833
|
-
return;
|
|
834
|
-
}
|
|
835
|
-
if (payload.revision < syncRevision) {
|
|
836
|
-
return;
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
const nextStateData = stripActionsFromState(payload.data as Partial<T>);
|
|
840
|
-
const nextSignature = JSON.stringify(nextStateData);
|
|
841
|
-
const currentSignature = JSON.stringify(
|
|
842
|
-
stripActionsFromState(store.getState()),
|
|
843
|
-
);
|
|
844
|
-
syncRevision = payload.revision;
|
|
845
|
-
syncedStateData = nextStateData;
|
|
846
|
-
syncedStateSignature = nextSignature;
|
|
847
|
-
|
|
848
|
-
if (nextSignature === currentSignature) {
|
|
849
|
-
return;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
store.setState(nextStateData);
|
|
853
|
-
};
|
|
854
|
-
|
|
855
|
-
socket.on("server:controllerJoined", handleControllerJoined);
|
|
856
|
-
socket.on("airjam:state_sync", handleSync);
|
|
857
|
-
socket.on("airjam:state_sync_request", handleStateSyncRequest);
|
|
858
|
-
socket.on("airjam:action_rpc", handleAction);
|
|
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
|
-
|
|
894
|
-
return {
|
|
895
|
-
refCount: 0,
|
|
896
|
-
flushHostStateSync,
|
|
897
|
-
cleanup: () => {
|
|
898
|
-
unregisterControl?.();
|
|
899
|
-
unsubscribe();
|
|
900
|
-
socket.off("server:controllerJoined", handleControllerJoined);
|
|
901
|
-
socket.off("airjam:state_sync", handleSync);
|
|
902
|
-
socket.off("airjam:state_sync_request", handleStateSyncRequest);
|
|
903
|
-
socket.off("airjam:action_rpc", handleAction);
|
|
904
|
-
},
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
let latestSyncRevision = -1;
|
|
909
|
-
|
|
910
|
-
const handleSync = (payload: AirJamStateSyncPayload) => {
|
|
911
|
-
if (payload.storeDomain !== resolvedStoreDomain) {
|
|
912
|
-
return;
|
|
913
|
-
}
|
|
914
|
-
if (payload.revision < latestSyncRevision) {
|
|
915
|
-
return;
|
|
916
|
-
}
|
|
917
|
-
latestSyncRevision = payload.revision;
|
|
918
|
-
const stateData = stripActionsFromState(payload.data as Partial<T>);
|
|
919
|
-
store.setState(stateData);
|
|
920
|
-
};
|
|
921
|
-
|
|
922
|
-
socket.on("airjam:state_sync", handleSync);
|
|
923
|
-
|
|
924
|
-
if (runtimeSnapshotRef.current.connectionStatus === "connected") {
|
|
925
|
-
socket.emit("controller:state_sync_request", {
|
|
926
|
-
roomId,
|
|
927
|
-
storeDomain: resolvedStoreDomain,
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
return {
|
|
932
|
-
refCount: 0,
|
|
933
|
-
cleanup: () => {
|
|
934
|
-
socket.off("airjam:state_sync", handleSync);
|
|
935
|
-
},
|
|
936
|
-
};
|
|
937
|
-
};
|
|
938
|
-
|
|
939
|
-
const useSyncedStore = <U>(
|
|
940
|
-
selector: (state: T) => U = (state) => state as unknown as U,
|
|
941
|
-
): U => {
|
|
942
|
-
const slice = store(selector);
|
|
943
|
-
|
|
944
|
-
const explicitDomain = options?.storeDomain;
|
|
945
|
-
let resolvedStoreDomain: string;
|
|
946
|
-
if (
|
|
947
|
-
typeof explicitDomain === "string" &&
|
|
948
|
-
explicitDomain.trim().length > 0
|
|
949
|
-
) {
|
|
950
|
-
const trimmed = explicitDomain.trim();
|
|
951
|
-
resolvedStoreDomain =
|
|
952
|
-
trimmed.length > 128 ? trimmed.slice(0, 128) : trimmed;
|
|
953
|
-
} else {
|
|
954
|
-
resolvedStoreDomain = resolveImplicitReplicatedStoreDomainFromWindow();
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
const { getSocket } = useAirJamContext();
|
|
958
|
-
const role = useAirJamState((state) => state.role);
|
|
959
|
-
const roomId = useAirJamState((state) => state.roomId);
|
|
960
|
-
const registeredRoomId = useAirJamState((state) => state.registeredRoomId);
|
|
961
|
-
const connectionStatus = useAirJamState((state) => state.connectionStatus);
|
|
962
|
-
const players = useAirJamState((state) => state.players);
|
|
963
|
-
const hostArcadeRestore = useAirJamState(
|
|
964
|
-
(state) => state.hostArcadeRestore,
|
|
965
|
-
);
|
|
966
|
-
const blockArcadeShellHostStateSync =
|
|
967
|
-
resolvedStoreDomain === AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN &&
|
|
968
|
-
hostArcadeRestore.phase !== "idle";
|
|
969
|
-
const hostStateRevisionFloor =
|
|
970
|
-
resolvedStoreDomain === AIR_JAM_ARCADE_SURFACE_STORE_DOMAIN
|
|
971
|
-
? (hostArcadeRestore.surfaceCheckpoint?.revision ?? 0)
|
|
972
|
-
: 0;
|
|
973
|
-
const canBroadcastHostState =
|
|
974
|
-
role === "host" &&
|
|
975
|
-
!!roomId &&
|
|
976
|
-
registeredRoomId === roomId &&
|
|
977
|
-
!blockArcadeShellHostStateSync;
|
|
978
|
-
const connectedPlayerIds = useMemo(
|
|
979
|
-
() => Array.from(new Set(players.map((player) => player.id))).sort(),
|
|
980
|
-
[players],
|
|
981
|
-
);
|
|
982
|
-
const playerRosterKey = useMemo(
|
|
983
|
-
() =>
|
|
984
|
-
players
|
|
985
|
-
.map((player) => player.id)
|
|
986
|
-
.sort()
|
|
987
|
-
.join(","),
|
|
988
|
-
[players],
|
|
989
|
-
);
|
|
990
|
-
const socket: AirJamRealtimeClient =
|
|
991
|
-
role === "host"
|
|
992
|
-
? getHostRealtimeClient((runtimeRole) => getSocket(runtimeRole))
|
|
993
|
-
: getControllerRealtimeClient((runtimeRole) => getSocket(runtimeRole));
|
|
994
|
-
|
|
995
|
-
runtimeSnapshotRef.current = {
|
|
996
|
-
socket,
|
|
997
|
-
role,
|
|
998
|
-
roomId,
|
|
999
|
-
resolvedStoreDomain,
|
|
1000
|
-
connectionStatus,
|
|
1001
|
-
canBroadcastHostState,
|
|
1002
|
-
hostStateSyncBlocked: blockArcadeShellHostStateSync,
|
|
1003
|
-
hostStateRevisionFloor,
|
|
1004
|
-
connectedPlayerIds,
|
|
1005
|
-
};
|
|
1006
|
-
|
|
1007
|
-
const runtimeBindingKey =
|
|
1008
|
-
socket && roomId && role
|
|
1009
|
-
? [
|
|
1010
|
-
role,
|
|
1011
|
-
roomId,
|
|
1012
|
-
resolvedStoreDomain,
|
|
1013
|
-
socket.id ?? "socket",
|
|
1014
|
-
role === "controller" ? connectionStatus : "host",
|
|
1015
|
-
].join(":")
|
|
1016
|
-
: null;
|
|
1017
|
-
|
|
1018
|
-
useEffect(() => {
|
|
1019
|
-
if (!runtimeBindingKey || !socket || !roomId || !role) {
|
|
1020
|
-
return;
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
let binding = runtimeBindings.get(runtimeBindingKey);
|
|
1024
|
-
if (!binding) {
|
|
1025
|
-
binding = createRuntimeBinding({
|
|
1026
|
-
socket,
|
|
1027
|
-
role,
|
|
1028
|
-
roomId,
|
|
1029
|
-
resolvedStoreDomain,
|
|
1030
|
-
});
|
|
1031
|
-
runtimeBindings.set(runtimeBindingKey, binding);
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
binding.refCount += 1;
|
|
1035
|
-
|
|
1036
|
-
return () => {
|
|
1037
|
-
const currentBinding = runtimeBindings.get(runtimeBindingKey);
|
|
1038
|
-
if (!currentBinding) {
|
|
1039
|
-
return;
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
currentBinding.refCount -= 1;
|
|
1043
|
-
if (currentBinding.refCount > 0) {
|
|
1044
|
-
return;
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
currentBinding.cleanup();
|
|
1048
|
-
runtimeBindings.delete(runtimeBindingKey);
|
|
1049
|
-
};
|
|
1050
|
-
}, [
|
|
1051
|
-
runtimeBindingKey,
|
|
1052
|
-
socket,
|
|
1053
|
-
role,
|
|
1054
|
-
roomId,
|
|
1055
|
-
socket?.id,
|
|
1056
|
-
resolvedStoreDomain,
|
|
1057
|
-
]);
|
|
1058
|
-
|
|
1059
|
-
useEffect(() => {
|
|
1060
|
-
if (
|
|
1061
|
-
!runtimeBindingKey ||
|
|
1062
|
-
role !== "host" ||
|
|
1063
|
-
!canBroadcastHostState ||
|
|
1064
|
-
!roomId
|
|
1065
|
-
) {
|
|
1066
|
-
return;
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
const binding = runtimeBindings.get(runtimeBindingKey);
|
|
1070
|
-
if (!binding?.flushHostStateSync) {
|
|
1071
|
-
return;
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
const flushKey = [
|
|
1075
|
-
roomId,
|
|
1076
|
-
registeredRoomId,
|
|
1077
|
-
socket?.id ?? "socket",
|
|
1078
|
-
resolvedStoreDomain,
|
|
1079
|
-
playerRosterKey,
|
|
1080
|
-
canBroadcastHostState ? "broadcast" : "blocked",
|
|
1081
|
-
].join(":");
|
|
1082
|
-
|
|
1083
|
-
if (binding.lastHostFlushKey === flushKey) {
|
|
1084
|
-
return;
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
binding.lastHostFlushKey = flushKey;
|
|
1088
|
-
binding.flushHostStateSync();
|
|
1089
|
-
}, [
|
|
1090
|
-
role,
|
|
1091
|
-
roomId,
|
|
1092
|
-
registeredRoomId,
|
|
1093
|
-
socket?.id,
|
|
1094
|
-
playerRosterKey,
|
|
1095
|
-
resolvedStoreDomain,
|
|
1096
|
-
canBroadcastHostState,
|
|
1097
|
-
runtimeBindingKey,
|
|
1098
|
-
]);
|
|
1099
|
-
|
|
1100
|
-
const dispatchedActions = useMemo<AirJamActionDispatchMap<T["actions"]>>(
|
|
1101
|
-
() => createDispatchedActions({ kind: "default" }),
|
|
1102
|
-
[],
|
|
1103
|
-
);
|
|
1104
|
-
|
|
1105
|
-
const stateActions = store.getState().actions;
|
|
1106
|
-
|
|
1107
|
-
if (slice === stateActions) {
|
|
1108
|
-
return dispatchedActions as U;
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
if (
|
|
1112
|
-
typeof slice === "object" &&
|
|
1113
|
-
slice !== null &&
|
|
1114
|
-
"actions" in slice &&
|
|
1115
|
-
(slice as { actions: unknown }).actions === stateActions
|
|
1116
|
-
) {
|
|
1117
|
-
return {
|
|
1118
|
-
...(slice as Record<string, unknown>),
|
|
1119
|
-
actions: dispatchedActions,
|
|
1120
|
-
} as U;
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
return slice;
|
|
1124
|
-
};
|
|
1125
|
-
|
|
1126
|
-
const syncedStore = useSyncedStore as AirJamSyncedStoreHook<T>;
|
|
1127
|
-
const useActions = (): AirJamActionDispatchMap<T["actions"]> =>
|
|
1128
|
-
useSyncedStore((state) => state.actions) as AirJamActionDispatchMap<
|
|
1129
|
-
T["actions"]
|
|
1130
|
-
>;
|
|
1131
|
-
const asPlayer = (
|
|
1132
|
-
controllerId: string,
|
|
1133
|
-
): AirJamActionDispatchMap<T["actions"]> =>
|
|
1134
|
-
createDispatchedActions({
|
|
1135
|
-
kind: "player",
|
|
1136
|
-
controllerId,
|
|
1137
|
-
});
|
|
1138
|
-
const subscribeHostActions = (
|
|
1139
|
-
listener: AirJamHostActionListener<T["actions"]>,
|
|
1140
|
-
options?: AirJamHostActionSubscriptionOptions<T["actions"]>,
|
|
1141
|
-
): (() => void) => {
|
|
1142
|
-
const actionNames =
|
|
1143
|
-
options?.actionNames && options.actionNames.length > 0
|
|
1144
|
-
? new Set<string>(options.actionNames)
|
|
1145
|
-
: null;
|
|
1146
|
-
const registration: HostActionListenerRegistration<T["actions"]> = {
|
|
1147
|
-
actionNames,
|
|
1148
|
-
includeRejected: options?.includeRejected ?? false,
|
|
1149
|
-
listener,
|
|
1150
|
-
};
|
|
1151
|
-
hostActionListeners.add(registration);
|
|
1152
|
-
return () => {
|
|
1153
|
-
hostActionListeners.delete(registration);
|
|
1154
|
-
};
|
|
1155
|
-
};
|
|
1156
|
-
const useHostActionListener = (
|
|
1157
|
-
listener: AirJamHostActionListener<T["actions"]>,
|
|
1158
|
-
options?: AirJamHostActionSubscriptionOptions<T["actions"]>,
|
|
1159
|
-
): void => {
|
|
1160
|
-
const listenerRef = useRef(listener);
|
|
1161
|
-
useEffect(() => {
|
|
1162
|
-
listenerRef.current = listener;
|
|
1163
|
-
}, [listener]);
|
|
1164
|
-
|
|
1165
|
-
const includeRejected = options?.includeRejected ?? false;
|
|
1166
|
-
const actionNamesKey = options?.actionNames?.join("\u0000") ?? "";
|
|
1167
|
-
|
|
1168
|
-
useEffect(() => {
|
|
1169
|
-
return subscribeHostActions((event) => {
|
|
1170
|
-
listenerRef.current(event);
|
|
1171
|
-
}, options);
|
|
1172
|
-
}, [actionNamesKey, includeRejected, options]);
|
|
1173
|
-
};
|
|
1174
|
-
const useLiveStateRef = (): MutableRefObject<T> => {
|
|
1175
|
-
const latestState = useSyncedStore((state) => state);
|
|
1176
|
-
const stateRef = useRef<T>(latestState);
|
|
1177
|
-
|
|
1178
|
-
useEffect(() => {
|
|
1179
|
-
stateRef.current = latestState;
|
|
1180
|
-
}, [latestState]);
|
|
1181
|
-
|
|
1182
|
-
return stateRef;
|
|
1183
|
-
};
|
|
1184
|
-
syncedStore.useActions = useActions;
|
|
1185
|
-
syncedStore.asPlayer = asPlayer;
|
|
1186
|
-
syncedStore.getState = store.getState;
|
|
1187
|
-
syncedStore.subscribe = store.subscribe;
|
|
1188
|
-
syncedStore.subscribeHostActions = subscribeHostActions;
|
|
1189
|
-
syncedStore.useHostActionListener = useHostActionListener;
|
|
1190
|
-
syncedStore.useLiveStateRef = useLiveStateRef;
|
|
1191
|
-
|
|
1192
|
-
return syncedStore;
|
|
1193
|
-
}
|