@air-jam/sdk 0.1.3 → 0.9.0

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 (348) 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 +488 -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 +13 -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 +363 -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 +28 -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 +1565 -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 +122 -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-2432OL7L.js +193 -0
  70. package/dist/chunk-2432OL7L.js.map +1 -0
  71. package/dist/chunk-2J65FXEP.js +41 -0
  72. package/dist/chunk-2J65FXEP.js.map +1 -0
  73. package/dist/chunk-32NYL7XI.js +539 -0
  74. package/dist/chunk-32NYL7XI.js.map +1 -0
  75. package/dist/chunk-3USU7GY2.js +54 -0
  76. package/dist/chunk-3USU7GY2.js.map +1 -0
  77. package/dist/chunk-BE6Z4SIT.js +65 -0
  78. package/dist/chunk-BE6Z4SIT.js.map +1 -0
  79. package/dist/chunk-CQUG24WX.js +249 -0
  80. package/dist/chunk-CQUG24WX.js.map +1 -0
  81. package/dist/chunk-D3X4MN4U.js +288 -0
  82. package/dist/chunk-D3X4MN4U.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-HFWRZVZ3.js +1438 -0
  86. package/dist/chunk-HFWRZVZ3.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-JTF47B56.js +1 -0
  90. package/dist/chunk-JTF47B56.js.map +1 -0
  91. package/dist/chunk-LIXPF4P6.js +22 -0
  92. package/dist/chunk-LIXPF4P6.js.map +1 -0
  93. package/dist/chunk-MKBASO6X.js +216 -0
  94. package/dist/chunk-MKBASO6X.js.map +1 -0
  95. package/dist/chunk-MPDMJIX5.js +1 -0
  96. package/dist/chunk-MPDMJIX5.js.map +1 -0
  97. package/dist/chunk-NCL6WJCL.js +91 -0
  98. package/dist/chunk-NCL6WJCL.js.map +1 -0
  99. package/dist/chunk-NU5W6VAV.js +126 -0
  100. package/dist/chunk-NU5W6VAV.js.map +1 -0
  101. package/dist/chunk-TGRTEWYV.js +195 -0
  102. package/dist/chunk-TGRTEWYV.js.map +1 -0
  103. package/dist/chunk-VDRNNGHX.js +184 -0
  104. package/dist/chunk-VDRNNGHX.js.map +1 -0
  105. package/dist/chunk-VN5LDWVN.js +32 -0
  106. package/dist/chunk-VN5LDWVN.js.map +1 -0
  107. package/dist/chunk-W2VK36RO.js +11 -0
  108. package/dist/chunk-W2VK36RO.js.map +1 -0
  109. package/dist/chunk-X24K52DG.js +12 -0
  110. package/dist/chunk-X24K52DG.js.map +1 -0
  111. package/dist/chunk-XLUWV45V.js +25 -0
  112. package/dist/chunk-XLUWV45V.js.map +1 -0
  113. package/dist/chunk-Y4RAPKKB.js +238 -0
  114. package/dist/chunk-Y4RAPKKB.js.map +1 -0
  115. package/dist/chunk-YXHH3MQT.js +230 -0
  116. package/dist/chunk-YXHH3MQT.js.map +1 -0
  117. package/dist/chunk-ZLPL2R3R.js +183 -0
  118. package/dist/chunk-ZLPL2R3R.js.map +1 -0
  119. package/dist/chunk-ZTQ5SP4H.js +9 -0
  120. package/dist/chunk-ZTQ5SP4H.js.map +1 -0
  121. package/dist/controller-Bod8YYr1.d.cts +172 -0
  122. package/dist/controller-DxVchfiA.d.ts +172 -0
  123. package/dist/dev-log-events-CVAM29hx.d.cts +123 -0
  124. package/dist/dev-log-events-CVAM29hx.d.ts +123 -0
  125. package/dist/handshake-CC_LrK5g.d.cts +31 -0
  126. package/dist/handshake-CC_LrK5g.d.ts +31 -0
  127. package/dist/host-8hmq_Sgc.d.cts +109 -0
  128. package/dist/host-Cw-N6e-5.d.ts +109 -0
  129. package/dist/index.cjs +8512 -3518
  130. package/dist/index.cjs.map +1 -1
  131. package/dist/index.d.cts +676 -1070
  132. package/dist/index.d.ts +676 -1070
  133. package/dist/index.js +4892 -3188
  134. package/dist/index.js.map +1 -1
  135. package/dist/metadata.cjs +114 -0
  136. package/dist/metadata.cjs.map +1 -0
  137. package/dist/metadata.d.cts +95 -0
  138. package/dist/metadata.d.ts +95 -0
  139. package/dist/metadata.js +83 -0
  140. package/dist/metadata.js.map +1 -0
  141. package/dist/notices-CnGaaS8B.d.ts +38 -0
  142. package/dist/notices-NyDM5Mtz.d.cts +38 -0
  143. package/dist/platform-machine.cjs +425 -0
  144. package/dist/platform-machine.cjs.map +1 -0
  145. package/dist/platform-machine.d.cts +1183 -0
  146. package/dist/platform-machine.d.ts +1183 -0
  147. package/dist/platform-machine.js +309 -0
  148. package/dist/platform-machine.js.map +1 -0
  149. package/dist/platform-settings-cuor3i11.d.cts +48 -0
  150. package/dist/platform-settings-cuor3i11.d.ts +48 -0
  151. package/dist/prefabs.cjs +36 -0
  152. package/dist/prefabs.cjs.map +1 -0
  153. package/dist/prefabs.d.cts +49 -0
  154. package/dist/prefabs.d.ts +49 -0
  155. package/dist/prefabs.js +8 -0
  156. package/dist/prefabs.js.map +1 -0
  157. package/dist/preview.cjs +2609 -0
  158. package/dist/preview.cjs.map +1 -0
  159. package/dist/preview.d.cts +155 -0
  160. package/dist/preview.d.ts +155 -0
  161. package/dist/preview.js +1671 -0
  162. package/dist/preview.js.map +1 -0
  163. package/dist/protocol.cjs +621 -54
  164. package/dist/protocol.cjs.map +1 -1
  165. package/dist/protocol.d.cts +76 -240
  166. package/dist/protocol.d.ts +76 -240
  167. package/dist/protocol.js +100 -2
  168. package/dist/protocol.js.map +1 -1
  169. package/dist/realtime-client-Cu8yVJFw.d.cts +15 -0
  170. package/dist/realtime-client-Cu8yVJFw.d.ts +15 -0
  171. package/dist/release.cjs +143 -0
  172. package/dist/release.cjs.map +1 -0
  173. package/dist/release.d.cts +64 -0
  174. package/dist/release.d.ts +64 -0
  175. package/dist/release.js +43 -0
  176. package/dist/release.js.map +1 -0
  177. package/dist/standard-match-phase-BucA5dYo.d.ts +44 -0
  178. package/dist/standard-match-phase-U2ra8J-0.d.cts +44 -0
  179. package/dist/sync-B6QsNrXz.d.cts +125 -0
  180. package/dist/sync-B6QsNrXz.d.ts +125 -0
  181. package/dist/ui.cjs +2827 -0
  182. package/dist/ui.cjs.map +1 -0
  183. package/dist/ui.d.cts +320 -0
  184. package/dist/ui.d.ts +320 -0
  185. package/dist/ui.js +1718 -0
  186. package/dist/ui.js.map +1 -0
  187. package/dist/url-policy-C89zxgw9.d.cts +9 -0
  188. package/dist/url-policy-C89zxgw9.d.ts +9 -0
  189. package/package.json +154 -13
  190. package/src/agent/agent-action.ts +304 -0
  191. package/src/agent/agent-contract.ts +180 -0
  192. package/src/agent-tooling.ts +20 -0
  193. package/src/arcade/bridge/controller.ts +15 -0
  194. package/src/arcade/bridge/host.ts +12 -0
  195. package/src/arcade/bridge/iframe.ts +61 -0
  196. package/src/arcade/bridge.ts +3 -0
  197. package/src/arcade/host.ts +1 -0
  198. package/src/arcade/surface.ts +4 -0
  199. package/src/arcade/url.ts +60 -0
  200. package/src/arcade.ts +4 -0
  201. package/src/audio/audio-manager.ts +162 -171
  202. package/src/audio/hooks.tsx +218 -97
  203. package/src/audio/index.ts +1 -1
  204. package/src/audio/music.tsx +139 -0
  205. package/src/capabilities/manifest.ts +71 -0
  206. package/src/capabilities.ts +12 -0
  207. package/src/components/connection-status-pill.tsx +55 -0
  208. package/src/components/controller-player-name-field.tsx +119 -0
  209. package/src/components/controller-primary-action.tsx +58 -0
  210. package/src/components/host-mute-button.tsx +49 -0
  211. package/src/components/join-qr-overlay.tsx +133 -0
  212. package/src/components/join-url-action-buttons.tsx +95 -0
  213. package/src/components/join-url-controls.tsx +58 -0
  214. package/src/components/join-url-field.tsx +52 -0
  215. package/src/components/lifecycle-action-group.tsx +129 -0
  216. package/src/components/player-avatar-strip.tsx +65 -0
  217. package/src/components/player-avatar.tsx +42 -14
  218. package/src/components/room-qr-code.tsx +125 -0
  219. package/src/components/runtime-shell-header.tsx +37 -0
  220. package/src/components/shell-classes.ts +19 -0
  221. package/src/components/surface-orientation-layout.ts +60 -0
  222. package/src/components/surface-viewport-layout.ts +268 -0
  223. package/src/components/surface-viewport.tsx +314 -0
  224. package/src/components/ui/button.tsx +4 -6
  225. package/src/components/ui/slider.tsx +1 -1
  226. package/src/components/volume-controls.tsx +65 -6
  227. package/src/context/air-jam-context.tsx +209 -141
  228. package/src/context/index.ts +2 -2
  229. package/src/context/session-providers.tsx +77 -0
  230. package/src/context/session-scope.ts +64 -0
  231. package/src/context/socket-manager.ts +6 -25
  232. package/src/contracts/v2/bridge.ts +261 -0
  233. package/src/contracts/v2/handshake.ts +40 -0
  234. package/src/contracts/v2/index.ts +2 -0
  235. package/src/dev/browser-log-sink.ts +912 -0
  236. package/src/diagnostics.ts +128 -0
  237. package/src/events.ts +7 -34
  238. package/src/hooks/internal/use-controller-runtime-api.ts +875 -0
  239. package/src/hooks/internal/use-host-runtime-api.ts +1051 -0
  240. package/src/hooks/internal/use-runtime-control-contract.ts +15 -0
  241. package/src/hooks/internal/use-runtime-inspection-contract.ts +16 -0
  242. package/src/hooks/internal/use-runtime-observability-contract.ts +24 -0
  243. package/src/hooks/use-air-jam-controller.ts +155 -475
  244. package/src/hooks/use-air-jam-host.ts +156 -485
  245. package/src/hooks/use-connection-status.ts +8 -0
  246. package/src/hooks/use-controller-lifecycle-intents.ts +27 -0
  247. package/src/hooks/use-controller-lifecycle-permissions.ts +36 -0
  248. package/src/hooks/use-controller-shell-status.ts +40 -0
  249. package/src/hooks/use-controller-tick.ts +65 -0
  250. package/src/hooks/use-controller-toasts.ts +116 -0
  251. package/src/hooks/use-get-input.ts +8 -5
  252. package/src/hooks/use-host-arcade-restore.ts +30 -0
  253. package/src/hooks/use-host-join-controls.ts +152 -0
  254. package/src/hooks/use-host-tick.ts +171 -0
  255. package/src/hooks/use-input-writer.ts +83 -0
  256. package/src/hooks/use-lifecycle-action-group-model.ts +98 -0
  257. package/src/hooks/use-players.ts +12 -0
  258. package/src/hooks/use-room.ts +22 -0
  259. package/src/hooks/use-send-signal.ts +6 -2
  260. package/src/index.ts +205 -31
  261. package/src/internal/input-manager.ts +195 -215
  262. package/src/lifecycle/index.ts +9 -0
  263. package/src/lifecycle/standard-match-phase.ts +32 -0
  264. package/src/metadata/manifest.ts +152 -0
  265. package/src/metadata.ts +12 -0
  266. package/src/platform-machine.ts +475 -0
  267. package/src/prefabs/types.ts +82 -0
  268. package/src/prefabs.ts +12 -0
  269. package/src/preview/host-workspace.tsx +59 -0
  270. package/src/preview/identity.ts +66 -0
  271. package/src/preview/layout.ts +223 -0
  272. package/src/preview/manager.ts +577 -0
  273. package/src/preview/messages.ts +26 -0
  274. package/src/preview/ownership.ts +81 -0
  275. package/src/preview/url.ts +117 -0
  276. package/src/preview/window.tsx +490 -0
  277. package/src/preview/workspace.tsx +678 -0
  278. package/src/preview.ts +42 -0
  279. package/src/protocol/arcade-platform-actions.ts +29 -0
  280. package/src/protocol/controller.ts +187 -0
  281. package/src/protocol/core.ts +23 -0
  282. package/src/protocol/dev-log-events.ts +222 -0
  283. package/src/protocol/errors.ts +21 -0
  284. package/src/protocol/host-grant.ts +185 -0
  285. package/src/protocol/host.ts +138 -0
  286. package/src/protocol/notices.ts +43 -0
  287. package/src/protocol/signals.ts +38 -0
  288. package/src/protocol/socket-events.ts +154 -0
  289. package/src/protocol/sync.ts +121 -0
  290. package/src/protocol/url-policy.ts +63 -0
  291. package/src/protocol.ts +12 -386
  292. package/src/qrcode.d.ts +16 -0
  293. package/src/release.ts +99 -0
  294. package/src/runtime/air-jam-config.ts +287 -0
  295. package/src/runtime/air-jam-error-boundary.tsx +672 -0
  296. package/src/runtime/arcade-bridge-request-surface.ts +15 -0
  297. package/src/runtime/arcade-runtime-url.ts +95 -0
  298. package/src/runtime/arcade-surface-identity.ts +16 -0
  299. package/src/runtime/contracts/control.ts +68 -0
  300. package/src/runtime/contracts/inspection.ts +165 -0
  301. package/src/runtime/contracts/observability.ts +94 -0
  302. package/src/runtime/controller-bridge.ts +451 -0
  303. package/src/runtime/controller-identity.ts +132 -0
  304. package/src/runtime/controller-presentation.ts +24 -0
  305. package/src/runtime/controller-realtime-client.ts +591 -0
  306. package/src/runtime/create-air-jam-app.tsx +260 -0
  307. package/src/runtime/dev-runtime-events.ts +36 -0
  308. package/src/runtime/embedded-runtime-adapters.ts +68 -0
  309. package/src/runtime/host-bridge.ts +388 -0
  310. package/src/runtime/host-realtime-client.ts +550 -0
  311. package/src/runtime/iframe-bridge.ts +135 -0
  312. package/src/runtime/realtime-client.ts +20 -0
  313. package/src/runtime/router-basename.ts +25 -0
  314. package/src/runtime/runtime-owner-contexts.tsx +4 -0
  315. package/src/runtime/runtime-session-params.ts +169 -0
  316. package/src/runtime/sdk-version.ts +6 -0
  317. package/src/runtime/session-runtimes.tsx +188 -0
  318. package/src/runtime/validate-arcade-bridge-attach.ts +14 -0
  319. package/src/runtime-control.ts +10 -0
  320. package/src/runtime-inspection.ts +14 -0
  321. package/src/runtime-observability.ts +9 -0
  322. package/src/settings/platform-settings-bridge.ts +336 -0
  323. package/src/settings/platform-settings-runtime.tsx +387 -0
  324. package/src/settings/platform-settings.ts +288 -0
  325. package/src/state/connection-store.ts +80 -12
  326. package/src/store/air-jam-store-domain-constants.ts +4 -0
  327. package/src/store/create-air-jam-store.ts +1094 -227
  328. package/src/styles.css +4 -38
  329. package/src/ui.ts +29 -0
  330. package/src/utils/is-rpc-serializable.ts +56 -0
  331. package/src/utils/player-avatar-url.ts +48 -0
  332. package/src/utils/url-builder.ts +7 -0
  333. package/dist/.tsbuildinfo +0 -1
  334. package/dist/chunk-B5DURUWT.js +0 -80
  335. package/dist/chunk-B5DURUWT.js.map +0 -1
  336. package/src/AirJamClient.ts +0 -224
  337. package/src/audio/volume-store.ts +0 -124
  338. package/src/components/controller-shell.tsx +0 -346
  339. package/src/components/host-shell.tsx +0 -521
  340. package/src/components/qr-scanner-dialog.tsx +0 -373
  341. package/src/components/ui/alert.tsx +0 -66
  342. package/src/components/ui/avatar.tsx +0 -46
  343. package/src/components/ui/badge.tsx +0 -47
  344. package/src/components/ui/card.tsx +0 -92
  345. package/src/components/ui/dialog.tsx +0 -122
  346. package/src/components/ui/tabs.tsx +0 -64
  347. package/src/hooks/use-air-jam-shell.ts +0 -379
  348. package/src/hooks/use-fullscreen.ts +0 -108
@@ -0,0 +1,119 @@
1
+ import type { JSX } from "react";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { useAirJamController } from "../hooks/use-air-jam-controller";
4
+ import { cn } from "../utils/cn";
5
+
6
+ const LABEL_MAX = 24;
7
+ const DEFAULT_DEBOUNCE_MS = 400;
8
+
9
+ export type ControllerPlayerNameFieldProps = {
10
+ /** Screen-reader / visible label copy */
11
+ fieldLabel?: string;
12
+ className?: string;
13
+ labelClassName?: string;
14
+ inputClassName?: string;
15
+ debounceMs?: number;
16
+ };
17
+
18
+ /**
19
+ * Edits the live room player display name. While connected, changes are sent with
20
+ * {@link AirJamControllerApi.updatePlayerProfile} (debounced) and broadcast to the room via
21
+ * `server:playerUpdated`. Also updates the nickname draft for the next join.
22
+ */
23
+ export const ControllerPlayerNameField = ({
24
+ fieldLabel = "Your name",
25
+ className,
26
+ labelClassName,
27
+ inputClassName,
28
+ debounceMs = DEFAULT_DEBOUNCE_MS,
29
+ }: ControllerPlayerNameFieldProps): JSX.Element => {
30
+ const controller = useAirJamController();
31
+ const [local, setLocal] = useState("");
32
+ const inputRef = useRef<HTMLInputElement>(null);
33
+ const debounceTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
34
+ const nextPlayerLabel = controller.selfPlayer?.label?.trim() ?? "";
35
+
36
+ useEffect(() => {
37
+ if (inputRef.current === document.activeElement) {
38
+ return;
39
+ }
40
+ setLocal(nextPlayerLabel);
41
+ }, [controller.controllerId, nextPlayerLabel]);
42
+
43
+ useEffect(
44
+ () => () => {
45
+ if (debounceTimerRef.current !== null) {
46
+ clearTimeout(debounceTimerRef.current);
47
+ }
48
+ },
49
+ [],
50
+ );
51
+
52
+ const pushRoomName = useCallback(
53
+ (raw: string) => {
54
+ const trimmed = raw.trim().slice(0, LABEL_MAX);
55
+ if (trimmed.length < 1) {
56
+ return;
57
+ }
58
+ controller.setNickname(trimmed);
59
+ void controller.updatePlayerProfile({ label: trimmed });
60
+ },
61
+ [controller],
62
+ );
63
+
64
+ const schedulePush = useCallback(
65
+ (raw: string) => {
66
+ if (debounceTimerRef.current !== null) {
67
+ clearTimeout(debounceTimerRef.current);
68
+ }
69
+ debounceTimerRef.current = setTimeout(() => {
70
+ debounceTimerRef.current = null;
71
+ pushRoomName(raw);
72
+ }, debounceMs);
73
+ },
74
+ [debounceMs, pushRoomName],
75
+ );
76
+
77
+ const connected = controller.connectionStatus === "connected";
78
+
79
+ return (
80
+ <div className={cn("min-w-0", className)}>
81
+ <label
82
+ className={cn("mb-1 block", labelClassName)}
83
+ htmlFor="airjam-controller-player-name"
84
+ >
85
+ {fieldLabel}
86
+ </label>
87
+ <input
88
+ ref={inputRef}
89
+ id="airjam-controller-player-name"
90
+ type="text"
91
+ name="airjam-controller-player-name"
92
+ autoComplete="nickname"
93
+ enterKeyHint="done"
94
+ maxLength={LABEL_MAX}
95
+ disabled={!connected}
96
+ value={local}
97
+ placeholder={connected ? "Enter name" : "Connect to edit"}
98
+ className={cn(inputClassName)}
99
+ onChange={(event) => {
100
+ const next = event.target.value.slice(0, LABEL_MAX);
101
+ setLocal(next);
102
+ schedulePush(next);
103
+ }}
104
+ onBlur={() => {
105
+ if (debounceTimerRef.current !== null) {
106
+ clearTimeout(debounceTimerRef.current);
107
+ debounceTimerRef.current = null;
108
+ }
109
+ const trimmed = local.trim();
110
+ if (trimmed.length < 1) {
111
+ setLocal(nextPlayerLabel);
112
+ return;
113
+ }
114
+ pushRoomName(local);
115
+ }}
116
+ />
117
+ </div>
118
+ );
119
+ };
@@ -0,0 +1,58 @@
1
+ import type { JSX, ReactNode } from "react";
2
+ import { cn } from "../utils/cn";
3
+ import { Button } from "./ui/button";
4
+
5
+ export interface ControllerPrimaryActionProps {
6
+ label: string;
7
+ helper?: string;
8
+ icon?: ReactNode;
9
+ disabled?: boolean;
10
+ onPress?: () => void;
11
+ testId?: string;
12
+ className?: string;
13
+ buttonClassName?: string;
14
+ }
15
+
16
+ export const ControllerPrimaryAction = ({
17
+ label,
18
+ helper,
19
+ icon,
20
+ disabled,
21
+ onPress,
22
+ testId,
23
+ className,
24
+ buttonClassName,
25
+ }: ControllerPrimaryActionProps): JSX.Element => {
26
+ return (
27
+ <div className={cn("mt-auto pt-3", className)}>
28
+ <Button
29
+ type="button"
30
+ onClick={onPress}
31
+ disabled={disabled}
32
+ data-testid={testId}
33
+ aria-label={label}
34
+ title={label}
35
+ className={cn(
36
+ "flex h-auto min-h-18 w-full items-center justify-between rounded-[1.5rem] border border-white/15 px-5 py-4 text-left shadow-lg",
37
+ buttonClassName,
38
+ )}
39
+ >
40
+ <div className="min-w-0">
41
+ <div className="truncate text-base font-black tracking-[0.12em] uppercase sm:text-lg">
42
+ {label}
43
+ </div>
44
+ {helper ? (
45
+ <div className="mt-1 text-sm/5 font-medium tracking-normal normal-case opacity-80">
46
+ {helper}
47
+ </div>
48
+ ) : null}
49
+ </div>
50
+ {icon ? (
51
+ <div className="ml-4 flex shrink-0 items-center justify-center">
52
+ {icon}
53
+ </div>
54
+ ) : null}
55
+ </Button>
56
+ </div>
57
+ );
58
+ };
@@ -0,0 +1,49 @@
1
+ import { Volume2, VolumeX } from "lucide-react";
2
+ import { cn } from "../utils/cn";
3
+ import { Button } from "./ui/button";
4
+
5
+ export interface HostMuteButtonProps {
6
+ muted: boolean;
7
+ onToggle: () => void;
8
+ className?: string;
9
+ labelClassName?: string;
10
+ mutedLabel?: string;
11
+ unmutedLabel?: string;
12
+ }
13
+
14
+ export function HostMuteButton({
15
+ muted,
16
+ onToggle,
17
+ className,
18
+ labelClassName,
19
+ mutedLabel = "Unmute",
20
+ unmutedLabel = "Mute",
21
+ }: HostMuteButtonProps) {
22
+ const label = muted ? mutedLabel : unmutedLabel;
23
+
24
+ return (
25
+ <Button
26
+ type="button"
27
+ variant="ghost"
28
+ size="sm"
29
+ onClick={onToggle}
30
+ aria-pressed={muted}
31
+ aria-label={label}
32
+ title={label}
33
+ className={cn(
34
+ "rounded-full border border-white/25 bg-black/35 px-3 text-white backdrop-blur-sm hover:bg-black/55",
35
+ className,
36
+ )}
37
+ >
38
+ {muted ? <VolumeX className="size-4" /> : <Volume2 className="size-4" />}
39
+ <span
40
+ className={cn(
41
+ "text-[11px] font-semibold tracking-[0.16em] uppercase",
42
+ labelClassName,
43
+ )}
44
+ >
45
+ {label}
46
+ </span>
47
+ </Button>
48
+ );
49
+ }
@@ -0,0 +1,133 @@
1
+ import { useEffect, type JSX, type MouseEvent } from "react";
2
+ import { cn } from "../utils/cn";
3
+ import { RoomQrCode } from "./room-qr-code";
4
+ import {
5
+ shellPanelClassName,
6
+ shellUtilityButtonClassName,
7
+ } from "./shell-classes";
8
+ import { Button } from "./ui/button";
9
+
10
+ export interface JoinQrOverlayProps {
11
+ open: boolean;
12
+ value: string | null | undefined;
13
+ roomId?: string | null;
14
+ onClose?: () => void;
15
+ title?: string;
16
+ description?: string;
17
+ className?: string;
18
+ panelClassName?: string;
19
+ qrClassName?: string;
20
+ size?: number;
21
+ }
22
+
23
+ export const JoinQrOverlay = ({
24
+ open,
25
+ value,
26
+ roomId,
27
+ onClose,
28
+ title = "Scan to join",
29
+ description = "Scan with your phone to connect as a controller.",
30
+ className,
31
+ panelClassName,
32
+ qrClassName,
33
+ size = 440,
34
+ }: JoinQrOverlayProps): JSX.Element | null => {
35
+ const joinUrlValue = value?.trim() ?? "";
36
+ const hasJoinUrl = joinUrlValue.length > 0;
37
+
38
+ useEffect(() => {
39
+ if (!open || typeof window === "undefined") {
40
+ return;
41
+ }
42
+
43
+ const handleKeyDown = (event: KeyboardEvent) => {
44
+ if (event.key === "Escape") {
45
+ onClose?.();
46
+ }
47
+ };
48
+
49
+ window.addEventListener("keydown", handleKeyDown);
50
+ return () => {
51
+ window.removeEventListener("keydown", handleKeyDown);
52
+ };
53
+ }, [onClose, open]);
54
+
55
+ if (!open) {
56
+ return null;
57
+ }
58
+
59
+ const handlePanelClick = (event: MouseEvent<HTMLDivElement>) => {
60
+ event.stopPropagation();
61
+ };
62
+
63
+ return (
64
+ <div
65
+ role="dialog"
66
+ aria-modal="true"
67
+ aria-label={roomId ? `Join room ${roomId}` : title}
68
+ className={cn(
69
+ "absolute inset-0 z-50 flex items-center justify-center bg-black/82 px-6 py-8 backdrop-blur-md",
70
+ className,
71
+ )}
72
+ onClick={onClose}
73
+ >
74
+ <div
75
+ className={cn(
76
+ "flex w-full max-w-xl flex-col items-center gap-6 px-6 py-7 text-center",
77
+ shellPanelClassName,
78
+ panelClassName,
79
+ )}
80
+ onClick={handlePanelClick}
81
+ >
82
+ <div className="space-y-1">
83
+ <p className="text-[0.6875rem] font-semibold tracking-[0.22em] text-white/52 uppercase">
84
+ {title}
85
+ </p>
86
+ {roomId ? (
87
+ <p className="text-3xl font-semibold tracking-[0.12em] text-white uppercase tabular-nums">
88
+ {roomId}
89
+ </p>
90
+ ) : null}
91
+ </div>
92
+
93
+ {hasJoinUrl ? (
94
+ <RoomQrCode
95
+ value={joinUrlValue}
96
+ size={size}
97
+ padding={2}
98
+ foregroundColor="#111827"
99
+ backgroundColor="#ffffff"
100
+ className={cn("rounded-xl bg-white shadow-sm", qrClassName)}
101
+ style={{
102
+ width: "min(72vw, 26rem)",
103
+ height: "auto",
104
+ aspectRatio: "1 / 1",
105
+ }}
106
+ alt={
107
+ roomId
108
+ ? `QR code to join room ${roomId}`
109
+ : "QR code to join as a controller"
110
+ }
111
+ />
112
+ ) : (
113
+ <div className="flex w-full max-w-[26rem] items-center justify-center rounded-xl border border-white/12 bg-white/6 px-5 py-10 text-sm leading-6 text-white/68">
114
+ Join URL unavailable right now.
115
+ </div>
116
+ )}
117
+
118
+ <p className="max-w-md text-sm leading-6 text-white/68">
119
+ {description}
120
+ </p>
121
+
122
+ <Button
123
+ type="button"
124
+ variant="outline"
125
+ onClick={onClose}
126
+ className={cn("rounded-2xl px-5", shellUtilityButtonClassName)}
127
+ >
128
+ Close
129
+ </Button>
130
+ </div>
131
+ </div>
132
+ );
133
+ };
@@ -0,0 +1,95 @@
1
+ import { Check, Copy, ExternalLink, QrCode } from "lucide-react";
2
+ import type { JSX } from "react";
3
+ import { cn } from "../utils/cn";
4
+ import { shellUtilityButtonClassName } from "./shell-classes";
5
+ import { Button } from "./ui/button";
6
+
7
+ export interface JoinUrlActionButtonsProps {
8
+ hasValue: boolean;
9
+ copied?: boolean;
10
+ onCopy?: () => void;
11
+ onOpen?: () => void;
12
+ qrVisible?: boolean;
13
+ onToggleQr?: () => void;
14
+ className?: string;
15
+ buttonClassName?: string;
16
+ }
17
+
18
+ export const JoinUrlActionButtons = ({
19
+ hasValue,
20
+ copied = false,
21
+ onCopy,
22
+ onOpen,
23
+ qrVisible = false,
24
+ onToggleQr,
25
+ className,
26
+ buttonClassName,
27
+ }: JoinUrlActionButtonsProps): JSX.Element => {
28
+ const showsQrButton = typeof onToggleQr === "function";
29
+
30
+ return (
31
+ <div
32
+ className={cn(
33
+ "grid w-full gap-2",
34
+ showsQrButton ? "grid-cols-3" : "grid-cols-2",
35
+ className,
36
+ )}
37
+ >
38
+ <Button
39
+ type="button"
40
+ variant="outline"
41
+ disabled={!hasValue || !onCopy}
42
+ onClick={onCopy}
43
+ aria-label={copied ? "Copied join link" : "Copy join link"}
44
+ title={copied ? "Copied" : "Copy join link"}
45
+ className={cn(
46
+ "h-11 min-w-0 justify-center rounded-2xl px-3 text-sm",
47
+ shellUtilityButtonClassName,
48
+ buttonClassName,
49
+ )}
50
+ >
51
+ {copied ? (
52
+ <Check className="h-4 w-4" aria-hidden />
53
+ ) : (
54
+ <Copy className="h-4 w-4" aria-hidden />
55
+ )}
56
+ <span className="truncate">{copied ? "Copied" : "Copy"}</span>
57
+ </Button>
58
+ <Button
59
+ type="button"
60
+ variant="outline"
61
+ disabled={!hasValue || !onOpen}
62
+ onClick={onOpen}
63
+ aria-label="Open join link"
64
+ title="Open join link"
65
+ className={cn(
66
+ "h-11 min-w-0 justify-center rounded-2xl px-3 text-sm",
67
+ shellUtilityButtonClassName,
68
+ buttonClassName,
69
+ )}
70
+ >
71
+ <ExternalLink className="h-4 w-4" aria-hidden />
72
+ <span className="truncate">New tab</span>
73
+ </Button>
74
+ {showsQrButton ? (
75
+ <Button
76
+ type="button"
77
+ variant="outline"
78
+ disabled={!hasValue}
79
+ aria-pressed={qrVisible}
80
+ onClick={onToggleQr}
81
+ aria-label={qrVisible ? "Hide join QR" : "Show join QR"}
82
+ title={qrVisible ? "Hide join QR" : "Show join QR"}
83
+ className={cn(
84
+ "h-11 min-w-0 justify-center rounded-2xl px-3 text-sm",
85
+ shellUtilityButtonClassName,
86
+ buttonClassName,
87
+ )}
88
+ >
89
+ <QrCode className="h-4 w-4" aria-hidden />
90
+ <span className="truncate">{qrVisible ? "Hide QR" : "QR code"}</span>
91
+ </Button>
92
+ ) : null}
93
+ </div>
94
+ );
95
+ };
@@ -0,0 +1,58 @@
1
+ import type { JSX, ReactNode } from "react";
2
+ import { cn } from "../utils/cn";
3
+ import { JoinUrlActionButtons } from "./join-url-action-buttons";
4
+ import { JoinUrlField } from "./join-url-field";
5
+
6
+ export interface JoinUrlControlsProps {
7
+ value: string | null | undefined;
8
+ label?: ReactNode;
9
+ helperText?: ReactNode;
10
+ copied?: boolean;
11
+ onCopy?: () => void;
12
+ onOpen?: () => void;
13
+ qrVisible?: boolean;
14
+ onToggleQr?: () => void;
15
+ className?: string;
16
+ inputClassName?: string;
17
+ buttonClassName?: string;
18
+ }
19
+
20
+ export const JoinUrlControls = ({
21
+ value,
22
+ label = "Controller link",
23
+ helperText,
24
+ copied = false,
25
+ onCopy,
26
+ onOpen,
27
+ qrVisible = false,
28
+ onToggleQr,
29
+ className,
30
+ inputClassName,
31
+ buttonClassName,
32
+ }: JoinUrlControlsProps): JSX.Element => {
33
+ const hasValue = Boolean(value && value.trim().length > 0);
34
+
35
+ return (
36
+ <div className={cn("w-full space-y-3", className)}>
37
+ <div className="flex flex-col gap-3">
38
+ <JoinUrlField
39
+ value={value}
40
+ label={label}
41
+ helperText={helperText}
42
+ className="w-full min-w-0"
43
+ inputClassName={inputClassName}
44
+ />
45
+ <JoinUrlActionButtons
46
+ hasValue={hasValue}
47
+ copied={copied}
48
+ onCopy={onCopy}
49
+ onOpen={onOpen}
50
+ qrVisible={qrVisible}
51
+ onToggleQr={onToggleQr}
52
+ className="w-full"
53
+ buttonClassName={buttonClassName}
54
+ />
55
+ </div>
56
+ </div>
57
+ );
58
+ };
@@ -0,0 +1,52 @@
1
+ import { useId, type JSX, type ReactNode } from "react";
2
+ import { cn } from "../utils/cn";
3
+ import {
4
+ shellFieldClassName,
5
+ shellHelperTextClassName,
6
+ shellLabelClassName,
7
+ } from "./shell-classes";
8
+
9
+ export interface JoinUrlFieldProps {
10
+ value: string | null | undefined;
11
+ label?: ReactNode;
12
+ helperText?: ReactNode;
13
+ className?: string;
14
+ inputClassName?: string;
15
+ inputId?: string;
16
+ inputName?: string;
17
+ }
18
+
19
+ export const JoinUrlField = ({
20
+ value,
21
+ label = "Controller link",
22
+ helperText,
23
+ className,
24
+ inputClassName,
25
+ inputId,
26
+ inputName = "airjam-controller-link",
27
+ }: JoinUrlFieldProps): JSX.Element => {
28
+ const hasValue = Boolean(value && value.trim().length > 0);
29
+ const generatedInputId = useId();
30
+ const resolvedInputId = inputId ?? generatedInputId;
31
+
32
+ return (
33
+ <div className={cn("space-y-2.5", className)}>
34
+ <label className={shellLabelClassName} htmlFor={resolvedInputId}>
35
+ {label}
36
+ </label>
37
+ <input
38
+ id={resolvedInputId}
39
+ name={inputName}
40
+ type="text"
41
+ readOnly
42
+ value={value ?? ""}
43
+ placeholder={hasValue ? undefined : "Generating join link..."}
44
+ aria-label={typeof label === "string" ? label : "Controller join link"}
45
+ className={cn(shellFieldClassName, inputClassName)}
46
+ />
47
+ {helperText ? (
48
+ <div className={shellHelperTextClassName}>{helperText}</div>
49
+ ) : null}
50
+ </div>
51
+ );
52
+ };
@@ -0,0 +1,129 @@
1
+ import { House, Pause, Play, RotateCcw } from "lucide-react";
2
+ import type { JSX } from "react";
3
+ import {
4
+ type LifecycleActionKind,
5
+ useLifecycleActionGroupModel,
6
+ } from "../hooks/use-lifecycle-action-group-model";
7
+ import type { ShellMatchPhase } from "../lifecycle";
8
+ import type { RuntimeState } from "../protocol";
9
+ import { cn } from "../utils/cn";
10
+ import { Button } from "./ui/button";
11
+
12
+ export interface LifecycleActionGroupProps {
13
+ phase: ShellMatchPhase;
14
+ runtimeState?: RuntimeState;
15
+ canInteract?: boolean;
16
+ onStart?: () => void;
17
+ onTogglePause?: () => void;
18
+ onBackToLobby?: () => void;
19
+ onRestart?: () => void;
20
+ startLabel?: string;
21
+ restartLabel?: string;
22
+ backLabel?: string;
23
+ presentation?: "pill" | "icon";
24
+ visibleKinds?: LifecycleActionKind[];
25
+ className?: string;
26
+ buttonClassName?: string;
27
+ }
28
+
29
+ export const LifecycleActionGroup = ({
30
+ phase,
31
+ runtimeState,
32
+ canInteract = true,
33
+ onStart,
34
+ onTogglePause,
35
+ onBackToLobby,
36
+ onRestart,
37
+ startLabel = "Start",
38
+ restartLabel = "Restart",
39
+ backLabel = "Back to Lobby",
40
+ presentation = "pill",
41
+ visibleKinds,
42
+ className,
43
+ buttonClassName,
44
+ }: LifecycleActionGroupProps): JSX.Element | null => {
45
+ const { actions: allActions } = useLifecycleActionGroupModel({
46
+ phase,
47
+ runtimeState,
48
+ canInteract,
49
+ onStart,
50
+ onTogglePause,
51
+ onBackToLobby,
52
+ onRestart,
53
+ startLabel,
54
+ restartLabel,
55
+ backLabel,
56
+ });
57
+
58
+ const actions = visibleKinds
59
+ ? allActions.filter((action) => visibleKinds.includes(action.kind))
60
+ : allActions;
61
+
62
+ if (actions.length === 0) {
63
+ return null;
64
+ }
65
+
66
+ const renderIcon = (
67
+ kind: LifecycleActionKind,
68
+ label: string,
69
+ ): JSX.Element => {
70
+ switch (kind) {
71
+ case "start":
72
+ return <Play aria-hidden className="size-4.5" />;
73
+ case "pause-toggle":
74
+ return label.toLowerCase() === "resume" ? (
75
+ <Play aria-hidden className="size-4.5" />
76
+ ) : (
77
+ <Pause aria-hidden className="size-4.5" />
78
+ );
79
+ case "restart":
80
+ return <RotateCcw aria-hidden className="size-4.5" />;
81
+ case "back-to-lobby":
82
+ return <House aria-hidden className="size-4.5" />;
83
+ }
84
+ };
85
+
86
+ return (
87
+ <div
88
+ className={cn(
89
+ "flex min-w-0 flex-nowrap items-center justify-end gap-1.5 overflow-x-auto",
90
+ className,
91
+ )}
92
+ >
93
+ {actions.map((action) => (
94
+ <Button
95
+ key={action.kind}
96
+ type="button"
97
+ variant={
98
+ presentation === "icon"
99
+ ? action.tone === "primary"
100
+ ? "secondary"
101
+ : "ghost"
102
+ : action.tone === "primary"
103
+ ? "default"
104
+ : "outline"
105
+ }
106
+ size={presentation === "icon" ? "icon-sm" : undefined}
107
+ onClick={action.onPress}
108
+ disabled={action.disabled}
109
+ aria-label={action.label}
110
+ title={action.label}
111
+ className={cn(
112
+ presentation === "icon"
113
+ ? action.tone === "primary"
114
+ ? "size-9 shrink-0 rounded-full border border-white/20 bg-white text-black hover:bg-white/90 sm:size-10"
115
+ : "size-9 shrink-0 rounded-full border border-white/12 bg-white/6 text-white hover:bg-white/12 sm:size-10"
116
+ : action.tone === "primary"
117
+ ? "h-8 shrink-0 rounded-full border border-white/15 bg-white px-3 py-0 text-[9px] font-semibold tracking-[0.12em] whitespace-nowrap text-black uppercase hover:bg-white/90 sm:h-9 sm:px-4 sm:text-[10px] sm:tracking-[0.16em]"
118
+ : "h-8 shrink-0 rounded-full border-white/15 bg-white/5 px-3 py-0 text-[9px] font-semibold tracking-[0.12em] whitespace-nowrap text-white uppercase hover:bg-white/10 sm:h-9 sm:px-4 sm:text-[10px] sm:tracking-[0.16em]",
119
+ buttonClassName,
120
+ )}
121
+ >
122
+ {presentation === "icon"
123
+ ? renderIcon(action.kind, action.label)
124
+ : action.label}
125
+ </Button>
126
+ ))}
127
+ </div>
128
+ );
129
+ };