@air-jam/sdk 0.1.1 → 0.1.3
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/dist/{chunk-7M5D3Y3L.js → chunk-B5DURUWT.js} +11 -3
- package/dist/chunk-B5DURUWT.js.map +1 -0
- package/dist/index.cjs +1733 -1783
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -66
- package/dist/index.d.ts +23 -66
- package/dist/index.js +1722 -1779
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs +10 -0
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +19 -1
- package/dist/protocol.d.ts +19 -1
- package/dist/protocol.js +1 -1
- package/package.json +4 -1
- package/src/AirJamClient.ts +1 -552
- package/src/audio/audio-manager.ts +12 -1
- package/src/audio/volume-store.ts +47 -0
- package/src/components/controller-shell.tsx +201 -177
- package/src/components/{air-jam-overlay.tsx → host-shell.tsx} +59 -51
- package/src/components/qr-scanner-dialog.tsx +2 -2
- package/src/constants.ts +3 -2
- package/src/context/air-jam-context.tsx +3 -14
- package/src/hooks/use-air-jam-controller.ts +1 -1
- package/src/hooks/use-air-jam-host.ts +94 -49
- package/src/hooks/use-air-jam-shell.ts +36 -0
- package/src/index.ts +1 -3
- package/src/internal/input-manager.ts +28 -14
- package/src/protocol.ts +28 -0
- package/src/store/create-air-jam-store.ts +69 -7
- package/src/utils/url-builder.ts +3 -3
- package/dist/chunk-7M5D3Y3L.js.map +0 -1
- package/src/components/air-jam-debug.tsx +0 -77
- package/src/components/debug-state-dialog.tsx +0 -83
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { AIRJAM_PROXY_PREFIX, ErrorCode, controllerInputSchema, controllerJoinSchema, controllerLeaveSchema, controllerStateSchema, controllerSystemSchema, hostJoinAsChildSchema, hostRegisterSystemSchema, hostRegistrationSchema, roomCodeSchema, systemLaunchGameSchema } from './chunk-
|
|
1
|
+
import { controllerSystemSchema, roomCodeSchema, controllerStateSchema, controllerInputSchema, controllerJoinSchema, hostReconnectSchema, hostCreateRoomSchema } from './chunk-B5DURUWT.js';
|
|
2
|
+
export { AIRJAM_PROXY_PREFIX, ErrorCode, controllerInputSchema, controllerJoinSchema, controllerLeaveSchema, controllerStateSchema, controllerSystemSchema, hostCreateRoomSchema, hostJoinAsChildSchema, hostReconnectSchema, hostRegisterSystemSchema, hostRegistrationSchema, roomCodeSchema, systemLaunchGameSchema } from './chunk-B5DURUWT.js';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { createContext, useMemo, useEffect, useCallback, useContext, useRef, useState } from 'react';
|
|
5
5
|
import { create, useStore } from 'zustand';
|
|
@@ -7,20 +7,19 @@ import { useShallow } from 'zustand/react/shallow';
|
|
|
7
7
|
import { io } from 'socket.io-client';
|
|
8
8
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
9
9
|
import { Howler, Howl } from 'howler';
|
|
10
|
-
import {
|
|
11
|
-
import { Slot } from '@radix-ui/react-slot';
|
|
12
|
-
import { cva } from 'class-variance-authority';
|
|
10
|
+
import { RefreshCw, QrCode, Pause, Play, Minimize, Maximize, Volume2, Music, Headphones, MonitorSmartphone, Settings, Check, Copy, ExternalLink } from 'lucide-react';
|
|
13
11
|
import { clsx } from 'clsx';
|
|
14
12
|
import { twMerge } from 'tailwind-merge';
|
|
15
|
-
import
|
|
13
|
+
import { Html5Qrcode } from 'html5-qrcode';
|
|
14
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
15
|
+
import { cva } from 'class-variance-authority';
|
|
16
16
|
import QRCode from 'qrcode';
|
|
17
17
|
import * as TabsPrimitive from '@radix-ui/react-tabs';
|
|
18
18
|
import * as SliderPrimitive from '@radix-ui/react-slider';
|
|
19
|
-
import { Html5Qrcode } from 'html5-qrcode';
|
|
20
19
|
|
|
21
20
|
// src/constants.ts
|
|
22
21
|
var DEFAULT_SERVER_PORT = 4e3;
|
|
23
|
-
var
|
|
22
|
+
var CONTROLLER_PATH = "/controller";
|
|
24
23
|
var INPUT_DEBOUNCE_MS = 200;
|
|
25
24
|
var TOGGLE_DEBOUNCE_MS = 300;
|
|
26
25
|
var SOCKET_CONFIG = {
|
|
@@ -34,26 +33,21 @@ var SOCKET_CONFIG = {
|
|
|
34
33
|
PING_TIMEOUT: 5e3
|
|
35
34
|
};
|
|
36
35
|
var DEFAULT_MAX_PLAYERS = 8;
|
|
37
|
-
|
|
38
|
-
// src/internal/input-manager.ts
|
|
39
36
|
var InputManager = class {
|
|
40
37
|
inputBuffer = /* @__PURE__ */ new Map();
|
|
41
38
|
latchState = /* @__PURE__ */ new Map();
|
|
42
39
|
config;
|
|
43
|
-
|
|
44
|
-
constructor(config = {}, roomId) {
|
|
40
|
+
constructor(config = {}) {
|
|
45
41
|
this.config = config;
|
|
46
|
-
this.roomId = roomId;
|
|
47
42
|
}
|
|
48
43
|
/**
|
|
49
44
|
* Handles incoming input events from the socket.
|
|
50
45
|
* Should be called when 'server:input' event is received.
|
|
51
46
|
*/
|
|
52
47
|
handleInput(payload) {
|
|
53
|
-
if (this.roomId && payload.roomId !== this.roomId) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
48
|
this.inputBuffer.set(payload.controllerId, payload.input);
|
|
49
|
+
const input = payload?.input;
|
|
50
|
+
input && (input.action === true || typeof input.vector === "object" && input.vector !== null && (Math.abs(input.vector.x ?? 0) > 0.01 || Math.abs(input.vector.y ?? 0) > 0.01));
|
|
57
51
|
}
|
|
58
52
|
/**
|
|
59
53
|
* Gets input for a specific controller.
|
|
@@ -92,12 +86,6 @@ var InputManager = class {
|
|
|
92
86
|
this.inputBuffer.delete(controllerId);
|
|
93
87
|
this.latchState.delete(controllerId);
|
|
94
88
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Updates the room ID filter.
|
|
97
|
-
*/
|
|
98
|
-
setRoomId(roomId) {
|
|
99
|
-
this.roomId = roomId;
|
|
100
|
-
}
|
|
101
89
|
/**
|
|
102
90
|
* Internal method to apply latching logic.
|
|
103
91
|
*/
|
|
@@ -321,7 +309,6 @@ var AirJamProvider = ({
|
|
|
321
309
|
children,
|
|
322
310
|
serverUrl,
|
|
323
311
|
apiKey,
|
|
324
|
-
controllerPath = DEFAULT_CONTROLLER_PATH,
|
|
325
312
|
maxPlayers = DEFAULT_MAX_PLAYERS,
|
|
326
313
|
publicHost,
|
|
327
314
|
input
|
|
@@ -330,11 +317,10 @@ var AirJamProvider = ({
|
|
|
330
317
|
() => ({
|
|
331
318
|
serverUrl: serverUrl ?? getEnvServerUrl(),
|
|
332
319
|
apiKey: apiKey ?? getEnvApiKey(),
|
|
333
|
-
controllerPath,
|
|
334
320
|
maxPlayers,
|
|
335
321
|
publicHost
|
|
336
322
|
}),
|
|
337
|
-
[serverUrl, apiKey,
|
|
323
|
+
[serverUrl, apiKey, maxPlayers, publicHost]
|
|
338
324
|
);
|
|
339
325
|
const inputManager = useMemo(() => {
|
|
340
326
|
if (!input) {
|
|
@@ -451,6 +437,22 @@ var useVolumeStore = create((set, get) => ({
|
|
|
451
437
|
return masterVolume * categoryVolume;
|
|
452
438
|
}
|
|
453
439
|
}));
|
|
440
|
+
var setupParentSettingsListener = () => {
|
|
441
|
+
if (typeof window === "undefined") return;
|
|
442
|
+
const isInIframe = window.parent !== window;
|
|
443
|
+
if (!isInIframe) return;
|
|
444
|
+
const handleMessage = (event) => {
|
|
445
|
+
if (event.source !== window.parent) return;
|
|
446
|
+
if (event.data?.type !== "AIRJAM_SETTINGS_SYNC") return;
|
|
447
|
+
const { masterVolume, musicVolume, sfxVolume } = event.data.payload;
|
|
448
|
+
const store = useVolumeStore.getState();
|
|
449
|
+
if (typeof masterVolume === "number") store.setMasterVolume(masterVolume);
|
|
450
|
+
if (typeof musicVolume === "number") store.setMusicVolume(musicVolume);
|
|
451
|
+
if (typeof sfxVolume === "number") store.setSfxVolume(sfxVolume);
|
|
452
|
+
};
|
|
453
|
+
window.addEventListener("message", handleMessage);
|
|
454
|
+
};
|
|
455
|
+
setupParentSettingsListener();
|
|
454
456
|
|
|
455
457
|
// src/audio/audio-manager.ts
|
|
456
458
|
function detectSoundCategory(config) {
|
|
@@ -519,7 +521,12 @@ var AudioManager = class {
|
|
|
519
521
|
if (roomId) this.roomId = roomId;
|
|
520
522
|
}
|
|
521
523
|
/**
|
|
522
|
-
*
|
|
524
|
+
* Resume audio context if suspended. This is automatically called by play(),
|
|
525
|
+
* so you typically don't need to call this manually.
|
|
526
|
+
*
|
|
527
|
+
* Note: Due to browser autoplay policies, audio context starts suspended
|
|
528
|
+
* and can only be resumed in response to a user gesture. The useAudio hook
|
|
529
|
+
* handles this automatically, and play() also calls init() internally.
|
|
523
530
|
*/
|
|
524
531
|
init() {
|
|
525
532
|
if (Howler.ctx && Howler.ctx.state === "suspended") {
|
|
@@ -563,6 +570,7 @@ var AudioManager = class {
|
|
|
563
570
|
sprite,
|
|
564
571
|
pitch
|
|
565
572
|
} = options || {};
|
|
573
|
+
this.init();
|
|
566
574
|
if (remote) {
|
|
567
575
|
this.playRemote(id, target, volume, loop);
|
|
568
576
|
return null;
|
|
@@ -620,6 +628,7 @@ var AudioManager = class {
|
|
|
620
628
|
* Play a sound at a specific 3D position
|
|
621
629
|
*/
|
|
622
630
|
playSpatial(id, pos, sprite) {
|
|
631
|
+
this.init();
|
|
623
632
|
const soundId = this.playLocal(id, void 0, void 0, sprite);
|
|
624
633
|
if (soundId !== null) {
|
|
625
634
|
const sound = this.sounds.get(id);
|
|
@@ -782,237 +791,87 @@ var useAudioManager = (manifest) => {
|
|
|
782
791
|
}
|
|
783
792
|
return managerRef.current;
|
|
784
793
|
};
|
|
785
|
-
var
|
|
786
|
-
|
|
787
|
-
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all cursor-pointer disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
788
|
-
{
|
|
789
|
-
variants: {
|
|
790
|
-
variant: {
|
|
791
|
-
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
792
|
-
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
793
|
-
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
794
|
-
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
795
|
-
ghost: "text-foreground hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
796
|
-
link: "text-primary underline-offset-4 hover:underline"
|
|
797
|
-
},
|
|
798
|
-
size: {
|
|
799
|
-
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
800
|
-
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
801
|
-
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
802
|
-
icon: "size-9",
|
|
803
|
-
"icon-sm": "size-8",
|
|
804
|
-
"icon-lg": "size-10"
|
|
805
|
-
}
|
|
806
|
-
},
|
|
807
|
-
defaultVariants: {
|
|
808
|
-
variant: "default",
|
|
809
|
-
size: "default"
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
);
|
|
813
|
-
function Button({
|
|
814
|
-
className,
|
|
815
|
-
variant,
|
|
816
|
-
size,
|
|
817
|
-
asChild = false,
|
|
818
|
-
...props
|
|
819
|
-
}) {
|
|
820
|
-
const Comp = asChild ? Slot : "button";
|
|
821
|
-
return /* @__PURE__ */ jsx(
|
|
822
|
-
Comp,
|
|
823
|
-
{
|
|
824
|
-
"data-slot": "button",
|
|
825
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
826
|
-
...props
|
|
827
|
-
}
|
|
828
|
-
);
|
|
829
|
-
}
|
|
830
|
-
var Dialog = DialogPrimitive.Root;
|
|
831
|
-
var DialogPortal = DialogPrimitive.Portal;
|
|
832
|
-
var DialogOverlay = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
833
|
-
DialogPrimitive.Overlay,
|
|
834
|
-
{
|
|
835
|
-
ref,
|
|
836
|
-
className: cn(
|
|
837
|
-
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-99999 bg-black/80",
|
|
838
|
-
className
|
|
839
|
-
),
|
|
840
|
-
...props
|
|
841
|
-
}
|
|
842
|
-
));
|
|
843
|
-
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
|
844
|
-
var DialogContent = React.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsx(DialogPortal, { children: /* @__PURE__ */ jsxs("div", { className: "dark", children: [
|
|
845
|
-
/* @__PURE__ */ jsx(DialogOverlay, {}),
|
|
846
|
-
/* @__PURE__ */ jsxs(
|
|
847
|
-
DialogPrimitive.Content,
|
|
848
|
-
{
|
|
849
|
-
ref,
|
|
850
|
-
className: cn(
|
|
851
|
-
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] fixed top-[50%] left-[50%] z-99999 w-full translate-x-[-50%] translate-y-[-50%] gap-4 rounded-xl border border-white p-6 shadow-lg duration-200",
|
|
852
|
-
className
|
|
853
|
-
),
|
|
854
|
-
...props,
|
|
855
|
-
children: [
|
|
856
|
-
children,
|
|
857
|
-
/* @__PURE__ */ jsxs(DialogPrimitive.Close, { className: "text-foreground ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none", children: [
|
|
858
|
-
/* @__PURE__ */ jsx(X, { className: "h-4 w-4" }),
|
|
859
|
-
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
|
|
860
|
-
] })
|
|
861
|
-
]
|
|
862
|
-
}
|
|
863
|
-
)
|
|
864
|
-
] }) }));
|
|
865
|
-
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
|
866
|
-
var DialogHeader = ({
|
|
867
|
-
className,
|
|
868
|
-
...props
|
|
869
|
-
}) => /* @__PURE__ */ jsx(
|
|
870
|
-
"div",
|
|
871
|
-
{
|
|
872
|
-
className: cn(
|
|
873
|
-
"flex flex-col space-y-1.5 text-center sm:text-left",
|
|
874
|
-
className
|
|
875
|
-
),
|
|
876
|
-
...props
|
|
877
|
-
}
|
|
878
|
-
);
|
|
879
|
-
DialogHeader.displayName = "DialogHeader";
|
|
880
|
-
var DialogTitle = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
881
|
-
DialogPrimitive.Title,
|
|
882
|
-
{
|
|
883
|
-
ref,
|
|
884
|
-
className: cn(
|
|
885
|
-
"text-lg leading-none font-semibold tracking-tight",
|
|
886
|
-
className
|
|
887
|
-
),
|
|
888
|
-
...props
|
|
889
|
-
}
|
|
890
|
-
));
|
|
891
|
-
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
|
892
|
-
var DialogDescription = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
893
|
-
DialogPrimitive.Description,
|
|
894
|
-
{
|
|
895
|
-
ref,
|
|
896
|
-
className: cn("text-muted-foreground text-sm", className),
|
|
897
|
-
...props
|
|
898
|
-
}
|
|
899
|
-
));
|
|
900
|
-
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
|
901
|
-
var DebugStateDialog = ({
|
|
902
|
-
isOpen,
|
|
903
|
-
onClose,
|
|
904
|
-
getState,
|
|
905
|
-
title = "Debug State",
|
|
906
|
-
updateInterval = 100
|
|
907
|
-
}) => {
|
|
908
|
-
const [state, setState] = useState(() => getState());
|
|
909
|
-
const [copied, setCopied] = useState(false);
|
|
794
|
+
var useFullscreen = () => {
|
|
795
|
+
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
910
796
|
useEffect(() => {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
797
|
+
const handleFullscreenChange = () => {
|
|
798
|
+
const doc = document;
|
|
799
|
+
setIsFullscreen(
|
|
800
|
+
!!(document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement)
|
|
801
|
+
);
|
|
802
|
+
};
|
|
803
|
+
document.addEventListener("fullscreenchange", handleFullscreenChange);
|
|
804
|
+
document.addEventListener("webkitfullscreenchange", handleFullscreenChange);
|
|
805
|
+
document.addEventListener("mozfullscreenchange", handleFullscreenChange);
|
|
806
|
+
document.addEventListener("msfullscreenchange", handleFullscreenChange);
|
|
918
807
|
return () => {
|
|
919
|
-
|
|
920
|
-
|
|
808
|
+
document.removeEventListener("fullscreenchange", handleFullscreenChange);
|
|
809
|
+
document.removeEventListener(
|
|
810
|
+
"webkitfullscreenchange",
|
|
811
|
+
handleFullscreenChange
|
|
812
|
+
);
|
|
813
|
+
document.removeEventListener(
|
|
814
|
+
"mozfullscreenchange",
|
|
815
|
+
handleFullscreenChange
|
|
816
|
+
);
|
|
817
|
+
document.removeEventListener(
|
|
818
|
+
"msfullscreenchange",
|
|
819
|
+
handleFullscreenChange
|
|
820
|
+
);
|
|
921
821
|
};
|
|
922
|
-
}, [
|
|
923
|
-
const
|
|
924
|
-
const handleCopy = async () => {
|
|
822
|
+
}, []);
|
|
823
|
+
const exitFullscreen = useCallback(async () => {
|
|
925
824
|
try {
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
825
|
+
const doc = document;
|
|
826
|
+
if (document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement) {
|
|
827
|
+
if (document.exitFullscreen) {
|
|
828
|
+
await document.exitFullscreen();
|
|
829
|
+
} else if (doc.webkitExitFullscreen) {
|
|
830
|
+
await doc.webkitExitFullscreen();
|
|
831
|
+
} else if (doc.mozCancelFullScreen) {
|
|
832
|
+
await doc.mozCancelFullScreen();
|
|
833
|
+
} else if (doc.msExitFullscreen) {
|
|
834
|
+
await doc.msExitFullscreen();
|
|
835
|
+
}
|
|
836
|
+
}
|
|
929
837
|
} catch (error) {
|
|
930
|
-
console.error("
|
|
838
|
+
console.error("Error exiting fullscreen:", error);
|
|
931
839
|
}
|
|
932
|
-
};
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
children: copied ? /* @__PURE__ */ jsx(Check, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(Copy, { className: "h-4 w-4" })
|
|
945
|
-
}
|
|
946
|
-
),
|
|
947
|
-
/* @__PURE__ */ jsx("pre", { className: "bg-muted text-muted-foreground overflow-auto rounded-lg border p-4 font-mono text-xs", children: jsonString })
|
|
948
|
-
] })
|
|
949
|
-
] }) });
|
|
950
|
-
};
|
|
951
|
-
var AirJamDebug = ({
|
|
952
|
-
state,
|
|
953
|
-
title = "Debug State",
|
|
954
|
-
updateInterval = 100,
|
|
955
|
-
className
|
|
956
|
-
}) => {
|
|
957
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
958
|
-
const [currentState, setCurrentState] = useState(state);
|
|
959
|
-
useEffect(() => {
|
|
960
|
-
if (!isOpen) return;
|
|
961
|
-
const interval = setInterval(() => {
|
|
962
|
-
setCurrentState(state);
|
|
963
|
-
}, updateInterval);
|
|
964
|
-
setCurrentState(state);
|
|
965
|
-
return () => clearInterval(interval);
|
|
966
|
-
}, [isOpen, state, updateInterval]);
|
|
967
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
968
|
-
/* @__PURE__ */ jsx(
|
|
969
|
-
Button,
|
|
970
|
-
{
|
|
971
|
-
type: "button",
|
|
972
|
-
variant: "ghost",
|
|
973
|
-
size: "icon",
|
|
974
|
-
onClick: () => setIsOpen(true),
|
|
975
|
-
"aria-label": "Debug state",
|
|
976
|
-
title,
|
|
977
|
-
className: `text-white hover:bg-white/20 hover:text-white ${className || ""}`,
|
|
978
|
-
children: /* @__PURE__ */ jsx(Bug, { className: "h-4 w-4" })
|
|
979
|
-
}
|
|
980
|
-
),
|
|
981
|
-
/* @__PURE__ */ jsx(
|
|
982
|
-
DebugStateDialog,
|
|
983
|
-
{
|
|
984
|
-
isOpen,
|
|
985
|
-
onClose: () => setIsOpen(false),
|
|
986
|
-
getState: () => currentState,
|
|
987
|
-
title,
|
|
988
|
-
updateInterval
|
|
840
|
+
}, []);
|
|
841
|
+
const enterFullscreen = useCallback(async (element) => {
|
|
842
|
+
try {
|
|
843
|
+
const elem = element || document.documentElement;
|
|
844
|
+
if (elem.requestFullscreen) {
|
|
845
|
+
await elem.requestFullscreen();
|
|
846
|
+
} else if (elem.webkitRequestFullscreen) {
|
|
847
|
+
await elem.webkitRequestFullscreen();
|
|
848
|
+
} else if (elem.mozRequestFullScreen) {
|
|
849
|
+
await elem.mozRequestFullScreen();
|
|
850
|
+
} else if (elem.msRequestFullscreen) {
|
|
851
|
+
await elem.msRequestFullscreen();
|
|
989
852
|
}
|
|
990
|
-
)
|
|
991
|
-
|
|
992
|
-
};
|
|
993
|
-
|
|
994
|
-
// src/utils/ids.ts
|
|
995
|
-
var alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
996
|
-
var generateRoomCode = () => {
|
|
997
|
-
const array = new Uint32Array(4);
|
|
998
|
-
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
999
|
-
crypto.getRandomValues(array);
|
|
1000
|
-
} else {
|
|
1001
|
-
for (let i = 0; i < array.length; i += 1) {
|
|
1002
|
-
array[i] = Math.floor(Math.random() * alphabet.length);
|
|
853
|
+
} catch (error) {
|
|
854
|
+
console.error("Error entering fullscreen:", error);
|
|
1003
855
|
}
|
|
1004
|
-
}
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
856
|
+
}, []);
|
|
857
|
+
const toggleFullscreen = useCallback(
|
|
858
|
+
async (element) => {
|
|
859
|
+
if (isFullscreen) {
|
|
860
|
+
await exitFullscreen();
|
|
861
|
+
} else {
|
|
862
|
+
await enterFullscreen(element);
|
|
863
|
+
}
|
|
864
|
+
},
|
|
865
|
+
[isFullscreen, exitFullscreen, enterFullscreen]
|
|
866
|
+
);
|
|
867
|
+
return {
|
|
868
|
+
isFullscreen,
|
|
869
|
+
enterFullscreen,
|
|
870
|
+
exitFullscreen,
|
|
871
|
+
toggleFullscreen
|
|
872
|
+
};
|
|
1015
873
|
};
|
|
874
|
+
var cn = (...inputs) => twMerge(clsx(inputs));
|
|
1016
875
|
|
|
1017
876
|
// src/utils/mode.ts
|
|
1018
877
|
var detectRunMode = () => {
|
|
@@ -1025,6 +884,47 @@ var detectRunMode = () => {
|
|
|
1025
884
|
return "platform";
|
|
1026
885
|
}
|
|
1027
886
|
};
|
|
887
|
+
var getPlayerAvatarUrl = (playerId) => {
|
|
888
|
+
return `https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=${encodeURIComponent(
|
|
889
|
+
playerId
|
|
890
|
+
)}`;
|
|
891
|
+
};
|
|
892
|
+
var hexToRgba = (hex, opacity) => {
|
|
893
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
894
|
+
if (!result) return `rgba(0, 0, 0, ${opacity})`;
|
|
895
|
+
const r = parseInt(result[1], 16);
|
|
896
|
+
const g = parseInt(result[2], 16);
|
|
897
|
+
const b = parseInt(result[3], 16);
|
|
898
|
+
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
899
|
+
};
|
|
900
|
+
var PlayerAvatar = ({
|
|
901
|
+
player,
|
|
902
|
+
size = "md",
|
|
903
|
+
className = ""
|
|
904
|
+
}) => {
|
|
905
|
+
const sizeClasses = {
|
|
906
|
+
sm: "h-8 w-8 border-2",
|
|
907
|
+
md: "h-12 w-12 border-4",
|
|
908
|
+
lg: "h-16 w-16 border-4"
|
|
909
|
+
};
|
|
910
|
+
const shadowStyles = {
|
|
911
|
+
sm: player.color ? `inset 0 0 4px rgba(0, 0, 0, 0.2), 0 0 8px ${hexToRgba(player.color, 0.4)}` : "inset 0 0 4px rgba(0, 0, 0, 0.2)",
|
|
912
|
+
md: player.color ? `inset 0 0 10px rgba(0, 0, 0, 0.4), 0 0 20px ${hexToRgba(player.color, 0.6)}, 0 0 10px ${hexToRgba(player.color, 0.8)}` : "inset 0 0 10px rgba(0, 0, 0, 0.4), 0 0 20px hsl(var(--border) / 0.5)",
|
|
913
|
+
lg: player.color ? `inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 24px ${hexToRgba(player.color, 0.6)}, 0 0 12px ${hexToRgba(player.color, 0.8)}` : "inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 24px hsl(var(--border) / 0.5)"
|
|
914
|
+
};
|
|
915
|
+
return /* @__PURE__ */ jsx(
|
|
916
|
+
"img",
|
|
917
|
+
{
|
|
918
|
+
src: getPlayerAvatarUrl(player.id),
|
|
919
|
+
alt: player.label,
|
|
920
|
+
className: `bg-secondary/30 shrink-0 rounded-full shadow-lg ${sizeClasses[size]} ${className}`,
|
|
921
|
+
style: {
|
|
922
|
+
borderColor: player.color || "hsl(var(--border))",
|
|
923
|
+
boxShadow: shadowStyles[size]
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
);
|
|
927
|
+
};
|
|
1028
928
|
|
|
1029
929
|
// src/utils/network-ip.ts
|
|
1030
930
|
var isVirtualNetwork = (ip) => {
|
|
@@ -1177,10 +1077,11 @@ var UrlBuilder = class {
|
|
|
1177
1077
|
}
|
|
1178
1078
|
/**
|
|
1179
1079
|
* Build a controller URL with room code.
|
|
1080
|
+
* Controller is always at {baseUrl}/controller (standardized convention).
|
|
1180
1081
|
* Automatically uses local IP when running on localhost.
|
|
1181
1082
|
*/
|
|
1182
1083
|
async buildControllerUrl(roomId, options) {
|
|
1183
|
-
const path =
|
|
1084
|
+
const path = CONTROLLER_PATH;
|
|
1184
1085
|
if (options?.host) {
|
|
1185
1086
|
const url2 = new URL(path, this.normalizeOrigin(options.host));
|
|
1186
1087
|
url2.searchParams.set("room", roomId);
|
|
@@ -1239,1638 +1140,1617 @@ var UrlBuilder = class {
|
|
|
1239
1140
|
}
|
|
1240
1141
|
};
|
|
1241
1142
|
var urlBuilder = new UrlBuilder();
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
return roomCodeSchema.parse(arcadeParams.room.toUpperCase());
|
|
1262
|
-
}
|
|
1263
|
-
if (typeof window !== "undefined") {
|
|
1264
|
-
const params = new URLSearchParams(window.location.search);
|
|
1265
|
-
const paramRoom = params.get("room");
|
|
1266
|
-
if (paramRoom) {
|
|
1267
|
-
const result = roomCodeSchema.safeParse(paramRoom.toUpperCase());
|
|
1268
|
-
if (result.success) return result.data;
|
|
1143
|
+
var buttonVariants = cva(
|
|
1144
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all cursor-pointer disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
1145
|
+
{
|
|
1146
|
+
variants: {
|
|
1147
|
+
variant: {
|
|
1148
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
1149
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
1150
|
+
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
1151
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
1152
|
+
ghost: "text-foreground hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
1153
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
1154
|
+
},
|
|
1155
|
+
size: {
|
|
1156
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
1157
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
1158
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
1159
|
+
icon: "size-9",
|
|
1160
|
+
"icon-sm": "size-8",
|
|
1161
|
+
"icon-lg": "size-10"
|
|
1269
1162
|
}
|
|
1163
|
+
},
|
|
1164
|
+
defaultVariants: {
|
|
1165
|
+
variant: "default",
|
|
1166
|
+
size: "default"
|
|
1270
1167
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1168
|
+
}
|
|
1169
|
+
);
|
|
1170
|
+
function Button({
|
|
1171
|
+
className,
|
|
1172
|
+
variant,
|
|
1173
|
+
size,
|
|
1174
|
+
asChild = false,
|
|
1175
|
+
...props
|
|
1176
|
+
}) {
|
|
1177
|
+
const Comp = asChild ? Slot : "button";
|
|
1178
|
+
return /* @__PURE__ */ jsx(
|
|
1179
|
+
Comp,
|
|
1180
|
+
{
|
|
1181
|
+
"data-slot": "button",
|
|
1182
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
1183
|
+
...props
|
|
1273
1184
|
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1185
|
+
);
|
|
1186
|
+
}
|
|
1187
|
+
var extractRoomCode = (text) => {
|
|
1188
|
+
try {
|
|
1189
|
+
const url = new URL(text);
|
|
1190
|
+
const roomParam = url.searchParams.get("room");
|
|
1191
|
+
if (roomParam) {
|
|
1192
|
+
const parsed2 = roomCodeSchema.safeParse(roomParam.toUpperCase());
|
|
1193
|
+
if (parsed2.success) {
|
|
1194
|
+
return parsed2.data;
|
|
1195
|
+
}
|
|
1279
1196
|
}
|
|
1280
|
-
}
|
|
1197
|
+
} catch {
|
|
1198
|
+
}
|
|
1199
|
+
const parsed = roomCodeSchema.safeParse(text.trim().toUpperCase());
|
|
1200
|
+
if (parsed.success) {
|
|
1201
|
+
return parsed.data;
|
|
1202
|
+
}
|
|
1203
|
+
return null;
|
|
1204
|
+
};
|
|
1205
|
+
var QRScannerDialog = ({
|
|
1206
|
+
isOpen,
|
|
1207
|
+
onClose,
|
|
1208
|
+
onScan,
|
|
1209
|
+
currentRoomId
|
|
1210
|
+
}) => {
|
|
1211
|
+
const [code, setCode] = useState("");
|
|
1212
|
+
const [isCameraAvailable, setIsCameraAvailable] = useState(false);
|
|
1281
1213
|
const [joinUrl, setJoinUrl] = useState("");
|
|
1282
|
-
const
|
|
1283
|
-
const
|
|
1284
|
-
const
|
|
1214
|
+
const [copied, setCopied] = useState(false);
|
|
1215
|
+
const scannerRef = useRef(null);
|
|
1216
|
+
const inputRef = useRef(null);
|
|
1217
|
+
const prevIsOpenRef = useRef(false);
|
|
1285
1218
|
useEffect(() => {
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
lastError: state.lastError,
|
|
1295
|
-
players: state.players,
|
|
1296
|
-
gameState: state.gameState,
|
|
1297
|
-
mode: state.mode
|
|
1298
|
-
}))
|
|
1299
|
-
);
|
|
1300
|
-
const socket = useMemo(
|
|
1301
|
-
() => getSocket("host") ,
|
|
1302
|
-
[shouldConnect, getSocket]
|
|
1303
|
-
);
|
|
1304
|
-
const [lastToggle, setLastToggle] = useState(0);
|
|
1305
|
-
const toggleGameState = useCallback(() => {
|
|
1306
|
-
const now = Date.now();
|
|
1307
|
-
if (now - lastToggle < TOGGLE_DEBOUNCE_MS) {
|
|
1308
|
-
return;
|
|
1309
|
-
}
|
|
1310
|
-
setLastToggle(now);
|
|
1311
|
-
if (!socket || !socket.connected) {
|
|
1312
|
-
return;
|
|
1313
|
-
}
|
|
1314
|
-
const payload = controllerSystemSchema.safeParse({
|
|
1315
|
-
roomId: parsedRoomId,
|
|
1316
|
-
command: "toggle_pause"
|
|
1317
|
-
});
|
|
1318
|
-
if (payload.success) {
|
|
1319
|
-
socket.emit("host:system", payload.data);
|
|
1219
|
+
if (isOpen && !prevIsOpenRef.current) {
|
|
1220
|
+
const initialCode = currentRoomId || "";
|
|
1221
|
+
setTimeout(() => {
|
|
1222
|
+
setIsCameraAvailable(false);
|
|
1223
|
+
setCode(initialCode);
|
|
1224
|
+
inputRef.current?.focus();
|
|
1225
|
+
inputRef.current?.select();
|
|
1226
|
+
}, 0);
|
|
1320
1227
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1228
|
+
prevIsOpenRef.current = isOpen;
|
|
1229
|
+
}, [isOpen, currentRoomId]);
|
|
1230
|
+
useEffect(() => {
|
|
1231
|
+
const buildUrl = async () => {
|
|
1232
|
+
const trimmed = code.trim().toUpperCase();
|
|
1233
|
+
const parsed = roomCodeSchema.safeParse(trimmed);
|
|
1234
|
+
if (parsed.success) {
|
|
1235
|
+
try {
|
|
1236
|
+
const url = await urlBuilder.buildControllerUrl(parsed.data);
|
|
1237
|
+
setJoinUrl(url);
|
|
1238
|
+
} catch {
|
|
1239
|
+
setJoinUrl("");
|
|
1240
|
+
}
|
|
1241
|
+
} else {
|
|
1242
|
+
setJoinUrl("");
|
|
1333
1243
|
}
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1244
|
+
};
|
|
1245
|
+
buildUrl();
|
|
1246
|
+
}, [code]);
|
|
1247
|
+
useEffect(() => {
|
|
1248
|
+
if (!isOpen) {
|
|
1249
|
+
setTimeout(() => {
|
|
1250
|
+
setIsCameraAvailable(false);
|
|
1251
|
+
}, 0);
|
|
1252
|
+
if (scannerRef.current) {
|
|
1253
|
+
const scanner = scannerRef.current;
|
|
1254
|
+
scanner.stop().catch(() => {
|
|
1255
|
+
}).finally(() => {
|
|
1256
|
+
try {
|
|
1257
|
+
scanner.clear();
|
|
1258
|
+
} catch {
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
scannerRef.current = null;
|
|
1343
1262
|
}
|
|
1344
|
-
const signal = {
|
|
1345
|
-
targetId,
|
|
1346
|
-
type,
|
|
1347
|
-
payload
|
|
1348
|
-
};
|
|
1349
|
-
socket.emit("host:signal", signal);
|
|
1350
|
-
},
|
|
1351
|
-
[socket]
|
|
1352
|
-
);
|
|
1353
|
-
const reconnect = useCallback(() => {
|
|
1354
|
-
disconnectSocket("host");
|
|
1355
|
-
if (socket) {
|
|
1356
|
-
socket.connect();
|
|
1357
1263
|
}
|
|
1358
|
-
}, [
|
|
1359
|
-
useEffect(() => {
|
|
1360
|
-
(async () => {
|
|
1361
|
-
const url = await urlBuilder.buildControllerUrl(parsedRoomId, {
|
|
1362
|
-
path: config.controllerPath,
|
|
1363
|
-
host: config.publicHost
|
|
1364
|
-
});
|
|
1365
|
-
setJoinUrl(url);
|
|
1366
|
-
})();
|
|
1367
|
-
}, [parsedRoomId, config.controllerPath, config.publicHost]);
|
|
1368
|
-
const setRegisteredRoomId = useStore(store, (s) => s.setRegisteredRoomId);
|
|
1264
|
+
}, [isOpen]);
|
|
1369
1265
|
useEffect(() => {
|
|
1370
|
-
|
|
1371
|
-
storeState.setMode(detectRunMode());
|
|
1372
|
-
storeState.setRole("host");
|
|
1373
|
-
storeState.setRoomId(parsedRoomId);
|
|
1374
|
-
storeState.setStatus("connecting");
|
|
1375
|
-
storeState.setError(void 0);
|
|
1376
|
-
if (!socket) {
|
|
1377
|
-
storeState.setStatus("idle");
|
|
1266
|
+
if (!isOpen) {
|
|
1378
1267
|
return;
|
|
1379
1268
|
}
|
|
1380
|
-
const
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1269
|
+
const containerId = "qr-reader";
|
|
1270
|
+
let scanner = null;
|
|
1271
|
+
let scannerRunning = false;
|
|
1272
|
+
let mounted = true;
|
|
1273
|
+
const startScanning = async () => {
|
|
1274
|
+
try {
|
|
1275
|
+
const container = document.getElementById(containerId);
|
|
1276
|
+
if (!container) {
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
const rect = container.getBoundingClientRect();
|
|
1280
|
+
if (rect.width === 0 || rect.height === 0) {
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
scanner = new Html5Qrcode(containerId);
|
|
1284
|
+
scannerRef.current = scanner;
|
|
1285
|
+
let cameraId = null;
|
|
1286
|
+
try {
|
|
1287
|
+
const devices = await Html5Qrcode.getCameras();
|
|
1288
|
+
if (devices && devices.length > 0) {
|
|
1289
|
+
const backCamera = devices.find(
|
|
1290
|
+
(d) => d.label.toLowerCase().includes("back") || d.label.toLowerCase().includes("rear")
|
|
1291
|
+
);
|
|
1292
|
+
const envCamera = devices.find((d) => {
|
|
1293
|
+
const label = d.label.toLowerCase();
|
|
1294
|
+
return label.includes("environment") || label.includes("facing back");
|
|
1295
|
+
});
|
|
1296
|
+
cameraId = (envCamera || backCamera || devices[0])?.id || null;
|
|
1297
|
+
}
|
|
1298
|
+
} catch {
|
|
1299
|
+
}
|
|
1300
|
+
const config = cameraId ? { deviceId: { exact: cameraId } } : { facingMode: "environment" };
|
|
1301
|
+
await scanner.start(
|
|
1302
|
+
config,
|
|
1303
|
+
{
|
|
1304
|
+
fps: 10,
|
|
1305
|
+
qrbox: (viewfinderWidth, viewfinderHeight) => {
|
|
1306
|
+
const minEdge = Math.min(viewfinderWidth, viewfinderHeight);
|
|
1307
|
+
const qrboxSize = Math.min(250, minEdge * 0.8);
|
|
1308
|
+
return {
|
|
1309
|
+
width: qrboxSize,
|
|
1310
|
+
height: qrboxSize
|
|
1311
|
+
};
|
|
1312
|
+
},
|
|
1313
|
+
aspectRatio: 1
|
|
1314
|
+
},
|
|
1315
|
+
(decodedText) => {
|
|
1316
|
+
if (!mounted) return;
|
|
1317
|
+
const roomCode = extractRoomCode(decodedText);
|
|
1318
|
+
if (roomCode) {
|
|
1319
|
+
setCode(roomCode);
|
|
1320
|
+
scannerRunning = false;
|
|
1321
|
+
scanner?.stop().catch(() => {
|
|
1322
|
+
}).finally(() => {
|
|
1323
|
+
if (mounted) {
|
|
1324
|
+
setIsCameraAvailable(false);
|
|
1325
|
+
}
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
},
|
|
1329
|
+
() => {
|
|
1330
|
+
}
|
|
1331
|
+
);
|
|
1332
|
+
scannerRunning = true;
|
|
1333
|
+
if (mounted) {
|
|
1334
|
+
setIsCameraAvailable(true);
|
|
1335
|
+
}
|
|
1336
|
+
} catch {
|
|
1337
|
+
if (mounted) {
|
|
1338
|
+
setIsCameraAvailable(false);
|
|
1339
|
+
}
|
|
1340
|
+
if (scanner) {
|
|
1341
|
+
try {
|
|
1342
|
+
scanner.clear();
|
|
1343
|
+
} catch {
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
scannerRef.current = null;
|
|
1450
1347
|
}
|
|
1451
1348
|
};
|
|
1452
|
-
const
|
|
1453
|
-
|
|
1454
|
-
};
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
if (
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1349
|
+
const timeoutId = setTimeout(() => {
|
|
1350
|
+
startScanning();
|
|
1351
|
+
}, 200);
|
|
1352
|
+
return () => {
|
|
1353
|
+
mounted = false;
|
|
1354
|
+
clearTimeout(timeoutId);
|
|
1355
|
+
if (scanner && scannerRunning) {
|
|
1356
|
+
scanner.stop().catch(() => {
|
|
1357
|
+
}).finally(() => {
|
|
1358
|
+
try {
|
|
1359
|
+
scanner?.clear();
|
|
1360
|
+
} catch {
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
} else if (scanner) {
|
|
1364
|
+
try {
|
|
1365
|
+
scanner.clear();
|
|
1366
|
+
} catch {
|
|
1367
|
+
}
|
|
1463
1368
|
}
|
|
1369
|
+
scannerRef.current = null;
|
|
1464
1370
|
};
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
socket.on("server:input", handleInput);
|
|
1473
|
-
socket.on("server:error", handleError);
|
|
1474
|
-
socket.on("server:closeChild", handleChildClose);
|
|
1475
|
-
socket.on("server:state", handleState);
|
|
1476
|
-
socket.connect();
|
|
1477
|
-
const currentRegisteredRoomId = store.getState().registeredRoomId;
|
|
1478
|
-
if (socket.connected && currentRegisteredRoomId !== parsedRoomId) {
|
|
1479
|
-
registerHost();
|
|
1480
|
-
}
|
|
1481
|
-
if (currentRegisteredRoomId && currentRegisteredRoomId !== parsedRoomId) {
|
|
1482
|
-
setRegisteredRoomId(null);
|
|
1371
|
+
}, [isOpen]);
|
|
1372
|
+
const handleSubmit = () => {
|
|
1373
|
+
const trimmed = code.trim().toUpperCase();
|
|
1374
|
+
const parsed = roomCodeSchema.safeParse(trimmed);
|
|
1375
|
+
if (parsed.success) {
|
|
1376
|
+
onScan(parsed.data);
|
|
1377
|
+
onClose();
|
|
1483
1378
|
}
|
|
1484
|
-
return () => {
|
|
1485
|
-
socket.off("connect", handleConnect);
|
|
1486
|
-
socket.off("disconnect", handleDisconnect);
|
|
1487
|
-
socket.off("server:controllerJoined", handleJoin);
|
|
1488
|
-
socket.off("server:controllerLeft", handleLeave);
|
|
1489
|
-
socket.off("server:input", handleInput);
|
|
1490
|
-
socket.off("server:error", handleError);
|
|
1491
|
-
socket.off("server:closeChild", handleChildClose);
|
|
1492
|
-
socket.off("server:state", handleState);
|
|
1493
|
-
};
|
|
1494
|
-
}, [
|
|
1495
|
-
config.maxPlayers,
|
|
1496
|
-
config.apiKey,
|
|
1497
|
-
options.maxPlayers,
|
|
1498
|
-
options.apiKey,
|
|
1499
|
-
parsedRoomId,
|
|
1500
|
-
arcadeParams,
|
|
1501
|
-
shouldConnect,
|
|
1502
|
-
socket,
|
|
1503
|
-
store,
|
|
1504
|
-
inputManager,
|
|
1505
|
-
setRegisteredRoomId
|
|
1506
|
-
]);
|
|
1507
|
-
const returnSocket = socket ?? getSocket("host");
|
|
1508
|
-
const getInput = useCallback(
|
|
1509
|
-
(controllerId) => {
|
|
1510
|
-
if (!inputManager) {
|
|
1511
|
-
return void 0;
|
|
1512
|
-
}
|
|
1513
|
-
return inputManager.getInput(controllerId);
|
|
1514
|
-
},
|
|
1515
|
-
[inputManager]
|
|
1516
|
-
);
|
|
1517
|
-
return {
|
|
1518
|
-
roomId: parsedRoomId,
|
|
1519
|
-
joinUrl,
|
|
1520
|
-
connectionStatus: connectionState.connectionStatus,
|
|
1521
|
-
players: connectionState.players,
|
|
1522
|
-
lastError: connectionState.lastError,
|
|
1523
|
-
mode: connectionState.mode,
|
|
1524
|
-
gameState: connectionState.gameState,
|
|
1525
|
-
toggleGameState,
|
|
1526
|
-
sendState,
|
|
1527
|
-
sendSignal,
|
|
1528
|
-
reconnect,
|
|
1529
|
-
socket: returnSocket,
|
|
1530
|
-
isChildMode,
|
|
1531
|
-
getInput
|
|
1532
1379
|
};
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
return `https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=${encodeURIComponent(
|
|
1536
|
-
playerId
|
|
1537
|
-
)}`;
|
|
1538
|
-
};
|
|
1539
|
-
var hexToRgba = (hex, opacity) => {
|
|
1540
|
-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
1541
|
-
if (!result) return `rgba(0, 0, 0, ${opacity})`;
|
|
1542
|
-
const r = parseInt(result[1], 16);
|
|
1543
|
-
const g = parseInt(result[2], 16);
|
|
1544
|
-
const b = parseInt(result[3], 16);
|
|
1545
|
-
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
1546
|
-
};
|
|
1547
|
-
var PlayerAvatar = ({
|
|
1548
|
-
player,
|
|
1549
|
-
size = "md",
|
|
1550
|
-
className = ""
|
|
1551
|
-
}) => {
|
|
1552
|
-
const sizeClasses = {
|
|
1553
|
-
sm: "h-8 w-8 border-2",
|
|
1554
|
-
md: "h-12 w-12 border-4",
|
|
1555
|
-
lg: "h-16 w-16 border-4"
|
|
1380
|
+
const handleInputFocus = (e) => {
|
|
1381
|
+
e.target.select();
|
|
1556
1382
|
};
|
|
1557
|
-
const
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
lg: player.color ? `inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 24px ${hexToRgba(player.color, 0.6)}, 0 0 12px ${hexToRgba(player.color, 0.8)}` : "inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 24px hsl(var(--border) / 0.5)"
|
|
1383
|
+
const handleInputChange = (e) => {
|
|
1384
|
+
setCode(e.target.value.toUpperCase());
|
|
1385
|
+
setCopied(false);
|
|
1561
1386
|
};
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
{
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1387
|
+
const handleCopyUrl = async () => {
|
|
1388
|
+
if (!joinUrl) return;
|
|
1389
|
+
try {
|
|
1390
|
+
await navigator.clipboard.writeText(joinUrl);
|
|
1391
|
+
setCopied(true);
|
|
1392
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
1393
|
+
} catch {
|
|
1394
|
+
const textArea = document.createElement("textarea");
|
|
1395
|
+
textArea.value = joinUrl;
|
|
1396
|
+
textArea.style.position = "fixed";
|
|
1397
|
+
textArea.style.opacity = "0";
|
|
1398
|
+
document.body.appendChild(textArea);
|
|
1399
|
+
textArea.select();
|
|
1400
|
+
try {
|
|
1401
|
+
document.execCommand("copy");
|
|
1402
|
+
setCopied(true);
|
|
1403
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
1404
|
+
} catch {
|
|
1571
1405
|
}
|
|
1406
|
+
document.body.removeChild(textArea);
|
|
1572
1407
|
}
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
"relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
|
|
1577
|
-
{
|
|
1578
|
-
variants: {
|
|
1579
|
-
variant: {
|
|
1580
|
-
default: "bg-card text-card-foreground",
|
|
1581
|
-
destructive: "text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"
|
|
1582
|
-
}
|
|
1583
|
-
},
|
|
1584
|
-
defaultVariants: {
|
|
1585
|
-
variant: "default"
|
|
1586
|
-
}
|
|
1408
|
+
};
|
|
1409
|
+
if (!isOpen) {
|
|
1410
|
+
return null;
|
|
1587
1411
|
}
|
|
1588
|
-
);
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1412
|
+
const isValid = code.trim().length > 0;
|
|
1413
|
+
return /* @__PURE__ */ jsxs("div", { className: "bg-background fixed inset-0 z-50 flex flex-col items-center justify-center", children: [
|
|
1414
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col items-center justify-center", children: [
|
|
1415
|
+
isCameraAvailable && /* @__PURE__ */ jsx("div", { className: "relative flex aspect-square w-full items-center justify-center overflow-hidden p-6", children: /* @__PURE__ */ jsx(
|
|
1416
|
+
"div",
|
|
1417
|
+
{
|
|
1418
|
+
id: "qr-reader",
|
|
1419
|
+
className: "h-full w-full overflow-hidden rounded-lg bg-black"
|
|
1420
|
+
}
|
|
1421
|
+
) }),
|
|
1422
|
+
/* @__PURE__ */ jsx("div", { className: "w-full max-w-md px-6", children: /* @__PURE__ */ jsx(
|
|
1423
|
+
"input",
|
|
1424
|
+
{
|
|
1425
|
+
ref: inputRef,
|
|
1426
|
+
type: "text",
|
|
1427
|
+
value: code,
|
|
1428
|
+
onChange: handleInputChange,
|
|
1429
|
+
onFocus: handleInputFocus,
|
|
1430
|
+
onKeyDown: (e) => {
|
|
1431
|
+
if (e.key === "Enter" && isValid) {
|
|
1432
|
+
handleSubmit();
|
|
1433
|
+
}
|
|
1434
|
+
},
|
|
1435
|
+
placeholder: "Enter room code",
|
|
1436
|
+
className: "border-border bg-background focus:ring-primary focus:border-primary w-full rounded-lg border-2 px-6 py-4 text-center font-mono text-2xl focus:ring-2 focus:outline-none",
|
|
1437
|
+
autoComplete: "off",
|
|
1438
|
+
autoCapitalize: "characters"
|
|
1439
|
+
}
|
|
1440
|
+
) }),
|
|
1441
|
+
joinUrl && /* @__PURE__ */ jsx("div", { className: "mt-4 w-full max-w-md px-6 pb-2", children: /* @__PURE__ */ jsx(
|
|
1442
|
+
"button",
|
|
1443
|
+
{
|
|
1444
|
+
type: "button",
|
|
1445
|
+
onClick: handleCopyUrl,
|
|
1446
|
+
className: "text-muted-foreground hover:text-foreground bg-muted/50 hover:bg-muted w-full rounded-lg px-4 py-3 text-center font-mono text-xs break-all transition-colors",
|
|
1447
|
+
children: copied ? "\u2713 Copied!" : joinUrl
|
|
1448
|
+
}
|
|
1449
|
+
) })
|
|
1450
|
+
] }),
|
|
1451
|
+
/* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-md gap-4 px-6 pb-6", children: [
|
|
1452
|
+
/* @__PURE__ */ jsx(
|
|
1453
|
+
Button,
|
|
1454
|
+
{
|
|
1455
|
+
type: "button",
|
|
1456
|
+
variant: "outline",
|
|
1457
|
+
onClick: onClose,
|
|
1458
|
+
className: "flex-1 py-6",
|
|
1459
|
+
children: "Cancel"
|
|
1460
|
+
}
|
|
1615
1461
|
),
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1462
|
+
/* @__PURE__ */ jsx(
|
|
1463
|
+
Button,
|
|
1464
|
+
{
|
|
1465
|
+
type: "button",
|
|
1466
|
+
onClick: handleSubmit,
|
|
1467
|
+
disabled: !isValid,
|
|
1468
|
+
className: "flex-1 py-6",
|
|
1469
|
+
children: "Connect"
|
|
1470
|
+
}
|
|
1471
|
+
)
|
|
1472
|
+
] })
|
|
1473
|
+
] });
|
|
1474
|
+
};
|
|
1475
|
+
var describeStatus = (status) => {
|
|
1476
|
+
switch (status) {
|
|
1477
|
+
case "connected":
|
|
1478
|
+
return "Connected to host";
|
|
1479
|
+
case "connecting":
|
|
1480
|
+
return "Connecting\u2026";
|
|
1481
|
+
case "reconnecting":
|
|
1482
|
+
return "Trying to reconnect\u2026";
|
|
1483
|
+
case "disconnected":
|
|
1484
|
+
return "Disconnected";
|
|
1485
|
+
case "idle":
|
|
1486
|
+
default:
|
|
1487
|
+
return "Idle";
|
|
1634
1488
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
}
|
|
1652
|
-
function Card({ className, ...props }) {
|
|
1653
|
-
return /* @__PURE__ */ jsx(
|
|
1654
|
-
"div",
|
|
1655
|
-
{
|
|
1656
|
-
"data-slot": "card",
|
|
1657
|
-
className: cn(
|
|
1658
|
-
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
|
1659
|
-
className
|
|
1660
|
-
),
|
|
1661
|
-
...props
|
|
1662
|
-
}
|
|
1489
|
+
};
|
|
1490
|
+
var orientationMatches = (required) => {
|
|
1491
|
+
if (!required) return true;
|
|
1492
|
+
if (typeof window === "undefined" || !window.matchMedia) return true;
|
|
1493
|
+
const matcher = window.matchMedia(`(orientation: ${required})`);
|
|
1494
|
+
return matcher.matches;
|
|
1495
|
+
};
|
|
1496
|
+
var ControllerShell = ({
|
|
1497
|
+
forceOrientation,
|
|
1498
|
+
children,
|
|
1499
|
+
customActions
|
|
1500
|
+
}) => {
|
|
1501
|
+
const { store, getSocket, disconnectSocket } = useAirJamContext();
|
|
1502
|
+
const isChildMode = useMemo(() => detectRunMode() === "platform", []);
|
|
1503
|
+
const [isOrientationOk, setOrientationOk] = useState(
|
|
1504
|
+
() => orientationMatches(forceOrientation)
|
|
1663
1505
|
);
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
{
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1506
|
+
const [isScannerOpen, setIsScannerOpen] = useState(false);
|
|
1507
|
+
const { isFullscreen, toggleFullscreen } = useFullscreen();
|
|
1508
|
+
const { roomId, connectionStatus, gameState, controllerId, players } = useStore(
|
|
1509
|
+
store,
|
|
1510
|
+
useShallow((state) => ({
|
|
1511
|
+
roomId: state.roomId,
|
|
1512
|
+
connectionStatus: state.connectionStatus,
|
|
1513
|
+
gameState: state.gameState,
|
|
1514
|
+
controllerId: state.controllerId,
|
|
1515
|
+
players: state.players
|
|
1516
|
+
}))
|
|
1673
1517
|
);
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1518
|
+
const socket = useMemo(() => getSocket("controller"), [getSocket]);
|
|
1519
|
+
const currentPlayer = useMemo(() => {
|
|
1520
|
+
if (!controllerId) return null;
|
|
1521
|
+
const found = players.find((p) => p.id === controllerId);
|
|
1522
|
+
if (!found && connectionStatus === "connected" && players.length > 0) ;
|
|
1523
|
+
return found || null;
|
|
1524
|
+
}, [controllerId, players, connectionStatus]);
|
|
1525
|
+
const sendSystemCommand = useCallback(
|
|
1526
|
+
(command) => {
|
|
1527
|
+
const storeState = store.getState();
|
|
1528
|
+
if (!roomId || !storeState.controllerId || !socket) return;
|
|
1529
|
+
if (!socket.connected) return;
|
|
1530
|
+
const payload = controllerSystemSchema.safeParse({
|
|
1531
|
+
roomId,
|
|
1532
|
+
command
|
|
1533
|
+
});
|
|
1534
|
+
if (payload.success) {
|
|
1535
|
+
socket.emit("controller:system", payload.data);
|
|
1536
|
+
}
|
|
1537
|
+
},
|
|
1538
|
+
[roomId, socket, store]
|
|
1683
1539
|
);
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1540
|
+
const reconnect = useCallback(() => {
|
|
1541
|
+
if (!roomId) return;
|
|
1542
|
+
disconnectSocket("controller");
|
|
1543
|
+
store.getState().setRoomId(roomId);
|
|
1544
|
+
}, [roomId, disconnectSocket, store]);
|
|
1545
|
+
useEffect(() => {
|
|
1546
|
+
if (!forceOrientation) {
|
|
1547
|
+
setOrientationOk(true);
|
|
1548
|
+
return;
|
|
1692
1549
|
}
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
})
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
{
|
|
1702
|
-
"
|
|
1703
|
-
|
|
1704
|
-
|
|
1550
|
+
const media = window.matchMedia(`(orientation: ${forceOrientation})`);
|
|
1551
|
+
const handleChange = () => setOrientationOk(media.matches);
|
|
1552
|
+
handleChange();
|
|
1553
|
+
media.addEventListener("change", handleChange);
|
|
1554
|
+
return () => media.removeEventListener("change", handleChange);
|
|
1555
|
+
}, [forceOrientation]);
|
|
1556
|
+
const orientationOk = !forceOrientation ? true : isOrientationOk;
|
|
1557
|
+
const statusDotColor = useMemo(() => {
|
|
1558
|
+
switch (connectionStatus) {
|
|
1559
|
+
case "connected":
|
|
1560
|
+
return "bg-green-500";
|
|
1561
|
+
case "connecting":
|
|
1562
|
+
case "reconnecting":
|
|
1563
|
+
return "bg-yellow-500";
|
|
1564
|
+
case "disconnected":
|
|
1565
|
+
default:
|
|
1566
|
+
return "bg-red-500";
|
|
1705
1567
|
}
|
|
1706
|
-
);
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
className:
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
),
|
|
1736
|
-
...props
|
|
1737
|
-
}
|
|
1738
|
-
);
|
|
1739
|
-
}
|
|
1740
|
-
function TabsContent({
|
|
1741
|
-
className,
|
|
1742
|
-
...props
|
|
1743
|
-
}) {
|
|
1744
|
-
return /* @__PURE__ */ jsx(
|
|
1745
|
-
TabsPrimitive.Content,
|
|
1746
|
-
{
|
|
1747
|
-
"data-slot": "tabs-content",
|
|
1748
|
-
className: cn("flex-1 outline-none", className),
|
|
1749
|
-
...props
|
|
1750
|
-
}
|
|
1751
|
-
);
|
|
1752
|
-
}
|
|
1753
|
-
function Slider({
|
|
1754
|
-
className,
|
|
1755
|
-
defaultValue,
|
|
1756
|
-
value,
|
|
1757
|
-
min = 0,
|
|
1758
|
-
max = 100,
|
|
1759
|
-
...props
|
|
1760
|
-
}) {
|
|
1761
|
-
const _values = React.useMemo(
|
|
1762
|
-
() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
|
|
1763
|
-
[value, defaultValue, min, max]
|
|
1764
|
-
);
|
|
1765
|
-
return /* @__PURE__ */ jsxs(
|
|
1766
|
-
SliderPrimitive.Root,
|
|
1767
|
-
{
|
|
1768
|
-
"data-slot": "slider",
|
|
1769
|
-
defaultValue,
|
|
1770
|
-
value,
|
|
1771
|
-
min,
|
|
1772
|
-
max,
|
|
1773
|
-
className: cn(
|
|
1774
|
-
"relative flex w-full cursor-pointer touch-none items-center select-none data-disabled:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
|
|
1775
|
-
className
|
|
1776
|
-
),
|
|
1777
|
-
...props,
|
|
1778
|
-
children: [
|
|
1779
|
-
/* @__PURE__ */ jsx(
|
|
1780
|
-
SliderPrimitive.Track,
|
|
1568
|
+
}, [connectionStatus]);
|
|
1569
|
+
if (isChildMode) {
|
|
1570
|
+
return /* @__PURE__ */ jsx("div", { className: "dark", children: /* @__PURE__ */ jsx("div", { className: "text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden bg-black select-none", children: /* @__PURE__ */ jsxs("main", { className: "relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4", children: [
|
|
1571
|
+
!orientationOk && /* @__PURE__ */ jsxs("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", children: [
|
|
1572
|
+
/* @__PURE__ */ jsx("p", { className: "text-card-foreground text-xl font-semibold", children: "Rotate your device" }),
|
|
1573
|
+
/* @__PURE__ */ jsxs("p", { className: "text-muted-foreground mt-2 text-sm", children: [
|
|
1574
|
+
"This game is best experienced in ",
|
|
1575
|
+
forceOrientation,
|
|
1576
|
+
" ",
|
|
1577
|
+
"orientation."
|
|
1578
|
+
] })
|
|
1579
|
+
] }),
|
|
1580
|
+
/* @__PURE__ */ jsx(
|
|
1581
|
+
"div",
|
|
1582
|
+
{
|
|
1583
|
+
className: cn(
|
|
1584
|
+
"h-full w-full select-none",
|
|
1585
|
+
!orientationOk && "pointer-events-none opacity-30"
|
|
1586
|
+
),
|
|
1587
|
+
children
|
|
1588
|
+
}
|
|
1589
|
+
)
|
|
1590
|
+
] }) }) });
|
|
1591
|
+
}
|
|
1592
|
+
return /* @__PURE__ */ jsx("div", { className: "dark", children: /* @__PURE__ */ jsxs("div", { className: "text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden bg-black select-none", children: [
|
|
1593
|
+
/* @__PURE__ */ jsxs("header", { className: "pointer-events-none sticky top-0 z-50 flex items-center justify-between border-b px-6 py-2", children: [
|
|
1594
|
+
/* @__PURE__ */ jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
1595
|
+
typeof window !== "undefined" && (currentPlayer || controllerId) && /* @__PURE__ */ jsxs(
|
|
1596
|
+
"div",
|
|
1781
1597
|
{
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1598
|
+
className: "relative",
|
|
1599
|
+
title: describeStatus(connectionStatus),
|
|
1600
|
+
children: [
|
|
1601
|
+
currentPlayer ? /* @__PURE__ */ jsx(PlayerAvatar, { player: currentPlayer, size: "sm" }) : controllerId ? /* @__PURE__ */ jsx(
|
|
1602
|
+
PlayerAvatar,
|
|
1603
|
+
{
|
|
1604
|
+
player: {
|
|
1605
|
+
id: controllerId,
|
|
1606
|
+
label: "Player"
|
|
1607
|
+
},
|
|
1608
|
+
size: "sm"
|
|
1609
|
+
}
|
|
1610
|
+
) : null,
|
|
1611
|
+
/* @__PURE__ */ jsx(
|
|
1612
|
+
"span",
|
|
1613
|
+
{
|
|
1614
|
+
className: "absolute right-0 bottom-0 h-3 w-3 rounded-full bg-black",
|
|
1615
|
+
"aria-hidden": "true"
|
|
1616
|
+
}
|
|
1617
|
+
),
|
|
1618
|
+
/* @__PURE__ */ jsx(
|
|
1619
|
+
"span",
|
|
1620
|
+
{
|
|
1621
|
+
className: cn(
|
|
1622
|
+
"absolute right-0.5 bottom-0.5 h-2 w-2 rounded-full",
|
|
1623
|
+
statusDotColor,
|
|
1624
|
+
connectionStatus === "connected" && "animate-pulse"
|
|
1625
|
+
),
|
|
1626
|
+
"aria-label": describeStatus(connectionStatus)
|
|
1627
|
+
}
|
|
1628
|
+
)
|
|
1629
|
+
]
|
|
1630
|
+
}
|
|
1631
|
+
),
|
|
1632
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1633
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-xs tracking-[0.24em] uppercase", children: "Room" }),
|
|
1634
|
+
/* @__PURE__ */ jsx("p", { className: "text-foreground text-lg font-semibold", children: typeof window !== "undefined" ? roomId ?? "N/A" : "N/A" })
|
|
1635
|
+
] })
|
|
1636
|
+
] }),
|
|
1637
|
+
/* @__PURE__ */ jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
1638
|
+
customActions,
|
|
1639
|
+
roomId && /* @__PURE__ */ jsx(
|
|
1640
|
+
Button,
|
|
1641
|
+
{
|
|
1642
|
+
type: "button",
|
|
1643
|
+
variant: "outline",
|
|
1644
|
+
size: "icon",
|
|
1645
|
+
onClick: () => window.location.reload(),
|
|
1646
|
+
disabled: connectionStatus === "connecting" || connectionStatus === "reconnecting",
|
|
1647
|
+
"aria-label": "Reconnect",
|
|
1648
|
+
title: "Reconnect to room",
|
|
1786
1649
|
children: /* @__PURE__ */ jsx(
|
|
1787
|
-
|
|
1650
|
+
RefreshCw,
|
|
1788
1651
|
{
|
|
1789
|
-
"data-slot": "slider-range",
|
|
1790
1652
|
className: cn(
|
|
1791
|
-
"
|
|
1653
|
+
"h-5 w-5",
|
|
1654
|
+
(connectionStatus === "connecting" || connectionStatus === "reconnecting") && "animate-spin"
|
|
1792
1655
|
)
|
|
1793
1656
|
}
|
|
1794
1657
|
)
|
|
1795
1658
|
}
|
|
1796
1659
|
),
|
|
1797
|
-
|
|
1798
|
-
|
|
1660
|
+
/* @__PURE__ */ jsx(
|
|
1661
|
+
Button,
|
|
1799
1662
|
{
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
value: [masterVolume * 100],
|
|
1835
|
-
onValueChange: (values) => setMasterVolume(values[0] / 100),
|
|
1836
|
-
min: 0,
|
|
1837
|
-
max: 100,
|
|
1838
|
-
step: 1,
|
|
1839
|
-
className: "w-full",
|
|
1840
|
-
"aria-label": "Master volume"
|
|
1841
|
-
}
|
|
1842
|
-
)
|
|
1663
|
+
type: "button",
|
|
1664
|
+
variant: "outline",
|
|
1665
|
+
size: "icon",
|
|
1666
|
+
onClick: () => setIsScannerOpen(true),
|
|
1667
|
+
"aria-label": "Scan QR code to reconnect",
|
|
1668
|
+
title: "Scan QR code to reconnect",
|
|
1669
|
+
children: /* @__PURE__ */ jsx(QrCode, { className: "h-5 w-5" })
|
|
1670
|
+
}
|
|
1671
|
+
),
|
|
1672
|
+
/* @__PURE__ */ jsx(
|
|
1673
|
+
Button,
|
|
1674
|
+
{
|
|
1675
|
+
type: "button",
|
|
1676
|
+
variant: "outline",
|
|
1677
|
+
size: "icon",
|
|
1678
|
+
onClick: () => sendSystemCommand("toggle_pause"),
|
|
1679
|
+
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
1680
|
+
title: gameState === "playing" ? "Pause" : "Play",
|
|
1681
|
+
children: gameState === "playing" ? /* @__PURE__ */ jsx(Pause, { className: "h-5 w-5" }) : /* @__PURE__ */ jsx(Play, { className: "h-5 w-5" })
|
|
1682
|
+
}
|
|
1683
|
+
),
|
|
1684
|
+
/* @__PURE__ */ jsx(
|
|
1685
|
+
Button,
|
|
1686
|
+
{
|
|
1687
|
+
type: "button",
|
|
1688
|
+
variant: "outline",
|
|
1689
|
+
size: "icon",
|
|
1690
|
+
onClick: () => toggleFullscreen(),
|
|
1691
|
+
"aria-label": isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
|
|
1692
|
+
title: isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
|
|
1693
|
+
children: isFullscreen ? /* @__PURE__ */ jsx(Minimize, { className: "h-5 w-5" }) : /* @__PURE__ */ jsx(Maximize, { className: "h-5 w-5" })
|
|
1694
|
+
}
|
|
1695
|
+
)
|
|
1696
|
+
] })
|
|
1843
1697
|
] }),
|
|
1844
|
-
/* @__PURE__ */ jsxs("div", { className: "
|
|
1845
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-
|
|
1846
|
-
/* @__PURE__ */
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
"%"
|
|
1698
|
+
/* @__PURE__ */ jsx("main", { className: "relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4", children: /* @__PURE__ */ jsxs("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", children: [
|
|
1699
|
+
!orientationOk && forceOrientation && /* @__PURE__ */ jsxs("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", children: [
|
|
1700
|
+
/* @__PURE__ */ jsx("p", { className: "text-card-foreground text-xl font-semibold", children: "Rotate your device" }),
|
|
1701
|
+
/* @__PURE__ */ jsxs("p", { className: "text-muted-foreground mt-2 text-sm", children: [
|
|
1702
|
+
"This game is best experienced in ",
|
|
1703
|
+
forceOrientation,
|
|
1704
|
+
" ",
|
|
1705
|
+
"orientation."
|
|
1853
1706
|
] })
|
|
1854
1707
|
] }),
|
|
1855
1708
|
/* @__PURE__ */ jsx(
|
|
1856
|
-
|
|
1709
|
+
"div",
|
|
1857
1710
|
{
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
className: "w-full",
|
|
1864
|
-
"aria-label": "Music volume"
|
|
1711
|
+
className: cn(
|
|
1712
|
+
"h-full w-full select-none",
|
|
1713
|
+
!orientationOk && "pointer-events-none opacity-30"
|
|
1714
|
+
),
|
|
1715
|
+
children
|
|
1865
1716
|
}
|
|
1866
1717
|
)
|
|
1867
|
-
] }),
|
|
1868
|
-
/* @__PURE__ */
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
value: [sfxVolume * 100],
|
|
1883
|
-
onValueChange: (values) => setSfxVolume(values[0] / 100),
|
|
1884
|
-
min: 0,
|
|
1885
|
-
max: 100,
|
|
1886
|
-
step: 1,
|
|
1887
|
-
className: "w-full",
|
|
1888
|
-
"aria-label": "SFX volume"
|
|
1889
|
-
}
|
|
1890
|
-
)
|
|
1891
|
-
] })
|
|
1892
|
-
] });
|
|
1893
|
-
}
|
|
1894
|
-
var statusCopy = {
|
|
1895
|
-
idle: "Idle",
|
|
1896
|
-
connecting: "Waiting for server\u2026",
|
|
1897
|
-
connected: "Ready for controllers",
|
|
1898
|
-
disconnected: "Disconnected",
|
|
1899
|
-
reconnecting: "Reconnecting\u2026"
|
|
1718
|
+
] }) }),
|
|
1719
|
+
/* @__PURE__ */ jsx(
|
|
1720
|
+
QRScannerDialog,
|
|
1721
|
+
{
|
|
1722
|
+
isOpen: isScannerOpen,
|
|
1723
|
+
onClose: () => setIsScannerOpen(false),
|
|
1724
|
+
onScan: (roomCode) => {
|
|
1725
|
+
store.getState().setRoomId(roomCode);
|
|
1726
|
+
reconnect();
|
|
1727
|
+
setIsScannerOpen(false);
|
|
1728
|
+
},
|
|
1729
|
+
currentRoomId: roomId
|
|
1730
|
+
}
|
|
1731
|
+
)
|
|
1732
|
+
] }) });
|
|
1900
1733
|
};
|
|
1901
|
-
var
|
|
1902
|
-
const
|
|
1903
|
-
const {
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
}
|
|
1913
|
-
const
|
|
1914
|
-
const
|
|
1915
|
-
const
|
|
1916
|
-
const
|
|
1734
|
+
var useAirJamHost = (options = {}) => {
|
|
1735
|
+
const { config, store, getSocket, disconnectSocket, inputManager } = useAirJamContext();
|
|
1736
|
+
const arcadeParams = useMemo(() => {
|
|
1737
|
+
if (typeof window === "undefined") return null;
|
|
1738
|
+
const params = new URLSearchParams(window.location.search);
|
|
1739
|
+
const room = params.get("aj_room");
|
|
1740
|
+
const token = params.get("aj_token");
|
|
1741
|
+
if (room && token) {
|
|
1742
|
+
return { room, token };
|
|
1743
|
+
}
|
|
1744
|
+
return null;
|
|
1745
|
+
}, []);
|
|
1746
|
+
const isChildMode = !!arcadeParams;
|
|
1747
|
+
const shouldConnect = true;
|
|
1748
|
+
const storeRoomId = useStore(store, (s) => s.roomId);
|
|
1749
|
+
const parsedRoomId = useMemo(() => {
|
|
1750
|
+
if (arcadeParams) {
|
|
1751
|
+
return roomCodeSchema.parse(arcadeParams.room.toUpperCase());
|
|
1752
|
+
}
|
|
1753
|
+
if (storeRoomId) {
|
|
1754
|
+
return roomCodeSchema.parse(storeRoomId.toUpperCase());
|
|
1755
|
+
}
|
|
1756
|
+
if (typeof window !== "undefined") {
|
|
1757
|
+
const params = new URLSearchParams(window.location.search);
|
|
1758
|
+
const paramRoom = params.get("room");
|
|
1759
|
+
if (paramRoom) {
|
|
1760
|
+
const result = roomCodeSchema.safeParse(paramRoom.toUpperCase());
|
|
1761
|
+
if (result.success) return result.data;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
if (options.roomId) {
|
|
1765
|
+
return roomCodeSchema.parse(options.roomId.toUpperCase());
|
|
1766
|
+
}
|
|
1767
|
+
return null;
|
|
1768
|
+
}, [options.roomId, storeRoomId, arcadeParams]);
|
|
1769
|
+
const [joinUrl, setJoinUrl] = useState("");
|
|
1770
|
+
const onPlayerJoinRef = useRef(options.onPlayerJoin);
|
|
1771
|
+
const onPlayerLeaveRef = useRef(options.onPlayerLeave);
|
|
1772
|
+
const onChildCloseRef = useRef(options.onChildClose);
|
|
1917
1773
|
useEffect(() => {
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1774
|
+
onPlayerJoinRef.current = options.onPlayerJoin;
|
|
1775
|
+
onPlayerLeaveRef.current = options.onPlayerLeave;
|
|
1776
|
+
onChildCloseRef.current = options.onChildClose;
|
|
1777
|
+
}, [options.onPlayerJoin, options.onPlayerLeave, options.onChildClose]);
|
|
1778
|
+
const connectionState = useStore(
|
|
1779
|
+
store,
|
|
1780
|
+
useShallow((state) => ({
|
|
1781
|
+
connectionStatus: state.connectionStatus,
|
|
1782
|
+
lastError: state.lastError,
|
|
1783
|
+
players: state.players,
|
|
1784
|
+
gameState: state.gameState,
|
|
1785
|
+
mode: state.mode,
|
|
1786
|
+
roomId: state.roomId
|
|
1787
|
+
}))
|
|
1788
|
+
);
|
|
1789
|
+
const socket = useMemo(
|
|
1790
|
+
() => getSocket("host") ,
|
|
1791
|
+
[shouldConnect, getSocket]
|
|
1792
|
+
);
|
|
1793
|
+
const [lastToggle, setLastToggle] = useState(0);
|
|
1794
|
+
const toggleGameState = useCallback(() => {
|
|
1795
|
+
const now = Date.now();
|
|
1796
|
+
if (now - lastToggle < TOGGLE_DEBOUNCE_MS) {
|
|
1797
|
+
return;
|
|
1798
|
+
}
|
|
1799
|
+
setLastToggle(now);
|
|
1800
|
+
if (!socket || !socket.connected) {
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1803
|
+
if (!parsedRoomId) return;
|
|
1804
|
+
const payload = controllerSystemSchema.safeParse({
|
|
1805
|
+
roomId: parsedRoomId,
|
|
1806
|
+
command: "toggle_pause"
|
|
1807
|
+
});
|
|
1808
|
+
if (payload.success) {
|
|
1809
|
+
socket.emit("host:system", payload.data);
|
|
1810
|
+
}
|
|
1811
|
+
}, [socket, parsedRoomId, lastToggle]);
|
|
1812
|
+
const sendState = useCallback(
|
|
1813
|
+
(state) => {
|
|
1814
|
+
if (!socket || !socket.connected || !parsedRoomId) {
|
|
1815
|
+
return false;
|
|
1931
1816
|
}
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1817
|
+
const payload = controllerStateSchema.safeParse({
|
|
1818
|
+
roomId: parsedRoomId,
|
|
1819
|
+
state
|
|
1820
|
+
});
|
|
1821
|
+
if (!payload.success) {
|
|
1822
|
+
return false;
|
|
1935
1823
|
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
const
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
setCopied(true);
|
|
1946
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
1947
|
-
} catch {
|
|
1948
|
-
const textArea = document.createElement("textarea");
|
|
1949
|
-
textArea.value = joinUrl;
|
|
1950
|
-
textArea.style.position = "fixed";
|
|
1951
|
-
textArea.style.opacity = "0";
|
|
1952
|
-
document.body.appendChild(textArea);
|
|
1953
|
-
textArea.select();
|
|
1954
|
-
try {
|
|
1955
|
-
document.execCommand("copy");
|
|
1956
|
-
setCopied(true);
|
|
1957
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
1958
|
-
} catch {
|
|
1824
|
+
socket.emit("host:state", payload.data);
|
|
1825
|
+
return true;
|
|
1826
|
+
},
|
|
1827
|
+
[socket, parsedRoomId]
|
|
1828
|
+
);
|
|
1829
|
+
const sendSignal = useCallback(
|
|
1830
|
+
(type, payload, targetId) => {
|
|
1831
|
+
if (!socket || !socket.connected) {
|
|
1832
|
+
return;
|
|
1959
1833
|
}
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1834
|
+
const signal = {
|
|
1835
|
+
targetId,
|
|
1836
|
+
type,
|
|
1837
|
+
payload
|
|
1838
|
+
};
|
|
1839
|
+
socket.emit("host:signal", signal);
|
|
1840
|
+
},
|
|
1841
|
+
[socket]
|
|
1842
|
+
);
|
|
1843
|
+
const reconnect = useCallback(() => {
|
|
1844
|
+
disconnectSocket("host");
|
|
1845
|
+
if (socket) {
|
|
1846
|
+
socket.connect();
|
|
1966
1847
|
}
|
|
1967
|
-
};
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
setCopiedPlayerId(playerId);
|
|
1985
|
-
setTimeout(() => setCopiedPlayerId(null), 1e3);
|
|
1986
|
-
} catch {
|
|
1987
|
-
}
|
|
1988
|
-
document.body.removeChild(textArea);
|
|
1848
|
+
}, [socket, disconnectSocket]);
|
|
1849
|
+
useEffect(() => {
|
|
1850
|
+
if (!parsedRoomId) return;
|
|
1851
|
+
(async () => {
|
|
1852
|
+
const url = await urlBuilder.buildControllerUrl(parsedRoomId, {
|
|
1853
|
+
host: config.publicHost
|
|
1854
|
+
});
|
|
1855
|
+
setJoinUrl(url);
|
|
1856
|
+
})();
|
|
1857
|
+
}, [parsedRoomId, config.publicHost, options.roomId]);
|
|
1858
|
+
const setRegisteredRoomId = useStore(store, (s) => s.setRegisteredRoomId);
|
|
1859
|
+
useEffect(() => {
|
|
1860
|
+
const storeState = store.getState();
|
|
1861
|
+
storeState.setMode(detectRunMode());
|
|
1862
|
+
storeState.setRole("host");
|
|
1863
|
+
if (parsedRoomId) {
|
|
1864
|
+
storeState.setRoomId(parsedRoomId);
|
|
1989
1865
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
case "connecting":
|
|
1996
|
-
case "reconnecting":
|
|
1997
|
-
return "secondary";
|
|
1998
|
-
default:
|
|
1999
|
-
return "destructive";
|
|
1866
|
+
storeState.setStatus("connecting");
|
|
1867
|
+
storeState.setError(void 0);
|
|
1868
|
+
if (!socket) {
|
|
1869
|
+
storeState.setStatus("idle");
|
|
1870
|
+
return;
|
|
2000
1871
|
}
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-xs tracking-[0.18em] uppercase", children: "Room" }),
|
|
2007
|
-
/* @__PURE__ */ jsx("p", { className: "text-foreground text-lg font-semibold", children: roomId })
|
|
2008
|
-
] }) }),
|
|
2009
|
-
/* @__PURE__ */ jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
2010
|
-
players.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center -space-x-2", children: [
|
|
2011
|
-
players.slice(0, 4).map((player) => /* @__PURE__ */ jsx(PlayerAvatar, { player, size: "sm" }, player.id)),
|
|
2012
|
-
players.length > 4 && /* @__PURE__ */ jsxs("div", { className: "border-background bg-muted flex h-8 w-8 items-center justify-center rounded-full border-2 text-xs font-medium", children: [
|
|
2013
|
-
"+",
|
|
2014
|
-
players.length - 4
|
|
2015
|
-
] })
|
|
2016
|
-
] }),
|
|
2017
|
-
/* @__PURE__ */ jsx(
|
|
2018
|
-
Button,
|
|
2019
|
-
{
|
|
2020
|
-
type: "button",
|
|
2021
|
-
variant: "ghost",
|
|
2022
|
-
size: "icon",
|
|
2023
|
-
onClick: toggleGameState,
|
|
2024
|
-
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
2025
|
-
className: "h-8 w-8",
|
|
2026
|
-
children: gameState === "playing" ? /* @__PURE__ */ jsx(Pause, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(Play, { className: "h-4 w-4" })
|
|
2027
|
-
}
|
|
2028
|
-
)
|
|
2029
|
-
] })
|
|
2030
|
-
] }) }) }),
|
|
2031
|
-
gameState === "paused" && /* @__PURE__ */ jsx("div", { className: "pointer-events-none fixed inset-0 z-99998 flex items-center justify-center p-4", children: /* @__PURE__ */ jsx("div", { className: "pointer-events-auto w-full max-w-2xl", children: /* @__PURE__ */ jsx(Card, { className: "bg-card/20 flex max-h-[85vh] flex-col overflow-hidden border py-0 shadow-lg backdrop-blur-sm", children: /* @__PURE__ */ jsxs(
|
|
2032
|
-
Tabs,
|
|
2033
|
-
{
|
|
2034
|
-
defaultValue: isChildMode ? "settings" : "room-code",
|
|
2035
|
-
className: "flex h-full w-full flex-col gap-0",
|
|
2036
|
-
children: [
|
|
2037
|
-
/* @__PURE__ */ jsxs(TabsList, { className: "border-border grid w-full shrink-0 grid-cols-2 rounded-none border-b bg-transparent p-0", children: [
|
|
2038
|
-
!isChildMode && /* @__PURE__ */ jsxs(
|
|
2039
|
-
TabsTrigger,
|
|
2040
|
-
{
|
|
2041
|
-
value: "room-code",
|
|
2042
|
-
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2043
|
-
children: [
|
|
2044
|
-
/* @__PURE__ */ jsx(QrCode, { className: "h-4 w-4" }),
|
|
2045
|
-
"Room Code"
|
|
2046
|
-
]
|
|
2047
|
-
}
|
|
2048
|
-
),
|
|
2049
|
-
isChildMode && /* @__PURE__ */ jsxs(
|
|
2050
|
-
TabsTrigger,
|
|
2051
|
-
{
|
|
2052
|
-
value: "info",
|
|
2053
|
-
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2054
|
-
children: [
|
|
2055
|
-
/* @__PURE__ */ jsx(MonitorSmartphone, { className: "h-4 w-4" }),
|
|
2056
|
-
"Platform"
|
|
2057
|
-
]
|
|
2058
|
-
}
|
|
2059
|
-
),
|
|
2060
|
-
/* @__PURE__ */ jsxs(
|
|
2061
|
-
TabsTrigger,
|
|
2062
|
-
{
|
|
2063
|
-
value: "settings",
|
|
2064
|
-
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2065
|
-
children: [
|
|
2066
|
-
/* @__PURE__ */ jsx(Settings, { className: "h-4 w-4" }),
|
|
2067
|
-
"Settings"
|
|
2068
|
-
]
|
|
2069
|
-
}
|
|
2070
|
-
)
|
|
2071
|
-
] }),
|
|
2072
|
-
!isChildMode && /* @__PURE__ */ jsx(
|
|
2073
|
-
TabsContent,
|
|
2074
|
-
{
|
|
2075
|
-
value: "room-code",
|
|
2076
|
-
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2077
|
-
children: /* @__PURE__ */ jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-[auto_1fr]", children: [
|
|
2078
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-start gap-4", children: [
|
|
2079
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
2080
|
-
/* @__PURE__ */ jsx(CardTitle, { className: "text-3xl font-bold tracking-wider", children: roomId }),
|
|
2081
|
-
/* @__PURE__ */ jsx(
|
|
2082
|
-
Badge,
|
|
2083
|
-
{
|
|
2084
|
-
variant: connectionVariant,
|
|
2085
|
-
className: "w-fit",
|
|
2086
|
-
children: statusCopy[connectionStatus]
|
|
2087
|
-
}
|
|
2088
|
-
)
|
|
2089
|
-
] }),
|
|
2090
|
-
/* @__PURE__ */ jsx("div", { className: "border-border bg-card w-48 shrink-0 overflow-hidden rounded-lg border-2 shadow-md", children: qrUrl ? /* @__PURE__ */ jsx(
|
|
2091
|
-
"img",
|
|
2092
|
-
{
|
|
2093
|
-
src: qrUrl,
|
|
2094
|
-
alt: `Join room ${roomId}`,
|
|
2095
|
-
className: "w-full rounded bg-white"
|
|
2096
|
-
}
|
|
2097
|
-
) : /* @__PURE__ */ jsx("div", { className: "text-muted-foreground flex h-48 items-center justify-center text-sm", children: qrError ? `QR failed: ${qrError}` : "Generating QR code\u2026" }) })
|
|
2098
|
-
] }),
|
|
2099
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
2100
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
2101
|
-
/* @__PURE__ */ jsx(CardDescription, { className: "text-xs tracking-[0.18em] uppercase", children: "Join URL" }),
|
|
2102
|
-
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
2103
|
-
/* @__PURE__ */ jsx(
|
|
2104
|
-
"input",
|
|
2105
|
-
{
|
|
2106
|
-
type: "text",
|
|
2107
|
-
readOnly: true,
|
|
2108
|
-
value: joinUrl,
|
|
2109
|
-
className: "bg-background border-input text-foreground focus:ring-ring flex h-10 w-full rounded-md border px-3 py-2 font-mono text-xs focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50"
|
|
2110
|
-
}
|
|
2111
|
-
),
|
|
2112
|
-
/* @__PURE__ */ jsx(
|
|
2113
|
-
Button,
|
|
2114
|
-
{
|
|
2115
|
-
type: "button",
|
|
2116
|
-
variant: "outline",
|
|
2117
|
-
size: "icon",
|
|
2118
|
-
onClick: handleCopyUrl,
|
|
2119
|
-
className: "h-10 shrink-0",
|
|
2120
|
-
"aria-label": "Copy join URL",
|
|
2121
|
-
children: copied ? /* @__PURE__ */ jsx(Check, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(Copy, { className: "h-4 w-4" })
|
|
2122
|
-
}
|
|
2123
|
-
),
|
|
2124
|
-
/* @__PURE__ */ jsx(
|
|
2125
|
-
Button,
|
|
2126
|
-
{
|
|
2127
|
-
type: "button",
|
|
2128
|
-
variant: "outline",
|
|
2129
|
-
size: "icon",
|
|
2130
|
-
onClick: handleOpenInNewTab,
|
|
2131
|
-
className: "h-10 shrink-0",
|
|
2132
|
-
"aria-label": "Open join URL in new tab",
|
|
2133
|
-
children: /* @__PURE__ */ jsx(ExternalLink, { className: "h-4 w-4" })
|
|
2134
|
-
}
|
|
2135
|
-
)
|
|
2136
|
-
] })
|
|
2137
|
-
] }),
|
|
2138
|
-
/* @__PURE__ */ jsx("div", { className: "space-y-3", children: players.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-white", children: "Waiting for controllers to join\u2026" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2139
|
-
/* @__PURE__ */ jsxs("p", { className: "text-foreground text-sm font-medium", children: [
|
|
2140
|
-
"Connected Players (",
|
|
2141
|
-
players.length,
|
|
2142
|
-
")"
|
|
2143
|
-
] }),
|
|
2144
|
-
/* @__PURE__ */ jsx("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: players.map((player) => /* @__PURE__ */ jsx(
|
|
2145
|
-
"li",
|
|
2146
|
-
{
|
|
2147
|
-
className: "flex min-w-0 flex-col items-start gap-2",
|
|
2148
|
-
children: /* @__PURE__ */ jsxs("div", { className: "flex w-full min-w-0 items-center gap-2", children: [
|
|
2149
|
-
/* @__PURE__ */ jsx(
|
|
2150
|
-
PlayerAvatar,
|
|
2151
|
-
{
|
|
2152
|
-
player,
|
|
2153
|
-
size: "md"
|
|
2154
|
-
}
|
|
2155
|
-
),
|
|
2156
|
-
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5 overflow-hidden", children: [
|
|
2157
|
-
/* @__PURE__ */ jsx("span", { className: "text-card-foreground truncate text-sm font-medium", children: player.label }),
|
|
2158
|
-
/* @__PURE__ */ jsx(
|
|
2159
|
-
"div",
|
|
2160
|
-
{
|
|
2161
|
-
onClick: () => handleCopyPlayerId(player.id),
|
|
2162
|
-
className: "text-muted-foreground m-0 inline min-w-0 cursor-pointer truncate border-0 font-mono text-xs transition-colors hover:text-white",
|
|
2163
|
-
title: "Click to copy player ID",
|
|
2164
|
-
children: copiedPlayerId === player.id ? "Copied!" : player.id.slice(0, 8)
|
|
2165
|
-
}
|
|
2166
|
-
)
|
|
2167
|
-
] })
|
|
2168
|
-
] })
|
|
2169
|
-
},
|
|
2170
|
-
player.id
|
|
2171
|
-
)) })
|
|
2172
|
-
] }) }),
|
|
2173
|
-
lastError && /* @__PURE__ */ jsx(Alert, { variant: "destructive", className: "w-full", children: /* @__PURE__ */ jsx(AlertDescription, { children: lastError }) }),
|
|
2174
|
-
/* @__PURE__ */ jsx("div", { className: "mt-auto flex justify-end", children: /* @__PURE__ */ jsxs(
|
|
2175
|
-
Button,
|
|
2176
|
-
{
|
|
2177
|
-
type: "button",
|
|
2178
|
-
onClick: toggleGameState,
|
|
2179
|
-
size: "lg",
|
|
2180
|
-
children: [
|
|
2181
|
-
/* @__PURE__ */ jsx(Play, { className: "mr-2 h-5 w-5" }),
|
|
2182
|
-
"Start Game"
|
|
2183
|
-
]
|
|
2184
|
-
}
|
|
2185
|
-
) })
|
|
2186
|
-
] })
|
|
2187
|
-
] }) })
|
|
2188
|
-
}
|
|
2189
|
-
),
|
|
2190
|
-
isChildMode && /* @__PURE__ */ jsx(
|
|
2191
|
-
TabsContent,
|
|
2192
|
-
{
|
|
2193
|
-
value: "info",
|
|
2194
|
-
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2195
|
-
children: /* @__PURE__ */ jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
2196
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
2197
|
-
/* @__PURE__ */ jsx(CardTitle, { className: "text-2xl font-bold tracking-wider", children: "Connected to Platform" }),
|
|
2198
|
-
/* @__PURE__ */ jsx(CardDescription, { children: "This game is running inside the Air Jam Platform." })
|
|
2199
|
-
] }),
|
|
2200
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
2201
|
-
/* @__PURE__ */ jsxs("p", { className: "text-foreground text-sm font-medium", children: [
|
|
2202
|
-
"Connected Players (",
|
|
2203
|
-
players.length,
|
|
2204
|
-
")"
|
|
2205
|
-
] }),
|
|
2206
|
-
/* @__PURE__ */ jsx("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: players.map((player) => /* @__PURE__ */ jsx(
|
|
2207
|
-
"li",
|
|
2208
|
-
{
|
|
2209
|
-
className: "flex min-w-0 flex-col items-start gap-2",
|
|
2210
|
-
children: /* @__PURE__ */ jsxs("div", { className: "flex w-full min-w-0 items-center gap-2", children: [
|
|
2211
|
-
/* @__PURE__ */ jsx(PlayerAvatar, { player, size: "md" }),
|
|
2212
|
-
/* @__PURE__ */ jsx("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5 overflow-hidden", children: /* @__PURE__ */ jsx("span", { className: "text-card-foreground truncate text-sm font-medium", children: player.label }) })
|
|
2213
|
-
] })
|
|
2214
|
-
},
|
|
2215
|
-
player.id
|
|
2216
|
-
)) })
|
|
2217
|
-
] }),
|
|
2218
|
-
/* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsxs(
|
|
2219
|
-
Button,
|
|
2220
|
-
{
|
|
2221
|
-
type: "button",
|
|
2222
|
-
onClick: toggleGameState,
|
|
2223
|
-
size: "lg",
|
|
2224
|
-
children: [
|
|
2225
|
-
/* @__PURE__ */ jsx(Play, { className: "mr-2 h-5 w-5" }),
|
|
2226
|
-
"Resume Game"
|
|
2227
|
-
]
|
|
2228
|
-
}
|
|
2229
|
-
) })
|
|
2230
|
-
] }) })
|
|
2231
|
-
}
|
|
2232
|
-
),
|
|
2233
|
-
/* @__PURE__ */ jsx(
|
|
2234
|
-
TabsContent,
|
|
2235
|
-
{
|
|
2236
|
-
value: "settings",
|
|
2237
|
-
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2238
|
-
children: /* @__PURE__ */ jsx(CardContent, { className: "pt-6 pb-6", children: /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
2239
|
-
/* @__PURE__ */ jsx("div", { className: "space-y-4", children: /* @__PURE__ */ jsx(VolumeControls, {}) }),
|
|
2240
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
2241
|
-
/* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", children: "Connection" }),
|
|
2242
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
2243
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2244
|
-
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: "Status" }),
|
|
2245
|
-
/* @__PURE__ */ jsx(Badge, { variant: connectionVariant, children: statusCopy[connectionStatus] })
|
|
2246
|
-
] }),
|
|
2247
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2248
|
-
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: "Room ID" }),
|
|
2249
|
-
/* @__PURE__ */ jsx("span", { className: "font-mono text-sm", children: roomId })
|
|
2250
|
-
] }),
|
|
2251
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2252
|
-
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: "Players" }),
|
|
2253
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: players.length })
|
|
2254
|
-
] })
|
|
2255
|
-
] })
|
|
2256
|
-
] }),
|
|
2257
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
2258
|
-
/* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", children: "Display" }),
|
|
2259
|
-
/* @__PURE__ */ jsx("div", { className: "space-y-2", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2260
|
-
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: "Game State" }),
|
|
2261
|
-
/* @__PURE__ */ jsx(Badge, { variant: "outline", className: "capitalize", children: gameState })
|
|
2262
|
-
] }) })
|
|
2263
|
-
] })
|
|
2264
|
-
] }) })
|
|
2265
|
-
}
|
|
2266
|
-
)
|
|
2267
|
-
]
|
|
2268
|
-
}
|
|
2269
|
-
) }) }) })
|
|
2270
|
-
] });
|
|
2271
|
-
};
|
|
2272
|
-
var useFullscreen = () => {
|
|
2273
|
-
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
2274
|
-
useEffect(() => {
|
|
2275
|
-
const handleFullscreenChange = () => {
|
|
2276
|
-
const doc = document;
|
|
2277
|
-
setIsFullscreen(
|
|
2278
|
-
!!(document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement)
|
|
2279
|
-
);
|
|
2280
|
-
};
|
|
2281
|
-
document.addEventListener("fullscreenchange", handleFullscreenChange);
|
|
2282
|
-
document.addEventListener("webkitfullscreenchange", handleFullscreenChange);
|
|
2283
|
-
document.addEventListener("mozfullscreenchange", handleFullscreenChange);
|
|
2284
|
-
document.addEventListener("msfullscreenchange", handleFullscreenChange);
|
|
2285
|
-
return () => {
|
|
2286
|
-
document.removeEventListener("fullscreenchange", handleFullscreenChange);
|
|
2287
|
-
document.removeEventListener(
|
|
2288
|
-
"webkitfullscreenchange",
|
|
2289
|
-
handleFullscreenChange
|
|
2290
|
-
);
|
|
2291
|
-
document.removeEventListener(
|
|
2292
|
-
"mozfullscreenchange",
|
|
2293
|
-
handleFullscreenChange
|
|
2294
|
-
);
|
|
2295
|
-
document.removeEventListener(
|
|
2296
|
-
"msfullscreenchange",
|
|
2297
|
-
handleFullscreenChange
|
|
2298
|
-
);
|
|
2299
|
-
};
|
|
2300
|
-
}, []);
|
|
2301
|
-
const exitFullscreen = useCallback(async () => {
|
|
2302
|
-
try {
|
|
2303
|
-
const doc = document;
|
|
2304
|
-
if (document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement) {
|
|
2305
|
-
if (document.exitFullscreen) {
|
|
2306
|
-
await document.exitFullscreen();
|
|
2307
|
-
} else if (doc.webkitExitFullscreen) {
|
|
2308
|
-
await doc.webkitExitFullscreen();
|
|
2309
|
-
} else if (doc.mozCancelFullScreen) {
|
|
2310
|
-
await doc.mozCancelFullScreen();
|
|
2311
|
-
} else if (doc.msExitFullscreen) {
|
|
2312
|
-
await doc.msExitFullscreen();
|
|
2313
|
-
}
|
|
2314
|
-
}
|
|
2315
|
-
} catch (error) {
|
|
2316
|
-
console.error("Error exiting fullscreen:", error);
|
|
2317
|
-
}
|
|
2318
|
-
}, []);
|
|
2319
|
-
const enterFullscreen = useCallback(async (element) => {
|
|
2320
|
-
try {
|
|
2321
|
-
const elem = element || document.documentElement;
|
|
2322
|
-
if (elem.requestFullscreen) {
|
|
2323
|
-
await elem.requestFullscreen();
|
|
2324
|
-
} else if (elem.webkitRequestFullscreen) {
|
|
2325
|
-
await elem.webkitRequestFullscreen();
|
|
2326
|
-
} else if (elem.mozRequestFullScreen) {
|
|
2327
|
-
await elem.mozRequestFullScreen();
|
|
2328
|
-
} else if (elem.msRequestFullscreen) {
|
|
2329
|
-
await elem.msRequestFullscreen();
|
|
2330
|
-
}
|
|
2331
|
-
} catch (error) {
|
|
2332
|
-
console.error("Error entering fullscreen:", error);
|
|
2333
|
-
}
|
|
2334
|
-
}, []);
|
|
2335
|
-
const toggleFullscreen = useCallback(
|
|
2336
|
-
async (element) => {
|
|
2337
|
-
if (isFullscreen) {
|
|
2338
|
-
await exitFullscreen();
|
|
2339
|
-
} else {
|
|
2340
|
-
await enterFullscreen(element);
|
|
2341
|
-
}
|
|
2342
|
-
},
|
|
2343
|
-
[isFullscreen, exitFullscreen, enterFullscreen]
|
|
2344
|
-
);
|
|
2345
|
-
return {
|
|
2346
|
-
isFullscreen,
|
|
2347
|
-
enterFullscreen,
|
|
2348
|
-
exitFullscreen,
|
|
2349
|
-
toggleFullscreen
|
|
2350
|
-
};
|
|
2351
|
-
};
|
|
2352
|
-
var extractRoomCode = (text) => {
|
|
2353
|
-
try {
|
|
2354
|
-
const url = new URL(text);
|
|
2355
|
-
const roomParam = url.searchParams.get("room");
|
|
2356
|
-
if (roomParam) {
|
|
2357
|
-
const parsed2 = roomCodeSchema.safeParse(roomParam.toUpperCase());
|
|
2358
|
-
if (parsed2.success) {
|
|
2359
|
-
return parsed2.data;
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
} catch {
|
|
2363
|
-
}
|
|
2364
|
-
const parsed = roomCodeSchema.safeParse(text.trim().toUpperCase());
|
|
2365
|
-
if (parsed.success) {
|
|
2366
|
-
return parsed.data;
|
|
2367
|
-
}
|
|
2368
|
-
return null;
|
|
2369
|
-
};
|
|
2370
|
-
var QRScannerDialog = ({
|
|
2371
|
-
isOpen,
|
|
2372
|
-
onClose,
|
|
2373
|
-
onScan,
|
|
2374
|
-
currentRoomId
|
|
2375
|
-
}) => {
|
|
2376
|
-
const [code, setCode] = useState("");
|
|
2377
|
-
const [isCameraAvailable, setIsCameraAvailable] = useState(false);
|
|
2378
|
-
const [joinUrl, setJoinUrl] = useState("");
|
|
2379
|
-
const [copied, setCopied] = useState(false);
|
|
2380
|
-
const scannerRef = useRef(null);
|
|
2381
|
-
const inputRef = useRef(null);
|
|
2382
|
-
const prevIsOpenRef = useRef(false);
|
|
2383
|
-
useEffect(() => {
|
|
2384
|
-
if (isOpen && !prevIsOpenRef.current) {
|
|
2385
|
-
const initialCode = currentRoomId || "";
|
|
2386
|
-
setTimeout(() => {
|
|
2387
|
-
setIsCameraAvailable(false);
|
|
2388
|
-
setCode(initialCode);
|
|
2389
|
-
inputRef.current?.focus();
|
|
2390
|
-
inputRef.current?.select();
|
|
2391
|
-
}, 0);
|
|
2392
|
-
}
|
|
2393
|
-
prevIsOpenRef.current = isOpen;
|
|
2394
|
-
}, [isOpen, currentRoomId]);
|
|
2395
|
-
useEffect(() => {
|
|
2396
|
-
const buildUrl = async () => {
|
|
2397
|
-
const trimmed = code.trim().toUpperCase();
|
|
2398
|
-
const parsed = roomCodeSchema.safeParse(trimmed);
|
|
2399
|
-
if (parsed.success) {
|
|
2400
|
-
try {
|
|
2401
|
-
const url = await urlBuilder.buildControllerUrl(parsed.data);
|
|
2402
|
-
setJoinUrl(url);
|
|
2403
|
-
} catch {
|
|
2404
|
-
setJoinUrl("");
|
|
2405
|
-
}
|
|
2406
|
-
} else {
|
|
2407
|
-
setJoinUrl("");
|
|
1872
|
+
const registerHost = async () => {
|
|
1873
|
+
const storeState2 = store.getState();
|
|
1874
|
+
const currentRegisteredRoomId2 = store.getState().registeredRoomId;
|
|
1875
|
+
if (currentRegisteredRoomId2 && socket.connected) {
|
|
1876
|
+
return;
|
|
2408
1877
|
}
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
} catch {
|
|
1878
|
+
if (arcadeParams) {
|
|
1879
|
+
const childRoomId = roomCodeSchema.parse(
|
|
1880
|
+
arcadeParams.room.toUpperCase()
|
|
1881
|
+
);
|
|
1882
|
+
const payload = {
|
|
1883
|
+
roomId: childRoomId,
|
|
1884
|
+
joinToken: arcadeParams.token
|
|
1885
|
+
};
|
|
1886
|
+
socket.emit("host:joinAsChild", payload, (ack) => {
|
|
1887
|
+
if (!ack.ok) {
|
|
1888
|
+
storeState2.setError(ack.message ?? "Failed to join as child");
|
|
1889
|
+
storeState2.setStatus("disconnected");
|
|
1890
|
+
setRegisteredRoomId(null);
|
|
1891
|
+
return;
|
|
2424
1892
|
}
|
|
1893
|
+
storeState2.setStatus("connected");
|
|
1894
|
+
storeState2.setRoomId(childRoomId);
|
|
1895
|
+
setRegisteredRoomId(childRoomId);
|
|
2425
1896
|
});
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
const label = d.label.toLowerCase();
|
|
2459
|
-
return label.includes("environment") || label.includes("facing back");
|
|
1897
|
+
} else {
|
|
1898
|
+
const createNewRoom = () => {
|
|
1899
|
+
const payload = hostCreateRoomSchema.parse({
|
|
1900
|
+
maxPlayers: options.maxPlayers ?? config.maxPlayers,
|
|
1901
|
+
apiKey: options.apiKey ?? config.apiKey
|
|
1902
|
+
});
|
|
1903
|
+
socket.emit("host:createRoom", payload, (ack) => {
|
|
1904
|
+
if (!ack.ok) {
|
|
1905
|
+
storeState2.setError(ack.message ?? "Failed to create room");
|
|
1906
|
+
storeState2.setStatus("disconnected");
|
|
1907
|
+
setRegisteredRoomId(null);
|
|
1908
|
+
return;
|
|
1909
|
+
}
|
|
1910
|
+
if (ack.roomId) {
|
|
1911
|
+
storeState2.setStatus("connected");
|
|
1912
|
+
storeState2.setRoomId(ack.roomId);
|
|
1913
|
+
setRegisteredRoomId(ack.roomId);
|
|
1914
|
+
if (typeof window !== "undefined") {
|
|
1915
|
+
sessionStorage.setItem("airjam_room_id", ack.roomId);
|
|
1916
|
+
}
|
|
1917
|
+
} else {
|
|
1918
|
+
storeState2.setError("Server did not return room ID");
|
|
1919
|
+
storeState2.setStatus("disconnected");
|
|
1920
|
+
}
|
|
1921
|
+
});
|
|
1922
|
+
};
|
|
1923
|
+
if (typeof window !== "undefined") {
|
|
1924
|
+
const savedRoomId = sessionStorage.getItem("airjam_room_id");
|
|
1925
|
+
if (savedRoomId) {
|
|
1926
|
+
const reconnectPayload = hostReconnectSchema.parse({
|
|
1927
|
+
roomId: savedRoomId,
|
|
1928
|
+
apiKey: options.apiKey ?? config.apiKey
|
|
2460
1929
|
});
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
fps: 10,
|
|
2470
|
-
qrbox: (viewfinderWidth, viewfinderHeight) => {
|
|
2471
|
-
const minEdge = Math.min(viewfinderWidth, viewfinderHeight);
|
|
2472
|
-
const qrboxSize = Math.min(250, minEdge * 0.8);
|
|
2473
|
-
return {
|
|
2474
|
-
width: qrboxSize,
|
|
2475
|
-
height: qrboxSize
|
|
2476
|
-
};
|
|
2477
|
-
},
|
|
2478
|
-
aspectRatio: 1
|
|
2479
|
-
},
|
|
2480
|
-
(decodedText) => {
|
|
2481
|
-
if (!mounted) return;
|
|
2482
|
-
const roomCode = extractRoomCode(decodedText);
|
|
2483
|
-
if (roomCode) {
|
|
2484
|
-
setCode(roomCode);
|
|
2485
|
-
scannerRunning = false;
|
|
2486
|
-
scanner?.stop().catch(() => {
|
|
2487
|
-
}).finally(() => {
|
|
2488
|
-
if (mounted) {
|
|
2489
|
-
setIsCameraAvailable(false);
|
|
1930
|
+
socket.emit("host:reconnect", reconnectPayload, (ack) => {
|
|
1931
|
+
if (ack.ok && ack.roomId) {
|
|
1932
|
+
storeState2.setStatus("connected");
|
|
1933
|
+
storeState2.setRoomId(ack.roomId);
|
|
1934
|
+
setRegisteredRoomId(ack.roomId);
|
|
1935
|
+
} else {
|
|
1936
|
+
if (typeof window !== "undefined") {
|
|
1937
|
+
sessionStorage.removeItem("airjam_room_id");
|
|
2490
1938
|
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
);
|
|
2497
|
-
scannerRunning = true;
|
|
2498
|
-
if (mounted) {
|
|
2499
|
-
setIsCameraAvailable(true);
|
|
2500
|
-
}
|
|
2501
|
-
} catch {
|
|
2502
|
-
if (mounted) {
|
|
2503
|
-
setIsCameraAvailable(false);
|
|
2504
|
-
}
|
|
2505
|
-
if (scanner) {
|
|
2506
|
-
try {
|
|
2507
|
-
scanner.clear();
|
|
2508
|
-
} catch {
|
|
1939
|
+
createNewRoom();
|
|
1940
|
+
}
|
|
1941
|
+
});
|
|
1942
|
+
} else {
|
|
1943
|
+
createNewRoom();
|
|
2509
1944
|
}
|
|
1945
|
+
} else {
|
|
1946
|
+
createNewRoom();
|
|
2510
1947
|
}
|
|
2511
|
-
scannerRef.current = null;
|
|
2512
1948
|
}
|
|
2513
1949
|
};
|
|
2514
|
-
const
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
1950
|
+
const handleConnect = () => {
|
|
1951
|
+
store.getState().setStatus("connected");
|
|
1952
|
+
registerHost();
|
|
1953
|
+
};
|
|
1954
|
+
const handleDisconnect = () => {
|
|
1955
|
+
store.getState().setStatus("disconnected");
|
|
1956
|
+
};
|
|
1957
|
+
const handleJoin = (payload) => {
|
|
1958
|
+
if (payload.player) {
|
|
1959
|
+
store.getState().upsertPlayer(payload.player);
|
|
1960
|
+
setTimeout(() => {
|
|
1961
|
+
onPlayerJoinRef.current?.(payload.player);
|
|
1962
|
+
}, 0);
|
|
1963
|
+
}
|
|
1964
|
+
};
|
|
1965
|
+
const handleLeave = (payload) => {
|
|
1966
|
+
store.getState().removePlayer(payload.controllerId);
|
|
1967
|
+
onPlayerLeaveRef.current?.(payload.controllerId);
|
|
1968
|
+
};
|
|
1969
|
+
const handleInput = (payload) => {
|
|
1970
|
+
if (inputManager) {
|
|
1971
|
+
inputManager.handleInput(payload);
|
|
2533
1972
|
}
|
|
2534
|
-
scannerRef.current = null;
|
|
2535
1973
|
};
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
const
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
1974
|
+
const handleChildClose = () => {
|
|
1975
|
+
onChildCloseRef.current?.();
|
|
1976
|
+
};
|
|
1977
|
+
const handleState = (payload) => {
|
|
1978
|
+
if (!parsedRoomId || payload.roomId !== parsedRoomId) return;
|
|
1979
|
+
const storeState2 = store.getState();
|
|
1980
|
+
if (payload.state.gameState) {
|
|
1981
|
+
storeState2.setGameState(payload.state.gameState);
|
|
1982
|
+
}
|
|
1983
|
+
if (payload.state.message !== void 0) {
|
|
1984
|
+
storeState2.setStateMessage(payload.state.message);
|
|
1985
|
+
}
|
|
1986
|
+
};
|
|
1987
|
+
const handleError = (payload) => {
|
|
1988
|
+
store.getState().setError(payload.message);
|
|
1989
|
+
};
|
|
1990
|
+
socket.on("connect", handleConnect);
|
|
1991
|
+
socket.on("disconnect", handleDisconnect);
|
|
1992
|
+
socket.on("server:controllerJoined", handleJoin);
|
|
1993
|
+
socket.on("server:controllerLeft", handleLeave);
|
|
1994
|
+
socket.on("server:input", handleInput);
|
|
1995
|
+
socket.on("server:error", handleError);
|
|
1996
|
+
socket.on("server:closeChild", handleChildClose);
|
|
1997
|
+
socket.on("server:state", handleState);
|
|
1998
|
+
socket.connect();
|
|
1999
|
+
const currentRegisteredRoomId = store.getState().registeredRoomId;
|
|
2000
|
+
if (socket.connected && !currentRegisteredRoomId) {
|
|
2001
|
+
registerHost();
|
|
2543
2002
|
}
|
|
2003
|
+
return () => {
|
|
2004
|
+
socket.off("connect", handleConnect);
|
|
2005
|
+
socket.off("disconnect", handleDisconnect);
|
|
2006
|
+
socket.off("server:controllerJoined", handleJoin);
|
|
2007
|
+
socket.off("server:controllerLeft", handleLeave);
|
|
2008
|
+
socket.off("server:input", handleInput);
|
|
2009
|
+
socket.off("server:error", handleError);
|
|
2010
|
+
socket.off("server:closeChild", handleChildClose);
|
|
2011
|
+
socket.off("server:state", handleState);
|
|
2012
|
+
};
|
|
2013
|
+
}, [
|
|
2014
|
+
config.maxPlayers,
|
|
2015
|
+
config.apiKey,
|
|
2016
|
+
options.maxPlayers,
|
|
2017
|
+
options.apiKey,
|
|
2018
|
+
arcadeParams,
|
|
2019
|
+
parsedRoomId,
|
|
2020
|
+
// Include parsedRoomId since it's used in handleState callback
|
|
2021
|
+
shouldConnect,
|
|
2022
|
+
socket,
|
|
2023
|
+
store,
|
|
2024
|
+
inputManager,
|
|
2025
|
+
setRegisteredRoomId
|
|
2026
|
+
]);
|
|
2027
|
+
const returnSocket = socket ?? getSocket("host");
|
|
2028
|
+
const getInput = useCallback(
|
|
2029
|
+
(controllerId) => {
|
|
2030
|
+
if (!inputManager) {
|
|
2031
|
+
return void 0;
|
|
2032
|
+
}
|
|
2033
|
+
return inputManager.getInput(controllerId);
|
|
2034
|
+
},
|
|
2035
|
+
[inputManager]
|
|
2036
|
+
);
|
|
2037
|
+
return {
|
|
2038
|
+
roomId: parsedRoomId ?? "",
|
|
2039
|
+
// Return empty string as fallback if not yet available
|
|
2040
|
+
joinUrl,
|
|
2041
|
+
connectionStatus: connectionState.connectionStatus,
|
|
2042
|
+
players: connectionState.players,
|
|
2043
|
+
lastError: connectionState.lastError,
|
|
2044
|
+
mode: connectionState.mode,
|
|
2045
|
+
gameState: connectionState.gameState,
|
|
2046
|
+
toggleGameState,
|
|
2047
|
+
sendState,
|
|
2048
|
+
sendSignal,
|
|
2049
|
+
reconnect,
|
|
2050
|
+
socket: returnSocket,
|
|
2051
|
+
isChildMode,
|
|
2052
|
+
getInput
|
|
2544
2053
|
};
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
if (!joinUrl) return;
|
|
2554
|
-
try {
|
|
2555
|
-
await navigator.clipboard.writeText(joinUrl);
|
|
2556
|
-
setCopied(true);
|
|
2557
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
2558
|
-
} catch {
|
|
2559
|
-
const textArea = document.createElement("textarea");
|
|
2560
|
-
textArea.value = joinUrl;
|
|
2561
|
-
textArea.style.position = "fixed";
|
|
2562
|
-
textArea.style.opacity = "0";
|
|
2563
|
-
document.body.appendChild(textArea);
|
|
2564
|
-
textArea.select();
|
|
2565
|
-
try {
|
|
2566
|
-
document.execCommand("copy");
|
|
2567
|
-
setCopied(true);
|
|
2568
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
2569
|
-
} catch {
|
|
2054
|
+
};
|
|
2055
|
+
var alertVariants = cva(
|
|
2056
|
+
"relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
|
|
2057
|
+
{
|
|
2058
|
+
variants: {
|
|
2059
|
+
variant: {
|
|
2060
|
+
default: "bg-card text-card-foreground",
|
|
2061
|
+
destructive: "text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"
|
|
2570
2062
|
}
|
|
2571
|
-
|
|
2063
|
+
},
|
|
2064
|
+
defaultVariants: {
|
|
2065
|
+
variant: "default"
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
);
|
|
2069
|
+
function Alert({
|
|
2070
|
+
className,
|
|
2071
|
+
variant,
|
|
2072
|
+
...props
|
|
2073
|
+
}) {
|
|
2074
|
+
return /* @__PURE__ */ jsx(
|
|
2075
|
+
"div",
|
|
2076
|
+
{
|
|
2077
|
+
"data-slot": "alert",
|
|
2078
|
+
role: "alert",
|
|
2079
|
+
className: cn(alertVariants({ variant }), className),
|
|
2080
|
+
...props
|
|
2081
|
+
}
|
|
2082
|
+
);
|
|
2083
|
+
}
|
|
2084
|
+
function AlertDescription({
|
|
2085
|
+
className,
|
|
2086
|
+
...props
|
|
2087
|
+
}) {
|
|
2088
|
+
return /* @__PURE__ */ jsx(
|
|
2089
|
+
"div",
|
|
2090
|
+
{
|
|
2091
|
+
"data-slot": "alert-description",
|
|
2092
|
+
className: cn(
|
|
2093
|
+
"text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",
|
|
2094
|
+
className
|
|
2095
|
+
),
|
|
2096
|
+
...props
|
|
2097
|
+
}
|
|
2098
|
+
);
|
|
2099
|
+
}
|
|
2100
|
+
var badgeVariants = cva(
|
|
2101
|
+
"inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
|
2102
|
+
{
|
|
2103
|
+
variants: {
|
|
2104
|
+
variant: {
|
|
2105
|
+
default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
|
2106
|
+
secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
|
2107
|
+
destructive: "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
2108
|
+
outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
|
|
2109
|
+
}
|
|
2110
|
+
},
|
|
2111
|
+
defaultVariants: {
|
|
2112
|
+
variant: "default"
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
);
|
|
2116
|
+
function Badge({
|
|
2117
|
+
className,
|
|
2118
|
+
variant,
|
|
2119
|
+
asChild = false,
|
|
2120
|
+
...props
|
|
2121
|
+
}) {
|
|
2122
|
+
const Comp = asChild ? Slot : "span";
|
|
2123
|
+
return /* @__PURE__ */ jsx(
|
|
2124
|
+
Comp,
|
|
2125
|
+
{
|
|
2126
|
+
"data-slot": "badge",
|
|
2127
|
+
className: cn(badgeVariants({ variant }), className),
|
|
2128
|
+
...props
|
|
2129
|
+
}
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
function Card({ className, ...props }) {
|
|
2133
|
+
return /* @__PURE__ */ jsx(
|
|
2134
|
+
"div",
|
|
2135
|
+
{
|
|
2136
|
+
"data-slot": "card",
|
|
2137
|
+
className: cn(
|
|
2138
|
+
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
|
2139
|
+
className
|
|
2140
|
+
),
|
|
2141
|
+
...props
|
|
2142
|
+
}
|
|
2143
|
+
);
|
|
2144
|
+
}
|
|
2145
|
+
function CardTitle({ className, ...props }) {
|
|
2146
|
+
return /* @__PURE__ */ jsx(
|
|
2147
|
+
"div",
|
|
2148
|
+
{
|
|
2149
|
+
"data-slot": "card-title",
|
|
2150
|
+
className: cn("leading-none font-semibold", className),
|
|
2151
|
+
...props
|
|
2152
|
+
}
|
|
2153
|
+
);
|
|
2154
|
+
}
|
|
2155
|
+
function CardDescription({ className, ...props }) {
|
|
2156
|
+
return /* @__PURE__ */ jsx(
|
|
2157
|
+
"div",
|
|
2158
|
+
{
|
|
2159
|
+
"data-slot": "card-description",
|
|
2160
|
+
className: cn("text-muted-foreground text-sm", className),
|
|
2161
|
+
...props
|
|
2162
|
+
}
|
|
2163
|
+
);
|
|
2164
|
+
}
|
|
2165
|
+
function CardContent({ className, ...props }) {
|
|
2166
|
+
return /* @__PURE__ */ jsx(
|
|
2167
|
+
"div",
|
|
2168
|
+
{
|
|
2169
|
+
"data-slot": "card-content",
|
|
2170
|
+
className: cn("px-6", className),
|
|
2171
|
+
...props
|
|
2172
|
+
}
|
|
2173
|
+
);
|
|
2174
|
+
}
|
|
2175
|
+
function Tabs({
|
|
2176
|
+
className,
|
|
2177
|
+
...props
|
|
2178
|
+
}) {
|
|
2179
|
+
return /* @__PURE__ */ jsx(
|
|
2180
|
+
TabsPrimitive.Root,
|
|
2181
|
+
{
|
|
2182
|
+
"data-slot": "tabs",
|
|
2183
|
+
className: cn("flex flex-col gap-2", className),
|
|
2184
|
+
...props
|
|
2185
|
+
}
|
|
2186
|
+
);
|
|
2187
|
+
}
|
|
2188
|
+
function TabsList({
|
|
2189
|
+
className,
|
|
2190
|
+
...props
|
|
2191
|
+
}) {
|
|
2192
|
+
return /* @__PURE__ */ jsx(
|
|
2193
|
+
TabsPrimitive.List,
|
|
2194
|
+
{
|
|
2195
|
+
"data-slot": "tabs-list",
|
|
2196
|
+
className: cn(
|
|
2197
|
+
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
|
2198
|
+
className
|
|
2199
|
+
),
|
|
2200
|
+
...props
|
|
2572
2201
|
}
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
)
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2202
|
+
);
|
|
2203
|
+
}
|
|
2204
|
+
function TabsTrigger({
|
|
2205
|
+
className,
|
|
2206
|
+
...props
|
|
2207
|
+
}) {
|
|
2208
|
+
return /* @__PURE__ */ jsx(
|
|
2209
|
+
TabsPrimitive.Trigger,
|
|
2210
|
+
{
|
|
2211
|
+
"data-slot": "tabs-trigger",
|
|
2212
|
+
className: cn(
|
|
2213
|
+
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
2214
|
+
className
|
|
2215
|
+
),
|
|
2216
|
+
...props
|
|
2217
|
+
}
|
|
2218
|
+
);
|
|
2219
|
+
}
|
|
2220
|
+
function TabsContent({
|
|
2221
|
+
className,
|
|
2222
|
+
...props
|
|
2223
|
+
}) {
|
|
2224
|
+
return /* @__PURE__ */ jsx(
|
|
2225
|
+
TabsPrimitive.Content,
|
|
2226
|
+
{
|
|
2227
|
+
"data-slot": "tabs-content",
|
|
2228
|
+
className: cn("flex-1 outline-none", className),
|
|
2229
|
+
...props
|
|
2230
|
+
}
|
|
2231
|
+
);
|
|
2232
|
+
}
|
|
2233
|
+
function Slider({
|
|
2234
|
+
className,
|
|
2235
|
+
defaultValue,
|
|
2236
|
+
value,
|
|
2237
|
+
min = 0,
|
|
2238
|
+
max = 100,
|
|
2239
|
+
...props
|
|
2240
|
+
}) {
|
|
2241
|
+
const _values = React.useMemo(
|
|
2242
|
+
() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
|
|
2243
|
+
[value, defaultValue, min, max]
|
|
2244
|
+
);
|
|
2245
|
+
return /* @__PURE__ */ jsxs(
|
|
2246
|
+
SliderPrimitive.Root,
|
|
2247
|
+
{
|
|
2248
|
+
"data-slot": "slider",
|
|
2249
|
+
defaultValue,
|
|
2250
|
+
value,
|
|
2251
|
+
min,
|
|
2252
|
+
max,
|
|
2253
|
+
className: cn(
|
|
2254
|
+
"relative flex w-full cursor-pointer touch-none items-center select-none data-disabled:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
|
|
2255
|
+
className
|
|
2256
|
+
),
|
|
2257
|
+
...props,
|
|
2258
|
+
children: [
|
|
2259
|
+
/* @__PURE__ */ jsx(
|
|
2260
|
+
SliderPrimitive.Track,
|
|
2261
|
+
{
|
|
2262
|
+
"data-slot": "slider-track",
|
|
2263
|
+
className: cn(
|
|
2264
|
+
"bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"
|
|
2265
|
+
),
|
|
2266
|
+
children: /* @__PURE__ */ jsx(
|
|
2267
|
+
SliderPrimitive.Range,
|
|
2268
|
+
{
|
|
2269
|
+
"data-slot": "slider-range",
|
|
2270
|
+
className: cn(
|
|
2271
|
+
"bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
|
|
2272
|
+
)
|
|
2273
|
+
}
|
|
2274
|
+
)
|
|
2275
|
+
}
|
|
2276
|
+
),
|
|
2277
|
+
Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ jsx(
|
|
2278
|
+
SliderPrimitive.Thumb,
|
|
2279
|
+
{
|
|
2280
|
+
"data-slot": "slider-thumb",
|
|
2281
|
+
className: "border-primary ring-ring/50 block size-4 shrink-0 cursor-pointer rounded-full border bg-white shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
|
|
2599
2282
|
},
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2283
|
+
index
|
|
2284
|
+
))
|
|
2285
|
+
]
|
|
2286
|
+
}
|
|
2287
|
+
);
|
|
2288
|
+
}
|
|
2289
|
+
function VolumeControls({ className, compact }) {
|
|
2290
|
+
const {
|
|
2291
|
+
masterVolume,
|
|
2292
|
+
musicVolume,
|
|
2293
|
+
sfxVolume,
|
|
2294
|
+
setMasterVolume,
|
|
2295
|
+
setMusicVolume,
|
|
2296
|
+
setSfxVolume
|
|
2297
|
+
} = useVolumeStore();
|
|
2298
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-3", compact && "gap-1", className), children: [
|
|
2299
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2300
|
+
/* @__PURE__ */ jsx(Volume2, { className: "text-muted-foreground h-4 w-4" }),
|
|
2301
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: "Volume" })
|
|
2302
|
+
] }),
|
|
2303
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
2304
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2305
|
+
/* @__PURE__ */ jsx("label", { className: "text-muted-foreground text-xs", children: "Master" }),
|
|
2306
|
+
/* @__PURE__ */ jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
2307
|
+
Math.round(masterVolume * 100),
|
|
2308
|
+
"%"
|
|
2309
|
+
] })
|
|
2310
|
+
] }),
|
|
2311
|
+
/* @__PURE__ */ jsx(
|
|
2312
|
+
Slider,
|
|
2608
2313
|
{
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2314
|
+
value: [masterVolume * 100],
|
|
2315
|
+
onValueChange: (values) => setMasterVolume(values[0] / 100),
|
|
2316
|
+
min: 0,
|
|
2317
|
+
max: 100,
|
|
2318
|
+
step: 1,
|
|
2319
|
+
className: "w-full",
|
|
2320
|
+
"aria-label": "Master volume"
|
|
2613
2321
|
}
|
|
2614
|
-
)
|
|
2322
|
+
)
|
|
2615
2323
|
] }),
|
|
2616
|
-
/* @__PURE__ */ jsxs("div", { className: "
|
|
2324
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
2325
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2326
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
2327
|
+
/* @__PURE__ */ jsx(Music, { className: "text-muted-foreground h-3 w-3" }),
|
|
2328
|
+
/* @__PURE__ */ jsx("label", { className: "text-muted-foreground text-xs", children: "Music" })
|
|
2329
|
+
] }),
|
|
2330
|
+
/* @__PURE__ */ jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
2331
|
+
Math.round(musicVolume * 100),
|
|
2332
|
+
"%"
|
|
2333
|
+
] })
|
|
2334
|
+
] }),
|
|
2617
2335
|
/* @__PURE__ */ jsx(
|
|
2618
|
-
|
|
2336
|
+
Slider,
|
|
2619
2337
|
{
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2338
|
+
value: [musicVolume * 100],
|
|
2339
|
+
onValueChange: (values) => setMusicVolume(values[0] / 100),
|
|
2340
|
+
min: 0,
|
|
2341
|
+
max: 100,
|
|
2342
|
+
step: 1,
|
|
2343
|
+
className: "w-full",
|
|
2344
|
+
"aria-label": "Music volume"
|
|
2625
2345
|
}
|
|
2626
|
-
)
|
|
2346
|
+
)
|
|
2347
|
+
] }),
|
|
2348
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
2349
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2350
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
2351
|
+
/* @__PURE__ */ jsx(Headphones, { className: "text-muted-foreground h-3 w-3" }),
|
|
2352
|
+
/* @__PURE__ */ jsx("label", { className: "text-muted-foreground text-xs", children: "SFX" })
|
|
2353
|
+
] }),
|
|
2354
|
+
/* @__PURE__ */ jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
2355
|
+
Math.round(sfxVolume * 100),
|
|
2356
|
+
"%"
|
|
2357
|
+
] })
|
|
2358
|
+
] }),
|
|
2627
2359
|
/* @__PURE__ */ jsx(
|
|
2628
|
-
|
|
2360
|
+
Slider,
|
|
2629
2361
|
{
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2362
|
+
value: [sfxVolume * 100],
|
|
2363
|
+
onValueChange: (values) => setSfxVolume(values[0] / 100),
|
|
2364
|
+
min: 0,
|
|
2365
|
+
max: 100,
|
|
2366
|
+
step: 1,
|
|
2367
|
+
className: "w-full",
|
|
2368
|
+
"aria-label": "SFX volume"
|
|
2635
2369
|
}
|
|
2636
2370
|
)
|
|
2637
2371
|
] })
|
|
2638
2372
|
] });
|
|
2639
|
-
}
|
|
2640
|
-
var
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
connectionStatus,
|
|
2664
|
-
requiredOrientation = "landscape",
|
|
2665
|
-
children,
|
|
2666
|
-
gameState = "paused",
|
|
2667
|
-
onTogglePlayPause,
|
|
2668
|
-
onReconnect,
|
|
2669
|
-
onRefresh,
|
|
2670
|
-
customActions
|
|
2671
|
-
}) => {
|
|
2672
|
-
const isChildMode = useMemo(() => detectRunMode() === "platform", []);
|
|
2673
|
-
const [isOrientationOk, setOrientationOk] = useState(
|
|
2674
|
-
() => orientationMatches(requiredOrientation)
|
|
2675
|
-
);
|
|
2676
|
-
const [isScannerOpen, setIsScannerOpen] = useState(false);
|
|
2677
|
-
const { isFullscreen, toggleFullscreen } = useFullscreen();
|
|
2678
|
-
const { store } = useAirJamContext();
|
|
2679
|
-
const { controllerId, players } = useStore(
|
|
2680
|
-
store,
|
|
2681
|
-
useShallow(
|
|
2682
|
-
(state) => ({
|
|
2683
|
-
controllerId: state.controllerId,
|
|
2684
|
-
players: state.players
|
|
2685
|
-
})
|
|
2686
|
-
)
|
|
2687
|
-
);
|
|
2688
|
-
const currentPlayer = useMemo(() => {
|
|
2689
|
-
if (!controllerId) return null;
|
|
2690
|
-
const found = players.find((p) => p.id === controllerId);
|
|
2691
|
-
if (!found && connectionStatus === "connected" && players.length > 0) ;
|
|
2692
|
-
return found || null;
|
|
2693
|
-
}, [controllerId, players, connectionStatus]);
|
|
2373
|
+
}
|
|
2374
|
+
var statusCopy = {
|
|
2375
|
+
idle: "Idle",
|
|
2376
|
+
connecting: "Waiting for server\u2026",
|
|
2377
|
+
connected: "Ready for controllers",
|
|
2378
|
+
disconnected: "Disconnected",
|
|
2379
|
+
reconnecting: "Reconnecting\u2026"
|
|
2380
|
+
};
|
|
2381
|
+
var HostShell = ({ children }) => {
|
|
2382
|
+
const host = useAirJamHost();
|
|
2383
|
+
const {
|
|
2384
|
+
roomId,
|
|
2385
|
+
joinUrl,
|
|
2386
|
+
connectionStatus,
|
|
2387
|
+
players,
|
|
2388
|
+
lastError,
|
|
2389
|
+
gameState,
|
|
2390
|
+
toggleGameState,
|
|
2391
|
+
isChildMode
|
|
2392
|
+
} = host;
|
|
2393
|
+
const [qrUrl, setQrUrl] = useState(null);
|
|
2394
|
+
const [qrError, setQrError] = useState(null);
|
|
2395
|
+
const [copied, setCopied] = useState(false);
|
|
2396
|
+
const [copiedPlayerId, setCopiedPlayerId] = useState(null);
|
|
2694
2397
|
useEffect(() => {
|
|
2695
|
-
if (
|
|
2696
|
-
|
|
2398
|
+
if (isChildMode) return;
|
|
2399
|
+
let mounted = true;
|
|
2400
|
+
QRCode.toDataURL(joinUrl, {
|
|
2401
|
+
margin: 1,
|
|
2402
|
+
color: {
|
|
2403
|
+
dark: "#0f172a",
|
|
2404
|
+
light: "#ffffff"
|
|
2405
|
+
},
|
|
2406
|
+
width: 320
|
|
2407
|
+
}).then((value) => {
|
|
2408
|
+
if (mounted) {
|
|
2409
|
+
setQrUrl(value);
|
|
2410
|
+
setQrError(null);
|
|
2411
|
+
}
|
|
2412
|
+
}).catch((err) => {
|
|
2413
|
+
if (mounted) {
|
|
2414
|
+
setQrError(err.message);
|
|
2415
|
+
}
|
|
2416
|
+
});
|
|
2417
|
+
return () => {
|
|
2418
|
+
mounted = false;
|
|
2419
|
+
};
|
|
2420
|
+
}, [joinUrl, isChildMode]);
|
|
2421
|
+
const handleCopyUrl = async () => {
|
|
2422
|
+
if (!joinUrl) return;
|
|
2423
|
+
try {
|
|
2424
|
+
await navigator.clipboard.writeText(joinUrl);
|
|
2425
|
+
setCopied(true);
|
|
2426
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
2427
|
+
} catch {
|
|
2428
|
+
const textArea = document.createElement("textarea");
|
|
2429
|
+
textArea.value = joinUrl;
|
|
2430
|
+
textArea.style.position = "fixed";
|
|
2431
|
+
textArea.style.opacity = "0";
|
|
2432
|
+
document.body.appendChild(textArea);
|
|
2433
|
+
textArea.select();
|
|
2434
|
+
try {
|
|
2435
|
+
document.execCommand("copy");
|
|
2436
|
+
setCopied(true);
|
|
2437
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
2438
|
+
} catch {
|
|
2439
|
+
}
|
|
2440
|
+
document.body.removeChild(textArea);
|
|
2697
2441
|
}
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
}
|
|
2704
|
-
const
|
|
2705
|
-
|
|
2442
|
+
};
|
|
2443
|
+
const handleOpenInNewTab = () => {
|
|
2444
|
+
if (joinUrl) {
|
|
2445
|
+
window.open(joinUrl, "_blank", "noopener,noreferrer");
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
const handleCopyPlayerId = async (playerId) => {
|
|
2449
|
+
try {
|
|
2450
|
+
await navigator.clipboard.writeText(playerId);
|
|
2451
|
+
console.log(`Copied player ID: ${playerId}`);
|
|
2452
|
+
setCopiedPlayerId(playerId);
|
|
2453
|
+
setTimeout(() => setCopiedPlayerId(null), 1e3);
|
|
2454
|
+
} catch {
|
|
2455
|
+
const textArea = document.createElement("textarea");
|
|
2456
|
+
textArea.value = playerId;
|
|
2457
|
+
textArea.style.position = "fixed";
|
|
2458
|
+
textArea.style.opacity = "0";
|
|
2459
|
+
document.body.appendChild(textArea);
|
|
2460
|
+
textArea.select();
|
|
2461
|
+
try {
|
|
2462
|
+
document.execCommand("copy");
|
|
2463
|
+
console.log(`Copied player ID: ${playerId}`);
|
|
2464
|
+
setCopiedPlayerId(playerId);
|
|
2465
|
+
setTimeout(() => setCopiedPlayerId(null), 1e3);
|
|
2466
|
+
} catch {
|
|
2467
|
+
}
|
|
2468
|
+
document.body.removeChild(textArea);
|
|
2469
|
+
}
|
|
2470
|
+
};
|
|
2471
|
+
const connectionVariant = useMemo(() => {
|
|
2706
2472
|
switch (connectionStatus) {
|
|
2707
2473
|
case "connected":
|
|
2708
|
-
return "
|
|
2474
|
+
return "default";
|
|
2709
2475
|
case "connecting":
|
|
2710
2476
|
case "reconnecting":
|
|
2711
|
-
return "
|
|
2712
|
-
case "disconnected":
|
|
2477
|
+
return "secondary";
|
|
2713
2478
|
default:
|
|
2714
|
-
return "
|
|
2479
|
+
return "destructive";
|
|
2715
2480
|
}
|
|
2716
2481
|
}, [connectionStatus]);
|
|
2717
2482
|
if (isChildMode) {
|
|
2718
|
-
return /* @__PURE__ */ jsx(
|
|
2719
|
-
!orientationOk && /* @__PURE__ */ jsxs("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", children: [
|
|
2720
|
-
/* @__PURE__ */ jsx("p", { className: "text-card-foreground text-xl font-semibold", children: "Rotate your device" }),
|
|
2721
|
-
/* @__PURE__ */ jsxs("p", { className: "text-muted-foreground mt-2 text-sm", children: [
|
|
2722
|
-
"This game is best experienced in ",
|
|
2723
|
-
requiredOrientation,
|
|
2724
|
-
" ",
|
|
2725
|
-
"orientation."
|
|
2726
|
-
] })
|
|
2727
|
-
] }),
|
|
2728
|
-
/* @__PURE__ */ jsx(
|
|
2729
|
-
"div",
|
|
2730
|
-
{
|
|
2731
|
-
className: cn(
|
|
2732
|
-
"h-full w-full select-none",
|
|
2733
|
-
!orientationOk && "pointer-events-none opacity-30"
|
|
2734
|
-
),
|
|
2735
|
-
children
|
|
2736
|
-
}
|
|
2737
|
-
)
|
|
2738
|
-
] }) }) });
|
|
2483
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2739
2484
|
}
|
|
2740
|
-
return /* @__PURE__ */
|
|
2741
|
-
/* @__PURE__ */
|
|
2485
|
+
return /* @__PURE__ */ jsxs("div", { className: "dark relative", children: [
|
|
2486
|
+
/* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-x-0 top-0 z-99999", children: /* @__PURE__ */ jsx("div", { className: "mx-auto w-full", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
|
|
2487
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ jsxs("div", { children: [
|
|
2488
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-xs tracking-[0.18em] uppercase", children: "Room" }),
|
|
2489
|
+
/* @__PURE__ */ jsx("p", { className: "text-foreground text-lg font-semibold", children: roomId })
|
|
2490
|
+
] }) }),
|
|
2742
2491
|
/* @__PURE__ */ jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2492
|
+
players.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center -space-x-2", children: [
|
|
2493
|
+
players.slice(0, 4).map((player) => /* @__PURE__ */ jsx(PlayerAvatar, { player, size: "sm" }, player.id)),
|
|
2494
|
+
players.length > 4 && /* @__PURE__ */ jsxs("div", { className: "border-background bg-muted flex h-8 w-8 items-center justify-center rounded-full border-2 text-xs font-medium", children: [
|
|
2495
|
+
"+",
|
|
2496
|
+
players.length - 4
|
|
2497
|
+
] })
|
|
2498
|
+
] }),
|
|
2499
|
+
/* @__PURE__ */ jsx(
|
|
2500
|
+
Button,
|
|
2501
|
+
{
|
|
2502
|
+
type: "button",
|
|
2503
|
+
variant: "ghost",
|
|
2504
|
+
size: "icon",
|
|
2505
|
+
onClick: toggleGameState,
|
|
2506
|
+
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
2507
|
+
className: "h-8 w-8",
|
|
2508
|
+
children: gameState === "playing" ? /* @__PURE__ */ jsx(Pause, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(Play, { className: "h-4 w-4" })
|
|
2509
|
+
}
|
|
2510
|
+
)
|
|
2511
|
+
] })
|
|
2512
|
+
] }) }) }),
|
|
2513
|
+
gameState === "paused" && /* @__PURE__ */ jsx("div", { className: "pointer-events-none fixed inset-0 z-99998 flex items-center justify-center p-4", children: /* @__PURE__ */ jsx("div", { className: "pointer-events-auto w-full max-w-2xl", children: /* @__PURE__ */ jsx(Card, { className: "bg-card/20 flex max-h-[85vh] flex-col overflow-hidden border py-0 shadow-lg backdrop-blur-sm", children: /* @__PURE__ */ jsxs(
|
|
2514
|
+
Tabs,
|
|
2515
|
+
{
|
|
2516
|
+
defaultValue: isChildMode ? "settings" : "room-code",
|
|
2517
|
+
className: "flex h-full w-full flex-col gap-0",
|
|
2518
|
+
children: [
|
|
2519
|
+
/* @__PURE__ */ jsxs(TabsList, { className: "border-border grid w-full shrink-0 grid-cols-2 rounded-none border-b bg-transparent p-0", children: [
|
|
2520
|
+
!isChildMode && /* @__PURE__ */ jsxs(
|
|
2521
|
+
TabsTrigger,
|
|
2522
|
+
{
|
|
2523
|
+
value: "room-code",
|
|
2524
|
+
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2525
|
+
children: [
|
|
2526
|
+
/* @__PURE__ */ jsx(QrCode, { className: "h-4 w-4" }),
|
|
2527
|
+
"Room Code"
|
|
2528
|
+
]
|
|
2529
|
+
}
|
|
2530
|
+
),
|
|
2531
|
+
isChildMode && /* @__PURE__ */ jsxs(
|
|
2532
|
+
TabsTrigger,
|
|
2533
|
+
{
|
|
2534
|
+
value: "info",
|
|
2535
|
+
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2536
|
+
children: [
|
|
2537
|
+
/* @__PURE__ */ jsx(MonitorSmartphone, { className: "h-4 w-4" }),
|
|
2538
|
+
"Platform"
|
|
2539
|
+
]
|
|
2540
|
+
}
|
|
2541
|
+
),
|
|
2542
|
+
/* @__PURE__ */ jsxs(
|
|
2543
|
+
TabsTrigger,
|
|
2544
|
+
{
|
|
2545
|
+
value: "settings",
|
|
2546
|
+
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2547
|
+
children: [
|
|
2548
|
+
/* @__PURE__ */ jsx(Settings, { className: "h-4 w-4" }),
|
|
2549
|
+
"Settings"
|
|
2550
|
+
]
|
|
2551
|
+
}
|
|
2552
|
+
)
|
|
2553
|
+
] }),
|
|
2554
|
+
!isChildMode && /* @__PURE__ */ jsx(
|
|
2555
|
+
TabsContent,
|
|
2746
2556
|
{
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2557
|
+
value: "room-code",
|
|
2558
|
+
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2559
|
+
children: /* @__PURE__ */ jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-[auto_1fr]", children: [
|
|
2560
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col items-start gap-4", children: [
|
|
2561
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
2562
|
+
/* @__PURE__ */ jsx(CardTitle, { className: "text-3xl font-bold tracking-wider", children: roomId }),
|
|
2563
|
+
/* @__PURE__ */ jsx(
|
|
2564
|
+
Badge,
|
|
2565
|
+
{
|
|
2566
|
+
variant: connectionVariant,
|
|
2567
|
+
className: "w-fit",
|
|
2568
|
+
children: statusCopy[connectionStatus]
|
|
2569
|
+
}
|
|
2570
|
+
)
|
|
2571
|
+
] }),
|
|
2572
|
+
/* @__PURE__ */ jsx("div", { className: "border-border bg-card w-48 shrink-0 overflow-hidden rounded-lg border-2 shadow-md", children: qrUrl ? /* @__PURE__ */ jsx(
|
|
2573
|
+
"img",
|
|
2574
|
+
{
|
|
2575
|
+
src: qrUrl,
|
|
2576
|
+
alt: `Join room ${roomId}`,
|
|
2577
|
+
className: "w-full rounded bg-white"
|
|
2578
|
+
}
|
|
2579
|
+
) : /* @__PURE__ */ jsx("div", { className: "text-muted-foreground flex h-48 items-center justify-center text-sm", children: qrError ? `QR failed: ${qrError}` : "Generating QR code\u2026" }) })
|
|
2580
|
+
] }),
|
|
2581
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
2582
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
2583
|
+
/* @__PURE__ */ jsx(CardDescription, { className: "text-xs tracking-[0.18em] uppercase", children: "Join URL" }),
|
|
2584
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
2585
|
+
/* @__PURE__ */ jsx(
|
|
2586
|
+
"input",
|
|
2587
|
+
{
|
|
2588
|
+
type: "text",
|
|
2589
|
+
readOnly: true,
|
|
2590
|
+
value: joinUrl,
|
|
2591
|
+
className: "bg-background border-input text-foreground focus:ring-ring flex h-10 w-full rounded-md border px-3 py-2 font-mono text-xs focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50"
|
|
2592
|
+
}
|
|
2593
|
+
),
|
|
2594
|
+
/* @__PURE__ */ jsx(
|
|
2595
|
+
Button,
|
|
2596
|
+
{
|
|
2597
|
+
type: "button",
|
|
2598
|
+
variant: "outline",
|
|
2599
|
+
size: "icon",
|
|
2600
|
+
onClick: handleCopyUrl,
|
|
2601
|
+
className: "h-10 shrink-0",
|
|
2602
|
+
"aria-label": "Copy join URL",
|
|
2603
|
+
children: copied ? /* @__PURE__ */ jsx(Check, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(Copy, { className: "h-4 w-4" })
|
|
2604
|
+
}
|
|
2605
|
+
),
|
|
2606
|
+
/* @__PURE__ */ jsx(
|
|
2607
|
+
Button,
|
|
2608
|
+
{
|
|
2609
|
+
type: "button",
|
|
2610
|
+
variant: "outline",
|
|
2611
|
+
size: "icon",
|
|
2612
|
+
onClick: handleOpenInNewTab,
|
|
2613
|
+
className: "h-10 shrink-0",
|
|
2614
|
+
"aria-label": "Open join URL in new tab",
|
|
2615
|
+
children: /* @__PURE__ */ jsx(ExternalLink, { className: "h-4 w-4" })
|
|
2616
|
+
}
|
|
2617
|
+
)
|
|
2618
|
+
] })
|
|
2619
|
+
] }),
|
|
2620
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-3", children: players.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-white", children: "Waiting for controllers to join\u2026" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2621
|
+
/* @__PURE__ */ jsxs("p", { className: "text-foreground text-sm font-medium", children: [
|
|
2622
|
+
"Connected Players (",
|
|
2623
|
+
players.length,
|
|
2624
|
+
")"
|
|
2625
|
+
] }),
|
|
2626
|
+
/* @__PURE__ */ jsx("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: players.map((player) => /* @__PURE__ */ jsx(
|
|
2627
|
+
"li",
|
|
2628
|
+
{
|
|
2629
|
+
className: "flex min-w-0 flex-col items-start gap-2",
|
|
2630
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex w-full min-w-0 items-center gap-2", children: [
|
|
2631
|
+
/* @__PURE__ */ jsx(
|
|
2632
|
+
PlayerAvatar,
|
|
2633
|
+
{
|
|
2634
|
+
player,
|
|
2635
|
+
size: "md"
|
|
2636
|
+
}
|
|
2637
|
+
),
|
|
2638
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5 overflow-hidden", children: [
|
|
2639
|
+
/* @__PURE__ */ jsx("span", { className: "text-card-foreground truncate text-sm font-medium", children: player.label }),
|
|
2640
|
+
/* @__PURE__ */ jsx(
|
|
2641
|
+
"div",
|
|
2642
|
+
{
|
|
2643
|
+
onClick: () => handleCopyPlayerId(player.id),
|
|
2644
|
+
className: "text-muted-foreground m-0 inline min-w-0 cursor-pointer truncate border-0 font-mono text-xs transition-colors hover:text-white",
|
|
2645
|
+
title: "Click to copy player ID",
|
|
2646
|
+
children: copiedPlayerId === player.id ? "Copied!" : player.id.slice(0, 8)
|
|
2647
|
+
}
|
|
2648
|
+
)
|
|
2649
|
+
] })
|
|
2650
|
+
] })
|
|
2651
|
+
},
|
|
2652
|
+
player.id
|
|
2653
|
+
)) })
|
|
2654
|
+
] }) }),
|
|
2655
|
+
lastError && /* @__PURE__ */ jsx(Alert, { variant: "destructive", className: "w-full", children: /* @__PURE__ */ jsx(AlertDescription, { children: lastError }) }),
|
|
2656
|
+
/* @__PURE__ */ jsx("div", { className: "mt-auto flex justify-end", children: /* @__PURE__ */ jsxs(
|
|
2657
|
+
Button,
|
|
2658
|
+
{
|
|
2659
|
+
type: "button",
|
|
2660
|
+
onClick: toggleGameState,
|
|
2661
|
+
size: "lg",
|
|
2662
|
+
children: [
|
|
2663
|
+
/* @__PURE__ */ jsx(Play, { className: "mr-2 h-5 w-5" }),
|
|
2664
|
+
"Play"
|
|
2665
|
+
]
|
|
2666
|
+
}
|
|
2667
|
+
) })
|
|
2668
|
+
] })
|
|
2669
|
+
] }) })
|
|
2752
2670
|
}
|
|
2753
|
-
)
|
|
2754
|
-
/* @__PURE__ */ jsx(
|
|
2755
|
-
|
|
2671
|
+
),
|
|
2672
|
+
isChildMode && /* @__PURE__ */ jsx(
|
|
2673
|
+
TabsContent,
|
|
2756
2674
|
{
|
|
2757
|
-
|
|
2758
|
-
"
|
|
2675
|
+
value: "info",
|
|
2676
|
+
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2677
|
+
children: /* @__PURE__ */ jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
2678
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
2679
|
+
/* @__PURE__ */ jsx(CardTitle, { className: "text-2xl font-bold tracking-wider", children: "Connected to Platform" }),
|
|
2680
|
+
/* @__PURE__ */ jsx(CardDescription, { children: "This game is running inside the Air Jam Platform." })
|
|
2681
|
+
] }),
|
|
2682
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
2683
|
+
/* @__PURE__ */ jsxs("p", { className: "text-foreground text-sm font-medium", children: [
|
|
2684
|
+
"Connected Players (",
|
|
2685
|
+
players.length,
|
|
2686
|
+
")"
|
|
2687
|
+
] }),
|
|
2688
|
+
/* @__PURE__ */ jsx("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: players.map((player) => /* @__PURE__ */ jsx(
|
|
2689
|
+
"li",
|
|
2690
|
+
{
|
|
2691
|
+
className: "flex min-w-0 flex-col items-start gap-2",
|
|
2692
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex w-full min-w-0 items-center gap-2", children: [
|
|
2693
|
+
/* @__PURE__ */ jsx(PlayerAvatar, { player, size: "md" }),
|
|
2694
|
+
/* @__PURE__ */ jsx("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5 overflow-hidden", children: /* @__PURE__ */ jsx("span", { className: "text-card-foreground truncate text-sm font-medium", children: player.label }) })
|
|
2695
|
+
] })
|
|
2696
|
+
},
|
|
2697
|
+
player.id
|
|
2698
|
+
)) })
|
|
2699
|
+
] }),
|
|
2700
|
+
/* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsxs(
|
|
2701
|
+
Button,
|
|
2702
|
+
{
|
|
2703
|
+
type: "button",
|
|
2704
|
+
onClick: toggleGameState,
|
|
2705
|
+
size: "lg",
|
|
2706
|
+
children: [
|
|
2707
|
+
/* @__PURE__ */ jsx(Play, { className: "mr-2 h-5 w-5" }),
|
|
2708
|
+
"Resume Game"
|
|
2709
|
+
]
|
|
2710
|
+
}
|
|
2711
|
+
) })
|
|
2712
|
+
] }) })
|
|
2759
2713
|
}
|
|
2760
2714
|
),
|
|
2761
2715
|
/* @__PURE__ */ jsx(
|
|
2762
|
-
|
|
2716
|
+
TabsContent,
|
|
2763
2717
|
{
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2718
|
+
value: "settings",
|
|
2719
|
+
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2720
|
+
children: /* @__PURE__ */ jsx(CardContent, { className: "pt-6 pb-6", children: /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
2721
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-4", children: /* @__PURE__ */ jsx(VolumeControls, {}) }),
|
|
2722
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
2723
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", children: "Connection" }),
|
|
2724
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
2725
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2726
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: "Status" }),
|
|
2727
|
+
/* @__PURE__ */ jsx(Badge, { variant: connectionVariant, children: statusCopy[connectionStatus] })
|
|
2728
|
+
] }),
|
|
2729
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2730
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: "Room ID" }),
|
|
2731
|
+
/* @__PURE__ */ jsx("span", { className: "font-mono text-sm", children: roomId })
|
|
2732
|
+
] }),
|
|
2733
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2734
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: "Players" }),
|
|
2735
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: players.length })
|
|
2736
|
+
] })
|
|
2737
|
+
] })
|
|
2738
|
+
] }),
|
|
2739
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
2740
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", children: "Display" }),
|
|
2741
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-2", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2742
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: "Game State" }),
|
|
2743
|
+
/* @__PURE__ */ jsx(Badge, { variant: "outline", className: "capitalize", children: gameState })
|
|
2744
|
+
] }) })
|
|
2745
|
+
] })
|
|
2746
|
+
] }) })
|
|
2770
2747
|
}
|
|
2771
2748
|
)
|
|
2772
|
-
]
|
|
2773
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
2774
|
-
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-xs tracking-[0.24em] uppercase", children: "Room" }),
|
|
2775
|
-
/* @__PURE__ */ jsx("p", { className: "text-foreground text-lg font-semibold", children: typeof window !== "undefined" ? roomId ?? "N/A" : "N/A" })
|
|
2776
|
-
] })
|
|
2777
|
-
] }),
|
|
2778
|
-
/* @__PURE__ */ jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
2779
|
-
customActions,
|
|
2780
|
-
onRefresh && roomId && /* @__PURE__ */ jsx(
|
|
2781
|
-
Button,
|
|
2782
|
-
{
|
|
2783
|
-
type: "button",
|
|
2784
|
-
variant: "outline",
|
|
2785
|
-
size: "icon",
|
|
2786
|
-
onClick: onRefresh,
|
|
2787
|
-
disabled: connectionStatus === "connecting" || connectionStatus === "reconnecting",
|
|
2788
|
-
"aria-label": "Reconnect",
|
|
2789
|
-
title: "Reconnect to room",
|
|
2790
|
-
children: /* @__PURE__ */ jsx(
|
|
2791
|
-
RefreshCw,
|
|
2792
|
-
{
|
|
2793
|
-
className: cn(
|
|
2794
|
-
"h-5 w-5",
|
|
2795
|
-
(connectionStatus === "connecting" || connectionStatus === "reconnecting") && "animate-spin"
|
|
2796
|
-
)
|
|
2797
|
-
}
|
|
2798
|
-
)
|
|
2799
|
-
}
|
|
2800
|
-
),
|
|
2801
|
-
onReconnect && /* @__PURE__ */ jsx(
|
|
2802
|
-
Button,
|
|
2803
|
-
{
|
|
2804
|
-
type: "button",
|
|
2805
|
-
variant: "outline",
|
|
2806
|
-
size: "icon",
|
|
2807
|
-
onClick: () => setIsScannerOpen(true),
|
|
2808
|
-
"aria-label": "Scan QR code to reconnect",
|
|
2809
|
-
title: "Scan QR code to reconnect",
|
|
2810
|
-
children: /* @__PURE__ */ jsx(QrCode, { className: "h-5 w-5" })
|
|
2811
|
-
}
|
|
2812
|
-
),
|
|
2813
|
-
onTogglePlayPause && /* @__PURE__ */ jsx(
|
|
2814
|
-
Button,
|
|
2815
|
-
{
|
|
2816
|
-
type: "button",
|
|
2817
|
-
variant: "outline",
|
|
2818
|
-
size: "icon",
|
|
2819
|
-
onClick: onTogglePlayPause,
|
|
2820
|
-
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
2821
|
-
title: gameState === "playing" ? "Pause" : "Play",
|
|
2822
|
-
children: gameState === "playing" ? /* @__PURE__ */ jsx(Pause, { className: "h-5 w-5" }) : /* @__PURE__ */ jsx(Play, { className: "h-5 w-5" })
|
|
2823
|
-
}
|
|
2824
|
-
),
|
|
2825
|
-
/* @__PURE__ */ jsx(
|
|
2826
|
-
Button,
|
|
2827
|
-
{
|
|
2828
|
-
type: "button",
|
|
2829
|
-
variant: "outline",
|
|
2830
|
-
size: "icon",
|
|
2831
|
-
onClick: () => toggleFullscreen(),
|
|
2832
|
-
"aria-label": isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
|
|
2833
|
-
title: isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
|
|
2834
|
-
children: isFullscreen ? /* @__PURE__ */ jsx(Minimize, { className: "h-5 w-5" }) : /* @__PURE__ */ jsx(Maximize, { className: "h-5 w-5" })
|
|
2835
|
-
}
|
|
2836
|
-
)
|
|
2837
|
-
] })
|
|
2838
|
-
] }),
|
|
2839
|
-
/* @__PURE__ */ jsx("div", { className: "pointer-events-none fixed right-4 bottom-4 z-50", children: /* @__PURE__ */ jsx("div", { className: "pointer-events-auto", children: /* @__PURE__ */ jsx(VolumeControls, { compact: true }) }) }),
|
|
2840
|
-
/* @__PURE__ */ jsx("main", { className: "relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4", children: /* @__PURE__ */ jsxs("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", children: [
|
|
2841
|
-
!orientationOk && /* @__PURE__ */ jsxs("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", children: [
|
|
2842
|
-
/* @__PURE__ */ jsx("p", { className: "text-card-foreground text-xl font-semibold", children: "Rotate your device" }),
|
|
2843
|
-
/* @__PURE__ */ jsxs("p", { className: "text-muted-foreground mt-2 text-sm", children: [
|
|
2844
|
-
"This game is best experienced in ",
|
|
2845
|
-
requiredOrientation,
|
|
2846
|
-
" ",
|
|
2847
|
-
"orientation."
|
|
2848
|
-
] })
|
|
2849
|
-
] }),
|
|
2850
|
-
/* @__PURE__ */ jsx(
|
|
2851
|
-
"div",
|
|
2852
|
-
{
|
|
2853
|
-
className: cn(
|
|
2854
|
-
"h-full w-full select-none",
|
|
2855
|
-
!orientationOk && "pointer-events-none opacity-30"
|
|
2856
|
-
),
|
|
2857
|
-
children
|
|
2858
|
-
}
|
|
2859
|
-
)
|
|
2860
|
-
] }) }),
|
|
2861
|
-
onReconnect && /* @__PURE__ */ jsx(
|
|
2862
|
-
QRScannerDialog,
|
|
2863
|
-
{
|
|
2864
|
-
isOpen: isScannerOpen,
|
|
2865
|
-
onClose: () => setIsScannerOpen(false),
|
|
2866
|
-
onScan: (roomCode) => {
|
|
2867
|
-
onReconnect(roomCode);
|
|
2868
|
-
setIsScannerOpen(false);
|
|
2869
|
-
},
|
|
2870
|
-
currentRoomId: roomId
|
|
2749
|
+
]
|
|
2871
2750
|
}
|
|
2872
|
-
)
|
|
2873
|
-
|
|
2751
|
+
) }) }) }),
|
|
2752
|
+
children
|
|
2753
|
+
] });
|
|
2874
2754
|
};
|
|
2875
2755
|
|
|
2876
2756
|
// src/events.ts
|
|
@@ -2978,6 +2858,31 @@ var Events = {
|
|
|
2978
2858
|
Client: ClientEvents,
|
|
2979
2859
|
Child: ChildEvents
|
|
2980
2860
|
};
|
|
2861
|
+
|
|
2862
|
+
// src/utils/ids.ts
|
|
2863
|
+
var alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
2864
|
+
var generateRoomCode = () => {
|
|
2865
|
+
const array = new Uint32Array(4);
|
|
2866
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
2867
|
+
crypto.getRandomValues(array);
|
|
2868
|
+
} else {
|
|
2869
|
+
for (let i = 0; i < array.length; i += 1) {
|
|
2870
|
+
array[i] = Math.floor(Math.random() * alphabet.length);
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
const code = Array.from(
|
|
2874
|
+
array,
|
|
2875
|
+
(value) => alphabet[value % alphabet.length]
|
|
2876
|
+
).join("");
|
|
2877
|
+
return roomCodeSchema.parse(code);
|
|
2878
|
+
};
|
|
2879
|
+
var generateControllerId = () => {
|
|
2880
|
+
const stamp = Math.floor(Date.now() % 1e5).toString().padStart(5, "0");
|
|
2881
|
+
const random = alphabet[Math.floor(Math.random() * alphabet.length)];
|
|
2882
|
+
return `C${random}${stamp}`;
|
|
2883
|
+
};
|
|
2884
|
+
|
|
2885
|
+
// src/hooks/use-air-jam-controller.ts
|
|
2981
2886
|
var getRoomFromLocation = () => {
|
|
2982
2887
|
if (typeof window === "undefined") {
|
|
2983
2888
|
return null;
|
|
@@ -3486,6 +3391,7 @@ var useAirJamShell = (options = {}) => {
|
|
|
3486
3391
|
const sendInput = useCallback(
|
|
3487
3392
|
(input) => {
|
|
3488
3393
|
const storeState = store.getState();
|
|
3394
|
+
input.action === true || typeof input.vector === "object" && input.vector !== null && (Math.abs(input.vector.x ?? 0) > 0.01 || Math.abs(input.vector.y ?? 0) > 0.01);
|
|
3489
3395
|
if (!parsedRoomId || !storeState.controllerId || !socket) {
|
|
3490
3396
|
storeState.setError("Not connected to a room");
|
|
3491
3397
|
return false;
|
|
@@ -3582,6 +3488,7 @@ function createAirJamStore2(initializer) {
|
|
|
3582
3488
|
}
|
|
3583
3489
|
};
|
|
3584
3490
|
});
|
|
3491
|
+
const gameUiUnloadedRef = { current: false };
|
|
3585
3492
|
const useSyncedStore = (selector = (s) => s) => {
|
|
3586
3493
|
const slice = store(selector);
|
|
3587
3494
|
const { getSocket } = useAirJamContext();
|
|
@@ -3589,6 +3496,10 @@ function createAirJamStore2(initializer) {
|
|
|
3589
3496
|
const roomId = useAirJamState((state) => state.roomId);
|
|
3590
3497
|
const controllerId = useAirJamState((state) => state.controllerId);
|
|
3591
3498
|
const socket = role === "host" ? getSocket("host") : getSocket("controller");
|
|
3499
|
+
const socketRef = useRef(socket);
|
|
3500
|
+
useEffect(() => {
|
|
3501
|
+
socketRef.current = socket;
|
|
3502
|
+
}, [socket]);
|
|
3592
3503
|
useEffect(() => {
|
|
3593
3504
|
if (!socket || !roomId || !role) {
|
|
3594
3505
|
return;
|
|
@@ -3612,6 +3523,7 @@ function createAirJamStore2(initializer) {
|
|
|
3612
3523
|
};
|
|
3613
3524
|
}
|
|
3614
3525
|
if (role === "controller") {
|
|
3526
|
+
gameUiUnloadedRef.current = false;
|
|
3615
3527
|
const handleSync = (payload) => {
|
|
3616
3528
|
const { data } = payload;
|
|
3617
3529
|
const currentState = store.getState();
|
|
@@ -3623,9 +3535,27 @@ function createAirJamStore2(initializer) {
|
|
|
3623
3535
|
}
|
|
3624
3536
|
};
|
|
3625
3537
|
socket.on("airjam:state_sync", handleSync);
|
|
3626
|
-
|
|
3538
|
+
const handleUnloadUi = () => {
|
|
3539
|
+
gameUiUnloadedRef.current = true;
|
|
3540
|
+
socket.off("airjam:state_sync", handleSync);
|
|
3541
|
+
};
|
|
3542
|
+
const handleLoadUi = () => {
|
|
3543
|
+
gameUiUnloadedRef.current = false;
|
|
3544
|
+
};
|
|
3545
|
+
socket.on("client:loadUi", handleLoadUi);
|
|
3546
|
+
const handleDisconnect = () => {
|
|
3547
|
+
gameUiUnloadedRef.current = true;
|
|
3548
|
+
};
|
|
3549
|
+
socket.on("disconnect", handleDisconnect);
|
|
3550
|
+
socket.on("client:unloadUi", handleUnloadUi);
|
|
3551
|
+
return () => {
|
|
3552
|
+
socket.off("airjam:state_sync", handleSync);
|
|
3553
|
+
socket.off("client:loadUi", handleLoadUi);
|
|
3554
|
+
socket.off("client:unloadUi", handleUnloadUi);
|
|
3555
|
+
socket.off("disconnect", handleDisconnect);
|
|
3556
|
+
};
|
|
3627
3557
|
}
|
|
3628
|
-
}, [socket, role, roomId]);
|
|
3558
|
+
}, [socket, role, roomId, socket?.id]);
|
|
3629
3559
|
if (role === "controller" && socket && roomId) {
|
|
3630
3560
|
let originalActions = null;
|
|
3631
3561
|
if (typeof slice === "object" && slice !== null && "actions" in slice) {
|
|
@@ -3646,13 +3576,26 @@ function createAirJamStore2(initializer) {
|
|
|
3646
3576
|
const proxyActions = {};
|
|
3647
3577
|
Object.keys(originalActions).forEach((key) => {
|
|
3648
3578
|
proxyActions[key] = (...args) => {
|
|
3579
|
+
if (gameUiUnloadedRef.current) {
|
|
3580
|
+
console.warn(
|
|
3581
|
+
`[AirJamStore] Action "${key}" blocked: Game UI unloaded.`
|
|
3582
|
+
);
|
|
3583
|
+
return;
|
|
3584
|
+
}
|
|
3585
|
+
const activeSocket = socketRef.current;
|
|
3586
|
+
if (!activeSocket || !activeSocket.connected) {
|
|
3587
|
+
console.warn(
|
|
3588
|
+
`[AirJamStore] Action "${key}" blocked: Socket disconnected.`
|
|
3589
|
+
);
|
|
3590
|
+
return;
|
|
3591
|
+
}
|
|
3649
3592
|
if (!controllerId) {
|
|
3650
3593
|
console.warn(
|
|
3651
3594
|
"[AirJamStore] Cannot send action RPC: controllerId not set"
|
|
3652
3595
|
);
|
|
3653
3596
|
return;
|
|
3654
3597
|
}
|
|
3655
|
-
|
|
3598
|
+
activeSocket.emit("controller:action_rpc", {
|
|
3656
3599
|
roomId,
|
|
3657
3600
|
actionName: key,
|
|
3658
3601
|
args,
|
|
@@ -3672,6 +3615,6 @@ function createAirJamStore2(initializer) {
|
|
|
3672
3615
|
return useSyncedStore;
|
|
3673
3616
|
}
|
|
3674
3617
|
|
|
3675
|
-
export { AirJamContext,
|
|
3618
|
+
export { AirJamContext, AirJamProvider, AudioManager, AudioProvider, Button, CONTROLLER_PATH, ChildEvents, ClientEvents, ControllerEvents, ControllerShell, DEFAULT_MAX_PLAYERS, DEFAULT_SERVER_PORT, Events, HostEvents, HostShell, INPUT_DEBOUNCE_MS, PlayerAvatar, SOCKET_CONFIG, ServerEvents, Slider, SocketManager, SystemEvents, TOGGLE_DEBOUNCE_MS, UrlBuilder, VolumeControls, buttonVariants, createAirJamStore2 as createAirJamStore, createAudioManager, detectSoundCategory, generateControllerId, generateRoomCode, getLocalNetworkIp, urlBuilder, useAirJamConfig, useAirJamContext, useAirJamController, useAirJamHost, useAirJamShell, useAirJamSocket, useAirJamState, useAudio, useAudioLegacy, useAudioManager, useGetInput, useSendSignal, useVolumeStore };
|
|
3676
3619
|
//# sourceMappingURL=index.js.map
|
|
3677
3620
|
//# sourceMappingURL=index.js.map
|