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