@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.
- package/LICENSE +21 -0
- package/README.md +627 -57
- package/dist/agent-tooling-BSMGBix9.d.cts +123 -0
- package/dist/agent-tooling-BSMGBix9.d.ts +123 -0
- package/dist/agent-tooling.cjs +83 -0
- package/dist/agent-tooling.cjs.map +1 -0
- package/dist/agent-tooling.d.cts +2 -0
- package/dist/agent-tooling.d.ts +2 -0
- package/dist/agent-tooling.js +17 -0
- package/dist/agent-tooling.js.map +1 -0
- package/dist/arcade/bridge/controller.cjs +749 -0
- package/dist/arcade/bridge/controller.cjs.map +1 -0
- package/dist/arcade/bridge/controller.d.cts +85 -0
- package/dist/arcade/bridge/controller.d.ts +85 -0
- package/dist/arcade/bridge/controller.js +33 -0
- package/dist/arcade/bridge/controller.js.map +1 -0
- package/dist/arcade/bridge/host.cjs +421 -0
- package/dist/arcade/bridge/host.cjs.map +1 -0
- package/dist/arcade/bridge/host.d.cts +73 -0
- package/dist/arcade/bridge/host.d.ts +73 -0
- package/dist/arcade/bridge/host.js +25 -0
- package/dist/arcade/bridge/host.js.map +1 -0
- package/dist/arcade/bridge/iframe.cjs +453 -0
- package/dist/arcade/bridge/iframe.cjs.map +1 -0
- package/dist/arcade/bridge/iframe.d.cts +80 -0
- package/dist/arcade/bridge/iframe.d.ts +80 -0
- package/dist/arcade/bridge/iframe.js +28 -0
- package/dist/arcade/bridge/iframe.js.map +1 -0
- package/dist/arcade/bridge.cjs +1067 -0
- package/dist/arcade/bridge.cjs.map +1 -0
- package/dist/arcade/bridge.d.cts +11 -0
- package/dist/arcade/bridge.d.ts +11 -0
- package/dist/arcade/bridge.js +76 -0
- package/dist/arcade/bridge.js.map +1 -0
- package/dist/arcade/host.cjs +488 -0
- package/dist/arcade/host.cjs.map +1 -0
- package/dist/arcade/host.d.cts +19 -0
- package/dist/arcade/host.d.ts +19 -0
- package/dist/arcade/host.js +13 -0
- package/dist/arcade/host.js.map +1 -0
- package/dist/arcade/surface.cjs +113 -0
- package/dist/arcade/surface.cjs.map +1 -0
- package/dist/arcade/surface.d.cts +14 -0
- package/dist/arcade/surface.d.ts +14 -0
- package/dist/arcade/surface.js +27 -0
- package/dist/arcade/surface.js.map +1 -0
- package/dist/arcade/url.cjs +363 -0
- package/dist/arcade/url.cjs.map +1 -0
- package/dist/arcade/url.d.cts +68 -0
- package/dist/arcade/url.d.ts +68 -0
- package/dist/arcade/url.js +28 -0
- package/dist/arcade/url.js.map +1 -0
- package/dist/arcade-runtime-url-BW-MUAOY.d.cts +28 -0
- package/dist/arcade-runtime-url-l8qj01Pg.d.ts +28 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.cts +16 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.ts +16 -0
- package/dist/arcade.cjs +1565 -0
- package/dist/arcade.cjs.map +1 -0
- package/dist/arcade.d.cts +18 -0
- package/dist/arcade.d.ts +18 -0
- package/dist/arcade.js +122 -0
- package/dist/arcade.js.map +1 -0
- package/dist/capabilities.cjs +39 -0
- package/dist/capabilities.cjs.map +1 -0
- package/dist/capabilities.d.cts +31 -0
- package/dist/capabilities.d.ts +31 -0
- package/dist/capabilities.js +12 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/chunk-2432OL7L.js +193 -0
- package/dist/chunk-2432OL7L.js.map +1 -0
- package/dist/chunk-2J65FXEP.js +41 -0
- package/dist/chunk-2J65FXEP.js.map +1 -0
- package/dist/chunk-32NYL7XI.js +539 -0
- package/dist/chunk-32NYL7XI.js.map +1 -0
- package/dist/chunk-3USU7GY2.js +54 -0
- package/dist/chunk-3USU7GY2.js.map +1 -0
- package/dist/chunk-BE6Z4SIT.js +65 -0
- package/dist/chunk-BE6Z4SIT.js.map +1 -0
- package/dist/chunk-CQUG24WX.js +249 -0
- package/dist/chunk-CQUG24WX.js.map +1 -0
- package/dist/chunk-D3X4MN4U.js +288 -0
- package/dist/chunk-D3X4MN4U.js.map +1 -0
- package/dist/chunk-EVZJA6RN.js +140 -0
- package/dist/chunk-EVZJA6RN.js.map +1 -0
- package/dist/chunk-HFWRZVZ3.js +1438 -0
- package/dist/chunk-HFWRZVZ3.js.map +1 -0
- package/dist/chunk-IKKDONQL.js +1 -0
- package/dist/chunk-IKKDONQL.js.map +1 -0
- package/dist/chunk-JTF47B56.js +1 -0
- package/dist/chunk-JTF47B56.js.map +1 -0
- package/dist/chunk-LIXPF4P6.js +22 -0
- package/dist/chunk-LIXPF4P6.js.map +1 -0
- package/dist/chunk-MKBASO6X.js +216 -0
- package/dist/chunk-MKBASO6X.js.map +1 -0
- package/dist/chunk-MPDMJIX5.js +1 -0
- package/dist/chunk-MPDMJIX5.js.map +1 -0
- package/dist/chunk-NCL6WJCL.js +91 -0
- package/dist/chunk-NCL6WJCL.js.map +1 -0
- package/dist/chunk-NU5W6VAV.js +126 -0
- package/dist/chunk-NU5W6VAV.js.map +1 -0
- package/dist/chunk-TGRTEWYV.js +195 -0
- package/dist/chunk-TGRTEWYV.js.map +1 -0
- package/dist/chunk-VDRNNGHX.js +184 -0
- package/dist/chunk-VDRNNGHX.js.map +1 -0
- package/dist/chunk-VN5LDWVN.js +32 -0
- package/dist/chunk-VN5LDWVN.js.map +1 -0
- package/dist/chunk-W2VK36RO.js +11 -0
- package/dist/chunk-W2VK36RO.js.map +1 -0
- package/dist/chunk-X24K52DG.js +12 -0
- package/dist/chunk-X24K52DG.js.map +1 -0
- package/dist/chunk-XLUWV45V.js +25 -0
- package/dist/chunk-XLUWV45V.js.map +1 -0
- package/dist/chunk-Y4RAPKKB.js +238 -0
- package/dist/chunk-Y4RAPKKB.js.map +1 -0
- package/dist/chunk-YXHH3MQT.js +230 -0
- package/dist/chunk-YXHH3MQT.js.map +1 -0
- package/dist/chunk-ZLPL2R3R.js +183 -0
- package/dist/chunk-ZLPL2R3R.js.map +1 -0
- package/dist/chunk-ZTQ5SP4H.js +9 -0
- package/dist/chunk-ZTQ5SP4H.js.map +1 -0
- package/dist/controller-Bod8YYr1.d.cts +172 -0
- package/dist/controller-DxVchfiA.d.ts +172 -0
- package/dist/dev-log-events-CVAM29hx.d.cts +123 -0
- package/dist/dev-log-events-CVAM29hx.d.ts +123 -0
- package/dist/handshake-CC_LrK5g.d.cts +31 -0
- package/dist/handshake-CC_LrK5g.d.ts +31 -0
- package/dist/host-8hmq_Sgc.d.cts +109 -0
- package/dist/host-Cw-N6e-5.d.ts +109 -0
- package/dist/index.cjs +8512 -3518
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +676 -1070
- package/dist/index.d.ts +676 -1070
- package/dist/index.js +4892 -3188
- package/dist/index.js.map +1 -1
- package/dist/metadata.cjs +114 -0
- package/dist/metadata.cjs.map +1 -0
- package/dist/metadata.d.cts +95 -0
- package/dist/metadata.d.ts +95 -0
- package/dist/metadata.js +83 -0
- package/dist/metadata.js.map +1 -0
- package/dist/notices-CnGaaS8B.d.ts +38 -0
- package/dist/notices-NyDM5Mtz.d.cts +38 -0
- package/dist/platform-machine.cjs +425 -0
- package/dist/platform-machine.cjs.map +1 -0
- package/dist/platform-machine.d.cts +1183 -0
- package/dist/platform-machine.d.ts +1183 -0
- package/dist/platform-machine.js +309 -0
- package/dist/platform-machine.js.map +1 -0
- package/dist/platform-settings-cuor3i11.d.cts +48 -0
- package/dist/platform-settings-cuor3i11.d.ts +48 -0
- package/dist/prefabs.cjs +36 -0
- package/dist/prefabs.cjs.map +1 -0
- package/dist/prefabs.d.cts +49 -0
- package/dist/prefabs.d.ts +49 -0
- package/dist/prefabs.js +8 -0
- package/dist/prefabs.js.map +1 -0
- package/dist/preview.cjs +2609 -0
- package/dist/preview.cjs.map +1 -0
- package/dist/preview.d.cts +155 -0
- package/dist/preview.d.ts +155 -0
- package/dist/preview.js +1671 -0
- package/dist/preview.js.map +1 -0
- package/dist/protocol.cjs +621 -54
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +76 -240
- package/dist/protocol.d.ts +76 -240
- package/dist/protocol.js +100 -2
- package/dist/protocol.js.map +1 -1
- package/dist/realtime-client-Cu8yVJFw.d.cts +15 -0
- package/dist/realtime-client-Cu8yVJFw.d.ts +15 -0
- package/dist/release.cjs +143 -0
- package/dist/release.cjs.map +1 -0
- package/dist/release.d.cts +64 -0
- package/dist/release.d.ts +64 -0
- package/dist/release.js +43 -0
- package/dist/release.js.map +1 -0
- package/dist/standard-match-phase-BucA5dYo.d.ts +44 -0
- package/dist/standard-match-phase-U2ra8J-0.d.cts +44 -0
- package/dist/sync-B6QsNrXz.d.cts +125 -0
- package/dist/sync-B6QsNrXz.d.ts +125 -0
- package/dist/ui.cjs +2827 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.cts +320 -0
- package/dist/ui.d.ts +320 -0
- package/dist/ui.js +1718 -0
- package/dist/ui.js.map +1 -0
- package/dist/url-policy-C89zxgw9.d.cts +9 -0
- package/dist/url-policy-C89zxgw9.d.ts +9 -0
- package/package.json +154 -13
- package/src/agent/agent-action.ts +304 -0
- package/src/agent/agent-contract.ts +180 -0
- package/src/agent-tooling.ts +20 -0
- package/src/arcade/bridge/controller.ts +15 -0
- package/src/arcade/bridge/host.ts +12 -0
- package/src/arcade/bridge/iframe.ts +61 -0
- package/src/arcade/bridge.ts +3 -0
- package/src/arcade/host.ts +1 -0
- package/src/arcade/surface.ts +4 -0
- package/src/arcade/url.ts +60 -0
- package/src/arcade.ts +4 -0
- package/src/audio/audio-manager.ts +162 -171
- package/src/audio/hooks.tsx +218 -97
- package/src/audio/index.ts +1 -1
- package/src/audio/music.tsx +139 -0
- package/src/capabilities/manifest.ts +71 -0
- package/src/capabilities.ts +12 -0
- package/src/components/connection-status-pill.tsx +55 -0
- package/src/components/controller-player-name-field.tsx +119 -0
- package/src/components/controller-primary-action.tsx +58 -0
- package/src/components/host-mute-button.tsx +49 -0
- package/src/components/join-qr-overlay.tsx +133 -0
- package/src/components/join-url-action-buttons.tsx +95 -0
- package/src/components/join-url-controls.tsx +58 -0
- package/src/components/join-url-field.tsx +52 -0
- package/src/components/lifecycle-action-group.tsx +129 -0
- package/src/components/player-avatar-strip.tsx +65 -0
- package/src/components/player-avatar.tsx +42 -14
- package/src/components/room-qr-code.tsx +125 -0
- package/src/components/runtime-shell-header.tsx +37 -0
- package/src/components/shell-classes.ts +19 -0
- package/src/components/surface-orientation-layout.ts +60 -0
- package/src/components/surface-viewport-layout.ts +268 -0
- package/src/components/surface-viewport.tsx +314 -0
- package/src/components/ui/button.tsx +4 -6
- package/src/components/ui/slider.tsx +1 -1
- package/src/components/volume-controls.tsx +65 -6
- package/src/context/air-jam-context.tsx +209 -141
- package/src/context/index.ts +2 -2
- package/src/context/session-providers.tsx +77 -0
- package/src/context/session-scope.ts +64 -0
- package/src/context/socket-manager.ts +6 -25
- package/src/contracts/v2/bridge.ts +261 -0
- package/src/contracts/v2/handshake.ts +40 -0
- package/src/contracts/v2/index.ts +2 -0
- package/src/dev/browser-log-sink.ts +912 -0
- package/src/diagnostics.ts +128 -0
- package/src/events.ts +7 -34
- package/src/hooks/internal/use-controller-runtime-api.ts +875 -0
- package/src/hooks/internal/use-host-runtime-api.ts +1051 -0
- package/src/hooks/internal/use-runtime-control-contract.ts +15 -0
- package/src/hooks/internal/use-runtime-inspection-contract.ts +16 -0
- package/src/hooks/internal/use-runtime-observability-contract.ts +24 -0
- package/src/hooks/use-air-jam-controller.ts +155 -475
- package/src/hooks/use-air-jam-host.ts +156 -485
- package/src/hooks/use-connection-status.ts +8 -0
- package/src/hooks/use-controller-lifecycle-intents.ts +27 -0
- package/src/hooks/use-controller-lifecycle-permissions.ts +36 -0
- package/src/hooks/use-controller-shell-status.ts +40 -0
- package/src/hooks/use-controller-tick.ts +65 -0
- package/src/hooks/use-controller-toasts.ts +116 -0
- package/src/hooks/use-get-input.ts +8 -5
- package/src/hooks/use-host-arcade-restore.ts +30 -0
- package/src/hooks/use-host-join-controls.ts +152 -0
- package/src/hooks/use-host-tick.ts +171 -0
- package/src/hooks/use-input-writer.ts +83 -0
- package/src/hooks/use-lifecycle-action-group-model.ts +98 -0
- package/src/hooks/use-players.ts +12 -0
- package/src/hooks/use-room.ts +22 -0
- package/src/hooks/use-send-signal.ts +6 -2
- package/src/index.ts +205 -31
- package/src/internal/input-manager.ts +195 -215
- package/src/lifecycle/index.ts +9 -0
- package/src/lifecycle/standard-match-phase.ts +32 -0
- package/src/metadata/manifest.ts +152 -0
- package/src/metadata.ts +12 -0
- package/src/platform-machine.ts +475 -0
- package/src/prefabs/types.ts +82 -0
- package/src/prefabs.ts +12 -0
- package/src/preview/host-workspace.tsx +59 -0
- package/src/preview/identity.ts +66 -0
- package/src/preview/layout.ts +223 -0
- package/src/preview/manager.ts +577 -0
- package/src/preview/messages.ts +26 -0
- package/src/preview/ownership.ts +81 -0
- package/src/preview/url.ts +117 -0
- package/src/preview/window.tsx +490 -0
- package/src/preview/workspace.tsx +678 -0
- package/src/preview.ts +42 -0
- package/src/protocol/arcade-platform-actions.ts +29 -0
- package/src/protocol/controller.ts +187 -0
- package/src/protocol/core.ts +23 -0
- package/src/protocol/dev-log-events.ts +222 -0
- package/src/protocol/errors.ts +21 -0
- package/src/protocol/host-grant.ts +185 -0
- package/src/protocol/host.ts +138 -0
- package/src/protocol/notices.ts +43 -0
- package/src/protocol/signals.ts +38 -0
- package/src/protocol/socket-events.ts +154 -0
- package/src/protocol/sync.ts +121 -0
- package/src/protocol/url-policy.ts +63 -0
- package/src/protocol.ts +12 -386
- package/src/qrcode.d.ts +16 -0
- package/src/release.ts +99 -0
- package/src/runtime/air-jam-config.ts +287 -0
- package/src/runtime/air-jam-error-boundary.tsx +672 -0
- package/src/runtime/arcade-bridge-request-surface.ts +15 -0
- package/src/runtime/arcade-runtime-url.ts +95 -0
- package/src/runtime/arcade-surface-identity.ts +16 -0
- package/src/runtime/contracts/control.ts +68 -0
- package/src/runtime/contracts/inspection.ts +165 -0
- package/src/runtime/contracts/observability.ts +94 -0
- package/src/runtime/controller-bridge.ts +451 -0
- package/src/runtime/controller-identity.ts +132 -0
- package/src/runtime/controller-presentation.ts +24 -0
- package/src/runtime/controller-realtime-client.ts +591 -0
- package/src/runtime/create-air-jam-app.tsx +260 -0
- package/src/runtime/dev-runtime-events.ts +36 -0
- package/src/runtime/embedded-runtime-adapters.ts +68 -0
- package/src/runtime/host-bridge.ts +388 -0
- package/src/runtime/host-realtime-client.ts +550 -0
- package/src/runtime/iframe-bridge.ts +135 -0
- package/src/runtime/realtime-client.ts +20 -0
- package/src/runtime/router-basename.ts +25 -0
- package/src/runtime/runtime-owner-contexts.tsx +4 -0
- package/src/runtime/runtime-session-params.ts +169 -0
- package/src/runtime/sdk-version.ts +6 -0
- package/src/runtime/session-runtimes.tsx +188 -0
- package/src/runtime/validate-arcade-bridge-attach.ts +14 -0
- package/src/runtime-control.ts +10 -0
- package/src/runtime-inspection.ts +14 -0
- package/src/runtime-observability.ts +9 -0
- package/src/settings/platform-settings-bridge.ts +336 -0
- package/src/settings/platform-settings-runtime.tsx +387 -0
- package/src/settings/platform-settings.ts +288 -0
- package/src/state/connection-store.ts +80 -12
- package/src/store/air-jam-store-domain-constants.ts +4 -0
- package/src/store/create-air-jam-store.ts +1094 -227
- package/src/styles.css +4 -38
- package/src/ui.ts +29 -0
- package/src/utils/is-rpc-serializable.ts +56 -0
- package/src/utils/player-avatar-url.ts +48 -0
- package/src/utils/url-builder.ts +7 -0
- package/dist/.tsbuildinfo +0 -1
- package/dist/chunk-B5DURUWT.js +0 -80
- package/dist/chunk-B5DURUWT.js.map +0 -1
- package/src/AirJamClient.ts +0 -224
- package/src/audio/volume-store.ts +0 -124
- package/src/components/controller-shell.tsx +0 -346
- package/src/components/host-shell.tsx +0 -521
- package/src/components/qr-scanner-dialog.tsx +0 -373
- package/src/components/ui/alert.tsx +0 -66
- package/src/components/ui/avatar.tsx +0 -46
- package/src/components/ui/badge.tsx +0 -47
- package/src/components/ui/card.tsx +0 -92
- package/src/components/ui/dialog.tsx +0 -122
- package/src/components/ui/tabs.tsx +0 -64
- package/src/hooks/use-air-jam-shell.ts +0 -379
- package/src/hooks/use-fullscreen.ts +0 -108
package/src/AirJamClient.ts
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import { io, Socket } from "socket.io-client";
|
|
2
|
-
import type { StoreApi } from "zustand";
|
|
3
|
-
import type {
|
|
4
|
-
ClientToServerEvents,
|
|
5
|
-
ConnectionRole,
|
|
6
|
-
ControllerInputPayload,
|
|
7
|
-
ControllerJoinedNotice,
|
|
8
|
-
ControllerLeftNotice,
|
|
9
|
-
GameState,
|
|
10
|
-
ServerToClientEvents,
|
|
11
|
-
} from "./protocol";
|
|
12
|
-
import { createAirJamStore, type AirJamStore } from "./state/connection-store";
|
|
13
|
-
import { detectRunMode } from "./utils/mode";
|
|
14
|
-
import { urlBuilder } from "./utils/url-builder";
|
|
15
|
-
|
|
16
|
-
export interface AirJamClientOptions {
|
|
17
|
-
apiKey?: string;
|
|
18
|
-
serverUrl?: string;
|
|
19
|
-
role: ConnectionRole;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The core Air Jam Engine.
|
|
24
|
-
* Manages the Socket.io connection and the state store for a single Air Jam session.
|
|
25
|
-
* This class is framework-agnostic and can be used outside of React.
|
|
26
|
-
*/
|
|
27
|
-
export class AirJamClient {
|
|
28
|
-
public readonly socket: Socket<ServerToClientEvents, ClientToServerEvents>;
|
|
29
|
-
public readonly store: StoreApi<AirJamStore>;
|
|
30
|
-
public readonly role: ConnectionRole;
|
|
31
|
-
private readonly _inputBuffer: Map<string, ControllerInputPayload> =
|
|
32
|
-
new Map();
|
|
33
|
-
public readonly _clientInstanceId: string;
|
|
34
|
-
|
|
35
|
-
constructor(options: AirJamClientOptions) {
|
|
36
|
-
this.role = options.role;
|
|
37
|
-
this._clientInstanceId = `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
38
|
-
|
|
39
|
-
// 1. Initialize State
|
|
40
|
-
this.store = createAirJamStore();
|
|
41
|
-
this.store.getState().setRole(options.role);
|
|
42
|
-
this.store.getState().setMode(detectRunMode());
|
|
43
|
-
|
|
44
|
-
// 2. Resolve Server URL
|
|
45
|
-
const resolvedUrl = options.serverUrl || urlBuilder.resolveServerUrl();
|
|
46
|
-
|
|
47
|
-
// 3. Initialize Socket
|
|
48
|
-
this.socket = io(resolvedUrl, {
|
|
49
|
-
autoConnect: false,
|
|
50
|
-
reconnection: true,
|
|
51
|
-
transports: ["websocket"],
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// 4. Set up core listeners
|
|
55
|
-
this.setupListeners();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private setupHostListeners() {
|
|
59
|
-
if (this.role !== "host") return;
|
|
60
|
-
|
|
61
|
-
// Remove existing listeners to avoid duplicates
|
|
62
|
-
this.socket.off("server:controllerJoined");
|
|
63
|
-
this.socket.off("server:controllerLeft");
|
|
64
|
-
this.socket.off("server:input");
|
|
65
|
-
|
|
66
|
-
this.socket.on(
|
|
67
|
-
"server:controllerJoined",
|
|
68
|
-
(payload: ControllerJoinedNotice) => {
|
|
69
|
-
console.log(`[AirJamClient] server:controllerJoined`, payload);
|
|
70
|
-
if (payload.player) {
|
|
71
|
-
this.store.getState().upsertPlayer(payload.player);
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
this.socket.on("server:controllerLeft", (payload: ControllerLeftNotice) => {
|
|
77
|
-
this.store.getState().removePlayer(payload.controllerId);
|
|
78
|
-
this._inputBuffer.delete(payload.controllerId);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
this.socket.on("server:input", (payload) => {
|
|
82
|
-
this._inputBuffer.set(payload.controllerId, payload.input);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private setupServerStateListener() {
|
|
87
|
-
// Remove existing listener to avoid duplicates
|
|
88
|
-
this.socket.off("server:state");
|
|
89
|
-
|
|
90
|
-
const serverStateHandler = (payload: {
|
|
91
|
-
state: { gameState?: GameState; message?: string };
|
|
92
|
-
}) => {
|
|
93
|
-
const store = this.store.getState();
|
|
94
|
-
if (payload.state.gameState) {
|
|
95
|
-
store.setGameState(payload.state.gameState);
|
|
96
|
-
}
|
|
97
|
-
if (payload.state.message !== undefined) {
|
|
98
|
-
store.setStateMessage(payload.state.message);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
this.socket.on("server:state", serverStateHandler);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private setupListeners() {
|
|
106
|
-
// Handle connect event
|
|
107
|
-
const onConnect = () => {
|
|
108
|
-
this.store.getState().setStatus("connected");
|
|
109
|
-
this.store.getState().setError(undefined);
|
|
110
|
-
// Re-register all listeners after connection to ensure they're active
|
|
111
|
-
// This fixes the issue where listeners registered before socket connects don't work
|
|
112
|
-
this.setupServerStateListener();
|
|
113
|
-
this.setupHostListeners();
|
|
114
|
-
};
|
|
115
|
-
this.socket.on("connect", onConnect);
|
|
116
|
-
|
|
117
|
-
// If socket is already connected, call handler immediately
|
|
118
|
-
if (this.socket.connected) {
|
|
119
|
-
onConnect();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
this.socket.on("disconnect", () => {
|
|
123
|
-
this.store.getState().setStatus("disconnected");
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
this.socket.on("server:error", (payload: { message: string }) => {
|
|
127
|
-
this.store.getState().setError(payload.message);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// DO NOT register server:state or host-specific listeners here
|
|
131
|
-
// They must be registered AFTER socket connects in the onConnect handler
|
|
132
|
-
// This is because Socket.io listeners registered before connect don't work reliably
|
|
133
|
-
|
|
134
|
-
// Controller-specific listeners
|
|
135
|
-
if (this.role === "controller") {
|
|
136
|
-
this.socket.on("server:welcome", (payload) => {
|
|
137
|
-
const store = this.store.getState();
|
|
138
|
-
store.setRoomId(payload.roomId);
|
|
139
|
-
if (payload.controllerId) {
|
|
140
|
-
store.setControllerId(payload.controllerId);
|
|
141
|
-
}
|
|
142
|
-
if (payload.player) {
|
|
143
|
-
store.upsertPlayer(payload.player);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
this.socket.on("server:hostLeft", (payload) => {
|
|
148
|
-
const store = this.store.getState();
|
|
149
|
-
store.setError(payload.reason);
|
|
150
|
-
store.setStatus("disconnected");
|
|
151
|
-
store.resetGameState();
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Connect to the Air Jam server.
|
|
158
|
-
*/
|
|
159
|
-
public connect() {
|
|
160
|
-
// CRITICAL FIX: Check if listeners were removed by destroy() and re-register them
|
|
161
|
-
// This handles React Strict Mode which calls destroy() then connect() on the same client
|
|
162
|
-
const hasConnectListener = this.socket.listeners("connect").length > 0;
|
|
163
|
-
if (!hasConnectListener) {
|
|
164
|
-
this.setupListeners();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (!this.socket.connected) {
|
|
168
|
-
this.store.getState().setStatus("connecting");
|
|
169
|
-
this.socket.connect();
|
|
170
|
-
// CRITICAL FIX: Register listener immediately if socket connects synchronously
|
|
171
|
-
// Socket.io may connect before the 'connect' event fires, so we check immediately
|
|
172
|
-
// and also use a timeout as fallback
|
|
173
|
-
const checkAndRegister = () => {
|
|
174
|
-
if (this.socket.connected) {
|
|
175
|
-
const hasListener = this.socket.listeners("server:state").length > 0;
|
|
176
|
-
if (!hasListener) {
|
|
177
|
-
this.store.getState().setStatus("connected");
|
|
178
|
-
this.store.getState().setError(undefined);
|
|
179
|
-
this.setupServerStateListener();
|
|
180
|
-
this.setupHostListeners();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
// Check immediately (in case socket connected synchronously)
|
|
185
|
-
checkAndRegister();
|
|
186
|
-
// Also check after a short delay (in case connection happens asynchronously)
|
|
187
|
-
setTimeout(checkAndRegister, 50);
|
|
188
|
-
setTimeout(checkAndRegister, 200);
|
|
189
|
-
setTimeout(checkAndRegister, 500);
|
|
190
|
-
} else {
|
|
191
|
-
// Ensure listeners are registered if socket is already connected
|
|
192
|
-
if (!this.socket.listeners("server:state").length) {
|
|
193
|
-
this.store.getState().setStatus("connected");
|
|
194
|
-
this.store.getState().setError(undefined);
|
|
195
|
-
this.setupServerStateListener();
|
|
196
|
-
this.setupHostListeners();
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Disconnect from the Air Jam server.
|
|
203
|
-
*/
|
|
204
|
-
public disconnect() {
|
|
205
|
-
this.socket.disconnect();
|
|
206
|
-
this.store.getState().setStatus("disconnected");
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Get the current input buffer.
|
|
211
|
-
*/
|
|
212
|
-
public get inputBuffer() {
|
|
213
|
-
return this._inputBuffer;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Cleanup resources.
|
|
218
|
-
*/
|
|
219
|
-
public destroy() {
|
|
220
|
-
this.disconnect();
|
|
221
|
-
this.socket.removeAllListeners();
|
|
222
|
-
this._inputBuffer.clear();
|
|
223
|
-
}
|
|
224
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { create } from "zustand";
|
|
2
|
-
|
|
3
|
-
interface VolumeSettings {
|
|
4
|
-
masterVolume: number; // 0-1
|
|
5
|
-
musicVolume: number; // 0-1
|
|
6
|
-
sfxVolume: number; // 0-1
|
|
7
|
-
setMasterVolume: (volume: number) => void;
|
|
8
|
-
setMusicVolume: (volume: number) => void;
|
|
9
|
-
setSfxVolume: (volume: number) => void;
|
|
10
|
-
getEffectiveVolume: (category: "music" | "sfx") => number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Settings sync message from parent (arcade) to child (game) iframe.
|
|
15
|
-
* This allows the arcade overlay to control volume for embedded games.
|
|
16
|
-
*/
|
|
17
|
-
interface AirJamSettingsSyncMessage {
|
|
18
|
-
type: "AIRJAM_SETTINGS_SYNC";
|
|
19
|
-
payload: {
|
|
20
|
-
masterVolume: number;
|
|
21
|
-
musicVolume: number;
|
|
22
|
-
sfxVolume: number;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const STORAGE_KEY = "air-jam-volume-settings";
|
|
27
|
-
|
|
28
|
-
// Load initial state from localStorage
|
|
29
|
-
const loadFromStorage = (): Partial<VolumeSettings> => {
|
|
30
|
-
if (typeof window === "undefined") return {};
|
|
31
|
-
try {
|
|
32
|
-
const stored = localStorage.getItem(STORAGE_KEY);
|
|
33
|
-
if (stored) {
|
|
34
|
-
const parsed = JSON.parse(stored);
|
|
35
|
-
return {
|
|
36
|
-
masterVolume: parsed.masterVolume ?? 1.0,
|
|
37
|
-
musicVolume: parsed.musicVolume ?? 0.8,
|
|
38
|
-
sfxVolume: parsed.sfxVolume ?? 1.0,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
} catch {
|
|
42
|
-
// Ignore parse errors
|
|
43
|
-
}
|
|
44
|
-
return {};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// Save to localStorage
|
|
48
|
-
const saveToStorage = (state: VolumeSettings) => {
|
|
49
|
-
if (typeof window === "undefined") return;
|
|
50
|
-
try {
|
|
51
|
-
localStorage.setItem(
|
|
52
|
-
STORAGE_KEY,
|
|
53
|
-
JSON.stringify({
|
|
54
|
-
masterVolume: state.masterVolume,
|
|
55
|
-
musicVolume: state.musicVolume,
|
|
56
|
-
sfxVolume: state.sfxVolume,
|
|
57
|
-
}),
|
|
58
|
-
);
|
|
59
|
-
} catch {
|
|
60
|
-
// Ignore storage errors (e.g., quota exceeded)
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const initialValues = loadFromStorage();
|
|
65
|
-
|
|
66
|
-
export const useVolumeStore = create<VolumeSettings>((set, get) => ({
|
|
67
|
-
masterVolume: initialValues.masterVolume ?? 1.0,
|
|
68
|
-
musicVolume: initialValues.musicVolume ?? 0.8,
|
|
69
|
-
sfxVolume: initialValues.sfxVolume ?? 1.0,
|
|
70
|
-
setMasterVolume: (volume) => {
|
|
71
|
-
const clamped = Math.max(0, Math.min(1, volume));
|
|
72
|
-
set({ masterVolume: clamped });
|
|
73
|
-
saveToStorage({ ...get(), masterVolume: clamped });
|
|
74
|
-
},
|
|
75
|
-
setMusicVolume: (volume) => {
|
|
76
|
-
const clamped = Math.max(0, Math.min(1, volume));
|
|
77
|
-
set({ musicVolume: clamped });
|
|
78
|
-
saveToStorage({ ...get(), musicVolume: clamped });
|
|
79
|
-
},
|
|
80
|
-
setSfxVolume: (volume) => {
|
|
81
|
-
const clamped = Math.max(0, Math.min(1, volume));
|
|
82
|
-
set({ sfxVolume: clamped });
|
|
83
|
-
saveToStorage({ ...get(), sfxVolume: clamped });
|
|
84
|
-
},
|
|
85
|
-
getEffectiveVolume: (category) => {
|
|
86
|
-
const { masterVolume, musicVolume, sfxVolume } = get();
|
|
87
|
-
const categoryVolume = category === "music" ? musicVolume : sfxVolume;
|
|
88
|
-
return masterVolume * categoryVolume;
|
|
89
|
-
},
|
|
90
|
-
}));
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Set up parent message listener for child mode (games running in arcade iframe).
|
|
94
|
-
* When the arcade sends AIRJAM_SETTINGS_SYNC messages, apply them to the volume store.
|
|
95
|
-
* This runs once at module load time and is completely transparent to game developers.
|
|
96
|
-
*/
|
|
97
|
-
const setupParentSettingsListener = () => {
|
|
98
|
-
if (typeof window === "undefined") return;
|
|
99
|
-
|
|
100
|
-
// Only listen if we're running inside an iframe (child mode)
|
|
101
|
-
const isInIframe = window.parent !== window;
|
|
102
|
-
if (!isInIframe) return;
|
|
103
|
-
|
|
104
|
-
const handleMessage = (event: MessageEvent<AirJamSettingsSyncMessage>) => {
|
|
105
|
-
// Only accept settings sync messages from parent
|
|
106
|
-
if (event.source !== window.parent) return;
|
|
107
|
-
if (event.data?.type !== "AIRJAM_SETTINGS_SYNC") return;
|
|
108
|
-
|
|
109
|
-
const { masterVolume, musicVolume, sfxVolume } = event.data.payload;
|
|
110
|
-
|
|
111
|
-
// Apply settings without saving to localStorage (arcade owns the settings)
|
|
112
|
-
const store = useVolumeStore.getState();
|
|
113
|
-
|
|
114
|
-
// Use setters to trigger AudioManager subscription updates
|
|
115
|
-
if (typeof masterVolume === "number") store.setMasterVolume(masterVolume);
|
|
116
|
-
if (typeof musicVolume === "number") store.setMusicVolume(musicVolume);
|
|
117
|
-
if (typeof sfxVolume === "number") store.setSfxVolume(sfxVolume);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
window.addEventListener("message", handleMessage);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// Initialize the parent settings listener
|
|
124
|
-
setupParentSettingsListener();
|
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Maximize,
|
|
3
|
-
Minimize,
|
|
4
|
-
Pause,
|
|
5
|
-
Play,
|
|
6
|
-
QrCode,
|
|
7
|
-
RefreshCw,
|
|
8
|
-
} from "lucide-react";
|
|
9
|
-
import type { JSX } from "react";
|
|
10
|
-
import {
|
|
11
|
-
useCallback,
|
|
12
|
-
useEffect,
|
|
13
|
-
useMemo,
|
|
14
|
-
useState,
|
|
15
|
-
type ReactNode,
|
|
16
|
-
} from "react";
|
|
17
|
-
import { useStore } from "zustand";
|
|
18
|
-
import { useShallow } from "zustand/react/shallow";
|
|
19
|
-
import { useAirJamContext } from "../context/air-jam-context";
|
|
20
|
-
import { useFullscreen } from "../hooks/use-fullscreen";
|
|
21
|
-
import type { PlayerProfile } from "../protocol";
|
|
22
|
-
import { controllerSystemSchema } from "../protocol";
|
|
23
|
-
import { cn } from "../utils/cn";
|
|
24
|
-
import { detectRunMode } from "../utils/mode";
|
|
25
|
-
import { PlayerAvatar } from "./player-avatar";
|
|
26
|
-
import { QRScannerDialog } from "./qr-scanner-dialog";
|
|
27
|
-
import { Button } from "./ui/button";
|
|
28
|
-
|
|
29
|
-
interface ControllerShellProps {
|
|
30
|
-
/** Optional forced orientation. If not set, no orientation enforcement is applied. */
|
|
31
|
-
forceOrientation?: "portrait" | "landscape";
|
|
32
|
-
children: ReactNode;
|
|
33
|
-
/** Optional custom actions to display in the header */
|
|
34
|
-
customActions?: ReactNode;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const describeStatus = (
|
|
38
|
-
status: "connected" | "connecting" | "reconnecting" | "disconnected" | "idle",
|
|
39
|
-
): string => {
|
|
40
|
-
switch (status) {
|
|
41
|
-
case "connected":
|
|
42
|
-
return "Connected to host";
|
|
43
|
-
case "connecting":
|
|
44
|
-
return "Connecting…";
|
|
45
|
-
case "reconnecting":
|
|
46
|
-
return "Trying to reconnect…";
|
|
47
|
-
case "disconnected":
|
|
48
|
-
return "Disconnected";
|
|
49
|
-
case "idle":
|
|
50
|
-
default:
|
|
51
|
-
return "Idle";
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const orientationMatches = (
|
|
56
|
-
required: "portrait" | "landscape" | undefined,
|
|
57
|
-
): boolean => {
|
|
58
|
-
if (!required) return true;
|
|
59
|
-
if (typeof window === "undefined" || !window.matchMedia) return true;
|
|
60
|
-
const matcher = window.matchMedia(`(orientation: ${required})`);
|
|
61
|
-
return matcher.matches;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const ControllerShell = ({
|
|
65
|
-
forceOrientation,
|
|
66
|
-
children,
|
|
67
|
-
customActions,
|
|
68
|
-
}: ControllerShellProps): JSX.Element => {
|
|
69
|
-
const { store, getSocket, disconnectSocket } = useAirJamContext();
|
|
70
|
-
|
|
71
|
-
const isChildMode = useMemo(() => detectRunMode() === "platform", []);
|
|
72
|
-
const [isOrientationOk, setOrientationOk] = useState(() =>
|
|
73
|
-
orientationMatches(forceOrientation),
|
|
74
|
-
);
|
|
75
|
-
const [isScannerOpen, setIsScannerOpen] = useState(false);
|
|
76
|
-
const { isFullscreen, toggleFullscreen } = useFullscreen();
|
|
77
|
-
|
|
78
|
-
// Read all state from the store (works with both useAirJamController and useAirJamShell)
|
|
79
|
-
const { roomId, connectionStatus, gameState, controllerId, players } =
|
|
80
|
-
useStore(
|
|
81
|
-
store,
|
|
82
|
-
useShallow((state) => ({
|
|
83
|
-
roomId: state.roomId,
|
|
84
|
-
connectionStatus: state.connectionStatus,
|
|
85
|
-
gameState: state.gameState,
|
|
86
|
-
controllerId: state.controllerId,
|
|
87
|
-
players: state.players,
|
|
88
|
-
})),
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
// Get socket for callbacks
|
|
92
|
-
const socket = useMemo(() => getSocket("controller"), [getSocket]);
|
|
93
|
-
|
|
94
|
-
// Find current player profile - must exist from server (single source of truth)
|
|
95
|
-
const currentPlayer = useMemo(() => {
|
|
96
|
-
if (!controllerId) return null;
|
|
97
|
-
const found = players.find((p: PlayerProfile) => p.id === controllerId);
|
|
98
|
-
|
|
99
|
-
// Only warn if we are fully connected and still can't find the player
|
|
100
|
-
// This avoids race conditions during the initial connection handshake
|
|
101
|
-
if (!found && connectionStatus === "connected" && players.length > 0) {
|
|
102
|
-
// Optional: Debug log here if needed
|
|
103
|
-
}
|
|
104
|
-
return found || null;
|
|
105
|
-
}, [controllerId, players, connectionStatus]);
|
|
106
|
-
|
|
107
|
-
// Implement sendSystemCommand using socket manager
|
|
108
|
-
const sendSystemCommand = useCallback(
|
|
109
|
-
(command: "exit" | "ready" | "toggle_pause") => {
|
|
110
|
-
const storeState = store.getState();
|
|
111
|
-
if (!roomId || !storeState.controllerId || !socket) return;
|
|
112
|
-
if (!socket.connected) return;
|
|
113
|
-
|
|
114
|
-
const payload = controllerSystemSchema.safeParse({
|
|
115
|
-
roomId,
|
|
116
|
-
command,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
if (payload.success) {
|
|
120
|
-
socket.emit("controller:system", payload.data);
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
[roomId, socket, store],
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
// Implement reconnect
|
|
127
|
-
const reconnect = useCallback(() => {
|
|
128
|
-
if (!roomId) return;
|
|
129
|
-
disconnectSocket("controller");
|
|
130
|
-
// Force reconnection by updating room ID (triggers hook reconnection)
|
|
131
|
-
store.getState().setRoomId(roomId);
|
|
132
|
-
}, [roomId, disconnectSocket, store]);
|
|
133
|
-
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
if (!forceOrientation) {
|
|
136
|
-
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
137
|
-
setOrientationOk(true);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const media = window.matchMedia(`(orientation: ${forceOrientation})`);
|
|
142
|
-
const handleChange = (): void => setOrientationOk(media.matches);
|
|
143
|
-
handleChange();
|
|
144
|
-
media.addEventListener("change", handleChange);
|
|
145
|
-
return () => media.removeEventListener("change", handleChange);
|
|
146
|
-
}, [forceOrientation]);
|
|
147
|
-
|
|
148
|
-
const orientationOk = !forceOrientation ? true : isOrientationOk;
|
|
149
|
-
|
|
150
|
-
const statusDotColor = useMemo(() => {
|
|
151
|
-
switch (connectionStatus) {
|
|
152
|
-
case "connected":
|
|
153
|
-
return "bg-green-500";
|
|
154
|
-
case "connecting":
|
|
155
|
-
case "reconnecting":
|
|
156
|
-
return "bg-yellow-500";
|
|
157
|
-
case "disconnected":
|
|
158
|
-
default:
|
|
159
|
-
return "bg-red-500";
|
|
160
|
-
}
|
|
161
|
-
}, [connectionStatus]);
|
|
162
|
-
|
|
163
|
-
// In child mode, we only render the content and maybe orientation check.
|
|
164
|
-
// The parent frame provides the shell (header, volume, etc).
|
|
165
|
-
if (isChildMode) {
|
|
166
|
-
return (
|
|
167
|
-
<div className="dark">
|
|
168
|
-
<div className="text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden bg-black select-none">
|
|
169
|
-
<main className="relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4">
|
|
170
|
-
{!orientationOk && (
|
|
171
|
-
<div className="bg-background/95 absolute inset-0 z-50 flex flex-col items-center justify-center p-6 text-center shadow-lg backdrop-blur-sm">
|
|
172
|
-
<p className="text-card-foreground text-xl font-semibold">
|
|
173
|
-
Rotate your device
|
|
174
|
-
</p>
|
|
175
|
-
<p className="text-muted-foreground mt-2 text-sm">
|
|
176
|
-
This game is best experienced in {forceOrientation}{" "}
|
|
177
|
-
orientation.
|
|
178
|
-
</p>
|
|
179
|
-
</div>
|
|
180
|
-
)}
|
|
181
|
-
<div
|
|
182
|
-
className={cn(
|
|
183
|
-
"h-full w-full select-none",
|
|
184
|
-
!orientationOk && "pointer-events-none opacity-30",
|
|
185
|
-
)}
|
|
186
|
-
>
|
|
187
|
-
{children}
|
|
188
|
-
</div>
|
|
189
|
-
</main>
|
|
190
|
-
</div>
|
|
191
|
-
</div>
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return (
|
|
196
|
-
<div className="dark">
|
|
197
|
-
<div className="text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden bg-black select-none">
|
|
198
|
-
<header className="pointer-events-none sticky top-0 z-50 flex items-center justify-between border-b px-6 py-2">
|
|
199
|
-
<div className="pointer-events-auto flex items-center gap-3">
|
|
200
|
-
{typeof window !== "undefined" &&
|
|
201
|
-
(currentPlayer || controllerId) && (
|
|
202
|
-
<div
|
|
203
|
-
className="relative"
|
|
204
|
-
title={describeStatus(connectionStatus)}
|
|
205
|
-
>
|
|
206
|
-
{currentPlayer ? (
|
|
207
|
-
<PlayerAvatar player={currentPlayer} size="sm" />
|
|
208
|
-
) : controllerId ? (
|
|
209
|
-
<PlayerAvatar
|
|
210
|
-
player={{
|
|
211
|
-
id: controllerId,
|
|
212
|
-
label: "Player",
|
|
213
|
-
}}
|
|
214
|
-
size="sm"
|
|
215
|
-
/>
|
|
216
|
-
) : null}
|
|
217
|
-
{/* Black border circle - always visible behind */}
|
|
218
|
-
<span
|
|
219
|
-
className="absolute right-0 bottom-0 h-3 w-3 rounded-full bg-black"
|
|
220
|
-
aria-hidden="true"
|
|
221
|
-
/>
|
|
222
|
-
{/* Colored status dot - on top */}
|
|
223
|
-
<span
|
|
224
|
-
className={cn(
|
|
225
|
-
"absolute right-0.5 bottom-0.5 h-2 w-2 rounded-full",
|
|
226
|
-
statusDotColor,
|
|
227
|
-
connectionStatus === "connected" && "animate-pulse",
|
|
228
|
-
)}
|
|
229
|
-
aria-label={describeStatus(connectionStatus)}
|
|
230
|
-
/>
|
|
231
|
-
</div>
|
|
232
|
-
)}
|
|
233
|
-
<div>
|
|
234
|
-
<p className="text-muted-foreground text-xs tracking-[0.24em] uppercase">
|
|
235
|
-
Room
|
|
236
|
-
</p>
|
|
237
|
-
<p className="text-foreground text-lg font-semibold">
|
|
238
|
-
{typeof window !== "undefined" ? (roomId ?? "N/A") : "N/A"}
|
|
239
|
-
</p>
|
|
240
|
-
</div>
|
|
241
|
-
</div>
|
|
242
|
-
<div className="pointer-events-auto flex items-center gap-3">
|
|
243
|
-
{customActions}
|
|
244
|
-
{roomId && (
|
|
245
|
-
<Button
|
|
246
|
-
type="button"
|
|
247
|
-
variant="outline"
|
|
248
|
-
size="icon"
|
|
249
|
-
onClick={() => window.location.reload()}
|
|
250
|
-
disabled={
|
|
251
|
-
connectionStatus === "connecting" ||
|
|
252
|
-
connectionStatus === "reconnecting"
|
|
253
|
-
}
|
|
254
|
-
aria-label="Reconnect"
|
|
255
|
-
title="Reconnect to room"
|
|
256
|
-
>
|
|
257
|
-
<RefreshCw
|
|
258
|
-
className={cn(
|
|
259
|
-
"h-5 w-5",
|
|
260
|
-
(connectionStatus === "connecting" ||
|
|
261
|
-
connectionStatus === "reconnecting") &&
|
|
262
|
-
"animate-spin",
|
|
263
|
-
)}
|
|
264
|
-
/>
|
|
265
|
-
</Button>
|
|
266
|
-
)}
|
|
267
|
-
<Button
|
|
268
|
-
type="button"
|
|
269
|
-
variant="outline"
|
|
270
|
-
size="icon"
|
|
271
|
-
onClick={() => setIsScannerOpen(true)}
|
|
272
|
-
aria-label="Scan QR code to reconnect"
|
|
273
|
-
title="Scan QR code to reconnect"
|
|
274
|
-
>
|
|
275
|
-
<QrCode className="h-5 w-5" />
|
|
276
|
-
</Button>
|
|
277
|
-
<Button
|
|
278
|
-
type="button"
|
|
279
|
-
variant="outline"
|
|
280
|
-
size="icon"
|
|
281
|
-
onClick={() => sendSystemCommand("toggle_pause")}
|
|
282
|
-
aria-label={gameState === "playing" ? "Pause" : "Play"}
|
|
283
|
-
title={gameState === "playing" ? "Pause" : "Play"}
|
|
284
|
-
>
|
|
285
|
-
{gameState === "playing" ? (
|
|
286
|
-
<Pause className="h-5 w-5" />
|
|
287
|
-
) : (
|
|
288
|
-
<Play className="h-5 w-5" />
|
|
289
|
-
)}
|
|
290
|
-
</Button>
|
|
291
|
-
<Button
|
|
292
|
-
type="button"
|
|
293
|
-
variant="outline"
|
|
294
|
-
size="icon"
|
|
295
|
-
onClick={() => toggleFullscreen()}
|
|
296
|
-
aria-label={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
|
|
297
|
-
title={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
|
|
298
|
-
>
|
|
299
|
-
{isFullscreen ? (
|
|
300
|
-
<Minimize className="h-5 w-5" />
|
|
301
|
-
) : (
|
|
302
|
-
<Maximize className="h-5 w-5" />
|
|
303
|
-
)}
|
|
304
|
-
</Button>
|
|
305
|
-
</div>
|
|
306
|
-
</header>
|
|
307
|
-
|
|
308
|
-
<main className="relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4">
|
|
309
|
-
<div className="bg-card/95 absolute inset-0 z-10 flex flex-col items-center justify-center p-6 text-center shadow-lg backdrop-blur-sm">
|
|
310
|
-
{!orientationOk && forceOrientation && (
|
|
311
|
-
<div className="bg-background/95 absolute inset-0 z-10 flex flex-col items-center justify-center p-6 text-center shadow-lg backdrop-blur-sm">
|
|
312
|
-
<p className="text-card-foreground text-xl font-semibold">
|
|
313
|
-
Rotate your device
|
|
314
|
-
</p>
|
|
315
|
-
<p className="text-muted-foreground mt-2 text-sm">
|
|
316
|
-
This game is best experienced in {forceOrientation}{" "}
|
|
317
|
-
orientation.
|
|
318
|
-
</p>
|
|
319
|
-
</div>
|
|
320
|
-
)}
|
|
321
|
-
<div
|
|
322
|
-
className={cn(
|
|
323
|
-
"h-full w-full select-none",
|
|
324
|
-
!orientationOk && "pointer-events-none opacity-30",
|
|
325
|
-
)}
|
|
326
|
-
>
|
|
327
|
-
{children}
|
|
328
|
-
</div>
|
|
329
|
-
</div>
|
|
330
|
-
</main>
|
|
331
|
-
|
|
332
|
-
<QRScannerDialog
|
|
333
|
-
isOpen={isScannerOpen}
|
|
334
|
-
onClose={() => setIsScannerOpen(false)}
|
|
335
|
-
onScan={(roomCode) => {
|
|
336
|
-
// Update room ID in the store, which will trigger reconnection
|
|
337
|
-
store.getState().setRoomId(roomCode);
|
|
338
|
-
reconnect();
|
|
339
|
-
setIsScannerOpen(false);
|
|
340
|
-
}}
|
|
341
|
-
currentRoomId={roomId}
|
|
342
|
-
/>
|
|
343
|
-
</div>
|
|
344
|
-
</div>
|
|
345
|
-
);
|
|
346
|
-
};
|