@air-jam/sdk 0.1.4 → 0.9.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 (357) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +627 -57
  3. package/dist/agent-tooling-BSMGBix9.d.cts +123 -0
  4. package/dist/agent-tooling-BSMGBix9.d.ts +123 -0
  5. package/dist/agent-tooling.cjs +83 -0
  6. package/dist/agent-tooling.cjs.map +1 -0
  7. package/dist/agent-tooling.d.cts +2 -0
  8. package/dist/agent-tooling.d.ts +2 -0
  9. package/dist/agent-tooling.js +17 -0
  10. package/dist/agent-tooling.js.map +1 -0
  11. package/dist/arcade/bridge/controller.cjs +749 -0
  12. package/dist/arcade/bridge/controller.cjs.map +1 -0
  13. package/dist/arcade/bridge/controller.d.cts +85 -0
  14. package/dist/arcade/bridge/controller.d.ts +85 -0
  15. package/dist/arcade/bridge/controller.js +33 -0
  16. package/dist/arcade/bridge/controller.js.map +1 -0
  17. package/dist/arcade/bridge/host.cjs +421 -0
  18. package/dist/arcade/bridge/host.cjs.map +1 -0
  19. package/dist/arcade/bridge/host.d.cts +73 -0
  20. package/dist/arcade/bridge/host.d.ts +73 -0
  21. package/dist/arcade/bridge/host.js +25 -0
  22. package/dist/arcade/bridge/host.js.map +1 -0
  23. package/dist/arcade/bridge/iframe.cjs +453 -0
  24. package/dist/arcade/bridge/iframe.cjs.map +1 -0
  25. package/dist/arcade/bridge/iframe.d.cts +80 -0
  26. package/dist/arcade/bridge/iframe.d.ts +80 -0
  27. package/dist/arcade/bridge/iframe.js +28 -0
  28. package/dist/arcade/bridge/iframe.js.map +1 -0
  29. package/dist/arcade/bridge.cjs +1067 -0
  30. package/dist/arcade/bridge.cjs.map +1 -0
  31. package/dist/arcade/bridge.d.cts +11 -0
  32. package/dist/arcade/bridge.d.ts +11 -0
  33. package/dist/arcade/bridge.js +76 -0
  34. package/dist/arcade/bridge.js.map +1 -0
  35. package/dist/arcade/host.cjs +481 -0
  36. package/dist/arcade/host.cjs.map +1 -0
  37. package/dist/arcade/host.d.cts +19 -0
  38. package/dist/arcade/host.d.ts +19 -0
  39. package/dist/arcade/host.js +14 -0
  40. package/dist/arcade/host.js.map +1 -0
  41. package/dist/arcade/surface.cjs +113 -0
  42. package/dist/arcade/surface.cjs.map +1 -0
  43. package/dist/arcade/surface.d.cts +14 -0
  44. package/dist/arcade/surface.d.ts +14 -0
  45. package/dist/arcade/surface.js +27 -0
  46. package/dist/arcade/surface.js.map +1 -0
  47. package/dist/arcade/url.cjs +544 -0
  48. package/dist/arcade/url.cjs.map +1 -0
  49. package/dist/arcade/url.d.cts +68 -0
  50. package/dist/arcade/url.d.ts +68 -0
  51. package/dist/arcade/url.js +29 -0
  52. package/dist/arcade/url.js.map +1 -0
  53. package/dist/arcade-runtime-url-BW-MUAOY.d.cts +28 -0
  54. package/dist/arcade-runtime-url-l8qj01Pg.d.ts +28 -0
  55. package/dist/arcade-surface-identity-CQxDpn_w.d.cts +16 -0
  56. package/dist/arcade-surface-identity-CQxDpn_w.d.ts +16 -0
  57. package/dist/arcade.cjs +1737 -0
  58. package/dist/arcade.cjs.map +1 -0
  59. package/dist/arcade.d.cts +18 -0
  60. package/dist/arcade.d.ts +18 -0
  61. package/dist/arcade.js +123 -0
  62. package/dist/arcade.js.map +1 -0
  63. package/dist/capabilities.cjs +39 -0
  64. package/dist/capabilities.cjs.map +1 -0
  65. package/dist/capabilities.d.cts +31 -0
  66. package/dist/capabilities.d.ts +31 -0
  67. package/dist/capabilities.js +12 -0
  68. package/dist/capabilities.js.map +1 -0
  69. package/dist/chunk-32NYL7XI.js +539 -0
  70. package/dist/chunk-32NYL7XI.js.map +1 -0
  71. package/dist/chunk-3USU7GY2.js +54 -0
  72. package/dist/chunk-3USU7GY2.js.map +1 -0
  73. package/dist/chunk-7UXSWCZZ.js +32 -0
  74. package/dist/chunk-7UXSWCZZ.js.map +1 -0
  75. package/dist/chunk-BE6Z4SIT.js +65 -0
  76. package/dist/chunk-BE6Z4SIT.js.map +1 -0
  77. package/dist/chunk-CABEUV65.js +184 -0
  78. package/dist/chunk-CABEUV65.js.map +1 -0
  79. package/dist/chunk-CEJ5RFSG.js +288 -0
  80. package/dist/chunk-CEJ5RFSG.js.map +1 -0
  81. package/dist/chunk-EDRQIOCV.js +25 -0
  82. package/dist/chunk-EDRQIOCV.js.map +1 -0
  83. package/dist/chunk-EVZJA6RN.js +140 -0
  84. package/dist/chunk-EVZJA6RN.js.map +1 -0
  85. package/dist/chunk-FAT2KJ3K.js +238 -0
  86. package/dist/chunk-FAT2KJ3K.js.map +1 -0
  87. package/dist/chunk-IKKDONQL.js +1 -0
  88. package/dist/chunk-IKKDONQL.js.map +1 -0
  89. package/dist/chunk-JEHV5C2X.js +249 -0
  90. package/dist/chunk-JEHV5C2X.js.map +1 -0
  91. package/dist/chunk-JO2HR5PV.js +43 -0
  92. package/dist/chunk-JO2HR5PV.js.map +1 -0
  93. package/dist/chunk-JTF47B56.js +1 -0
  94. package/dist/chunk-JTF47B56.js.map +1 -0
  95. package/dist/chunk-KXAFI5OP.js +193 -0
  96. package/dist/chunk-KXAFI5OP.js.map +1 -0
  97. package/dist/chunk-LIXPF4P6.js +22 -0
  98. package/dist/chunk-LIXPF4P6.js.map +1 -0
  99. package/dist/chunk-MPDMJIX5.js +1 -0
  100. package/dist/chunk-MPDMJIX5.js.map +1 -0
  101. package/dist/chunk-NCL6WJCL.js +91 -0
  102. package/dist/chunk-NCL6WJCL.js.map +1 -0
  103. package/dist/chunk-NUJBMV3O.js +1435 -0
  104. package/dist/chunk-NUJBMV3O.js.map +1 -0
  105. package/dist/chunk-TGRTEWYV.js +195 -0
  106. package/dist/chunk-TGRTEWYV.js.map +1 -0
  107. package/dist/chunk-UWJOIVON.js +369 -0
  108. package/dist/chunk-UWJOIVON.js.map +1 -0
  109. package/dist/chunk-VKBMZHMQ.js +216 -0
  110. package/dist/chunk-VKBMZHMQ.js.map +1 -0
  111. package/dist/chunk-W2VK36RO.js +11 -0
  112. package/dist/chunk-W2VK36RO.js.map +1 -0
  113. package/dist/chunk-W3YA5BWR.js +126 -0
  114. package/dist/chunk-W3YA5BWR.js.map +1 -0
  115. package/dist/chunk-X24K52DG.js +12 -0
  116. package/dist/chunk-X24K52DG.js.map +1 -0
  117. package/dist/chunk-YXHH3MQT.js +230 -0
  118. package/dist/chunk-YXHH3MQT.js.map +1 -0
  119. package/dist/chunk-ZLPL2R3R.js +183 -0
  120. package/dist/chunk-ZLPL2R3R.js.map +1 -0
  121. package/dist/chunk-ZTQ5SP4H.js +9 -0
  122. package/dist/chunk-ZTQ5SP4H.js.map +1 -0
  123. package/dist/controller-Bod8YYr1.d.cts +172 -0
  124. package/dist/controller-DxVchfiA.d.ts +172 -0
  125. package/dist/dev-log-events-CVAM29hx.d.cts +123 -0
  126. package/dist/dev-log-events-CVAM29hx.d.ts +123 -0
  127. package/dist/handshake-CC_LrK5g.d.cts +31 -0
  128. package/dist/handshake-CC_LrK5g.d.ts +31 -0
  129. package/dist/host-8hmq_Sgc.d.cts +109 -0
  130. package/dist/host-Cw-N6e-5.d.ts +109 -0
  131. package/dist/index.cjs +8730 -3426
  132. package/dist/index.cjs.map +1 -1
  133. package/dist/index.d.cts +676 -1070
  134. package/dist/index.d.ts +676 -1070
  135. package/dist/index.js +4892 -3196
  136. package/dist/index.js.map +1 -1
  137. package/dist/metadata.cjs +114 -0
  138. package/dist/metadata.cjs.map +1 -0
  139. package/dist/metadata.d.cts +95 -0
  140. package/dist/metadata.d.ts +95 -0
  141. package/dist/metadata.js +83 -0
  142. package/dist/metadata.js.map +1 -0
  143. package/dist/notices-CnGaaS8B.d.ts +38 -0
  144. package/dist/notices-NyDM5Mtz.d.cts +38 -0
  145. package/dist/platform-machine.cjs +425 -0
  146. package/dist/platform-machine.cjs.map +1 -0
  147. package/dist/platform-machine.d.cts +1183 -0
  148. package/dist/platform-machine.d.ts +1183 -0
  149. package/dist/platform-machine.js +309 -0
  150. package/dist/platform-machine.js.map +1 -0
  151. package/dist/platform-settings-cuor3i11.d.cts +48 -0
  152. package/dist/platform-settings-cuor3i11.d.ts +48 -0
  153. package/dist/prefabs.cjs +36 -0
  154. package/dist/prefabs.cjs.map +1 -0
  155. package/dist/prefabs.d.cts +49 -0
  156. package/dist/prefabs.d.ts +49 -0
  157. package/dist/prefabs.js +8 -0
  158. package/dist/prefabs.js.map +1 -0
  159. package/dist/preview.cjs +2620 -0
  160. package/dist/preview.cjs.map +1 -0
  161. package/dist/preview.d.cts +155 -0
  162. package/dist/preview.d.ts +155 -0
  163. package/dist/preview.js +1671 -0
  164. package/dist/preview.js.map +1 -0
  165. package/dist/protocol.cjs +621 -54
  166. package/dist/protocol.cjs.map +1 -1
  167. package/dist/protocol.d.cts +76 -240
  168. package/dist/protocol.d.ts +76 -240
  169. package/dist/protocol.js +100 -2
  170. package/dist/protocol.js.map +1 -1
  171. package/dist/realtime-client-Cu8yVJFw.d.cts +15 -0
  172. package/dist/realtime-client-Cu8yVJFw.d.ts +15 -0
  173. package/dist/release.cjs +143 -0
  174. package/dist/release.cjs.map +1 -0
  175. package/dist/release.d.cts +64 -0
  176. package/dist/release.d.ts +64 -0
  177. package/dist/release.js +43 -0
  178. package/dist/release.js.map +1 -0
  179. package/dist/runtime-topology.cjs +405 -0
  180. package/dist/runtime-topology.cjs.map +1 -0
  181. package/dist/runtime-topology.d.cts +59 -0
  182. package/dist/runtime-topology.d.ts +59 -0
  183. package/dist/runtime-topology.js +31 -0
  184. package/dist/runtime-topology.js.map +1 -0
  185. package/dist/standard-match-phase-BucA5dYo.d.ts +44 -0
  186. package/dist/standard-match-phase-U2ra8J-0.d.cts +44 -0
  187. package/dist/sync-B6QsNrXz.d.cts +125 -0
  188. package/dist/sync-B6QsNrXz.d.ts +125 -0
  189. package/dist/ui.cjs +3061 -0
  190. package/dist/ui.cjs.map +1 -0
  191. package/dist/ui.d.cts +320 -0
  192. package/dist/ui.d.ts +320 -0
  193. package/dist/ui.js +1719 -0
  194. package/dist/ui.js.map +1 -0
  195. package/dist/url-policy-C89zxgw9.d.cts +9 -0
  196. package/dist/url-policy-C89zxgw9.d.ts +9 -0
  197. package/package.json +155 -10
  198. package/src/agent/agent-action.ts +304 -0
  199. package/src/agent/agent-contract.ts +180 -0
  200. package/src/agent-tooling.ts +20 -0
  201. package/src/arcade/bridge/controller.ts +15 -0
  202. package/src/arcade/bridge/host.ts +12 -0
  203. package/src/arcade/bridge/iframe.ts +61 -0
  204. package/src/arcade/bridge.ts +3 -0
  205. package/src/arcade/host.ts +1 -0
  206. package/src/arcade/surface.ts +4 -0
  207. package/src/arcade/url.ts +60 -0
  208. package/src/arcade.ts +4 -0
  209. package/src/audio/audio-manager.ts +162 -171
  210. package/src/audio/hooks.tsx +218 -97
  211. package/src/audio/index.ts +1 -1
  212. package/src/audio/music.tsx +139 -0
  213. package/src/capabilities/manifest.ts +71 -0
  214. package/src/capabilities.ts +12 -0
  215. package/src/components/connection-status-pill.tsx +55 -0
  216. package/src/components/controller-player-name-field.tsx +119 -0
  217. package/src/components/controller-primary-action.tsx +58 -0
  218. package/src/components/host-mute-button.tsx +49 -0
  219. package/src/components/join-qr-overlay.tsx +133 -0
  220. package/src/components/join-url-action-buttons.tsx +95 -0
  221. package/src/components/join-url-controls.tsx +58 -0
  222. package/src/components/join-url-field.tsx +52 -0
  223. package/src/components/lifecycle-action-group.tsx +129 -0
  224. package/src/components/player-avatar-strip.tsx +65 -0
  225. package/src/components/player-avatar.tsx +42 -13
  226. package/src/components/room-qr-code.tsx +125 -0
  227. package/src/components/runtime-shell-header.tsx +37 -0
  228. package/src/components/shell-classes.ts +19 -0
  229. package/src/components/surface-orientation-layout.ts +60 -0
  230. package/src/components/surface-viewport-layout.ts +268 -0
  231. package/src/components/surface-viewport.tsx +314 -0
  232. package/src/components/ui/button.tsx +4 -6
  233. package/src/components/ui/slider.tsx +1 -1
  234. package/src/components/volume-controls.tsx +65 -6
  235. package/src/context/air-jam-context.tsx +209 -161
  236. package/src/context/index.ts +2 -2
  237. package/src/context/session-providers.tsx +77 -0
  238. package/src/context/session-scope.ts +64 -0
  239. package/src/context/socket-manager.ts +6 -24
  240. package/src/contracts/v2/bridge.ts +261 -0
  241. package/src/contracts/v2/handshake.ts +40 -0
  242. package/src/contracts/v2/index.ts +2 -0
  243. package/src/dev/browser-log-sink.ts +912 -0
  244. package/src/diagnostics.ts +128 -0
  245. package/src/events.ts +7 -34
  246. package/src/hooks/internal/use-controller-runtime-api.ts +875 -0
  247. package/src/hooks/internal/use-host-runtime-api.ts +1051 -0
  248. package/src/hooks/internal/use-runtime-control-contract.ts +15 -0
  249. package/src/hooks/internal/use-runtime-inspection-contract.ts +16 -0
  250. package/src/hooks/internal/use-runtime-observability-contract.ts +24 -0
  251. package/src/hooks/use-air-jam-controller.ts +155 -475
  252. package/src/hooks/use-air-jam-host.ts +156 -485
  253. package/src/hooks/use-connection-status.ts +8 -0
  254. package/src/hooks/use-controller-lifecycle-intents.ts +27 -0
  255. package/src/hooks/use-controller-lifecycle-permissions.ts +36 -0
  256. package/src/hooks/use-controller-shell-status.ts +40 -0
  257. package/src/hooks/use-controller-tick.ts +65 -0
  258. package/src/hooks/use-controller-toasts.ts +116 -0
  259. package/src/hooks/use-get-input.ts +8 -5
  260. package/src/hooks/use-host-arcade-restore.ts +30 -0
  261. package/src/hooks/use-host-join-controls.ts +152 -0
  262. package/src/hooks/use-host-tick.ts +171 -0
  263. package/src/hooks/use-input-writer.ts +83 -0
  264. package/src/hooks/use-lifecycle-action-group-model.ts +98 -0
  265. package/src/hooks/use-players.ts +12 -0
  266. package/src/hooks/use-room.ts +22 -0
  267. package/src/hooks/use-send-signal.ts +6 -2
  268. package/src/index.ts +205 -31
  269. package/src/internal/input-manager.ts +195 -215
  270. package/src/lifecycle/index.ts +9 -0
  271. package/src/lifecycle/standard-match-phase.ts +32 -0
  272. package/src/metadata/manifest.ts +152 -0
  273. package/src/metadata.ts +12 -0
  274. package/src/platform-machine.ts +475 -0
  275. package/src/prefabs/types.ts +82 -0
  276. package/src/prefabs.ts +12 -0
  277. package/src/preview/host-workspace.tsx +59 -0
  278. package/src/preview/identity.ts +66 -0
  279. package/src/preview/layout.ts +223 -0
  280. package/src/preview/manager.ts +577 -0
  281. package/src/preview/messages.ts +26 -0
  282. package/src/preview/ownership.ts +81 -0
  283. package/src/preview/url.ts +117 -0
  284. package/src/preview/window.tsx +490 -0
  285. package/src/preview/workspace.tsx +678 -0
  286. package/src/preview.ts +42 -0
  287. package/src/protocol/arcade-platform-actions.ts +29 -0
  288. package/src/protocol/controller.ts +187 -0
  289. package/src/protocol/core.ts +23 -0
  290. package/src/protocol/dev-log-events.ts +222 -0
  291. package/src/protocol/errors.ts +21 -0
  292. package/src/protocol/host-grant.ts +185 -0
  293. package/src/protocol/host.ts +138 -0
  294. package/src/protocol/notices.ts +43 -0
  295. package/src/protocol/signals.ts +38 -0
  296. package/src/protocol/socket-events.ts +154 -0
  297. package/src/protocol/sync.ts +121 -0
  298. package/src/protocol/url-policy.ts +63 -0
  299. package/src/protocol.ts +12 -386
  300. package/src/qrcode.d.ts +16 -0
  301. package/src/release.ts +99 -0
  302. package/src/runtime/air-jam-config.ts +287 -0
  303. package/src/runtime/air-jam-error-boundary.tsx +672 -0
  304. package/src/runtime/arcade-bridge-request-surface.ts +15 -0
  305. package/src/runtime/arcade-runtime-url.ts +95 -0
  306. package/src/runtime/arcade-surface-identity.ts +16 -0
  307. package/src/runtime/contracts/control.ts +68 -0
  308. package/src/runtime/contracts/inspection.ts +165 -0
  309. package/src/runtime/contracts/observability.ts +94 -0
  310. package/src/runtime/controller-bridge.ts +451 -0
  311. package/src/runtime/controller-identity.ts +132 -0
  312. package/src/runtime/controller-presentation.ts +24 -0
  313. package/src/runtime/controller-realtime-client.ts +591 -0
  314. package/src/runtime/create-air-jam-app.tsx +260 -0
  315. package/src/runtime/dev-runtime-events.ts +36 -0
  316. package/src/runtime/embedded-runtime-adapters.ts +68 -0
  317. package/src/runtime/host-bridge.ts +388 -0
  318. package/src/runtime/host-realtime-client.ts +550 -0
  319. package/src/runtime/iframe-bridge.ts +135 -0
  320. package/src/runtime/realtime-client.ts +20 -0
  321. package/src/runtime/router-basename.ts +25 -0
  322. package/src/runtime/runtime-owner-contexts.tsx +4 -0
  323. package/src/runtime/runtime-session-params.ts +169 -0
  324. package/src/runtime/sdk-version.ts +6 -0
  325. package/src/runtime/session-runtimes.tsx +188 -0
  326. package/src/runtime/validate-arcade-bridge-attach.ts +14 -0
  327. package/src/runtime-control.ts +10 -0
  328. package/src/runtime-inspection.ts +14 -0
  329. package/src/runtime-observability.ts +9 -0
  330. package/src/runtime-topology.ts +569 -0
  331. package/src/settings/platform-settings-bridge.ts +336 -0
  332. package/src/settings/platform-settings-runtime.tsx +387 -0
  333. package/src/settings/platform-settings.ts +288 -0
  334. package/src/state/connection-store.ts +80 -12
  335. package/src/store/air-jam-store-domain-constants.ts +4 -0
  336. package/src/store/create-air-jam-store.ts +1094 -227
  337. package/src/styles.css +4 -38
  338. package/src/ui.ts +29 -0
  339. package/src/utils/is-rpc-serializable.ts +56 -0
  340. package/src/utils/player-avatar-url.ts +48 -0
  341. package/src/utils/url-builder.ts +7 -0
  342. package/dist/.tsbuildinfo +0 -1
  343. package/dist/chunk-B5DURUWT.js +0 -80
  344. package/dist/chunk-B5DURUWT.js.map +0 -1
  345. package/src/AirJamClient.ts +0 -224
  346. package/src/audio/volume-store.ts +0 -124
  347. package/src/components/controller-shell.tsx +0 -346
  348. package/src/components/host-shell.tsx +0 -520
  349. package/src/components/qr-scanner-dialog.tsx +0 -373
  350. package/src/components/ui/alert.tsx +0 -66
  351. package/src/components/ui/avatar.tsx +0 -46
  352. package/src/components/ui/badge.tsx +0 -47
  353. package/src/components/ui/card.tsx +0 -92
  354. package/src/components/ui/dialog.tsx +0 -122
  355. package/src/components/ui/tabs.tsx +0 -64
  356. package/src/hooks/use-air-jam-shell.ts +0 -379
  357. package/src/hooks/use-fullscreen.ts +0 -108
@@ -1,140 +1,261 @@
1
- /* eslint-disable react-refresh/only-export-components */
2
- import { createContext, useContext, useEffect, useRef } from "react";
1
+ import {
2
+ createContext,
3
+ useCallback,
4
+ useContext,
5
+ useEffect,
6
+ useMemo,
7
+ useState,
8
+ type ReactNode,
9
+ } from "react";
3
10
  import { useStore } from "zustand";
4
11
  import { useAirJamContext } from "../context/air-jam-context";
5
- import { AudioManager, SoundManifest } from "./audio-manager";
12
+ import type { PlaySoundPayload } from "../protocol";
13
+ import { getControllerRealtimeClient } from "../runtime/controller-realtime-client";
14
+ import { getHostRealtimeClient } from "../runtime/host-realtime-client";
15
+ import {
16
+ usePlatformSettingsRuntimeStatus,
17
+ useResolvedPlatformSettingsSnapshot,
18
+ } from "../settings/platform-settings-runtime";
19
+ import {
20
+ AudioManager,
21
+ type AudioHandle,
22
+ type SoundManifest,
23
+ } from "./audio-manager";
6
24
 
7
- // Module-level singleton manager cache
8
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
- const managerCache = new WeakMap<SoundManifest, AudioManager<any>>();
10
25
  let globalInitialized = false;
26
+ const audioManagerContext = createContext<AudioHandle<string> | null>(null);
27
+ const audioRuntimeStatusContext = createContext<AudioRuntimeStatus | null>(
28
+ null,
29
+ );
30
+ const audioRuntimeControlsContext = createContext<AudioRuntimeControls | null>(
31
+ null,
32
+ );
11
33
 
12
- /**
13
- * Hook to use audio with a sound manifest
14
- * Creates a singleton AudioManager for the manifest and handles socket injection
15
- * @param manifest The sound manifest configuration
16
- * @returns The AudioManager instance with type-safe sound IDs
17
- */
18
- export function useAudio<M extends SoundManifest>(
34
+ export type AudioRuntimeStatus = "idle" | "blocked" | "ready";
35
+
36
+ export interface AudioRuntimeControls {
37
+ retry: () => Promise<boolean>;
38
+ }
39
+
40
+ export interface AudioRuntimeProps<M extends SoundManifest = SoundManifest> {
41
+ manifest: M;
42
+ children: ReactNode;
43
+ }
44
+
45
+ export function AudioRuntime<M extends SoundManifest>({
46
+ manifest,
47
+ children,
48
+ }: AudioRuntimeProps<M>) {
49
+ const { manager, status, controls } = useOwnedAudio(manifest);
50
+
51
+ useRemoteSound(manifest, manager);
52
+
53
+ return (
54
+ <audioRuntimeStatusContext.Provider value={status}>
55
+ <audioRuntimeControlsContext.Provider value={controls}>
56
+ <audioManagerContext.Provider value={manager as AudioHandle<string>}>
57
+ {children}
58
+ </audioManagerContext.Provider>
59
+ </audioRuntimeControlsContext.Provider>
60
+ </audioRuntimeStatusContext.Provider>
61
+ );
62
+ }
63
+
64
+ export function useAudio<T extends string = string>(): AudioHandle<T> {
65
+ const manager = useContext(audioManagerContext);
66
+
67
+ if (!manager) {
68
+ throw new Error("useAudio must be used within an AudioRuntime");
69
+ }
70
+
71
+ return manager as AudioHandle<T>;
72
+ }
73
+
74
+ export function useAudioRuntimeStatus(): AudioRuntimeStatus {
75
+ const status = useContext(audioRuntimeStatusContext);
76
+
77
+ if (!status) {
78
+ throw new Error(
79
+ "useAudioRuntimeStatus must be used within an AudioRuntime",
80
+ );
81
+ }
82
+
83
+ return status;
84
+ }
85
+
86
+ export function useAudioRuntimeControls(): AudioRuntimeControls {
87
+ const controls = useContext(audioRuntimeControlsContext);
88
+
89
+ if (!controls) {
90
+ throw new Error(
91
+ "useAudioRuntimeControls must be used within an AudioRuntime",
92
+ );
93
+ }
94
+
95
+ return controls;
96
+ }
97
+
98
+ function useOwnedAudio<M extends SoundManifest>(
19
99
  manifest: M,
20
- ): AudioManager<keyof M & string> {
100
+ ): {
101
+ manager: AudioManager<keyof M & string>;
102
+ status: AudioRuntimeStatus;
103
+ controls: AudioRuntimeControls;
104
+ } {
21
105
  const { store, getSocket } = useAirJamContext();
22
106
  const roomId = useStore(store, (state) => state.roomId);
23
107
  const role = useStore(store, (state) => state.role);
24
- const initRef = useRef(false);
25
-
26
- // Get or create singleton manager for this manifest
108
+ const platformSettings = useResolvedPlatformSettingsSnapshot();
109
+ const platformSettingsStatus = usePlatformSettingsRuntimeStatus();
110
+ const platformSettingsReady = platformSettingsStatus === "ready";
27
111
  type SoundId = keyof M & string;
28
- let manager = managerCache.get(manifest) as AudioManager<SoundId> | undefined;
29
- if (!manager) {
30
- manager = new AudioManager<SoundId>(manifest);
31
- managerCache.set(manifest, manager);
32
- }
112
+ const manager = useMemo(
113
+ () => new AudioManager<SoundId>(manifest),
114
+ [manifest],
115
+ );
116
+ const [status, setStatus] = useState<AudioRuntimeStatus>(() =>
117
+ globalInitialized && platformSettingsReady ? "ready" : "idle",
118
+ );
119
+
120
+ const retry = useCallback(async () => {
121
+ if (!platformSettingsReady) {
122
+ setStatus("idle");
123
+ return false;
124
+ }
125
+
126
+ const ready = await manager.init();
127
+ if (ready) {
128
+ globalInitialized = true;
129
+ setStatus("ready");
130
+ return true;
131
+ }
132
+
133
+ setStatus((current) => (current === "ready" ? current : "blocked"));
134
+ return false;
135
+ }, [manager, platformSettingsReady]);
136
+
137
+ useEffect(() => {
138
+ if (!platformSettingsReady) {
139
+ return;
140
+ }
141
+
142
+ manager.applyPlatformAudioSettings(platformSettings.audio);
143
+ }, [manager, platformSettings.audio, platformSettingsReady]);
144
+
145
+ useEffect(() => {
146
+ if (platformSettingsReady) {
147
+ return;
148
+ }
149
+
150
+ setStatus("idle");
151
+ }, [platformSettingsReady]);
33
152
 
34
- // Inject socket into manager when connection is available
35
153
  useEffect(() => {
36
154
  if (role && roomId) {
37
- const socket = getSocket(role);
38
- manager.setSocket(socket, roomId);
155
+ const directSocket = getSocket(role);
156
+ if (!directSocket) {
157
+ manager.setSocket(null, roomId, role);
158
+ return;
159
+ }
160
+
161
+ const realtimeClient =
162
+ role === "controller"
163
+ ? getControllerRealtimeClient(() => directSocket)
164
+ : getHostRealtimeClient(() => directSocket);
165
+ manager.setSocket(realtimeClient, roomId, role);
39
166
  }
40
167
  }, [manager, role, roomId, getSocket]);
41
168
 
42
- // Ensure audio context is resumed on first interaction (only once globally)
43
169
  useEffect(() => {
44
- if (initRef.current || globalInitialized) return;
170
+ return () => {
171
+ manager.destroy();
172
+ };
173
+ }, [manager]);
174
+
175
+ useEffect(() => {
176
+ void retry();
177
+ }, [retry]);
178
+
179
+ useEffect(() => {
180
+ if (status === "ready") {
181
+ return;
182
+ }
45
183
 
46
184
  const handleInteraction = () => {
47
- manager.init();
48
- globalInitialized = true;
49
- initRef.current = true;
50
- window.removeEventListener("click", handleInteraction);
51
- window.removeEventListener("touchstart", handleInteraction);
52
- window.removeEventListener("keydown", handleInteraction);
185
+ void retry();
53
186
  };
54
187
 
55
188
  window.addEventListener("click", handleInteraction);
56
189
  window.addEventListener("touchstart", handleInteraction);
57
190
  window.addEventListener("keydown", handleInteraction);
191
+ window.addEventListener("pointerdown", handleInteraction);
192
+ window.addEventListener("mousedown", handleInteraction);
58
193
 
59
194
  return () => {
60
195
  window.removeEventListener("click", handleInteraction);
61
196
  window.removeEventListener("touchstart", handleInteraction);
62
197
  window.removeEventListener("keydown", handleInteraction);
198
+ window.removeEventListener("pointerdown", handleInteraction);
199
+ window.removeEventListener("mousedown", handleInteraction);
63
200
  };
64
- }, [manager]);
201
+ }, [retry, status]);
65
202
 
66
- return manager;
203
+ return {
204
+ manager,
205
+ status,
206
+ controls: {
207
+ retry,
208
+ },
209
+ };
67
210
  }
68
211
 
69
- // Legacy exports for backward compatibility (can be removed later)
70
- const LegacyAudioContext = createContext<AudioManager | null>(null);
212
+ const isManifestSoundId = <M extends SoundManifest>(
213
+ manifest: M,
214
+ soundId: unknown,
215
+ ): soundId is keyof M & string =>
216
+ typeof soundId === "string" &&
217
+ Object.prototype.hasOwnProperty.call(manifest, soundId);
71
218
 
72
- export const AudioProvider = ({
73
- children,
74
- manager,
75
- }: {
76
- children: React.ReactNode;
77
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
- manager: AudioManager<any>;
79
- }) => {
80
- const { store, getSocket } = useAirJamContext();
81
- const roomId = useStore(store, (state) => state.roomId);
219
+ function useRemoteSound<M extends SoundManifest>(
220
+ manifest: M,
221
+ audio: Pick<AudioHandle<keyof M & string>, "play">,
222
+ ): void {
223
+ const { getSocket, store } = useAirJamContext();
82
224
  const role = useStore(store, (state) => state.role);
225
+ const connectionStatus = useStore(store, (state) => state.connectionStatus);
226
+ const socket = useMemo(() => {
227
+ if (role !== "controller") {
228
+ return null;
229
+ }
83
230
 
84
- // Inject socket into manager
85
- useEffect(() => {
86
- if (role && roomId) {
87
- const socket = getSocket(role);
88
- manager.setSocket(socket, roomId);
231
+ const directSocket = getSocket("controller");
232
+ if (!directSocket) {
233
+ return null;
89
234
  }
90
- }, [manager, role, roomId, getSocket]);
91
235
 
92
- // Ensure audio context is resumed on first interaction
236
+ return getControllerRealtimeClient(() => directSocket);
237
+ }, [getSocket, role]);
238
+ const enabled = role === "controller" && connectionStatus === "connected";
239
+
93
240
  useEffect(() => {
94
- const handleInteraction = () => {
95
- manager.init();
96
- window.removeEventListener("click", handleInteraction);
97
- window.removeEventListener("touchstart", handleInteraction);
98
- window.removeEventListener("keydown", handleInteraction);
99
- };
241
+ if (!socket || !enabled) {
242
+ return;
243
+ }
100
244
 
101
- window.addEventListener("click", handleInteraction);
102
- window.addEventListener("touchstart", handleInteraction);
103
- window.addEventListener("keydown", handleInteraction);
245
+ const handlePlaySound = (payload: PlaySoundPayload): void => {
246
+ if (!isManifestSoundId(manifest, payload.id)) {
247
+ return;
248
+ }
104
249
 
105
- return () => {
106
- window.removeEventListener("click", handleInteraction);
107
- window.removeEventListener("touchstart", handleInteraction);
108
- window.removeEventListener("keydown", handleInteraction);
250
+ audio.play(payload.id, {
251
+ volume: payload.volume,
252
+ loop: payload.loop,
253
+ });
109
254
  };
110
- }, [manager]);
111
-
112
- return (
113
- <LegacyAudioContext.Provider value={manager}>
114
- {children}
115
- </LegacyAudioContext.Provider>
116
- );
117
- };
118
255
 
119
- export const useAudioLegacy = <T extends string = string>() => {
120
- const manager = useContext(LegacyAudioContext);
121
- if (!manager) {
122
- throw new Error("useAudioLegacy must be used within an AudioProvider");
123
- }
124
- return manager as AudioManager<T>;
125
- };
126
-
127
- /**
128
- * Hook to create a stable AudioManager instance
129
- */
130
- export const useAudioManager = <T extends string = string>(
131
- manifest: SoundManifest,
132
- ) => {
133
- const managerRef = useRef<AudioManager<T> | null>(null);
134
-
135
- if (!managerRef.current) {
136
- managerRef.current = new AudioManager<T>(manifest);
137
- }
138
-
139
- return managerRef.current;
140
- };
256
+ socket.on("server:playSound", handlePlaySound);
257
+ return () => {
258
+ socket.off("server:playSound", handlePlaySound);
259
+ };
260
+ }, [audio, enabled, manifest, socket]);
261
+ }
@@ -1,3 +1,3 @@
1
1
  export * from "./audio-manager";
2
2
  export * from "./hooks";
3
- export * from "./volume-store";
3
+ export * from "./music";
@@ -0,0 +1,139 @@
1
+ import { useEffect, useMemo, useRef } from "react";
2
+ import { getEffectiveAudioVolume } from "../settings/platform-settings";
3
+ import {
4
+ usePlatformSettingsRuntimeStatus,
5
+ useResolvedPlatformSettingsSnapshot,
6
+ } from "../settings/platform-settings-runtime";
7
+ import { type SoundCategory } from "./audio-manager";
8
+ import { useAudio, useAudioRuntimeStatus } from "./hooks";
9
+
10
+ export type AudioVolumeCategory = SoundCategory | "master";
11
+
12
+ export interface MusicPlaylistProps<TTrackId extends string = string> {
13
+ tracks: readonly TTrackId[];
14
+ playing: boolean;
15
+ order?: "sequence" | "shuffle";
16
+ fadeMs?: number;
17
+ startIndex?: number;
18
+ }
19
+
20
+ export function useAudioCategoryVolume(category: AudioVolumeCategory): number {
21
+ const settingsStatus = usePlatformSettingsRuntimeStatus();
22
+ const settings = useResolvedPlatformSettingsSnapshot();
23
+
24
+ if (settingsStatus !== "ready") {
25
+ return 0;
26
+ }
27
+
28
+ if (category === "master") {
29
+ return settings.audio.masterVolume;
30
+ }
31
+
32
+ return getEffectiveAudioVolume(settings.audio, category);
33
+ }
34
+
35
+ export function useMusicVolume(): number {
36
+ return useAudioCategoryVolume("music");
37
+ }
38
+
39
+ export function MusicPlaylist<TTrackId extends string = string>({
40
+ tracks,
41
+ playing,
42
+ order = "sequence",
43
+ fadeMs = 1000,
44
+ startIndex = 0,
45
+ }: MusicPlaylistProps<TTrackId>) {
46
+ const audio = useAudio<TTrackId>();
47
+ const status = useAudioRuntimeStatus();
48
+ const activeRef = useRef<{ trackId: TTrackId; soundId: number } | null>(null);
49
+ const generationRef = useRef(0);
50
+ const tracksRef = useRef(tracks);
51
+ const tracksKey = useMemo(() => tracks.join("\0"), [tracks]);
52
+ tracksRef.current = tracks;
53
+
54
+ useEffect(() => {
55
+ const generation = generationRef.current + 1;
56
+ generationRef.current = generation;
57
+ let disposed = false;
58
+
59
+ const stopActive = () => {
60
+ const active = activeRef.current;
61
+ if (!active) {
62
+ return;
63
+ }
64
+
65
+ activeRef.current = null;
66
+ audio.fadeOutAndStop(active.trackId, active.soundId, fadeMs);
67
+ };
68
+
69
+ const getNextIndex = (currentIndex: number): number => {
70
+ const currentTracks = tracksRef.current;
71
+ if (currentTracks.length <= 1) {
72
+ return 0;
73
+ }
74
+
75
+ if (order === "shuffle") {
76
+ const randomOffset = Math.floor(
77
+ Math.random() * (currentTracks.length - 1),
78
+ );
79
+ return (currentIndex + 1 + randomOffset) % currentTracks.length;
80
+ }
81
+
82
+ return (currentIndex + 1) % currentTracks.length;
83
+ };
84
+
85
+ const startTrack = (trackIndex: number) => {
86
+ const currentTracks = tracksRef.current;
87
+ if (
88
+ disposed ||
89
+ generationRef.current !== generation ||
90
+ !playing ||
91
+ status !== "ready" ||
92
+ currentTracks.length === 0
93
+ ) {
94
+ return;
95
+ }
96
+
97
+ const normalizedIndex =
98
+ ((trackIndex % currentTracks.length) + currentTracks.length) %
99
+ currentTracks.length;
100
+ const trackId = currentTracks[normalizedIndex];
101
+ const soundId = audio.play(trackId, {
102
+ fadeInMs: fadeMs,
103
+ loop: false,
104
+ onEnd: (endedSoundId) => {
105
+ const active = activeRef.current;
106
+ if (
107
+ disposed ||
108
+ generationRef.current !== generation ||
109
+ !active ||
110
+ active.trackId !== trackId ||
111
+ active.soundId !== endedSoundId
112
+ ) {
113
+ return;
114
+ }
115
+
116
+ activeRef.current = null;
117
+ startTrack(getNextIndex(normalizedIndex));
118
+ },
119
+ });
120
+
121
+ if (soundId !== null) {
122
+ activeRef.current = { trackId, soundId };
123
+ }
124
+ };
125
+
126
+ stopActive();
127
+
128
+ if (playing && status === "ready" && tracksRef.current.length > 0) {
129
+ startTrack(startIndex);
130
+ }
131
+
132
+ return () => {
133
+ disposed = true;
134
+ stopActive();
135
+ };
136
+ }, [audio, fadeMs, order, playing, startIndex, status, tracksKey]);
137
+
138
+ return null;
139
+ }
@@ -0,0 +1,71 @@
1
+ export type AirJamGameActionCapabilityKind =
2
+ | "button"
3
+ | "axis"
4
+ | "trigger"
5
+ | "command"
6
+ | "composite";
7
+
8
+ export type AirJamGameStateCapabilityKind =
9
+ | "phase"
10
+ | "boolean"
11
+ | "number"
12
+ | "enum"
13
+ | "text"
14
+ | "collection";
15
+
16
+ export type AirJamGameEvaluationCapabilityKind =
17
+ | "success"
18
+ | "failure"
19
+ | "progress"
20
+ | "score"
21
+ | "quality";
22
+
23
+ export type AirJamGameCapabilityAudience = "host" | "controller" | "shared";
24
+
25
+ interface AirJamGameCapabilityDescriptorBase {
26
+ key: string;
27
+ label: string;
28
+ description?: string;
29
+ audience?: AirJamGameCapabilityAudience;
30
+ }
31
+
32
+ export interface AirJamGameActionCapability extends AirJamGameCapabilityDescriptorBase {
33
+ kind: AirJamGameActionCapabilityKind;
34
+ }
35
+
36
+ export interface AirJamGameStateCapability extends AirJamGameCapabilityDescriptorBase {
37
+ kind: AirJamGameStateCapabilityKind;
38
+ }
39
+
40
+ export interface AirJamGameEvaluationCapability extends AirJamGameCapabilityDescriptorBase {
41
+ kind: AirJamGameEvaluationCapabilityKind;
42
+ }
43
+
44
+ export interface AirJamGameCapabilityManifest {
45
+ version: 1;
46
+ actions?: readonly AirJamGameActionCapability[];
47
+ state?: readonly AirJamGameStateCapability[];
48
+ evaluation?: readonly AirJamGameEvaluationCapability[];
49
+ }
50
+
51
+ export type DefineAirJamGameCapabilitiesInput = Omit<
52
+ AirJamGameCapabilityManifest,
53
+ "version"
54
+ > & {
55
+ version?: 1;
56
+ };
57
+
58
+ const cloneSection = <T>(
59
+ entries: readonly T[] | undefined,
60
+ ): readonly T[] | undefined =>
61
+ entries ? Object.freeze([...entries]) : undefined;
62
+
63
+ export const defineAirJamGameCapabilities = (
64
+ input: DefineAirJamGameCapabilitiesInput,
65
+ ): AirJamGameCapabilityManifest =>
66
+ Object.freeze({
67
+ version: 1,
68
+ actions: cloneSection(input.actions),
69
+ state: cloneSection(input.state),
70
+ evaluation: cloneSection(input.evaluation),
71
+ });
@@ -0,0 +1,12 @@
1
+ export {
2
+ defineAirJamGameCapabilities,
3
+ type AirJamGameActionCapability,
4
+ type AirJamGameActionCapabilityKind,
5
+ type AirJamGameCapabilityAudience,
6
+ type AirJamGameCapabilityManifest,
7
+ type AirJamGameEvaluationCapability,
8
+ type AirJamGameEvaluationCapabilityKind,
9
+ type AirJamGameStateCapability,
10
+ type AirJamGameStateCapabilityKind,
11
+ type DefineAirJamGameCapabilitiesInput,
12
+ } from "./capabilities/manifest";
@@ -0,0 +1,55 @@
1
+ import type { ConnectionStatus } from "../protocol";
2
+ import { cn } from "../utils/cn";
3
+
4
+ const statusLabelByConnection: Record<ConnectionStatus, string> = {
5
+ connected: "Live",
6
+ connecting: "Syncing",
7
+ reconnecting: "Syncing",
8
+ disconnected: "Offline",
9
+ idle: "Idle",
10
+ };
11
+
12
+ const statusToneByConnection: Record<ConnectionStatus, string> = {
13
+ connected: "border-emerald-400/18 bg-emerald-400/8 text-emerald-50",
14
+ connecting: "border-amber-400/18 bg-amber-400/8 text-amber-50",
15
+ reconnecting: "border-amber-400/18 bg-amber-400/8 text-amber-50",
16
+ disconnected: "border-rose-400/18 bg-rose-400/8 text-rose-50",
17
+ idle: "border-white/10 bg-white/[0.05] text-white/78",
18
+ };
19
+
20
+ const statusDotToneByConnection: Record<ConnectionStatus, string> = {
21
+ connected: "bg-emerald-300",
22
+ connecting: "bg-amber-300",
23
+ reconnecting: "bg-amber-300",
24
+ disconnected: "bg-rose-300",
25
+ idle: "bg-white/45",
26
+ };
27
+
28
+ export interface ConnectionStatusPillProps {
29
+ status: ConnectionStatus;
30
+ className?: string;
31
+ }
32
+
33
+ export const ConnectionStatusPill = ({
34
+ status,
35
+ className,
36
+ }: ConnectionStatusPillProps) => {
37
+ return (
38
+ <span
39
+ className={cn(
40
+ "inline-flex shrink-0 items-center gap-1.5 rounded-full border px-2.5 py-1 text-[0.625rem] font-semibold tracking-[0.16em] uppercase",
41
+ statusToneByConnection[status],
42
+ className,
43
+ )}
44
+ >
45
+ <span
46
+ className={cn(
47
+ "h-1.5 w-1.5 shrink-0 rounded-full",
48
+ statusDotToneByConnection[status],
49
+ )}
50
+ aria-hidden
51
+ />
52
+ {statusLabelByConnection[status]}
53
+ </span>
54
+ );
55
+ };