@air-jam/sdk 0.9.3 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +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-DfLm4Mf-.d.ts} +3 -19
- package/dist/{agent-contract-CD2QnbBJ.d.ts → agent-contract-TINzp-5Y.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-BCVCWiaT.d.ts} +121 -114
- package/dist/{use-air-jam-host-DM-ybB3C.d.cts → air-jam-context-DavligpM.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 +10354 -4690
- 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-2QZADUGA.js +188 -0
- package/dist/chunk-2QZADUGA.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-5TVVPBQI.js +7 -0
- package/dist/chunk-5TVVPBQI.js.map +1 -0
- package/dist/chunk-6Y3F6Y2K.js +343 -0
- package/dist/chunk-6Y3F6Y2K.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-BEM77SVQ.js +57 -0
- package/dist/chunk-BEM77SVQ.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-DHFKL3DI.js +2477 -0
- package/dist/chunk-DHFKL3DI.js.map +1 -0
- package/dist/chunk-DRBPVG47.js +89 -0
- package/dist/chunk-DRBPVG47.js.map +1 -0
- package/dist/{chunk-MIMPMB7O.js → chunk-EG25EXSA.js} +24 -3
- package/dist/chunk-EG25EXSA.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-X35LLCWV.js → chunk-I6TSHJF7.js} +6 -8
- package/dist/chunk-I6TSHJF7.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-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-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-S3TN7Y7L.js +921 -0
- package/dist/chunk-S3TN7Y7L.js.map +1 -0
- package/dist/chunk-SMKD4JY3.js +129 -0
- package/dist/chunk-SMKD4JY3.js.map +1 -0
- package/dist/{chunk-O6X7FJ6N.js → chunk-TFW4NJW2.js} +619 -643
- package/dist/chunk-TFW4NJW2.js.map +1 -0
- package/dist/chunk-UBBP2UY3.js +83 -0
- package/dist/chunk-UBBP2UY3.js.map +1 -0
- package/dist/chunk-URVBMQCK.js +802 -0
- package/dist/chunk-URVBMQCK.js.map +1 -0
- package/dist/chunk-VGX2274F.js +1995 -0
- package/dist/chunk-VGX2274F.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-XLY44PXZ.js +46 -0
- package/dist/chunk-XLY44PXZ.js.map +1 -0
- package/dist/connection-store-BYpQ50W2.d.ts +41 -0
- package/dist/connection-store-D6QqzXU1.d.cts +41 -0
- package/dist/control-Bv8dWjyp.d.ts +1400 -0
- package/dist/control-CNzybWMd.d.cts +1400 -0
- package/dist/controller-0CVO1t_3.d.cts +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-h9M2Nngd.d.ts +26 -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 +5931 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +232 -0
- package/dist/core.d.ts +232 -0
- package/dist/core.js +906 -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-Db58JNk3.d.cts +77 -0
- package/dist/game-bySEy-QO.d.ts +77 -0
- package/dist/host-runtime-BuLhGQx5.d.ts +399 -0
- package/dist/host-runtime-_06jpW5v.d.cts +399 -0
- package/dist/index.cjs +11580 -7584
- 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-Xvs80gqG.d.cts +92 -0
- package/dist/input-Xvs80gqG.d.ts +92 -0
- package/dist/input-bindings-BaEFrgRb.d.cts +129 -0
- package/dist/input-bindings-BgsJRLPm.d.ts +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-Ca6rlxJr.d.ts +439 -0
- package/dist/phone-room-session-DkPR-K6e.d.cts +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 +2214 -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-BvX4As2f.d.ts +31 -0
- package/dist/replay-input-log-Vcl0VDIy.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 +2112 -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-CiiWu06D.d.ts +66 -0
- package/dist/scoped-connector-D7252pn0.d.cts +66 -0
- package/dist/sdk-channels-S6j6AH8v.d.cts +103 -0
- package/dist/sdk-channels-S6j6AH8v.d.ts +103 -0
- package/dist/simulation-BfRnC4rg.d.ts +782 -0
- package/dist/simulation-BwZx2pgt.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 +2182 -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 +26 -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 +162 -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
|
@@ -0,0 +1,2477 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stageCaptureCanvasSelector,
|
|
3
|
+
supportsStageCapture
|
|
4
|
+
} from "./chunk-OAXCFPZ7.js";
|
|
5
|
+
import {
|
|
6
|
+
isAirJamInspectionDocument,
|
|
7
|
+
prefabInspectionMessageSchema,
|
|
8
|
+
prefabInspectionRequestSchema
|
|
9
|
+
} from "./chunk-K6BJJJJM.js";
|
|
10
|
+
import {
|
|
11
|
+
HostRoomSession,
|
|
12
|
+
PhoneRoomSession,
|
|
13
|
+
browserDeviceWakeEvents,
|
|
14
|
+
createRoomKey,
|
|
15
|
+
createWebSocketConnector
|
|
16
|
+
} from "./chunk-S3TN7Y7L.js";
|
|
17
|
+
import {
|
|
18
|
+
createControllerRuntimeInspectionContract,
|
|
19
|
+
createHostRuntimeInspectionContract,
|
|
20
|
+
publishEmbeddedControllerAgent,
|
|
21
|
+
publishEmbeddedHostAgent,
|
|
22
|
+
publishEmbeddedHostPreview,
|
|
23
|
+
publishRuntimeInspectionContract,
|
|
24
|
+
readRuntimeInspectionContract
|
|
25
|
+
} from "./chunk-3M7656SU.js";
|
|
26
|
+
import {
|
|
27
|
+
useAirJamController
|
|
28
|
+
} from "./chunk-I6TSHJF7.js";
|
|
29
|
+
import {
|
|
30
|
+
requestEmbeddingRoom
|
|
31
|
+
} from "./chunk-UBBP2UY3.js";
|
|
32
|
+
import {
|
|
33
|
+
ControllerRuntime,
|
|
34
|
+
HostRuntime
|
|
35
|
+
} from "./chunk-VGX2274F.js";
|
|
36
|
+
import {
|
|
37
|
+
DEFAULT_PREFAB_VIEW,
|
|
38
|
+
prefabCatalogMetadataSchema,
|
|
39
|
+
prefabMetadata
|
|
40
|
+
} from "./chunk-FCG42U7D.js";
|
|
41
|
+
import {
|
|
42
|
+
AIR_JAM_PREVIEW_CLOSE_RESULT,
|
|
43
|
+
AIR_JAM_PREVIEW_SEAT,
|
|
44
|
+
LocalPlayersHost,
|
|
45
|
+
isPreviewCloseRequestMessage,
|
|
46
|
+
listenForLocalSeatInput,
|
|
47
|
+
readLocalSeatLabel,
|
|
48
|
+
useAirJamHost
|
|
49
|
+
} from "./chunk-URVBMQCK.js";
|
|
50
|
+
import {
|
|
51
|
+
AIR_JAM_PREVIEW_CAPTURE_QUERY_PARAM,
|
|
52
|
+
readPreviewControllerDeviceIdFromLocation,
|
|
53
|
+
readPreviewControllerParent
|
|
54
|
+
} from "./chunk-BEM77SVQ.js";
|
|
55
|
+
import {
|
|
56
|
+
AirJamContext,
|
|
57
|
+
AirJamProvider,
|
|
58
|
+
PlatformSettingsBoundary,
|
|
59
|
+
RuntimeOwnerRegistryContext,
|
|
60
|
+
SessionScopeContext,
|
|
61
|
+
controllerRuntimeContext,
|
|
62
|
+
declaredStoresContext,
|
|
63
|
+
fixedControllerOrientationContext,
|
|
64
|
+
hostRuntimeContext,
|
|
65
|
+
readEmbeddedControllerChildSession,
|
|
66
|
+
readEmbeddedHostChildSession,
|
|
67
|
+
resolveAirJamConfig,
|
|
68
|
+
updateDevBrowserLogContext,
|
|
69
|
+
useAirJamConfig,
|
|
70
|
+
useAirJamContext,
|
|
71
|
+
useAssertSessionScope,
|
|
72
|
+
useClaimSessionRuntimeOwner
|
|
73
|
+
} from "./chunk-TFW4NJW2.js";
|
|
74
|
+
import {
|
|
75
|
+
resolveImplicitReplicatedStoreDomainFromWindow
|
|
76
|
+
} from "./chunk-M5553I2G.js";
|
|
77
|
+
import {
|
|
78
|
+
emitAirJamDevRuntimeEvent
|
|
79
|
+
} from "./chunk-EG25EXSA.js";
|
|
80
|
+
import {
|
|
81
|
+
bindBrowserReplay,
|
|
82
|
+
isAirJamReplayDocument
|
|
83
|
+
} from "./chunk-2QZADUGA.js";
|
|
84
|
+
import {
|
|
85
|
+
embeddedRuntimeParent
|
|
86
|
+
} from "./chunk-LX6CTPDW.js";
|
|
87
|
+
import {
|
|
88
|
+
controllerBridgeContext
|
|
89
|
+
} from "./chunk-FJ4J2BEC.js";
|
|
90
|
+
import {
|
|
91
|
+
createAirJamDiagnosticError,
|
|
92
|
+
emitAirJamDiagnostic
|
|
93
|
+
} from "./chunk-DBF7NJ3S.js";
|
|
94
|
+
import {
|
|
95
|
+
AIRJAM_DEV_LOG_EVENTS
|
|
96
|
+
} from "./chunk-KUGROY5S.js";
|
|
97
|
+
import {
|
|
98
|
+
CONTROLLER_PATH,
|
|
99
|
+
DEFAULT_SERVER_PORT
|
|
100
|
+
} from "./chunk-6Y3F6Y2K.js";
|
|
101
|
+
import {
|
|
102
|
+
AIRJAM_RUNTIME_ERROR_REPORT_CONTRACT_VERSION
|
|
103
|
+
} from "./chunk-KSYN4I5Y.js";
|
|
104
|
+
import {
|
|
105
|
+
CLIP_FRAME_MAX_EDGE,
|
|
106
|
+
CLIP_PAGE_BASE64_CHARS,
|
|
107
|
+
CLIP_VIDEO_MAX_BYTES,
|
|
108
|
+
CLIP_VIDEO_MAX_DURATION_MS,
|
|
109
|
+
HOST_OBSERVATION_IMAGE_BYTES,
|
|
110
|
+
airJamSettingsValuesSchema
|
|
111
|
+
} from "./chunk-WAFGYJZN.js";
|
|
112
|
+
import {
|
|
113
|
+
runtimeTopologyToQueryParams
|
|
114
|
+
} from "./chunk-2H2FGF3H.js";
|
|
115
|
+
import {
|
|
116
|
+
roomCodeSchema
|
|
117
|
+
} from "./chunk-24NZZOIO.js";
|
|
118
|
+
|
|
119
|
+
// src/agent/capture-canvas.ts
|
|
120
|
+
async function captureAgentCanvas(canvas, { maxEdge, quality } = {
|
|
121
|
+
maxEdge: 1280,
|
|
122
|
+
quality: 0.8
|
|
123
|
+
}) {
|
|
124
|
+
if (!canvas) return null;
|
|
125
|
+
const image = canvas.ownerDocument.createElement("canvas");
|
|
126
|
+
if (!drawAgentCanvas(canvas, image, { maxEdge })) return null;
|
|
127
|
+
return encodeAgentCanvas(image, quality);
|
|
128
|
+
}
|
|
129
|
+
function drawAgentCanvas(canvas, image, { maxEdge }) {
|
|
130
|
+
if (!canvas || !canvas.width || !canvas.height) return false;
|
|
131
|
+
const scale = Math.min(1, maxEdge / canvas.width, maxEdge / canvas.height);
|
|
132
|
+
const width = Math.max(1, Math.round(canvas.width * scale));
|
|
133
|
+
if (image.width !== width) image.width = width;
|
|
134
|
+
const height = Math.max(1, Math.round(canvas.height * scale));
|
|
135
|
+
if (image.height !== height) image.height = height;
|
|
136
|
+
const context = image.getContext("2d");
|
|
137
|
+
if (!context)
|
|
138
|
+
throw new Error("Canvas observation requires a 2D capture context.");
|
|
139
|
+
context.clearRect(0, 0, image.width, image.height);
|
|
140
|
+
context.drawImage(canvas, 0, 0, image.width, image.height);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
async function encodeAgentCanvas(image, quality) {
|
|
144
|
+
const { width, height } = image;
|
|
145
|
+
const blob = await new Promise((resolve, reject) => {
|
|
146
|
+
image.toBlob(
|
|
147
|
+
(blob2) => {
|
|
148
|
+
if (blob2) resolve(blob2);
|
|
149
|
+
else
|
|
150
|
+
reject(new Error("The renderer did not produce a JPEG observation."));
|
|
151
|
+
},
|
|
152
|
+
"image/jpeg",
|
|
153
|
+
quality
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
const encoded = await new Promise((resolve, reject) => {
|
|
157
|
+
const reader = new FileReader();
|
|
158
|
+
reader.onerror = () => reject(reader.error);
|
|
159
|
+
reader.onload = () => {
|
|
160
|
+
if (typeof reader.result === "string") resolve(reader.result);
|
|
161
|
+
else
|
|
162
|
+
reject(new Error("The renderer did not produce a JPEG observation."));
|
|
163
|
+
};
|
|
164
|
+
reader.readAsDataURL(blob);
|
|
165
|
+
});
|
|
166
|
+
const prefix = "data:image/jpeg;base64,";
|
|
167
|
+
if (!encoded.startsWith(prefix))
|
|
168
|
+
throw new Error("The renderer did not produce a JPEG observation.");
|
|
169
|
+
const data = encoded.slice(prefix.length);
|
|
170
|
+
if (data.length > Math.ceil(HOST_OBSERVATION_IMAGE_BYTES / 3) * 4)
|
|
171
|
+
throw new Error("Canvas observation exceeds its image transfer budget.");
|
|
172
|
+
return {
|
|
173
|
+
mimeType: "image/jpeg",
|
|
174
|
+
data,
|
|
175
|
+
width,
|
|
176
|
+
height,
|
|
177
|
+
coverage: "render-surface"
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/runtime/air-jam-error-boundary.tsx
|
|
182
|
+
import {
|
|
183
|
+
Check,
|
|
184
|
+
Copy,
|
|
185
|
+
Maximize2,
|
|
186
|
+
Minimize2,
|
|
187
|
+
RefreshCw,
|
|
188
|
+
RotateCcw
|
|
189
|
+
} from "lucide-react";
|
|
190
|
+
import { Component, useCallback, useEffect, useRef, useState } from "react";
|
|
191
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
192
|
+
var toError = (value) => {
|
|
193
|
+
if (value instanceof Error) {
|
|
194
|
+
return value;
|
|
195
|
+
}
|
|
196
|
+
if (typeof value === "string") {
|
|
197
|
+
return new Error(value);
|
|
198
|
+
}
|
|
199
|
+
return new Error("Unknown runtime error");
|
|
200
|
+
};
|
|
201
|
+
var isEmbeddedRuntime = () => typeof window !== "undefined" && typeof window.parent !== "undefined" && window.parent !== window;
|
|
202
|
+
var roleLabel = (role) => role === "host" ? "Host runtime" : "Controller runtime";
|
|
203
|
+
var mono = "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, monospace";
|
|
204
|
+
var errorSurface = {
|
|
205
|
+
bg: "#0a0a0a",
|
|
206
|
+
panel: "#141414",
|
|
207
|
+
panelBorder: "rgba(255, 255, 255, 0.08)",
|
|
208
|
+
inset: "#0c0c0c",
|
|
209
|
+
insetBorder: "rgba(255, 255, 255, 0.06)",
|
|
210
|
+
text: "#fafafa",
|
|
211
|
+
muted: "#a3a3a3",
|
|
212
|
+
dim: "#737373",
|
|
213
|
+
zOverlay: 2147483e3
|
|
214
|
+
};
|
|
215
|
+
var iconSize = 16;
|
|
216
|
+
var createErrorDigest = (error) => {
|
|
217
|
+
const input = `${error.name}:${error.message}:${error.stack ?? ""}`;
|
|
218
|
+
let hash = 0;
|
|
219
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
220
|
+
hash = hash * 31 + input.charCodeAt(index) >>> 0;
|
|
221
|
+
}
|
|
222
|
+
return hash.toString(16).padStart(8, "0");
|
|
223
|
+
};
|
|
224
|
+
var createRuntimeReportId = () => {
|
|
225
|
+
const direct = globalThis.crypto?.randomUUID?.();
|
|
226
|
+
if (direct) return direct;
|
|
227
|
+
const bytes = new Uint8Array(16);
|
|
228
|
+
if (globalThis.crypto?.getRandomValues) {
|
|
229
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
230
|
+
} else {
|
|
231
|
+
for (let index = 0; index < bytes.length; index += 1) {
|
|
232
|
+
bytes[index] = Math.floor(Math.random() * 256);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
236
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
237
|
+
const hex = Array.from(
|
|
238
|
+
bytes,
|
|
239
|
+
(value) => value.toString(16).padStart(2, "0")
|
|
240
|
+
).join("");
|
|
241
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
242
|
+
};
|
|
243
|
+
var copyTextToClipboard = async (text) => {
|
|
244
|
+
if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
|
|
245
|
+
await navigator.clipboard.writeText(text);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (typeof document === "undefined") {
|
|
249
|
+
throw new Error("Clipboard is unavailable");
|
|
250
|
+
}
|
|
251
|
+
const textarea = document.createElement("textarea");
|
|
252
|
+
textarea.value = text;
|
|
253
|
+
textarea.style.position = "fixed";
|
|
254
|
+
textarea.style.opacity = "0";
|
|
255
|
+
textarea.style.pointerEvents = "none";
|
|
256
|
+
document.body.appendChild(textarea);
|
|
257
|
+
textarea.focus();
|
|
258
|
+
textarea.select();
|
|
259
|
+
const succeeded = typeof document.execCommand === "function" ? document.execCommand("copy") : false;
|
|
260
|
+
document.body.removeChild(textarea);
|
|
261
|
+
if (!succeeded) {
|
|
262
|
+
throw new Error("Copy command failed");
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var createCopyPayload = ({
|
|
266
|
+
role,
|
|
267
|
+
roomId,
|
|
268
|
+
appId,
|
|
269
|
+
error,
|
|
270
|
+
digest,
|
|
271
|
+
isEmbedded
|
|
272
|
+
}) => {
|
|
273
|
+
const lines = [
|
|
274
|
+
"AirJam Runtime Error",
|
|
275
|
+
`Role: ${role}`,
|
|
276
|
+
`Digest: ${digest}`,
|
|
277
|
+
`Embedded: ${isEmbedded ? "yes" : "no"}`,
|
|
278
|
+
roomId ? `Room: ${roomId}` : null,
|
|
279
|
+
appId ? `App ID: ${appId}` : null,
|
|
280
|
+
`Error: ${error.message || "Unknown error"}`,
|
|
281
|
+
"",
|
|
282
|
+
"Stack:",
|
|
283
|
+
error.stack ?? "(no stack)"
|
|
284
|
+
].filter((line) => line !== null);
|
|
285
|
+
return lines.join("\n");
|
|
286
|
+
};
|
|
287
|
+
var btnRow = {
|
|
288
|
+
display: "inline-flex",
|
|
289
|
+
alignItems: "center",
|
|
290
|
+
justifyContent: "center",
|
|
291
|
+
gap: "0.35rem",
|
|
292
|
+
borderRadius: "0.5rem",
|
|
293
|
+
padding: "0.5rem 0.75rem",
|
|
294
|
+
fontSize: "0.8125rem",
|
|
295
|
+
fontWeight: 600,
|
|
296
|
+
cursor: "pointer",
|
|
297
|
+
fontFamily: "ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif"
|
|
298
|
+
};
|
|
299
|
+
var DefaultFallback = ({
|
|
300
|
+
role,
|
|
301
|
+
roomId,
|
|
302
|
+
appId,
|
|
303
|
+
error,
|
|
304
|
+
reset,
|
|
305
|
+
reload,
|
|
306
|
+
isEmbedded
|
|
307
|
+
}) => {
|
|
308
|
+
const digest = createErrorDigest(error);
|
|
309
|
+
const [isMinimized, setIsMinimized] = useState(false);
|
|
310
|
+
const [copyState, setCopyState] = useState(
|
|
311
|
+
"idle"
|
|
312
|
+
);
|
|
313
|
+
const copyResetTimeoutRef = useRef(null);
|
|
314
|
+
useEffect(() => {
|
|
315
|
+
return () => {
|
|
316
|
+
if (copyResetTimeoutRef.current !== null && typeof window !== "undefined") {
|
|
317
|
+
window.clearTimeout(copyResetTimeoutRef.current);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}, []);
|
|
321
|
+
const scheduleCopyStatusReset = useCallback(() => {
|
|
322
|
+
if (typeof window === "undefined") {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (copyResetTimeoutRef.current !== null) {
|
|
326
|
+
window.clearTimeout(copyResetTimeoutRef.current);
|
|
327
|
+
}
|
|
328
|
+
copyResetTimeoutRef.current = window.setTimeout(() => {
|
|
329
|
+
setCopyState("idle");
|
|
330
|
+
copyResetTimeoutRef.current = null;
|
|
331
|
+
}, 1800);
|
|
332
|
+
}, []);
|
|
333
|
+
const handleCopy = useCallback(async () => {
|
|
334
|
+
try {
|
|
335
|
+
await copyTextToClipboard(
|
|
336
|
+
createCopyPayload({
|
|
337
|
+
role,
|
|
338
|
+
roomId,
|
|
339
|
+
appId,
|
|
340
|
+
error,
|
|
341
|
+
isEmbedded,
|
|
342
|
+
digest
|
|
343
|
+
})
|
|
344
|
+
);
|
|
345
|
+
setCopyState("copied");
|
|
346
|
+
scheduleCopyStatusReset();
|
|
347
|
+
} catch {
|
|
348
|
+
setCopyState("failed");
|
|
349
|
+
scheduleCopyStatusReset();
|
|
350
|
+
}
|
|
351
|
+
}, [appId, digest, error, isEmbedded, role, roomId, scheduleCopyStatusReset]);
|
|
352
|
+
const copyButtonLabel = copyState === "copied" ? "Copied" : copyState === "failed" ? "Copy failed" : "Copy details";
|
|
353
|
+
const CopyGlyph = copyState === "copied" ? /* @__PURE__ */ jsx(Check, { size: iconSize, strokeWidth: 2, "aria-hidden": true }) : /* @__PURE__ */ jsx(Copy, { size: iconSize, strokeWidth: 2, "aria-hidden": true });
|
|
354
|
+
if (isMinimized) {
|
|
355
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
356
|
+
/* @__PURE__ */ jsx(
|
|
357
|
+
"div",
|
|
358
|
+
{
|
|
359
|
+
"aria-hidden": true,
|
|
360
|
+
style: {
|
|
361
|
+
position: "fixed",
|
|
362
|
+
inset: 0,
|
|
363
|
+
zIndex: errorSurface.zOverlay,
|
|
364
|
+
background: "rgba(10, 10, 10, 0.72)"
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
),
|
|
368
|
+
/* @__PURE__ */ jsxs(
|
|
369
|
+
"div",
|
|
370
|
+
{
|
|
371
|
+
style: {
|
|
372
|
+
position: "fixed",
|
|
373
|
+
bottom: "1rem",
|
|
374
|
+
right: "1rem",
|
|
375
|
+
zIndex: errorSurface.zOverlay + 1,
|
|
376
|
+
maxWidth: "min(22rem, calc(100vw - 2rem))",
|
|
377
|
+
borderRadius: "0.625rem",
|
|
378
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
379
|
+
background: errorSurface.panel,
|
|
380
|
+
boxShadow: "0 16px 48px rgba(0, 0, 0, 0.55)",
|
|
381
|
+
padding: "0.75rem 0.85rem"
|
|
382
|
+
},
|
|
383
|
+
children: [
|
|
384
|
+
/* @__PURE__ */ jsxs(
|
|
385
|
+
"div",
|
|
386
|
+
{
|
|
387
|
+
style: {
|
|
388
|
+
display: "flex",
|
|
389
|
+
alignItems: "flex-start",
|
|
390
|
+
justifyContent: "space-between",
|
|
391
|
+
gap: "0.5rem"
|
|
392
|
+
},
|
|
393
|
+
children: [
|
|
394
|
+
/* @__PURE__ */ jsxs("div", { style: { minWidth: 0 }, children: [
|
|
395
|
+
/* @__PURE__ */ jsx(
|
|
396
|
+
"div",
|
|
397
|
+
{
|
|
398
|
+
style: {
|
|
399
|
+
fontSize: "0.6875rem",
|
|
400
|
+
fontWeight: 600,
|
|
401
|
+
letterSpacing: "0.02em",
|
|
402
|
+
color: errorSurface.dim,
|
|
403
|
+
textTransform: "uppercase"
|
|
404
|
+
},
|
|
405
|
+
children: "AirJam \xB7 runtime error"
|
|
406
|
+
}
|
|
407
|
+
),
|
|
408
|
+
/* @__PURE__ */ jsxs(
|
|
409
|
+
"div",
|
|
410
|
+
{
|
|
411
|
+
style: {
|
|
412
|
+
marginTop: "0.25rem",
|
|
413
|
+
fontSize: "0.75rem",
|
|
414
|
+
color: errorSurface.muted,
|
|
415
|
+
fontFamily: mono,
|
|
416
|
+
lineHeight: 1.4,
|
|
417
|
+
wordBreak: "break-word"
|
|
418
|
+
},
|
|
419
|
+
children: [
|
|
420
|
+
role,
|
|
421
|
+
" \xB7 ",
|
|
422
|
+
digest
|
|
423
|
+
]
|
|
424
|
+
}
|
|
425
|
+
)
|
|
426
|
+
] }),
|
|
427
|
+
/* @__PURE__ */ jsx(
|
|
428
|
+
"button",
|
|
429
|
+
{
|
|
430
|
+
type: "button",
|
|
431
|
+
onClick: () => setIsMinimized(false),
|
|
432
|
+
"aria-label": "Expand error panel",
|
|
433
|
+
title: "Expand error panel",
|
|
434
|
+
style: {
|
|
435
|
+
...btnRow,
|
|
436
|
+
flexShrink: 0,
|
|
437
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
438
|
+
background: errorSurface.inset,
|
|
439
|
+
color: errorSurface.text,
|
|
440
|
+
padding: "0.4rem"
|
|
441
|
+
},
|
|
442
|
+
children: /* @__PURE__ */ jsx(Maximize2, { size: iconSize, strokeWidth: 2, "aria-hidden": true })
|
|
443
|
+
}
|
|
444
|
+
)
|
|
445
|
+
]
|
|
446
|
+
}
|
|
447
|
+
),
|
|
448
|
+
/* @__PURE__ */ jsxs(
|
|
449
|
+
"div",
|
|
450
|
+
{
|
|
451
|
+
style: {
|
|
452
|
+
marginTop: "0.65rem",
|
|
453
|
+
display: "flex",
|
|
454
|
+
flexWrap: "wrap",
|
|
455
|
+
gap: "0.4rem"
|
|
456
|
+
},
|
|
457
|
+
children: [
|
|
458
|
+
/* @__PURE__ */ jsxs(
|
|
459
|
+
"button",
|
|
460
|
+
{
|
|
461
|
+
type: "button",
|
|
462
|
+
onClick: () => {
|
|
463
|
+
void handleCopy();
|
|
464
|
+
},
|
|
465
|
+
style: {
|
|
466
|
+
...btnRow,
|
|
467
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
468
|
+
background: "transparent",
|
|
469
|
+
color: errorSurface.muted
|
|
470
|
+
},
|
|
471
|
+
children: [
|
|
472
|
+
CopyGlyph,
|
|
473
|
+
copyButtonLabel
|
|
474
|
+
]
|
|
475
|
+
}
|
|
476
|
+
),
|
|
477
|
+
/* @__PURE__ */ jsxs(
|
|
478
|
+
"button",
|
|
479
|
+
{
|
|
480
|
+
type: "button",
|
|
481
|
+
onClick: reload,
|
|
482
|
+
style: {
|
|
483
|
+
...btnRow,
|
|
484
|
+
border: "none",
|
|
485
|
+
background: errorSurface.text,
|
|
486
|
+
color: errorSurface.bg
|
|
487
|
+
},
|
|
488
|
+
children: [
|
|
489
|
+
/* @__PURE__ */ jsx(RefreshCw, { size: iconSize, strokeWidth: 2, "aria-hidden": true }),
|
|
490
|
+
"Reload"
|
|
491
|
+
]
|
|
492
|
+
}
|
|
493
|
+
)
|
|
494
|
+
]
|
|
495
|
+
}
|
|
496
|
+
)
|
|
497
|
+
]
|
|
498
|
+
}
|
|
499
|
+
)
|
|
500
|
+
] });
|
|
501
|
+
}
|
|
502
|
+
return /* @__PURE__ */ jsx(
|
|
503
|
+
"div",
|
|
504
|
+
{
|
|
505
|
+
style: {
|
|
506
|
+
minHeight: "100vh",
|
|
507
|
+
width: "100%",
|
|
508
|
+
display: "flex",
|
|
509
|
+
alignItems: "center",
|
|
510
|
+
justifyContent: "center",
|
|
511
|
+
background: errorSurface.bg,
|
|
512
|
+
padding: "1.5rem 1rem",
|
|
513
|
+
boxSizing: "border-box"
|
|
514
|
+
},
|
|
515
|
+
children: /* @__PURE__ */ jsxs(
|
|
516
|
+
"div",
|
|
517
|
+
{
|
|
518
|
+
style: {
|
|
519
|
+
position: "relative",
|
|
520
|
+
width: "100%",
|
|
521
|
+
maxWidth: "42rem",
|
|
522
|
+
borderRadius: "0.625rem",
|
|
523
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
524
|
+
background: errorSurface.panel,
|
|
525
|
+
boxShadow: "0 24px 64px rgba(0, 0, 0, 0.45)",
|
|
526
|
+
padding: "1.25rem 1.35rem",
|
|
527
|
+
boxSizing: "border-box"
|
|
528
|
+
},
|
|
529
|
+
children: [
|
|
530
|
+
/* @__PURE__ */ jsx(
|
|
531
|
+
"button",
|
|
532
|
+
{
|
|
533
|
+
type: "button",
|
|
534
|
+
onClick: () => setIsMinimized(true),
|
|
535
|
+
"aria-label": "Minimize error panel",
|
|
536
|
+
title: "Minimize error panel",
|
|
537
|
+
style: {
|
|
538
|
+
...btnRow,
|
|
539
|
+
position: "absolute",
|
|
540
|
+
top: "0.85rem",
|
|
541
|
+
right: "0.85rem",
|
|
542
|
+
padding: "0.4rem",
|
|
543
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
544
|
+
background: errorSurface.inset,
|
|
545
|
+
color: errorSurface.muted
|
|
546
|
+
},
|
|
547
|
+
children: /* @__PURE__ */ jsx(Minimize2, { size: iconSize, strokeWidth: 2, "aria-hidden": true })
|
|
548
|
+
}
|
|
549
|
+
),
|
|
550
|
+
/* @__PURE__ */ jsxs(
|
|
551
|
+
"div",
|
|
552
|
+
{
|
|
553
|
+
style: {
|
|
554
|
+
fontSize: "0.6875rem",
|
|
555
|
+
fontWeight: 500,
|
|
556
|
+
letterSpacing: "0.04em",
|
|
557
|
+
color: errorSurface.dim,
|
|
558
|
+
textTransform: "uppercase",
|
|
559
|
+
paddingRight: "2.5rem"
|
|
560
|
+
},
|
|
561
|
+
children: [
|
|
562
|
+
"AirJam \xB7 runtime error \xB7 ",
|
|
563
|
+
role
|
|
564
|
+
]
|
|
565
|
+
}
|
|
566
|
+
),
|
|
567
|
+
/* @__PURE__ */ jsx(
|
|
568
|
+
"h1",
|
|
569
|
+
{
|
|
570
|
+
style: {
|
|
571
|
+
marginTop: "0.65rem",
|
|
572
|
+
marginBottom: 0,
|
|
573
|
+
fontSize: "1.25rem",
|
|
574
|
+
lineHeight: 1.25,
|
|
575
|
+
fontWeight: 600,
|
|
576
|
+
color: errorSurface.text,
|
|
577
|
+
fontFamily: "ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif"
|
|
578
|
+
},
|
|
579
|
+
children: "Something went wrong"
|
|
580
|
+
}
|
|
581
|
+
),
|
|
582
|
+
/* @__PURE__ */ jsxs(
|
|
583
|
+
"p",
|
|
584
|
+
{
|
|
585
|
+
style: {
|
|
586
|
+
marginTop: "0.45rem",
|
|
587
|
+
marginBottom: 0,
|
|
588
|
+
fontSize: "0.8125rem",
|
|
589
|
+
color: errorSurface.muted,
|
|
590
|
+
lineHeight: 1.45
|
|
591
|
+
},
|
|
592
|
+
children: [
|
|
593
|
+
roleLabel(role),
|
|
594
|
+
" hit an error. Details below."
|
|
595
|
+
]
|
|
596
|
+
}
|
|
597
|
+
),
|
|
598
|
+
/* @__PURE__ */ jsxs(
|
|
599
|
+
"div",
|
|
600
|
+
{
|
|
601
|
+
style: {
|
|
602
|
+
marginTop: "1rem",
|
|
603
|
+
border: `1px solid ${errorSurface.insetBorder}`,
|
|
604
|
+
borderRadius: "0.5rem",
|
|
605
|
+
background: errorSurface.inset,
|
|
606
|
+
padding: "0.75rem 0.85rem",
|
|
607
|
+
fontSize: "0.75rem",
|
|
608
|
+
color: errorSurface.muted,
|
|
609
|
+
fontFamily: mono,
|
|
610
|
+
lineHeight: 1.5,
|
|
611
|
+
wordBreak: "break-word"
|
|
612
|
+
},
|
|
613
|
+
children: [
|
|
614
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
615
|
+
/* @__PURE__ */ jsx("span", { style: { color: errorSurface.dim }, children: "Digest " }),
|
|
616
|
+
digest
|
|
617
|
+
] }),
|
|
618
|
+
roomId ? /* @__PURE__ */ jsxs("div", { style: { marginTop: "0.35rem" }, children: [
|
|
619
|
+
/* @__PURE__ */ jsx("span", { style: { color: errorSurface.dim }, children: "Room " }),
|
|
620
|
+
roomId
|
|
621
|
+
] }) : null,
|
|
622
|
+
/* @__PURE__ */ jsxs("div", { style: { marginTop: "0.35rem" }, children: [
|
|
623
|
+
/* @__PURE__ */ jsx("span", { style: { color: errorSurface.dim }, children: "Error " }),
|
|
624
|
+
error.message || "Unknown error"
|
|
625
|
+
] })
|
|
626
|
+
]
|
|
627
|
+
}
|
|
628
|
+
),
|
|
629
|
+
/* @__PURE__ */ jsxs(
|
|
630
|
+
"details",
|
|
631
|
+
{
|
|
632
|
+
style: {
|
|
633
|
+
marginTop: "0.75rem",
|
|
634
|
+
fontSize: "0.75rem",
|
|
635
|
+
color: errorSurface.muted
|
|
636
|
+
},
|
|
637
|
+
children: [
|
|
638
|
+
/* @__PURE__ */ jsx(
|
|
639
|
+
"summary",
|
|
640
|
+
{
|
|
641
|
+
style: {
|
|
642
|
+
cursor: "pointer",
|
|
643
|
+
fontWeight: 500,
|
|
644
|
+
color: errorSurface.muted,
|
|
645
|
+
listStyle: "none"
|
|
646
|
+
},
|
|
647
|
+
children: "Stack trace"
|
|
648
|
+
}
|
|
649
|
+
),
|
|
650
|
+
/* @__PURE__ */ jsx(
|
|
651
|
+
"pre",
|
|
652
|
+
{
|
|
653
|
+
style: {
|
|
654
|
+
marginTop: "0.5rem",
|
|
655
|
+
marginBottom: 0,
|
|
656
|
+
overflowX: "auto",
|
|
657
|
+
whiteSpace: "pre-wrap",
|
|
658
|
+
wordBreak: "break-word",
|
|
659
|
+
border: `1px solid ${errorSurface.insetBorder}`,
|
|
660
|
+
borderRadius: "0.45rem",
|
|
661
|
+
background: errorSurface.inset,
|
|
662
|
+
padding: "0.65rem 0.75rem",
|
|
663
|
+
color: errorSurface.muted,
|
|
664
|
+
fontFamily: mono,
|
|
665
|
+
fontSize: "0.6875rem",
|
|
666
|
+
lineHeight: 1.45
|
|
667
|
+
},
|
|
668
|
+
children: error.stack ?? error.message
|
|
669
|
+
}
|
|
670
|
+
)
|
|
671
|
+
]
|
|
672
|
+
}
|
|
673
|
+
),
|
|
674
|
+
/* @__PURE__ */ jsxs(
|
|
675
|
+
"div",
|
|
676
|
+
{
|
|
677
|
+
style: {
|
|
678
|
+
marginTop: "1.1rem",
|
|
679
|
+
display: "flex",
|
|
680
|
+
flexWrap: "wrap",
|
|
681
|
+
alignItems: "center",
|
|
682
|
+
gap: "0.45rem"
|
|
683
|
+
},
|
|
684
|
+
children: [
|
|
685
|
+
/* @__PURE__ */ jsxs(
|
|
686
|
+
"button",
|
|
687
|
+
{
|
|
688
|
+
type: "button",
|
|
689
|
+
onClick: reload,
|
|
690
|
+
style: {
|
|
691
|
+
...btnRow,
|
|
692
|
+
border: "none",
|
|
693
|
+
background: errorSurface.text,
|
|
694
|
+
color: errorSurface.bg
|
|
695
|
+
},
|
|
696
|
+
children: [
|
|
697
|
+
/* @__PURE__ */ jsx(RefreshCw, { size: iconSize, strokeWidth: 2, "aria-hidden": true }),
|
|
698
|
+
"Reload"
|
|
699
|
+
]
|
|
700
|
+
}
|
|
701
|
+
),
|
|
702
|
+
/* @__PURE__ */ jsxs(
|
|
703
|
+
"button",
|
|
704
|
+
{
|
|
705
|
+
type: "button",
|
|
706
|
+
onClick: reset,
|
|
707
|
+
style: {
|
|
708
|
+
...btnRow,
|
|
709
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
710
|
+
background: "transparent",
|
|
711
|
+
color: errorSurface.text
|
|
712
|
+
},
|
|
713
|
+
children: [
|
|
714
|
+
/* @__PURE__ */ jsx(RotateCcw, { size: iconSize, strokeWidth: 2, "aria-hidden": true }),
|
|
715
|
+
"Try again"
|
|
716
|
+
]
|
|
717
|
+
}
|
|
718
|
+
),
|
|
719
|
+
/* @__PURE__ */ jsxs(
|
|
720
|
+
"button",
|
|
721
|
+
{
|
|
722
|
+
type: "button",
|
|
723
|
+
onClick: () => {
|
|
724
|
+
void handleCopy();
|
|
725
|
+
},
|
|
726
|
+
style: {
|
|
727
|
+
...btnRow,
|
|
728
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
729
|
+
background: "transparent",
|
|
730
|
+
color: errorSurface.muted
|
|
731
|
+
},
|
|
732
|
+
children: [
|
|
733
|
+
CopyGlyph,
|
|
734
|
+
copyButtonLabel
|
|
735
|
+
]
|
|
736
|
+
}
|
|
737
|
+
)
|
|
738
|
+
]
|
|
739
|
+
}
|
|
740
|
+
),
|
|
741
|
+
isEmbedded ? /* @__PURE__ */ jsx(
|
|
742
|
+
"p",
|
|
743
|
+
{
|
|
744
|
+
style: {
|
|
745
|
+
marginTop: "0.85rem",
|
|
746
|
+
marginBottom: 0,
|
|
747
|
+
fontSize: "0.6875rem",
|
|
748
|
+
color: errorSurface.dim,
|
|
749
|
+
lineHeight: 1.4,
|
|
750
|
+
fontFamily: mono
|
|
751
|
+
},
|
|
752
|
+
children: "Embedded: if reload loops, exit and relaunch from the Arcade shell."
|
|
753
|
+
}
|
|
754
|
+
) : null
|
|
755
|
+
]
|
|
756
|
+
}
|
|
757
|
+
)
|
|
758
|
+
}
|
|
759
|
+
);
|
|
760
|
+
};
|
|
761
|
+
var AirJamErrorBoundary = class extends Component {
|
|
762
|
+
state = {
|
|
763
|
+
error: null
|
|
764
|
+
};
|
|
765
|
+
static getDerivedStateFromError(error) {
|
|
766
|
+
return {
|
|
767
|
+
error: toError(error)
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
componentDidCatch(error, errorInfo) {
|
|
771
|
+
const { role, roomId, appId, onError, reportError } = this.props;
|
|
772
|
+
const details = {
|
|
773
|
+
role,
|
|
774
|
+
roomId,
|
|
775
|
+
appId,
|
|
776
|
+
name: error.name,
|
|
777
|
+
message: error.message,
|
|
778
|
+
stack: error.stack,
|
|
779
|
+
componentStack: errorInfo.componentStack
|
|
780
|
+
};
|
|
781
|
+
emitAirJamDiagnostic({
|
|
782
|
+
code: "AJ_RUNTIME_RENDER_CRASH",
|
|
783
|
+
severity: "error",
|
|
784
|
+
message: `[AirJam] ${role} runtime crashed during render.`,
|
|
785
|
+
details
|
|
786
|
+
});
|
|
787
|
+
emitAirJamDevRuntimeEvent({
|
|
788
|
+
event: AIRJAM_DEV_LOG_EVENTS.browser.runtime,
|
|
789
|
+
level: "error",
|
|
790
|
+
message: `AirJam ${role} runtime crashed during render`,
|
|
791
|
+
role,
|
|
792
|
+
roomId,
|
|
793
|
+
code: "AJ_RUNTIME_RENDER_CRASH",
|
|
794
|
+
data: details
|
|
795
|
+
});
|
|
796
|
+
if (reportError) {
|
|
797
|
+
try {
|
|
798
|
+
reportError({
|
|
799
|
+
contractVersion: AIRJAM_RUNTIME_ERROR_REPORT_CONTRACT_VERSION,
|
|
800
|
+
reportId: createRuntimeReportId(),
|
|
801
|
+
role,
|
|
802
|
+
code: "AJ_RUNTIME_RENDER_CRASH",
|
|
803
|
+
errorName: /^[A-Za-z][A-Za-z0-9._-]{0,79}$/u.test(error.name) ? error.name : "Error",
|
|
804
|
+
digest: createErrorDigest(error),
|
|
805
|
+
occurredAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
806
|
+
});
|
|
807
|
+
} catch {
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
onError?.(error, errorInfo, {
|
|
811
|
+
role,
|
|
812
|
+
roomId,
|
|
813
|
+
appId
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
handleReset = () => {
|
|
817
|
+
this.setState({ error: null });
|
|
818
|
+
};
|
|
819
|
+
handleReload = () => {
|
|
820
|
+
if (typeof window !== "undefined") {
|
|
821
|
+
window.location.reload();
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
render() {
|
|
825
|
+
const { error } = this.state;
|
|
826
|
+
const { children, role, roomId, appId, renderFallback } = this.props;
|
|
827
|
+
if (!error) {
|
|
828
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
829
|
+
}
|
|
830
|
+
const fallbackProps = {
|
|
831
|
+
role,
|
|
832
|
+
roomId,
|
|
833
|
+
appId,
|
|
834
|
+
error,
|
|
835
|
+
reset: this.handleReset,
|
|
836
|
+
reload: this.handleReload,
|
|
837
|
+
isEmbedded: isEmbeddedRuntime()
|
|
838
|
+
};
|
|
839
|
+
if (renderFallback) {
|
|
840
|
+
return renderFallback(fallbackProps);
|
|
841
|
+
}
|
|
842
|
+
return /* @__PURE__ */ jsx(DefaultFallback, { ...fallbackProps });
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
// src/runtime/prefab-inspection-context.ts
|
|
847
|
+
import { createContext, useContext } from "react";
|
|
848
|
+
var prefabInspectionContext = createContext(
|
|
849
|
+
null
|
|
850
|
+
);
|
|
851
|
+
function usePrefabInspection() {
|
|
852
|
+
const value = useContext(prefabInspectionContext);
|
|
853
|
+
if (!value)
|
|
854
|
+
throw new Error(
|
|
855
|
+
"usePrefabInspection requires the host's prefabStage in an inspection document."
|
|
856
|
+
);
|
|
857
|
+
return value;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
// src/runtime/session-runtimes.tsx
|
|
861
|
+
import { useEffect as useEffect7, useMemo as useMemo6, useSyncExternalStore } from "react";
|
|
862
|
+
|
|
863
|
+
// src/context/session-providers.tsx
|
|
864
|
+
import { useCallback as useCallback3, useRef as useRef2 } from "react";
|
|
865
|
+
|
|
866
|
+
// src/components/stage-capture-surface.tsx
|
|
867
|
+
import { useCallback as useCallback2, useState as useState2 } from "react";
|
|
868
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
869
|
+
function StageCaptureSurface({
|
|
870
|
+
children,
|
|
871
|
+
role,
|
|
872
|
+
captureStage = true
|
|
873
|
+
}) {
|
|
874
|
+
const [enabled] = useState2(
|
|
875
|
+
() => captureStage && typeof window !== "undefined" && (role === "host" || readPreviewControllerParent() !== null && new URLSearchParams(window.location.search).get(
|
|
876
|
+
AIR_JAM_PREVIEW_CAPTURE_QUERY_PARAM
|
|
877
|
+
) === "1") && supportsStageCapture()
|
|
878
|
+
);
|
|
879
|
+
const mount = useCallback2((element) => {
|
|
880
|
+
if (!element) return;
|
|
881
|
+
const canvas = element;
|
|
882
|
+
const context = canvas.getContext("2d");
|
|
883
|
+
const root = canvas.firstElementChild;
|
|
884
|
+
if (!context || !root)
|
|
885
|
+
throw new Error("The stage capture surface could not mount.");
|
|
886
|
+
const paint = () => {
|
|
887
|
+
context.reset();
|
|
888
|
+
context.drawElementImage(root, 0, 0, canvas.width, canvas.height);
|
|
889
|
+
};
|
|
890
|
+
const resize = () => {
|
|
891
|
+
canvas.width = Math.max(
|
|
892
|
+
1,
|
|
893
|
+
Math.round(canvas.clientWidth * window.devicePixelRatio)
|
|
894
|
+
);
|
|
895
|
+
canvas.height = Math.max(
|
|
896
|
+
1,
|
|
897
|
+
Math.round(canvas.clientHeight * window.devicePixelRatio)
|
|
898
|
+
);
|
|
899
|
+
canvas.requestPaint();
|
|
900
|
+
};
|
|
901
|
+
canvas.addEventListener("paint", paint);
|
|
902
|
+
const observer = new ResizeObserver(resize);
|
|
903
|
+
observer.observe(canvas);
|
|
904
|
+
resize();
|
|
905
|
+
return () => {
|
|
906
|
+
observer.disconnect();
|
|
907
|
+
canvas.removeEventListener("paint", paint);
|
|
908
|
+
};
|
|
909
|
+
}, []);
|
|
910
|
+
if (!enabled) return children;
|
|
911
|
+
return /* @__PURE__ */ jsx2(
|
|
912
|
+
"canvas",
|
|
913
|
+
{
|
|
914
|
+
...{ content: "drawable", "data-airjam-stage-capture": "" },
|
|
915
|
+
className: "fixed inset-0 block h-dvh w-screen",
|
|
916
|
+
ref: mount,
|
|
917
|
+
children: /* @__PURE__ */ jsx2(
|
|
918
|
+
"div",
|
|
919
|
+
{
|
|
920
|
+
...{ drawable: "" },
|
|
921
|
+
className: "h-dvh w-screen [&_canvas]:[contain:paint]",
|
|
922
|
+
children
|
|
923
|
+
}
|
|
924
|
+
)
|
|
925
|
+
}
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// src/context/session-providers.tsx
|
|
930
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
931
|
+
var createScopedSessionProvider = (scope) => {
|
|
932
|
+
const ScopedSessionProvider = ({
|
|
933
|
+
children,
|
|
934
|
+
captureStage,
|
|
935
|
+
...providerProps
|
|
936
|
+
}) => {
|
|
937
|
+
const runtimeOwnersRef = useRef2(/* @__PURE__ */ new Map());
|
|
938
|
+
const claimOwner = useCallback3(
|
|
939
|
+
(kind, token, hookName) => {
|
|
940
|
+
const existing = runtimeOwnersRef.current.get(kind);
|
|
941
|
+
if (existing && existing.token !== token) {
|
|
942
|
+
throw createAirJamDiagnosticError(
|
|
943
|
+
"AJ_DUPLICATE_SESSION_OWNER",
|
|
944
|
+
`${hookName} mounted while another ${kind} already owns this session provider. Mount one runtime owner hook per provider tree and use useAirJamHost() or useAirJamController() in child components instead.`,
|
|
945
|
+
{
|
|
946
|
+
scope,
|
|
947
|
+
kind,
|
|
948
|
+
hookName,
|
|
949
|
+
existingHookName: existing.hookName
|
|
950
|
+
}
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
runtimeOwnersRef.current.set(kind, { token, hookName });
|
|
954
|
+
return () => {
|
|
955
|
+
const current = runtimeOwnersRef.current.get(kind);
|
|
956
|
+
if (current?.token === token) {
|
|
957
|
+
runtimeOwnersRef.current.delete(kind);
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
},
|
|
961
|
+
[]
|
|
962
|
+
);
|
|
963
|
+
return /* @__PURE__ */ jsx3(SessionScopeContext.Provider, { value: scope, children: /* @__PURE__ */ jsx3(RuntimeOwnerRegistryContext.Provider, { value: { claimOwner }, children: /* @__PURE__ */ jsx3(AirJamProvider, { ...providerProps, surfaceRole: scope, children: /* @__PURE__ */ jsx3(StageCaptureSurface, { role: scope, captureStage, children }) }) }) });
|
|
964
|
+
};
|
|
965
|
+
return ScopedSessionProvider;
|
|
966
|
+
};
|
|
967
|
+
var HostSessionProvider = createScopedSessionProvider("host");
|
|
968
|
+
var ControllerSessionProvider = createScopedSessionProvider("controller");
|
|
969
|
+
|
|
970
|
+
// src/hooks/internal/use-controller-runtime-api.ts
|
|
971
|
+
import { useEffect as useEffect2, useMemo } from "react";
|
|
972
|
+
import { useStore } from "zustand";
|
|
973
|
+
|
|
974
|
+
// src/utils/mode.ts
|
|
975
|
+
var detectRunMode = () => {
|
|
976
|
+
if (typeof window === "undefined") {
|
|
977
|
+
return "standalone";
|
|
978
|
+
}
|
|
979
|
+
try {
|
|
980
|
+
return window.self !== window.top ? "platform" : "standalone";
|
|
981
|
+
} catch {
|
|
982
|
+
return "platform";
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
// src/runtime/browser-room.ts
|
|
987
|
+
var browserRoomConnector = ({
|
|
988
|
+
topology,
|
|
989
|
+
role,
|
|
990
|
+
embedding
|
|
991
|
+
}) => {
|
|
992
|
+
const parent = embedding ? embeddedRuntimeParent(topology) : null;
|
|
993
|
+
if (parent && embedding)
|
|
994
|
+
return requestEmbeddingRoom({ parent, role, context: embedding });
|
|
995
|
+
return createWebSocketConnector(topology.socketOrigin);
|
|
996
|
+
};
|
|
997
|
+
var devLogRuntimeErrorReporter = (report) => emitAirJamDevRuntimeEvent({
|
|
998
|
+
event: AIRJAM_DEV_LOG_EVENTS.runtime.errorReport,
|
|
999
|
+
level: "error",
|
|
1000
|
+
message: `The ${report.role} crashed while rendering (${report.errorName}).`,
|
|
1001
|
+
roomId: report.roomId,
|
|
1002
|
+
...report.seat ? { controllerId: report.seat } : {},
|
|
1003
|
+
data: { ...report }
|
|
1004
|
+
});
|
|
1005
|
+
|
|
1006
|
+
// src/runtime/controller-identity.ts
|
|
1007
|
+
import { z } from "zod";
|
|
1008
|
+
var ROOM_BINDINGS_STORAGE_KEY = "airjam_controller_room_bindings";
|
|
1009
|
+
var bindingsSchema = z.record(
|
|
1010
|
+
z.string(),
|
|
1011
|
+
z.object({
|
|
1012
|
+
key: z.string().min(16),
|
|
1013
|
+
instance: z.string().min(1).optional()
|
|
1014
|
+
})
|
|
1015
|
+
);
|
|
1016
|
+
var localStorageOrNull = () => {
|
|
1017
|
+
if (typeof window === "undefined") return null;
|
|
1018
|
+
try {
|
|
1019
|
+
return window.localStorage;
|
|
1020
|
+
} catch {
|
|
1021
|
+
return null;
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
var readBindings = (storage) => {
|
|
1025
|
+
try {
|
|
1026
|
+
const parsed = bindingsSchema.safeParse(
|
|
1027
|
+
JSON.parse(storage.getItem(ROOM_BINDINGS_STORAGE_KEY) ?? "{}")
|
|
1028
|
+
);
|
|
1029
|
+
return parsed.success ? parsed.data : {};
|
|
1030
|
+
} catch {
|
|
1031
|
+
return {};
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
var createControllerRoomBindings = (scope, storage = localStorageOrNull()) => {
|
|
1035
|
+
const entry = (roomId) => `${scope}:${roomId.toUpperCase()}`;
|
|
1036
|
+
const write = (update) => {
|
|
1037
|
+
if (!storage) return;
|
|
1038
|
+
const bindings = readBindings(storage);
|
|
1039
|
+
update(bindings);
|
|
1040
|
+
try {
|
|
1041
|
+
storage.setItem(ROOM_BINDINGS_STORAGE_KEY, JSON.stringify(bindings));
|
|
1042
|
+
} catch {
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
return {
|
|
1046
|
+
readBinding: (roomId) => storage ? readBindings(storage)[entry(roomId)] ?? null : null,
|
|
1047
|
+
writeBinding: (roomId, binding) => write((bindings) => {
|
|
1048
|
+
bindings[entry(roomId)] = binding;
|
|
1049
|
+
}),
|
|
1050
|
+
clearBinding: (roomId) => write((bindings) => {
|
|
1051
|
+
delete bindings[entry(roomId)];
|
|
1052
|
+
})
|
|
1053
|
+
};
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
// src/runtime/browser-controller-environment.ts
|
|
1057
|
+
var createBrowserControllerEnvironment = (config) => {
|
|
1058
|
+
const params = new URLSearchParams(window.location.search);
|
|
1059
|
+
const embedded = readEmbeddedControllerChildSession();
|
|
1060
|
+
const previewDeviceId = readPreviewControllerDeviceIdFromLocation();
|
|
1061
|
+
const connector = browserRoomConnector({
|
|
1062
|
+
topology: config.topology,
|
|
1063
|
+
role: "controller",
|
|
1064
|
+
embedding: embedded ? controllerBridgeContext(embedded) : null
|
|
1065
|
+
});
|
|
1066
|
+
return {
|
|
1067
|
+
embedded: embedded ? {
|
|
1068
|
+
roomId: embedded.roomId,
|
|
1069
|
+
...embedded.playerProfile ? { playerProfile: embedded.playerProfile } : {}
|
|
1070
|
+
} : null,
|
|
1071
|
+
requestedRoomId: params.get("room")?.toUpperCase() ?? null,
|
|
1072
|
+
seatKind: previewDeviceId ? "preview" : "phone",
|
|
1073
|
+
localSeatLabel: readLocalSeatLabel(),
|
|
1074
|
+
runMode: detectRunMode(),
|
|
1075
|
+
defaultStoreDomain: resolveImplicitReplicatedStoreDomainFromWindow(),
|
|
1076
|
+
presentationChannel: config.presentationChannel,
|
|
1077
|
+
joinRoom: (options) => new PhoneRoomSession({
|
|
1078
|
+
...options,
|
|
1079
|
+
connector,
|
|
1080
|
+
deviceWakeEvents: browserDeviceWakeEvents
|
|
1081
|
+
}),
|
|
1082
|
+
createKey: createRoomKey,
|
|
1083
|
+
...createControllerRoomBindings(previewDeviceId ?? "phone"),
|
|
1084
|
+
vibrate: (pattern) => {
|
|
1085
|
+
if (typeof navigator !== "undefined" && navigator.vibrate)
|
|
1086
|
+
navigator.vibrate(pattern);
|
|
1087
|
+
},
|
|
1088
|
+
requestFrame: (callback) => {
|
|
1089
|
+
requestAnimationFrame(() => callback());
|
|
1090
|
+
},
|
|
1091
|
+
reportError: config.reportError ?? devLogRuntimeErrorReporter,
|
|
1092
|
+
emitDevEvent: emitAirJamDevRuntimeEvent,
|
|
1093
|
+
setDevLogContext: updateDevBrowserLogContext
|
|
1094
|
+
};
|
|
1095
|
+
};
|
|
1096
|
+
var followPreviewParent = (runtime) => {
|
|
1097
|
+
const parent = readPreviewControllerParent();
|
|
1098
|
+
const deviceId = readPreviewControllerDeviceIdFromLocation();
|
|
1099
|
+
if (runtime.isEmbedded || !parent || !deviceId) return () => {
|
|
1100
|
+
};
|
|
1101
|
+
let reported;
|
|
1102
|
+
const reportSeat = () => {
|
|
1103
|
+
const seat = runtime.store.getState().controllerId;
|
|
1104
|
+
if (seat === reported) return;
|
|
1105
|
+
reported = seat;
|
|
1106
|
+
parent.window.postMessage(
|
|
1107
|
+
{ type: AIR_JAM_PREVIEW_SEAT, deviceId, seat },
|
|
1108
|
+
parent.origin
|
|
1109
|
+
);
|
|
1110
|
+
};
|
|
1111
|
+
reportSeat();
|
|
1112
|
+
const stopReporting = runtime.store.subscribe(reportSeat);
|
|
1113
|
+
const handleMessage = (event) => {
|
|
1114
|
+
if (event.source !== parent.window || event.origin !== parent.origin)
|
|
1115
|
+
return;
|
|
1116
|
+
if (!isPreviewCloseRequestMessage(event.data)) return;
|
|
1117
|
+
void runtime.leave().then(
|
|
1118
|
+
(ack) => parent.window.postMessage(
|
|
1119
|
+
{ type: AIR_JAM_PREVIEW_CLOSE_RESULT, ok: ack.ok },
|
|
1120
|
+
parent.origin
|
|
1121
|
+
)
|
|
1122
|
+
);
|
|
1123
|
+
};
|
|
1124
|
+
window.addEventListener("message", handleMessage);
|
|
1125
|
+
return () => {
|
|
1126
|
+
stopReporting();
|
|
1127
|
+
window.removeEventListener("message", handleMessage);
|
|
1128
|
+
};
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
// src/hooks/internal/use-controller-runtime-api.ts
|
|
1132
|
+
var useControllerRuntimeApi = (options, hookName, stores, input) => {
|
|
1133
|
+
useAssertSessionScope("controller", hookName);
|
|
1134
|
+
useClaimSessionRuntimeOwner("controller-runtime", hookName);
|
|
1135
|
+
const { config, store } = useAirJamContext();
|
|
1136
|
+
const { roomId } = options;
|
|
1137
|
+
const runtime = useMemo(
|
|
1138
|
+
() => new ControllerRuntime(
|
|
1139
|
+
{
|
|
1140
|
+
store,
|
|
1141
|
+
environment: createBrowserControllerEnvironment(config),
|
|
1142
|
+
stores,
|
|
1143
|
+
input
|
|
1144
|
+
},
|
|
1145
|
+
{ roomId }
|
|
1146
|
+
),
|
|
1147
|
+
[config, store, stores, input, roomId]
|
|
1148
|
+
);
|
|
1149
|
+
useEffect2(
|
|
1150
|
+
() => runtime.setNickname(options.nickname ?? ""),
|
|
1151
|
+
[runtime, options.nickname]
|
|
1152
|
+
);
|
|
1153
|
+
useEffect2(
|
|
1154
|
+
() => runtime.setAvatarId(options.avatarId ?? ""),
|
|
1155
|
+
[runtime, options.avatarId]
|
|
1156
|
+
);
|
|
1157
|
+
useEffect2(() => runtime.start(), [runtime]);
|
|
1158
|
+
useEffect2(() => publishEmbeddedControllerAgent(runtime), [runtime]);
|
|
1159
|
+
useEffect2(() => {
|
|
1160
|
+
const controls = runtime.input;
|
|
1161
|
+
if (!controls) return;
|
|
1162
|
+
const release = () => controls.releaseAll();
|
|
1163
|
+
const releaseWhenHidden = () => {
|
|
1164
|
+
if (document.hidden) release();
|
|
1165
|
+
};
|
|
1166
|
+
window.addEventListener("blur", release);
|
|
1167
|
+
document.addEventListener("visibilitychange", releaseWhenHidden);
|
|
1168
|
+
return () => {
|
|
1169
|
+
window.removeEventListener("blur", release);
|
|
1170
|
+
document.removeEventListener("visibilitychange", releaseWhenHidden);
|
|
1171
|
+
};
|
|
1172
|
+
}, [runtime]);
|
|
1173
|
+
useEffect2(() => followPreviewParent(runtime), [runtime]);
|
|
1174
|
+
useEffect2(() => listenForLocalSeatInput(runtime.input), [runtime]);
|
|
1175
|
+
const session = useStore(store, () => runtime.session);
|
|
1176
|
+
return useMemo(
|
|
1177
|
+
() => ({
|
|
1178
|
+
sendSystemCommand: runtime.sendSystemCommand,
|
|
1179
|
+
setNickname: runtime.setNickname,
|
|
1180
|
+
setAvatarId: runtime.setAvatarId,
|
|
1181
|
+
updatePlayerProfile: runtime.updatePlayerProfile,
|
|
1182
|
+
leave: runtime.leave,
|
|
1183
|
+
session,
|
|
1184
|
+
input: runtime.input
|
|
1185
|
+
}),
|
|
1186
|
+
[runtime, session]
|
|
1187
|
+
);
|
|
1188
|
+
};
|
|
1189
|
+
|
|
1190
|
+
// src/hooks/internal/use-host-runtime-api.ts
|
|
1191
|
+
import { useEffect as useEffect3, useMemo as useMemo2, useState as useState3 } from "react";
|
|
1192
|
+
import { useStore as useStore2 } from "zustand";
|
|
1193
|
+
|
|
1194
|
+
// src/runtime/browser-host-environment.ts
|
|
1195
|
+
import { z as z2 } from "zod";
|
|
1196
|
+
|
|
1197
|
+
// src/utils/network-ip.ts
|
|
1198
|
+
var isVirtualNetwork = (ip) => {
|
|
1199
|
+
if (ip.startsWith("192.168.64.") || ip.startsWith("192.168.65.")) {
|
|
1200
|
+
return true;
|
|
1201
|
+
}
|
|
1202
|
+
if (ip.startsWith("172.17.")) {
|
|
1203
|
+
return true;
|
|
1204
|
+
}
|
|
1205
|
+
if (ip.startsWith("172.18.") || ip.startsWith("172.19.")) {
|
|
1206
|
+
return true;
|
|
1207
|
+
}
|
|
1208
|
+
if (ip.startsWith("169.254.")) {
|
|
1209
|
+
return true;
|
|
1210
|
+
}
|
|
1211
|
+
return false;
|
|
1212
|
+
};
|
|
1213
|
+
var scoreIp = (ip) => {
|
|
1214
|
+
if (ip.startsWith("192.168.")) {
|
|
1215
|
+
const parts = ip.split(".");
|
|
1216
|
+
const thirdOctet = parseInt(parts[2] || "0", 10);
|
|
1217
|
+
if (thirdOctet < 64) {
|
|
1218
|
+
return 100 - thirdOctet;
|
|
1219
|
+
}
|
|
1220
|
+
return 10;
|
|
1221
|
+
}
|
|
1222
|
+
if (ip.startsWith("10.")) {
|
|
1223
|
+
return 50;
|
|
1224
|
+
}
|
|
1225
|
+
if (/^172\.(1[6-9]|2[0-9]|3[01])\./.test(ip)) {
|
|
1226
|
+
return 30;
|
|
1227
|
+
}
|
|
1228
|
+
return 0;
|
|
1229
|
+
};
|
|
1230
|
+
var getLocalNetworkIp = () => {
|
|
1231
|
+
return new Promise((resolve) => {
|
|
1232
|
+
if (typeof window === "undefined" || typeof RTCPeerConnection === "undefined") {
|
|
1233
|
+
resolve(null);
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1236
|
+
const pc = new RTCPeerConnection({
|
|
1237
|
+
iceServers: [{ urls: "stun:stun.l.google.com:19302" }]
|
|
1238
|
+
});
|
|
1239
|
+
const candidates = [];
|
|
1240
|
+
let candidateGatheringComplete = false;
|
|
1241
|
+
const resolveOnce = (ip) => {
|
|
1242
|
+
pc.close();
|
|
1243
|
+
resolve(ip);
|
|
1244
|
+
};
|
|
1245
|
+
const timeout = setTimeout(() => {
|
|
1246
|
+
if (candidateGatheringComplete) {
|
|
1247
|
+
pickBestCandidate();
|
|
1248
|
+
} else {
|
|
1249
|
+
setTimeout(() => {
|
|
1250
|
+
pickBestCandidate();
|
|
1251
|
+
}, 500);
|
|
1252
|
+
}
|
|
1253
|
+
}, 3e3);
|
|
1254
|
+
const pickBestCandidate = () => {
|
|
1255
|
+
if (candidates.length === 0) {
|
|
1256
|
+
resolveOnce(null);
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
candidates.sort((a, b) => b.score - a.score);
|
|
1260
|
+
const best = candidates[0];
|
|
1261
|
+
clearTimeout(timeout);
|
|
1262
|
+
resolveOnce(best.ip);
|
|
1263
|
+
};
|
|
1264
|
+
pc.onicecandidate = (event) => {
|
|
1265
|
+
if (event.candidate) {
|
|
1266
|
+
const candidate = event.candidate.candidate;
|
|
1267
|
+
const match = candidate.match(/([0-9]{1,3}(\.[0-9]{1,3}){3})/);
|
|
1268
|
+
if (match) {
|
|
1269
|
+
const ip = match[1];
|
|
1270
|
+
if (ip === "127.0.0.1") {
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
const isPrivate = ip.startsWith("192.168.") || ip.startsWith("10.") || /^172\.(1[6-9]|2[0-9]|3[01])\./.test(ip);
|
|
1274
|
+
if (isPrivate && !isVirtualNetwork(ip)) {
|
|
1275
|
+
const score = scoreIp(ip);
|
|
1276
|
+
candidates.push({ ip, score });
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
} else {
|
|
1280
|
+
candidateGatheringComplete = true;
|
|
1281
|
+
setTimeout(() => {
|
|
1282
|
+
pickBestCandidate();
|
|
1283
|
+
}, 200);
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
pc.createDataChannel("");
|
|
1287
|
+
pc.createOffer().then((offer) => pc.setLocalDescription(offer)).catch(() => {
|
|
1288
|
+
clearTimeout(timeout);
|
|
1289
|
+
resolveOnce(null);
|
|
1290
|
+
});
|
|
1291
|
+
});
|
|
1292
|
+
};
|
|
1293
|
+
|
|
1294
|
+
// src/utils/url-builder.ts
|
|
1295
|
+
var UrlBuilder = class {
|
|
1296
|
+
cachedLocalIp = null;
|
|
1297
|
+
ipDetectionPromise = null;
|
|
1298
|
+
/**
|
|
1299
|
+
* Get the local network IP address with caching.
|
|
1300
|
+
* First call triggers detection, subsequent calls return cached value.
|
|
1301
|
+
*/
|
|
1302
|
+
async getLocalIp() {
|
|
1303
|
+
if (this.cachedLocalIp !== null) {
|
|
1304
|
+
return this.cachedLocalIp;
|
|
1305
|
+
}
|
|
1306
|
+
if (this.ipDetectionPromise !== null) {
|
|
1307
|
+
return this.ipDetectionPromise;
|
|
1308
|
+
}
|
|
1309
|
+
this.ipDetectionPromise = getLocalNetworkIp().then((ip) => {
|
|
1310
|
+
this.cachedLocalIp = ip;
|
|
1311
|
+
this.ipDetectionPromise = null;
|
|
1312
|
+
return ip;
|
|
1313
|
+
});
|
|
1314
|
+
return this.ipDetectionPromise;
|
|
1315
|
+
}
|
|
1316
|
+
/**
|
|
1317
|
+
* Clear the cached IP address.
|
|
1318
|
+
* Useful for testing or when network changes are detected.
|
|
1319
|
+
*/
|
|
1320
|
+
clearCache() {
|
|
1321
|
+
this.cachedLocalIp = null;
|
|
1322
|
+
this.ipDetectionPromise = null;
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Normalize a URL for mobile access.
|
|
1326
|
+
* Replaces localhost with the local network IP.
|
|
1327
|
+
*/
|
|
1328
|
+
async normalizeForMobile(url) {
|
|
1329
|
+
if (typeof window === "undefined") return url;
|
|
1330
|
+
try {
|
|
1331
|
+
const urlObj = new URL(url);
|
|
1332
|
+
if (urlObj.hostname === "localhost" || urlObj.hostname === "127.0.0.1") {
|
|
1333
|
+
const localIp = await this.getLocalIp();
|
|
1334
|
+
if (localIp) {
|
|
1335
|
+
urlObj.hostname = localIp;
|
|
1336
|
+
return urlObj.toString();
|
|
1337
|
+
}
|
|
1338
|
+
urlObj.hostname = window.location.hostname;
|
|
1339
|
+
return urlObj.toString();
|
|
1340
|
+
}
|
|
1341
|
+
return url;
|
|
1342
|
+
} catch {
|
|
1343
|
+
return url;
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Build a controller URL with room code.
|
|
1348
|
+
* Controller is always at {baseUrl}/controller (standardized convention).
|
|
1349
|
+
* Automatically uses local IP when running on localhost.
|
|
1350
|
+
*/
|
|
1351
|
+
async buildControllerUrl(roomId, options) {
|
|
1352
|
+
const path = CONTROLLER_PATH;
|
|
1353
|
+
if (options?.host) {
|
|
1354
|
+
const url2 = new URL(path, this.normalizeOrigin(options.host));
|
|
1355
|
+
url2.searchParams.set("room", roomId);
|
|
1356
|
+
return url2.toString();
|
|
1357
|
+
}
|
|
1358
|
+
let base;
|
|
1359
|
+
if (typeof window === "undefined") {
|
|
1360
|
+
base = `http://localhost:${DEFAULT_SERVER_PORT}`;
|
|
1361
|
+
} else {
|
|
1362
|
+
const currentUrl = new URL(window.location.href);
|
|
1363
|
+
if (!this.isLocalhost(currentUrl.hostname)) {
|
|
1364
|
+
base = currentUrl.origin;
|
|
1365
|
+
} else {
|
|
1366
|
+
const localIp = await this.getLocalIp();
|
|
1367
|
+
if (localIp) {
|
|
1368
|
+
const port = currentUrl.port;
|
|
1369
|
+
base = port ? `http://${localIp}:${port}` : `http://${localIp}`;
|
|
1370
|
+
} else {
|
|
1371
|
+
base = currentUrl.origin;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
const url = new URL(path, base);
|
|
1376
|
+
url.searchParams.set("room", roomId);
|
|
1377
|
+
return url.toString();
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Resolve the server URL.
|
|
1381
|
+
* Uses explicit URL if provided, otherwise infers from window location.
|
|
1382
|
+
*/
|
|
1383
|
+
resolveServerUrl(explicit) {
|
|
1384
|
+
if (explicit) {
|
|
1385
|
+
return this.normalizeOrigin(explicit);
|
|
1386
|
+
}
|
|
1387
|
+
if (typeof window !== "undefined") {
|
|
1388
|
+
const url = new URL(window.location.href);
|
|
1389
|
+
url.port = String(DEFAULT_SERVER_PORT);
|
|
1390
|
+
return url.origin;
|
|
1391
|
+
}
|
|
1392
|
+
return `http://localhost:${DEFAULT_SERVER_PORT}`;
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Check if a hostname is localhost.
|
|
1396
|
+
*/
|
|
1397
|
+
isLocalhost(hostname) {
|
|
1398
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Normalize an origin string to ensure it has a protocol.
|
|
1402
|
+
*/
|
|
1403
|
+
normalizeOrigin(origin) {
|
|
1404
|
+
if (!origin.includes("://")) {
|
|
1405
|
+
return `http://${origin}`;
|
|
1406
|
+
}
|
|
1407
|
+
return origin;
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
var urlBuilder = new UrlBuilder();
|
|
1411
|
+
|
|
1412
|
+
// src/runtime/browser-host-environment.ts
|
|
1413
|
+
var HOST_RESUME_STORAGE_KEY = "airjam_host_room";
|
|
1414
|
+
var hostResumeSchema = z2.object({
|
|
1415
|
+
key: z2.string().min(16),
|
|
1416
|
+
code: roomCodeSchema,
|
|
1417
|
+
instance: z2.string().min(1)
|
|
1418
|
+
});
|
|
1419
|
+
var hostGrantResponseSchema = z2.object({ hostGrant: z2.string().min(1) });
|
|
1420
|
+
var readRequestedRoomId = () => {
|
|
1421
|
+
const room = new URLSearchParams(window.location.search).get("room");
|
|
1422
|
+
if (!room) return null;
|
|
1423
|
+
const parsed = roomCodeSchema.safeParse(room.toUpperCase());
|
|
1424
|
+
return parsed.success ? parsed.data : null;
|
|
1425
|
+
};
|
|
1426
|
+
var createBrowserHostEnvironment = (config) => {
|
|
1427
|
+
const embedded = readEmbeddedHostChildSession();
|
|
1428
|
+
const connector = browserRoomConnector({
|
|
1429
|
+
topology: config.topology,
|
|
1430
|
+
role: "host",
|
|
1431
|
+
embedding: embedded ? { arcadeSurface: embedded.arcadeSurface } : null
|
|
1432
|
+
});
|
|
1433
|
+
return {
|
|
1434
|
+
embedded: embedded ? { joinUrl: embedded.joinUrl } : null,
|
|
1435
|
+
requestedRoomId: readRequestedRoomId(),
|
|
1436
|
+
runMode: detectRunMode(),
|
|
1437
|
+
defaultStoreDomain: resolveImplicitReplicatedStoreDomainFromWindow(),
|
|
1438
|
+
presentationChannel: config.presentationChannel,
|
|
1439
|
+
controlTarget: window,
|
|
1440
|
+
openRoom: (roomOptions) => new HostRoomSession({
|
|
1441
|
+
...roomOptions,
|
|
1442
|
+
connector,
|
|
1443
|
+
deviceWakeEvents: browserDeviceWakeEvents
|
|
1444
|
+
}),
|
|
1445
|
+
createKey: createRoomKey,
|
|
1446
|
+
// An embedded host's place belongs to the page that embeds it.
|
|
1447
|
+
readResume: () => {
|
|
1448
|
+
if (embedded) return null;
|
|
1449
|
+
try {
|
|
1450
|
+
const parsed = hostResumeSchema.safeParse(
|
|
1451
|
+
JSON.parse(sessionStorage.getItem(HOST_RESUME_STORAGE_KEY) ?? "null")
|
|
1452
|
+
);
|
|
1453
|
+
return parsed.success ? parsed.data : null;
|
|
1454
|
+
} catch {
|
|
1455
|
+
return null;
|
|
1456
|
+
}
|
|
1457
|
+
},
|
|
1458
|
+
writeResume: (resume) => {
|
|
1459
|
+
if (embedded) return;
|
|
1460
|
+
try {
|
|
1461
|
+
if (resume)
|
|
1462
|
+
sessionStorage.setItem(
|
|
1463
|
+
HOST_RESUME_STORAGE_KEY,
|
|
1464
|
+
JSON.stringify(resume)
|
|
1465
|
+
);
|
|
1466
|
+
else sessionStorage.removeItem(HOST_RESUME_STORAGE_KEY);
|
|
1467
|
+
} catch {
|
|
1468
|
+
}
|
|
1469
|
+
},
|
|
1470
|
+
requestHostGrant: async (endpoint, appId) => {
|
|
1471
|
+
const response = await fetch(endpoint, {
|
|
1472
|
+
method: "POST",
|
|
1473
|
+
headers: { "content-type": "application/json" },
|
|
1474
|
+
body: JSON.stringify(appId ? { appId } : {})
|
|
1475
|
+
});
|
|
1476
|
+
if (!response.ok)
|
|
1477
|
+
throw new Error(`Failed to fetch host grant (${response.status})`);
|
|
1478
|
+
const parsed = hostGrantResponseSchema.safeParse(await response.json());
|
|
1479
|
+
if (!parsed.success) throw new Error("Invalid host grant response");
|
|
1480
|
+
return parsed.data.hostGrant;
|
|
1481
|
+
},
|
|
1482
|
+
controllerUrl: async (roomId) => {
|
|
1483
|
+
const url = new URL(
|
|
1484
|
+
await urlBuilder.buildControllerUrl(roomId, {
|
|
1485
|
+
host: config.topology.publicHost
|
|
1486
|
+
})
|
|
1487
|
+
);
|
|
1488
|
+
if (config.topology.runtimeMode === "standalone-dev" || config.topology.runtimeMode === "standalone-secure")
|
|
1489
|
+
for (const [key, value] of Object.entries(
|
|
1490
|
+
runtimeTopologyToQueryParams({
|
|
1491
|
+
...config.topology,
|
|
1492
|
+
surfaceRole: "controller",
|
|
1493
|
+
embedded: false,
|
|
1494
|
+
embedParentOrigin: void 0
|
|
1495
|
+
})
|
|
1496
|
+
))
|
|
1497
|
+
url.searchParams.set(key, value);
|
|
1498
|
+
return url.toString();
|
|
1499
|
+
},
|
|
1500
|
+
reportError: config.reportError ?? devLogRuntimeErrorReporter,
|
|
1501
|
+
emitDevEvent: emitAirJamDevRuntimeEvent,
|
|
1502
|
+
setDevLogContext: updateDevBrowserLogContext,
|
|
1503
|
+
seed: () => crypto.getRandomValues(new Uint32Array(1))[0],
|
|
1504
|
+
now: () => performance.now(),
|
|
1505
|
+
frames: (onFrame) => {
|
|
1506
|
+
let stopped = false;
|
|
1507
|
+
let frame = requestAnimationFrame(function next(now) {
|
|
1508
|
+
onFrame(now);
|
|
1509
|
+
if (!stopped) frame = requestAnimationFrame(next);
|
|
1510
|
+
});
|
|
1511
|
+
return () => {
|
|
1512
|
+
stopped = true;
|
|
1513
|
+
cancelAnimationFrame(frame);
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
// src/hooks/internal/use-host-runtime-api.ts
|
|
1520
|
+
var useHostRuntimeApi = (options, hookName, {
|
|
1521
|
+
stores,
|
|
1522
|
+
simulation,
|
|
1523
|
+
agent,
|
|
1524
|
+
input,
|
|
1525
|
+
settings,
|
|
1526
|
+
fixedControllerOrientation
|
|
1527
|
+
}) => {
|
|
1528
|
+
useAssertSessionScope("host", hookName);
|
|
1529
|
+
useClaimSessionRuntimeOwner("host-runtime", hookName);
|
|
1530
|
+
const { config, store } = useAirJamContext();
|
|
1531
|
+
const runtime = useMemo2(
|
|
1532
|
+
() => new HostRuntime(
|
|
1533
|
+
{
|
|
1534
|
+
fixedControllerOrientation,
|
|
1535
|
+
config,
|
|
1536
|
+
store,
|
|
1537
|
+
input,
|
|
1538
|
+
environment: createBrowserHostEnvironment(config),
|
|
1539
|
+
stores,
|
|
1540
|
+
settings,
|
|
1541
|
+
simulation,
|
|
1542
|
+
agent
|
|
1543
|
+
},
|
|
1544
|
+
{
|
|
1545
|
+
settings: airJamSettingsValuesSchema.parse(
|
|
1546
|
+
JSON.parse(
|
|
1547
|
+
new URLSearchParams(window.location.search).get(
|
|
1548
|
+
"airjamSettings"
|
|
1549
|
+
) ?? "{}"
|
|
1550
|
+
)
|
|
1551
|
+
)
|
|
1552
|
+
}
|
|
1553
|
+
),
|
|
1554
|
+
[
|
|
1555
|
+
config,
|
|
1556
|
+
store,
|
|
1557
|
+
input,
|
|
1558
|
+
stores,
|
|
1559
|
+
settings,
|
|
1560
|
+
simulation,
|
|
1561
|
+
agent,
|
|
1562
|
+
fixedControllerOrientation
|
|
1563
|
+
]
|
|
1564
|
+
);
|
|
1565
|
+
useEffect3(() => {
|
|
1566
|
+
runtime.setOptions({
|
|
1567
|
+
roomId: options.roomId,
|
|
1568
|
+
onPlayerJoin: options.onPlayerJoin,
|
|
1569
|
+
onPlayerLeave: options.onPlayerLeave
|
|
1570
|
+
});
|
|
1571
|
+
}, [runtime, options.roomId, options.onPlayerJoin, options.onPlayerLeave]);
|
|
1572
|
+
useEffect3(() => runtime.start(), [runtime]);
|
|
1573
|
+
const [, setLoaded] = useState3(null);
|
|
1574
|
+
const [loadError, setLoadError] = useState3(null);
|
|
1575
|
+
useEffect3(() => {
|
|
1576
|
+
let current = true;
|
|
1577
|
+
runtime.ready.then(
|
|
1578
|
+
() => current && setLoaded(runtime),
|
|
1579
|
+
(error) => current && setLoadError(error)
|
|
1580
|
+
);
|
|
1581
|
+
return () => {
|
|
1582
|
+
current = false;
|
|
1583
|
+
};
|
|
1584
|
+
}, [runtime]);
|
|
1585
|
+
if (loadError) throw loadError;
|
|
1586
|
+
const clock = runtime.simulation;
|
|
1587
|
+
const roomId = useStore2(store, () => runtime.roomId);
|
|
1588
|
+
const room = useStore2(store, () => runtime.room);
|
|
1589
|
+
const joinUrl = useStore2(store, (state) => state.joinUrl);
|
|
1590
|
+
const joinUrlStatus = useStore2(store, (state) => state.joinUrlStatus);
|
|
1591
|
+
return useMemo2(
|
|
1592
|
+
() => ({
|
|
1593
|
+
roomId: roomId ?? "",
|
|
1594
|
+
joinUrl,
|
|
1595
|
+
joinUrlStatus,
|
|
1596
|
+
pauseRuntime: runtime.pauseRuntime,
|
|
1597
|
+
resumeRuntime: runtime.resumeRuntime,
|
|
1598
|
+
setRuntimeState: runtime.setRuntimeState,
|
|
1599
|
+
sendSignal: runtime.sendSignal,
|
|
1600
|
+
removeController: runtime.removeController,
|
|
1601
|
+
resetRoom: runtime.resetRoom,
|
|
1602
|
+
room,
|
|
1603
|
+
simulation: clock,
|
|
1604
|
+
setObservationCapture: runtime.setObservationCapture,
|
|
1605
|
+
playSoundOnControllers: runtime.playSoundOnControllers,
|
|
1606
|
+
settings: runtime.settings
|
|
1607
|
+
}),
|
|
1608
|
+
[runtime, roomId, room, joinUrl, joinUrlStatus, clock]
|
|
1609
|
+
);
|
|
1610
|
+
};
|
|
1611
|
+
|
|
1612
|
+
// src/hooks/internal/use-runtime-inspection-contract.ts
|
|
1613
|
+
import { useStore as useStore3 } from "zustand";
|
|
1614
|
+
var useHostRuntimeInspectionContract = () => {
|
|
1615
|
+
const api = useAirJamHost();
|
|
1616
|
+
const { store } = useAirJamContext();
|
|
1617
|
+
const controllerOrientation = useStore3(
|
|
1618
|
+
store,
|
|
1619
|
+
(state) => state.controllerOrientation
|
|
1620
|
+
);
|
|
1621
|
+
return createHostRuntimeInspectionContract({
|
|
1622
|
+
...api,
|
|
1623
|
+
controllerOrientation
|
|
1624
|
+
});
|
|
1625
|
+
};
|
|
1626
|
+
var useControllerRuntimeInspectionContract = () => createControllerRuntimeInspectionContract(useAirJamController());
|
|
1627
|
+
|
|
1628
|
+
// src/runtime/host-capture-boundary.tsx
|
|
1629
|
+
import {
|
|
1630
|
+
useEffect as useEffect4,
|
|
1631
|
+
useLayoutEffect,
|
|
1632
|
+
useMemo as useMemo3,
|
|
1633
|
+
useRef as useRef3
|
|
1634
|
+
} from "react";
|
|
1635
|
+
|
|
1636
|
+
// src/agent/host-canvas-capture.ts
|
|
1637
|
+
function createHostCanvasCapture(draw) {
|
|
1638
|
+
const canvas = document.createElement("canvas");
|
|
1639
|
+
let active;
|
|
1640
|
+
const capture = ({ maxEdge, quality }) => {
|
|
1641
|
+
if (active) throw new Error("clip_busy: The capture canvas is recording.");
|
|
1642
|
+
return draw(canvas, { maxEdge }) ? encodeAgentCanvas(canvas, quality) : null;
|
|
1643
|
+
};
|
|
1644
|
+
capture.startVideo = (intervalMs) => {
|
|
1645
|
+
if (active) throw new Error("clip_busy: The capture canvas is recording.");
|
|
1646
|
+
if (typeof MediaRecorder === "undefined" || !canvas.captureStream)
|
|
1647
|
+
throw new Error(
|
|
1648
|
+
"clip_unsupported: Native canvas recording is unavailable."
|
|
1649
|
+
);
|
|
1650
|
+
if (!draw(canvas, { maxEdge: CLIP_FRAME_MAX_EDGE }))
|
|
1651
|
+
throw new Error(
|
|
1652
|
+
"clip_surface_unavailable: The game has no render surface."
|
|
1653
|
+
);
|
|
1654
|
+
const mimeType = "video/webm;codecs=vp9";
|
|
1655
|
+
if (!MediaRecorder.isTypeSupported(mimeType))
|
|
1656
|
+
throw new Error(
|
|
1657
|
+
"clip_unsupported: The browser has no VP9 media recorder."
|
|
1658
|
+
);
|
|
1659
|
+
const width = canvas.width;
|
|
1660
|
+
const height = canvas.height;
|
|
1661
|
+
const stream = canvas.captureStream(Math.min(30, 1e3 / intervalMs));
|
|
1662
|
+
let recorder;
|
|
1663
|
+
try {
|
|
1664
|
+
recorder = new MediaRecorder(stream, {
|
|
1665
|
+
mimeType,
|
|
1666
|
+
videoBitsPerSecond: 4e6
|
|
1667
|
+
});
|
|
1668
|
+
} catch (error) {
|
|
1669
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
1670
|
+
throw error;
|
|
1671
|
+
}
|
|
1672
|
+
const blobs = [];
|
|
1673
|
+
let disposed = false;
|
|
1674
|
+
let bytes = 0;
|
|
1675
|
+
let data;
|
|
1676
|
+
let failure;
|
|
1677
|
+
let started = false;
|
|
1678
|
+
let drawsAttempted = 1;
|
|
1679
|
+
let drawsMade = 1;
|
|
1680
|
+
const drawIntervalMs = Math.max(intervalMs, 1e3 / 30);
|
|
1681
|
+
let nextAt = performance.now();
|
|
1682
|
+
let resolveStopped;
|
|
1683
|
+
const stopped = new Promise((resolve) => {
|
|
1684
|
+
resolveStopped = resolve;
|
|
1685
|
+
});
|
|
1686
|
+
const release = () => {
|
|
1687
|
+
clearTimeout(timer);
|
|
1688
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
1689
|
+
if (active === binding) active = void 0;
|
|
1690
|
+
};
|
|
1691
|
+
const stop = () => {
|
|
1692
|
+
if (!started) {
|
|
1693
|
+
release();
|
|
1694
|
+
resolveStopped();
|
|
1695
|
+
} else if (recorder.state !== "inactive") recorder.stop();
|
|
1696
|
+
};
|
|
1697
|
+
const binding = {
|
|
1698
|
+
render() {
|
|
1699
|
+
const now = performance.now();
|
|
1700
|
+
if (now < nextAt || started && recorder.state !== "recording") return;
|
|
1701
|
+
nextAt += (Math.floor((now - nextAt) / drawIntervalMs) + 1) * drawIntervalMs;
|
|
1702
|
+
drawsAttempted++;
|
|
1703
|
+
try {
|
|
1704
|
+
if (!draw(canvas, { maxEdge: CLIP_FRAME_MAX_EDGE }))
|
|
1705
|
+
throw new Error(
|
|
1706
|
+
"clip_surface_unavailable: The game stopped drawing."
|
|
1707
|
+
);
|
|
1708
|
+
if (canvas.width !== width || canvas.height !== height)
|
|
1709
|
+
throw new Error(
|
|
1710
|
+
"clip_capture_failed: The capture dimensions changed."
|
|
1711
|
+
);
|
|
1712
|
+
drawsMade++;
|
|
1713
|
+
if (!started) {
|
|
1714
|
+
recorder.start(1e3);
|
|
1715
|
+
started = true;
|
|
1716
|
+
}
|
|
1717
|
+
} catch (error) {
|
|
1718
|
+
failure = error instanceof Error ? error : new Error(String(error));
|
|
1719
|
+
stop();
|
|
1720
|
+
}
|
|
1721
|
+
},
|
|
1722
|
+
dispose() {
|
|
1723
|
+
disposed = true;
|
|
1724
|
+
stop();
|
|
1725
|
+
release();
|
|
1726
|
+
blobs.length = 0;
|
|
1727
|
+
data = void 0;
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
recorder.ondataavailable = (event) => {
|
|
1731
|
+
if (disposed) return;
|
|
1732
|
+
bytes += event.data.size;
|
|
1733
|
+
if (bytes > CLIP_VIDEO_MAX_BYTES) {
|
|
1734
|
+
failure = new Error(
|
|
1735
|
+
"clip_capture_failed: Native recording exceeds its byte budget."
|
|
1736
|
+
);
|
|
1737
|
+
stop();
|
|
1738
|
+
} else blobs.push(event.data);
|
|
1739
|
+
};
|
|
1740
|
+
recorder.onerror = () => {
|
|
1741
|
+
failure = new Error(
|
|
1742
|
+
"clip_capture_failed: Native media recording failed."
|
|
1743
|
+
);
|
|
1744
|
+
stop();
|
|
1745
|
+
};
|
|
1746
|
+
recorder.onstop = () => {
|
|
1747
|
+
release();
|
|
1748
|
+
resolveStopped();
|
|
1749
|
+
};
|
|
1750
|
+
const timer = setTimeout(() => {
|
|
1751
|
+
failure = new Error(
|
|
1752
|
+
"clip_capture_failed: Native recording exceeded 60 seconds."
|
|
1753
|
+
);
|
|
1754
|
+
stop();
|
|
1755
|
+
}, CLIP_VIDEO_MAX_DURATION_MS + 2e3);
|
|
1756
|
+
active = binding;
|
|
1757
|
+
let finalizing;
|
|
1758
|
+
return {
|
|
1759
|
+
stop() {
|
|
1760
|
+
finalizing ??= (async () => {
|
|
1761
|
+
stop();
|
|
1762
|
+
await stopped;
|
|
1763
|
+
if (failure) throw failure;
|
|
1764
|
+
if (disposed)
|
|
1765
|
+
throw new Error("clip_not_found: Recording was released.");
|
|
1766
|
+
data = new Uint8Array(
|
|
1767
|
+
await new Blob(blobs, { type: mimeType }).arrayBuffer()
|
|
1768
|
+
);
|
|
1769
|
+
blobs.length = 0;
|
|
1770
|
+
if (!data.length)
|
|
1771
|
+
throw new Error("clip_capture_failed: Native recording is empty.");
|
|
1772
|
+
})();
|
|
1773
|
+
return finalizing;
|
|
1774
|
+
},
|
|
1775
|
+
page(fromChunk) {
|
|
1776
|
+
if (failure) throw failure;
|
|
1777
|
+
const chunkBytes = CLIP_PAGE_BASE64_CHARS / 4 * 3;
|
|
1778
|
+
const offset = fromChunk * chunkBytes;
|
|
1779
|
+
const chunks = [];
|
|
1780
|
+
if (data && offset < data.length) {
|
|
1781
|
+
const chunk = data.subarray(offset, offset + chunkBytes);
|
|
1782
|
+
let text = "";
|
|
1783
|
+
for (let index = 0; index < chunk.length; index += 8192)
|
|
1784
|
+
text += String.fromCharCode(...chunk.subarray(index, index + 8192));
|
|
1785
|
+
chunks.push(btoa(text));
|
|
1786
|
+
}
|
|
1787
|
+
return {
|
|
1788
|
+
mimeType,
|
|
1789
|
+
width,
|
|
1790
|
+
height,
|
|
1791
|
+
chunks,
|
|
1792
|
+
nextChunk: data && offset + chunkBytes < data.length ? fromChunk + 1 : null
|
|
1793
|
+
};
|
|
1794
|
+
},
|
|
1795
|
+
stats: () => ({ drawsAttempted, drawsMade }),
|
|
1796
|
+
dispose: binding.dispose
|
|
1797
|
+
};
|
|
1798
|
+
};
|
|
1799
|
+
return {
|
|
1800
|
+
capture,
|
|
1801
|
+
rendered: () => active?.render(),
|
|
1802
|
+
recording: () => active !== void 0,
|
|
1803
|
+
dispose: () => active?.dispose()
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
// src/runtime/host-capture-context.ts
|
|
1808
|
+
import { createContext as createContext2 } from "react";
|
|
1809
|
+
var hostCaptureContext = createContext2(null);
|
|
1810
|
+
|
|
1811
|
+
// src/runtime/host-capture-boundary.tsx
|
|
1812
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1813
|
+
function HostCaptureBoundary({
|
|
1814
|
+
children,
|
|
1815
|
+
setObservationCapture
|
|
1816
|
+
}) {
|
|
1817
|
+
const draw = useRef3(null);
|
|
1818
|
+
const usingStage = useRef3(false);
|
|
1819
|
+
const binding = useRef3(
|
|
1820
|
+
null
|
|
1821
|
+
);
|
|
1822
|
+
const owner = useMemo3(
|
|
1823
|
+
() => ({
|
|
1824
|
+
setDraw: (value) => {
|
|
1825
|
+
draw.current = value;
|
|
1826
|
+
},
|
|
1827
|
+
rendered: () => {
|
|
1828
|
+
if (!usingStage.current || !binding.current?.recording())
|
|
1829
|
+
binding.current?.rendered();
|
|
1830
|
+
}
|
|
1831
|
+
}),
|
|
1832
|
+
[]
|
|
1833
|
+
);
|
|
1834
|
+
useLayoutEffect(() => {
|
|
1835
|
+
const captureBinding = createHostCanvasCapture((target, options) => {
|
|
1836
|
+
if (!usingStage.current || !captureBinding.recording())
|
|
1837
|
+
usingStage.current = !draw.current?.(target, options);
|
|
1838
|
+
if (!usingStage.current) return true;
|
|
1839
|
+
const stage = document.querySelector(
|
|
1840
|
+
stageCaptureCanvasSelector
|
|
1841
|
+
);
|
|
1842
|
+
stage?.requestPaint();
|
|
1843
|
+
return drawAgentCanvas(stage, target, options);
|
|
1844
|
+
});
|
|
1845
|
+
binding.current = captureBinding;
|
|
1846
|
+
const capture = (options) => {
|
|
1847
|
+
const image = captureBinding.capture(options);
|
|
1848
|
+
const coverage = usingStage.current ? "host-document" : "render-surface";
|
|
1849
|
+
return Promise.resolve(image).then(
|
|
1850
|
+
(value) => value && { ...value, coverage }
|
|
1851
|
+
);
|
|
1852
|
+
};
|
|
1853
|
+
capture.startVideo = captureBinding.capture.startVideo;
|
|
1854
|
+
setObservationCapture(capture);
|
|
1855
|
+
return () => {
|
|
1856
|
+
setObservationCapture(null);
|
|
1857
|
+
captureBinding.dispose();
|
|
1858
|
+
binding.current = null;
|
|
1859
|
+
};
|
|
1860
|
+
}, [setObservationCapture]);
|
|
1861
|
+
useEffect4(() => {
|
|
1862
|
+
const stage = document.querySelector(
|
|
1863
|
+
stageCaptureCanvasSelector
|
|
1864
|
+
);
|
|
1865
|
+
if (!stage) return;
|
|
1866
|
+
const painted = () => {
|
|
1867
|
+
if (!usingStage.current || !binding.current?.recording()) return;
|
|
1868
|
+
binding.current.rendered();
|
|
1869
|
+
if (usingStage.current && binding.current.recording())
|
|
1870
|
+
stage.requestPaint();
|
|
1871
|
+
};
|
|
1872
|
+
stage.addEventListener("paint", painted);
|
|
1873
|
+
return () => stage.removeEventListener("paint", painted);
|
|
1874
|
+
}, []);
|
|
1875
|
+
return /* @__PURE__ */ jsx4(hostCaptureContext.Provider, { value: owner, children });
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
// src/runtime/prefab-inspection-runtime.tsx
|
|
1879
|
+
import {
|
|
1880
|
+
useCallback as useCallback4,
|
|
1881
|
+
useEffect as useEffect5,
|
|
1882
|
+
useMemo as useMemo4,
|
|
1883
|
+
useRef as useRef4,
|
|
1884
|
+
useState as useState4
|
|
1885
|
+
} from "react";
|
|
1886
|
+
import { flushSync } from "react-dom";
|
|
1887
|
+
|
|
1888
|
+
// src/runtime/prefab-inspection-clock.ts
|
|
1889
|
+
function advancePrefabClock(time, elapsed, state) {
|
|
1890
|
+
if (!state.seconds) return { time: 0, playing: false };
|
|
1891
|
+
const next = Math.max(0, time + elapsed);
|
|
1892
|
+
return state.loop ? { time: next % state.seconds, playing: true } : { time: Math.min(next, state.seconds), playing: next < state.seconds };
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
// src/runtime/prefab-inspection-runtime.tsx
|
|
1896
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1897
|
+
function InspectionStage({
|
|
1898
|
+
selection,
|
|
1899
|
+
prefab,
|
|
1900
|
+
state,
|
|
1901
|
+
stage: Stage
|
|
1902
|
+
}) {
|
|
1903
|
+
return /* @__PURE__ */ jsx5(
|
|
1904
|
+
prefabInspectionContext.Provider,
|
|
1905
|
+
{
|
|
1906
|
+
value: {
|
|
1907
|
+
...selection,
|
|
1908
|
+
prefab,
|
|
1909
|
+
props: prefab.configSchema.parse(prefab.defaultProps),
|
|
1910
|
+
state
|
|
1911
|
+
},
|
|
1912
|
+
children: /* @__PURE__ */ jsx5(Stage, {})
|
|
1913
|
+
}
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1916
|
+
var NO_PREFABS = [];
|
|
1917
|
+
function PrefabInspectionRuntime({
|
|
1918
|
+
prefabs = NO_PREFABS,
|
|
1919
|
+
prefabStage: Stage,
|
|
1920
|
+
...config
|
|
1921
|
+
}) {
|
|
1922
|
+
const { catalog, reason } = useMemo4(() => {
|
|
1923
|
+
try {
|
|
1924
|
+
const catalog2 = prefabCatalogMetadataSchema.parse(
|
|
1925
|
+
prefabs.map(prefabMetadata)
|
|
1926
|
+
);
|
|
1927
|
+
for (const prefab2 of prefabs)
|
|
1928
|
+
prefab2.configSchema.parse(prefab2.defaultProps);
|
|
1929
|
+
return { catalog: catalog2, reason: null };
|
|
1930
|
+
} catch (error) {
|
|
1931
|
+
return {
|
|
1932
|
+
catalog: [],
|
|
1933
|
+
reason: `Invalid prefab catalog: ${error instanceof Error ? error.message : String(error)}`
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
}, [prefabs]);
|
|
1937
|
+
const topology = resolveAirJamConfig(config).topology;
|
|
1938
|
+
const { embedded, embedParentOrigin } = topology;
|
|
1939
|
+
const parent = useMemo4(
|
|
1940
|
+
() => embeddedRuntimeParent({ embedded, embedParentOrigin }),
|
|
1941
|
+
[embedded, embedParentOrigin]
|
|
1942
|
+
);
|
|
1943
|
+
const capture = useRef4(null);
|
|
1944
|
+
const captureOwner = useMemo4(
|
|
1945
|
+
() => ({
|
|
1946
|
+
setObservationCapture: (value) => {
|
|
1947
|
+
capture.current = value;
|
|
1948
|
+
}
|
|
1949
|
+
}),
|
|
1950
|
+
[]
|
|
1951
|
+
);
|
|
1952
|
+
const [selection, setSelection] = useState4(() => {
|
|
1953
|
+
const query = new URLSearchParams(window.location.search);
|
|
1954
|
+
const prefab2 = catalog.find((item) => item.id === query.get("prefab")) ?? catalog[0];
|
|
1955
|
+
if (!prefab2) return null;
|
|
1956
|
+
const state2 = prefab2.states.find((item) => item.id === query.get("state")) ?? prefab2.states[0];
|
|
1957
|
+
const time = Number(query.get("time") ?? 0);
|
|
1958
|
+
return {
|
|
1959
|
+
prefabId: prefab2.id,
|
|
1960
|
+
stateId: state2.id,
|
|
1961
|
+
time: Number.isFinite(time) && time >= 0 ? advancePrefabClock(time, 0, state2).time : 0,
|
|
1962
|
+
playing: false,
|
|
1963
|
+
view: DEFAULT_PREFAB_VIEW
|
|
1964
|
+
};
|
|
1965
|
+
});
|
|
1966
|
+
const current = useRef4(selection);
|
|
1967
|
+
current.current = selection;
|
|
1968
|
+
const failure = useRef4(null);
|
|
1969
|
+
const report = useCallback4(
|
|
1970
|
+
(message) => parent?.window.postMessage(
|
|
1971
|
+
prefabInspectionMessageSchema.parse(message),
|
|
1972
|
+
parent.origin
|
|
1973
|
+
),
|
|
1974
|
+
[parent]
|
|
1975
|
+
);
|
|
1976
|
+
const unavailable = reason ?? (!catalog.length ? "This game declares no prefabs. Add prefabs: createPrefabCatalog([...]) to defineAirJamGame." : !Stage ? "This game has no prefab stage. Pass prefabStage={Stage} to app.Host." : null);
|
|
1977
|
+
const commit = useCallback4(
|
|
1978
|
+
(next) => {
|
|
1979
|
+
const prefab2 = catalog.find((item) => item.id === next.prefabId);
|
|
1980
|
+
if (!prefab2) throw new Error(`Unknown prefab: ${next.prefabId}`);
|
|
1981
|
+
const state2 = prefab2.states.find((item) => item.id === next.stateId);
|
|
1982
|
+
if (!state2) throw new Error(`Unknown state: ${next.stateId}`);
|
|
1983
|
+
const clock = advancePrefabClock(next.time, 0, state2);
|
|
1984
|
+
const value = {
|
|
1985
|
+
...next,
|
|
1986
|
+
time: clock.time,
|
|
1987
|
+
playing: next.playing && clock.playing
|
|
1988
|
+
};
|
|
1989
|
+
flushSync(() => setSelection(value));
|
|
1990
|
+
current.current = value;
|
|
1991
|
+
report({ type: "AIRJAM_PREFAB_SELECTION", selection: value });
|
|
1992
|
+
},
|
|
1993
|
+
[catalog, report]
|
|
1994
|
+
);
|
|
1995
|
+
useEffect5(() => {
|
|
1996
|
+
let closed = false;
|
|
1997
|
+
let queue = Promise.resolve();
|
|
1998
|
+
let restore = null;
|
|
1999
|
+
const publish = () => {
|
|
2000
|
+
if (failure.current)
|
|
2001
|
+
report({ type: "AIRJAM_PREFAB_ERROR", reason: failure.current });
|
|
2002
|
+
else if (unavailable)
|
|
2003
|
+
report({ type: "AIRJAM_PREFAB_UNAVAILABLE", reason: unavailable });
|
|
2004
|
+
else {
|
|
2005
|
+
report({ type: "AIRJAM_PREFAB_READY", catalog });
|
|
2006
|
+
if (current.current)
|
|
2007
|
+
report({
|
|
2008
|
+
type: "AIRJAM_PREFAB_SELECTION",
|
|
2009
|
+
selection: current.current
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
};
|
|
2013
|
+
const frames = () => new Promise(
|
|
2014
|
+
(resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve()))
|
|
2015
|
+
);
|
|
2016
|
+
const captureViews = async (requestId, views) => {
|
|
2017
|
+
try {
|
|
2018
|
+
if (unavailable) throw new Error(unavailable);
|
|
2019
|
+
if (failure.current) throw new Error(failure.current);
|
|
2020
|
+
const previous = current.current;
|
|
2021
|
+
if (!previous) throw new Error("Select a prefab before capture.");
|
|
2022
|
+
restore = previous;
|
|
2023
|
+
const images = [];
|
|
2024
|
+
try {
|
|
2025
|
+
for (const view of views) {
|
|
2026
|
+
if (closed) return;
|
|
2027
|
+
commit({ ...previous, ...view, playing: false });
|
|
2028
|
+
await frames();
|
|
2029
|
+
if (closed) return;
|
|
2030
|
+
if (failure.current) throw new Error(failure.current);
|
|
2031
|
+
const image = await capture.current?.({
|
|
2032
|
+
maxEdge: 1280,
|
|
2033
|
+
quality: 0.85
|
|
2034
|
+
});
|
|
2035
|
+
if (!image)
|
|
2036
|
+
throw new Error(
|
|
2037
|
+
"The prefab stage has no registered canvas. Use useHostAgentCapture."
|
|
2038
|
+
);
|
|
2039
|
+
images.push({
|
|
2040
|
+
...view,
|
|
2041
|
+
time: current.current.time,
|
|
2042
|
+
imageUrl: `data:${image.mimeType};base64,${image.data}`,
|
|
2043
|
+
width: image.width,
|
|
2044
|
+
height: image.height
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
} finally {
|
|
2048
|
+
const next = restore;
|
|
2049
|
+
restore = null;
|
|
2050
|
+
if (!closed && next) commit(next);
|
|
2051
|
+
}
|
|
2052
|
+
if (!closed)
|
|
2053
|
+
report({ type: "AIRJAM_PREFAB_CAPTURED", requestId, images });
|
|
2054
|
+
} catch (error) {
|
|
2055
|
+
if (!closed)
|
|
2056
|
+
report({
|
|
2057
|
+
type: "AIRJAM_PREFAB_ERROR",
|
|
2058
|
+
requestId,
|
|
2059
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
2060
|
+
});
|
|
2061
|
+
}
|
|
2062
|
+
};
|
|
2063
|
+
const listen = (event) => {
|
|
2064
|
+
if (!parent || event.source !== parent.window || event.origin !== parent.origin)
|
|
2065
|
+
return;
|
|
2066
|
+
const parsed = prefabInspectionRequestSchema.safeParse(event.data);
|
|
2067
|
+
if (!parsed.success) return;
|
|
2068
|
+
const message = parsed.data;
|
|
2069
|
+
if (message.type === "AIRJAM_PREFAB_READ") publish();
|
|
2070
|
+
else if (message.type === "AIRJAM_PREFAB_CAPTURE")
|
|
2071
|
+
queue = queue.then(
|
|
2072
|
+
() => captureViews(message.requestId, message.views)
|
|
2073
|
+
);
|
|
2074
|
+
else if (restore) restore = message.selection;
|
|
2075
|
+
else {
|
|
2076
|
+
try {
|
|
2077
|
+
if (unavailable) throw new Error(unavailable);
|
|
2078
|
+
if (failure.current) throw new Error(failure.current);
|
|
2079
|
+
commit(message.selection);
|
|
2080
|
+
} catch (error) {
|
|
2081
|
+
report({
|
|
2082
|
+
type: "AIRJAM_PREFAB_ERROR",
|
|
2083
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
window.addEventListener("message", listen);
|
|
2089
|
+
publish();
|
|
2090
|
+
return () => {
|
|
2091
|
+
closed = true;
|
|
2092
|
+
window.removeEventListener("message", listen);
|
|
2093
|
+
};
|
|
2094
|
+
}, [parent, catalog, unavailable, report, commit]);
|
|
2095
|
+
useEffect5(() => {
|
|
2096
|
+
if (!selection?.playing) return;
|
|
2097
|
+
let frame = 0;
|
|
2098
|
+
let last = null;
|
|
2099
|
+
let published = 0;
|
|
2100
|
+
const animate = (now) => {
|
|
2101
|
+
const value = current.current;
|
|
2102
|
+
if (!value?.playing) return;
|
|
2103
|
+
const state2 = catalog.find((item) => item.id === value.prefabId)?.states.find((item) => item.id === value.stateId);
|
|
2104
|
+
if (!state2) return;
|
|
2105
|
+
const next = {
|
|
2106
|
+
...value,
|
|
2107
|
+
...advancePrefabClock(
|
|
2108
|
+
value.time,
|
|
2109
|
+
last === null ? 0 : (now - last) / 1e3,
|
|
2110
|
+
state2
|
|
2111
|
+
)
|
|
2112
|
+
};
|
|
2113
|
+
last = now;
|
|
2114
|
+
current.current = next;
|
|
2115
|
+
setSelection(next);
|
|
2116
|
+
if (now - published >= 1e3 / 15 || !next.playing) {
|
|
2117
|
+
report({ type: "AIRJAM_PREFAB_SELECTION", selection: next });
|
|
2118
|
+
published = now;
|
|
2119
|
+
}
|
|
2120
|
+
if (next.playing) frame = requestAnimationFrame(animate);
|
|
2121
|
+
};
|
|
2122
|
+
frame = requestAnimationFrame(animate);
|
|
2123
|
+
return () => cancelAnimationFrame(frame);
|
|
2124
|
+
}, [selection?.playing, catalog, report]);
|
|
2125
|
+
const prefab = unavailable ? void 0 : prefabs.find((item) => item.id === selection?.prefabId);
|
|
2126
|
+
const state = catalog.find((item) => item.id === selection?.prefabId)?.states.find((item) => item.id === selection?.stateId);
|
|
2127
|
+
return /* @__PURE__ */ jsx5(
|
|
2128
|
+
AirJamErrorBoundary,
|
|
2129
|
+
{
|
|
2130
|
+
role: "host",
|
|
2131
|
+
onError: (error) => {
|
|
2132
|
+
failure.current = error.message;
|
|
2133
|
+
report({ type: "AIRJAM_PREFAB_ERROR", reason: error.message });
|
|
2134
|
+
},
|
|
2135
|
+
children: /* @__PURE__ */ jsx5(StageCaptureSurface, { role: "host", children: /* @__PURE__ */ jsx5(
|
|
2136
|
+
HostCaptureBoundary,
|
|
2137
|
+
{
|
|
2138
|
+
setObservationCapture: captureOwner.setObservationCapture,
|
|
2139
|
+
children: unavailable ? /* @__PURE__ */ jsx5("p", { children: unavailable }) : prefab && state && selection && Stage ? /* @__PURE__ */ jsx5(
|
|
2140
|
+
InspectionStage,
|
|
2141
|
+
{
|
|
2142
|
+
selection,
|
|
2143
|
+
prefab,
|
|
2144
|
+
state,
|
|
2145
|
+
stage: Stage
|
|
2146
|
+
}
|
|
2147
|
+
) : null
|
|
2148
|
+
}
|
|
2149
|
+
) })
|
|
2150
|
+
}
|
|
2151
|
+
);
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
// src/runtime/replay-runtime.tsx
|
|
2155
|
+
import { useEffect as useEffect6, useMemo as useMemo5, useState as useState5 } from "react";
|
|
2156
|
+
import { flushSync as flushSync2 } from "react-dom";
|
|
2157
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
2158
|
+
var NO_STORES = [];
|
|
2159
|
+
function ReplayRuntime({
|
|
2160
|
+
children,
|
|
2161
|
+
stores = NO_STORES,
|
|
2162
|
+
simulation,
|
|
2163
|
+
settings,
|
|
2164
|
+
input,
|
|
2165
|
+
agent,
|
|
2166
|
+
gameId,
|
|
2167
|
+
fixedControllerOrientation
|
|
2168
|
+
}) {
|
|
2169
|
+
const context = useAirJamContext();
|
|
2170
|
+
const [replay, setReplay] = useState5(null);
|
|
2171
|
+
const declared = useMemo5(() => new Set(stores), [stores]);
|
|
2172
|
+
useEffect6(() => {
|
|
2173
|
+
const parent = embeddedRuntimeParent(context.config.topology);
|
|
2174
|
+
if (!parent)
|
|
2175
|
+
throw new Error(
|
|
2176
|
+
"A browser replay requires its declared embedding parent."
|
|
2177
|
+
);
|
|
2178
|
+
return bindBrowserReplay({
|
|
2179
|
+
parent: parent.window,
|
|
2180
|
+
parentOrigin: parent.origin,
|
|
2181
|
+
createHostRuntime: (dependencies, options) => new HostRuntime(
|
|
2182
|
+
{
|
|
2183
|
+
...dependencies,
|
|
2184
|
+
fixedControllerOrientation,
|
|
2185
|
+
stores,
|
|
2186
|
+
simulation,
|
|
2187
|
+
settings,
|
|
2188
|
+
input,
|
|
2189
|
+
agent: agent && { contract: agent, gameId: gameId ?? "game" }
|
|
2190
|
+
},
|
|
2191
|
+
options
|
|
2192
|
+
),
|
|
2193
|
+
// Commit the game tree and its layout effects before the first observation.
|
|
2194
|
+
mounted: (value) => flushSync2(() => setReplay(value)),
|
|
2195
|
+
listen: (listener) => {
|
|
2196
|
+
window.addEventListener("message", listener);
|
|
2197
|
+
return () => window.removeEventListener("message", listener);
|
|
2198
|
+
}
|
|
2199
|
+
});
|
|
2200
|
+
}, [
|
|
2201
|
+
context.config.topology,
|
|
2202
|
+
stores,
|
|
2203
|
+
simulation,
|
|
2204
|
+
settings,
|
|
2205
|
+
input,
|
|
2206
|
+
agent,
|
|
2207
|
+
gameId,
|
|
2208
|
+
fixedControllerOrientation
|
|
2209
|
+
]);
|
|
2210
|
+
if (!replay) return null;
|
|
2211
|
+
const runtime = replay.runtime;
|
|
2212
|
+
const controls = {
|
|
2213
|
+
roomId: replay.roomId,
|
|
2214
|
+
joinUrl: "",
|
|
2215
|
+
joinUrlStatus: "ready",
|
|
2216
|
+
pauseRuntime: runtime.pauseRuntime,
|
|
2217
|
+
resumeRuntime: runtime.resumeRuntime,
|
|
2218
|
+
setRuntimeState: runtime.setRuntimeState,
|
|
2219
|
+
sendSignal: runtime.sendSignal,
|
|
2220
|
+
removeController: runtime.removeController,
|
|
2221
|
+
resetRoom: runtime.resetRoom,
|
|
2222
|
+
room: runtime.room,
|
|
2223
|
+
simulation: runtime.simulation,
|
|
2224
|
+
setObservationCapture: runtime.setObservationCapture,
|
|
2225
|
+
playSoundOnControllers: runtime.playSoundOnControllers,
|
|
2226
|
+
settings: runtime.settings
|
|
2227
|
+
};
|
|
2228
|
+
return /* @__PURE__ */ jsx6(AirJamContext.Provider, { value: { ...context, store: runtime.store }, children: /* @__PURE__ */ jsx6(hostRuntimeContext.Provider, { value: controls, children: /* @__PURE__ */ jsx6(
|
|
2229
|
+
HostCaptureBoundary,
|
|
2230
|
+
{
|
|
2231
|
+
setObservationCapture: runtime.setObservationCapture,
|
|
2232
|
+
children: /* @__PURE__ */ jsx6(declaredStoresContext.Provider, { value: declared, children })
|
|
2233
|
+
}
|
|
2234
|
+
) }) });
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
// src/runtime/session-runtimes.tsx
|
|
2238
|
+
import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2239
|
+
var NO_STORES2 = [];
|
|
2240
|
+
var HostRuntimeInspectionPublisher = () => {
|
|
2241
|
+
const inspection = useHostRuntimeInspectionContract();
|
|
2242
|
+
const { topology } = useAirJamConfig();
|
|
2243
|
+
useEffect7(() => {
|
|
2244
|
+
if (typeof window === "undefined") {
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2247
|
+
publishRuntimeInspectionContract(window, inspection);
|
|
2248
|
+
const hostAgent = publishEmbeddedHostAgent(inspection, topology);
|
|
2249
|
+
const stopPublishing = publishEmbeddedHostPreview(
|
|
2250
|
+
inspection,
|
|
2251
|
+
topology,
|
|
2252
|
+
hostAgent.supported
|
|
2253
|
+
);
|
|
2254
|
+
return () => {
|
|
2255
|
+
stopPublishing();
|
|
2256
|
+
hostAgent.close();
|
|
2257
|
+
if (readRuntimeInspectionContract(window)?.role === "host") {
|
|
2258
|
+
publishRuntimeInspectionContract(window, null);
|
|
2259
|
+
}
|
|
2260
|
+
};
|
|
2261
|
+
}, [inspection, topology]);
|
|
2262
|
+
return null;
|
|
2263
|
+
};
|
|
2264
|
+
var ControllerRuntimeInspectionPublisher = () => {
|
|
2265
|
+
const inspection = useControllerRuntimeInspectionContract();
|
|
2266
|
+
useEffect7(() => {
|
|
2267
|
+
if (typeof window === "undefined") {
|
|
2268
|
+
return;
|
|
2269
|
+
}
|
|
2270
|
+
publishRuntimeInspectionContract(window, inspection);
|
|
2271
|
+
return () => {
|
|
2272
|
+
if (readRuntimeInspectionContract(window)?.role === "controller") {
|
|
2273
|
+
publishRuntimeInspectionContract(window, null);
|
|
2274
|
+
}
|
|
2275
|
+
};
|
|
2276
|
+
}, [inspection]);
|
|
2277
|
+
return null;
|
|
2278
|
+
};
|
|
2279
|
+
var HostRuntimeOwner = ({
|
|
2280
|
+
children,
|
|
2281
|
+
roomId,
|
|
2282
|
+
onPlayerJoin,
|
|
2283
|
+
onPlayerLeave,
|
|
2284
|
+
agent,
|
|
2285
|
+
gameId,
|
|
2286
|
+
stores = NO_STORES2,
|
|
2287
|
+
simulation,
|
|
2288
|
+
settings,
|
|
2289
|
+
input,
|
|
2290
|
+
inputBindings,
|
|
2291
|
+
fixedControllerOrientation
|
|
2292
|
+
}) => {
|
|
2293
|
+
const declared = useMemo6(() => new Set(stores), [stores]);
|
|
2294
|
+
const game = useMemo6(
|
|
2295
|
+
() => ({
|
|
2296
|
+
stores,
|
|
2297
|
+
fixedControllerOrientation,
|
|
2298
|
+
simulation,
|
|
2299
|
+
settings,
|
|
2300
|
+
input,
|
|
2301
|
+
agent: agent && { contract: agent, gameId: gameId ?? "game" }
|
|
2302
|
+
}),
|
|
2303
|
+
[
|
|
2304
|
+
stores,
|
|
2305
|
+
simulation,
|
|
2306
|
+
settings,
|
|
2307
|
+
input,
|
|
2308
|
+
agent,
|
|
2309
|
+
gameId,
|
|
2310
|
+
fixedControllerOrientation
|
|
2311
|
+
]
|
|
2312
|
+
);
|
|
2313
|
+
const runtime = useHostRuntimeApi(
|
|
2314
|
+
{
|
|
2315
|
+
roomId,
|
|
2316
|
+
onPlayerJoin,
|
|
2317
|
+
onPlayerLeave
|
|
2318
|
+
},
|
|
2319
|
+
"AirJamHostRuntime",
|
|
2320
|
+
game
|
|
2321
|
+
);
|
|
2322
|
+
return /* @__PURE__ */ jsx7(hostRuntimeContext.Provider, { value: runtime, children: /* @__PURE__ */ jsx7(
|
|
2323
|
+
HostCaptureBoundary,
|
|
2324
|
+
{
|
|
2325
|
+
setObservationCapture: runtime.setObservationCapture,
|
|
2326
|
+
children: /* @__PURE__ */ jsxs2(declaredStoresContext.Provider, { value: declared, children: [
|
|
2327
|
+
/* @__PURE__ */ jsx7(HostRuntimeInspectionPublisher, {}),
|
|
2328
|
+
/* @__PURE__ */ jsx7(LocalPlayersHost, { input, bindings: inputBindings, children: simulation && !runtime.simulation ? null : children })
|
|
2329
|
+
] })
|
|
2330
|
+
}
|
|
2331
|
+
) });
|
|
2332
|
+
};
|
|
2333
|
+
var ControllerRuntimeOwner = ({
|
|
2334
|
+
children,
|
|
2335
|
+
roomId,
|
|
2336
|
+
nickname,
|
|
2337
|
+
avatarId,
|
|
2338
|
+
stores = NO_STORES2,
|
|
2339
|
+
input
|
|
2340
|
+
}) => {
|
|
2341
|
+
const declared = useMemo6(() => new Set(stores), [stores]);
|
|
2342
|
+
const runtime = useControllerRuntimeApi(
|
|
2343
|
+
{
|
|
2344
|
+
roomId,
|
|
2345
|
+
nickname,
|
|
2346
|
+
avatarId
|
|
2347
|
+
},
|
|
2348
|
+
"AirJamControllerRuntime",
|
|
2349
|
+
stores,
|
|
2350
|
+
input
|
|
2351
|
+
);
|
|
2352
|
+
return /* @__PURE__ */ jsx7(controllerRuntimeContext.Provider, { value: runtime, children: /* @__PURE__ */ jsxs2(declaredStoresContext.Provider, { value: declared, children: [
|
|
2353
|
+
/* @__PURE__ */ jsx7(ControllerRuntimeInspectionPublisher, {}),
|
|
2354
|
+
children
|
|
2355
|
+
] }) });
|
|
2356
|
+
};
|
|
2357
|
+
var subscribeToNothing = () => () => {
|
|
2358
|
+
};
|
|
2359
|
+
var useInBrowser = () => useSyncExternalStore(
|
|
2360
|
+
subscribeToNothing,
|
|
2361
|
+
() => true,
|
|
2362
|
+
() => false
|
|
2363
|
+
);
|
|
2364
|
+
var AirJamHostRuntime = ({
|
|
2365
|
+
children,
|
|
2366
|
+
captureStage,
|
|
2367
|
+
roomId,
|
|
2368
|
+
onPlayerJoin,
|
|
2369
|
+
onPlayerLeave,
|
|
2370
|
+
agent,
|
|
2371
|
+
gameId,
|
|
2372
|
+
stores,
|
|
2373
|
+
simulation,
|
|
2374
|
+
settings,
|
|
2375
|
+
input,
|
|
2376
|
+
inputBindings,
|
|
2377
|
+
fixedControllerOrientation,
|
|
2378
|
+
prefabs,
|
|
2379
|
+
prefabStage,
|
|
2380
|
+
...providerProps
|
|
2381
|
+
}) => {
|
|
2382
|
+
if (!useInBrowser()) return null;
|
|
2383
|
+
if (isAirJamInspectionDocument())
|
|
2384
|
+
return /* @__PURE__ */ jsx7(
|
|
2385
|
+
PrefabInspectionRuntime,
|
|
2386
|
+
{
|
|
2387
|
+
...providerProps,
|
|
2388
|
+
prefabs,
|
|
2389
|
+
prefabStage
|
|
2390
|
+
}
|
|
2391
|
+
);
|
|
2392
|
+
if (isAirJamReplayDocument())
|
|
2393
|
+
return /* @__PURE__ */ jsx7(
|
|
2394
|
+
fixedControllerOrientationContext.Provider,
|
|
2395
|
+
{
|
|
2396
|
+
value: fixedControllerOrientation ?? null,
|
|
2397
|
+
children: /* @__PURE__ */ jsx7(HostSessionProvider, { ...providerProps, captureStage, children: /* @__PURE__ */ jsx7(
|
|
2398
|
+
ReplayRuntime,
|
|
2399
|
+
{
|
|
2400
|
+
...providerProps,
|
|
2401
|
+
fixedControllerOrientation,
|
|
2402
|
+
stores,
|
|
2403
|
+
simulation,
|
|
2404
|
+
settings,
|
|
2405
|
+
input,
|
|
2406
|
+
agent,
|
|
2407
|
+
gameId,
|
|
2408
|
+
children
|
|
2409
|
+
}
|
|
2410
|
+
) })
|
|
2411
|
+
}
|
|
2412
|
+
);
|
|
2413
|
+
return /* @__PURE__ */ jsx7(
|
|
2414
|
+
fixedControllerOrientationContext.Provider,
|
|
2415
|
+
{
|
|
2416
|
+
value: fixedControllerOrientation ?? null,
|
|
2417
|
+
children: /* @__PURE__ */ jsx7(HostSessionProvider, { ...providerProps, captureStage, children: /* @__PURE__ */ jsx7(PlatformSettingsBoundary, { children: /* @__PURE__ */ jsx7(
|
|
2418
|
+
HostRuntimeOwner,
|
|
2419
|
+
{
|
|
2420
|
+
roomId,
|
|
2421
|
+
onPlayerJoin,
|
|
2422
|
+
onPlayerLeave,
|
|
2423
|
+
agent,
|
|
2424
|
+
gameId,
|
|
2425
|
+
stores,
|
|
2426
|
+
simulation,
|
|
2427
|
+
settings,
|
|
2428
|
+
input,
|
|
2429
|
+
inputBindings,
|
|
2430
|
+
fixedControllerOrientation,
|
|
2431
|
+
children
|
|
2432
|
+
}
|
|
2433
|
+
) }) })
|
|
2434
|
+
}
|
|
2435
|
+
);
|
|
2436
|
+
};
|
|
2437
|
+
var AirJamControllerRuntime = ({
|
|
2438
|
+
children,
|
|
2439
|
+
roomId,
|
|
2440
|
+
nickname,
|
|
2441
|
+
avatarId,
|
|
2442
|
+
fixedControllerOrientation,
|
|
2443
|
+
stores,
|
|
2444
|
+
input,
|
|
2445
|
+
...providerProps
|
|
2446
|
+
}) => {
|
|
2447
|
+
if (!useInBrowser()) return null;
|
|
2448
|
+
return /* @__PURE__ */ jsx7(
|
|
2449
|
+
fixedControllerOrientationContext.Provider,
|
|
2450
|
+
{
|
|
2451
|
+
value: fixedControllerOrientation ?? null,
|
|
2452
|
+
children: /* @__PURE__ */ jsx7(ControllerSessionProvider, { ...providerProps, children: /* @__PURE__ */ jsx7(PlatformSettingsBoundary, { children: /* @__PURE__ */ jsx7(
|
|
2453
|
+
ControllerRuntimeOwner,
|
|
2454
|
+
{
|
|
2455
|
+
roomId,
|
|
2456
|
+
nickname,
|
|
2457
|
+
avatarId,
|
|
2458
|
+
stores,
|
|
2459
|
+
input,
|
|
2460
|
+
children
|
|
2461
|
+
}
|
|
2462
|
+
) }) })
|
|
2463
|
+
}
|
|
2464
|
+
);
|
|
2465
|
+
};
|
|
2466
|
+
|
|
2467
|
+
export {
|
|
2468
|
+
captureAgentCanvas,
|
|
2469
|
+
drawAgentCanvas,
|
|
2470
|
+
hostCaptureContext,
|
|
2471
|
+
AirJamErrorBoundary,
|
|
2472
|
+
devLogRuntimeErrorReporter,
|
|
2473
|
+
usePrefabInspection,
|
|
2474
|
+
AirJamHostRuntime,
|
|
2475
|
+
AirJamControllerRuntime
|
|
2476
|
+
};
|
|
2477
|
+
//# sourceMappingURL=chunk-DHFKL3DI.js.map
|