@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.cjs
CHANGED
|
@@ -7,16 +7,15 @@ var socket_ioClient = require('socket.io-client');
|
|
|
7
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
8
|
var howler = require('howler');
|
|
9
9
|
var lucideReact = require('lucide-react');
|
|
10
|
-
var
|
|
11
|
-
var classVarianceAuthority = require('class-variance-authority');
|
|
10
|
+
var zod = require('zod');
|
|
12
11
|
var clsx = require('clsx');
|
|
13
12
|
var tailwindMerge = require('tailwind-merge');
|
|
14
|
-
var
|
|
13
|
+
var html5Qrcode = require('html5-qrcode');
|
|
14
|
+
var reactSlot = require('@radix-ui/react-slot');
|
|
15
|
+
var classVarianceAuthority = require('class-variance-authority');
|
|
15
16
|
var QRCode = require('qrcode');
|
|
16
|
-
var zod = require('zod');
|
|
17
17
|
var TabsPrimitive = require('@radix-ui/react-tabs');
|
|
18
18
|
var SliderPrimitive = require('@radix-ui/react-slider');
|
|
19
|
-
var html5Qrcode = require('html5-qrcode');
|
|
20
19
|
|
|
21
20
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
22
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -40,7 +39,6 @@ function _interopNamespace(e) {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
43
|
-
var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespace(DialogPrimitive);
|
|
44
42
|
var QRCode__default = /*#__PURE__*/_interopDefault(QRCode);
|
|
45
43
|
var TabsPrimitive__namespace = /*#__PURE__*/_interopNamespace(TabsPrimitive);
|
|
46
44
|
var SliderPrimitive__namespace = /*#__PURE__*/_interopNamespace(SliderPrimitive);
|
|
@@ -49,7 +47,7 @@ var SliderPrimitive__namespace = /*#__PURE__*/_interopNamespace(SliderPrimitive)
|
|
|
49
47
|
|
|
50
48
|
// src/constants.ts
|
|
51
49
|
var DEFAULT_SERVER_PORT = 4e3;
|
|
52
|
-
var
|
|
50
|
+
var CONTROLLER_PATH = "/controller";
|
|
53
51
|
var INPUT_DEBOUNCE_MS = 200;
|
|
54
52
|
var TOGGLE_DEBOUNCE_MS = 300;
|
|
55
53
|
var SOCKET_CONFIG = {
|
|
@@ -63,26 +61,21 @@ var SOCKET_CONFIG = {
|
|
|
63
61
|
PING_TIMEOUT: 5e3
|
|
64
62
|
};
|
|
65
63
|
var DEFAULT_MAX_PLAYERS = 8;
|
|
66
|
-
|
|
67
|
-
// src/internal/input-manager.ts
|
|
68
64
|
var InputManager = class {
|
|
69
65
|
inputBuffer = /* @__PURE__ */ new Map();
|
|
70
66
|
latchState = /* @__PURE__ */ new Map();
|
|
71
67
|
config;
|
|
72
|
-
|
|
73
|
-
constructor(config = {}, roomId) {
|
|
68
|
+
constructor(config = {}) {
|
|
74
69
|
this.config = config;
|
|
75
|
-
this.roomId = roomId;
|
|
76
70
|
}
|
|
77
71
|
/**
|
|
78
72
|
* Handles incoming input events from the socket.
|
|
79
73
|
* Should be called when 'server:input' event is received.
|
|
80
74
|
*/
|
|
81
75
|
handleInput(payload) {
|
|
82
|
-
if (this.roomId && payload.roomId !== this.roomId) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
76
|
this.inputBuffer.set(payload.controllerId, payload.input);
|
|
77
|
+
const input = payload?.input;
|
|
78
|
+
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));
|
|
86
79
|
}
|
|
87
80
|
/**
|
|
88
81
|
* Gets input for a specific controller.
|
|
@@ -121,12 +114,6 @@ var InputManager = class {
|
|
|
121
114
|
this.inputBuffer.delete(controllerId);
|
|
122
115
|
this.latchState.delete(controllerId);
|
|
123
116
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Updates the room ID filter.
|
|
126
|
-
*/
|
|
127
|
-
setRoomId(roomId) {
|
|
128
|
-
this.roomId = roomId;
|
|
129
|
-
}
|
|
130
117
|
/**
|
|
131
118
|
* Internal method to apply latching logic.
|
|
132
119
|
*/
|
|
@@ -350,7 +337,6 @@ var AirJamProvider = ({
|
|
|
350
337
|
children,
|
|
351
338
|
serverUrl,
|
|
352
339
|
apiKey,
|
|
353
|
-
controllerPath = DEFAULT_CONTROLLER_PATH,
|
|
354
340
|
maxPlayers = DEFAULT_MAX_PLAYERS,
|
|
355
341
|
publicHost,
|
|
356
342
|
input
|
|
@@ -359,11 +345,10 @@ var AirJamProvider = ({
|
|
|
359
345
|
() => ({
|
|
360
346
|
serverUrl: serverUrl ?? getEnvServerUrl(),
|
|
361
347
|
apiKey: apiKey ?? getEnvApiKey(),
|
|
362
|
-
controllerPath,
|
|
363
348
|
maxPlayers,
|
|
364
349
|
publicHost
|
|
365
350
|
}),
|
|
366
|
-
[serverUrl, apiKey,
|
|
351
|
+
[serverUrl, apiKey, maxPlayers, publicHost]
|
|
367
352
|
);
|
|
368
353
|
const inputManager = React.useMemo(() => {
|
|
369
354
|
if (!input) {
|
|
@@ -480,6 +465,22 @@ var useVolumeStore = zustand.create((set, get) => ({
|
|
|
480
465
|
return masterVolume * categoryVolume;
|
|
481
466
|
}
|
|
482
467
|
}));
|
|
468
|
+
var setupParentSettingsListener = () => {
|
|
469
|
+
if (typeof window === "undefined") return;
|
|
470
|
+
const isInIframe = window.parent !== window;
|
|
471
|
+
if (!isInIframe) return;
|
|
472
|
+
const handleMessage = (event) => {
|
|
473
|
+
if (event.source !== window.parent) return;
|
|
474
|
+
if (event.data?.type !== "AIRJAM_SETTINGS_SYNC") return;
|
|
475
|
+
const { masterVolume, musicVolume, sfxVolume } = event.data.payload;
|
|
476
|
+
const store = useVolumeStore.getState();
|
|
477
|
+
if (typeof masterVolume === "number") store.setMasterVolume(masterVolume);
|
|
478
|
+
if (typeof musicVolume === "number") store.setMusicVolume(musicVolume);
|
|
479
|
+
if (typeof sfxVolume === "number") store.setSfxVolume(sfxVolume);
|
|
480
|
+
};
|
|
481
|
+
window.addEventListener("message", handleMessage);
|
|
482
|
+
};
|
|
483
|
+
setupParentSettingsListener();
|
|
483
484
|
|
|
484
485
|
// src/audio/audio-manager.ts
|
|
485
486
|
function detectSoundCategory(config) {
|
|
@@ -548,7 +549,12 @@ var AudioManager = class {
|
|
|
548
549
|
if (roomId) this.roomId = roomId;
|
|
549
550
|
}
|
|
550
551
|
/**
|
|
551
|
-
*
|
|
552
|
+
* Resume audio context if suspended. This is automatically called by play(),
|
|
553
|
+
* so you typically don't need to call this manually.
|
|
554
|
+
*
|
|
555
|
+
* Note: Due to browser autoplay policies, audio context starts suspended
|
|
556
|
+
* and can only be resumed in response to a user gesture. The useAudio hook
|
|
557
|
+
* handles this automatically, and play() also calls init() internally.
|
|
552
558
|
*/
|
|
553
559
|
init() {
|
|
554
560
|
if (howler.Howler.ctx && howler.Howler.ctx.state === "suspended") {
|
|
@@ -592,6 +598,7 @@ var AudioManager = class {
|
|
|
592
598
|
sprite,
|
|
593
599
|
pitch
|
|
594
600
|
} = options || {};
|
|
601
|
+
this.init();
|
|
595
602
|
if (remote) {
|
|
596
603
|
this.playRemote(id, target, volume, loop);
|
|
597
604
|
return null;
|
|
@@ -649,6 +656,7 @@ var AudioManager = class {
|
|
|
649
656
|
* Play a sound at a specific 3D position
|
|
650
657
|
*/
|
|
651
658
|
playSpatial(id, pos, sprite) {
|
|
659
|
+
this.init();
|
|
652
660
|
const soundId = this.playLocal(id, void 0, void 0, sprite);
|
|
653
661
|
if (soundId !== null) {
|
|
654
662
|
const sound = this.sounds.get(id);
|
|
@@ -811,213 +819,85 @@ var useAudioManager = (manifest) => {
|
|
|
811
819
|
}
|
|
812
820
|
return managerRef.current;
|
|
813
821
|
};
|
|
814
|
-
var
|
|
815
|
-
|
|
816
|
-
"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",
|
|
817
|
-
{
|
|
818
|
-
variants: {
|
|
819
|
-
variant: {
|
|
820
|
-
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
821
|
-
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
822
|
-
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",
|
|
823
|
-
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
824
|
-
ghost: "text-foreground hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
825
|
-
link: "text-primary underline-offset-4 hover:underline"
|
|
826
|
-
},
|
|
827
|
-
size: {
|
|
828
|
-
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
829
|
-
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
830
|
-
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
831
|
-
icon: "size-9",
|
|
832
|
-
"icon-sm": "size-8",
|
|
833
|
-
"icon-lg": "size-10"
|
|
834
|
-
}
|
|
835
|
-
},
|
|
836
|
-
defaultVariants: {
|
|
837
|
-
variant: "default",
|
|
838
|
-
size: "default"
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
);
|
|
842
|
-
function Button({
|
|
843
|
-
className,
|
|
844
|
-
variant,
|
|
845
|
-
size,
|
|
846
|
-
asChild = false,
|
|
847
|
-
...props
|
|
848
|
-
}) {
|
|
849
|
-
const Comp = asChild ? reactSlot.Slot : "button";
|
|
850
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
851
|
-
Comp,
|
|
852
|
-
{
|
|
853
|
-
"data-slot": "button",
|
|
854
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
855
|
-
...props
|
|
856
|
-
}
|
|
857
|
-
);
|
|
858
|
-
}
|
|
859
|
-
var Dialog = DialogPrimitive__namespace.Root;
|
|
860
|
-
var DialogPortal = DialogPrimitive__namespace.Portal;
|
|
861
|
-
var DialogOverlay = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
862
|
-
DialogPrimitive__namespace.Overlay,
|
|
863
|
-
{
|
|
864
|
-
ref,
|
|
865
|
-
className: cn(
|
|
866
|
-
"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",
|
|
867
|
-
className
|
|
868
|
-
),
|
|
869
|
-
...props
|
|
870
|
-
}
|
|
871
|
-
));
|
|
872
|
-
DialogOverlay.displayName = DialogPrimitive__namespace.Overlay.displayName;
|
|
873
|
-
var DialogContent = React__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(DialogPortal, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dark", children: [
|
|
874
|
-
/* @__PURE__ */ jsxRuntime.jsx(DialogOverlay, {}),
|
|
875
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
876
|
-
DialogPrimitive__namespace.Content,
|
|
877
|
-
{
|
|
878
|
-
ref,
|
|
879
|
-
className: cn(
|
|
880
|
-
"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",
|
|
881
|
-
className
|
|
882
|
-
),
|
|
883
|
-
...props,
|
|
884
|
-
children: [
|
|
885
|
-
children,
|
|
886
|
-
/* @__PURE__ */ jsxRuntime.jsxs(DialogPrimitive__namespace.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: [
|
|
887
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-4 w-4" }),
|
|
888
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Close" })
|
|
889
|
-
] })
|
|
890
|
-
]
|
|
891
|
-
}
|
|
892
|
-
)
|
|
893
|
-
] }) }));
|
|
894
|
-
DialogContent.displayName = DialogPrimitive__namespace.Content.displayName;
|
|
895
|
-
var DialogHeader = ({
|
|
896
|
-
className,
|
|
897
|
-
...props
|
|
898
|
-
}) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
899
|
-
"div",
|
|
900
|
-
{
|
|
901
|
-
className: cn(
|
|
902
|
-
"flex flex-col space-y-1.5 text-center sm:text-left",
|
|
903
|
-
className
|
|
904
|
-
),
|
|
905
|
-
...props
|
|
906
|
-
}
|
|
907
|
-
);
|
|
908
|
-
DialogHeader.displayName = "DialogHeader";
|
|
909
|
-
var DialogTitle = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
910
|
-
DialogPrimitive__namespace.Title,
|
|
911
|
-
{
|
|
912
|
-
ref,
|
|
913
|
-
className: cn(
|
|
914
|
-
"text-lg leading-none font-semibold tracking-tight",
|
|
915
|
-
className
|
|
916
|
-
),
|
|
917
|
-
...props
|
|
918
|
-
}
|
|
919
|
-
));
|
|
920
|
-
DialogTitle.displayName = DialogPrimitive__namespace.Title.displayName;
|
|
921
|
-
var DialogDescription = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
922
|
-
DialogPrimitive__namespace.Description,
|
|
923
|
-
{
|
|
924
|
-
ref,
|
|
925
|
-
className: cn("text-muted-foreground text-sm", className),
|
|
926
|
-
...props
|
|
927
|
-
}
|
|
928
|
-
));
|
|
929
|
-
DialogDescription.displayName = DialogPrimitive__namespace.Description.displayName;
|
|
930
|
-
var DebugStateDialog = ({
|
|
931
|
-
isOpen,
|
|
932
|
-
onClose,
|
|
933
|
-
getState,
|
|
934
|
-
title = "Debug State",
|
|
935
|
-
updateInterval = 100
|
|
936
|
-
}) => {
|
|
937
|
-
const [state, setState] = React.useState(() => getState());
|
|
938
|
-
const [copied, setCopied] = React.useState(false);
|
|
822
|
+
var useFullscreen = () => {
|
|
823
|
+
const [isFullscreen, setIsFullscreen] = React.useState(false);
|
|
939
824
|
React.useEffect(() => {
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
825
|
+
const handleFullscreenChange = () => {
|
|
826
|
+
const doc = document;
|
|
827
|
+
setIsFullscreen(
|
|
828
|
+
!!(document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement)
|
|
829
|
+
);
|
|
830
|
+
};
|
|
831
|
+
document.addEventListener("fullscreenchange", handleFullscreenChange);
|
|
832
|
+
document.addEventListener("webkitfullscreenchange", handleFullscreenChange);
|
|
833
|
+
document.addEventListener("mozfullscreenchange", handleFullscreenChange);
|
|
834
|
+
document.addEventListener("msfullscreenchange", handleFullscreenChange);
|
|
947
835
|
return () => {
|
|
948
|
-
|
|
949
|
-
|
|
836
|
+
document.removeEventListener("fullscreenchange", handleFullscreenChange);
|
|
837
|
+
document.removeEventListener(
|
|
838
|
+
"webkitfullscreenchange",
|
|
839
|
+
handleFullscreenChange
|
|
840
|
+
);
|
|
841
|
+
document.removeEventListener(
|
|
842
|
+
"mozfullscreenchange",
|
|
843
|
+
handleFullscreenChange
|
|
844
|
+
);
|
|
845
|
+
document.removeEventListener(
|
|
846
|
+
"msfullscreenchange",
|
|
847
|
+
handleFullscreenChange
|
|
848
|
+
);
|
|
950
849
|
};
|
|
951
|
-
}, [
|
|
952
|
-
const
|
|
953
|
-
const handleCopy = async () => {
|
|
850
|
+
}, []);
|
|
851
|
+
const exitFullscreen = React.useCallback(async () => {
|
|
954
852
|
try {
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
853
|
+
const doc = document;
|
|
854
|
+
if (document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement) {
|
|
855
|
+
if (document.exitFullscreen) {
|
|
856
|
+
await document.exitFullscreen();
|
|
857
|
+
} else if (doc.webkitExitFullscreen) {
|
|
858
|
+
await doc.webkitExitFullscreen();
|
|
859
|
+
} else if (doc.mozCancelFullScreen) {
|
|
860
|
+
await doc.mozCancelFullScreen();
|
|
861
|
+
} else if (doc.msExitFullscreen) {
|
|
862
|
+
await doc.msExitFullscreen();
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
} catch (error) {
|
|
866
|
+
console.error("Error exiting fullscreen:", error);
|
|
867
|
+
}
|
|
868
|
+
}, []);
|
|
869
|
+
const enterFullscreen = React.useCallback(async (element) => {
|
|
870
|
+
try {
|
|
871
|
+
const elem = element || document.documentElement;
|
|
872
|
+
if (elem.requestFullscreen) {
|
|
873
|
+
await elem.requestFullscreen();
|
|
874
|
+
} else if (elem.webkitRequestFullscreen) {
|
|
875
|
+
await elem.webkitRequestFullscreen();
|
|
876
|
+
} else if (elem.mozRequestFullScreen) {
|
|
877
|
+
await elem.mozRequestFullScreen();
|
|
878
|
+
} else if (elem.msRequestFullscreen) {
|
|
879
|
+
await elem.msRequestFullscreen();
|
|
880
|
+
}
|
|
958
881
|
} catch (error) {
|
|
959
|
-
console.error("
|
|
882
|
+
console.error("Error entering fullscreen:", error);
|
|
960
883
|
}
|
|
961
|
-
};
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
variant: "ghost",
|
|
969
|
-
size: "icon-sm",
|
|
970
|
-
onClick: handleCopy,
|
|
971
|
-
className: "text-muted-foreground hover:text-foreground absolute top-6 right-2 z-10",
|
|
972
|
-
"aria-label": "Copy state",
|
|
973
|
-
children: copied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "h-4 w-4" })
|
|
974
|
-
}
|
|
975
|
-
),
|
|
976
|
-
/* @__PURE__ */ jsxRuntime.jsx("pre", { className: "bg-muted text-muted-foreground overflow-auto rounded-lg border p-4 font-mono text-xs", children: jsonString })
|
|
977
|
-
] })
|
|
978
|
-
] }) });
|
|
979
|
-
};
|
|
980
|
-
var AirJamDebug = ({
|
|
981
|
-
state,
|
|
982
|
-
title = "Debug State",
|
|
983
|
-
updateInterval = 100,
|
|
984
|
-
className
|
|
985
|
-
}) => {
|
|
986
|
-
const [isOpen, setIsOpen] = React.useState(false);
|
|
987
|
-
const [currentState, setCurrentState] = React.useState(state);
|
|
988
|
-
React.useEffect(() => {
|
|
989
|
-
if (!isOpen) return;
|
|
990
|
-
const interval = setInterval(() => {
|
|
991
|
-
setCurrentState(state);
|
|
992
|
-
}, updateInterval);
|
|
993
|
-
setCurrentState(state);
|
|
994
|
-
return () => clearInterval(interval);
|
|
995
|
-
}, [isOpen, state, updateInterval]);
|
|
996
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
997
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
998
|
-
Button,
|
|
999
|
-
{
|
|
1000
|
-
type: "button",
|
|
1001
|
-
variant: "ghost",
|
|
1002
|
-
size: "icon",
|
|
1003
|
-
onClick: () => setIsOpen(true),
|
|
1004
|
-
"aria-label": "Debug state",
|
|
1005
|
-
title,
|
|
1006
|
-
className: `text-white hover:bg-white/20 hover:text-white ${className || ""}`,
|
|
1007
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Bug, { className: "h-4 w-4" })
|
|
1008
|
-
}
|
|
1009
|
-
),
|
|
1010
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1011
|
-
DebugStateDialog,
|
|
1012
|
-
{
|
|
1013
|
-
isOpen,
|
|
1014
|
-
onClose: () => setIsOpen(false),
|
|
1015
|
-
getState: () => currentState,
|
|
1016
|
-
title,
|
|
1017
|
-
updateInterval
|
|
884
|
+
}, []);
|
|
885
|
+
const toggleFullscreen = React.useCallback(
|
|
886
|
+
async (element) => {
|
|
887
|
+
if (isFullscreen) {
|
|
888
|
+
await exitFullscreen();
|
|
889
|
+
} else {
|
|
890
|
+
await enterFullscreen(element);
|
|
1018
891
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
892
|
+
},
|
|
893
|
+
[isFullscreen, exitFullscreen, enterFullscreen]
|
|
894
|
+
);
|
|
895
|
+
return {
|
|
896
|
+
isFullscreen,
|
|
897
|
+
enterFullscreen,
|
|
898
|
+
exitFullscreen,
|
|
899
|
+
toggleFullscreen
|
|
900
|
+
};
|
|
1021
901
|
};
|
|
1022
902
|
var roomCodeSchema = zod.z.string().trim().min(4).max(8).regex(/^[A-Z0-9]+$/, { message: "room code must contain only A-Z or 0-9" });
|
|
1023
903
|
var controllerInputSchema = zod.z.object({
|
|
@@ -1083,30 +963,16 @@ var hostJoinAsChildSchema = zod.z.object({
|
|
|
1083
963
|
roomId: roomCodeSchema,
|
|
1084
964
|
joinToken: zod.z.string()
|
|
1085
965
|
});
|
|
966
|
+
var hostCreateRoomSchema = zod.z.object({
|
|
967
|
+
maxPlayers: zod.z.number().int().min(1).max(16).default(8),
|
|
968
|
+
apiKey: zod.z.string().optional()
|
|
969
|
+
});
|
|
970
|
+
var hostReconnectSchema = zod.z.object({
|
|
971
|
+
roomId: roomCodeSchema,
|
|
972
|
+
apiKey: zod.z.string().optional()
|
|
973
|
+
});
|
|
1086
974
|
var AIRJAM_PROXY_PREFIX = "AIRJAM_";
|
|
1087
|
-
|
|
1088
|
-
// src/utils/ids.ts
|
|
1089
|
-
var alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
1090
|
-
var generateRoomCode = () => {
|
|
1091
|
-
const array = new Uint32Array(4);
|
|
1092
|
-
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
1093
|
-
crypto.getRandomValues(array);
|
|
1094
|
-
} else {
|
|
1095
|
-
for (let i = 0; i < array.length; i += 1) {
|
|
1096
|
-
array[i] = Math.floor(Math.random() * alphabet.length);
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
const code = Array.from(
|
|
1100
|
-
array,
|
|
1101
|
-
(value) => alphabet[value % alphabet.length]
|
|
1102
|
-
).join("");
|
|
1103
|
-
return roomCodeSchema.parse(code);
|
|
1104
|
-
};
|
|
1105
|
-
var generateControllerId = () => {
|
|
1106
|
-
const stamp = Math.floor(Date.now() % 1e5).toString().padStart(5, "0");
|
|
1107
|
-
const random = alphabet[Math.floor(Math.random() * alphabet.length)];
|
|
1108
|
-
return `C${random}${stamp}`;
|
|
1109
|
-
};
|
|
975
|
+
var cn = (...inputs) => tailwindMerge.twMerge(clsx.clsx(inputs));
|
|
1110
976
|
|
|
1111
977
|
// src/utils/mode.ts
|
|
1112
978
|
var detectRunMode = () => {
|
|
@@ -1119,6 +985,47 @@ var detectRunMode = () => {
|
|
|
1119
985
|
return "platform";
|
|
1120
986
|
}
|
|
1121
987
|
};
|
|
988
|
+
var getPlayerAvatarUrl = (playerId) => {
|
|
989
|
+
return `https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=${encodeURIComponent(
|
|
990
|
+
playerId
|
|
991
|
+
)}`;
|
|
992
|
+
};
|
|
993
|
+
var hexToRgba = (hex, opacity) => {
|
|
994
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
995
|
+
if (!result) return `rgba(0, 0, 0, ${opacity})`;
|
|
996
|
+
const r = parseInt(result[1], 16);
|
|
997
|
+
const g = parseInt(result[2], 16);
|
|
998
|
+
const b = parseInt(result[3], 16);
|
|
999
|
+
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
1000
|
+
};
|
|
1001
|
+
var PlayerAvatar = ({
|
|
1002
|
+
player,
|
|
1003
|
+
size = "md",
|
|
1004
|
+
className = ""
|
|
1005
|
+
}) => {
|
|
1006
|
+
const sizeClasses = {
|
|
1007
|
+
sm: "h-8 w-8 border-2",
|
|
1008
|
+
md: "h-12 w-12 border-4",
|
|
1009
|
+
lg: "h-16 w-16 border-4"
|
|
1010
|
+
};
|
|
1011
|
+
const shadowStyles = {
|
|
1012
|
+
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)",
|
|
1013
|
+
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)",
|
|
1014
|
+
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)"
|
|
1015
|
+
};
|
|
1016
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1017
|
+
"img",
|
|
1018
|
+
{
|
|
1019
|
+
src: getPlayerAvatarUrl(player.id),
|
|
1020
|
+
alt: player.label,
|
|
1021
|
+
className: `bg-secondary/30 shrink-0 rounded-full shadow-lg ${sizeClasses[size]} ${className}`,
|
|
1022
|
+
style: {
|
|
1023
|
+
borderColor: player.color || "hsl(var(--border))",
|
|
1024
|
+
boxShadow: shadowStyles[size]
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
);
|
|
1028
|
+
};
|
|
1122
1029
|
|
|
1123
1030
|
// src/utils/network-ip.ts
|
|
1124
1031
|
var isVirtualNetwork = (ip) => {
|
|
@@ -1271,10 +1178,11 @@ var UrlBuilder = class {
|
|
|
1271
1178
|
}
|
|
1272
1179
|
/**
|
|
1273
1180
|
* Build a controller URL with room code.
|
|
1181
|
+
* Controller is always at {baseUrl}/controller (standardized convention).
|
|
1274
1182
|
* Automatically uses local IP when running on localhost.
|
|
1275
1183
|
*/
|
|
1276
1184
|
async buildControllerUrl(roomId, options) {
|
|
1277
|
-
const path =
|
|
1185
|
+
const path = CONTROLLER_PATH;
|
|
1278
1186
|
if (options?.host) {
|
|
1279
1187
|
const url2 = new URL(path, this.normalizeOrigin(options.host));
|
|
1280
1188
|
url2.searchParams.set("room", roomId);
|
|
@@ -1333,1638 +1241,1617 @@ var UrlBuilder = class {
|
|
|
1333
1241
|
}
|
|
1334
1242
|
};
|
|
1335
1243
|
var urlBuilder = new UrlBuilder();
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
return roomCodeSchema.parse(arcadeParams.room.toUpperCase());
|
|
1356
|
-
}
|
|
1357
|
-
if (typeof window !== "undefined") {
|
|
1358
|
-
const params = new URLSearchParams(window.location.search);
|
|
1359
|
-
const paramRoom = params.get("room");
|
|
1360
|
-
if (paramRoom) {
|
|
1361
|
-
const result = roomCodeSchema.safeParse(paramRoom.toUpperCase());
|
|
1362
|
-
if (result.success) return result.data;
|
|
1244
|
+
var buttonVariants = classVarianceAuthority.cva(
|
|
1245
|
+
"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",
|
|
1246
|
+
{
|
|
1247
|
+
variants: {
|
|
1248
|
+
variant: {
|
|
1249
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
1250
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
1251
|
+
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",
|
|
1252
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
1253
|
+
ghost: "text-foreground hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
1254
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
1255
|
+
},
|
|
1256
|
+
size: {
|
|
1257
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
1258
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
1259
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
1260
|
+
icon: "size-9",
|
|
1261
|
+
"icon-sm": "size-8",
|
|
1262
|
+
"icon-lg": "size-10"
|
|
1363
1263
|
}
|
|
1264
|
+
},
|
|
1265
|
+
defaultVariants: {
|
|
1266
|
+
variant: "default",
|
|
1267
|
+
size: "default"
|
|
1364
1268
|
}
|
|
1365
|
-
|
|
1366
|
-
|
|
1269
|
+
}
|
|
1270
|
+
);
|
|
1271
|
+
function Button({
|
|
1272
|
+
className,
|
|
1273
|
+
variant,
|
|
1274
|
+
size,
|
|
1275
|
+
asChild = false,
|
|
1276
|
+
...props
|
|
1277
|
+
}) {
|
|
1278
|
+
const Comp = asChild ? reactSlot.Slot : "button";
|
|
1279
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1280
|
+
Comp,
|
|
1281
|
+
{
|
|
1282
|
+
"data-slot": "button",
|
|
1283
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
1284
|
+
...props
|
|
1367
1285
|
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1288
|
+
var extractRoomCode = (text) => {
|
|
1289
|
+
try {
|
|
1290
|
+
const url = new URL(text);
|
|
1291
|
+
const roomParam = url.searchParams.get("room");
|
|
1292
|
+
if (roomParam) {
|
|
1293
|
+
const parsed2 = roomCodeSchema.safeParse(roomParam.toUpperCase());
|
|
1294
|
+
if (parsed2.success) {
|
|
1295
|
+
return parsed2.data;
|
|
1296
|
+
}
|
|
1373
1297
|
}
|
|
1374
|
-
}
|
|
1298
|
+
} catch {
|
|
1299
|
+
}
|
|
1300
|
+
const parsed = roomCodeSchema.safeParse(text.trim().toUpperCase());
|
|
1301
|
+
if (parsed.success) {
|
|
1302
|
+
return parsed.data;
|
|
1303
|
+
}
|
|
1304
|
+
return null;
|
|
1305
|
+
};
|
|
1306
|
+
var QRScannerDialog = ({
|
|
1307
|
+
isOpen,
|
|
1308
|
+
onClose,
|
|
1309
|
+
onScan,
|
|
1310
|
+
currentRoomId
|
|
1311
|
+
}) => {
|
|
1312
|
+
const [code, setCode] = React.useState("");
|
|
1313
|
+
const [isCameraAvailable, setIsCameraAvailable] = React.useState(false);
|
|
1375
1314
|
const [joinUrl, setJoinUrl] = React.useState("");
|
|
1376
|
-
const
|
|
1377
|
-
const
|
|
1378
|
-
const
|
|
1315
|
+
const [copied, setCopied] = React.useState(false);
|
|
1316
|
+
const scannerRef = React.useRef(null);
|
|
1317
|
+
const inputRef = React.useRef(null);
|
|
1318
|
+
const prevIsOpenRef = React.useRef(false);
|
|
1379
1319
|
React.useEffect(() => {
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
lastError: state.lastError,
|
|
1389
|
-
players: state.players,
|
|
1390
|
-
gameState: state.gameState,
|
|
1391
|
-
mode: state.mode
|
|
1392
|
-
}))
|
|
1393
|
-
);
|
|
1394
|
-
const socket = React.useMemo(
|
|
1395
|
-
() => getSocket("host") ,
|
|
1396
|
-
[shouldConnect, getSocket]
|
|
1397
|
-
);
|
|
1398
|
-
const [lastToggle, setLastToggle] = React.useState(0);
|
|
1399
|
-
const toggleGameState = React.useCallback(() => {
|
|
1400
|
-
const now = Date.now();
|
|
1401
|
-
if (now - lastToggle < TOGGLE_DEBOUNCE_MS) {
|
|
1402
|
-
return;
|
|
1403
|
-
}
|
|
1404
|
-
setLastToggle(now);
|
|
1405
|
-
if (!socket || !socket.connected) {
|
|
1406
|
-
return;
|
|
1407
|
-
}
|
|
1408
|
-
const payload = controllerSystemSchema.safeParse({
|
|
1409
|
-
roomId: parsedRoomId,
|
|
1410
|
-
command: "toggle_pause"
|
|
1411
|
-
});
|
|
1412
|
-
if (payload.success) {
|
|
1413
|
-
socket.emit("host:system", payload.data);
|
|
1320
|
+
if (isOpen && !prevIsOpenRef.current) {
|
|
1321
|
+
const initialCode = currentRoomId || "";
|
|
1322
|
+
setTimeout(() => {
|
|
1323
|
+
setIsCameraAvailable(false);
|
|
1324
|
+
setCode(initialCode);
|
|
1325
|
+
inputRef.current?.focus();
|
|
1326
|
+
inputRef.current?.select();
|
|
1327
|
+
}, 0);
|
|
1414
1328
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1329
|
+
prevIsOpenRef.current = isOpen;
|
|
1330
|
+
}, [isOpen, currentRoomId]);
|
|
1331
|
+
React.useEffect(() => {
|
|
1332
|
+
const buildUrl = async () => {
|
|
1333
|
+
const trimmed = code.trim().toUpperCase();
|
|
1334
|
+
const parsed = roomCodeSchema.safeParse(trimmed);
|
|
1335
|
+
if (parsed.success) {
|
|
1336
|
+
try {
|
|
1337
|
+
const url = await urlBuilder.buildControllerUrl(parsed.data);
|
|
1338
|
+
setJoinUrl(url);
|
|
1339
|
+
} catch {
|
|
1340
|
+
setJoinUrl("");
|
|
1341
|
+
}
|
|
1342
|
+
} else {
|
|
1343
|
+
setJoinUrl("");
|
|
1427
1344
|
}
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1345
|
+
};
|
|
1346
|
+
buildUrl();
|
|
1347
|
+
}, [code]);
|
|
1348
|
+
React.useEffect(() => {
|
|
1349
|
+
if (!isOpen) {
|
|
1350
|
+
setTimeout(() => {
|
|
1351
|
+
setIsCameraAvailable(false);
|
|
1352
|
+
}, 0);
|
|
1353
|
+
if (scannerRef.current) {
|
|
1354
|
+
const scanner = scannerRef.current;
|
|
1355
|
+
scanner.stop().catch(() => {
|
|
1356
|
+
}).finally(() => {
|
|
1357
|
+
try {
|
|
1358
|
+
scanner.clear();
|
|
1359
|
+
} catch {
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1362
|
+
scannerRef.current = null;
|
|
1437
1363
|
}
|
|
1438
|
-
const signal = {
|
|
1439
|
-
targetId,
|
|
1440
|
-
type,
|
|
1441
|
-
payload
|
|
1442
|
-
};
|
|
1443
|
-
socket.emit("host:signal", signal);
|
|
1444
|
-
},
|
|
1445
|
-
[socket]
|
|
1446
|
-
);
|
|
1447
|
-
const reconnect = React.useCallback(() => {
|
|
1448
|
-
disconnectSocket("host");
|
|
1449
|
-
if (socket) {
|
|
1450
|
-
socket.connect();
|
|
1451
1364
|
}
|
|
1452
|
-
}, [
|
|
1453
|
-
React.useEffect(() => {
|
|
1454
|
-
(async () => {
|
|
1455
|
-
const url = await urlBuilder.buildControllerUrl(parsedRoomId, {
|
|
1456
|
-
path: config.controllerPath,
|
|
1457
|
-
host: config.publicHost
|
|
1458
|
-
});
|
|
1459
|
-
setJoinUrl(url);
|
|
1460
|
-
})();
|
|
1461
|
-
}, [parsedRoomId, config.controllerPath, config.publicHost]);
|
|
1462
|
-
const setRegisteredRoomId = zustand.useStore(store, (s) => s.setRegisteredRoomId);
|
|
1365
|
+
}, [isOpen]);
|
|
1463
1366
|
React.useEffect(() => {
|
|
1464
|
-
|
|
1465
|
-
storeState.setMode(detectRunMode());
|
|
1466
|
-
storeState.setRole("host");
|
|
1467
|
-
storeState.setRoomId(parsedRoomId);
|
|
1468
|
-
storeState.setStatus("connecting");
|
|
1469
|
-
storeState.setError(void 0);
|
|
1470
|
-
if (!socket) {
|
|
1471
|
-
storeState.setStatus("idle");
|
|
1367
|
+
if (!isOpen) {
|
|
1472
1368
|
return;
|
|
1473
1369
|
}
|
|
1474
|
-
const
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
const
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1370
|
+
const containerId = "qr-reader";
|
|
1371
|
+
let scanner = null;
|
|
1372
|
+
let scannerRunning = false;
|
|
1373
|
+
let mounted = true;
|
|
1374
|
+
const startScanning = async () => {
|
|
1375
|
+
try {
|
|
1376
|
+
const container = document.getElementById(containerId);
|
|
1377
|
+
if (!container) {
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
const rect = container.getBoundingClientRect();
|
|
1381
|
+
if (rect.width === 0 || rect.height === 0) {
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1384
|
+
scanner = new html5Qrcode.Html5Qrcode(containerId);
|
|
1385
|
+
scannerRef.current = scanner;
|
|
1386
|
+
let cameraId = null;
|
|
1387
|
+
try {
|
|
1388
|
+
const devices = await html5Qrcode.Html5Qrcode.getCameras();
|
|
1389
|
+
if (devices && devices.length > 0) {
|
|
1390
|
+
const backCamera = devices.find(
|
|
1391
|
+
(d) => d.label.toLowerCase().includes("back") || d.label.toLowerCase().includes("rear")
|
|
1392
|
+
);
|
|
1393
|
+
const envCamera = devices.find((d) => {
|
|
1394
|
+
const label = d.label.toLowerCase();
|
|
1395
|
+
return label.includes("environment") || label.includes("facing back");
|
|
1396
|
+
});
|
|
1397
|
+
cameraId = (envCamera || backCamera || devices[0])?.id || null;
|
|
1398
|
+
}
|
|
1399
|
+
} catch {
|
|
1400
|
+
}
|
|
1401
|
+
const config = cameraId ? { deviceId: { exact: cameraId } } : { facingMode: "environment" };
|
|
1402
|
+
await scanner.start(
|
|
1403
|
+
config,
|
|
1404
|
+
{
|
|
1405
|
+
fps: 10,
|
|
1406
|
+
qrbox: (viewfinderWidth, viewfinderHeight) => {
|
|
1407
|
+
const minEdge = Math.min(viewfinderWidth, viewfinderHeight);
|
|
1408
|
+
const qrboxSize = Math.min(250, minEdge * 0.8);
|
|
1409
|
+
return {
|
|
1410
|
+
width: qrboxSize,
|
|
1411
|
+
height: qrboxSize
|
|
1412
|
+
};
|
|
1413
|
+
},
|
|
1414
|
+
aspectRatio: 1
|
|
1415
|
+
},
|
|
1416
|
+
(decodedText) => {
|
|
1417
|
+
if (!mounted) return;
|
|
1418
|
+
const roomCode = extractRoomCode(decodedText);
|
|
1419
|
+
if (roomCode) {
|
|
1420
|
+
setCode(roomCode);
|
|
1421
|
+
scannerRunning = false;
|
|
1422
|
+
scanner?.stop().catch(() => {
|
|
1423
|
+
}).finally(() => {
|
|
1424
|
+
if (mounted) {
|
|
1425
|
+
setIsCameraAvailable(false);
|
|
1426
|
+
}
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
},
|
|
1430
|
+
() => {
|
|
1431
|
+
}
|
|
1432
|
+
);
|
|
1433
|
+
scannerRunning = true;
|
|
1434
|
+
if (mounted) {
|
|
1435
|
+
setIsCameraAvailable(true);
|
|
1436
|
+
}
|
|
1437
|
+
} catch {
|
|
1438
|
+
if (mounted) {
|
|
1439
|
+
setIsCameraAvailable(false);
|
|
1440
|
+
}
|
|
1441
|
+
if (scanner) {
|
|
1442
|
+
try {
|
|
1443
|
+
scanner.clear();
|
|
1444
|
+
} catch {
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
scannerRef.current = null;
|
|
1544
1448
|
}
|
|
1545
1449
|
};
|
|
1546
|
-
const
|
|
1547
|
-
|
|
1548
|
-
};
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
if (
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1450
|
+
const timeoutId = setTimeout(() => {
|
|
1451
|
+
startScanning();
|
|
1452
|
+
}, 200);
|
|
1453
|
+
return () => {
|
|
1454
|
+
mounted = false;
|
|
1455
|
+
clearTimeout(timeoutId);
|
|
1456
|
+
if (scanner && scannerRunning) {
|
|
1457
|
+
scanner.stop().catch(() => {
|
|
1458
|
+
}).finally(() => {
|
|
1459
|
+
try {
|
|
1460
|
+
scanner?.clear();
|
|
1461
|
+
} catch {
|
|
1462
|
+
}
|
|
1463
|
+
});
|
|
1464
|
+
} else if (scanner) {
|
|
1465
|
+
try {
|
|
1466
|
+
scanner.clear();
|
|
1467
|
+
} catch {
|
|
1468
|
+
}
|
|
1557
1469
|
}
|
|
1470
|
+
scannerRef.current = null;
|
|
1558
1471
|
};
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
socket.on("server:input", handleInput);
|
|
1567
|
-
socket.on("server:error", handleError);
|
|
1568
|
-
socket.on("server:closeChild", handleChildClose);
|
|
1569
|
-
socket.on("server:state", handleState);
|
|
1570
|
-
socket.connect();
|
|
1571
|
-
const currentRegisteredRoomId = store.getState().registeredRoomId;
|
|
1572
|
-
if (socket.connected && currentRegisteredRoomId !== parsedRoomId) {
|
|
1573
|
-
registerHost();
|
|
1574
|
-
}
|
|
1575
|
-
if (currentRegisteredRoomId && currentRegisteredRoomId !== parsedRoomId) {
|
|
1576
|
-
setRegisteredRoomId(null);
|
|
1472
|
+
}, [isOpen]);
|
|
1473
|
+
const handleSubmit = () => {
|
|
1474
|
+
const trimmed = code.trim().toUpperCase();
|
|
1475
|
+
const parsed = roomCodeSchema.safeParse(trimmed);
|
|
1476
|
+
if (parsed.success) {
|
|
1477
|
+
onScan(parsed.data);
|
|
1478
|
+
onClose();
|
|
1577
1479
|
}
|
|
1578
|
-
return () => {
|
|
1579
|
-
socket.off("connect", handleConnect);
|
|
1580
|
-
socket.off("disconnect", handleDisconnect);
|
|
1581
|
-
socket.off("server:controllerJoined", handleJoin);
|
|
1582
|
-
socket.off("server:controllerLeft", handleLeave);
|
|
1583
|
-
socket.off("server:input", handleInput);
|
|
1584
|
-
socket.off("server:error", handleError);
|
|
1585
|
-
socket.off("server:closeChild", handleChildClose);
|
|
1586
|
-
socket.off("server:state", handleState);
|
|
1587
|
-
};
|
|
1588
|
-
}, [
|
|
1589
|
-
config.maxPlayers,
|
|
1590
|
-
config.apiKey,
|
|
1591
|
-
options.maxPlayers,
|
|
1592
|
-
options.apiKey,
|
|
1593
|
-
parsedRoomId,
|
|
1594
|
-
arcadeParams,
|
|
1595
|
-
shouldConnect,
|
|
1596
|
-
socket,
|
|
1597
|
-
store,
|
|
1598
|
-
inputManager,
|
|
1599
|
-
setRegisteredRoomId
|
|
1600
|
-
]);
|
|
1601
|
-
const returnSocket = socket ?? getSocket("host");
|
|
1602
|
-
const getInput = React.useCallback(
|
|
1603
|
-
(controllerId) => {
|
|
1604
|
-
if (!inputManager) {
|
|
1605
|
-
return void 0;
|
|
1606
|
-
}
|
|
1607
|
-
return inputManager.getInput(controllerId);
|
|
1608
|
-
},
|
|
1609
|
-
[inputManager]
|
|
1610
|
-
);
|
|
1611
|
-
return {
|
|
1612
|
-
roomId: parsedRoomId,
|
|
1613
|
-
joinUrl,
|
|
1614
|
-
connectionStatus: connectionState.connectionStatus,
|
|
1615
|
-
players: connectionState.players,
|
|
1616
|
-
lastError: connectionState.lastError,
|
|
1617
|
-
mode: connectionState.mode,
|
|
1618
|
-
gameState: connectionState.gameState,
|
|
1619
|
-
toggleGameState,
|
|
1620
|
-
sendState,
|
|
1621
|
-
sendSignal,
|
|
1622
|
-
reconnect,
|
|
1623
|
-
socket: returnSocket,
|
|
1624
|
-
isChildMode,
|
|
1625
|
-
getInput
|
|
1626
1480
|
};
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
return `https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=${encodeURIComponent(
|
|
1630
|
-
playerId
|
|
1631
|
-
)}`;
|
|
1632
|
-
};
|
|
1633
|
-
var hexToRgba = (hex, opacity) => {
|
|
1634
|
-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
1635
|
-
if (!result) return `rgba(0, 0, 0, ${opacity})`;
|
|
1636
|
-
const r = parseInt(result[1], 16);
|
|
1637
|
-
const g = parseInt(result[2], 16);
|
|
1638
|
-
const b = parseInt(result[3], 16);
|
|
1639
|
-
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
1640
|
-
};
|
|
1641
|
-
var PlayerAvatar = ({
|
|
1642
|
-
player,
|
|
1643
|
-
size = "md",
|
|
1644
|
-
className = ""
|
|
1645
|
-
}) => {
|
|
1646
|
-
const sizeClasses = {
|
|
1647
|
-
sm: "h-8 w-8 border-2",
|
|
1648
|
-
md: "h-12 w-12 border-4",
|
|
1649
|
-
lg: "h-16 w-16 border-4"
|
|
1481
|
+
const handleInputFocus = (e) => {
|
|
1482
|
+
e.target.select();
|
|
1650
1483
|
};
|
|
1651
|
-
const
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
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)"
|
|
1484
|
+
const handleInputChange = (e) => {
|
|
1485
|
+
setCode(e.target.value.toUpperCase());
|
|
1486
|
+
setCopied(false);
|
|
1655
1487
|
};
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
{
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
}
|
|
1677
|
-
},
|
|
1678
|
-
defaultVariants: {
|
|
1679
|
-
variant: "default"
|
|
1488
|
+
const handleCopyUrl = async () => {
|
|
1489
|
+
if (!joinUrl) return;
|
|
1490
|
+
try {
|
|
1491
|
+
await navigator.clipboard.writeText(joinUrl);
|
|
1492
|
+
setCopied(true);
|
|
1493
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
1494
|
+
} catch {
|
|
1495
|
+
const textArea = document.createElement("textarea");
|
|
1496
|
+
textArea.value = joinUrl;
|
|
1497
|
+
textArea.style.position = "fixed";
|
|
1498
|
+
textArea.style.opacity = "0";
|
|
1499
|
+
document.body.appendChild(textArea);
|
|
1500
|
+
textArea.select();
|
|
1501
|
+
try {
|
|
1502
|
+
document.execCommand("copy");
|
|
1503
|
+
setCopied(true);
|
|
1504
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
1505
|
+
} catch {
|
|
1506
|
+
}
|
|
1507
|
+
document.body.removeChild(textArea);
|
|
1680
1508
|
}
|
|
1509
|
+
};
|
|
1510
|
+
if (!isOpen) {
|
|
1511
|
+
return null;
|
|
1681
1512
|
}
|
|
1682
|
-
);
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1513
|
+
const isValid = code.trim().length > 0;
|
|
1514
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-background fixed inset-0 z-50 flex flex-col items-center justify-center", children: [
|
|
1515
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col items-center justify-center", children: [
|
|
1516
|
+
isCameraAvailable && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative flex aspect-square w-full items-center justify-center overflow-hidden p-6", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1517
|
+
"div",
|
|
1518
|
+
{
|
|
1519
|
+
id: "qr-reader",
|
|
1520
|
+
className: "h-full w-full overflow-hidden rounded-lg bg-black"
|
|
1521
|
+
}
|
|
1522
|
+
) }),
|
|
1523
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full max-w-md px-6", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1524
|
+
"input",
|
|
1525
|
+
{
|
|
1526
|
+
ref: inputRef,
|
|
1527
|
+
type: "text",
|
|
1528
|
+
value: code,
|
|
1529
|
+
onChange: handleInputChange,
|
|
1530
|
+
onFocus: handleInputFocus,
|
|
1531
|
+
onKeyDown: (e) => {
|
|
1532
|
+
if (e.key === "Enter" && isValid) {
|
|
1533
|
+
handleSubmit();
|
|
1534
|
+
}
|
|
1535
|
+
},
|
|
1536
|
+
placeholder: "Enter room code",
|
|
1537
|
+
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",
|
|
1538
|
+
autoComplete: "off",
|
|
1539
|
+
autoCapitalize: "characters"
|
|
1540
|
+
}
|
|
1541
|
+
) }),
|
|
1542
|
+
joinUrl && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 w-full max-w-md px-6 pb-2", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1543
|
+
"button",
|
|
1544
|
+
{
|
|
1545
|
+
type: "button",
|
|
1546
|
+
onClick: handleCopyUrl,
|
|
1547
|
+
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",
|
|
1548
|
+
children: copied ? "\u2713 Copied!" : joinUrl
|
|
1549
|
+
}
|
|
1550
|
+
) })
|
|
1551
|
+
] }),
|
|
1552
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-md gap-4 px-6 pb-6", children: [
|
|
1553
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1554
|
+
Button,
|
|
1555
|
+
{
|
|
1556
|
+
type: "button",
|
|
1557
|
+
variant: "outline",
|
|
1558
|
+
onClick: onClose,
|
|
1559
|
+
className: "flex-1 py-6",
|
|
1560
|
+
children: "Cancel"
|
|
1561
|
+
}
|
|
1709
1562
|
),
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1563
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1564
|
+
Button,
|
|
1565
|
+
{
|
|
1566
|
+
type: "button",
|
|
1567
|
+
onClick: handleSubmit,
|
|
1568
|
+
disabled: !isValid,
|
|
1569
|
+
className: "flex-1 py-6",
|
|
1570
|
+
children: "Connect"
|
|
1571
|
+
}
|
|
1572
|
+
)
|
|
1573
|
+
] })
|
|
1574
|
+
] });
|
|
1575
|
+
};
|
|
1576
|
+
var describeStatus = (status) => {
|
|
1577
|
+
switch (status) {
|
|
1578
|
+
case "connected":
|
|
1579
|
+
return "Connected to host";
|
|
1580
|
+
case "connecting":
|
|
1581
|
+
return "Connecting\u2026";
|
|
1582
|
+
case "reconnecting":
|
|
1583
|
+
return "Trying to reconnect\u2026";
|
|
1584
|
+
case "disconnected":
|
|
1585
|
+
return "Disconnected";
|
|
1586
|
+
case "idle":
|
|
1587
|
+
default:
|
|
1588
|
+
return "Idle";
|
|
1728
1589
|
}
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1590
|
+
};
|
|
1591
|
+
var orientationMatches = (required) => {
|
|
1592
|
+
if (!required) return true;
|
|
1593
|
+
if (typeof window === "undefined" || !window.matchMedia) return true;
|
|
1594
|
+
const matcher = window.matchMedia(`(orientation: ${required})`);
|
|
1595
|
+
return matcher.matches;
|
|
1596
|
+
};
|
|
1597
|
+
var ControllerShell = ({
|
|
1598
|
+
forceOrientation,
|
|
1599
|
+
children,
|
|
1600
|
+
customActions
|
|
1601
|
+
}) => {
|
|
1602
|
+
const { store, getSocket, disconnectSocket } = useAirJamContext();
|
|
1603
|
+
const isChildMode = React.useMemo(() => detectRunMode() === "platform", []);
|
|
1604
|
+
const [isOrientationOk, setOrientationOk] = React.useState(
|
|
1605
|
+
() => orientationMatches(forceOrientation)
|
|
1744
1606
|
);
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
{
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
}
|
|
1607
|
+
const [isScannerOpen, setIsScannerOpen] = React.useState(false);
|
|
1608
|
+
const { isFullscreen, toggleFullscreen } = useFullscreen();
|
|
1609
|
+
const { roomId, connectionStatus, gameState, controllerId, players } = zustand.useStore(
|
|
1610
|
+
store,
|
|
1611
|
+
shallow.useShallow((state) => ({
|
|
1612
|
+
roomId: state.roomId,
|
|
1613
|
+
connectionStatus: state.connectionStatus,
|
|
1614
|
+
gameState: state.gameState,
|
|
1615
|
+
controllerId: state.controllerId,
|
|
1616
|
+
players: state.players
|
|
1617
|
+
}))
|
|
1757
1618
|
);
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1619
|
+
const socket = React.useMemo(() => getSocket("controller"), [getSocket]);
|
|
1620
|
+
const currentPlayer = React.useMemo(() => {
|
|
1621
|
+
if (!controllerId) return null;
|
|
1622
|
+
const found = players.find((p) => p.id === controllerId);
|
|
1623
|
+
if (!found && connectionStatus === "connected" && players.length > 0) ;
|
|
1624
|
+
return found || null;
|
|
1625
|
+
}, [controllerId, players, connectionStatus]);
|
|
1626
|
+
const sendSystemCommand = React.useCallback(
|
|
1627
|
+
(command) => {
|
|
1628
|
+
const storeState = store.getState();
|
|
1629
|
+
if (!roomId || !storeState.controllerId || !socket) return;
|
|
1630
|
+
if (!socket.connected) return;
|
|
1631
|
+
const payload = controllerSystemSchema.safeParse({
|
|
1632
|
+
roomId,
|
|
1633
|
+
command
|
|
1634
|
+
});
|
|
1635
|
+
if (payload.success) {
|
|
1636
|
+
socket.emit("controller:system", payload.data);
|
|
1637
|
+
}
|
|
1638
|
+
},
|
|
1639
|
+
[roomId, socket, store]
|
|
1767
1640
|
);
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1641
|
+
const reconnect = React.useCallback(() => {
|
|
1642
|
+
if (!roomId) return;
|
|
1643
|
+
disconnectSocket("controller");
|
|
1644
|
+
store.getState().setRoomId(roomId);
|
|
1645
|
+
}, [roomId, disconnectSocket, store]);
|
|
1646
|
+
React.useEffect(() => {
|
|
1647
|
+
if (!forceOrientation) {
|
|
1648
|
+
setOrientationOk(true);
|
|
1649
|
+
return;
|
|
1776
1650
|
}
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
"
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1651
|
+
const media = window.matchMedia(`(orientation: ${forceOrientation})`);
|
|
1652
|
+
const handleChange = () => setOrientationOk(media.matches);
|
|
1653
|
+
handleChange();
|
|
1654
|
+
media.addEventListener("change", handleChange);
|
|
1655
|
+
return () => media.removeEventListener("change", handleChange);
|
|
1656
|
+
}, [forceOrientation]);
|
|
1657
|
+
const orientationOk = !forceOrientation ? true : isOrientationOk;
|
|
1658
|
+
const statusDotColor = React.useMemo(() => {
|
|
1659
|
+
switch (connectionStatus) {
|
|
1660
|
+
case "connected":
|
|
1661
|
+
return "bg-green-500";
|
|
1662
|
+
case "connecting":
|
|
1663
|
+
case "reconnecting":
|
|
1664
|
+
return "bg-yellow-500";
|
|
1665
|
+
case "disconnected":
|
|
1666
|
+
default:
|
|
1667
|
+
return "bg-red-500";
|
|
1786
1668
|
}
|
|
1787
|
-
);
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
);
|
|
1817
|
-
}
|
|
1818
|
-
function TabsTrigger({
|
|
1819
|
-
className,
|
|
1820
|
-
...props
|
|
1821
|
-
}) {
|
|
1822
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1823
|
-
TabsPrimitive__namespace.Trigger,
|
|
1824
|
-
{
|
|
1825
|
-
"data-slot": "tabs-trigger",
|
|
1826
|
-
className: cn(
|
|
1827
|
-
"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",
|
|
1828
|
-
className
|
|
1829
|
-
),
|
|
1830
|
-
...props
|
|
1831
|
-
}
|
|
1832
|
-
);
|
|
1833
|
-
}
|
|
1834
|
-
function TabsContent({
|
|
1835
|
-
className,
|
|
1836
|
-
...props
|
|
1837
|
-
}) {
|
|
1838
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1839
|
-
TabsPrimitive__namespace.Content,
|
|
1840
|
-
{
|
|
1841
|
-
"data-slot": "tabs-content",
|
|
1842
|
-
className: cn("flex-1 outline-none", className),
|
|
1843
|
-
...props
|
|
1844
|
-
}
|
|
1845
|
-
);
|
|
1846
|
-
}
|
|
1847
|
-
function Slider({
|
|
1848
|
-
className,
|
|
1849
|
-
defaultValue,
|
|
1850
|
-
value,
|
|
1851
|
-
min = 0,
|
|
1852
|
-
max = 100,
|
|
1853
|
-
...props
|
|
1854
|
-
}) {
|
|
1855
|
-
const _values = React__namespace.useMemo(
|
|
1856
|
-
() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
|
|
1857
|
-
[value, defaultValue, min, max]
|
|
1858
|
-
);
|
|
1859
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1860
|
-
SliderPrimitive__namespace.Root,
|
|
1861
|
-
{
|
|
1862
|
-
"data-slot": "slider",
|
|
1863
|
-
defaultValue,
|
|
1864
|
-
value,
|
|
1865
|
-
min,
|
|
1866
|
-
max,
|
|
1867
|
-
className: cn(
|
|
1868
|
-
"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",
|
|
1869
|
-
className
|
|
1870
|
-
),
|
|
1871
|
-
...props,
|
|
1872
|
-
children: [
|
|
1873
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1874
|
-
SliderPrimitive__namespace.Track,
|
|
1669
|
+
}, [connectionStatus]);
|
|
1670
|
+
if (isChildMode) {
|
|
1671
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dark", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden bg-black select-none", children: /* @__PURE__ */ jsxRuntime.jsxs("main", { className: "relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4", children: [
|
|
1672
|
+
!orientationOk && /* @__PURE__ */ jsxRuntime.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: [
|
|
1673
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-card-foreground text-xl font-semibold", children: "Rotate your device" }),
|
|
1674
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-muted-foreground mt-2 text-sm", children: [
|
|
1675
|
+
"This game is best experienced in ",
|
|
1676
|
+
forceOrientation,
|
|
1677
|
+
" ",
|
|
1678
|
+
"orientation."
|
|
1679
|
+
] })
|
|
1680
|
+
] }),
|
|
1681
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1682
|
+
"div",
|
|
1683
|
+
{
|
|
1684
|
+
className: cn(
|
|
1685
|
+
"h-full w-full select-none",
|
|
1686
|
+
!orientationOk && "pointer-events-none opacity-30"
|
|
1687
|
+
),
|
|
1688
|
+
children
|
|
1689
|
+
}
|
|
1690
|
+
)
|
|
1691
|
+
] }) }) });
|
|
1692
|
+
}
|
|
1693
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dark", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden bg-black select-none", children: [
|
|
1694
|
+
/* @__PURE__ */ jsxRuntime.jsxs("header", { className: "pointer-events-none sticky top-0 z-50 flex items-center justify-between border-b px-6 py-2", children: [
|
|
1695
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
1696
|
+
typeof window !== "undefined" && (currentPlayer || controllerId) && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1697
|
+
"div",
|
|
1875
1698
|
{
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1699
|
+
className: "relative",
|
|
1700
|
+
title: describeStatus(connectionStatus),
|
|
1701
|
+
children: [
|
|
1702
|
+
currentPlayer ? /* @__PURE__ */ jsxRuntime.jsx(PlayerAvatar, { player: currentPlayer, size: "sm" }) : controllerId ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1703
|
+
PlayerAvatar,
|
|
1704
|
+
{
|
|
1705
|
+
player: {
|
|
1706
|
+
id: controllerId,
|
|
1707
|
+
label: "Player"
|
|
1708
|
+
},
|
|
1709
|
+
size: "sm"
|
|
1710
|
+
}
|
|
1711
|
+
) : null,
|
|
1712
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1713
|
+
"span",
|
|
1714
|
+
{
|
|
1715
|
+
className: "absolute right-0 bottom-0 h-3 w-3 rounded-full bg-black",
|
|
1716
|
+
"aria-hidden": "true"
|
|
1717
|
+
}
|
|
1718
|
+
),
|
|
1719
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1720
|
+
"span",
|
|
1721
|
+
{
|
|
1722
|
+
className: cn(
|
|
1723
|
+
"absolute right-0.5 bottom-0.5 h-2 w-2 rounded-full",
|
|
1724
|
+
statusDotColor,
|
|
1725
|
+
connectionStatus === "connected" && "animate-pulse"
|
|
1726
|
+
),
|
|
1727
|
+
"aria-label": describeStatus(connectionStatus)
|
|
1728
|
+
}
|
|
1729
|
+
)
|
|
1730
|
+
]
|
|
1731
|
+
}
|
|
1732
|
+
),
|
|
1733
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1734
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs tracking-[0.24em] uppercase", children: "Room" }),
|
|
1735
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-foreground text-lg font-semibold", children: typeof window !== "undefined" ? roomId ?? "N/A" : "N/A" })
|
|
1736
|
+
] })
|
|
1737
|
+
] }),
|
|
1738
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
1739
|
+
customActions,
|
|
1740
|
+
roomId && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1741
|
+
Button,
|
|
1742
|
+
{
|
|
1743
|
+
type: "button",
|
|
1744
|
+
variant: "outline",
|
|
1745
|
+
size: "icon",
|
|
1746
|
+
onClick: () => window.location.reload(),
|
|
1747
|
+
disabled: connectionStatus === "connecting" || connectionStatus === "reconnecting",
|
|
1748
|
+
"aria-label": "Reconnect",
|
|
1749
|
+
title: "Reconnect to room",
|
|
1880
1750
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1881
|
-
|
|
1751
|
+
lucideReact.RefreshCw,
|
|
1882
1752
|
{
|
|
1883
|
-
"data-slot": "slider-range",
|
|
1884
1753
|
className: cn(
|
|
1885
|
-
"
|
|
1754
|
+
"h-5 w-5",
|
|
1755
|
+
(connectionStatus === "connecting" || connectionStatus === "reconnecting") && "animate-spin"
|
|
1886
1756
|
)
|
|
1887
1757
|
}
|
|
1888
1758
|
)
|
|
1889
1759
|
}
|
|
1890
1760
|
),
|
|
1891
|
-
|
|
1892
|
-
|
|
1761
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1762
|
+
Button,
|
|
1893
1763
|
{
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
value: [masterVolume * 100],
|
|
1929
|
-
onValueChange: (values) => setMasterVolume(values[0] / 100),
|
|
1930
|
-
min: 0,
|
|
1931
|
-
max: 100,
|
|
1932
|
-
step: 1,
|
|
1933
|
-
className: "w-full",
|
|
1934
|
-
"aria-label": "Master volume"
|
|
1935
|
-
}
|
|
1936
|
-
)
|
|
1764
|
+
type: "button",
|
|
1765
|
+
variant: "outline",
|
|
1766
|
+
size: "icon",
|
|
1767
|
+
onClick: () => setIsScannerOpen(true),
|
|
1768
|
+
"aria-label": "Scan QR code to reconnect",
|
|
1769
|
+
title: "Scan QR code to reconnect",
|
|
1770
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.QrCode, { className: "h-5 w-5" })
|
|
1771
|
+
}
|
|
1772
|
+
),
|
|
1773
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1774
|
+
Button,
|
|
1775
|
+
{
|
|
1776
|
+
type: "button",
|
|
1777
|
+
variant: "outline",
|
|
1778
|
+
size: "icon",
|
|
1779
|
+
onClick: () => sendSystemCommand("toggle_pause"),
|
|
1780
|
+
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
1781
|
+
title: gameState === "playing" ? "Pause" : "Play",
|
|
1782
|
+
children: gameState === "playing" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, { className: "h-5 w-5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "h-5 w-5" })
|
|
1783
|
+
}
|
|
1784
|
+
),
|
|
1785
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1786
|
+
Button,
|
|
1787
|
+
{
|
|
1788
|
+
type: "button",
|
|
1789
|
+
variant: "outline",
|
|
1790
|
+
size: "icon",
|
|
1791
|
+
onClick: () => toggleFullscreen(),
|
|
1792
|
+
"aria-label": isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
|
|
1793
|
+
title: isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
|
|
1794
|
+
children: isFullscreen ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Minimize, { className: "h-5 w-5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Maximize, { className: "h-5 w-5" })
|
|
1795
|
+
}
|
|
1796
|
+
)
|
|
1797
|
+
] })
|
|
1937
1798
|
] }),
|
|
1938
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1939
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-
|
|
1940
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
"%"
|
|
1799
|
+
/* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.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: [
|
|
1800
|
+
!orientationOk && forceOrientation && /* @__PURE__ */ jsxRuntime.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: [
|
|
1801
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-card-foreground text-xl font-semibold", children: "Rotate your device" }),
|
|
1802
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-muted-foreground mt-2 text-sm", children: [
|
|
1803
|
+
"This game is best experienced in ",
|
|
1804
|
+
forceOrientation,
|
|
1805
|
+
" ",
|
|
1806
|
+
"orientation."
|
|
1947
1807
|
] })
|
|
1948
1808
|
] }),
|
|
1949
1809
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1950
|
-
|
|
1810
|
+
"div",
|
|
1951
1811
|
{
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
className: "w-full",
|
|
1958
|
-
"aria-label": "Music volume"
|
|
1812
|
+
className: cn(
|
|
1813
|
+
"h-full w-full select-none",
|
|
1814
|
+
!orientationOk && "pointer-events-none opacity-30"
|
|
1815
|
+
),
|
|
1816
|
+
children
|
|
1959
1817
|
}
|
|
1960
1818
|
)
|
|
1961
|
-
] }),
|
|
1962
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
value: [sfxVolume * 100],
|
|
1977
|
-
onValueChange: (values) => setSfxVolume(values[0] / 100),
|
|
1978
|
-
min: 0,
|
|
1979
|
-
max: 100,
|
|
1980
|
-
step: 1,
|
|
1981
|
-
className: "w-full",
|
|
1982
|
-
"aria-label": "SFX volume"
|
|
1983
|
-
}
|
|
1984
|
-
)
|
|
1985
|
-
] })
|
|
1986
|
-
] });
|
|
1987
|
-
}
|
|
1988
|
-
var statusCopy = {
|
|
1989
|
-
idle: "Idle",
|
|
1990
|
-
connecting: "Waiting for server\u2026",
|
|
1991
|
-
connected: "Ready for controllers",
|
|
1992
|
-
disconnected: "Disconnected",
|
|
1993
|
-
reconnecting: "Reconnecting\u2026"
|
|
1819
|
+
] }) }),
|
|
1820
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1821
|
+
QRScannerDialog,
|
|
1822
|
+
{
|
|
1823
|
+
isOpen: isScannerOpen,
|
|
1824
|
+
onClose: () => setIsScannerOpen(false),
|
|
1825
|
+
onScan: (roomCode) => {
|
|
1826
|
+
store.getState().setRoomId(roomCode);
|
|
1827
|
+
reconnect();
|
|
1828
|
+
setIsScannerOpen(false);
|
|
1829
|
+
},
|
|
1830
|
+
currentRoomId: roomId
|
|
1831
|
+
}
|
|
1832
|
+
)
|
|
1833
|
+
] }) });
|
|
1994
1834
|
};
|
|
1995
|
-
var
|
|
1996
|
-
const
|
|
1997
|
-
const {
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
}
|
|
2007
|
-
const
|
|
2008
|
-
const
|
|
2009
|
-
const
|
|
2010
|
-
const
|
|
1835
|
+
var useAirJamHost = (options = {}) => {
|
|
1836
|
+
const { config, store, getSocket, disconnectSocket, inputManager } = useAirJamContext();
|
|
1837
|
+
const arcadeParams = React.useMemo(() => {
|
|
1838
|
+
if (typeof window === "undefined") return null;
|
|
1839
|
+
const params = new URLSearchParams(window.location.search);
|
|
1840
|
+
const room = params.get("aj_room");
|
|
1841
|
+
const token = params.get("aj_token");
|
|
1842
|
+
if (room && token) {
|
|
1843
|
+
return { room, token };
|
|
1844
|
+
}
|
|
1845
|
+
return null;
|
|
1846
|
+
}, []);
|
|
1847
|
+
const isChildMode = !!arcadeParams;
|
|
1848
|
+
const shouldConnect = true;
|
|
1849
|
+
const storeRoomId = zustand.useStore(store, (s) => s.roomId);
|
|
1850
|
+
const parsedRoomId = React.useMemo(() => {
|
|
1851
|
+
if (arcadeParams) {
|
|
1852
|
+
return roomCodeSchema.parse(arcadeParams.room.toUpperCase());
|
|
1853
|
+
}
|
|
1854
|
+
if (storeRoomId) {
|
|
1855
|
+
return roomCodeSchema.parse(storeRoomId.toUpperCase());
|
|
1856
|
+
}
|
|
1857
|
+
if (typeof window !== "undefined") {
|
|
1858
|
+
const params = new URLSearchParams(window.location.search);
|
|
1859
|
+
const paramRoom = params.get("room");
|
|
1860
|
+
if (paramRoom) {
|
|
1861
|
+
const result = roomCodeSchema.safeParse(paramRoom.toUpperCase());
|
|
1862
|
+
if (result.success) return result.data;
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
if (options.roomId) {
|
|
1866
|
+
return roomCodeSchema.parse(options.roomId.toUpperCase());
|
|
1867
|
+
}
|
|
1868
|
+
return null;
|
|
1869
|
+
}, [options.roomId, storeRoomId, arcadeParams]);
|
|
1870
|
+
const [joinUrl, setJoinUrl] = React.useState("");
|
|
1871
|
+
const onPlayerJoinRef = React.useRef(options.onPlayerJoin);
|
|
1872
|
+
const onPlayerLeaveRef = React.useRef(options.onPlayerLeave);
|
|
1873
|
+
const onChildCloseRef = React.useRef(options.onChildClose);
|
|
2011
1874
|
React.useEffect(() => {
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
1875
|
+
onPlayerJoinRef.current = options.onPlayerJoin;
|
|
1876
|
+
onPlayerLeaveRef.current = options.onPlayerLeave;
|
|
1877
|
+
onChildCloseRef.current = options.onChildClose;
|
|
1878
|
+
}, [options.onPlayerJoin, options.onPlayerLeave, options.onChildClose]);
|
|
1879
|
+
const connectionState = zustand.useStore(
|
|
1880
|
+
store,
|
|
1881
|
+
shallow.useShallow((state) => ({
|
|
1882
|
+
connectionStatus: state.connectionStatus,
|
|
1883
|
+
lastError: state.lastError,
|
|
1884
|
+
players: state.players,
|
|
1885
|
+
gameState: state.gameState,
|
|
1886
|
+
mode: state.mode,
|
|
1887
|
+
roomId: state.roomId
|
|
1888
|
+
}))
|
|
1889
|
+
);
|
|
1890
|
+
const socket = React.useMemo(
|
|
1891
|
+
() => getSocket("host") ,
|
|
1892
|
+
[shouldConnect, getSocket]
|
|
1893
|
+
);
|
|
1894
|
+
const [lastToggle, setLastToggle] = React.useState(0);
|
|
1895
|
+
const toggleGameState = React.useCallback(() => {
|
|
1896
|
+
const now = Date.now();
|
|
1897
|
+
if (now - lastToggle < TOGGLE_DEBOUNCE_MS) {
|
|
1898
|
+
return;
|
|
1899
|
+
}
|
|
1900
|
+
setLastToggle(now);
|
|
1901
|
+
if (!socket || !socket.connected) {
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
if (!parsedRoomId) return;
|
|
1905
|
+
const payload = controllerSystemSchema.safeParse({
|
|
1906
|
+
roomId: parsedRoomId,
|
|
1907
|
+
command: "toggle_pause"
|
|
1908
|
+
});
|
|
1909
|
+
if (payload.success) {
|
|
1910
|
+
socket.emit("host:system", payload.data);
|
|
1911
|
+
}
|
|
1912
|
+
}, [socket, parsedRoomId, lastToggle]);
|
|
1913
|
+
const sendState = React.useCallback(
|
|
1914
|
+
(state) => {
|
|
1915
|
+
if (!socket || !socket.connected || !parsedRoomId) {
|
|
1916
|
+
return false;
|
|
2025
1917
|
}
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
1918
|
+
const payload = controllerStateSchema.safeParse({
|
|
1919
|
+
roomId: parsedRoomId,
|
|
1920
|
+
state
|
|
1921
|
+
});
|
|
1922
|
+
if (!payload.success) {
|
|
1923
|
+
return false;
|
|
2029
1924
|
}
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
const
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
setCopied(true);
|
|
2040
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
2041
|
-
} catch {
|
|
2042
|
-
const textArea = document.createElement("textarea");
|
|
2043
|
-
textArea.value = joinUrl;
|
|
2044
|
-
textArea.style.position = "fixed";
|
|
2045
|
-
textArea.style.opacity = "0";
|
|
2046
|
-
document.body.appendChild(textArea);
|
|
2047
|
-
textArea.select();
|
|
2048
|
-
try {
|
|
2049
|
-
document.execCommand("copy");
|
|
2050
|
-
setCopied(true);
|
|
2051
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
2052
|
-
} catch {
|
|
1925
|
+
socket.emit("host:state", payload.data);
|
|
1926
|
+
return true;
|
|
1927
|
+
},
|
|
1928
|
+
[socket, parsedRoomId]
|
|
1929
|
+
);
|
|
1930
|
+
const sendSignal = React.useCallback(
|
|
1931
|
+
(type, payload, targetId) => {
|
|
1932
|
+
if (!socket || !socket.connected) {
|
|
1933
|
+
return;
|
|
2053
1934
|
}
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
1935
|
+
const signal = {
|
|
1936
|
+
targetId,
|
|
1937
|
+
type,
|
|
1938
|
+
payload
|
|
1939
|
+
};
|
|
1940
|
+
socket.emit("host:signal", signal);
|
|
1941
|
+
},
|
|
1942
|
+
[socket]
|
|
1943
|
+
);
|
|
1944
|
+
const reconnect = React.useCallback(() => {
|
|
1945
|
+
disconnectSocket("host");
|
|
1946
|
+
if (socket) {
|
|
1947
|
+
socket.connect();
|
|
2060
1948
|
}
|
|
2061
|
-
};
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
setCopiedPlayerId(playerId);
|
|
2079
|
-
setTimeout(() => setCopiedPlayerId(null), 1e3);
|
|
2080
|
-
} catch {
|
|
2081
|
-
}
|
|
2082
|
-
document.body.removeChild(textArea);
|
|
1949
|
+
}, [socket, disconnectSocket]);
|
|
1950
|
+
React.useEffect(() => {
|
|
1951
|
+
if (!parsedRoomId) return;
|
|
1952
|
+
(async () => {
|
|
1953
|
+
const url = await urlBuilder.buildControllerUrl(parsedRoomId, {
|
|
1954
|
+
host: config.publicHost
|
|
1955
|
+
});
|
|
1956
|
+
setJoinUrl(url);
|
|
1957
|
+
})();
|
|
1958
|
+
}, [parsedRoomId, config.publicHost, options.roomId]);
|
|
1959
|
+
const setRegisteredRoomId = zustand.useStore(store, (s) => s.setRegisteredRoomId);
|
|
1960
|
+
React.useEffect(() => {
|
|
1961
|
+
const storeState = store.getState();
|
|
1962
|
+
storeState.setMode(detectRunMode());
|
|
1963
|
+
storeState.setRole("host");
|
|
1964
|
+
if (parsedRoomId) {
|
|
1965
|
+
storeState.setRoomId(parsedRoomId);
|
|
2083
1966
|
}
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
case "connecting":
|
|
2090
|
-
case "reconnecting":
|
|
2091
|
-
return "secondary";
|
|
2092
|
-
default:
|
|
2093
|
-
return "destructive";
|
|
1967
|
+
storeState.setStatus("connecting");
|
|
1968
|
+
storeState.setError(void 0);
|
|
1969
|
+
if (!socket) {
|
|
1970
|
+
storeState.setStatus("idle");
|
|
1971
|
+
return;
|
|
2094
1972
|
}
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs tracking-[0.18em] uppercase", children: "Room" }),
|
|
2101
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-foreground text-lg font-semibold", children: roomId })
|
|
2102
|
-
] }) }),
|
|
2103
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
2104
|
-
players.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center -space-x-2", children: [
|
|
2105
|
-
players.slice(0, 4).map((player) => /* @__PURE__ */ jsxRuntime.jsx(PlayerAvatar, { player, size: "sm" }, player.id)),
|
|
2106
|
-
players.length > 4 && /* @__PURE__ */ jsxRuntime.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: [
|
|
2107
|
-
"+",
|
|
2108
|
-
players.length - 4
|
|
2109
|
-
] })
|
|
2110
|
-
] }),
|
|
2111
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2112
|
-
Button,
|
|
2113
|
-
{
|
|
2114
|
-
type: "button",
|
|
2115
|
-
variant: "ghost",
|
|
2116
|
-
size: "icon",
|
|
2117
|
-
onClick: toggleGameState,
|
|
2118
|
-
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
2119
|
-
className: "h-8 w-8",
|
|
2120
|
-
children: gameState === "playing" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "h-4 w-4" })
|
|
2121
|
-
}
|
|
2122
|
-
)
|
|
2123
|
-
] })
|
|
2124
|
-
] }) }) }),
|
|
2125
|
-
gameState === "paused" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none fixed inset-0 z-99998 flex items-center justify-center p-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-auto w-full max-w-2xl", children: /* @__PURE__ */ jsxRuntime.jsx(Card, { className: "bg-card/20 flex max-h-[85vh] flex-col overflow-hidden border py-0 shadow-lg backdrop-blur-sm", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2126
|
-
Tabs,
|
|
2127
|
-
{
|
|
2128
|
-
defaultValue: isChildMode ? "settings" : "room-code",
|
|
2129
|
-
className: "flex h-full w-full flex-col gap-0",
|
|
2130
|
-
children: [
|
|
2131
|
-
/* @__PURE__ */ jsxRuntime.jsxs(TabsList, { className: "border-border grid w-full shrink-0 grid-cols-2 rounded-none border-b bg-transparent p-0", children: [
|
|
2132
|
-
!isChildMode && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2133
|
-
TabsTrigger,
|
|
2134
|
-
{
|
|
2135
|
-
value: "room-code",
|
|
2136
|
-
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2137
|
-
children: [
|
|
2138
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.QrCode, { className: "h-4 w-4" }),
|
|
2139
|
-
"Room Code"
|
|
2140
|
-
]
|
|
2141
|
-
}
|
|
2142
|
-
),
|
|
2143
|
-
isChildMode && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2144
|
-
TabsTrigger,
|
|
2145
|
-
{
|
|
2146
|
-
value: "info",
|
|
2147
|
-
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2148
|
-
children: [
|
|
2149
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.MonitorSmartphone, { className: "h-4 w-4" }),
|
|
2150
|
-
"Platform"
|
|
2151
|
-
]
|
|
2152
|
-
}
|
|
2153
|
-
),
|
|
2154
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2155
|
-
TabsTrigger,
|
|
2156
|
-
{
|
|
2157
|
-
value: "settings",
|
|
2158
|
-
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2159
|
-
children: [
|
|
2160
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Settings, { className: "h-4 w-4" }),
|
|
2161
|
-
"Settings"
|
|
2162
|
-
]
|
|
2163
|
-
}
|
|
2164
|
-
)
|
|
2165
|
-
] }),
|
|
2166
|
-
!isChildMode && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2167
|
-
TabsContent,
|
|
2168
|
-
{
|
|
2169
|
-
value: "room-code",
|
|
2170
|
-
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2171
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-[auto_1fr]", children: [
|
|
2172
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start gap-4", children: [
|
|
2173
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
2174
|
-
/* @__PURE__ */ jsxRuntime.jsx(CardTitle, { className: "text-3xl font-bold tracking-wider", children: roomId }),
|
|
2175
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2176
|
-
Badge,
|
|
2177
|
-
{
|
|
2178
|
-
variant: connectionVariant,
|
|
2179
|
-
className: "w-fit",
|
|
2180
|
-
children: statusCopy[connectionStatus]
|
|
2181
|
-
}
|
|
2182
|
-
)
|
|
2183
|
-
] }),
|
|
2184
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-border bg-card w-48 shrink-0 overflow-hidden rounded-lg border-2 shadow-md", children: qrUrl ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2185
|
-
"img",
|
|
2186
|
-
{
|
|
2187
|
-
src: qrUrl,
|
|
2188
|
-
alt: `Join room ${roomId}`,
|
|
2189
|
-
className: "w-full rounded bg-white"
|
|
2190
|
-
}
|
|
2191
|
-
) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-muted-foreground flex h-48 items-center justify-center text-sm", children: qrError ? `QR failed: ${qrError}` : "Generating QR code\u2026" }) })
|
|
2192
|
-
] }),
|
|
2193
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
2194
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
|
|
2195
|
-
/* @__PURE__ */ jsxRuntime.jsx(CardDescription, { className: "text-xs tracking-[0.18em] uppercase", children: "Join URL" }),
|
|
2196
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
2197
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2198
|
-
"input",
|
|
2199
|
-
{
|
|
2200
|
-
type: "text",
|
|
2201
|
-
readOnly: true,
|
|
2202
|
-
value: joinUrl,
|
|
2203
|
-
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"
|
|
2204
|
-
}
|
|
2205
|
-
),
|
|
2206
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2207
|
-
Button,
|
|
2208
|
-
{
|
|
2209
|
-
type: "button",
|
|
2210
|
-
variant: "outline",
|
|
2211
|
-
size: "icon",
|
|
2212
|
-
onClick: handleCopyUrl,
|
|
2213
|
-
className: "h-10 shrink-0",
|
|
2214
|
-
"aria-label": "Copy join URL",
|
|
2215
|
-
children: copied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "h-4 w-4" })
|
|
2216
|
-
}
|
|
2217
|
-
),
|
|
2218
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2219
|
-
Button,
|
|
2220
|
-
{
|
|
2221
|
-
type: "button",
|
|
2222
|
-
variant: "outline",
|
|
2223
|
-
size: "icon",
|
|
2224
|
-
onClick: handleOpenInNewTab,
|
|
2225
|
-
className: "h-10 shrink-0",
|
|
2226
|
-
"aria-label": "Open join URL in new tab",
|
|
2227
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ExternalLink, { className: "h-4 w-4" })
|
|
2228
|
-
}
|
|
2229
|
-
)
|
|
2230
|
-
] })
|
|
2231
|
-
] }),
|
|
2232
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: players.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-white", children: "Waiting for controllers to join\u2026" }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2233
|
-
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-foreground text-sm font-medium", children: [
|
|
2234
|
-
"Connected Players (",
|
|
2235
|
-
players.length,
|
|
2236
|
-
")"
|
|
2237
|
-
] }),
|
|
2238
|
-
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: players.map((player) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2239
|
-
"li",
|
|
2240
|
-
{
|
|
2241
|
-
className: "flex min-w-0 flex-col items-start gap-2",
|
|
2242
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full min-w-0 items-center gap-2", children: [
|
|
2243
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2244
|
-
PlayerAvatar,
|
|
2245
|
-
{
|
|
2246
|
-
player,
|
|
2247
|
-
size: "md"
|
|
2248
|
-
}
|
|
2249
|
-
),
|
|
2250
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5 overflow-hidden", children: [
|
|
2251
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-card-foreground truncate text-sm font-medium", children: player.label }),
|
|
2252
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2253
|
-
"div",
|
|
2254
|
-
{
|
|
2255
|
-
onClick: () => handleCopyPlayerId(player.id),
|
|
2256
|
-
className: "text-muted-foreground m-0 inline min-w-0 cursor-pointer truncate border-0 font-mono text-xs transition-colors hover:text-white",
|
|
2257
|
-
title: "Click to copy player ID",
|
|
2258
|
-
children: copiedPlayerId === player.id ? "Copied!" : player.id.slice(0, 8)
|
|
2259
|
-
}
|
|
2260
|
-
)
|
|
2261
|
-
] })
|
|
2262
|
-
] })
|
|
2263
|
-
},
|
|
2264
|
-
player.id
|
|
2265
|
-
)) })
|
|
2266
|
-
] }) }),
|
|
2267
|
-
lastError && /* @__PURE__ */ jsxRuntime.jsx(Alert, { variant: "destructive", className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsx(AlertDescription, { children: lastError }) }),
|
|
2268
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-auto flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2269
|
-
Button,
|
|
2270
|
-
{
|
|
2271
|
-
type: "button",
|
|
2272
|
-
onClick: toggleGameState,
|
|
2273
|
-
size: "lg",
|
|
2274
|
-
children: [
|
|
2275
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "mr-2 h-5 w-5" }),
|
|
2276
|
-
"Start Game"
|
|
2277
|
-
]
|
|
2278
|
-
}
|
|
2279
|
-
) })
|
|
2280
|
-
] })
|
|
2281
|
-
] }) })
|
|
2282
|
-
}
|
|
2283
|
-
),
|
|
2284
|
-
isChildMode && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2285
|
-
TabsContent,
|
|
2286
|
-
{
|
|
2287
|
-
value: "info",
|
|
2288
|
-
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2289
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6", children: [
|
|
2290
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
2291
|
-
/* @__PURE__ */ jsxRuntime.jsx(CardTitle, { className: "text-2xl font-bold tracking-wider", children: "Connected to Platform" }),
|
|
2292
|
-
/* @__PURE__ */ jsxRuntime.jsx(CardDescription, { children: "This game is running inside the Air Jam Platform." })
|
|
2293
|
-
] }),
|
|
2294
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
|
|
2295
|
-
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-foreground text-sm font-medium", children: [
|
|
2296
|
-
"Connected Players (",
|
|
2297
|
-
players.length,
|
|
2298
|
-
")"
|
|
2299
|
-
] }),
|
|
2300
|
-
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: players.map((player) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2301
|
-
"li",
|
|
2302
|
-
{
|
|
2303
|
-
className: "flex min-w-0 flex-col items-start gap-2",
|
|
2304
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full min-w-0 items-center gap-2", children: [
|
|
2305
|
-
/* @__PURE__ */ jsxRuntime.jsx(PlayerAvatar, { player, size: "md" }),
|
|
2306
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-card-foreground truncate text-sm font-medium", children: player.label }) })
|
|
2307
|
-
] })
|
|
2308
|
-
},
|
|
2309
|
-
player.id
|
|
2310
|
-
)) })
|
|
2311
|
-
] }),
|
|
2312
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2313
|
-
Button,
|
|
2314
|
-
{
|
|
2315
|
-
type: "button",
|
|
2316
|
-
onClick: toggleGameState,
|
|
2317
|
-
size: "lg",
|
|
2318
|
-
children: [
|
|
2319
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "mr-2 h-5 w-5" }),
|
|
2320
|
-
"Resume Game"
|
|
2321
|
-
]
|
|
2322
|
-
}
|
|
2323
|
-
) })
|
|
2324
|
-
] }) })
|
|
2325
|
-
}
|
|
2326
|
-
),
|
|
2327
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2328
|
-
TabsContent,
|
|
2329
|
-
{
|
|
2330
|
-
value: "settings",
|
|
2331
|
-
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2332
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(CardContent, { className: "pt-6 pb-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6", children: [
|
|
2333
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-4", children: /* @__PURE__ */ jsxRuntime.jsx(VolumeControls, {}) }),
|
|
2334
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
2335
|
-
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold", children: "Connection" }),
|
|
2336
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
2337
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2338
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Status" }),
|
|
2339
|
-
/* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: connectionVariant, children: statusCopy[connectionStatus] })
|
|
2340
|
-
] }),
|
|
2341
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2342
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Room ID" }),
|
|
2343
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono text-sm", children: roomId })
|
|
2344
|
-
] }),
|
|
2345
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2346
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Players" }),
|
|
2347
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: players.length })
|
|
2348
|
-
] })
|
|
2349
|
-
] })
|
|
2350
|
-
] }),
|
|
2351
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
2352
|
-
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold", children: "Display" }),
|
|
2353
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2354
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Game State" }),
|
|
2355
|
-
/* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "outline", className: "capitalize", children: gameState })
|
|
2356
|
-
] }) })
|
|
2357
|
-
] })
|
|
2358
|
-
] }) })
|
|
2359
|
-
}
|
|
2360
|
-
)
|
|
2361
|
-
]
|
|
2362
|
-
}
|
|
2363
|
-
) }) }) })
|
|
2364
|
-
] });
|
|
2365
|
-
};
|
|
2366
|
-
var useFullscreen = () => {
|
|
2367
|
-
const [isFullscreen, setIsFullscreen] = React.useState(false);
|
|
2368
|
-
React.useEffect(() => {
|
|
2369
|
-
const handleFullscreenChange = () => {
|
|
2370
|
-
const doc = document;
|
|
2371
|
-
setIsFullscreen(
|
|
2372
|
-
!!(document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement)
|
|
2373
|
-
);
|
|
2374
|
-
};
|
|
2375
|
-
document.addEventListener("fullscreenchange", handleFullscreenChange);
|
|
2376
|
-
document.addEventListener("webkitfullscreenchange", handleFullscreenChange);
|
|
2377
|
-
document.addEventListener("mozfullscreenchange", handleFullscreenChange);
|
|
2378
|
-
document.addEventListener("msfullscreenchange", handleFullscreenChange);
|
|
2379
|
-
return () => {
|
|
2380
|
-
document.removeEventListener("fullscreenchange", handleFullscreenChange);
|
|
2381
|
-
document.removeEventListener(
|
|
2382
|
-
"webkitfullscreenchange",
|
|
2383
|
-
handleFullscreenChange
|
|
2384
|
-
);
|
|
2385
|
-
document.removeEventListener(
|
|
2386
|
-
"mozfullscreenchange",
|
|
2387
|
-
handleFullscreenChange
|
|
2388
|
-
);
|
|
2389
|
-
document.removeEventListener(
|
|
2390
|
-
"msfullscreenchange",
|
|
2391
|
-
handleFullscreenChange
|
|
2392
|
-
);
|
|
2393
|
-
};
|
|
2394
|
-
}, []);
|
|
2395
|
-
const exitFullscreen = React.useCallback(async () => {
|
|
2396
|
-
try {
|
|
2397
|
-
const doc = document;
|
|
2398
|
-
if (document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement) {
|
|
2399
|
-
if (document.exitFullscreen) {
|
|
2400
|
-
await document.exitFullscreen();
|
|
2401
|
-
} else if (doc.webkitExitFullscreen) {
|
|
2402
|
-
await doc.webkitExitFullscreen();
|
|
2403
|
-
} else if (doc.mozCancelFullScreen) {
|
|
2404
|
-
await doc.mozCancelFullScreen();
|
|
2405
|
-
} else if (doc.msExitFullscreen) {
|
|
2406
|
-
await doc.msExitFullscreen();
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
} catch (error) {
|
|
2410
|
-
console.error("Error exiting fullscreen:", error);
|
|
2411
|
-
}
|
|
2412
|
-
}, []);
|
|
2413
|
-
const enterFullscreen = React.useCallback(async (element) => {
|
|
2414
|
-
try {
|
|
2415
|
-
const elem = element || document.documentElement;
|
|
2416
|
-
if (elem.requestFullscreen) {
|
|
2417
|
-
await elem.requestFullscreen();
|
|
2418
|
-
} else if (elem.webkitRequestFullscreen) {
|
|
2419
|
-
await elem.webkitRequestFullscreen();
|
|
2420
|
-
} else if (elem.mozRequestFullScreen) {
|
|
2421
|
-
await elem.mozRequestFullScreen();
|
|
2422
|
-
} else if (elem.msRequestFullscreen) {
|
|
2423
|
-
await elem.msRequestFullscreen();
|
|
2424
|
-
}
|
|
2425
|
-
} catch (error) {
|
|
2426
|
-
console.error("Error entering fullscreen:", error);
|
|
2427
|
-
}
|
|
2428
|
-
}, []);
|
|
2429
|
-
const toggleFullscreen = React.useCallback(
|
|
2430
|
-
async (element) => {
|
|
2431
|
-
if (isFullscreen) {
|
|
2432
|
-
await exitFullscreen();
|
|
2433
|
-
} else {
|
|
2434
|
-
await enterFullscreen(element);
|
|
2435
|
-
}
|
|
2436
|
-
},
|
|
2437
|
-
[isFullscreen, exitFullscreen, enterFullscreen]
|
|
2438
|
-
);
|
|
2439
|
-
return {
|
|
2440
|
-
isFullscreen,
|
|
2441
|
-
enterFullscreen,
|
|
2442
|
-
exitFullscreen,
|
|
2443
|
-
toggleFullscreen
|
|
2444
|
-
};
|
|
2445
|
-
};
|
|
2446
|
-
var extractRoomCode = (text) => {
|
|
2447
|
-
try {
|
|
2448
|
-
const url = new URL(text);
|
|
2449
|
-
const roomParam = url.searchParams.get("room");
|
|
2450
|
-
if (roomParam) {
|
|
2451
|
-
const parsed2 = roomCodeSchema.safeParse(roomParam.toUpperCase());
|
|
2452
|
-
if (parsed2.success) {
|
|
2453
|
-
return parsed2.data;
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
} catch {
|
|
2457
|
-
}
|
|
2458
|
-
const parsed = roomCodeSchema.safeParse(text.trim().toUpperCase());
|
|
2459
|
-
if (parsed.success) {
|
|
2460
|
-
return parsed.data;
|
|
2461
|
-
}
|
|
2462
|
-
return null;
|
|
2463
|
-
};
|
|
2464
|
-
var QRScannerDialog = ({
|
|
2465
|
-
isOpen,
|
|
2466
|
-
onClose,
|
|
2467
|
-
onScan,
|
|
2468
|
-
currentRoomId
|
|
2469
|
-
}) => {
|
|
2470
|
-
const [code, setCode] = React.useState("");
|
|
2471
|
-
const [isCameraAvailable, setIsCameraAvailable] = React.useState(false);
|
|
2472
|
-
const [joinUrl, setJoinUrl] = React.useState("");
|
|
2473
|
-
const [copied, setCopied] = React.useState(false);
|
|
2474
|
-
const scannerRef = React.useRef(null);
|
|
2475
|
-
const inputRef = React.useRef(null);
|
|
2476
|
-
const prevIsOpenRef = React.useRef(false);
|
|
2477
|
-
React.useEffect(() => {
|
|
2478
|
-
if (isOpen && !prevIsOpenRef.current) {
|
|
2479
|
-
const initialCode = currentRoomId || "";
|
|
2480
|
-
setTimeout(() => {
|
|
2481
|
-
setIsCameraAvailable(false);
|
|
2482
|
-
setCode(initialCode);
|
|
2483
|
-
inputRef.current?.focus();
|
|
2484
|
-
inputRef.current?.select();
|
|
2485
|
-
}, 0);
|
|
2486
|
-
}
|
|
2487
|
-
prevIsOpenRef.current = isOpen;
|
|
2488
|
-
}, [isOpen, currentRoomId]);
|
|
2489
|
-
React.useEffect(() => {
|
|
2490
|
-
const buildUrl = async () => {
|
|
2491
|
-
const trimmed = code.trim().toUpperCase();
|
|
2492
|
-
const parsed = roomCodeSchema.safeParse(trimmed);
|
|
2493
|
-
if (parsed.success) {
|
|
2494
|
-
try {
|
|
2495
|
-
const url = await urlBuilder.buildControllerUrl(parsed.data);
|
|
2496
|
-
setJoinUrl(url);
|
|
2497
|
-
} catch {
|
|
2498
|
-
setJoinUrl("");
|
|
2499
|
-
}
|
|
2500
|
-
} else {
|
|
2501
|
-
setJoinUrl("");
|
|
1973
|
+
const registerHost = async () => {
|
|
1974
|
+
const storeState2 = store.getState();
|
|
1975
|
+
const currentRegisteredRoomId2 = store.getState().registeredRoomId;
|
|
1976
|
+
if (currentRegisteredRoomId2 && socket.connected) {
|
|
1977
|
+
return;
|
|
2502
1978
|
}
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
} catch {
|
|
1979
|
+
if (arcadeParams) {
|
|
1980
|
+
const childRoomId = roomCodeSchema.parse(
|
|
1981
|
+
arcadeParams.room.toUpperCase()
|
|
1982
|
+
);
|
|
1983
|
+
const payload = {
|
|
1984
|
+
roomId: childRoomId,
|
|
1985
|
+
joinToken: arcadeParams.token
|
|
1986
|
+
};
|
|
1987
|
+
socket.emit("host:joinAsChild", payload, (ack) => {
|
|
1988
|
+
if (!ack.ok) {
|
|
1989
|
+
storeState2.setError(ack.message ?? "Failed to join as child");
|
|
1990
|
+
storeState2.setStatus("disconnected");
|
|
1991
|
+
setRegisteredRoomId(null);
|
|
1992
|
+
return;
|
|
2518
1993
|
}
|
|
1994
|
+
storeState2.setStatus("connected");
|
|
1995
|
+
storeState2.setRoomId(childRoomId);
|
|
1996
|
+
setRegisteredRoomId(childRoomId);
|
|
2519
1997
|
});
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
const label = d.label.toLowerCase();
|
|
2553
|
-
return label.includes("environment") || label.includes("facing back");
|
|
1998
|
+
} else {
|
|
1999
|
+
const createNewRoom = () => {
|
|
2000
|
+
const payload = hostCreateRoomSchema.parse({
|
|
2001
|
+
maxPlayers: options.maxPlayers ?? config.maxPlayers,
|
|
2002
|
+
apiKey: options.apiKey ?? config.apiKey
|
|
2003
|
+
});
|
|
2004
|
+
socket.emit("host:createRoom", payload, (ack) => {
|
|
2005
|
+
if (!ack.ok) {
|
|
2006
|
+
storeState2.setError(ack.message ?? "Failed to create room");
|
|
2007
|
+
storeState2.setStatus("disconnected");
|
|
2008
|
+
setRegisteredRoomId(null);
|
|
2009
|
+
return;
|
|
2010
|
+
}
|
|
2011
|
+
if (ack.roomId) {
|
|
2012
|
+
storeState2.setStatus("connected");
|
|
2013
|
+
storeState2.setRoomId(ack.roomId);
|
|
2014
|
+
setRegisteredRoomId(ack.roomId);
|
|
2015
|
+
if (typeof window !== "undefined") {
|
|
2016
|
+
sessionStorage.setItem("airjam_room_id", ack.roomId);
|
|
2017
|
+
}
|
|
2018
|
+
} else {
|
|
2019
|
+
storeState2.setError("Server did not return room ID");
|
|
2020
|
+
storeState2.setStatus("disconnected");
|
|
2021
|
+
}
|
|
2022
|
+
});
|
|
2023
|
+
};
|
|
2024
|
+
if (typeof window !== "undefined") {
|
|
2025
|
+
const savedRoomId = sessionStorage.getItem("airjam_room_id");
|
|
2026
|
+
if (savedRoomId) {
|
|
2027
|
+
const reconnectPayload = hostReconnectSchema.parse({
|
|
2028
|
+
roomId: savedRoomId,
|
|
2029
|
+
apiKey: options.apiKey ?? config.apiKey
|
|
2554
2030
|
});
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
fps: 10,
|
|
2564
|
-
qrbox: (viewfinderWidth, viewfinderHeight) => {
|
|
2565
|
-
const minEdge = Math.min(viewfinderWidth, viewfinderHeight);
|
|
2566
|
-
const qrboxSize = Math.min(250, minEdge * 0.8);
|
|
2567
|
-
return {
|
|
2568
|
-
width: qrboxSize,
|
|
2569
|
-
height: qrboxSize
|
|
2570
|
-
};
|
|
2571
|
-
},
|
|
2572
|
-
aspectRatio: 1
|
|
2573
|
-
},
|
|
2574
|
-
(decodedText) => {
|
|
2575
|
-
if (!mounted) return;
|
|
2576
|
-
const roomCode = extractRoomCode(decodedText);
|
|
2577
|
-
if (roomCode) {
|
|
2578
|
-
setCode(roomCode);
|
|
2579
|
-
scannerRunning = false;
|
|
2580
|
-
scanner?.stop().catch(() => {
|
|
2581
|
-
}).finally(() => {
|
|
2582
|
-
if (mounted) {
|
|
2583
|
-
setIsCameraAvailable(false);
|
|
2031
|
+
socket.emit("host:reconnect", reconnectPayload, (ack) => {
|
|
2032
|
+
if (ack.ok && ack.roomId) {
|
|
2033
|
+
storeState2.setStatus("connected");
|
|
2034
|
+
storeState2.setRoomId(ack.roomId);
|
|
2035
|
+
setRegisteredRoomId(ack.roomId);
|
|
2036
|
+
} else {
|
|
2037
|
+
if (typeof window !== "undefined") {
|
|
2038
|
+
sessionStorage.removeItem("airjam_room_id");
|
|
2584
2039
|
}
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
);
|
|
2591
|
-
scannerRunning = true;
|
|
2592
|
-
if (mounted) {
|
|
2593
|
-
setIsCameraAvailable(true);
|
|
2594
|
-
}
|
|
2595
|
-
} catch {
|
|
2596
|
-
if (mounted) {
|
|
2597
|
-
setIsCameraAvailable(false);
|
|
2598
|
-
}
|
|
2599
|
-
if (scanner) {
|
|
2600
|
-
try {
|
|
2601
|
-
scanner.clear();
|
|
2602
|
-
} catch {
|
|
2040
|
+
createNewRoom();
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
} else {
|
|
2044
|
+
createNewRoom();
|
|
2603
2045
|
}
|
|
2046
|
+
} else {
|
|
2047
|
+
createNewRoom();
|
|
2604
2048
|
}
|
|
2605
|
-
scannerRef.current = null;
|
|
2606
2049
|
}
|
|
2607
2050
|
};
|
|
2608
|
-
const
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2051
|
+
const handleConnect = () => {
|
|
2052
|
+
store.getState().setStatus("connected");
|
|
2053
|
+
registerHost();
|
|
2054
|
+
};
|
|
2055
|
+
const handleDisconnect = () => {
|
|
2056
|
+
store.getState().setStatus("disconnected");
|
|
2057
|
+
};
|
|
2058
|
+
const handleJoin = (payload) => {
|
|
2059
|
+
if (payload.player) {
|
|
2060
|
+
store.getState().upsertPlayer(payload.player);
|
|
2061
|
+
setTimeout(() => {
|
|
2062
|
+
onPlayerJoinRef.current?.(payload.player);
|
|
2063
|
+
}, 0);
|
|
2064
|
+
}
|
|
2065
|
+
};
|
|
2066
|
+
const handleLeave = (payload) => {
|
|
2067
|
+
store.getState().removePlayer(payload.controllerId);
|
|
2068
|
+
onPlayerLeaveRef.current?.(payload.controllerId);
|
|
2069
|
+
};
|
|
2070
|
+
const handleInput = (payload) => {
|
|
2071
|
+
if (inputManager) {
|
|
2072
|
+
inputManager.handleInput(payload);
|
|
2627
2073
|
}
|
|
2628
|
-
scannerRef.current = null;
|
|
2629
2074
|
};
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
const
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2075
|
+
const handleChildClose = () => {
|
|
2076
|
+
onChildCloseRef.current?.();
|
|
2077
|
+
};
|
|
2078
|
+
const handleState = (payload) => {
|
|
2079
|
+
if (!parsedRoomId || payload.roomId !== parsedRoomId) return;
|
|
2080
|
+
const storeState2 = store.getState();
|
|
2081
|
+
if (payload.state.gameState) {
|
|
2082
|
+
storeState2.setGameState(payload.state.gameState);
|
|
2083
|
+
}
|
|
2084
|
+
if (payload.state.message !== void 0) {
|
|
2085
|
+
storeState2.setStateMessage(payload.state.message);
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
const handleError = (payload) => {
|
|
2089
|
+
store.getState().setError(payload.message);
|
|
2090
|
+
};
|
|
2091
|
+
socket.on("connect", handleConnect);
|
|
2092
|
+
socket.on("disconnect", handleDisconnect);
|
|
2093
|
+
socket.on("server:controllerJoined", handleJoin);
|
|
2094
|
+
socket.on("server:controllerLeft", handleLeave);
|
|
2095
|
+
socket.on("server:input", handleInput);
|
|
2096
|
+
socket.on("server:error", handleError);
|
|
2097
|
+
socket.on("server:closeChild", handleChildClose);
|
|
2098
|
+
socket.on("server:state", handleState);
|
|
2099
|
+
socket.connect();
|
|
2100
|
+
const currentRegisteredRoomId = store.getState().registeredRoomId;
|
|
2101
|
+
if (socket.connected && !currentRegisteredRoomId) {
|
|
2102
|
+
registerHost();
|
|
2637
2103
|
}
|
|
2104
|
+
return () => {
|
|
2105
|
+
socket.off("connect", handleConnect);
|
|
2106
|
+
socket.off("disconnect", handleDisconnect);
|
|
2107
|
+
socket.off("server:controllerJoined", handleJoin);
|
|
2108
|
+
socket.off("server:controllerLeft", handleLeave);
|
|
2109
|
+
socket.off("server:input", handleInput);
|
|
2110
|
+
socket.off("server:error", handleError);
|
|
2111
|
+
socket.off("server:closeChild", handleChildClose);
|
|
2112
|
+
socket.off("server:state", handleState);
|
|
2113
|
+
};
|
|
2114
|
+
}, [
|
|
2115
|
+
config.maxPlayers,
|
|
2116
|
+
config.apiKey,
|
|
2117
|
+
options.maxPlayers,
|
|
2118
|
+
options.apiKey,
|
|
2119
|
+
arcadeParams,
|
|
2120
|
+
parsedRoomId,
|
|
2121
|
+
// Include parsedRoomId since it's used in handleState callback
|
|
2122
|
+
shouldConnect,
|
|
2123
|
+
socket,
|
|
2124
|
+
store,
|
|
2125
|
+
inputManager,
|
|
2126
|
+
setRegisteredRoomId
|
|
2127
|
+
]);
|
|
2128
|
+
const returnSocket = socket ?? getSocket("host");
|
|
2129
|
+
const getInput = React.useCallback(
|
|
2130
|
+
(controllerId) => {
|
|
2131
|
+
if (!inputManager) {
|
|
2132
|
+
return void 0;
|
|
2133
|
+
}
|
|
2134
|
+
return inputManager.getInput(controllerId);
|
|
2135
|
+
},
|
|
2136
|
+
[inputManager]
|
|
2137
|
+
);
|
|
2138
|
+
return {
|
|
2139
|
+
roomId: parsedRoomId ?? "",
|
|
2140
|
+
// Return empty string as fallback if not yet available
|
|
2141
|
+
joinUrl,
|
|
2142
|
+
connectionStatus: connectionState.connectionStatus,
|
|
2143
|
+
players: connectionState.players,
|
|
2144
|
+
lastError: connectionState.lastError,
|
|
2145
|
+
mode: connectionState.mode,
|
|
2146
|
+
gameState: connectionState.gameState,
|
|
2147
|
+
toggleGameState,
|
|
2148
|
+
sendState,
|
|
2149
|
+
sendSignal,
|
|
2150
|
+
reconnect,
|
|
2151
|
+
socket: returnSocket,
|
|
2152
|
+
isChildMode,
|
|
2153
|
+
getInput
|
|
2638
2154
|
};
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
if (!joinUrl) return;
|
|
2648
|
-
try {
|
|
2649
|
-
await navigator.clipboard.writeText(joinUrl);
|
|
2650
|
-
setCopied(true);
|
|
2651
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
2652
|
-
} catch {
|
|
2653
|
-
const textArea = document.createElement("textarea");
|
|
2654
|
-
textArea.value = joinUrl;
|
|
2655
|
-
textArea.style.position = "fixed";
|
|
2656
|
-
textArea.style.opacity = "0";
|
|
2657
|
-
document.body.appendChild(textArea);
|
|
2658
|
-
textArea.select();
|
|
2659
|
-
try {
|
|
2660
|
-
document.execCommand("copy");
|
|
2661
|
-
setCopied(true);
|
|
2662
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
2663
|
-
} catch {
|
|
2155
|
+
};
|
|
2156
|
+
var alertVariants = classVarianceAuthority.cva(
|
|
2157
|
+
"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",
|
|
2158
|
+
{
|
|
2159
|
+
variants: {
|
|
2160
|
+
variant: {
|
|
2161
|
+
default: "bg-card text-card-foreground",
|
|
2162
|
+
destructive: "text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"
|
|
2664
2163
|
}
|
|
2665
|
-
|
|
2164
|
+
},
|
|
2165
|
+
defaultVariants: {
|
|
2166
|
+
variant: "default"
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
);
|
|
2170
|
+
function Alert({
|
|
2171
|
+
className,
|
|
2172
|
+
variant,
|
|
2173
|
+
...props
|
|
2174
|
+
}) {
|
|
2175
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2176
|
+
"div",
|
|
2177
|
+
{
|
|
2178
|
+
"data-slot": "alert",
|
|
2179
|
+
role: "alert",
|
|
2180
|
+
className: cn(alertVariants({ variant }), className),
|
|
2181
|
+
...props
|
|
2182
|
+
}
|
|
2183
|
+
);
|
|
2184
|
+
}
|
|
2185
|
+
function AlertDescription({
|
|
2186
|
+
className,
|
|
2187
|
+
...props
|
|
2188
|
+
}) {
|
|
2189
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2190
|
+
"div",
|
|
2191
|
+
{
|
|
2192
|
+
"data-slot": "alert-description",
|
|
2193
|
+
className: cn(
|
|
2194
|
+
"text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",
|
|
2195
|
+
className
|
|
2196
|
+
),
|
|
2197
|
+
...props
|
|
2198
|
+
}
|
|
2199
|
+
);
|
|
2200
|
+
}
|
|
2201
|
+
var badgeVariants = classVarianceAuthority.cva(
|
|
2202
|
+
"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",
|
|
2203
|
+
{
|
|
2204
|
+
variants: {
|
|
2205
|
+
variant: {
|
|
2206
|
+
default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
|
2207
|
+
secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
|
2208
|
+
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",
|
|
2209
|
+
outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
|
|
2210
|
+
}
|
|
2211
|
+
},
|
|
2212
|
+
defaultVariants: {
|
|
2213
|
+
variant: "default"
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
);
|
|
2217
|
+
function Badge({
|
|
2218
|
+
className,
|
|
2219
|
+
variant,
|
|
2220
|
+
asChild = false,
|
|
2221
|
+
...props
|
|
2222
|
+
}) {
|
|
2223
|
+
const Comp = asChild ? reactSlot.Slot : "span";
|
|
2224
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2225
|
+
Comp,
|
|
2226
|
+
{
|
|
2227
|
+
"data-slot": "badge",
|
|
2228
|
+
className: cn(badgeVariants({ variant }), className),
|
|
2229
|
+
...props
|
|
2230
|
+
}
|
|
2231
|
+
);
|
|
2232
|
+
}
|
|
2233
|
+
function Card({ className, ...props }) {
|
|
2234
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2235
|
+
"div",
|
|
2236
|
+
{
|
|
2237
|
+
"data-slot": "card",
|
|
2238
|
+
className: cn(
|
|
2239
|
+
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
|
2240
|
+
className
|
|
2241
|
+
),
|
|
2242
|
+
...props
|
|
2243
|
+
}
|
|
2244
|
+
);
|
|
2245
|
+
}
|
|
2246
|
+
function CardTitle({ className, ...props }) {
|
|
2247
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2248
|
+
"div",
|
|
2249
|
+
{
|
|
2250
|
+
"data-slot": "card-title",
|
|
2251
|
+
className: cn("leading-none font-semibold", className),
|
|
2252
|
+
...props
|
|
2253
|
+
}
|
|
2254
|
+
);
|
|
2255
|
+
}
|
|
2256
|
+
function CardDescription({ className, ...props }) {
|
|
2257
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2258
|
+
"div",
|
|
2259
|
+
{
|
|
2260
|
+
"data-slot": "card-description",
|
|
2261
|
+
className: cn("text-muted-foreground text-sm", className),
|
|
2262
|
+
...props
|
|
2263
|
+
}
|
|
2264
|
+
);
|
|
2265
|
+
}
|
|
2266
|
+
function CardContent({ className, ...props }) {
|
|
2267
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2268
|
+
"div",
|
|
2269
|
+
{
|
|
2270
|
+
"data-slot": "card-content",
|
|
2271
|
+
className: cn("px-6", className),
|
|
2272
|
+
...props
|
|
2273
|
+
}
|
|
2274
|
+
);
|
|
2275
|
+
}
|
|
2276
|
+
function Tabs({
|
|
2277
|
+
className,
|
|
2278
|
+
...props
|
|
2279
|
+
}) {
|
|
2280
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2281
|
+
TabsPrimitive__namespace.Root,
|
|
2282
|
+
{
|
|
2283
|
+
"data-slot": "tabs",
|
|
2284
|
+
className: cn("flex flex-col gap-2", className),
|
|
2285
|
+
...props
|
|
2286
|
+
}
|
|
2287
|
+
);
|
|
2288
|
+
}
|
|
2289
|
+
function TabsList({
|
|
2290
|
+
className,
|
|
2291
|
+
...props
|
|
2292
|
+
}) {
|
|
2293
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2294
|
+
TabsPrimitive__namespace.List,
|
|
2295
|
+
{
|
|
2296
|
+
"data-slot": "tabs-list",
|
|
2297
|
+
className: cn(
|
|
2298
|
+
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
|
2299
|
+
className
|
|
2300
|
+
),
|
|
2301
|
+
...props
|
|
2666
2302
|
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
)
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2303
|
+
);
|
|
2304
|
+
}
|
|
2305
|
+
function TabsTrigger({
|
|
2306
|
+
className,
|
|
2307
|
+
...props
|
|
2308
|
+
}) {
|
|
2309
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2310
|
+
TabsPrimitive__namespace.Trigger,
|
|
2311
|
+
{
|
|
2312
|
+
"data-slot": "tabs-trigger",
|
|
2313
|
+
className: cn(
|
|
2314
|
+
"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",
|
|
2315
|
+
className
|
|
2316
|
+
),
|
|
2317
|
+
...props
|
|
2318
|
+
}
|
|
2319
|
+
);
|
|
2320
|
+
}
|
|
2321
|
+
function TabsContent({
|
|
2322
|
+
className,
|
|
2323
|
+
...props
|
|
2324
|
+
}) {
|
|
2325
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2326
|
+
TabsPrimitive__namespace.Content,
|
|
2327
|
+
{
|
|
2328
|
+
"data-slot": "tabs-content",
|
|
2329
|
+
className: cn("flex-1 outline-none", className),
|
|
2330
|
+
...props
|
|
2331
|
+
}
|
|
2332
|
+
);
|
|
2333
|
+
}
|
|
2334
|
+
function Slider({
|
|
2335
|
+
className,
|
|
2336
|
+
defaultValue,
|
|
2337
|
+
value,
|
|
2338
|
+
min = 0,
|
|
2339
|
+
max = 100,
|
|
2340
|
+
...props
|
|
2341
|
+
}) {
|
|
2342
|
+
const _values = React__namespace.useMemo(
|
|
2343
|
+
() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
|
|
2344
|
+
[value, defaultValue, min, max]
|
|
2345
|
+
);
|
|
2346
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2347
|
+
SliderPrimitive__namespace.Root,
|
|
2348
|
+
{
|
|
2349
|
+
"data-slot": "slider",
|
|
2350
|
+
defaultValue,
|
|
2351
|
+
value,
|
|
2352
|
+
min,
|
|
2353
|
+
max,
|
|
2354
|
+
className: cn(
|
|
2355
|
+
"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",
|
|
2356
|
+
className
|
|
2357
|
+
),
|
|
2358
|
+
...props,
|
|
2359
|
+
children: [
|
|
2360
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2361
|
+
SliderPrimitive__namespace.Track,
|
|
2362
|
+
{
|
|
2363
|
+
"data-slot": "slider-track",
|
|
2364
|
+
className: cn(
|
|
2365
|
+
"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"
|
|
2366
|
+
),
|
|
2367
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2368
|
+
SliderPrimitive__namespace.Range,
|
|
2369
|
+
{
|
|
2370
|
+
"data-slot": "slider-range",
|
|
2371
|
+
className: cn(
|
|
2372
|
+
"bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
|
|
2373
|
+
)
|
|
2374
|
+
}
|
|
2375
|
+
)
|
|
2376
|
+
}
|
|
2377
|
+
),
|
|
2378
|
+
Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2379
|
+
SliderPrimitive__namespace.Thumb,
|
|
2380
|
+
{
|
|
2381
|
+
"data-slot": "slider-thumb",
|
|
2382
|
+
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"
|
|
2693
2383
|
},
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2384
|
+
index
|
|
2385
|
+
))
|
|
2386
|
+
]
|
|
2387
|
+
}
|
|
2388
|
+
);
|
|
2389
|
+
}
|
|
2390
|
+
function VolumeControls({ className, compact }) {
|
|
2391
|
+
const {
|
|
2392
|
+
masterVolume,
|
|
2393
|
+
musicVolume,
|
|
2394
|
+
sfxVolume,
|
|
2395
|
+
setMasterVolume,
|
|
2396
|
+
setMusicVolume,
|
|
2397
|
+
setSfxVolume
|
|
2398
|
+
} = useVolumeStore();
|
|
2399
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col gap-3", compact && "gap-1", className), children: [
|
|
2400
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2401
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Volume2, { className: "text-muted-foreground h-4 w-4" }),
|
|
2402
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: "Volume" })
|
|
2403
|
+
] }),
|
|
2404
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
|
|
2405
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2406
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-muted-foreground text-xs", children: "Master" }),
|
|
2407
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
2408
|
+
Math.round(masterVolume * 100),
|
|
2409
|
+
"%"
|
|
2410
|
+
] })
|
|
2411
|
+
] }),
|
|
2412
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2413
|
+
Slider,
|
|
2702
2414
|
{
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2415
|
+
value: [masterVolume * 100],
|
|
2416
|
+
onValueChange: (values) => setMasterVolume(values[0] / 100),
|
|
2417
|
+
min: 0,
|
|
2418
|
+
max: 100,
|
|
2419
|
+
step: 1,
|
|
2420
|
+
className: "w-full",
|
|
2421
|
+
"aria-label": "Master volume"
|
|
2707
2422
|
}
|
|
2708
|
-
)
|
|
2423
|
+
)
|
|
2709
2424
|
] }),
|
|
2710
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
2425
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
|
|
2426
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2427
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
2428
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Music, { className: "text-muted-foreground h-3 w-3" }),
|
|
2429
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-muted-foreground text-xs", children: "Music" })
|
|
2430
|
+
] }),
|
|
2431
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
2432
|
+
Math.round(musicVolume * 100),
|
|
2433
|
+
"%"
|
|
2434
|
+
] })
|
|
2435
|
+
] }),
|
|
2711
2436
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2712
|
-
|
|
2437
|
+
Slider,
|
|
2713
2438
|
{
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2439
|
+
value: [musicVolume * 100],
|
|
2440
|
+
onValueChange: (values) => setMusicVolume(values[0] / 100),
|
|
2441
|
+
min: 0,
|
|
2442
|
+
max: 100,
|
|
2443
|
+
step: 1,
|
|
2444
|
+
className: "w-full",
|
|
2445
|
+
"aria-label": "Music volume"
|
|
2719
2446
|
}
|
|
2720
|
-
)
|
|
2447
|
+
)
|
|
2448
|
+
] }),
|
|
2449
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
|
|
2450
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2451
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
2452
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Headphones, { className: "text-muted-foreground h-3 w-3" }),
|
|
2453
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-muted-foreground text-xs", children: "SFX" })
|
|
2454
|
+
] }),
|
|
2455
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
2456
|
+
Math.round(sfxVolume * 100),
|
|
2457
|
+
"%"
|
|
2458
|
+
] })
|
|
2459
|
+
] }),
|
|
2721
2460
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2722
|
-
|
|
2461
|
+
Slider,
|
|
2723
2462
|
{
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2463
|
+
value: [sfxVolume * 100],
|
|
2464
|
+
onValueChange: (values) => setSfxVolume(values[0] / 100),
|
|
2465
|
+
min: 0,
|
|
2466
|
+
max: 100,
|
|
2467
|
+
step: 1,
|
|
2468
|
+
className: "w-full",
|
|
2469
|
+
"aria-label": "SFX volume"
|
|
2729
2470
|
}
|
|
2730
2471
|
)
|
|
2731
2472
|
] })
|
|
2732
2473
|
] });
|
|
2733
|
-
}
|
|
2734
|
-
var
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
connectionStatus,
|
|
2758
|
-
requiredOrientation = "landscape",
|
|
2759
|
-
children,
|
|
2760
|
-
gameState = "paused",
|
|
2761
|
-
onTogglePlayPause,
|
|
2762
|
-
onReconnect,
|
|
2763
|
-
onRefresh,
|
|
2764
|
-
customActions
|
|
2765
|
-
}) => {
|
|
2766
|
-
const isChildMode = React.useMemo(() => detectRunMode() === "platform", []);
|
|
2767
|
-
const [isOrientationOk, setOrientationOk] = React.useState(
|
|
2768
|
-
() => orientationMatches(requiredOrientation)
|
|
2769
|
-
);
|
|
2770
|
-
const [isScannerOpen, setIsScannerOpen] = React.useState(false);
|
|
2771
|
-
const { isFullscreen, toggleFullscreen } = useFullscreen();
|
|
2772
|
-
const { store } = useAirJamContext();
|
|
2773
|
-
const { controllerId, players } = zustand.useStore(
|
|
2774
|
-
store,
|
|
2775
|
-
shallow.useShallow(
|
|
2776
|
-
(state) => ({
|
|
2777
|
-
controllerId: state.controllerId,
|
|
2778
|
-
players: state.players
|
|
2779
|
-
})
|
|
2780
|
-
)
|
|
2781
|
-
);
|
|
2782
|
-
const currentPlayer = React.useMemo(() => {
|
|
2783
|
-
if (!controllerId) return null;
|
|
2784
|
-
const found = players.find((p) => p.id === controllerId);
|
|
2785
|
-
if (!found && connectionStatus === "connected" && players.length > 0) ;
|
|
2786
|
-
return found || null;
|
|
2787
|
-
}, [controllerId, players, connectionStatus]);
|
|
2474
|
+
}
|
|
2475
|
+
var statusCopy = {
|
|
2476
|
+
idle: "Idle",
|
|
2477
|
+
connecting: "Waiting for server\u2026",
|
|
2478
|
+
connected: "Ready for controllers",
|
|
2479
|
+
disconnected: "Disconnected",
|
|
2480
|
+
reconnecting: "Reconnecting\u2026"
|
|
2481
|
+
};
|
|
2482
|
+
var HostShell = ({ children }) => {
|
|
2483
|
+
const host = useAirJamHost();
|
|
2484
|
+
const {
|
|
2485
|
+
roomId,
|
|
2486
|
+
joinUrl,
|
|
2487
|
+
connectionStatus,
|
|
2488
|
+
players,
|
|
2489
|
+
lastError,
|
|
2490
|
+
gameState,
|
|
2491
|
+
toggleGameState,
|
|
2492
|
+
isChildMode
|
|
2493
|
+
} = host;
|
|
2494
|
+
const [qrUrl, setQrUrl] = React.useState(null);
|
|
2495
|
+
const [qrError, setQrError] = React.useState(null);
|
|
2496
|
+
const [copied, setCopied] = React.useState(false);
|
|
2497
|
+
const [copiedPlayerId, setCopiedPlayerId] = React.useState(null);
|
|
2788
2498
|
React.useEffect(() => {
|
|
2789
|
-
if (
|
|
2790
|
-
|
|
2499
|
+
if (isChildMode) return;
|
|
2500
|
+
let mounted = true;
|
|
2501
|
+
QRCode__default.default.toDataURL(joinUrl, {
|
|
2502
|
+
margin: 1,
|
|
2503
|
+
color: {
|
|
2504
|
+
dark: "#0f172a",
|
|
2505
|
+
light: "#ffffff"
|
|
2506
|
+
},
|
|
2507
|
+
width: 320
|
|
2508
|
+
}).then((value) => {
|
|
2509
|
+
if (mounted) {
|
|
2510
|
+
setQrUrl(value);
|
|
2511
|
+
setQrError(null);
|
|
2512
|
+
}
|
|
2513
|
+
}).catch((err) => {
|
|
2514
|
+
if (mounted) {
|
|
2515
|
+
setQrError(err.message);
|
|
2516
|
+
}
|
|
2517
|
+
});
|
|
2518
|
+
return () => {
|
|
2519
|
+
mounted = false;
|
|
2520
|
+
};
|
|
2521
|
+
}, [joinUrl, isChildMode]);
|
|
2522
|
+
const handleCopyUrl = async () => {
|
|
2523
|
+
if (!joinUrl) return;
|
|
2524
|
+
try {
|
|
2525
|
+
await navigator.clipboard.writeText(joinUrl);
|
|
2526
|
+
setCopied(true);
|
|
2527
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
2528
|
+
} catch {
|
|
2529
|
+
const textArea = document.createElement("textarea");
|
|
2530
|
+
textArea.value = joinUrl;
|
|
2531
|
+
textArea.style.position = "fixed";
|
|
2532
|
+
textArea.style.opacity = "0";
|
|
2533
|
+
document.body.appendChild(textArea);
|
|
2534
|
+
textArea.select();
|
|
2535
|
+
try {
|
|
2536
|
+
document.execCommand("copy");
|
|
2537
|
+
setCopied(true);
|
|
2538
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
2539
|
+
} catch {
|
|
2540
|
+
}
|
|
2541
|
+
document.body.removeChild(textArea);
|
|
2791
2542
|
}
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
}
|
|
2798
|
-
const
|
|
2799
|
-
|
|
2543
|
+
};
|
|
2544
|
+
const handleOpenInNewTab = () => {
|
|
2545
|
+
if (joinUrl) {
|
|
2546
|
+
window.open(joinUrl, "_blank", "noopener,noreferrer");
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
const handleCopyPlayerId = async (playerId) => {
|
|
2550
|
+
try {
|
|
2551
|
+
await navigator.clipboard.writeText(playerId);
|
|
2552
|
+
console.log(`Copied player ID: ${playerId}`);
|
|
2553
|
+
setCopiedPlayerId(playerId);
|
|
2554
|
+
setTimeout(() => setCopiedPlayerId(null), 1e3);
|
|
2555
|
+
} catch {
|
|
2556
|
+
const textArea = document.createElement("textarea");
|
|
2557
|
+
textArea.value = playerId;
|
|
2558
|
+
textArea.style.position = "fixed";
|
|
2559
|
+
textArea.style.opacity = "0";
|
|
2560
|
+
document.body.appendChild(textArea);
|
|
2561
|
+
textArea.select();
|
|
2562
|
+
try {
|
|
2563
|
+
document.execCommand("copy");
|
|
2564
|
+
console.log(`Copied player ID: ${playerId}`);
|
|
2565
|
+
setCopiedPlayerId(playerId);
|
|
2566
|
+
setTimeout(() => setCopiedPlayerId(null), 1e3);
|
|
2567
|
+
} catch {
|
|
2568
|
+
}
|
|
2569
|
+
document.body.removeChild(textArea);
|
|
2570
|
+
}
|
|
2571
|
+
};
|
|
2572
|
+
const connectionVariant = React.useMemo(() => {
|
|
2800
2573
|
switch (connectionStatus) {
|
|
2801
2574
|
case "connected":
|
|
2802
|
-
return "
|
|
2575
|
+
return "default";
|
|
2803
2576
|
case "connecting":
|
|
2804
2577
|
case "reconnecting":
|
|
2805
|
-
return "
|
|
2806
|
-
case "disconnected":
|
|
2578
|
+
return "secondary";
|
|
2807
2579
|
default:
|
|
2808
|
-
return "
|
|
2580
|
+
return "destructive";
|
|
2809
2581
|
}
|
|
2810
2582
|
}, [connectionStatus]);
|
|
2811
2583
|
if (isChildMode) {
|
|
2812
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2813
|
-
!orientationOk && /* @__PURE__ */ jsxRuntime.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: [
|
|
2814
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-card-foreground text-xl font-semibold", children: "Rotate your device" }),
|
|
2815
|
-
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-muted-foreground mt-2 text-sm", children: [
|
|
2816
|
-
"This game is best experienced in ",
|
|
2817
|
-
requiredOrientation,
|
|
2818
|
-
" ",
|
|
2819
|
-
"orientation."
|
|
2820
|
-
] })
|
|
2821
|
-
] }),
|
|
2822
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2823
|
-
"div",
|
|
2824
|
-
{
|
|
2825
|
-
className: cn(
|
|
2826
|
-
"h-full w-full select-none",
|
|
2827
|
-
!orientationOk && "pointer-events-none opacity-30"
|
|
2828
|
-
),
|
|
2829
|
-
children
|
|
2830
|
-
}
|
|
2831
|
-
)
|
|
2832
|
-
] }) }) });
|
|
2584
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
2833
2585
|
}
|
|
2834
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
2835
|
-
/* @__PURE__ */ jsxRuntime.
|
|
2586
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dark relative", children: [
|
|
2587
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none absolute inset-x-0 top-0 z-99999", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mx-auto w-full", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
|
|
2588
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2589
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs tracking-[0.18em] uppercase", children: "Room" }),
|
|
2590
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-foreground text-lg font-semibold", children: roomId })
|
|
2591
|
+
] }) }),
|
|
2836
2592
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2593
|
+
players.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center -space-x-2", children: [
|
|
2594
|
+
players.slice(0, 4).map((player) => /* @__PURE__ */ jsxRuntime.jsx(PlayerAvatar, { player, size: "sm" }, player.id)),
|
|
2595
|
+
players.length > 4 && /* @__PURE__ */ jsxRuntime.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: [
|
|
2596
|
+
"+",
|
|
2597
|
+
players.length - 4
|
|
2598
|
+
] })
|
|
2599
|
+
] }),
|
|
2600
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2601
|
+
Button,
|
|
2602
|
+
{
|
|
2603
|
+
type: "button",
|
|
2604
|
+
variant: "ghost",
|
|
2605
|
+
size: "icon",
|
|
2606
|
+
onClick: toggleGameState,
|
|
2607
|
+
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
2608
|
+
className: "h-8 w-8",
|
|
2609
|
+
children: gameState === "playing" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "h-4 w-4" })
|
|
2610
|
+
}
|
|
2611
|
+
)
|
|
2612
|
+
] })
|
|
2613
|
+
] }) }) }),
|
|
2614
|
+
gameState === "paused" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none fixed inset-0 z-99998 flex items-center justify-center p-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-auto w-full max-w-2xl", children: /* @__PURE__ */ jsxRuntime.jsx(Card, { className: "bg-card/20 flex max-h-[85vh] flex-col overflow-hidden border py-0 shadow-lg backdrop-blur-sm", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2615
|
+
Tabs,
|
|
2616
|
+
{
|
|
2617
|
+
defaultValue: isChildMode ? "settings" : "room-code",
|
|
2618
|
+
className: "flex h-full w-full flex-col gap-0",
|
|
2619
|
+
children: [
|
|
2620
|
+
/* @__PURE__ */ jsxRuntime.jsxs(TabsList, { className: "border-border grid w-full shrink-0 grid-cols-2 rounded-none border-b bg-transparent p-0", children: [
|
|
2621
|
+
!isChildMode && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2622
|
+
TabsTrigger,
|
|
2623
|
+
{
|
|
2624
|
+
value: "room-code",
|
|
2625
|
+
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2626
|
+
children: [
|
|
2627
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.QrCode, { className: "h-4 w-4" }),
|
|
2628
|
+
"Room Code"
|
|
2629
|
+
]
|
|
2630
|
+
}
|
|
2631
|
+
),
|
|
2632
|
+
isChildMode && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2633
|
+
TabsTrigger,
|
|
2634
|
+
{
|
|
2635
|
+
value: "info",
|
|
2636
|
+
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2637
|
+
children: [
|
|
2638
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.MonitorSmartphone, { className: "h-4 w-4" }),
|
|
2639
|
+
"Platform"
|
|
2640
|
+
]
|
|
2641
|
+
}
|
|
2642
|
+
),
|
|
2643
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2644
|
+
TabsTrigger,
|
|
2645
|
+
{
|
|
2646
|
+
value: "settings",
|
|
2647
|
+
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2648
|
+
children: [
|
|
2649
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Settings, { className: "h-4 w-4" }),
|
|
2650
|
+
"Settings"
|
|
2651
|
+
]
|
|
2652
|
+
}
|
|
2653
|
+
)
|
|
2654
|
+
] }),
|
|
2655
|
+
!isChildMode && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2656
|
+
TabsContent,
|
|
2840
2657
|
{
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2658
|
+
value: "room-code",
|
|
2659
|
+
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2660
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-[auto_1fr]", children: [
|
|
2661
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start gap-4", children: [
|
|
2662
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
2663
|
+
/* @__PURE__ */ jsxRuntime.jsx(CardTitle, { className: "text-3xl font-bold tracking-wider", children: roomId }),
|
|
2664
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2665
|
+
Badge,
|
|
2666
|
+
{
|
|
2667
|
+
variant: connectionVariant,
|
|
2668
|
+
className: "w-fit",
|
|
2669
|
+
children: statusCopy[connectionStatus]
|
|
2670
|
+
}
|
|
2671
|
+
)
|
|
2672
|
+
] }),
|
|
2673
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-border bg-card w-48 shrink-0 overflow-hidden rounded-lg border-2 shadow-md", children: qrUrl ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2674
|
+
"img",
|
|
2675
|
+
{
|
|
2676
|
+
src: qrUrl,
|
|
2677
|
+
alt: `Join room ${roomId}`,
|
|
2678
|
+
className: "w-full rounded bg-white"
|
|
2679
|
+
}
|
|
2680
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-muted-foreground flex h-48 items-center justify-center text-sm", children: qrError ? `QR failed: ${qrError}` : "Generating QR code\u2026" }) })
|
|
2681
|
+
] }),
|
|
2682
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
2683
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
|
|
2684
|
+
/* @__PURE__ */ jsxRuntime.jsx(CardDescription, { className: "text-xs tracking-[0.18em] uppercase", children: "Join URL" }),
|
|
2685
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
2686
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2687
|
+
"input",
|
|
2688
|
+
{
|
|
2689
|
+
type: "text",
|
|
2690
|
+
readOnly: true,
|
|
2691
|
+
value: joinUrl,
|
|
2692
|
+
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"
|
|
2693
|
+
}
|
|
2694
|
+
),
|
|
2695
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2696
|
+
Button,
|
|
2697
|
+
{
|
|
2698
|
+
type: "button",
|
|
2699
|
+
variant: "outline",
|
|
2700
|
+
size: "icon",
|
|
2701
|
+
onClick: handleCopyUrl,
|
|
2702
|
+
className: "h-10 shrink-0",
|
|
2703
|
+
"aria-label": "Copy join URL",
|
|
2704
|
+
children: copied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "h-4 w-4" })
|
|
2705
|
+
}
|
|
2706
|
+
),
|
|
2707
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2708
|
+
Button,
|
|
2709
|
+
{
|
|
2710
|
+
type: "button",
|
|
2711
|
+
variant: "outline",
|
|
2712
|
+
size: "icon",
|
|
2713
|
+
onClick: handleOpenInNewTab,
|
|
2714
|
+
className: "h-10 shrink-0",
|
|
2715
|
+
"aria-label": "Open join URL in new tab",
|
|
2716
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ExternalLink, { className: "h-4 w-4" })
|
|
2717
|
+
}
|
|
2718
|
+
)
|
|
2719
|
+
] })
|
|
2720
|
+
] }),
|
|
2721
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: players.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-white", children: "Waiting for controllers to join\u2026" }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2722
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-foreground text-sm font-medium", children: [
|
|
2723
|
+
"Connected Players (",
|
|
2724
|
+
players.length,
|
|
2725
|
+
")"
|
|
2726
|
+
] }),
|
|
2727
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: players.map((player) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2728
|
+
"li",
|
|
2729
|
+
{
|
|
2730
|
+
className: "flex min-w-0 flex-col items-start gap-2",
|
|
2731
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full min-w-0 items-center gap-2", children: [
|
|
2732
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2733
|
+
PlayerAvatar,
|
|
2734
|
+
{
|
|
2735
|
+
player,
|
|
2736
|
+
size: "md"
|
|
2737
|
+
}
|
|
2738
|
+
),
|
|
2739
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5 overflow-hidden", children: [
|
|
2740
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-card-foreground truncate text-sm font-medium", children: player.label }),
|
|
2741
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2742
|
+
"div",
|
|
2743
|
+
{
|
|
2744
|
+
onClick: () => handleCopyPlayerId(player.id),
|
|
2745
|
+
className: "text-muted-foreground m-0 inline min-w-0 cursor-pointer truncate border-0 font-mono text-xs transition-colors hover:text-white",
|
|
2746
|
+
title: "Click to copy player ID",
|
|
2747
|
+
children: copiedPlayerId === player.id ? "Copied!" : player.id.slice(0, 8)
|
|
2748
|
+
}
|
|
2749
|
+
)
|
|
2750
|
+
] })
|
|
2751
|
+
] })
|
|
2752
|
+
},
|
|
2753
|
+
player.id
|
|
2754
|
+
)) })
|
|
2755
|
+
] }) }),
|
|
2756
|
+
lastError && /* @__PURE__ */ jsxRuntime.jsx(Alert, { variant: "destructive", className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsx(AlertDescription, { children: lastError }) }),
|
|
2757
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-auto flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2758
|
+
Button,
|
|
2759
|
+
{
|
|
2760
|
+
type: "button",
|
|
2761
|
+
onClick: toggleGameState,
|
|
2762
|
+
size: "lg",
|
|
2763
|
+
children: [
|
|
2764
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "mr-2 h-5 w-5" }),
|
|
2765
|
+
"Play"
|
|
2766
|
+
]
|
|
2767
|
+
}
|
|
2768
|
+
) })
|
|
2769
|
+
] })
|
|
2770
|
+
] }) })
|
|
2846
2771
|
}
|
|
2847
|
-
)
|
|
2848
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2849
|
-
|
|
2772
|
+
),
|
|
2773
|
+
isChildMode && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2774
|
+
TabsContent,
|
|
2850
2775
|
{
|
|
2851
|
-
|
|
2852
|
-
"
|
|
2776
|
+
value: "info",
|
|
2777
|
+
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2778
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6", children: [
|
|
2779
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
2780
|
+
/* @__PURE__ */ jsxRuntime.jsx(CardTitle, { className: "text-2xl font-bold tracking-wider", children: "Connected to Platform" }),
|
|
2781
|
+
/* @__PURE__ */ jsxRuntime.jsx(CardDescription, { children: "This game is running inside the Air Jam Platform." })
|
|
2782
|
+
] }),
|
|
2783
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
|
|
2784
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-foreground text-sm font-medium", children: [
|
|
2785
|
+
"Connected Players (",
|
|
2786
|
+
players.length,
|
|
2787
|
+
")"
|
|
2788
|
+
] }),
|
|
2789
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: players.map((player) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2790
|
+
"li",
|
|
2791
|
+
{
|
|
2792
|
+
className: "flex min-w-0 flex-col items-start gap-2",
|
|
2793
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full min-w-0 items-center gap-2", children: [
|
|
2794
|
+
/* @__PURE__ */ jsxRuntime.jsx(PlayerAvatar, { player, size: "md" }),
|
|
2795
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-card-foreground truncate text-sm font-medium", children: player.label }) })
|
|
2796
|
+
] })
|
|
2797
|
+
},
|
|
2798
|
+
player.id
|
|
2799
|
+
)) })
|
|
2800
|
+
] }),
|
|
2801
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2802
|
+
Button,
|
|
2803
|
+
{
|
|
2804
|
+
type: "button",
|
|
2805
|
+
onClick: toggleGameState,
|
|
2806
|
+
size: "lg",
|
|
2807
|
+
children: [
|
|
2808
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "mr-2 h-5 w-5" }),
|
|
2809
|
+
"Resume Game"
|
|
2810
|
+
]
|
|
2811
|
+
}
|
|
2812
|
+
) })
|
|
2813
|
+
] }) })
|
|
2853
2814
|
}
|
|
2854
2815
|
),
|
|
2855
2816
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2856
|
-
|
|
2817
|
+
TabsContent,
|
|
2857
2818
|
{
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2819
|
+
value: "settings",
|
|
2820
|
+
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2821
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(CardContent, { className: "pt-6 pb-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6", children: [
|
|
2822
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-4", children: /* @__PURE__ */ jsxRuntime.jsx(VolumeControls, {}) }),
|
|
2823
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
2824
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold", children: "Connection" }),
|
|
2825
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
2826
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2827
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Status" }),
|
|
2828
|
+
/* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: connectionVariant, children: statusCopy[connectionStatus] })
|
|
2829
|
+
] }),
|
|
2830
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2831
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Room ID" }),
|
|
2832
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono text-sm", children: roomId })
|
|
2833
|
+
] }),
|
|
2834
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2835
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Players" }),
|
|
2836
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: players.length })
|
|
2837
|
+
] })
|
|
2838
|
+
] })
|
|
2839
|
+
] }),
|
|
2840
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
2841
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold", children: "Display" }),
|
|
2842
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2843
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Game State" }),
|
|
2844
|
+
/* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "outline", className: "capitalize", children: gameState })
|
|
2845
|
+
] }) })
|
|
2846
|
+
] })
|
|
2847
|
+
] }) })
|
|
2864
2848
|
}
|
|
2865
2849
|
)
|
|
2866
|
-
]
|
|
2867
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2868
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs tracking-[0.24em] uppercase", children: "Room" }),
|
|
2869
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-foreground text-lg font-semibold", children: typeof window !== "undefined" ? roomId ?? "N/A" : "N/A" })
|
|
2870
|
-
] })
|
|
2871
|
-
] }),
|
|
2872
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
2873
|
-
customActions,
|
|
2874
|
-
onRefresh && roomId && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2875
|
-
Button,
|
|
2876
|
-
{
|
|
2877
|
-
type: "button",
|
|
2878
|
-
variant: "outline",
|
|
2879
|
-
size: "icon",
|
|
2880
|
-
onClick: onRefresh,
|
|
2881
|
-
disabled: connectionStatus === "connecting" || connectionStatus === "reconnecting",
|
|
2882
|
-
"aria-label": "Reconnect",
|
|
2883
|
-
title: "Reconnect to room",
|
|
2884
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2885
|
-
lucideReact.RefreshCw,
|
|
2886
|
-
{
|
|
2887
|
-
className: cn(
|
|
2888
|
-
"h-5 w-5",
|
|
2889
|
-
(connectionStatus === "connecting" || connectionStatus === "reconnecting") && "animate-spin"
|
|
2890
|
-
)
|
|
2891
|
-
}
|
|
2892
|
-
)
|
|
2893
|
-
}
|
|
2894
|
-
),
|
|
2895
|
-
onReconnect && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2896
|
-
Button,
|
|
2897
|
-
{
|
|
2898
|
-
type: "button",
|
|
2899
|
-
variant: "outline",
|
|
2900
|
-
size: "icon",
|
|
2901
|
-
onClick: () => setIsScannerOpen(true),
|
|
2902
|
-
"aria-label": "Scan QR code to reconnect",
|
|
2903
|
-
title: "Scan QR code to reconnect",
|
|
2904
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.QrCode, { className: "h-5 w-5" })
|
|
2905
|
-
}
|
|
2906
|
-
),
|
|
2907
|
-
onTogglePlayPause && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2908
|
-
Button,
|
|
2909
|
-
{
|
|
2910
|
-
type: "button",
|
|
2911
|
-
variant: "outline",
|
|
2912
|
-
size: "icon",
|
|
2913
|
-
onClick: onTogglePlayPause,
|
|
2914
|
-
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
2915
|
-
title: gameState === "playing" ? "Pause" : "Play",
|
|
2916
|
-
children: gameState === "playing" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, { className: "h-5 w-5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "h-5 w-5" })
|
|
2917
|
-
}
|
|
2918
|
-
),
|
|
2919
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2920
|
-
Button,
|
|
2921
|
-
{
|
|
2922
|
-
type: "button",
|
|
2923
|
-
variant: "outline",
|
|
2924
|
-
size: "icon",
|
|
2925
|
-
onClick: () => toggleFullscreen(),
|
|
2926
|
-
"aria-label": isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
|
|
2927
|
-
title: isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
|
|
2928
|
-
children: isFullscreen ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Minimize, { className: "h-5 w-5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Maximize, { className: "h-5 w-5" })
|
|
2929
|
-
}
|
|
2930
|
-
)
|
|
2931
|
-
] })
|
|
2932
|
-
] }),
|
|
2933
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none fixed right-4 bottom-4 z-50", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-auto", children: /* @__PURE__ */ jsxRuntime.jsx(VolumeControls, { compact: true }) }) }),
|
|
2934
|
-
/* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.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: [
|
|
2935
|
-
!orientationOk && /* @__PURE__ */ jsxRuntime.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: [
|
|
2936
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-card-foreground text-xl font-semibold", children: "Rotate your device" }),
|
|
2937
|
-
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-muted-foreground mt-2 text-sm", children: [
|
|
2938
|
-
"This game is best experienced in ",
|
|
2939
|
-
requiredOrientation,
|
|
2940
|
-
" ",
|
|
2941
|
-
"orientation."
|
|
2942
|
-
] })
|
|
2943
|
-
] }),
|
|
2944
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2945
|
-
"div",
|
|
2946
|
-
{
|
|
2947
|
-
className: cn(
|
|
2948
|
-
"h-full w-full select-none",
|
|
2949
|
-
!orientationOk && "pointer-events-none opacity-30"
|
|
2950
|
-
),
|
|
2951
|
-
children
|
|
2952
|
-
}
|
|
2953
|
-
)
|
|
2954
|
-
] }) }),
|
|
2955
|
-
onReconnect && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2956
|
-
QRScannerDialog,
|
|
2957
|
-
{
|
|
2958
|
-
isOpen: isScannerOpen,
|
|
2959
|
-
onClose: () => setIsScannerOpen(false),
|
|
2960
|
-
onScan: (roomCode) => {
|
|
2961
|
-
onReconnect(roomCode);
|
|
2962
|
-
setIsScannerOpen(false);
|
|
2963
|
-
},
|
|
2964
|
-
currentRoomId: roomId
|
|
2850
|
+
]
|
|
2965
2851
|
}
|
|
2966
|
-
)
|
|
2967
|
-
|
|
2852
|
+
) }) }) }),
|
|
2853
|
+
children
|
|
2854
|
+
] });
|
|
2968
2855
|
};
|
|
2969
2856
|
|
|
2970
2857
|
// src/events.ts
|
|
@@ -3072,6 +2959,31 @@ var Events = {
|
|
|
3072
2959
|
Client: ClientEvents,
|
|
3073
2960
|
Child: ChildEvents
|
|
3074
2961
|
};
|
|
2962
|
+
|
|
2963
|
+
// src/utils/ids.ts
|
|
2964
|
+
var alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
2965
|
+
var generateRoomCode = () => {
|
|
2966
|
+
const array = new Uint32Array(4);
|
|
2967
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
2968
|
+
crypto.getRandomValues(array);
|
|
2969
|
+
} else {
|
|
2970
|
+
for (let i = 0; i < array.length; i += 1) {
|
|
2971
|
+
array[i] = Math.floor(Math.random() * alphabet.length);
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
const code = Array.from(
|
|
2975
|
+
array,
|
|
2976
|
+
(value) => alphabet[value % alphabet.length]
|
|
2977
|
+
).join("");
|
|
2978
|
+
return roomCodeSchema.parse(code);
|
|
2979
|
+
};
|
|
2980
|
+
var generateControllerId = () => {
|
|
2981
|
+
const stamp = Math.floor(Date.now() % 1e5).toString().padStart(5, "0");
|
|
2982
|
+
const random = alphabet[Math.floor(Math.random() * alphabet.length)];
|
|
2983
|
+
return `C${random}${stamp}`;
|
|
2984
|
+
};
|
|
2985
|
+
|
|
2986
|
+
// src/hooks/use-air-jam-controller.ts
|
|
3075
2987
|
var getRoomFromLocation = () => {
|
|
3076
2988
|
if (typeof window === "undefined") {
|
|
3077
2989
|
return null;
|
|
@@ -3580,6 +3492,7 @@ var useAirJamShell = (options = {}) => {
|
|
|
3580
3492
|
const sendInput = React.useCallback(
|
|
3581
3493
|
(input) => {
|
|
3582
3494
|
const storeState = store.getState();
|
|
3495
|
+
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);
|
|
3583
3496
|
if (!parsedRoomId || !storeState.controllerId || !socket) {
|
|
3584
3497
|
storeState.setError("Not connected to a room");
|
|
3585
3498
|
return false;
|
|
@@ -3676,6 +3589,7 @@ function createAirJamStore2(initializer) {
|
|
|
3676
3589
|
}
|
|
3677
3590
|
};
|
|
3678
3591
|
});
|
|
3592
|
+
const gameUiUnloadedRef = { current: false };
|
|
3679
3593
|
const useSyncedStore = (selector = (s) => s) => {
|
|
3680
3594
|
const slice = store(selector);
|
|
3681
3595
|
const { getSocket } = useAirJamContext();
|
|
@@ -3683,6 +3597,10 @@ function createAirJamStore2(initializer) {
|
|
|
3683
3597
|
const roomId = useAirJamState((state) => state.roomId);
|
|
3684
3598
|
const controllerId = useAirJamState((state) => state.controllerId);
|
|
3685
3599
|
const socket = role === "host" ? getSocket("host") : getSocket("controller");
|
|
3600
|
+
const socketRef = React.useRef(socket);
|
|
3601
|
+
React.useEffect(() => {
|
|
3602
|
+
socketRef.current = socket;
|
|
3603
|
+
}, [socket]);
|
|
3686
3604
|
React.useEffect(() => {
|
|
3687
3605
|
if (!socket || !roomId || !role) {
|
|
3688
3606
|
return;
|
|
@@ -3706,6 +3624,7 @@ function createAirJamStore2(initializer) {
|
|
|
3706
3624
|
};
|
|
3707
3625
|
}
|
|
3708
3626
|
if (role === "controller") {
|
|
3627
|
+
gameUiUnloadedRef.current = false;
|
|
3709
3628
|
const handleSync = (payload) => {
|
|
3710
3629
|
const { data } = payload;
|
|
3711
3630
|
const currentState = store.getState();
|
|
@@ -3717,9 +3636,27 @@ function createAirJamStore2(initializer) {
|
|
|
3717
3636
|
}
|
|
3718
3637
|
};
|
|
3719
3638
|
socket.on("airjam:state_sync", handleSync);
|
|
3720
|
-
|
|
3639
|
+
const handleUnloadUi = () => {
|
|
3640
|
+
gameUiUnloadedRef.current = true;
|
|
3641
|
+
socket.off("airjam:state_sync", handleSync);
|
|
3642
|
+
};
|
|
3643
|
+
const handleLoadUi = () => {
|
|
3644
|
+
gameUiUnloadedRef.current = false;
|
|
3645
|
+
};
|
|
3646
|
+
socket.on("client:loadUi", handleLoadUi);
|
|
3647
|
+
const handleDisconnect = () => {
|
|
3648
|
+
gameUiUnloadedRef.current = true;
|
|
3649
|
+
};
|
|
3650
|
+
socket.on("disconnect", handleDisconnect);
|
|
3651
|
+
socket.on("client:unloadUi", handleUnloadUi);
|
|
3652
|
+
return () => {
|
|
3653
|
+
socket.off("airjam:state_sync", handleSync);
|
|
3654
|
+
socket.off("client:loadUi", handleLoadUi);
|
|
3655
|
+
socket.off("client:unloadUi", handleUnloadUi);
|
|
3656
|
+
socket.off("disconnect", handleDisconnect);
|
|
3657
|
+
};
|
|
3721
3658
|
}
|
|
3722
|
-
}, [socket, role, roomId]);
|
|
3659
|
+
}, [socket, role, roomId, socket?.id]);
|
|
3723
3660
|
if (role === "controller" && socket && roomId) {
|
|
3724
3661
|
let originalActions = null;
|
|
3725
3662
|
if (typeof slice === "object" && slice !== null && "actions" in slice) {
|
|
@@ -3740,13 +3677,26 @@ function createAirJamStore2(initializer) {
|
|
|
3740
3677
|
const proxyActions = {};
|
|
3741
3678
|
Object.keys(originalActions).forEach((key) => {
|
|
3742
3679
|
proxyActions[key] = (...args) => {
|
|
3680
|
+
if (gameUiUnloadedRef.current) {
|
|
3681
|
+
console.warn(
|
|
3682
|
+
`[AirJamStore] Action "${key}" blocked: Game UI unloaded.`
|
|
3683
|
+
);
|
|
3684
|
+
return;
|
|
3685
|
+
}
|
|
3686
|
+
const activeSocket = socketRef.current;
|
|
3687
|
+
if (!activeSocket || !activeSocket.connected) {
|
|
3688
|
+
console.warn(
|
|
3689
|
+
`[AirJamStore] Action "${key}" blocked: Socket disconnected.`
|
|
3690
|
+
);
|
|
3691
|
+
return;
|
|
3692
|
+
}
|
|
3743
3693
|
if (!controllerId) {
|
|
3744
3694
|
console.warn(
|
|
3745
3695
|
"[AirJamStore] Cannot send action RPC: controllerId not set"
|
|
3746
3696
|
);
|
|
3747
3697
|
return;
|
|
3748
3698
|
}
|
|
3749
|
-
|
|
3699
|
+
activeSocket.emit("controller:action_rpc", {
|
|
3750
3700
|
roomId,
|
|
3751
3701
|
actionName: key,
|
|
3752
3702
|
args,
|
|
@@ -3768,23 +3718,21 @@ function createAirJamStore2(initializer) {
|
|
|
3768
3718
|
|
|
3769
3719
|
exports.AIRJAM_PROXY_PREFIX = AIRJAM_PROXY_PREFIX;
|
|
3770
3720
|
exports.AirJamContext = AirJamContext;
|
|
3771
|
-
exports.AirJamDebug = AirJamDebug;
|
|
3772
|
-
exports.AirJamOverlay = AirJamOverlay;
|
|
3773
3721
|
exports.AirJamProvider = AirJamProvider;
|
|
3774
3722
|
exports.AudioManager = AudioManager;
|
|
3775
3723
|
exports.AudioProvider = AudioProvider;
|
|
3776
3724
|
exports.Button = Button;
|
|
3725
|
+
exports.CONTROLLER_PATH = CONTROLLER_PATH;
|
|
3777
3726
|
exports.ChildEvents = ChildEvents;
|
|
3778
3727
|
exports.ClientEvents = ClientEvents;
|
|
3779
3728
|
exports.ControllerEvents = ControllerEvents;
|
|
3780
3729
|
exports.ControllerShell = ControllerShell;
|
|
3781
|
-
exports.DEFAULT_CONTROLLER_PATH = DEFAULT_CONTROLLER_PATH;
|
|
3782
3730
|
exports.DEFAULT_MAX_PLAYERS = DEFAULT_MAX_PLAYERS;
|
|
3783
3731
|
exports.DEFAULT_SERVER_PORT = DEFAULT_SERVER_PORT;
|
|
3784
|
-
exports.DebugStateDialog = DebugStateDialog;
|
|
3785
3732
|
exports.ErrorCode = ErrorCode;
|
|
3786
3733
|
exports.Events = Events;
|
|
3787
3734
|
exports.HostEvents = HostEvents;
|
|
3735
|
+
exports.HostShell = HostShell;
|
|
3788
3736
|
exports.INPUT_DEBOUNCE_MS = INPUT_DEBOUNCE_MS;
|
|
3789
3737
|
exports.PlayerAvatar = PlayerAvatar;
|
|
3790
3738
|
exports.SOCKET_CONFIG = SOCKET_CONFIG;
|
|
@@ -3807,7 +3755,9 @@ exports.detectSoundCategory = detectSoundCategory;
|
|
|
3807
3755
|
exports.generateControllerId = generateControllerId;
|
|
3808
3756
|
exports.generateRoomCode = generateRoomCode;
|
|
3809
3757
|
exports.getLocalNetworkIp = getLocalNetworkIp;
|
|
3758
|
+
exports.hostCreateRoomSchema = hostCreateRoomSchema;
|
|
3810
3759
|
exports.hostJoinAsChildSchema = hostJoinAsChildSchema;
|
|
3760
|
+
exports.hostReconnectSchema = hostReconnectSchema;
|
|
3811
3761
|
exports.hostRegisterSystemSchema = hostRegisterSystemSchema;
|
|
3812
3762
|
exports.hostRegistrationSchema = hostRegistrationSchema;
|
|
3813
3763
|
exports.roomCodeSchema = roomCodeSchema;
|