@air-jam/sdk 0.9.2 → 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.
Files changed (590) hide show
  1. package/README.md +185 -242
  2. package/dist/actions-D4eh6Xaa.d.cts +72 -0
  3. package/dist/actions-D4eh6Xaa.d.ts +72 -0
  4. package/dist/{agent-tooling-BSMGBix9.d.cts → agent-contract-DfLm4Mf-.d.ts} +3 -19
  5. package/dist/{agent-tooling-BSMGBix9.d.ts → agent-contract-TINzp-5Y.d.cts} +3 -19
  6. package/dist/agent-tooling.cjs +270 -42
  7. package/dist/agent-tooling.cjs.map +1 -1
  8. package/dist/agent-tooling.d.cts +117 -2
  9. package/dist/agent-tooling.d.ts +117 -2
  10. package/dist/agent-tooling.js +150 -11
  11. package/dist/agent-tooling.js.map +1 -1
  12. package/dist/air-jam-context-BCVCWiaT.d.ts +410 -0
  13. package/dist/air-jam-context-DavligpM.d.cts +410 -0
  14. package/dist/arcade/bridge/controller.cjs +872 -582
  15. package/dist/arcade/bridge/controller.cjs.map +1 -1
  16. package/dist/arcade/bridge/controller.d.cts +28 -76
  17. package/dist/arcade/bridge/controller.d.ts +28 -76
  18. package/dist/arcade/bridge/controller.js +27 -26
  19. package/dist/arcade/bridge/controller.js.map +1 -1
  20. package/dist/arcade/bridge/host.cjs +1017 -252
  21. package/dist/arcade/bridge/host.cjs.map +1 -1
  22. package/dist/arcade/bridge/host.d.cts +6 -72
  23. package/dist/arcade/bridge/host.d.ts +6 -72
  24. package/dist/arcade/bridge/host.js +19 -21
  25. package/dist/arcade/bridge/host.js.map +1 -1
  26. package/dist/arcade/bridge/iframe.cjs +3 -31
  27. package/dist/arcade/bridge/iframe.cjs.map +1 -1
  28. package/dist/arcade/bridge/iframe.d.cts +4 -46
  29. package/dist/arcade/bridge/iframe.d.ts +4 -46
  30. package/dist/arcade/bridge/iframe.js +6 -18
  31. package/dist/arcade/bridge/iframe.js.map +1 -1
  32. package/dist/arcade/host.cjs +0 -479
  33. package/dist/arcade/host.cjs.map +1 -1
  34. package/dist/arcade/host.d.cts +1 -18
  35. package/dist/arcade/host.d.ts +1 -18
  36. package/dist/arcade/host.js +0 -13
  37. package/dist/arcade/host.js.map +1 -1
  38. package/dist/arcade/runtime.cjs +12163 -0
  39. package/dist/arcade/runtime.cjs.map +1 -0
  40. package/dist/arcade/runtime.d.cts +54 -0
  41. package/dist/arcade/runtime.d.ts +54 -0
  42. package/dist/arcade/runtime.js +45 -0
  43. package/dist/arcade/runtime.js.map +1 -0
  44. package/dist/arcade/surface.cjs +12 -35
  45. package/dist/arcade/surface.cjs.map +1 -1
  46. package/dist/arcade/surface.d.cts +19 -2
  47. package/dist/arcade/surface.d.ts +19 -2
  48. package/dist/arcade/surface.js +12 -14
  49. package/dist/arcade/surface.js.map +1 -1
  50. package/dist/arcade/url.cjs +45 -283
  51. package/dist/arcade/url.cjs.map +1 -1
  52. package/dist/arcade/url.d.cts +3 -56
  53. package/dist/arcade/url.d.ts +3 -56
  54. package/dist/arcade/url.js +33 -16
  55. package/dist/arcade/url.js.map +1 -1
  56. package/dist/chunk-24NZZOIO.js +700 -0
  57. package/dist/chunk-24NZZOIO.js.map +1 -0
  58. package/dist/chunk-27QLKLZL.js +469 -0
  59. package/dist/chunk-27QLKLZL.js.map +1 -0
  60. package/dist/{chunk-UWJOIVON.js → chunk-2H2FGF3H.js} +3 -6
  61. package/dist/chunk-2H2FGF3H.js.map +1 -0
  62. package/dist/chunk-2QZADUGA.js +188 -0
  63. package/dist/chunk-2QZADUGA.js.map +1 -0
  64. package/dist/chunk-3LDQCQL2.js +307 -0
  65. package/dist/chunk-3LDQCQL2.js.map +1 -0
  66. package/dist/chunk-3M7656SU.js +389 -0
  67. package/dist/chunk-3M7656SU.js.map +1 -0
  68. package/dist/{chunk-ZLPL2R3R.js → chunk-5CRZFIN6.js} +2 -82
  69. package/dist/chunk-5CRZFIN6.js.map +1 -0
  70. package/dist/chunk-5TVVPBQI.js +7 -0
  71. package/dist/chunk-5TVVPBQI.js.map +1 -0
  72. package/dist/chunk-6Y3F6Y2K.js +343 -0
  73. package/dist/chunk-6Y3F6Y2K.js.map +1 -0
  74. package/dist/{chunk-EVZJA6RN.js → chunk-6ZJUA63D.js} +183 -2
  75. package/dist/chunk-6ZJUA63D.js.map +1 -0
  76. package/dist/chunk-A6EOGRRG.js +49 -0
  77. package/dist/chunk-A6EOGRRG.js.map +1 -0
  78. package/dist/chunk-BEM77SVQ.js +57 -0
  79. package/dist/chunk-BEM77SVQ.js.map +1 -0
  80. package/dist/chunk-C5722GTG.js +176 -0
  81. package/dist/chunk-C5722GTG.js.map +1 -0
  82. package/dist/{chunk-DY67S3LR.js → chunk-C5GS2GMK.js} +99 -105
  83. package/dist/chunk-C5GS2GMK.js.map +1 -0
  84. package/dist/chunk-CDL7LYZH.js +19 -0
  85. package/dist/chunk-CDL7LYZH.js.map +1 -0
  86. package/dist/chunk-DA3TE4OP.js +16 -0
  87. package/dist/chunk-DA3TE4OP.js.map +1 -0
  88. package/dist/chunk-DBF7NJ3S.js +72 -0
  89. package/dist/chunk-DBF7NJ3S.js.map +1 -0
  90. package/dist/chunk-DHFKL3DI.js +2477 -0
  91. package/dist/chunk-DHFKL3DI.js.map +1 -0
  92. package/dist/chunk-DRBPVG47.js +89 -0
  93. package/dist/chunk-DRBPVG47.js.map +1 -0
  94. package/dist/{chunk-7OTQTT6H.js → chunk-EG25EXSA.js} +24 -3
  95. package/dist/chunk-EG25EXSA.js.map +1 -0
  96. package/dist/chunk-FCG42U7D.js +131 -0
  97. package/dist/chunk-FCG42U7D.js.map +1 -0
  98. package/dist/chunk-FJ4J2BEC.js +26 -0
  99. package/dist/chunk-FJ4J2BEC.js.map +1 -0
  100. package/dist/chunk-H4DEVMTO.js +221 -0
  101. package/dist/chunk-H4DEVMTO.js.map +1 -0
  102. package/dist/chunk-I6TSHJF7.js +63 -0
  103. package/dist/chunk-I6TSHJF7.js.map +1 -0
  104. package/dist/{chunk-NCL6WJCL.js → chunk-JCGTL77W.js} +32 -1
  105. package/dist/chunk-JCGTL77W.js.map +1 -0
  106. package/dist/chunk-JJVCBUYM.js +98 -0
  107. package/dist/chunk-JJVCBUYM.js.map +1 -0
  108. package/dist/chunk-K6BJJJJM.js +138 -0
  109. package/dist/chunk-K6BJJJJM.js.map +1 -0
  110. package/dist/chunk-KSYN4I5Y.js +50 -0
  111. package/dist/chunk-KSYN4I5Y.js.map +1 -0
  112. package/dist/chunk-KUGROY5S.js +265 -0
  113. package/dist/chunk-KUGROY5S.js.map +1 -0
  114. package/dist/chunk-LX6CTPDW.js +16 -0
  115. package/dist/chunk-LX6CTPDW.js.map +1 -0
  116. package/dist/{chunk-BE6Z4SIT.js → chunk-M5553I2G.js} +2 -11
  117. package/dist/chunk-M5553I2G.js.map +1 -0
  118. package/dist/{chunk-X24K52DG.js → chunk-MD25536W.js} +1 -1
  119. package/dist/chunk-MD25536W.js.map +1 -0
  120. package/dist/{chunk-3USU7GY2.js → chunk-MJAWAHLT.js} +1 -1
  121. package/dist/chunk-MJAWAHLT.js.map +1 -0
  122. package/dist/chunk-OAXCFPZ7.js +14 -0
  123. package/dist/chunk-OAXCFPZ7.js.map +1 -0
  124. package/dist/chunk-QHBRHYMV.js +81 -0
  125. package/dist/chunk-QHBRHYMV.js.map +1 -0
  126. package/dist/chunk-QTNYGAZ7.js +45 -0
  127. package/dist/chunk-QTNYGAZ7.js.map +1 -0
  128. package/dist/chunk-S3TN7Y7L.js +921 -0
  129. package/dist/chunk-S3TN7Y7L.js.map +1 -0
  130. package/dist/chunk-SMKD4JY3.js +129 -0
  131. package/dist/chunk-SMKD4JY3.js.map +1 -0
  132. package/dist/{chunk-NUJBMV3O.js → chunk-TFW4NJW2.js} +619 -646
  133. package/dist/chunk-TFW4NJW2.js.map +1 -0
  134. package/dist/chunk-UBBP2UY3.js +83 -0
  135. package/dist/chunk-UBBP2UY3.js.map +1 -0
  136. package/dist/chunk-URVBMQCK.js +802 -0
  137. package/dist/chunk-URVBMQCK.js.map +1 -0
  138. package/dist/chunk-VGX2274F.js +1995 -0
  139. package/dist/chunk-VGX2274F.js.map +1 -0
  140. package/dist/chunk-WAFGYJZN.js +1513 -0
  141. package/dist/chunk-WAFGYJZN.js.map +1 -0
  142. package/dist/chunk-WGHNGQUS.js +78 -0
  143. package/dist/chunk-WGHNGQUS.js.map +1 -0
  144. package/dist/chunk-XLY44PXZ.js +46 -0
  145. package/dist/chunk-XLY44PXZ.js.map +1 -0
  146. package/dist/connection-store-BYpQ50W2.d.ts +41 -0
  147. package/dist/connection-store-D6QqzXU1.d.cts +41 -0
  148. package/dist/control-Bv8dWjyp.d.ts +1400 -0
  149. package/dist/control-CNzybWMd.d.cts +1400 -0
  150. package/dist/controller-0CVO1t_3.d.cts +26 -0
  151. package/dist/controller-agent-vOiuK7T6.d.cts +130 -0
  152. package/dist/controller-agent-vOiuK7T6.d.ts +130 -0
  153. package/dist/controller-bridge.cjs +992 -0
  154. package/dist/controller-bridge.cjs.map +1 -0
  155. package/dist/controller-bridge.d.cts +52 -0
  156. package/dist/controller-bridge.d.ts +52 -0
  157. package/dist/controller-bridge.js +23 -0
  158. package/dist/controller-bridge.js.map +1 -0
  159. package/dist/controller-capture-2GKKGHJ2.js +8 -0
  160. package/dist/controller-capture-2GKKGHJ2.js.map +1 -0
  161. package/dist/controller-h9M2Nngd.d.ts +26 -0
  162. package/dist/controller-press-EWWIMVXP.js +231 -0
  163. package/dist/controller-press-EWWIMVXP.js.map +1 -0
  164. package/dist/core-BAO0pHrJ.d.cts +15 -0
  165. package/dist/core-BAO0pHrJ.d.ts +15 -0
  166. package/dist/core.cjs +5931 -0
  167. package/dist/core.cjs.map +1 -0
  168. package/dist/core.d.cts +232 -0
  169. package/dist/core.d.ts +232 -0
  170. package/dist/core.js +906 -0
  171. package/dist/core.js.map +1 -0
  172. package/dist/dev-events-BffobOfb.d.ts +31 -0
  173. package/dist/dev-events-Ct7QEgKb.d.cts +31 -0
  174. package/dist/dev-log-events-B1_B3guZ.d.cts +47 -0
  175. package/dist/dev-log-events-B1_B3guZ.d.ts +47 -0
  176. package/dist/frames-D-xKuODS.d.cts +686 -0
  177. package/dist/frames-D-xKuODS.d.ts +686 -0
  178. package/dist/game-Db58JNk3.d.cts +77 -0
  179. package/dist/game-bySEy-QO.d.ts +77 -0
  180. package/dist/host-runtime-BuLhGQx5.d.ts +399 -0
  181. package/dist/host-runtime-_06jpW5v.d.cts +399 -0
  182. package/dist/index.cjs +12406 -8020
  183. package/dist/index.cjs.map +1 -1
  184. package/dist/index.d.cts +106 -973
  185. package/dist/index.d.ts +106 -973
  186. package/dist/index.js +451 -4637
  187. package/dist/index.js.map +1 -1
  188. package/dist/input-Xvs80gqG.d.cts +92 -0
  189. package/dist/input-Xvs80gqG.d.ts +92 -0
  190. package/dist/input-bindings-BaEFrgRb.d.cts +129 -0
  191. package/dist/input-bindings-BgsJRLPm.d.ts +129 -0
  192. package/dist/leased-control-BEg4JuXA.d.cts +158 -0
  193. package/dist/leased-control-BEg4JuXA.d.ts +158 -0
  194. package/dist/metadata.cjs +3 -9
  195. package/dist/metadata.cjs.map +1 -1
  196. package/dist/metadata.d.cts +6 -17
  197. package/dist/metadata.d.ts +6 -17
  198. package/dist/metadata.js +8 -76
  199. package/dist/metadata.js.map +1 -1
  200. package/dist/phone-room-session-Ca6rlxJr.d.ts +439 -0
  201. package/dist/phone-room-session-DkPR-K6e.d.cts +439 -0
  202. package/dist/platform-machine.cjs +248 -18
  203. package/dist/platform-machine.cjs.map +1 -1
  204. package/dist/platform-machine.d.cts +1867 -96
  205. package/dist/platform-machine.d.ts +1867 -96
  206. package/dist/platform-machine.js +206 -18
  207. package/dist/platform-machine.js.map +1 -1
  208. package/dist/{platform-settings-cuor3i11.d.cts → platform-settings-Yb0fQ1dl.d.cts} +1 -3
  209. package/dist/{platform-settings-cuor3i11.d.ts → platform-settings-Yb0fQ1dl.d.ts} +1 -3
  210. package/dist/prefabs.cjs +134 -3
  211. package/dist/prefabs.cjs.map +1 -1
  212. package/dist/prefabs.d.cts +23 -47
  213. package/dist/prefabs.d.ts +23 -47
  214. package/dist/prefabs.js +23 -4
  215. package/dist/prefabs.js.map +1 -1
  216. package/dist/preview.cjs +2269 -774
  217. package/dist/preview.cjs.map +1 -1
  218. package/dist/preview.d.cts +195 -38
  219. package/dist/preview.d.ts +195 -38
  220. package/dist/preview.js +494 -260
  221. package/dist/preview.js.map +1 -1
  222. package/dist/protocol.cjs +705 -396
  223. package/dist/protocol.cjs.map +1 -1
  224. package/dist/protocol.d.cts +49 -100
  225. package/dist/protocol.d.ts +49 -100
  226. package/dist/protocol.js +56 -75
  227. package/dist/protocol.js.map +1 -1
  228. package/dist/release.cjs +37 -0
  229. package/dist/release.cjs.map +1 -1
  230. package/dist/release.d.cts +29 -3
  231. package/dist/release.d.ts +29 -3
  232. package/dist/release.js +13 -1
  233. package/dist/release.js.map +1 -1
  234. package/dist/replay-input-log-BvX4As2f.d.ts +31 -0
  235. package/dist/replay-input-log-Vcl0VDIy.d.cts +31 -0
  236. package/dist/room-protocol.cjs +794 -0
  237. package/dist/room-protocol.cjs.map +1 -0
  238. package/dist/room-protocol.d.cts +63 -0
  239. package/dist/room-protocol.d.ts +63 -0
  240. package/dist/room-protocol.js +143 -0
  241. package/dist/room-protocol.js.map +1 -0
  242. package/dist/room-session.cjs +2336 -0
  243. package/dist/room-session.cjs.map +1 -0
  244. package/dist/room-session.d.cts +77 -0
  245. package/dist/room-session.d.ts +77 -0
  246. package/dist/room-session.js +103 -0
  247. package/dist/room-session.js.map +1 -0
  248. package/dist/runtime/prefab-inspection-bridge.cjs +207 -0
  249. package/dist/runtime/prefab-inspection-bridge.cjs.map +1 -0
  250. package/dist/runtime/prefab-inspection-bridge.d.cts +156 -0
  251. package/dist/runtime/prefab-inspection-bridge.d.ts +156 -0
  252. package/dist/runtime/prefab-inspection-bridge.js +22 -0
  253. package/dist/runtime/prefab-inspection-bridge.js.map +1 -0
  254. package/dist/runtime-control.cjs +2150 -0
  255. package/dist/runtime-control.cjs.map +1 -0
  256. package/dist/runtime-control.d.cts +985 -0
  257. package/dist/runtime-control.d.ts +985 -0
  258. package/dist/runtime-control.js +268 -0
  259. package/dist/runtime-control.js.map +1 -0
  260. package/dist/runtime-inspection.cjs +1319 -0
  261. package/dist/runtime-inspection.cjs.map +1 -0
  262. package/dist/runtime-inspection.d.cts +555 -0
  263. package/dist/runtime-inspection.d.ts +555 -0
  264. package/dist/runtime-inspection.js +29 -0
  265. package/dist/runtime-inspection.js.map +1 -0
  266. package/dist/runtime-reporting-K_ZXpubu.d.cts +43 -0
  267. package/dist/runtime-reporting-K_ZXpubu.d.ts +43 -0
  268. package/dist/runtime-topology.cjs +2 -5
  269. package/dist/runtime-topology.cjs.map +1 -1
  270. package/dist/runtime-topology.d.cts +1 -1
  271. package/dist/runtime-topology.d.ts +1 -1
  272. package/dist/runtime-topology.js +1 -1
  273. package/dist/runtime-topology.js.map +1 -1
  274. package/dist/scoped-connector-CiiWu06D.d.ts +66 -0
  275. package/dist/scoped-connector-D7252pn0.d.cts +66 -0
  276. package/dist/sdk-channels-S6j6AH8v.d.cts +103 -0
  277. package/dist/sdk-channels-S6j6AH8v.d.ts +103 -0
  278. package/dist/simulation-BfRnC4rg.d.ts +782 -0
  279. package/dist/simulation-BwZx2pgt.d.cts +782 -0
  280. package/dist/{standard-match-phase-BucA5dYo.d.ts → standard-match-phase-D4N-AU0d.d.cts} +3 -13
  281. package/dist/{standard-match-phase-U2ra8J-0.d.cts → standard-match-phase-abt8ZjCh.d.ts} +3 -13
  282. package/dist/transport-CWF29jU6.d.cts +173 -0
  283. package/dist/transport-CWF29jU6.d.ts +173 -0
  284. package/dist/types-p28maMEo.d.cts +102 -0
  285. package/dist/types-p28maMEo.d.ts +102 -0
  286. package/dist/ui.cjs +2324 -1051
  287. package/dist/ui.cjs.map +1 -1
  288. package/dist/ui.d.cts +75 -17
  289. package/dist/ui.d.ts +75 -17
  290. package/dist/ui.js +555 -389
  291. package/dist/ui.js.map +1 -1
  292. package/package.json +88 -37
  293. package/src/agent/agent-action.ts +0 -39
  294. package/src/agent/agent-contract-conformance.ts +208 -0
  295. package/src/agent/agent-contract.ts +2 -4
  296. package/src/agent/agent-evaluator.ts +95 -0
  297. package/src/agent/capture-canvas.ts +79 -0
  298. package/src/agent/host-canvas-capture.ts +189 -0
  299. package/src/agent-tooling.ts +8 -18
  300. package/src/arcade/bridge/controller.ts +8 -11
  301. package/src/arcade/bridge/host.ts +6 -11
  302. package/src/arcade/bridge/iframe.ts +1 -50
  303. package/src/arcade/host.ts +0 -1
  304. package/src/arcade/runtime.ts +6 -0
  305. package/src/arcade/surface.ts +6 -1
  306. package/src/arcade/url.ts +2 -9
  307. package/src/audio/audio-manager.ts +23 -47
  308. package/src/audio/hooks.tsx +59 -72
  309. package/src/components/controller-player-name-field.tsx +2 -2
  310. package/src/components/controller-primary-action.tsx +1 -1
  311. package/src/components/controls.tsx +398 -0
  312. package/src/components/gamepad-layout.tsx +69 -0
  313. package/src/components/join-url-controls.tsx +5 -1
  314. package/src/components/lifecycle-action-group.tsx +1 -1
  315. package/src/components/player-avatar.tsx +50 -3
  316. package/src/components/room-qr-code.tsx +36 -77
  317. package/src/components/stage-capture-surface.tsx +91 -0
  318. package/src/components/surface-viewport.tsx +16 -3
  319. package/src/components/ui/button.tsx +1 -1
  320. package/src/constants.ts +0 -15
  321. package/src/context/air-jam-context.tsx +64 -195
  322. package/src/context/session-providers.tsx +13 -10
  323. package/src/controller-bridge.ts +7 -0
  324. package/src/core/assets.ts +48 -0
  325. package/src/core/config.ts +70 -0
  326. package/src/core/connection-store.ts +77 -0
  327. package/src/core/controller-input.ts +147 -0
  328. package/src/core/controller-runtime.ts +427 -0
  329. package/src/core/dev-events.ts +18 -0
  330. package/src/core/environment.ts +132 -0
  331. package/src/core/game-description.ts +44 -0
  332. package/src/core/game.ts +130 -0
  333. package/src/core/host-input.ts +207 -0
  334. package/src/core/host-runtime.ts +988 -0
  335. package/src/core/hosted-rooms.ts +26 -0
  336. package/src/core/input-bindings.ts +180 -0
  337. package/src/core/input-log.ts +144 -0
  338. package/src/core/input.ts +228 -0
  339. package/src/core/local-input.ts +319 -0
  340. package/src/core/replay-input-log.ts +298 -0
  341. package/src/core/replicated-store.ts +1178 -0
  342. package/src/core/room-action-ack.ts +43 -0
  343. package/src/core/settings.ts +202 -0
  344. package/src/core/simulation.ts +307 -0
  345. package/src/core/theme.ts +33 -0
  346. package/src/core.ts +162 -0
  347. package/src/dev/browser-log-sink.ts +47 -27
  348. package/src/diagnostics.ts +5 -6
  349. package/src/hooks/internal/use-controller-runtime-api.ts +58 -836
  350. package/src/hooks/internal/use-host-runtime-api.ts +98 -1013
  351. package/src/hooks/internal/use-runtime-inspection-contract.ts +14 -2
  352. package/src/hooks/use-air-jam-controller.ts +41 -62
  353. package/src/hooks/use-air-jam-host.ts +66 -107
  354. package/src/hooks/use-air-jam-settings.ts +27 -0
  355. package/src/hooks/use-controller-toasts.ts +16 -19
  356. package/src/hooks/use-host-agent-capture.ts +31 -0
  357. package/src/hooks/use-lifecycle-action-group-model.ts +1 -1
  358. package/src/hooks/use-send-signal.ts +23 -156
  359. package/src/hooks/use-simulation.ts +83 -0
  360. package/src/index.ts +26 -106
  361. package/src/lifecycle/index.ts +0 -4
  362. package/src/lifecycle/standard-match-phase.ts +1 -22
  363. package/src/metadata/manifest.ts +8 -20
  364. package/src/metadata.ts +1 -1
  365. package/src/platform-machine.ts +236 -15
  366. package/src/prefabs/types.ts +91 -20
  367. package/src/prefabs/view.ts +82 -0
  368. package/src/prefabs.ts +19 -0
  369. package/src/preview/host-workspace.tsx +4 -9
  370. package/src/preview/identity.ts +31 -23
  371. package/src/preview/layout.ts +5 -1
  372. package/src/preview/manager.ts +205 -78
  373. package/src/preview/messages.ts +47 -0
  374. package/src/preview/ownership.ts +6 -1
  375. package/src/preview/url.ts +46 -23
  376. package/src/preview/window.tsx +26 -69
  377. package/src/preview/workspace-local-seats.ts +166 -0
  378. package/src/preview/workspace.tsx +137 -66
  379. package/src/preview.ts +27 -15
  380. package/src/protocol/actions.ts +58 -0
  381. package/src/protocol/arcade-platform-actions.ts +20 -16
  382. package/src/protocol/controller.ts +15 -169
  383. package/src/protocol/core.ts +8 -15
  384. package/src/protocol/dev-log-events.ts +5 -84
  385. package/src/protocol/leased-control.ts +177 -0
  386. package/src/protocol/room/addressing.ts +35 -0
  387. package/src/protocol/room/close-codes.ts +33 -0
  388. package/src/protocol/room/frames.ts +343 -0
  389. package/src/protocol/room/input-codec.ts +182 -0
  390. package/src/protocol/room/limits.ts +58 -0
  391. package/src/protocol/room/patch.ts +135 -0
  392. package/src/protocol/room/sdk-channels.ts +81 -0
  393. package/src/protocol/room/seat-id.ts +31 -0
  394. package/src/protocol/room/transport.ts +63 -0
  395. package/src/protocol/room/weight.ts +58 -0
  396. package/src/protocol/runtime-reporting.ts +78 -0
  397. package/src/protocol/signed-envelope.ts +176 -0
  398. package/src/protocol.ts +4 -7
  399. package/src/qrcode.d.ts +3 -13
  400. package/src/release.ts +32 -0
  401. package/src/room-protocol.ts +10 -0
  402. package/src/room-session/browser-wake-events.ts +14 -0
  403. package/src/room-session/channel-state.ts +293 -0
  404. package/src/room-session/clock.ts +24 -0
  405. package/src/room-session/host-room-session.ts +379 -0
  406. package/src/room-session/input-lane.ts +125 -0
  407. package/src/room-session/listeners.ts +22 -0
  408. package/src/room-session/loopback-link.ts +58 -0
  409. package/src/room-session/phone-room-session.ts +368 -0
  410. package/src/room-session/port-link.ts +116 -0
  411. package/src/room-session/room-key.ts +9 -0
  412. package/src/room-session/roster.ts +23 -0
  413. package/src/room-session/scoped-connector.ts +577 -0
  414. package/src/room-session/session-link.ts +306 -0
  415. package/src/room-session/web-socket-link.ts +57 -0
  416. package/src/room-session.ts +12 -0
  417. package/src/runtime/air-jam-config.ts +53 -51
  418. package/src/runtime/air-jam-error-boundary.tsx +52 -2
  419. package/src/runtime/arcade-runtime-url.ts +8 -9
  420. package/src/runtime/browser-controller-environment.ts +116 -0
  421. package/src/runtime/browser-host-environment.ts +137 -0
  422. package/src/runtime/browser-replay.ts +211 -0
  423. package/src/runtime/browser-room.ts +41 -0
  424. package/src/runtime/connected-runtime-error-boundary.tsx +58 -0
  425. package/src/runtime/contracts/agent-control.ts +195 -0
  426. package/src/runtime/contracts/clip.ts +169 -0
  427. package/src/runtime/contracts/control.ts +744 -59
  428. package/src/runtime/contracts/controller-agent.ts +130 -0
  429. package/src/runtime/contracts/input-log.ts +38 -0
  430. package/src/runtime/contracts/inspection.ts +25 -22
  431. package/src/runtime/contracts/observation.ts +186 -0
  432. package/src/runtime/contracts/runtime-identity.ts +43 -0
  433. package/src/runtime/contracts/timeline.ts +59 -0
  434. package/src/runtime/controller-agent-bridge.ts +152 -0
  435. package/src/runtime/controller-bridge-context.ts +29 -0
  436. package/src/runtime/controller-capture.ts +50 -0
  437. package/src/runtime/controller-identity.ts +54 -115
  438. package/src/runtime/controller-presentation.ts +47 -17
  439. package/src/runtime/controller-press.ts +271 -0
  440. package/src/runtime/create-air-jam-app.tsx +120 -83
  441. package/src/runtime/dev-runtime-events.ts +6 -18
  442. package/src/runtime/embedded-parent.ts +22 -0
  443. package/src/runtime/embedded-runtime-adapters.ts +10 -9
  444. package/src/runtime/host-agent-bridge.ts +127 -0
  445. package/src/runtime/host-capture-boundary.tsx +92 -0
  446. package/src/runtime/host-capture-context.ts +7 -0
  447. package/src/runtime/host-clip-reader.ts +93 -0
  448. package/src/runtime/host-clip-recorder.ts +342 -0
  449. package/src/runtime/host-input-log-reader.ts +120 -0
  450. package/src/runtime/host-observation.ts +207 -0
  451. package/src/runtime/host-pace.ts +36 -0
  452. package/src/runtime/host-runtime-fault.ts +51 -0
  453. package/src/runtime/host-timeline.ts +152 -0
  454. package/src/runtime/local-players.tsx +96 -0
  455. package/src/runtime/local-reference-game-identity.ts +13 -0
  456. package/src/runtime/local-seats.ts +612 -0
  457. package/src/runtime/participant-control.ts +162 -0
  458. package/src/runtime/prefab-inspection-bridge.ts +174 -0
  459. package/src/runtime/prefab-inspection-clock.ts +12 -0
  460. package/src/runtime/prefab-inspection-context.ts +20 -0
  461. package/src/runtime/prefab-inspection-runtime.tsx +328 -0
  462. package/src/runtime/preview-inspection-bridge.ts +130 -0
  463. package/src/runtime/replay-runtime.tsx +101 -0
  464. package/src/runtime/room-bridge.ts +110 -0
  465. package/src/runtime/runtime-owner-contexts.tsx +9 -0
  466. package/src/runtime/runtime-session-params.ts +23 -86
  467. package/src/runtime/session-runtimes.tsx +231 -64
  468. package/src/runtime/stage-capture.ts +25 -0
  469. package/src/runtime-control.ts +44 -8
  470. package/src/runtime-inspection.ts +14 -7
  471. package/src/runtime-topology.ts +7 -8
  472. package/src/settings/platform-settings-runtime.tsx +48 -8
  473. package/src/settings/platform-settings.ts +0 -96
  474. package/src/store/use-air-jam-store.ts +73 -0
  475. package/src/ui.ts +3 -3
  476. package/src/utils/is-rpc-serializable.ts +11 -19
  477. package/src/utils/url-builder.ts +0 -7
  478. package/dist/arcade/bridge.cjs +0 -1067
  479. package/dist/arcade/bridge.cjs.map +0 -1
  480. package/dist/arcade/bridge.d.cts +0 -11
  481. package/dist/arcade/bridge.d.ts +0 -11
  482. package/dist/arcade/bridge.js +0 -76
  483. package/dist/arcade/bridge.js.map +0 -1
  484. package/dist/arcade-runtime-url-BW-MUAOY.d.cts +0 -28
  485. package/dist/arcade-runtime-url-l8qj01Pg.d.ts +0 -28
  486. package/dist/arcade.cjs +0 -1737
  487. package/dist/arcade.cjs.map +0 -1
  488. package/dist/arcade.d.cts +0 -18
  489. package/dist/arcade.d.ts +0 -18
  490. package/dist/arcade.js +0 -123
  491. package/dist/arcade.js.map +0 -1
  492. package/dist/capabilities.cjs +0 -39
  493. package/dist/capabilities.cjs.map +0 -1
  494. package/dist/capabilities.d.cts +0 -31
  495. package/dist/capabilities.d.ts +0 -31
  496. package/dist/capabilities.js +0 -12
  497. package/dist/capabilities.js.map +0 -1
  498. package/dist/chunk-32NYL7XI.js +0 -539
  499. package/dist/chunk-32NYL7XI.js.map +0 -1
  500. package/dist/chunk-3USU7GY2.js.map +0 -1
  501. package/dist/chunk-6CMB356F.js +0 -193
  502. package/dist/chunk-6CMB356F.js.map +0 -1
  503. package/dist/chunk-7OTQTT6H.js.map +0 -1
  504. package/dist/chunk-BE6Z4SIT.js.map +0 -1
  505. package/dist/chunk-CVYR5RJT.js +0 -184
  506. package/dist/chunk-CVYR5RJT.js.map +0 -1
  507. package/dist/chunk-DY67S3LR.js.map +0 -1
  508. package/dist/chunk-E5PVHEAX.js +0 -126
  509. package/dist/chunk-E5PVHEAX.js.map +0 -1
  510. package/dist/chunk-EDRQIOCV.js +0 -25
  511. package/dist/chunk-EDRQIOCV.js.map +0 -1
  512. package/dist/chunk-EVZJA6RN.js.map +0 -1
  513. package/dist/chunk-IKKDONQL.js +0 -1
  514. package/dist/chunk-IKKDONQL.js.map +0 -1
  515. package/dist/chunk-JO2HR5PV.js +0 -43
  516. package/dist/chunk-JO2HR5PV.js.map +0 -1
  517. package/dist/chunk-JTF47B56.js +0 -1
  518. package/dist/chunk-JTF47B56.js.map +0 -1
  519. package/dist/chunk-KOB73SPD.js +0 -216
  520. package/dist/chunk-KOB73SPD.js.map +0 -1
  521. package/dist/chunk-LIXPF4P6.js +0 -22
  522. package/dist/chunk-LIXPF4P6.js.map +0 -1
  523. package/dist/chunk-M4DKOI42.js +0 -32
  524. package/dist/chunk-M4DKOI42.js.map +0 -1
  525. package/dist/chunk-MPDMJIX5.js +0 -1
  526. package/dist/chunk-MPDMJIX5.js.map +0 -1
  527. package/dist/chunk-NCL6WJCL.js.map +0 -1
  528. package/dist/chunk-NUJBMV3O.js.map +0 -1
  529. package/dist/chunk-Q4UALQO4.js +0 -288
  530. package/dist/chunk-Q4UALQO4.js.map +0 -1
  531. package/dist/chunk-TGRTEWYV.js +0 -195
  532. package/dist/chunk-TGRTEWYV.js.map +0 -1
  533. package/dist/chunk-UWJOIVON.js.map +0 -1
  534. package/dist/chunk-W2VK36RO.js +0 -11
  535. package/dist/chunk-W2VK36RO.js.map +0 -1
  536. package/dist/chunk-X24K52DG.js.map +0 -1
  537. package/dist/chunk-YXHH3MQT.js +0 -230
  538. package/dist/chunk-YXHH3MQT.js.map +0 -1
  539. package/dist/chunk-ZLPL2R3R.js.map +0 -1
  540. package/dist/chunk-ZTQ5SP4H.js +0 -9
  541. package/dist/chunk-ZTQ5SP4H.js.map +0 -1
  542. package/dist/controller-Bod8YYr1.d.cts +0 -172
  543. package/dist/controller-DxVchfiA.d.ts +0 -172
  544. package/dist/dev-log-events-CVAM29hx.d.cts +0 -123
  545. package/dist/dev-log-events-CVAM29hx.d.ts +0 -123
  546. package/dist/handshake-CC_LrK5g.d.cts +0 -31
  547. package/dist/handshake-CC_LrK5g.d.ts +0 -31
  548. package/dist/host-8hmq_Sgc.d.cts +0 -109
  549. package/dist/host-Cw-N6e-5.d.ts +0 -109
  550. package/dist/notices-CnGaaS8B.d.ts +0 -38
  551. package/dist/notices-NyDM5Mtz.d.cts +0 -38
  552. package/dist/realtime-client-Cu8yVJFw.d.cts +0 -15
  553. package/dist/realtime-client-Cu8yVJFw.d.ts +0 -15
  554. package/dist/sync-B6QsNrXz.d.cts +0 -125
  555. package/dist/sync-B6QsNrXz.d.ts +0 -125
  556. package/src/arcade/bridge.ts +0 -3
  557. package/src/arcade.ts +0 -4
  558. package/src/capabilities/manifest.ts +0 -71
  559. package/src/capabilities.ts +0 -12
  560. package/src/context/socket-manager.ts +0 -79
  561. package/src/events.ts +0 -124
  562. package/src/hooks/internal/use-runtime-control-contract.ts +0 -15
  563. package/src/hooks/internal/use-runtime-observability-contract.ts +0 -24
  564. package/src/hooks/use-connection-status.ts +0 -8
  565. package/src/hooks/use-controller-tick.ts +0 -65
  566. package/src/hooks/use-get-input.ts +0 -100
  567. package/src/hooks/use-host-arcade-restore.ts +0 -30
  568. package/src/hooks/use-host-tick.ts +0 -171
  569. package/src/hooks/use-input-writer.ts +0 -83
  570. package/src/hooks/use-players.ts +0 -12
  571. package/src/internal/input-manager.ts +0 -356
  572. package/src/protocol/errors.ts +0 -21
  573. package/src/protocol/host-grant.ts +0 -185
  574. package/src/protocol/host.ts +0 -138
  575. package/src/protocol/notices.ts +0 -43
  576. package/src/protocol/signals.ts +0 -38
  577. package/src/protocol/socket-events.ts +0 -154
  578. package/src/protocol/sync.ts +0 -121
  579. package/src/runtime/contracts/observability.ts +0 -94
  580. package/src/runtime/controller-bridge.ts +0 -451
  581. package/src/runtime/controller-realtime-client.ts +0 -591
  582. package/src/runtime/host-bridge.ts +0 -388
  583. package/src/runtime/host-realtime-client.ts +0 -550
  584. package/src/runtime/realtime-client.ts +0 -20
  585. package/src/runtime/validate-arcade-bridge-attach.ts +0 -14
  586. package/src/runtime-observability.ts +0 -9
  587. package/src/state/connection-store.ts +0 -152
  588. package/src/store/create-air-jam-store.ts +0 -1141
  589. package/src/store/index.ts +0 -1
  590. package/src/utils/ids.ts +0 -31
@@ -20,35 +20,901 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/arcade/bridge/host.ts
21
21
  var host_exports = {};
22
22
  __export(host_exports, {
23
- AIRJAM_HOST_BRIDGE_EVENT: () => AIRJAM_HOST_BRIDGE_EVENT,
24
- AIRJAM_HOST_BRIDGE_RESPONSE: () => AIRJAM_HOST_BRIDGE_RESPONSE,
25
- createHostBridgeAttachMessage: () => createHostBridgeAttachMessage,
26
- createHostBridgeCloseMessage: () => createHostBridgeCloseMessage,
27
- createHostBridgeResponseMessage: () => createHostBridgeResponseMessage,
28
- parseHostBridgeEmitMessage: () => parseHostBridgeEmitMessage,
29
- parseHostBridgeRequestMessage: () => parseHostBridgeRequestMessage,
30
- parseHostBridgeResponseMessage: () => parseHostBridgeResponseMessage
23
+ createScopedHostConnector: () => createScopedHostConnector,
24
+ readRoomBridgeRequest: () => readRoomBridgeRequest,
25
+ refuseRoomBridge: () => refuseRoomBridge,
26
+ serveRoomPort: () => serveRoomPort
31
27
  });
32
28
  module.exports = __toCommonJS(host_exports);
33
29
 
34
- // src/runtime/host-bridge.ts
30
+ // src/room-session/port-link.ts
31
+ var import_zod6 = require("zod");
32
+
33
+ // src/protocol/room/addressing.ts
34
+ var import_zod = require("zod");
35
+ var roomCodeSchema = import_zod.z.string().regex(/^[A-Z0-9]{4,8}$/);
36
+
37
+ // src/protocol/room/close-codes.ts
38
+ var roomCloseCodes = {
39
+ replaced: { code: 4e3, terminal: true },
40
+ removed: { code: 4001, terminal: true },
41
+ left: { code: 4002, terminal: true },
42
+ closed: { code: 4003, terminal: true },
43
+ "not-found": { code: 4004, terminal: true },
44
+ full: { code: 4005, terminal: true },
45
+ unauthorised: { code: 4006, terminal: true },
46
+ "unsupported-version": { code: 4007, terminal: true },
47
+ "limits-broken": { code: 4008, terminal: true },
48
+ restarting: { code: 4100, terminal: false },
49
+ "try-later": { code: 4101, terminal: false }
50
+ };
51
+
52
+ // src/protocol/room/frames.ts
53
+ var import_zod4 = require("zod");
54
+
55
+ // src/protocol/room/limits.ts
56
+ var import_zod2 = require("zod");
57
+ var MAXIMUM_ROOM_SEATS = 16;
58
+ var count = import_zod2.z.number().int().positive();
59
+ var duration = import_zod2.z.number().int().nonnegative();
60
+ var roomLimitsShape = {
61
+ seats: count.max(MAXIMUM_ROOM_SEATS),
62
+ channels: count,
63
+ /** How often a phone may send its controls; phones coalesce to it. */
64
+ inputIntervalMs: count,
65
+ /** One phone's whole control state; a host input record states its length in one byte. */
66
+ inputBytes: count.max(255),
67
+ inputsPerSecond: count,
68
+ /** The most a channel's document, or any one state frame, may weigh. */
69
+ stateBytes: count,
70
+ statesPerSecond: count,
71
+ /** The most any other text frame may weigh. */
72
+ frameBytes: count,
73
+ /** Text frames other than state, per connection. */
74
+ framesPerSecond: count,
75
+ /** Frames that do not parse, within one second, before the connection is closed. */
76
+ strikesPerSecond: count,
77
+ seatHoldMs: duration,
78
+ /** How long the room waits for its host, as it opens and after the host's connection ends. */
79
+ hostGraceMs: count,
80
+ maximumAgeMs: count
81
+ };
82
+ var roomLimitsSchema = import_zod2.z.strictObject(roomLimitsShape);
83
+ var roomLimitsWireSchema = import_zod2.z.object(roomLimitsShape);
84
+ var DEFAULT_ROOM_LIMITS = Object.freeze({
85
+ seats: MAXIMUM_ROOM_SEATS,
86
+ channels: 8,
87
+ inputIntervalMs: 16,
88
+ inputBytes: 64,
89
+ inputsPerSecond: 120,
90
+ stateBytes: 65536,
91
+ statesPerSecond: 60,
92
+ frameBytes: 8192,
93
+ framesPerSecond: 60,
94
+ strikesPerSecond: 64,
95
+ seatHoldMs: 12e4,
96
+ hostGraceMs: 6e4,
97
+ maximumAgeMs: 24 * 60 * 60 * 1e3
98
+ });
99
+
100
+ // src/protocol/room/patch.ts
101
+ var isPlainObject = (value) => {
102
+ if (typeof value !== "object" || value === null || Array.isArray(value))
103
+ return false;
104
+ const prototype = Object.getPrototypeOf(value);
105
+ return prototype === Object.prototype || prototype === null;
106
+ };
107
+ var ownValue = (object, key) => Object.hasOwn(object, key) ? object[key] : void 0;
108
+ var isEmptyStatePatch = (patch) => patch.set.length === 0 && patch.unset.length === 0;
109
+ var defineEntry = (object, key, value) => Object.defineProperty(object, key, {
110
+ value,
111
+ writable: true,
112
+ enumerable: true,
113
+ configurable: true
114
+ });
115
+ var applyStatePatch = (document, patch, replaced) => {
116
+ if (isEmptyStatePatch(patch)) return document;
117
+ const copies = /* @__PURE__ */ new Set();
118
+ const writable = (object) => {
119
+ if (copies.has(object)) return object;
120
+ const copy = { ...object };
121
+ copies.add(copy);
122
+ return copy;
123
+ };
124
+ const root = writable(document);
125
+ const parentOf = (path) => {
126
+ let parent = root;
127
+ for (const key of path.slice(0, -1)) {
128
+ const child = ownValue(parent, key);
129
+ if (!isPlainObject(child)) return null;
130
+ const copy = writable(child);
131
+ if (copy !== child) defineEntry(parent, key, copy);
132
+ parent = copy;
133
+ }
134
+ return parent;
135
+ };
136
+ for (const path of patch.unset) {
137
+ const key = path.at(-1);
138
+ const parent = parentOf(path);
139
+ if (key === void 0 || !parent || !Object.hasOwn(parent, key))
140
+ return null;
141
+ replaced?.(key, ownValue(parent, key), void 0);
142
+ delete parent[key];
143
+ }
144
+ for (const [path, value] of patch.set) {
145
+ const key = path.at(-1);
146
+ const parent = parentOf(path);
147
+ if (key === void 0 || !parent) return null;
148
+ replaced?.(key, ownValue(parent, key), value);
149
+ defineEntry(parent, key, value);
150
+ }
151
+ return root;
152
+ };
153
+
154
+ // src/protocol/room/seat-id.ts
155
+ var import_zod3 = require("zod");
156
+ var MAXIMUM_SEAT_NUMBER = 65535;
157
+ var seatIdSchema = import_zod3.z.string().regex(/^p[1-9][0-9]{0,4}$/);
158
+ var seatIdFromNumber = (seatNumber) => {
159
+ if (!Number.isInteger(seatNumber) || seatNumber < 1 || seatNumber > MAXIMUM_SEAT_NUMBER)
160
+ throw new Error(`Seat number ${seatNumber} is out of range.`);
161
+ return `p${seatNumber}`;
162
+ };
163
+ var seatNumberFromId = (seatId) => {
164
+ const seatNumber = Number(seatId.slice(1));
165
+ if (!seatIdSchema.safeParse(seatId).success || seatNumber > MAXIMUM_SEAT_NUMBER)
166
+ throw new Error(`"${seatId}" is not a seat id.`);
167
+ return seatNumber;
168
+ };
169
+
170
+ // src/protocol/room/frames.ts
171
+ var PING_FRAME = "ping";
172
+ var PONG_FRAME = "pong";
173
+ var MAXIMUM_FRAME_DEPTH = 32;
174
+ var keySchema = import_zod4.z.string().min(16).max(128);
175
+ var instanceSchema = import_zod4.z.string().min(1).max(64);
176
+ var channelSchema = import_zod4.z.string().min(1).max(128);
177
+ var revisionSchema = import_zod4.z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
178
+ var requestIdSchema = import_zod4.z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
179
+ var featuresSchema = import_zod4.z.array(import_zod4.z.string().min(1).max(64)).max(32);
180
+ var documentSchema = import_zod4.z.custom(isPlainObject, {
181
+ message: "A state document is a plain JSON object."
182
+ });
183
+ var pathSchema = import_zod4.z.array(import_zod4.z.string()).min(1).max(32);
184
+ var seatKindSchema = import_zod4.z.enum(["phone", "preview", "agent"]);
185
+ var seatProfileSchema = import_zod4.z.object({
186
+ label: import_zod4.z.string().trim().min(1).max(24).optional(),
187
+ avatarId: import_zod4.z.string().trim().min(1).max(48).optional(),
188
+ /** Shown instead of the label while a local seat plays through this phone. */
189
+ localSeatLabel: import_zod4.z.string().trim().min(1).max(32).optional()
190
+ });
191
+ var helloFields = {
192
+ type: import_zod4.z.literal("hello"),
193
+ key: keySchema,
194
+ instance: instanceSchema.optional(),
195
+ sdk: import_zod4.z.string().min(1).max(64),
196
+ features: featuresSchema.optional()
197
+ };
198
+ var hostHelloSchema = import_zod4.z.object({
199
+ ...helloFields,
200
+ /** Opaque to the room; the gate reads it before the room opens. */
201
+ credential: import_zod4.z.string().min(1).max(8192).optional(),
202
+ /** How many players the game takes; the room admits no more. */
203
+ seats: import_zod4.z.number().int().min(1).max(MAXIMUM_ROOM_SEATS)
204
+ });
205
+ var phoneHelloSchema = import_zod4.z.object({
206
+ ...helloFields,
207
+ kind: seatKindSchema,
208
+ profile: seatProfileSchema.optional(),
209
+ /**
210
+ * The page this phone runs in, the same across its reconnects. A seat
211
+ * resumed from another page (a reload, or another tab taking it over)
212
+ * starts its controls afresh, so the host takes a new input baseline.
213
+ */
214
+ page: import_zod4.z.string().min(1).max(64).optional()
215
+ });
216
+ var statePatchFields = {
217
+ type: import_zod4.z.literal("state"),
218
+ channel: channelSchema,
219
+ revision: revisionSchema,
220
+ base: revisionSchema,
221
+ set: import_zod4.z.array(import_zod4.z.tuple([pathSchema, import_zod4.z.unknown()])).default([]),
222
+ unset: import_zod4.z.array(pathSchema).default([])
223
+ };
224
+ var stateDocumentFields = {
225
+ type: import_zod4.z.literal("state"),
226
+ channel: channelSchema,
227
+ revision: revisionSchema,
228
+ document: documentSchema
229
+ };
230
+ var hostStateFrameSchema = import_zod4.z.union([
231
+ import_zod4.z.object({
232
+ ...stateDocumentFields,
233
+ /** The store's shape, so a reloading host knows whether to take its state back. */
234
+ fingerprint: import_zod4.z.string().min(1).max(256).optional(),
235
+ /** A top-level field keyed by seat whose entries only their own seat sees. */
236
+ private: import_zod4.z.string().min(1).max(128).optional()
237
+ }),
238
+ import_zod4.z.object(statePatchFields).refine(
239
+ (frame) => frame.revision > frame.base,
240
+ "A patch produces a later revision than its base."
241
+ )
242
+ ]);
243
+ var hostToRoomFrameSchemas = {
244
+ state: hostStateFrameSchema,
245
+ response: import_zod4.z.object({
246
+ type: import_zod4.z.literal("response"),
247
+ seat: seatIdSchema,
248
+ id: requestIdSchema,
249
+ result: import_zod4.z.unknown().optional()
250
+ }),
251
+ signal: import_zod4.z.object({
252
+ type: import_zod4.z.literal("signal"),
253
+ seat: seatIdSchema.optional(),
254
+ kind: import_zod4.z.string().min(1).max(64),
255
+ payload: import_zod4.z.unknown().optional()
256
+ }),
257
+ room: import_zod4.z.object({
258
+ type: import_zod4.z.literal("room"),
259
+ seats: import_zod4.z.number().int().min(1).max(MAXIMUM_ROOM_SEATS).optional(),
260
+ locked: import_zod4.z.boolean().optional()
261
+ }),
262
+ remove: import_zod4.z.object({ type: import_zod4.z.literal("remove"), seat: seatIdSchema }),
263
+ drop: import_zod4.z.object({ type: import_zod4.z.literal("drop"), channel: channelSchema }),
264
+ activity: import_zod4.z.object({
265
+ type: import_zod4.z.literal("activity"),
266
+ activity: import_zod4.z.string().min(1).max(128).nullable()
267
+ }),
268
+ end: import_zod4.z.object({ type: import_zod4.z.literal("end") })
269
+ };
270
+ var phoneToRoomFrameSchemas = {
271
+ request: import_zod4.z.object({
272
+ type: import_zod4.z.literal("request"),
273
+ id: requestIdSchema,
274
+ channel: channelSchema,
275
+ name: import_zod4.z.string().min(1).max(128),
276
+ payload: import_zod4.z.unknown().optional()
277
+ }),
278
+ profile: import_zod4.z.object({
279
+ type: import_zod4.z.literal("profile"),
280
+ label: seatProfileSchema.shape.label,
281
+ avatarId: seatProfileSchema.shape.avatarId
282
+ }).refine(
283
+ (frame) => frame.label !== void 0 || frame.avatarId !== void 0,
284
+ "A profile change names a label or an avatar."
285
+ ),
286
+ leave: import_zod4.z.object({ type: import_zod4.z.literal("leave") }),
287
+ /** This seat's controls start again from zero, as a newly loaded controller frame's do. */
288
+ baseline: import_zod4.z.object({ type: import_zod4.z.literal("baseline") })
289
+ };
290
+ var seatViewSchema = import_zod4.z.object({
291
+ id: seatIdSchema,
292
+ label: import_zod4.z.string(),
293
+ color: import_zod4.z.string(),
294
+ avatarId: import_zod4.z.string().optional(),
295
+ kind: seatKindSchema,
296
+ connected: import_zod4.z.boolean()
297
+ });
298
+ var channelCopySchema = import_zod4.z.object({
299
+ channel: channelSchema,
300
+ revision: revisionSchema,
301
+ document: documentSchema,
302
+ fingerprint: import_zod4.z.string().optional(),
303
+ private: import_zod4.z.string().optional()
304
+ });
305
+ var welcomeFields = {
306
+ type: import_zod4.z.literal("welcome"),
307
+ code: import_zod4.z.string(),
308
+ instance: instanceSchema,
309
+ seats: import_zod4.z.array(seatViewSchema),
310
+ channels: import_zod4.z.array(channelCopySchema),
311
+ limits: roomLimitsWireSchema,
312
+ features: featuresSchema
313
+ };
314
+ var roomStateFrameSchema = import_zod4.z.union([
315
+ import_zod4.z.object(stateDocumentFields),
316
+ import_zod4.z.object(statePatchFields)
317
+ ]);
318
+ var roomToHostFrameSchemas = {
319
+ welcome: import_zod4.z.object({
320
+ ...welcomeFields,
321
+ /** Seats the room admits, and whether it admits new players at all. */
322
+ seatsWanted: import_zod4.z.number().int().min(1).max(MAXIMUM_ROOM_SEATS),
323
+ locked: import_zod4.z.boolean(),
324
+ activity: import_zod4.z.string().nullable()
325
+ }),
326
+ wait: import_zod4.z.object({
327
+ type: import_zod4.z.literal("wait"),
328
+ position: import_zod4.z.number().int().positive()
329
+ }),
330
+ seat: import_zod4.z.object({
331
+ type: import_zod4.z.literal("seat"),
332
+ seat: seatViewSchema,
333
+ /** The seat's controls restart from a new page: decode them afresh. */
334
+ inputBaseline: import_zod4.z.literal(true).optional()
335
+ }),
336
+ left: import_zod4.z.object({ type: import_zod4.z.literal("left"), seat: seatIdSchema }),
337
+ need: import_zod4.z.object({ type: import_zod4.z.literal("need"), channel: channelSchema }),
338
+ request: import_zod4.z.object({
339
+ type: import_zod4.z.literal("request"),
340
+ seat: seatIdSchema,
341
+ id: requestIdSchema,
342
+ channel: channelSchema,
343
+ name: import_zod4.z.string(),
344
+ payload: import_zod4.z.unknown().optional()
345
+ })
346
+ };
347
+ var roomToPhoneFrameSchemas = {
348
+ welcome: import_zod4.z.object({
349
+ ...welcomeFields,
350
+ seat: seatIdSchema,
351
+ host: import_zod4.z.boolean()
352
+ }),
353
+ seat: roomToHostFrameSchemas.seat,
354
+ left: roomToHostFrameSchemas.left,
355
+ host: import_zod4.z.object({ type: import_zod4.z.literal("host"), present: import_zod4.z.boolean() }),
356
+ state: roomStateFrameSchema,
357
+ drop: hostToRoomFrameSchemas.drop,
358
+ // The refusal comes first: a result may be absent, so the other branch
359
+ // would accept a refusal and strip what it says.
360
+ response: import_zod4.z.union([
361
+ import_zod4.z.object({
362
+ type: import_zod4.z.literal("response"),
363
+ id: requestIdSchema,
364
+ /** The room answered itself because no host could. */
365
+ refused: import_zod4.z.literal("host-away")
366
+ }),
367
+ import_zod4.z.object({
368
+ type: import_zod4.z.literal("response"),
369
+ id: requestIdSchema,
370
+ result: import_zod4.z.unknown().optional()
371
+ })
372
+ ]),
373
+ signal: import_zod4.z.object({
374
+ type: import_zod4.z.literal("signal"),
375
+ kind: import_zod4.z.string(),
376
+ payload: import_zod4.z.unknown().optional()
377
+ })
378
+ };
379
+ var nestsWithin = (value, depth) => {
380
+ if (typeof value !== "object" || value === null) return true;
381
+ if (depth === 0) return false;
382
+ for (const child of Object.values(value))
383
+ if (!nestsWithin(child, depth - 1)) return false;
384
+ return true;
385
+ };
386
+ var TOO_DEEP = /* @__PURE__ */ Symbol("too deep");
387
+ var parseJson = (text) => {
388
+ let value;
389
+ try {
390
+ value = JSON.parse(text);
391
+ } catch {
392
+ return void 0;
393
+ }
394
+ return nestsWithin(value, MAXIMUM_FRAME_DEPTH) ? value : TOO_DEEP;
395
+ };
396
+ var readType = (value) => isPlainObject(value) && typeof value.type === "string" ? value.type : null;
397
+ var createFrameParser = (schemas) => (text) => {
398
+ const value = parseJson(text);
399
+ if (value === TOO_DEEP) return { status: "too-deep" };
400
+ const type = readType(value);
401
+ if (type === null) return { status: "invalid" };
402
+ if (!Object.hasOwn(schemas, type)) return { status: "unknown" };
403
+ const parsed = schemas[type].safeParse(value);
404
+ return parsed.success ? { status: "frame", frame: parsed.data } : { status: "invalid" };
405
+ };
406
+ var parseHostToRoomFrame = createFrameParser(hostToRoomFrameSchemas);
407
+ var parsePhoneToRoomFrame = createFrameParser(phoneToRoomFrameSchemas);
408
+ var parseRoomToHostFrame = createFrameParser(roomToHostFrameSchemas);
409
+ var parseRoomToPhoneFrame = createFrameParser(roomToPhoneFrameSchemas);
410
+ var createHelloParser = (schema) => (text) => {
411
+ const parsed = schema.safeParse(parseJson(text));
412
+ return parsed.success ? parsed.data : null;
413
+ };
414
+ var parseHostHello = createHelloParser(hostHelloSchema);
415
+ var parsePhoneHello = createHelloParser(phoneHelloSchema);
416
+ var encodeFrame = (frame) => JSON.stringify(frame);
417
+
418
+ // src/protocol/room/input-codec.ts
419
+ var INPUT_FRAME_KIND = 1;
420
+ var RECORD_HEADER_BYTES = 3;
421
+ var encodePhoneInputFrame = (payload) => {
422
+ const frame = new Uint8Array(1 + payload.byteLength);
423
+ frame[0] = INPUT_FRAME_KIND;
424
+ frame.set(payload, 1);
425
+ return frame;
426
+ };
427
+ var encodeHostInputFrame = (seat, phoneFrame) => {
428
+ const payloadLength = phoneFrame.byteLength - 1;
429
+ const seatNumber = seatNumberFromId(seat);
430
+ const frame = new Uint8Array(1 + RECORD_HEADER_BYTES + payloadLength);
431
+ frame[0] = INPUT_FRAME_KIND;
432
+ frame[1] = seatNumber >> 8;
433
+ frame[2] = seatNumber & 255;
434
+ frame[3] = payloadLength;
435
+ frame.set(phoneFrame.subarray(1), 1 + RECORD_HEADER_BYTES);
436
+ return frame;
437
+ };
438
+ var joinHostInputFrames = (frames) => {
439
+ const records = frames.reduce(
440
+ (length, frame) => length + frame.byteLength - 1,
441
+ 0
442
+ );
443
+ const joined = new Uint8Array(1 + records);
444
+ joined[0] = INPUT_FRAME_KIND;
445
+ let offset = 1;
446
+ for (const frame of frames) {
447
+ joined.set(frame.subarray(1), offset);
448
+ offset += frame.byteLength - 1;
449
+ }
450
+ return joined;
451
+ };
452
+ var decodeHostInputFrame = (frame) => {
453
+ if (frame[0] !== INPUT_FRAME_KIND) throw new Error("Not an input frame.");
454
+ const records = [];
455
+ let offset = 1;
456
+ while (offset < frame.byteLength) {
457
+ if (offset + RECORD_HEADER_BYTES > frame.byteLength)
458
+ throw new Error("Truncated input record header.");
459
+ const seatNumber = (frame[offset] ?? 0) << 8 | (frame[offset + 1] ?? 0);
460
+ const length = frame[offset + 2] ?? 0;
461
+ const start = offset + RECORD_HEADER_BYTES;
462
+ if (start + length > frame.byteLength)
463
+ throw new Error("Truncated input record.");
464
+ records.push({
465
+ seat: seatIdFromNumber(seatNumber),
466
+ payload: frame.subarray(start, start + length)
467
+ });
468
+ offset = start + length;
469
+ }
470
+ return records;
471
+ };
472
+
473
+ // src/protocol/room/sdk-channels.ts
35
474
  var import_zod5 = require("zod");
475
+ var runtimeStateSchema = import_zod5.z.enum(["paused", "playing"]);
476
+ var controllerOrientationSchema = import_zod5.z.enum(["portrait", "landscape"]);
477
+ var presentationDocumentSchema = import_zod5.z.object({
478
+ runtimeState: runtimeStateSchema,
479
+ orientation: controllerOrientationSchema
480
+ });
481
+ var presentationRequestSchema = import_zod5.z.enum(["pause", "resume"]);
482
+ var hapticSignalPayloadSchema = import_zod5.z.object({
483
+ pattern: import_zod5.z.enum(["light", "medium", "heavy", "success", "failure", "custom"]),
484
+ sequence: import_zod5.z.union([import_zod5.z.number().nonnegative(), import_zod5.z.array(import_zod5.z.number().nonnegative())]).optional()
485
+ });
486
+ var toastSignalPayloadSchema = import_zod5.z.object({
487
+ message: import_zod5.z.string(),
488
+ color: import_zod5.z.string().optional(),
489
+ duration: import_zod5.z.number().nonnegative().optional()
490
+ });
491
+ var soundSignalPayloadSchema = import_zod5.z.object({
492
+ soundId: import_zod5.z.string().min(1),
493
+ volume: import_zod5.z.number().min(0).max(1).optional(),
494
+ loop: import_zod5.z.boolean().optional()
495
+ });
496
+
497
+ // src/protocol/room/transport.ts
498
+ var ABNORMAL_CLOSE_CODE = 1006;
499
+
500
+ // src/room-session/port-link.ts
501
+ var wireDataSchema = import_zod6.z.union([
502
+ import_zod6.z.string(),
503
+ import_zod6.z.custom((value) => value instanceof Uint8Array)
504
+ ]);
505
+ var linkIdSchema = import_zod6.z.number().int().positive();
506
+ var addressSchema = import_zod6.z.discriminatedUnion("role", [
507
+ import_zod6.z.object({ role: import_zod6.z.literal("host"), code: roomCodeSchema.nullable() }),
508
+ import_zod6.z.object({ role: import_zod6.z.literal("phone"), code: roomCodeSchema })
509
+ ]);
510
+ var toParentSchema = import_zod6.z.union([
511
+ import_zod6.z.object({ link: linkIdSchema, open: addressSchema }),
512
+ import_zod6.z.object({ link: linkIdSchema, data: wireDataSchema }),
513
+ import_zod6.z.object({ link: linkIdSchema, close: import_zod6.z.literal(true) })
514
+ ]);
515
+ var toFrameSchema = import_zod6.z.union([
516
+ import_zod6.z.object({ link: linkIdSchema, opened: import_zod6.z.literal(true) }),
517
+ import_zod6.z.object({ link: linkIdSchema, data: wireDataSchema }),
518
+ import_zod6.z.object({ link: linkIdSchema, closed: import_zod6.z.number().int() })
519
+ ]);
520
+ var serveRoomPort = (port, connector) => {
521
+ const links = /* @__PURE__ */ new Map();
522
+ const post = (message) => port.postMessage(message);
523
+ const onMessage = (event) => {
524
+ const parsed = toParentSchema.safeParse(event.data);
525
+ if (!parsed.success) return;
526
+ const message = parsed.data;
527
+ if ("open" in message) {
528
+ if (links.has(message.link)) return;
529
+ const id = message.link;
530
+ links.set(
531
+ id,
532
+ connector(message.open, {
533
+ open: () => post({ link: id, opened: true }),
534
+ message: (data) => post({ link: id, data }),
535
+ close: (code) => {
536
+ links.delete(id);
537
+ post({ link: id, closed: code });
538
+ }
539
+ })
540
+ );
541
+ } else if ("data" in message) links.get(message.link)?.send(message.data);
542
+ else {
543
+ links.get(message.link)?.close();
544
+ links.delete(message.link);
545
+ }
546
+ };
547
+ port.addEventListener("message", onMessage);
548
+ port.start();
549
+ return () => {
550
+ port.removeEventListener("message", onMessage);
551
+ for (const link of links.values()) link.close();
552
+ links.clear();
553
+ };
554
+ };
555
+
556
+ // src/room-session/channel-state.ts
557
+ var ChannelMirror = class {
558
+ copies = /* @__PURE__ */ new Map();
559
+ reset(copies) {
560
+ this.copies.clear();
561
+ for (const copy of copies)
562
+ this.copies.set(copy.channel, { copy, diverged: false });
563
+ }
564
+ /** The channel's new document, or null when the frame did not apply. */
565
+ receive(frame) {
566
+ if ("document" in frame) {
567
+ this.copies.set(frame.channel, {
568
+ copy: {
569
+ channel: frame.channel,
570
+ revision: frame.revision,
571
+ document: frame.document,
572
+ ..."fingerprint" in frame && frame.fingerprint !== void 0 ? { fingerprint: frame.fingerprint } : {},
573
+ ..."private" in frame && frame.private !== void 0 ? { private: frame.private } : {}
574
+ },
575
+ diverged: false
576
+ });
577
+ return frame.document;
578
+ }
579
+ const held = this.copies.get(frame.channel);
580
+ if (!held || held.diverged) return null;
581
+ const next = held.copy.revision === frame.base ? applyStatePatch(held.copy.document, frame) : null;
582
+ if (!next) {
583
+ held.diverged = true;
584
+ return null;
585
+ }
586
+ held.copy = { ...held.copy, revision: frame.revision, document: next };
587
+ return next;
588
+ }
589
+ drop(channel) {
590
+ return this.copies.delete(channel);
591
+ }
592
+ document(channel) {
593
+ return this.copies.get(channel)?.copy.document;
594
+ }
595
+ copy(channel) {
596
+ return this.copies.get(channel)?.copy;
597
+ }
598
+ documents() {
599
+ return new Map(
600
+ [...this.copies].map(([channel, held]) => [channel, held.copy.document])
601
+ );
602
+ }
603
+ };
604
+
605
+ // src/room-session/scoped-connector.ts
606
+ var MAXIMUM_FORWARDED_REQUESTS = 1024;
607
+ var closeCode = (reason) => roomCloseCodes[reason].code;
608
+ var FrameLink = class {
609
+ constructor(handlers) {
610
+ this.handlers = handlers;
611
+ queueMicrotask(() => {
612
+ if (!this.clientClosed) handlers.open();
613
+ });
614
+ }
615
+ clientClosed = false;
616
+ serverClosed = false;
617
+ welcomed = false;
618
+ get live() {
619
+ return !this.clientClosed && !this.serverClosed;
620
+ }
621
+ send(data) {
622
+ if (!this.live) return;
623
+ const delivered = typeof data === "string" ? data : data.slice();
624
+ queueMicrotask(() => {
625
+ if (!this.clientClosed) this.handlers.message(delivered);
626
+ });
627
+ }
628
+ close(code) {
629
+ if (!this.live) return;
630
+ this.serverClosed = true;
631
+ queueMicrotask(() => {
632
+ if (!this.clientClosed) this.handlers.close(code);
633
+ });
634
+ }
635
+ clientClose() {
636
+ this.clientClosed = true;
637
+ }
638
+ };
639
+ var FrameLinks = class {
640
+ constructor(welcome) {
641
+ this.welcome = welcome;
642
+ }
643
+ links = /* @__PURE__ */ new Set();
644
+ stopped = false;
645
+ add(link) {
646
+ this.links.add(link);
647
+ }
648
+ remove(link) {
649
+ this.links.delete(link);
650
+ }
651
+ welcomed() {
652
+ return [...this.links].filter((link) => link.live && link.welcomed);
653
+ }
654
+ /**
655
+ * A frame has one link at a time, as a host has one connection: welcoming
656
+ * a link closes every other as `replaced`, which tells the frame it held
657
+ * not to come back. A reloaded or slow-closing old frame then cannot
658
+ * publish over the new one or send input for the same seat.
659
+ */
660
+ replaceOthers(link) {
661
+ for (const other of [...this.links]) {
662
+ if (other === link) continue;
663
+ other.close(closeCode("replaced"));
664
+ this.links.delete(other);
665
+ }
666
+ }
667
+ /**
668
+ * The page's session changed status. While it is away, welcomed links are
669
+ * lost and reconnect, and hellos wait; when it is back, waiting hellos are
670
+ * answered; when it closed for good, so does every link.
671
+ */
672
+ follow(status, waiting) {
673
+ if (status.phase === "closed")
674
+ return this.closeAll(
675
+ closeCode(status.reason === "owner" ? "closed" : status.reason)
676
+ );
677
+ for (const link of [...this.links]) {
678
+ if (!link.live) {
679
+ this.links.delete(link);
680
+ continue;
681
+ }
682
+ if (status.phase !== "open") {
683
+ if (link.welcomed) {
684
+ link.close(ABNORMAL_CLOSE_CODE);
685
+ this.links.delete(link);
686
+ }
687
+ } else if (!link.welcomed && waiting(link)) this.welcome(link);
688
+ }
689
+ }
690
+ closeAll(code) {
691
+ this.stopped = true;
692
+ for (const link of this.links) link.close(code);
693
+ this.links.clear();
694
+ }
695
+ get closed() {
696
+ return this.stopped;
697
+ }
698
+ };
699
+ var rosterChanges = (told, seats) => {
700
+ const frames = [];
701
+ const current = /* @__PURE__ */ new Set();
702
+ for (const seat of seats) {
703
+ current.add(seat.id);
704
+ if (JSON.stringify(told.get(seat.id)) === JSON.stringify(seat)) continue;
705
+ told.set(seat.id, seat);
706
+ frames.push({ type: "seat", seat });
707
+ }
708
+ for (const id of [...told.keys()])
709
+ if (!current.has(id)) {
710
+ told.delete(id);
711
+ frames.push({ type: "left", seat: id });
712
+ }
713
+ return frames;
714
+ };
715
+ var rosterOf = (seats) => new Map(seats.map((seat) => [seat.id, seat]));
716
+ var createScopedHostConnector = (parent, scope) => {
717
+ const hellos = /* @__PURE__ */ new WeakMap();
718
+ const mirrors = /* @__PURE__ */ new WeakMap();
719
+ const toldSeats = /* @__PURE__ */ new WeakMap();
720
+ const latestInput = /* @__PURE__ */ new Map();
721
+ const forwarded = /* @__PURE__ */ new Set();
722
+ const welcome = (link) => {
723
+ const seats = hellos.get(link);
724
+ const room = parent.room;
725
+ const instance = parent.instance;
726
+ const code = parent.code;
727
+ if (seats === void 0 || !room || !instance || !code) return;
728
+ if (seats !== room.seatsWanted) parent.configure({ seats });
729
+ const channels = parent.channels().filter((copy) => scope(copy.channel)).map((copy) => ({ ...copy, revision: 0 }));
730
+ const mirror = new ChannelMirror();
731
+ mirror.reset(channels);
732
+ mirrors.set(link, mirror);
733
+ toldSeats.set(link, rosterOf(parent.seats));
734
+ links.replaceOthers(link);
735
+ link.welcomed = true;
736
+ link.send(
737
+ encodeFrame({
738
+ type: "welcome",
739
+ code,
740
+ instance,
741
+ seats: [...parent.seats],
742
+ channels,
743
+ limits: parent.limits,
744
+ features: [...room.features],
745
+ seatsWanted: seats,
746
+ locked: room.locked,
747
+ activity: room.activity
748
+ })
749
+ );
750
+ if (latestInput.size > 0)
751
+ link.send(
752
+ joinHostInputFrames(
753
+ [...latestInput].map(
754
+ ([seat, payload]) => encodeHostInputFrame(seat, encodePhoneInputFrame(payload))
755
+ )
756
+ )
757
+ );
758
+ };
759
+ const links = new FrameLinks(welcome);
760
+ const forward = (frame) => {
761
+ const data = encodeFrame(frame);
762
+ for (const link of links.welcomed()) link.send(data);
763
+ };
764
+ const releases = [
765
+ parent.on(
766
+ "status",
767
+ (status) => links.follow(status, (link) => hellos.has(link))
768
+ ),
769
+ parent.on("seats", (seats) => {
770
+ const present = new Set(seats.map((seat) => seat.id));
771
+ for (const seat of [...latestInput.keys()])
772
+ if (!present.has(seat)) latestInput.delete(seat);
773
+ for (const entry of [...forwarded])
774
+ if (!present.has(entry.slice(0, entry.indexOf(":"))))
775
+ forwarded.delete(entry);
776
+ for (const link of links.welcomed()) {
777
+ const told = toldSeats.get(link);
778
+ if (!told) continue;
779
+ for (const frame of rosterChanges(told, seats))
780
+ link.send(encodeFrame(frame));
781
+ }
782
+ }),
783
+ // A seat's new page restarts its controls: the frame decodes them afresh too.
784
+ parent.on("inputBaseline", (seat) => {
785
+ latestInput.delete(seat);
786
+ const view = parent.seats.find((candidate) => candidate.id === seat);
787
+ if (view) forward({ type: "seat", seat: view, inputBaseline: true });
788
+ }),
789
+ parent.on("inputFrame", (frame) => {
790
+ let records;
791
+ try {
792
+ records = decodeHostInputFrame(frame);
793
+ } catch {
794
+ return;
795
+ }
796
+ for (const record of records)
797
+ latestInput.set(record.seat, record.payload.slice());
798
+ for (const link of links.welcomed()) link.send(frame);
799
+ }),
800
+ parent.on("request", (request) => {
801
+ if (!scope(request.channel) || links.welcomed().length === 0) return;
802
+ forwarded.add(`${request.seat}:${request.id}`);
803
+ if (forwarded.size > MAXIMUM_FORWARDED_REQUESTS)
804
+ forwarded.delete(forwarded.values().next().value);
805
+ forward({ type: "request", ...request });
806
+ })
807
+ ];
808
+ const close = () => {
809
+ links.closeAll(closeCode("closed"));
810
+ for (const release of releases.splice(0)) release();
811
+ };
812
+ const receive = (link, data) => {
813
+ if (!link.live) return;
814
+ if (!hellos.has(link)) {
815
+ const hello = typeof data === "string" ? parseHostHello(data) : null;
816
+ if (!hello) return link.close(closeCode("unsupported-version"));
817
+ hellos.set(link, hello.seats);
818
+ if (parent.status.phase === "open") welcome(link);
819
+ return;
820
+ }
821
+ if (data === PING_FRAME) return link.send(PONG_FRAME);
822
+ if (!link.welcomed) return;
823
+ if (typeof data !== "string") return link.close(closeCode("unauthorised"));
824
+ const parsed = parseHostToRoomFrame(data);
825
+ if (parsed.status === "unknown") return;
826
+ if (parsed.status !== "frame")
827
+ return link.close(closeCode("limits-broken"));
828
+ const frame = parsed.frame;
829
+ switch (frame.type) {
830
+ case "state": {
831
+ if (!scope(frame.channel)) return link.close(closeCode("unauthorised"));
832
+ const mirror = mirrors.get(link);
833
+ const document = mirror?.receive(frame) ?? null;
834
+ const copy = mirror?.copy(frame.channel);
835
+ if (document === null || !copy)
836
+ return link.close(closeCode("limits-broken"));
837
+ try {
838
+ parent.publish(frame.channel, document, {
839
+ ...copy.fingerprint === void 0 ? {} : { fingerprint: copy.fingerprint },
840
+ ...copy.private === void 0 ? {} : { private: copy.private }
841
+ });
842
+ } catch {
843
+ link.close(closeCode("limits-broken"));
844
+ }
845
+ return;
846
+ }
847
+ case "response":
848
+ if (forwarded.delete(`${frame.seat}:${frame.id}`))
849
+ parent.respond(frame.seat, frame.id, frame.result);
850
+ return;
851
+ case "signal":
852
+ return parent.signal(frame.kind, frame.payload, frame.seat);
853
+ case "room":
854
+ return parent.configure({
855
+ ...frame.seats === void 0 ? {} : { seats: frame.seats },
856
+ ...frame.locked === void 0 ? {} : { locked: frame.locked }
857
+ });
858
+ case "remove":
859
+ return parent.remove(frame.seat);
860
+ case "drop":
861
+ if (!scope(frame.channel)) return link.close(closeCode("unauthorised"));
862
+ mirrors.get(link)?.drop(frame.channel);
863
+ return parent.drop(frame.channel);
864
+ case "activity":
865
+ case "end":
866
+ return link.close(closeCode("unauthorised"));
867
+ }
868
+ };
869
+ const connector = (address, handlers) => {
870
+ const link = new FrameLink(handlers);
871
+ if (address.role !== "host" || links.closed) {
872
+ link.close(closeCode(links.closed ? "closed" : "unauthorised"));
873
+ return { send: () => {
874
+ }, buffered: () => false, close: () => {
875
+ } };
876
+ }
877
+ links.add(link);
878
+ if (parent.status.phase === "closed")
879
+ links.follow(parent.status, () => false);
880
+ return {
881
+ send: (data) => receive(link, data),
882
+ buffered: () => false,
883
+ close: () => {
884
+ link.clientClose();
885
+ links.remove(link);
886
+ }
887
+ };
888
+ };
889
+ return {
890
+ connector,
891
+ close,
892
+ end: () => {
893
+ close();
894
+ for (const copy of parent.channels())
895
+ if (scope(copy.channel)) parent.drop(copy.channel);
896
+ }
897
+ };
898
+ };
899
+
900
+ // src/runtime/room-bridge.ts
901
+ var import_zod12 = require("zod");
36
902
 
37
903
  // src/contracts/v2/bridge.ts
38
- var import_zod = require("zod");
39
- var roomCodeSchema = import_zod.z.string().trim().min(4).max(8).regex(/^[A-Z0-9]+$/, {
904
+ var import_zod7 = require("zod");
905
+ var roomCodeSchema2 = import_zod7.z.string().trim().min(4).max(8).regex(/^[A-Z0-9]+$/, {
40
906
  message: "room code must contain only A-Z or 0-9"
41
907
  });
42
- var runtimeStateSchema = import_zod.z.enum(["paused", "playing"]);
43
- var playerProfileSchema = import_zod.z.object({
44
- id: import_zod.z.string().min(1),
45
- label: import_zod.z.string().min(1),
46
- color: import_zod.z.string().optional(),
47
- avatarId: import_zod.z.string().optional()
908
+ var runtimeStateSchema2 = import_zod7.z.enum(["paused", "playing"]);
909
+ var playerProfileSchema = import_zod7.z.object({
910
+ id: import_zod7.z.string().min(1),
911
+ label: import_zod7.z.string().min(1),
912
+ color: import_zod7.z.string().optional(),
913
+ avatarId: import_zod7.z.string().optional()
48
914
  }).strict();
49
- var inputFrameEntrySchema = import_zod.z.object({
50
- controllerId: import_zod.z.string().min(1),
51
- input: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())
915
+ var inputFrameEntrySchema = import_zod7.z.object({
916
+ controllerId: import_zod7.z.string().min(1),
917
+ input: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.unknown())
52
918
  }).strict();
53
919
  var V2_BRIDGE_PARENT_TO_GAME_TYPES = [
54
920
  "BOOTSTRAP",
@@ -71,89 +937,89 @@ var allMessageTypes = [
71
937
  ...V2_BRIDGE_GAME_TO_PARENT_TYPES
72
938
  ];
73
939
  var knownBridgeMessageTypeSet = new Set(allMessageTypes);
74
- var bootstrapMessageSchema = import_zod.z.object({
75
- type: import_zod.z.literal("BOOTSTRAP"),
76
- payload: import_zod.z.object({
77
- roomId: roomCodeSchema,
78
- players: import_zod.z.array(playerProfileSchema),
79
- state: import_zod.z.object({
80
- runtimeState: runtimeStateSchema,
81
- message: import_zod.z.string().optional()
940
+ var bootstrapMessageSchema = import_zod7.z.object({
941
+ type: import_zod7.z.literal("BOOTSTRAP"),
942
+ payload: import_zod7.z.object({
943
+ roomId: roomCodeSchema2,
944
+ players: import_zod7.z.array(playerProfileSchema),
945
+ state: import_zod7.z.object({
946
+ runtimeState: runtimeStateSchema2,
947
+ message: import_zod7.z.string().optional()
82
948
  }).strict(),
83
- capabilities: import_zod.z.record(import_zod.z.string(), import_zod.z.boolean()).default({})
949
+ capabilities: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.boolean()).default({})
84
950
  }).strict()
85
951
  }).strict();
86
- var playersUpdateMessageSchema = import_zod.z.object({
87
- type: import_zod.z.literal("PLAYERS_UPDATE"),
88
- payload: import_zod.z.object({
89
- players: import_zod.z.array(playerProfileSchema)
952
+ var playersUpdateMessageSchema = import_zod7.z.object({
953
+ type: import_zod7.z.literal("PLAYERS_UPDATE"),
954
+ payload: import_zod7.z.object({
955
+ players: import_zod7.z.array(playerProfileSchema)
90
956
  }).strict()
91
957
  }).strict();
92
- var runtimeStateUpdateMessageSchema = import_zod.z.object({
93
- type: import_zod.z.literal("RUNTIME_STATE_UPDATE"),
94
- payload: import_zod.z.object({
95
- runtimeState: runtimeStateSchema,
96
- message: import_zod.z.string().optional()
958
+ var runtimeStateUpdateMessageSchema = import_zod7.z.object({
959
+ type: import_zod7.z.literal("RUNTIME_STATE_UPDATE"),
960
+ payload: import_zod7.z.object({
961
+ runtimeState: runtimeStateSchema2,
962
+ message: import_zod7.z.string().optional()
97
963
  }).strict()
98
964
  }).strict();
99
- var inputFrameMessageSchema = import_zod.z.object({
100
- type: import_zod.z.literal("INPUT_FRAME"),
101
- payload: import_zod.z.object({
102
- frameId: import_zod.z.number().int().nonnegative(),
103
- inputs: import_zod.z.array(inputFrameEntrySchema)
965
+ var inputFrameMessageSchema = import_zod7.z.object({
966
+ type: import_zod7.z.literal("INPUT_FRAME"),
967
+ payload: import_zod7.z.object({
968
+ frameId: import_zod7.z.number().int().nonnegative(),
969
+ inputs: import_zod7.z.array(inputFrameEntrySchema)
104
970
  }).strict()
105
971
  }).strict();
106
- var pauseMessageSchema = import_zod.z.object({
107
- type: import_zod.z.literal("PAUSE"),
108
- payload: import_zod.z.object({
109
- reason: import_zod.z.string().optional()
972
+ var pauseMessageSchema = import_zod7.z.object({
973
+ type: import_zod7.z.literal("PAUSE"),
974
+ payload: import_zod7.z.object({
975
+ reason: import_zod7.z.string().optional()
110
976
  }).strict()
111
977
  }).strict();
112
- var resumeMessageSchema = import_zod.z.object({
113
- type: import_zod.z.literal("RESUME"),
114
- payload: import_zod.z.object({}).strict()
978
+ var resumeMessageSchema = import_zod7.z.object({
979
+ type: import_zod7.z.literal("RESUME"),
980
+ payload: import_zod7.z.object({}).strict()
115
981
  }).strict();
116
- var shutdownMessageSchema = import_zod.z.object({
117
- type: import_zod.z.literal("SHUTDOWN"),
118
- payload: import_zod.z.object({
119
- reason: import_zod.z.string().min(1)
982
+ var shutdownMessageSchema = import_zod7.z.object({
983
+ type: import_zod7.z.literal("SHUTDOWN"),
984
+ payload: import_zod7.z.object({
985
+ reason: import_zod7.z.string().min(1)
120
986
  }).strict()
121
987
  }).strict();
122
- var readyMessageSchema = import_zod.z.object({
123
- type: import_zod.z.literal("READY"),
124
- payload: import_zod.z.object({
125
- readyAtMs: import_zod.z.number().int().nonnegative()
988
+ var readyMessageSchema = import_zod7.z.object({
989
+ type: import_zod7.z.literal("READY"),
990
+ payload: import_zod7.z.object({
991
+ readyAtMs: import_zod7.z.number().int().nonnegative()
126
992
  }).strict()
127
993
  }).strict();
128
- var statePatchMessageSchema = import_zod.z.object({
129
- type: import_zod.z.literal("STATE_PATCH"),
130
- payload: import_zod.z.object({
131
- patch: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())
994
+ var statePatchMessageSchema = import_zod7.z.object({
995
+ type: import_zod7.z.literal("STATE_PATCH"),
996
+ payload: import_zod7.z.object({
997
+ patch: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.unknown())
132
998
  }).strict()
133
999
  }).strict();
134
- var signalMessageSchema = import_zod.z.object({
135
- type: import_zod.z.literal("SIGNAL"),
136
- payload: import_zod.z.object({
137
- signalType: import_zod.z.string().min(1),
138
- targetId: import_zod.z.string().min(1).optional(),
139
- data: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())
1000
+ var signalMessageSchema = import_zod7.z.object({
1001
+ type: import_zod7.z.literal("SIGNAL"),
1002
+ payload: import_zod7.z.object({
1003
+ signalType: import_zod7.z.string().min(1),
1004
+ targetId: import_zod7.z.string().min(1).optional(),
1005
+ data: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.unknown())
140
1006
  }).strict()
141
1007
  }).strict();
142
- var errorMessageSchema = import_zod.z.object({
143
- type: import_zod.z.literal("ERROR"),
144
- payload: import_zod.z.object({
145
- code: import_zod.z.string().min(1),
146
- message: import_zod.z.string().min(1),
147
- details: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
1008
+ var errorMessageSchema = import_zod7.z.object({
1009
+ type: import_zod7.z.literal("ERROR"),
1010
+ payload: import_zod7.z.object({
1011
+ code: import_zod7.z.string().min(1),
1012
+ message: import_zod7.z.string().min(1),
1013
+ details: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.unknown()).optional()
148
1014
  }).strict()
149
1015
  }).strict();
150
- var metricsMessageSchema = import_zod.z.object({
151
- type: import_zod.z.literal("METRICS"),
152
- payload: import_zod.z.object({
153
- values: import_zod.z.record(import_zod.z.string(), import_zod.z.number())
1016
+ var metricsMessageSchema = import_zod7.z.object({
1017
+ type: import_zod7.z.literal("METRICS"),
1018
+ payload: import_zod7.z.object({
1019
+ values: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.number())
154
1020
  }).strict()
155
1021
  }).strict();
156
- var v2BridgeParentToGameMessageSchema = import_zod.z.union([
1022
+ var v2BridgeParentToGameMessageSchema = import_zod7.z.union([
157
1023
  bootstrapMessageSchema,
158
1024
  playersUpdateMessageSchema,
159
1025
  runtimeStateUpdateMessageSchema,
@@ -162,24 +1028,24 @@ var v2BridgeParentToGameMessageSchema = import_zod.z.union([
162
1028
  resumeMessageSchema,
163
1029
  shutdownMessageSchema
164
1030
  ]);
165
- var v2BridgeGameToParentMessageSchema = import_zod.z.union([
1031
+ var v2BridgeGameToParentMessageSchema = import_zod7.z.union([
166
1032
  readyMessageSchema,
167
1033
  statePatchMessageSchema,
168
1034
  signalMessageSchema,
169
1035
  errorMessageSchema,
170
1036
  metricsMessageSchema
171
1037
  ]);
172
- var v2BridgeMessageSchema = import_zod.z.union([
1038
+ var v2BridgeMessageSchema = import_zod7.z.union([
173
1039
  v2BridgeParentToGameMessageSchema,
174
1040
  v2BridgeGameToParentMessageSchema
175
1041
  ]);
176
1042
 
177
1043
  // src/contracts/v2/handshake.ts
178
- var import_zod2 = require("zod");
1044
+ var import_zod8 = require("zod");
179
1045
  var AIR_JAM_PROTOCOL_V2 = "2";
180
1046
  var semanticVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
181
- var v2ProtocolVersionSchema = import_zod2.z.literal(AIR_JAM_PROTOCOL_V2);
182
- var runtimeKindSchema = import_zod2.z.enum([
1047
+ var v2ProtocolVersionSchema = import_zod8.z.literal(AIR_JAM_PROTOCOL_V2);
1048
+ var runtimeKindSchema = import_zod8.z.enum([
183
1049
  "standalone-host",
184
1050
  "standalone-controller",
185
1051
  "arcade-runtime",
@@ -189,28 +1055,37 @@ var runtimeKindSchema = import_zod2.z.enum([
189
1055
  "arcade-controller-runtime",
190
1056
  "arcade-controller-iframe"
191
1057
  ]);
192
- var capabilityFlagsSchema = import_zod2.z.record(import_zod2.z.string(), import_zod2.z.boolean());
193
- var sdkVersionSchema = import_zod2.z.string().regex(
1058
+ var capabilityFlagsSchema = import_zod8.z.record(import_zod8.z.string(), import_zod8.z.boolean());
1059
+ var sdkVersionSchema = import_zod8.z.string().regex(
194
1060
  semanticVersionPattern,
195
1061
  "sdkVersion must use semantic version format (for example 1.2.3)"
196
1062
  );
197
- var v2HandshakeSchema = import_zod2.z.object({
1063
+ var v2HandshakeSchema = import_zod8.z.object({
198
1064
  protocolVersion: v2ProtocolVersionSchema,
199
1065
  sdkVersion: sdkVersionSchema,
200
1066
  runtimeKind: runtimeKindSchema,
201
1067
  capabilityFlags: capabilityFlagsSchema.default({})
202
1068
  }).strict();
203
1069
 
1070
+ // src/runtime/controller-bridge-context.ts
1071
+ var import_zod10 = require("zod");
1072
+
204
1073
  // src/runtime/arcade-surface-identity.ts
205
- var import_zod3 = require("zod");
206
- var arcadeSurfaceRuntimeIdentitySchema = import_zod3.z.object({
207
- epoch: import_zod3.z.number().int().nonnegative(),
208
- kind: import_zod3.z.enum(["browser", "game"]),
209
- gameId: import_zod3.z.string().nullable()
1074
+ var import_zod9 = require("zod");
1075
+ var arcadeSurfaceRuntimeIdentitySchema = import_zod9.z.object({
1076
+ epoch: import_zod9.z.number().int().nonnegative(),
1077
+ kind: import_zod9.z.enum(["browser", "game"]),
1078
+ gameId: import_zod9.z.string().nullable()
210
1079
  }).strict();
211
1080
 
1081
+ // src/runtime/controller-bridge-context.ts
1082
+ var controllerBridgeContextSchema = import_zod10.z.union([
1083
+ import_zod10.z.object({ arcadeSurface: arcadeSurfaceRuntimeIdentitySchema }).strict(),
1084
+ import_zod10.z.object({ harnessSessionId: import_zod10.z.uuid() }).strict()
1085
+ ]);
1086
+
212
1087
  // src/runtime/iframe-bridge.ts
213
- var import_zod4 = require("zod");
1088
+ var import_zod11 = require("zod");
214
1089
 
215
1090
  // src/settings/platform-settings.ts
216
1091
  var DEFAULT_PLATFORM_SETTINGS = {
@@ -239,183 +1114,73 @@ var DEFAULT_ROOM_PLATFORM_SETTINGS = {
239
1114
  var AIRJAM_BRIDGE_INIT = "AIRJAM_BRIDGE_INIT";
240
1115
  var AIRJAM_SETTINGS_SYNC = "AIRJAM_SETTINGS_SYNC";
241
1116
  var AIRJAM_SETTINGS_READY = "AIRJAM_SETTINGS_READY";
242
- var airJamSettingsSyncSchema = import_zod4.z.object({
243
- type: import_zod4.z.literal(AIRJAM_SETTINGS_SYNC),
244
- payload: import_zod4.z.object({
245
- settings: import_zod4.z.object({
246
- audio: import_zod4.z.object({
247
- masterVolume: import_zod4.z.number(),
248
- musicVolume: import_zod4.z.number(),
249
- sfxVolume: import_zod4.z.number()
1117
+ var airJamSettingsSyncSchema = import_zod11.z.object({
1118
+ type: import_zod11.z.literal(AIRJAM_SETTINGS_SYNC),
1119
+ payload: import_zod11.z.object({
1120
+ settings: import_zod11.z.object({
1121
+ audio: import_zod11.z.object({
1122
+ masterVolume: import_zod11.z.number(),
1123
+ musicVolume: import_zod11.z.number(),
1124
+ sfxVolume: import_zod11.z.number()
250
1125
  }).strict(),
251
- accessibility: import_zod4.z.object({
252
- reducedMotion: import_zod4.z.boolean(),
253
- highContrast: import_zod4.z.boolean()
1126
+ accessibility: import_zod11.z.object({
1127
+ reducedMotion: import_zod11.z.boolean(),
1128
+ highContrast: import_zod11.z.boolean()
254
1129
  }).strict(),
255
- feedback: import_zod4.z.object({
256
- hapticsEnabled: import_zod4.z.boolean()
1130
+ feedback: import_zod11.z.object({
1131
+ hapticsEnabled: import_zod11.z.boolean()
257
1132
  }).strict(),
258
- previewControllers: import_zod4.z.object({
259
- activeOpacity: import_zod4.z.number()
1133
+ previewControllers: import_zod11.z.object({
1134
+ activeOpacity: import_zod11.z.number()
260
1135
  }).strict()
261
1136
  }).strict()
262
1137
  }).strict()
263
1138
  }).strict();
264
- var airJamBridgeInitSchema = import_zod4.z.object({
265
- type: import_zod4.z.literal(AIRJAM_BRIDGE_INIT),
266
- payload: import_zod4.z.object({
1139
+ var airJamBridgeInitSchema = import_zod11.z.object({
1140
+ type: import_zod11.z.literal(AIRJAM_BRIDGE_INIT),
1141
+ payload: import_zod11.z.object({
267
1142
  handshake: v2HandshakeSchema
268
1143
  }).strict()
269
1144
  }).strict();
270
- var airJamSettingsReadySchema = import_zod4.z.object({
271
- type: import_zod4.z.literal(AIRJAM_SETTINGS_READY),
272
- payload: import_zod4.z.object({
273
- ready: import_zod4.z.literal(true)
1145
+ var airJamSettingsReadySchema = import_zod11.z.object({
1146
+ type: import_zod11.z.literal(AIRJAM_SETTINGS_READY),
1147
+ payload: import_zod11.z.object({
1148
+ ready: import_zod11.z.literal(true)
274
1149
  }).strict()
275
1150
  }).strict();
276
- var createBridgeHandshake = ({
277
- sdkVersion,
278
- runtimeKind,
279
- capabilityFlags = {}
280
- }) => v2HandshakeSchema.parse({
281
- protocolVersion: AIR_JAM_PROTOCOL_V2,
282
- sdkVersion,
283
- runtimeKind,
284
- capabilityFlags
285
- });
286
1151
 
287
- // src/runtime/sdk-version.ts
288
- var AIR_JAM_SDK_VERSION = true ? "0.9.2" : "0.0.0";
289
-
290
- // src/runtime/host-bridge.ts
291
- var AIRJAM_HOST_BRIDGE_REQUEST = "AIRJAM_HOST_BRIDGE_REQUEST";
292
- var AIRJAM_HOST_BRIDGE_ATTACH = "AIRJAM_HOST_BRIDGE_ATTACH";
293
- var AIRJAM_HOST_BRIDGE_EVENT = "AIRJAM_HOST_BRIDGE_EVENT";
294
- var AIRJAM_HOST_BRIDGE_EMIT = "AIRJAM_HOST_BRIDGE_EMIT";
295
- var AIRJAM_HOST_BRIDGE_CLOSE = "AIRJAM_HOST_BRIDGE_CLOSE";
296
- var AIRJAM_HOST_BRIDGE_RESPONSE = "AIRJAM_HOST_BRIDGE_RESPONSE";
297
- var hostBridgeClientEvents = [
298
- "host:state",
299
- "host:signal",
300
- "host:play_sound",
301
- "host:system",
302
- "host:state_sync"
303
- ];
304
- var hostBridgeServerEvents = [
305
- "connect",
306
- "disconnect",
307
- "airjam:state_sync_request",
308
- "server:controllerJoined",
309
- "server:controllerLeft",
310
- "server:playerUpdated",
311
- "server:input",
312
- "server:error",
313
- "server:state",
314
- "server:hostLeft",
315
- "server:playSound",
316
- "airjam:action_rpc",
317
- "server:closeChild"
318
- ];
319
- var hostBridgeRequestSchema = import_zod5.z.object({
320
- type: import_zod5.z.literal(AIRJAM_HOST_BRIDGE_REQUEST),
321
- payload: import_zod5.z.object({
322
- handshake: v2HandshakeSchema,
323
- roomId: import_zod5.z.string().min(1),
324
- capabilityToken: import_zod5.z.string().min(1),
325
- arcadeSurface: arcadeSurfaceRuntimeIdentitySchema
326
- }).strict()
327
- }).strict();
328
- var hostBridgeAttachSchema = import_zod5.z.object({
329
- type: import_zod5.z.literal(AIRJAM_HOST_BRIDGE_ATTACH),
330
- payload: import_zod5.z.object({
331
- handshake: v2HandshakeSchema,
332
- snapshot: import_zod5.z.object({
333
- roomId: import_zod5.z.string().min(1),
334
- capabilityToken: import_zod5.z.string().min(1),
335
- connected: import_zod5.z.boolean(),
336
- socketId: import_zod5.z.string().optional(),
337
- players: import_zod5.z.array(import_zod5.z.unknown()),
338
- state: import_zod5.z.unknown().optional(),
339
- arcadeSurface: arcadeSurfaceRuntimeIdentitySchema
340
- }).strict()
341
- }).strict()
342
- }).strict();
343
- var hostBridgeEventSchema = import_zod5.z.object({
344
- type: import_zod5.z.literal(AIRJAM_HOST_BRIDGE_EVENT),
345
- payload: import_zod5.z.object({
346
- event: import_zod5.z.enum(hostBridgeServerEvents),
347
- args: import_zod5.z.array(import_zod5.z.unknown()),
348
- requestId: import_zod5.z.string().min(1).optional()
349
- }).strict()
350
- }).strict();
351
- var hostBridgeEmitSchema = import_zod5.z.object({
352
- type: import_zod5.z.literal(AIRJAM_HOST_BRIDGE_EMIT),
353
- payload: import_zod5.z.object({
354
- event: import_zod5.z.enum(hostBridgeClientEvents),
355
- args: import_zod5.z.array(import_zod5.z.unknown()),
356
- requestId: import_zod5.z.string().min(1).optional()
357
- }).strict()
358
- }).strict();
359
- var hostBridgeResponseSchema = import_zod5.z.object({
360
- type: import_zod5.z.literal(AIRJAM_HOST_BRIDGE_RESPONSE),
361
- payload: import_zod5.z.object({
362
- requestId: import_zod5.z.string().min(1),
363
- ack: import_zod5.z.unknown()
364
- }).strict()
365
- }).strict();
366
- var hostBridgeCloseSchema = import_zod5.z.object({
367
- type: import_zod5.z.literal(AIRJAM_HOST_BRIDGE_CLOSE),
368
- payload: import_zod5.z.object({
369
- reason: import_zod5.z.string().optional()
370
- }).strict()
371
- }).strict();
372
- var createHostBridgeAttachMessage = (snapshot) => ({
373
- type: AIRJAM_HOST_BRIDGE_ATTACH,
374
- payload: {
375
- handshake: createBridgeHandshake({
376
- sdkVersion: AIR_JAM_SDK_VERSION,
377
- runtimeKind: "arcade-host-runtime",
378
- capabilityFlags: {
379
- hostBridge: true
380
- }
1152
+ // src/runtime/room-bridge.ts
1153
+ var AIRJAM_ROOM_BRIDGE_REQUEST = "AIRJAM_ROOM_BRIDGE_REQUEST";
1154
+ var roomBridgeRequestSchema = import_zod12.z.object({
1155
+ type: import_zod12.z.literal(AIRJAM_ROOM_BRIDGE_REQUEST),
1156
+ payload: import_zod12.z.intersection(
1157
+ import_zod12.z.object({
1158
+ handshake: v2HandshakeSchema,
1159
+ role: import_zod12.z.enum(["host", "controller"])
381
1160
  }),
382
- snapshot
383
- }
384
- });
385
- var createHostBridgeResponseMessage = (requestId, ack) => ({
386
- type: AIRJAM_HOST_BRIDGE_RESPONSE,
387
- payload: {
388
- requestId,
389
- ack
390
- }
391
- });
392
- var createHostBridgeCloseMessage = (reason) => ({
393
- type: AIRJAM_HOST_BRIDGE_CLOSE,
394
- payload: {
395
- reason
396
- }
397
- });
398
- var parseHostBridgeRequestMessage = (value) => {
399
- const result = hostBridgeRequestSchema.safeParse(value);
400
- return result.success ? result.data : null;
1161
+ controllerBridgeContextSchema
1162
+ )
1163
+ }).strict();
1164
+ var readRoomBridgeRequest = (event) => {
1165
+ const parsed = roomBridgeRequestSchema.safeParse(event.data);
1166
+ const port = event.ports[0];
1167
+ if (!parsed.success || !port) return null;
1168
+ return { request: parsed.data.payload, port };
401
1169
  };
402
- var parseHostBridgeEmitMessage = (value) => {
403
- const result = hostBridgeEmitSchema.safeParse(value);
404
- return result.success ? result.data : null;
1170
+ var refusingConnector = (_address, handlers) => {
1171
+ queueMicrotask(() => handlers.close(roomCloseCodes.unauthorised.code));
1172
+ return { send: () => {
1173
+ }, buffered: () => false, close: () => {
1174
+ } };
405
1175
  };
406
- var parseHostBridgeResponseMessage = (value) => {
407
- const result = hostBridgeResponseSchema.safeParse(value);
408
- return result.success ? result.data : null;
1176
+ var refuseRoomBridge = (port) => {
1177
+ serveRoomPort(port, refusingConnector);
409
1178
  };
410
1179
  // Annotate the CommonJS export names for ESM import in node:
411
1180
  0 && (module.exports = {
412
- AIRJAM_HOST_BRIDGE_EVENT,
413
- AIRJAM_HOST_BRIDGE_RESPONSE,
414
- createHostBridgeAttachMessage,
415
- createHostBridgeCloseMessage,
416
- createHostBridgeResponseMessage,
417
- parseHostBridgeEmitMessage,
418
- parseHostBridgeRequestMessage,
419
- parseHostBridgeResponseMessage
1181
+ createScopedHostConnector,
1182
+ readRoomBridgeRequest,
1183
+ refuseRoomBridge,
1184
+ serveRoomPort
420
1185
  });
421
1186
  //# sourceMappingURL=host.cjs.map