@air-jam/sdk 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-XSXI3RIS.js → chunk-7M5D3Y3L.js} +2 -2
- package/dist/{chunk-XSXI3RIS.js.map → chunk-7M5D3Y3L.js.map} +1 -1
- package/dist/index.cjs +2209 -1893
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -16
- package/dist/index.d.ts +80 -16
- package/dist/index.js +1984 -1673
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +24 -1
- package/dist/protocol.d.ts +24 -1
- package/dist/protocol.js +1 -1
- package/package.json +2 -1
- package/src/components/air-jam-debug.tsx +77 -0
- package/src/components/air-jam-overlay.tsx +243 -186
- package/src/components/controller-shell.tsx +17 -24
- package/src/components/debug-state-dialog.tsx +83 -0
- package/src/components/player-avatar.tsx +64 -0
- package/src/components/ui/button.tsx +1 -1
- package/src/components/ui/dialog.tsx +122 -0
- package/src/index.ts +6 -0
- package/src/protocol.ts +27 -0
- package/src/store/create-air-jam-store.ts +212 -0
- package/src/store/index.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -7,15 +7,16 @@ var socket_ioClient = require('socket.io-client');
|
|
|
7
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
8
|
var howler = require('howler');
|
|
9
9
|
var lucideReact = require('lucide-react');
|
|
10
|
-
var
|
|
10
|
+
var reactSlot = require('@radix-ui/react-slot');
|
|
11
11
|
var classVarianceAuthority = require('class-variance-authority');
|
|
12
12
|
var clsx = require('clsx');
|
|
13
13
|
var tailwindMerge = require('tailwind-merge');
|
|
14
|
-
var
|
|
14
|
+
var DialogPrimitive = require('@radix-ui/react-dialog');
|
|
15
|
+
var QRCode = require('qrcode');
|
|
16
|
+
var zod = require('zod');
|
|
15
17
|
var TabsPrimitive = require('@radix-ui/react-tabs');
|
|
16
18
|
var SliderPrimitive = require('@radix-ui/react-slider');
|
|
17
19
|
var html5Qrcode = require('html5-qrcode');
|
|
18
|
-
var zod = require('zod');
|
|
19
20
|
|
|
20
21
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
21
22
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -39,6 +40,7 @@ function _interopNamespace(e) {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
43
|
+
var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespace(DialogPrimitive);
|
|
42
44
|
var QRCode__default = /*#__PURE__*/_interopDefault(QRCode);
|
|
43
45
|
var TabsPrimitive__namespace = /*#__PURE__*/_interopNamespace(TabsPrimitive);
|
|
44
46
|
var SliderPrimitive__namespace = /*#__PURE__*/_interopNamespace(SliderPrimitive);
|
|
@@ -810,116 +812,6 @@ var useAudioManager = (manifest) => {
|
|
|
810
812
|
return managerRef.current;
|
|
811
813
|
};
|
|
812
814
|
var cn = (...inputs) => tailwindMerge.twMerge(clsx.clsx(inputs));
|
|
813
|
-
var alertVariants = classVarianceAuthority.cva(
|
|
814
|
-
"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",
|
|
815
|
-
{
|
|
816
|
-
variants: {
|
|
817
|
-
variant: {
|
|
818
|
-
default: "bg-card text-card-foreground",
|
|
819
|
-
destructive: "text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"
|
|
820
|
-
}
|
|
821
|
-
},
|
|
822
|
-
defaultVariants: {
|
|
823
|
-
variant: "default"
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
);
|
|
827
|
-
function Alert({
|
|
828
|
-
className,
|
|
829
|
-
variant,
|
|
830
|
-
...props
|
|
831
|
-
}) {
|
|
832
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
833
|
-
"div",
|
|
834
|
-
{
|
|
835
|
-
"data-slot": "alert",
|
|
836
|
-
role: "alert",
|
|
837
|
-
className: cn(alertVariants({ variant }), className),
|
|
838
|
-
...props
|
|
839
|
-
}
|
|
840
|
-
);
|
|
841
|
-
}
|
|
842
|
-
function AlertDescription({
|
|
843
|
-
className,
|
|
844
|
-
...props
|
|
845
|
-
}) {
|
|
846
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
847
|
-
"div",
|
|
848
|
-
{
|
|
849
|
-
"data-slot": "alert-description",
|
|
850
|
-
className: cn(
|
|
851
|
-
"text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",
|
|
852
|
-
className
|
|
853
|
-
),
|
|
854
|
-
...props
|
|
855
|
-
}
|
|
856
|
-
);
|
|
857
|
-
}
|
|
858
|
-
var Avatar = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
859
|
-
"div",
|
|
860
|
-
{
|
|
861
|
-
ref,
|
|
862
|
-
className: cn(
|
|
863
|
-
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
|
|
864
|
-
className
|
|
865
|
-
),
|
|
866
|
-
...props
|
|
867
|
-
}
|
|
868
|
-
));
|
|
869
|
-
Avatar.displayName = "Avatar";
|
|
870
|
-
var AvatarImage = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
871
|
-
"img",
|
|
872
|
-
{
|
|
873
|
-
ref,
|
|
874
|
-
className: cn("aspect-square h-full w-full", className),
|
|
875
|
-
...props
|
|
876
|
-
}
|
|
877
|
-
));
|
|
878
|
-
AvatarImage.displayName = "AvatarImage";
|
|
879
|
-
var AvatarFallback = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
880
|
-
"div",
|
|
881
|
-
{
|
|
882
|
-
ref,
|
|
883
|
-
className: cn(
|
|
884
|
-
"bg-muted flex h-full w-full items-center justify-center rounded-full",
|
|
885
|
-
className
|
|
886
|
-
),
|
|
887
|
-
...props
|
|
888
|
-
}
|
|
889
|
-
));
|
|
890
|
-
AvatarFallback.displayName = "AvatarFallback";
|
|
891
|
-
var badgeVariants = classVarianceAuthority.cva(
|
|
892
|
-
"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",
|
|
893
|
-
{
|
|
894
|
-
variants: {
|
|
895
|
-
variant: {
|
|
896
|
-
default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
|
897
|
-
secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
|
898
|
-
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",
|
|
899
|
-
outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
|
|
900
|
-
}
|
|
901
|
-
},
|
|
902
|
-
defaultVariants: {
|
|
903
|
-
variant: "default"
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
);
|
|
907
|
-
function Badge({
|
|
908
|
-
className,
|
|
909
|
-
variant,
|
|
910
|
-
asChild = false,
|
|
911
|
-
...props
|
|
912
|
-
}) {
|
|
913
|
-
const Comp = asChild ? reactSlot.Slot : "span";
|
|
914
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
915
|
-
Comp,
|
|
916
|
-
{
|
|
917
|
-
"data-slot": "badge",
|
|
918
|
-
className: cn(badgeVariants({ variant }), className),
|
|
919
|
-
...props
|
|
920
|
-
}
|
|
921
|
-
);
|
|
922
|
-
}
|
|
923
815
|
var buttonVariants = classVarianceAuthority.cva(
|
|
924
816
|
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all cursor-pointer disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
925
817
|
{
|
|
@@ -929,7 +821,7 @@ var buttonVariants = classVarianceAuthority.cva(
|
|
|
929
821
|
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
930
822
|
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
931
823
|
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
932
|
-
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
824
|
+
ghost: "text-foreground hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
933
825
|
link: "text-primary underline-offset-4 hover:underline"
|
|
934
826
|
},
|
|
935
827
|
size: {
|
|
@@ -964,667 +856,168 @@ function Button({
|
|
|
964
856
|
}
|
|
965
857
|
);
|
|
966
858
|
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
859
|
+
var Dialog = DialogPrimitive__namespace.Root;
|
|
860
|
+
var DialogPortal = DialogPrimitive__namespace.Portal;
|
|
861
|
+
var DialogOverlay = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
862
|
+
DialogPrimitive__namespace.Overlay,
|
|
863
|
+
{
|
|
864
|
+
ref,
|
|
865
|
+
className: cn(
|
|
866
|
+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-99999 bg-black/80",
|
|
867
|
+
className
|
|
868
|
+
),
|
|
869
|
+
...props
|
|
870
|
+
}
|
|
871
|
+
));
|
|
872
|
+
DialogOverlay.displayName = DialogPrimitive__namespace.Overlay.displayName;
|
|
873
|
+
var DialogContent = React__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(DialogPortal, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dark", children: [
|
|
874
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogOverlay, {}),
|
|
875
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
876
|
+
DialogPrimitive__namespace.Content,
|
|
983
877
|
{
|
|
984
|
-
|
|
878
|
+
ref,
|
|
985
879
|
className: cn(
|
|
986
|
-
"
|
|
880
|
+
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] fixed top-[50%] left-[50%] z-99999 w-full translate-x-[-50%] translate-y-[-50%] gap-4 rounded-xl border border-white p-6 shadow-lg duration-200",
|
|
987
881
|
className
|
|
988
882
|
),
|
|
989
|
-
...props
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
"data-slot": "card-title",
|
|
998
|
-
className: cn("leading-none font-semibold", className),
|
|
999
|
-
...props
|
|
1000
|
-
}
|
|
1001
|
-
);
|
|
1002
|
-
}
|
|
1003
|
-
function CardDescription({ className, ...props }) {
|
|
1004
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1005
|
-
"div",
|
|
1006
|
-
{
|
|
1007
|
-
"data-slot": "card-description",
|
|
1008
|
-
className: cn("text-muted-foreground text-sm", className),
|
|
1009
|
-
...props
|
|
1010
|
-
}
|
|
1011
|
-
);
|
|
1012
|
-
}
|
|
1013
|
-
function CardContent({ className, ...props }) {
|
|
1014
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1015
|
-
"div",
|
|
1016
|
-
{
|
|
1017
|
-
"data-slot": "card-content",
|
|
1018
|
-
className: cn("px-6", className),
|
|
1019
|
-
...props
|
|
1020
|
-
}
|
|
1021
|
-
);
|
|
1022
|
-
}
|
|
1023
|
-
function Tabs({
|
|
1024
|
-
className,
|
|
1025
|
-
...props
|
|
1026
|
-
}) {
|
|
1027
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1028
|
-
TabsPrimitive__namespace.Root,
|
|
1029
|
-
{
|
|
1030
|
-
"data-slot": "tabs",
|
|
1031
|
-
className: cn("flex flex-col gap-2", className),
|
|
1032
|
-
...props
|
|
883
|
+
...props,
|
|
884
|
+
children: [
|
|
885
|
+
children,
|
|
886
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DialogPrimitive__namespace.Close, { className: "text-foreground ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none", children: [
|
|
887
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-4 w-4" }),
|
|
888
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Close" })
|
|
889
|
+
] })
|
|
890
|
+
]
|
|
1033
891
|
}
|
|
1034
|
-
)
|
|
1035
|
-
}
|
|
1036
|
-
|
|
892
|
+
)
|
|
893
|
+
] }) }));
|
|
894
|
+
DialogContent.displayName = DialogPrimitive__namespace.Content.displayName;
|
|
895
|
+
var DialogHeader = ({
|
|
1037
896
|
className,
|
|
1038
897
|
...props
|
|
1039
|
-
})
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
"
|
|
1044
|
-
className
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
898
|
+
}) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
899
|
+
"div",
|
|
900
|
+
{
|
|
901
|
+
className: cn(
|
|
902
|
+
"flex flex-col space-y-1.5 text-center sm:text-left",
|
|
903
|
+
className
|
|
904
|
+
),
|
|
905
|
+
...props
|
|
906
|
+
}
|
|
907
|
+
);
|
|
908
|
+
DialogHeader.displayName = "DialogHeader";
|
|
909
|
+
var DialogTitle = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
910
|
+
DialogPrimitive__namespace.Title,
|
|
911
|
+
{
|
|
912
|
+
ref,
|
|
913
|
+
className: cn(
|
|
914
|
+
"text-lg leading-none font-semibold tracking-tight",
|
|
915
|
+
className
|
|
916
|
+
),
|
|
917
|
+
...props
|
|
918
|
+
}
|
|
919
|
+
));
|
|
920
|
+
DialogTitle.displayName = DialogPrimitive__namespace.Title.displayName;
|
|
921
|
+
var DialogDescription = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
922
|
+
DialogPrimitive__namespace.Description,
|
|
923
|
+
{
|
|
924
|
+
ref,
|
|
925
|
+
className: cn("text-muted-foreground text-sm", className),
|
|
926
|
+
...props
|
|
927
|
+
}
|
|
928
|
+
));
|
|
929
|
+
DialogDescription.displayName = DialogPrimitive__namespace.Description.displayName;
|
|
930
|
+
var DebugStateDialog = ({
|
|
931
|
+
isOpen,
|
|
932
|
+
onClose,
|
|
933
|
+
getState,
|
|
934
|
+
title = "Debug State",
|
|
935
|
+
updateInterval = 100
|
|
936
|
+
}) => {
|
|
937
|
+
const [state, setState] = React.useState(() => getState());
|
|
938
|
+
const [copied, setCopied] = React.useState(false);
|
|
939
|
+
React.useEffect(() => {
|
|
940
|
+
if (!isOpen) return;
|
|
941
|
+
const interval = setInterval(() => {
|
|
942
|
+
setState(getState());
|
|
943
|
+
}, updateInterval);
|
|
944
|
+
const timeoutId = setTimeout(() => {
|
|
945
|
+
setState(getState());
|
|
946
|
+
}, 0);
|
|
947
|
+
return () => {
|
|
948
|
+
clearInterval(interval);
|
|
949
|
+
clearTimeout(timeoutId);
|
|
950
|
+
};
|
|
951
|
+
}, [isOpen, getState, updateInterval]);
|
|
952
|
+
const jsonString = JSON.stringify(state, null, 2);
|
|
953
|
+
const handleCopy = async () => {
|
|
954
|
+
try {
|
|
955
|
+
await navigator.clipboard.writeText(jsonString);
|
|
956
|
+
setCopied(true);
|
|
957
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
958
|
+
} catch (error) {
|
|
959
|
+
console.error("Failed to copy:", error);
|
|
1049
960
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
961
|
+
};
|
|
962
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open: isOpen, onOpenChange: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "dark max-h-[90vh] max-w-2xl flex-col", children: [
|
|
963
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "text-foreground", children: title }) }),
|
|
964
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex-1 overflow-auto pt-4", children: [
|
|
965
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
966
|
+
Button,
|
|
967
|
+
{
|
|
968
|
+
variant: "ghost",
|
|
969
|
+
size: "icon-sm",
|
|
970
|
+
onClick: handleCopy,
|
|
971
|
+
className: "text-muted-foreground hover:text-foreground absolute top-6 right-2 z-10",
|
|
972
|
+
"aria-label": "Copy state",
|
|
973
|
+
children: copied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "h-4 w-4" })
|
|
974
|
+
}
|
|
1063
975
|
),
|
|
1064
|
-
|
|
1065
|
-
}
|
|
1066
|
-
);
|
|
1067
|
-
}
|
|
1068
|
-
function TabsContent({
|
|
1069
|
-
className,
|
|
1070
|
-
...props
|
|
1071
|
-
}) {
|
|
1072
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1073
|
-
TabsPrimitive__namespace.Content,
|
|
1074
|
-
{
|
|
1075
|
-
"data-slot": "tabs-content",
|
|
1076
|
-
className: cn("flex-1 outline-none", className),
|
|
1077
|
-
...props
|
|
1078
|
-
}
|
|
1079
|
-
);
|
|
1080
|
-
}
|
|
1081
|
-
function Slider({
|
|
1082
|
-
className,
|
|
1083
|
-
defaultValue,
|
|
1084
|
-
value,
|
|
1085
|
-
min = 0,
|
|
1086
|
-
max = 100,
|
|
1087
|
-
...props
|
|
1088
|
-
}) {
|
|
1089
|
-
const _values = React__namespace.useMemo(
|
|
1090
|
-
() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
|
|
1091
|
-
[value, defaultValue, min, max]
|
|
1092
|
-
);
|
|
1093
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1094
|
-
SliderPrimitive__namespace.Root,
|
|
1095
|
-
{
|
|
1096
|
-
"data-slot": "slider",
|
|
1097
|
-
defaultValue,
|
|
1098
|
-
value,
|
|
1099
|
-
min,
|
|
1100
|
-
max,
|
|
1101
|
-
className: cn(
|
|
1102
|
-
"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",
|
|
1103
|
-
className
|
|
1104
|
-
),
|
|
1105
|
-
...props,
|
|
1106
|
-
children: [
|
|
1107
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1108
|
-
SliderPrimitive__namespace.Track,
|
|
1109
|
-
{
|
|
1110
|
-
"data-slot": "slider-track",
|
|
1111
|
-
className: cn(
|
|
1112
|
-
"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"
|
|
1113
|
-
),
|
|
1114
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1115
|
-
SliderPrimitive__namespace.Range,
|
|
1116
|
-
{
|
|
1117
|
-
"data-slot": "slider-range",
|
|
1118
|
-
className: cn(
|
|
1119
|
-
"bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
|
|
1120
|
-
)
|
|
1121
|
-
}
|
|
1122
|
-
)
|
|
1123
|
-
}
|
|
1124
|
-
),
|
|
1125
|
-
Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1126
|
-
SliderPrimitive__namespace.Thumb,
|
|
1127
|
-
{
|
|
1128
|
-
"data-slot": "slider-thumb",
|
|
1129
|
-
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"
|
|
1130
|
-
},
|
|
1131
|
-
index
|
|
1132
|
-
))
|
|
1133
|
-
]
|
|
1134
|
-
}
|
|
1135
|
-
);
|
|
1136
|
-
}
|
|
1137
|
-
function VolumeControls({ className, compact }) {
|
|
1138
|
-
const {
|
|
1139
|
-
masterVolume,
|
|
1140
|
-
musicVolume,
|
|
1141
|
-
sfxVolume,
|
|
1142
|
-
setMasterVolume,
|
|
1143
|
-
setMusicVolume,
|
|
1144
|
-
setSfxVolume
|
|
1145
|
-
} = useVolumeStore();
|
|
1146
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col gap-3", compact && "gap-1", className), children: [
|
|
1147
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1148
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Volume2, { className: "text-muted-foreground h-4 w-4" }),
|
|
1149
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: "Volume" })
|
|
1150
|
-
] }),
|
|
1151
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
|
|
1152
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1153
|
-
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-muted-foreground text-xs", children: "Master" }),
|
|
1154
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
1155
|
-
Math.round(masterVolume * 100),
|
|
1156
|
-
"%"
|
|
1157
|
-
] })
|
|
1158
|
-
] }),
|
|
1159
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1160
|
-
Slider,
|
|
1161
|
-
{
|
|
1162
|
-
value: [masterVolume * 100],
|
|
1163
|
-
onValueChange: (values) => setMasterVolume(values[0] / 100),
|
|
1164
|
-
min: 0,
|
|
1165
|
-
max: 100,
|
|
1166
|
-
step: 1,
|
|
1167
|
-
className: "w-full",
|
|
1168
|
-
"aria-label": "Master volume"
|
|
1169
|
-
}
|
|
1170
|
-
)
|
|
1171
|
-
] }),
|
|
1172
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
|
|
1173
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1174
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
1175
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Music, { className: "text-muted-foreground h-3 w-3" }),
|
|
1176
|
-
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-muted-foreground text-xs", children: "Music" })
|
|
1177
|
-
] }),
|
|
1178
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
1179
|
-
Math.round(musicVolume * 100),
|
|
1180
|
-
"%"
|
|
1181
|
-
] })
|
|
1182
|
-
] }),
|
|
1183
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1184
|
-
Slider,
|
|
1185
|
-
{
|
|
1186
|
-
value: [musicVolume * 100],
|
|
1187
|
-
onValueChange: (values) => setMusicVolume(values[0] / 100),
|
|
1188
|
-
min: 0,
|
|
1189
|
-
max: 100,
|
|
1190
|
-
step: 1,
|
|
1191
|
-
className: "w-full",
|
|
1192
|
-
"aria-label": "Music volume"
|
|
1193
|
-
}
|
|
1194
|
-
)
|
|
1195
|
-
] }),
|
|
1196
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
|
|
1197
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1198
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
1199
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Headphones, { className: "text-muted-foreground h-3 w-3" }),
|
|
1200
|
-
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-muted-foreground text-xs", children: "SFX" })
|
|
1201
|
-
] }),
|
|
1202
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
1203
|
-
Math.round(sfxVolume * 100),
|
|
1204
|
-
"%"
|
|
1205
|
-
] })
|
|
1206
|
-
] }),
|
|
1207
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1208
|
-
Slider,
|
|
1209
|
-
{
|
|
1210
|
-
value: [sfxVolume * 100],
|
|
1211
|
-
onValueChange: (values) => setSfxVolume(values[0] / 100),
|
|
1212
|
-
min: 0,
|
|
1213
|
-
max: 100,
|
|
1214
|
-
step: 1,
|
|
1215
|
-
className: "w-full",
|
|
1216
|
-
"aria-label": "SFX volume"
|
|
1217
|
-
}
|
|
1218
|
-
)
|
|
976
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { className: "bg-muted text-muted-foreground overflow-auto rounded-lg border p-4 font-mono text-xs", children: jsonString })
|
|
1219
977
|
] })
|
|
1220
|
-
] });
|
|
1221
|
-
}
|
|
1222
|
-
var statusCopy = {
|
|
1223
|
-
idle: "Idle",
|
|
1224
|
-
connecting: "Waiting for server\u2026",
|
|
1225
|
-
connected: "Ready for controllers",
|
|
1226
|
-
disconnected: "Disconnected",
|
|
1227
|
-
reconnecting: "Reconnecting\u2026"
|
|
1228
|
-
};
|
|
1229
|
-
var getPlayerAvatarUrl = (playerId) => {
|
|
1230
|
-
return `https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=${encodeURIComponent(
|
|
1231
|
-
playerId
|
|
1232
|
-
)}`;
|
|
978
|
+
] }) });
|
|
1233
979
|
};
|
|
1234
|
-
var
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
lastError,
|
|
1240
|
-
gameState,
|
|
1241
|
-
onTogglePlayPause,
|
|
1242
|
-
isChildMode = false
|
|
980
|
+
var AirJamDebug = ({
|
|
981
|
+
state,
|
|
982
|
+
title = "Debug State",
|
|
983
|
+
updateInterval = 100,
|
|
984
|
+
className
|
|
1243
985
|
}) => {
|
|
1244
|
-
const [
|
|
1245
|
-
const [
|
|
986
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
987
|
+
const [currentState, setCurrentState] = React.useState(state);
|
|
1246
988
|
React.useEffect(() => {
|
|
1247
|
-
if (
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
},
|
|
1255
|
-
width: 320
|
|
1256
|
-
}).then((value) => {
|
|
1257
|
-
if (mounted) {
|
|
1258
|
-
setQrUrl(value);
|
|
1259
|
-
setQrError(null);
|
|
1260
|
-
}
|
|
1261
|
-
}).catch((err) => {
|
|
1262
|
-
if (mounted) {
|
|
1263
|
-
setQrError(err.message);
|
|
1264
|
-
}
|
|
1265
|
-
});
|
|
1266
|
-
return () => {
|
|
1267
|
-
mounted = false;
|
|
1268
|
-
};
|
|
1269
|
-
}, [joinUrl, isChildMode]);
|
|
1270
|
-
const connectionVariant = React.useMemo(() => {
|
|
1271
|
-
switch (connectionStatus) {
|
|
1272
|
-
case "connected":
|
|
1273
|
-
return "default";
|
|
1274
|
-
case "connecting":
|
|
1275
|
-
case "reconnecting":
|
|
1276
|
-
return "secondary";
|
|
1277
|
-
default:
|
|
1278
|
-
return "destructive";
|
|
1279
|
-
}
|
|
1280
|
-
}, [connectionStatus]);
|
|
1281
|
-
if (isChildMode) return null;
|
|
989
|
+
if (!isOpen) return;
|
|
990
|
+
const interval = setInterval(() => {
|
|
991
|
+
setCurrentState(state);
|
|
992
|
+
}, updateInterval);
|
|
993
|
+
setCurrentState(state);
|
|
994
|
+
return () => clearInterval(interval);
|
|
995
|
+
}, [isOpen, state, updateInterval]);
|
|
1282
996
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs tracking-[0.18em] uppercase", children: "Room" }),
|
|
1286
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-foreground text-lg font-semibold", children: roomId })
|
|
1287
|
-
] }) }),
|
|
1288
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
1289
|
-
players.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center -space-x-2", children: [
|
|
1290
|
-
players.slice(0, 4).map((player) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1291
|
-
Avatar,
|
|
1292
|
-
{
|
|
1293
|
-
className: "h-8 w-8 border-2",
|
|
1294
|
-
style: {
|
|
1295
|
-
borderColor: player.color || "hsl(var(--border))"
|
|
1296
|
-
},
|
|
1297
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1298
|
-
AvatarImage,
|
|
1299
|
-
{
|
|
1300
|
-
src: getPlayerAvatarUrl(player.id),
|
|
1301
|
-
alt: player.label
|
|
1302
|
-
}
|
|
1303
|
-
)
|
|
1304
|
-
},
|
|
1305
|
-
player.id
|
|
1306
|
-
)),
|
|
1307
|
-
players.length > 4 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-background bg-muted flex h-8 w-8 items-center justify-center rounded-full border-2 text-xs font-medium", children: [
|
|
1308
|
-
"+",
|
|
1309
|
-
players.length - 4
|
|
1310
|
-
] })
|
|
1311
|
-
] }),
|
|
1312
|
-
onTogglePlayPause && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1313
|
-
Button,
|
|
1314
|
-
{
|
|
1315
|
-
type: "button",
|
|
1316
|
-
variant: "ghost",
|
|
1317
|
-
size: "icon",
|
|
1318
|
-
onClick: onTogglePlayPause,
|
|
1319
|
-
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
1320
|
-
className: "h-8 w-8",
|
|
1321
|
-
children: gameState === "playing" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "h-4 w-4" })
|
|
1322
|
-
}
|
|
1323
|
-
)
|
|
1324
|
-
] })
|
|
1325
|
-
] }) }) }),
|
|
1326
|
-
gameState === "paused" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none fixed inset-0 z-99998 flex items-center justify-center p-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-auto w-full max-w-2xl", children: /* @__PURE__ */ jsxRuntime.jsx(Card, { className: "bg-card/20 flex h-[80vh] flex-col overflow-hidden border py-0 shadow-lg backdrop-blur-sm", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1327
|
-
Tabs,
|
|
997
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
998
|
+
Button,
|
|
1328
999
|
{
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
1338
|
-
children: [
|
|
1339
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.QrCode, { className: "h-4 w-4" }),
|
|
1340
|
-
"Room Code"
|
|
1341
|
-
]
|
|
1342
|
-
}
|
|
1343
|
-
),
|
|
1344
|
-
isChildMode && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1345
|
-
TabsTrigger,
|
|
1346
|
-
{
|
|
1347
|
-
value: "info",
|
|
1348
|
-
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
1349
|
-
children: [
|
|
1350
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.MonitorSmartphone, { className: "h-4 w-4" }),
|
|
1351
|
-
"Platform"
|
|
1352
|
-
]
|
|
1353
|
-
}
|
|
1354
|
-
),
|
|
1355
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1356
|
-
TabsTrigger,
|
|
1357
|
-
{
|
|
1358
|
-
value: "settings",
|
|
1359
|
-
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
1360
|
-
children: [
|
|
1361
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Settings, { className: "h-4 w-4" }),
|
|
1362
|
-
"Settings"
|
|
1363
|
-
]
|
|
1364
|
-
}
|
|
1365
|
-
)
|
|
1366
|
-
] }),
|
|
1367
|
-
!isChildMode && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1368
|
-
TabsContent,
|
|
1369
|
-
{
|
|
1370
|
-
value: "room-code",
|
|
1371
|
-
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
1372
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6 pb-6", children: [
|
|
1373
|
-
/* @__PURE__ */ jsxRuntime.jsxs(CardHeader, { className: "pt-6 text-center", children: [
|
|
1374
|
-
/* @__PURE__ */ jsxRuntime.jsx(CardTitle, { className: "text-4xl font-bold tracking-wider", children: roomId }),
|
|
1375
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1376
|
-
Badge,
|
|
1377
|
-
{
|
|
1378
|
-
variant: connectionVariant,
|
|
1379
|
-
className: "mx-auto mt-3",
|
|
1380
|
-
children: statusCopy[connectionStatus]
|
|
1381
|
-
}
|
|
1382
|
-
)
|
|
1383
|
-
] }),
|
|
1384
|
-
/* @__PURE__ */ jsxRuntime.jsx(CardContent, { className: "space-y-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center space-y-4", children: [
|
|
1385
|
-
/* @__PURE__ */ jsxRuntime.jsx(CardDescription, { className: "text-xs tracking-[0.18em] uppercase", children: "Join URL" }),
|
|
1386
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-center font-mono text-xs break-all", children: joinUrl }),
|
|
1387
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-border bg-card w-48 overflow-hidden rounded-lg border-2 shadow-md", children: qrUrl ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1388
|
-
"img",
|
|
1389
|
-
{
|
|
1390
|
-
src: qrUrl,
|
|
1391
|
-
alt: `Join room ${roomId}`,
|
|
1392
|
-
className: "w-full rounded bg-white"
|
|
1393
|
-
}
|
|
1394
|
-
) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-muted-foreground flex h-48 items-center justify-center text-sm", children: qrError ? `QR failed: ${qrError}` : "Generating QR code\u2026" }) }),
|
|
1395
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full", children: players.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground py-4 text-center text-sm", children: "Waiting for controllers to join\u2026" }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
|
|
1396
|
-
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-foreground text-center text-sm font-medium", children: [
|
|
1397
|
-
"Connected Players (",
|
|
1398
|
-
players.length,
|
|
1399
|
-
")"
|
|
1400
|
-
] }),
|
|
1401
|
-
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "flex flex-wrap items-center justify-center gap-4", children: players.map((player) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1402
|
-
"li",
|
|
1403
|
-
{
|
|
1404
|
-
className: "flex flex-col items-center gap-2",
|
|
1405
|
-
children: [
|
|
1406
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1407
|
-
"img",
|
|
1408
|
-
{
|
|
1409
|
-
src: getPlayerAvatarUrl(player.id),
|
|
1410
|
-
alt: player.label,
|
|
1411
|
-
className: "bg-secondary/30 h-16 w-16 rounded-full border-4 shadow-md",
|
|
1412
|
-
style: {
|
|
1413
|
-
borderColor: player.color || "hsl(var(--border))"
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
),
|
|
1417
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-0.5", children: [
|
|
1418
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-card-foreground max-w-[100px] truncate text-center text-sm font-medium", children: player.label }),
|
|
1419
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground font-mono text-xs", children: player.id.slice(0, 8) })
|
|
1420
|
-
] })
|
|
1421
|
-
]
|
|
1422
|
-
},
|
|
1423
|
-
player.id
|
|
1424
|
-
)) })
|
|
1425
|
-
] }) }),
|
|
1426
|
-
lastError && /* @__PURE__ */ jsxRuntime.jsx(Alert, { variant: "destructive", className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsx(AlertDescription, { children: lastError }) }),
|
|
1427
|
-
onTogglePlayPause && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1428
|
-
Button,
|
|
1429
|
-
{
|
|
1430
|
-
type: "button",
|
|
1431
|
-
onClick: onTogglePlayPause,
|
|
1432
|
-
size: "lg",
|
|
1433
|
-
children: [
|
|
1434
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "mr-2 h-5 w-5" }),
|
|
1435
|
-
"Start Game"
|
|
1436
|
-
]
|
|
1437
|
-
}
|
|
1438
|
-
) })
|
|
1439
|
-
] }) })
|
|
1440
|
-
] })
|
|
1441
|
-
}
|
|
1442
|
-
),
|
|
1443
|
-
isChildMode && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1444
|
-
TabsContent,
|
|
1445
|
-
{
|
|
1446
|
-
value: "info",
|
|
1447
|
-
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
1448
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6 pb-6", children: [
|
|
1449
|
-
/* @__PURE__ */ jsxRuntime.jsxs(CardHeader, { className: "pt-6 text-center", children: [
|
|
1450
|
-
/* @__PURE__ */ jsxRuntime.jsx(CardTitle, { className: "text-2xl font-bold tracking-wider", children: "Connected to Platform" }),
|
|
1451
|
-
/* @__PURE__ */ jsxRuntime.jsx(CardDescription, { className: "mt-2", children: "This game is running inside the Air Jam Platform." })
|
|
1452
|
-
] }),
|
|
1453
|
-
/* @__PURE__ */ jsxRuntime.jsx(CardContent, { className: "space-y-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center space-y-4", children: [
|
|
1454
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
|
|
1455
|
-
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-foreground text-center text-sm font-medium", children: [
|
|
1456
|
-
"Connected Players (",
|
|
1457
|
-
players.length,
|
|
1458
|
-
")"
|
|
1459
|
-
] }),
|
|
1460
|
-
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "flex flex-wrap items-center justify-center gap-4", children: players.map((player) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1461
|
-
"li",
|
|
1462
|
-
{
|
|
1463
|
-
className: "flex flex-col items-center gap-2",
|
|
1464
|
-
children: [
|
|
1465
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1466
|
-
"img",
|
|
1467
|
-
{
|
|
1468
|
-
src: getPlayerAvatarUrl(player.id),
|
|
1469
|
-
alt: player.label,
|
|
1470
|
-
className: "bg-secondary/30 h-16 w-16 rounded-full border-4 shadow-md",
|
|
1471
|
-
style: {
|
|
1472
|
-
borderColor: player.color || "hsl(var(--border))"
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
),
|
|
1476
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-center gap-0.5", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-card-foreground max-w-[100px] truncate text-center text-sm font-medium", children: player.label }) })
|
|
1477
|
-
]
|
|
1478
|
-
},
|
|
1479
|
-
player.id
|
|
1480
|
-
)) })
|
|
1481
|
-
] }) }),
|
|
1482
|
-
onTogglePlayPause && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1483
|
-
Button,
|
|
1484
|
-
{
|
|
1485
|
-
type: "button",
|
|
1486
|
-
onClick: onTogglePlayPause,
|
|
1487
|
-
size: "lg",
|
|
1488
|
-
children: [
|
|
1489
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "mr-2 h-5 w-5" }),
|
|
1490
|
-
"Resume Game"
|
|
1491
|
-
]
|
|
1492
|
-
}
|
|
1493
|
-
) })
|
|
1494
|
-
] }) })
|
|
1495
|
-
] })
|
|
1496
|
-
}
|
|
1497
|
-
),
|
|
1498
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1499
|
-
TabsContent,
|
|
1500
|
-
{
|
|
1501
|
-
value: "settings",
|
|
1502
|
-
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
1503
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(CardContent, { className: "pt-6 pb-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6", children: [
|
|
1504
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-4", children: /* @__PURE__ */ jsxRuntime.jsx(VolumeControls, {}) }),
|
|
1505
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
1506
|
-
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold", children: "Connection" }),
|
|
1507
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
1508
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1509
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Status" }),
|
|
1510
|
-
/* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: connectionVariant, children: statusCopy[connectionStatus] })
|
|
1511
|
-
] }),
|
|
1512
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1513
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Room ID" }),
|
|
1514
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono text-sm", children: roomId })
|
|
1515
|
-
] }),
|
|
1516
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1517
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Players" }),
|
|
1518
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: players.length })
|
|
1519
|
-
] })
|
|
1520
|
-
] })
|
|
1521
|
-
] }),
|
|
1522
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
1523
|
-
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold", children: "Display" }),
|
|
1524
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1525
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Game State" }),
|
|
1526
|
-
/* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "outline", className: "capitalize", children: gameState })
|
|
1527
|
-
] }) })
|
|
1528
|
-
] })
|
|
1529
|
-
] }) })
|
|
1530
|
-
}
|
|
1531
|
-
)
|
|
1532
|
-
]
|
|
1533
|
-
}
|
|
1534
|
-
) }) }) })
|
|
1535
|
-
] });
|
|
1536
|
-
};
|
|
1537
|
-
var useFullscreen = () => {
|
|
1538
|
-
const [isFullscreen, setIsFullscreen] = React.useState(false);
|
|
1539
|
-
React.useEffect(() => {
|
|
1540
|
-
const handleFullscreenChange = () => {
|
|
1541
|
-
const doc = document;
|
|
1542
|
-
setIsFullscreen(
|
|
1543
|
-
!!(document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement)
|
|
1544
|
-
);
|
|
1545
|
-
};
|
|
1546
|
-
document.addEventListener("fullscreenchange", handleFullscreenChange);
|
|
1547
|
-
document.addEventListener("webkitfullscreenchange", handleFullscreenChange);
|
|
1548
|
-
document.addEventListener("mozfullscreenchange", handleFullscreenChange);
|
|
1549
|
-
document.addEventListener("msfullscreenchange", handleFullscreenChange);
|
|
1550
|
-
return () => {
|
|
1551
|
-
document.removeEventListener("fullscreenchange", handleFullscreenChange);
|
|
1552
|
-
document.removeEventListener(
|
|
1553
|
-
"webkitfullscreenchange",
|
|
1554
|
-
handleFullscreenChange
|
|
1555
|
-
);
|
|
1556
|
-
document.removeEventListener(
|
|
1557
|
-
"mozfullscreenchange",
|
|
1558
|
-
handleFullscreenChange
|
|
1559
|
-
);
|
|
1560
|
-
document.removeEventListener(
|
|
1561
|
-
"msfullscreenchange",
|
|
1562
|
-
handleFullscreenChange
|
|
1563
|
-
);
|
|
1564
|
-
};
|
|
1565
|
-
}, []);
|
|
1566
|
-
const exitFullscreen = React.useCallback(async () => {
|
|
1567
|
-
try {
|
|
1568
|
-
const doc = document;
|
|
1569
|
-
if (document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement) {
|
|
1570
|
-
if (document.exitFullscreen) {
|
|
1571
|
-
await document.exitFullscreen();
|
|
1572
|
-
} else if (doc.webkitExitFullscreen) {
|
|
1573
|
-
await doc.webkitExitFullscreen();
|
|
1574
|
-
} else if (doc.mozCancelFullScreen) {
|
|
1575
|
-
await doc.mozCancelFullScreen();
|
|
1576
|
-
} else if (doc.msExitFullscreen) {
|
|
1577
|
-
await doc.msExitFullscreen();
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
} catch (error) {
|
|
1581
|
-
console.error("Error exiting fullscreen:", error);
|
|
1582
|
-
}
|
|
1583
|
-
}, []);
|
|
1584
|
-
const enterFullscreen = React.useCallback(async (element) => {
|
|
1585
|
-
try {
|
|
1586
|
-
const elem = element || document.documentElement;
|
|
1587
|
-
if (elem.requestFullscreen) {
|
|
1588
|
-
await elem.requestFullscreen();
|
|
1589
|
-
} else if (elem.webkitRequestFullscreen) {
|
|
1590
|
-
await elem.webkitRequestFullscreen();
|
|
1591
|
-
} else if (elem.mozRequestFullScreen) {
|
|
1592
|
-
await elem.mozRequestFullScreen();
|
|
1593
|
-
} else if (elem.msRequestFullscreen) {
|
|
1594
|
-
await elem.msRequestFullscreen();
|
|
1000
|
+
type: "button",
|
|
1001
|
+
variant: "ghost",
|
|
1002
|
+
size: "icon",
|
|
1003
|
+
onClick: () => setIsOpen(true),
|
|
1004
|
+
"aria-label": "Debug state",
|
|
1005
|
+
title,
|
|
1006
|
+
className: `text-white hover:bg-white/20 hover:text-white ${className || ""}`,
|
|
1007
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Bug, { className: "h-4 w-4" })
|
|
1595
1008
|
}
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
await enterFullscreen(element);
|
|
1009
|
+
),
|
|
1010
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1011
|
+
DebugStateDialog,
|
|
1012
|
+
{
|
|
1013
|
+
isOpen,
|
|
1014
|
+
onClose: () => setIsOpen(false),
|
|
1015
|
+
getState: () => currentState,
|
|
1016
|
+
title,
|
|
1017
|
+
updateInterval
|
|
1606
1018
|
}
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
);
|
|
1610
|
-
return {
|
|
1611
|
-
isFullscreen,
|
|
1612
|
-
enterFullscreen,
|
|
1613
|
-
exitFullscreen,
|
|
1614
|
-
toggleFullscreen
|
|
1615
|
-
};
|
|
1616
|
-
};
|
|
1617
|
-
|
|
1618
|
-
// src/utils/mode.ts
|
|
1619
|
-
var detectRunMode = () => {
|
|
1620
|
-
if (typeof window === "undefined") {
|
|
1621
|
-
return "standalone";
|
|
1622
|
-
}
|
|
1623
|
-
try {
|
|
1624
|
-
return window.self !== window.top ? "platform" : "standalone";
|
|
1625
|
-
} catch {
|
|
1626
|
-
return "platform";
|
|
1627
|
-
}
|
|
1019
|
+
)
|
|
1020
|
+
] });
|
|
1628
1021
|
};
|
|
1629
1022
|
var roomCodeSchema = zod.z.string().trim().min(4).max(8).regex(/^[A-Z0-9]+$/, { message: "room code must contain only A-Z or 0-9" });
|
|
1630
1023
|
var controllerInputSchema = zod.z.object({
|
|
@@ -1692,6 +1085,41 @@ var hostJoinAsChildSchema = zod.z.object({
|
|
|
1692
1085
|
});
|
|
1693
1086
|
var AIRJAM_PROXY_PREFIX = "AIRJAM_";
|
|
1694
1087
|
|
|
1088
|
+
// src/utils/ids.ts
|
|
1089
|
+
var alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
1090
|
+
var generateRoomCode = () => {
|
|
1091
|
+
const array = new Uint32Array(4);
|
|
1092
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
1093
|
+
crypto.getRandomValues(array);
|
|
1094
|
+
} else {
|
|
1095
|
+
for (let i = 0; i < array.length; i += 1) {
|
|
1096
|
+
array[i] = Math.floor(Math.random() * alphabet.length);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
const code = Array.from(
|
|
1100
|
+
array,
|
|
1101
|
+
(value) => alphabet[value % alphabet.length]
|
|
1102
|
+
).join("");
|
|
1103
|
+
return roomCodeSchema.parse(code);
|
|
1104
|
+
};
|
|
1105
|
+
var generateControllerId = () => {
|
|
1106
|
+
const stamp = Math.floor(Date.now() % 1e5).toString().padStart(5, "0");
|
|
1107
|
+
const random = alphabet[Math.floor(Math.random() * alphabet.length)];
|
|
1108
|
+
return `C${random}${stamp}`;
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
// src/utils/mode.ts
|
|
1112
|
+
var detectRunMode = () => {
|
|
1113
|
+
if (typeof window === "undefined") {
|
|
1114
|
+
return "standalone";
|
|
1115
|
+
}
|
|
1116
|
+
try {
|
|
1117
|
+
return window.self !== window.top ? "platform" : "standalone";
|
|
1118
|
+
} catch {
|
|
1119
|
+
return "platform";
|
|
1120
|
+
}
|
|
1121
|
+
};
|
|
1122
|
+
|
|
1695
1123
|
// src/utils/network-ip.ts
|
|
1696
1124
|
var isVirtualNetwork = (ip) => {
|
|
1697
1125
|
if (ip.startsWith("192.168.64.") || ip.startsWith("192.168.65.")) {
|
|
@@ -1905,1206 +1333,1944 @@ var UrlBuilder = class {
|
|
|
1905
1333
|
}
|
|
1906
1334
|
};
|
|
1907
1335
|
var urlBuilder = new UrlBuilder();
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1336
|
+
|
|
1337
|
+
// src/hooks/use-air-jam-host.ts
|
|
1338
|
+
var useAirJamHost = (options = {}) => {
|
|
1339
|
+
const { config, store, getSocket, disconnectSocket, inputManager } = useAirJamContext();
|
|
1340
|
+
const arcadeParams = React.useMemo(() => {
|
|
1341
|
+
if (typeof window === "undefined") return null;
|
|
1342
|
+
const params = new URLSearchParams(window.location.search);
|
|
1343
|
+
const room = params.get("aj_room");
|
|
1344
|
+
const token = params.get("aj_token");
|
|
1345
|
+
if (room && token) {
|
|
1346
|
+
return { room, token };
|
|
1347
|
+
}
|
|
1348
|
+
return null;
|
|
1349
|
+
}, []);
|
|
1350
|
+
const isChildMode = !!arcadeParams;
|
|
1351
|
+
const shouldConnect = true;
|
|
1352
|
+
const [fallbackRoomId] = React.useState(() => generateRoomCode());
|
|
1353
|
+
const parsedRoomId = React.useMemo(() => {
|
|
1354
|
+
if (arcadeParams) {
|
|
1355
|
+
return roomCodeSchema.parse(arcadeParams.room.toUpperCase());
|
|
1356
|
+
}
|
|
1357
|
+
if (typeof window !== "undefined") {
|
|
1358
|
+
const params = new URLSearchParams(window.location.search);
|
|
1359
|
+
const paramRoom = params.get("room");
|
|
1360
|
+
if (paramRoom) {
|
|
1361
|
+
const result = roomCodeSchema.safeParse(paramRoom.toUpperCase());
|
|
1362
|
+
if (result.success) return result.data;
|
|
1916
1363
|
}
|
|
1917
1364
|
}
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
}
|
|
1924
|
-
return null;
|
|
1925
|
-
};
|
|
1926
|
-
var QRScannerDialog = ({
|
|
1927
|
-
isOpen,
|
|
1928
|
-
onClose,
|
|
1929
|
-
onScan,
|
|
1930
|
-
currentRoomId
|
|
1931
|
-
}) => {
|
|
1932
|
-
const [code, setCode] = React.useState("");
|
|
1933
|
-
const [isCameraAvailable, setIsCameraAvailable] = React.useState(false);
|
|
1934
|
-
const [joinUrl, setJoinUrl] = React.useState("");
|
|
1935
|
-
const [copied, setCopied] = React.useState(false);
|
|
1936
|
-
const scannerRef = React.useRef(null);
|
|
1937
|
-
const inputRef = React.useRef(null);
|
|
1938
|
-
const prevIsOpenRef = React.useRef(false);
|
|
1365
|
+
if (options.roomId) {
|
|
1366
|
+
return roomCodeSchema.parse(options.roomId.toUpperCase());
|
|
1367
|
+
}
|
|
1368
|
+
return fallbackRoomId;
|
|
1369
|
+
}, [options.roomId, fallbackRoomId, arcadeParams]);
|
|
1939
1370
|
React.useEffect(() => {
|
|
1940
|
-
if (
|
|
1941
|
-
|
|
1942
|
-
setTimeout(() => {
|
|
1943
|
-
setIsCameraAvailable(false);
|
|
1944
|
-
setCode(initialCode);
|
|
1945
|
-
inputRef.current?.focus();
|
|
1946
|
-
inputRef.current?.select();
|
|
1947
|
-
}, 0);
|
|
1371
|
+
if (inputManager) {
|
|
1372
|
+
inputManager.setRoomId(parsedRoomId);
|
|
1948
1373
|
}
|
|
1949
|
-
|
|
1950
|
-
|
|
1374
|
+
}, [inputManager, parsedRoomId]);
|
|
1375
|
+
const [joinUrl, setJoinUrl] = React.useState("");
|
|
1376
|
+
const onPlayerJoinRef = React.useRef(options.onPlayerJoin);
|
|
1377
|
+
const onPlayerLeaveRef = React.useRef(options.onPlayerLeave);
|
|
1378
|
+
const onChildCloseRef = React.useRef(options.onChildClose);
|
|
1951
1379
|
React.useEffect(() => {
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1380
|
+
onPlayerJoinRef.current = options.onPlayerJoin;
|
|
1381
|
+
onPlayerLeaveRef.current = options.onPlayerLeave;
|
|
1382
|
+
onChildCloseRef.current = options.onChildClose;
|
|
1383
|
+
}, [options.onPlayerJoin, options.onPlayerLeave, options.onChildClose]);
|
|
1384
|
+
const connectionState = zustand.useStore(
|
|
1385
|
+
store,
|
|
1386
|
+
shallow.useShallow((state) => ({
|
|
1387
|
+
connectionStatus: state.connectionStatus,
|
|
1388
|
+
lastError: state.lastError,
|
|
1389
|
+
players: state.players,
|
|
1390
|
+
gameState: state.gameState,
|
|
1391
|
+
mode: state.mode
|
|
1392
|
+
}))
|
|
1393
|
+
);
|
|
1394
|
+
const socket = React.useMemo(
|
|
1395
|
+
() => getSocket("host") ,
|
|
1396
|
+
[shouldConnect, getSocket]
|
|
1397
|
+
);
|
|
1398
|
+
const [lastToggle, setLastToggle] = React.useState(0);
|
|
1399
|
+
const toggleGameState = React.useCallback(() => {
|
|
1400
|
+
const now = Date.now();
|
|
1401
|
+
if (now - lastToggle < TOGGLE_DEBOUNCE_MS) {
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1404
|
+
setLastToggle(now);
|
|
1405
|
+
if (!socket || !socket.connected) {
|
|
1406
|
+
return;
|
|
1407
|
+
}
|
|
1408
|
+
const payload = controllerSystemSchema.safeParse({
|
|
1409
|
+
roomId: parsedRoomId,
|
|
1410
|
+
command: "toggle_pause"
|
|
1411
|
+
});
|
|
1412
|
+
if (payload.success) {
|
|
1413
|
+
socket.emit("host:system", payload.data);
|
|
1414
|
+
}
|
|
1415
|
+
}, [socket, parsedRoomId, lastToggle]);
|
|
1416
|
+
const sendState = React.useCallback(
|
|
1417
|
+
(state) => {
|
|
1418
|
+
if (!socket || !socket.connected) {
|
|
1419
|
+
return false;
|
|
1964
1420
|
}
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
});
|
|
1982
|
-
scannerRef.current = null;
|
|
1421
|
+
const payload = controllerStateSchema.safeParse({
|
|
1422
|
+
roomId: parsedRoomId,
|
|
1423
|
+
state
|
|
1424
|
+
});
|
|
1425
|
+
if (!payload.success) {
|
|
1426
|
+
return false;
|
|
1427
|
+
}
|
|
1428
|
+
socket.emit("host:state", payload.data);
|
|
1429
|
+
return true;
|
|
1430
|
+
},
|
|
1431
|
+
[socket, parsedRoomId]
|
|
1432
|
+
);
|
|
1433
|
+
const sendSignal = React.useCallback(
|
|
1434
|
+
(type, payload, targetId) => {
|
|
1435
|
+
if (!socket || !socket.connected) {
|
|
1436
|
+
return;
|
|
1983
1437
|
}
|
|
1438
|
+
const signal = {
|
|
1439
|
+
targetId,
|
|
1440
|
+
type,
|
|
1441
|
+
payload
|
|
1442
|
+
};
|
|
1443
|
+
socket.emit("host:signal", signal);
|
|
1444
|
+
},
|
|
1445
|
+
[socket]
|
|
1446
|
+
);
|
|
1447
|
+
const reconnect = React.useCallback(() => {
|
|
1448
|
+
disconnectSocket("host");
|
|
1449
|
+
if (socket) {
|
|
1450
|
+
socket.connect();
|
|
1984
1451
|
}
|
|
1985
|
-
}, [
|
|
1452
|
+
}, [socket, disconnectSocket]);
|
|
1986
1453
|
React.useEffect(() => {
|
|
1987
|
-
|
|
1454
|
+
(async () => {
|
|
1455
|
+
const url = await urlBuilder.buildControllerUrl(parsedRoomId, {
|
|
1456
|
+
path: config.controllerPath,
|
|
1457
|
+
host: config.publicHost
|
|
1458
|
+
});
|
|
1459
|
+
setJoinUrl(url);
|
|
1460
|
+
})();
|
|
1461
|
+
}, [parsedRoomId, config.controllerPath, config.publicHost]);
|
|
1462
|
+
const setRegisteredRoomId = zustand.useStore(store, (s) => s.setRegisteredRoomId);
|
|
1463
|
+
React.useEffect(() => {
|
|
1464
|
+
const storeState = store.getState();
|
|
1465
|
+
storeState.setMode(detectRunMode());
|
|
1466
|
+
storeState.setRole("host");
|
|
1467
|
+
storeState.setRoomId(parsedRoomId);
|
|
1468
|
+
storeState.setStatus("connecting");
|
|
1469
|
+
storeState.setError(void 0);
|
|
1470
|
+
if (!socket) {
|
|
1471
|
+
storeState.setStatus("idle");
|
|
1988
1472
|
return;
|
|
1989
1473
|
}
|
|
1990
|
-
const
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
const
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
}
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
const backCamera = devices.find(
|
|
2011
|
-
(d) => d.label.toLowerCase().includes("back") || d.label.toLowerCase().includes("rear")
|
|
2012
|
-
);
|
|
2013
|
-
const envCamera = devices.find((d) => {
|
|
2014
|
-
const label = d.label.toLowerCase();
|
|
2015
|
-
return label.includes("environment") || label.includes("facing back");
|
|
2016
|
-
});
|
|
2017
|
-
cameraId = (envCamera || backCamera || devices[0])?.id || null;
|
|
1474
|
+
const registerHost = async () => {
|
|
1475
|
+
const storeState2 = store.getState();
|
|
1476
|
+
const currentRegisteredRoomId2 = store.getState().registeredRoomId;
|
|
1477
|
+
if (currentRegisteredRoomId2 === parsedRoomId && socket.connected) {
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
if (arcadeParams) {
|
|
1481
|
+
const childRoomId = roomCodeSchema.parse(
|
|
1482
|
+
arcadeParams.room.toUpperCase()
|
|
1483
|
+
);
|
|
1484
|
+
const payload = {
|
|
1485
|
+
roomId: childRoomId,
|
|
1486
|
+
joinToken: arcadeParams.token
|
|
1487
|
+
};
|
|
1488
|
+
socket.emit("host:joinAsChild", payload, (ack) => {
|
|
1489
|
+
if (!ack.ok) {
|
|
1490
|
+
storeState2.setError(ack.message ?? "Failed to join as child");
|
|
1491
|
+
storeState2.setStatus("disconnected");
|
|
1492
|
+
setRegisteredRoomId(null);
|
|
1493
|
+
return;
|
|
2018
1494
|
}
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
},
|
|
2036
|
-
(decodedText) => {
|
|
2037
|
-
if (!mounted) return;
|
|
2038
|
-
const roomCode = extractRoomCode(decodedText);
|
|
2039
|
-
if (roomCode) {
|
|
2040
|
-
setCode(roomCode);
|
|
2041
|
-
scannerRunning = false;
|
|
2042
|
-
scanner?.stop().catch(() => {
|
|
2043
|
-
}).finally(() => {
|
|
2044
|
-
if (mounted) {
|
|
2045
|
-
setIsCameraAvailable(false);
|
|
2046
|
-
}
|
|
2047
|
-
});
|
|
2048
|
-
}
|
|
2049
|
-
},
|
|
2050
|
-
() => {
|
|
1495
|
+
storeState2.setStatus("connected");
|
|
1496
|
+
storeState2.setRoomId(childRoomId);
|
|
1497
|
+
setRegisteredRoomId(childRoomId);
|
|
1498
|
+
});
|
|
1499
|
+
} else {
|
|
1500
|
+
const payload = hostRegistrationSchema.parse({
|
|
1501
|
+
roomId: parsedRoomId,
|
|
1502
|
+
maxPlayers: options.maxPlayers ?? config.maxPlayers,
|
|
1503
|
+
apiKey: options.apiKey ?? config.apiKey
|
|
1504
|
+
});
|
|
1505
|
+
socket.emit("host:register", payload, (ack) => {
|
|
1506
|
+
if (!ack.ok) {
|
|
1507
|
+
storeState2.setError(ack.message ?? "Failed to register host");
|
|
1508
|
+
storeState2.setStatus("disconnected");
|
|
1509
|
+
setRegisteredRoomId(null);
|
|
1510
|
+
return;
|
|
2051
1511
|
}
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
if (mounted) {
|
|
2059
|
-
setIsCameraAvailable(false);
|
|
2060
|
-
}
|
|
2061
|
-
if (scanner) {
|
|
2062
|
-
try {
|
|
2063
|
-
scanner.clear();
|
|
2064
|
-
} catch {
|
|
1512
|
+
storeState2.setStatus("connected");
|
|
1513
|
+
if (ack.roomId) {
|
|
1514
|
+
storeState2.setRoomId(ack.roomId);
|
|
1515
|
+
setRegisteredRoomId(ack.roomId);
|
|
1516
|
+
} else {
|
|
1517
|
+
setRegisteredRoomId(parsedRoomId);
|
|
2065
1518
|
}
|
|
2066
|
-
}
|
|
2067
|
-
scannerRef.current = null;
|
|
1519
|
+
});
|
|
2068
1520
|
}
|
|
2069
1521
|
};
|
|
2070
|
-
const
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
});
|
|
2084
|
-
} else if (scanner) {
|
|
2085
|
-
try {
|
|
2086
|
-
scanner.clear();
|
|
2087
|
-
} catch {
|
|
2088
|
-
}
|
|
1522
|
+
const handleConnect = () => {
|
|
1523
|
+
store.getState().setStatus("connected");
|
|
1524
|
+
registerHost();
|
|
1525
|
+
};
|
|
1526
|
+
const handleDisconnect = () => {
|
|
1527
|
+
store.getState().setStatus("disconnected");
|
|
1528
|
+
};
|
|
1529
|
+
const handleJoin = (payload) => {
|
|
1530
|
+
if (payload.player) {
|
|
1531
|
+
store.getState().upsertPlayer(payload.player);
|
|
1532
|
+
setTimeout(() => {
|
|
1533
|
+
onPlayerJoinRef.current?.(payload.player);
|
|
1534
|
+
}, 0);
|
|
2089
1535
|
}
|
|
2090
|
-
scannerRef.current = null;
|
|
2091
1536
|
};
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
1537
|
+
const handleLeave = (payload) => {
|
|
1538
|
+
store.getState().removePlayer(payload.controllerId);
|
|
1539
|
+
onPlayerLeaveRef.current?.(payload.controllerId);
|
|
1540
|
+
};
|
|
1541
|
+
const handleInput = (payload) => {
|
|
1542
|
+
if (inputManager) {
|
|
1543
|
+
inputManager.handleInput(payload);
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
const handleChildClose = () => {
|
|
1547
|
+
onChildCloseRef.current?.();
|
|
1548
|
+
};
|
|
1549
|
+
const handleState = (payload) => {
|
|
1550
|
+
if (payload.roomId !== parsedRoomId) return;
|
|
1551
|
+
const storeState2 = store.getState();
|
|
1552
|
+
if (payload.state.gameState) {
|
|
1553
|
+
storeState2.setGameState(payload.state.gameState);
|
|
1554
|
+
}
|
|
1555
|
+
if (payload.state.message !== void 0) {
|
|
1556
|
+
storeState2.setStateMessage(payload.state.message);
|
|
1557
|
+
}
|
|
1558
|
+
};
|
|
1559
|
+
const handleError = (payload) => {
|
|
1560
|
+
store.getState().setError(payload.message);
|
|
1561
|
+
};
|
|
1562
|
+
socket.on("connect", handleConnect);
|
|
1563
|
+
socket.on("disconnect", handleDisconnect);
|
|
1564
|
+
socket.on("server:controllerJoined", handleJoin);
|
|
1565
|
+
socket.on("server:controllerLeft", handleLeave);
|
|
1566
|
+
socket.on("server:input", handleInput);
|
|
1567
|
+
socket.on("server:error", handleError);
|
|
1568
|
+
socket.on("server:closeChild", handleChildClose);
|
|
1569
|
+
socket.on("server:state", handleState);
|
|
1570
|
+
socket.connect();
|
|
1571
|
+
const currentRegisteredRoomId = store.getState().registeredRoomId;
|
|
1572
|
+
if (socket.connected && currentRegisteredRoomId !== parsedRoomId) {
|
|
1573
|
+
registerHost();
|
|
1574
|
+
}
|
|
1575
|
+
if (currentRegisteredRoomId && currentRegisteredRoomId !== parsedRoomId) {
|
|
1576
|
+
setRegisteredRoomId(null);
|
|
2099
1577
|
}
|
|
1578
|
+
return () => {
|
|
1579
|
+
socket.off("connect", handleConnect);
|
|
1580
|
+
socket.off("disconnect", handleDisconnect);
|
|
1581
|
+
socket.off("server:controllerJoined", handleJoin);
|
|
1582
|
+
socket.off("server:controllerLeft", handleLeave);
|
|
1583
|
+
socket.off("server:input", handleInput);
|
|
1584
|
+
socket.off("server:error", handleError);
|
|
1585
|
+
socket.off("server:closeChild", handleChildClose);
|
|
1586
|
+
socket.off("server:state", handleState);
|
|
1587
|
+
};
|
|
1588
|
+
}, [
|
|
1589
|
+
config.maxPlayers,
|
|
1590
|
+
config.apiKey,
|
|
1591
|
+
options.maxPlayers,
|
|
1592
|
+
options.apiKey,
|
|
1593
|
+
parsedRoomId,
|
|
1594
|
+
arcadeParams,
|
|
1595
|
+
shouldConnect,
|
|
1596
|
+
socket,
|
|
1597
|
+
store,
|
|
1598
|
+
inputManager,
|
|
1599
|
+
setRegisteredRoomId
|
|
1600
|
+
]);
|
|
1601
|
+
const returnSocket = socket ?? getSocket("host");
|
|
1602
|
+
const getInput = React.useCallback(
|
|
1603
|
+
(controllerId) => {
|
|
1604
|
+
if (!inputManager) {
|
|
1605
|
+
return void 0;
|
|
1606
|
+
}
|
|
1607
|
+
return inputManager.getInput(controllerId);
|
|
1608
|
+
},
|
|
1609
|
+
[inputManager]
|
|
1610
|
+
);
|
|
1611
|
+
return {
|
|
1612
|
+
roomId: parsedRoomId,
|
|
1613
|
+
joinUrl,
|
|
1614
|
+
connectionStatus: connectionState.connectionStatus,
|
|
1615
|
+
players: connectionState.players,
|
|
1616
|
+
lastError: connectionState.lastError,
|
|
1617
|
+
mode: connectionState.mode,
|
|
1618
|
+
gameState: connectionState.gameState,
|
|
1619
|
+
toggleGameState,
|
|
1620
|
+
sendState,
|
|
1621
|
+
sendSignal,
|
|
1622
|
+
reconnect,
|
|
1623
|
+
socket: returnSocket,
|
|
1624
|
+
isChildMode,
|
|
1625
|
+
getInput
|
|
2100
1626
|
};
|
|
2101
|
-
|
|
2102
|
-
|
|
1627
|
+
};
|
|
1628
|
+
var getPlayerAvatarUrl = (playerId) => {
|
|
1629
|
+
return `https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=${encodeURIComponent(
|
|
1630
|
+
playerId
|
|
1631
|
+
)}`;
|
|
1632
|
+
};
|
|
1633
|
+
var hexToRgba = (hex, opacity) => {
|
|
1634
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
1635
|
+
if (!result) return `rgba(0, 0, 0, ${opacity})`;
|
|
1636
|
+
const r = parseInt(result[1], 16);
|
|
1637
|
+
const g = parseInt(result[2], 16);
|
|
1638
|
+
const b = parseInt(result[3], 16);
|
|
1639
|
+
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
1640
|
+
};
|
|
1641
|
+
var PlayerAvatar = ({
|
|
1642
|
+
player,
|
|
1643
|
+
size = "md",
|
|
1644
|
+
className = ""
|
|
1645
|
+
}) => {
|
|
1646
|
+
const sizeClasses = {
|
|
1647
|
+
sm: "h-8 w-8 border-2",
|
|
1648
|
+
md: "h-12 w-12 border-4",
|
|
1649
|
+
lg: "h-16 w-16 border-4"
|
|
2103
1650
|
};
|
|
2104
|
-
const
|
|
2105
|
-
|
|
2106
|
-
|
|
1651
|
+
const shadowStyles = {
|
|
1652
|
+
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)",
|
|
1653
|
+
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)",
|
|
1654
|
+
lg: player.color ? `inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 24px ${hexToRgba(player.color, 0.6)}, 0 0 12px ${hexToRgba(player.color, 0.8)}` : "inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 24px hsl(var(--border) / 0.5)"
|
|
2107
1655
|
};
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
textArea.style.position = "fixed";
|
|
2118
|
-
textArea.style.opacity = "0";
|
|
2119
|
-
document.body.appendChild(textArea);
|
|
2120
|
-
textArea.select();
|
|
2121
|
-
try {
|
|
2122
|
-
document.execCommand("copy");
|
|
2123
|
-
setCopied(true);
|
|
2124
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
2125
|
-
} catch {
|
|
1656
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1657
|
+
"img",
|
|
1658
|
+
{
|
|
1659
|
+
src: getPlayerAvatarUrl(player.id),
|
|
1660
|
+
alt: player.label,
|
|
1661
|
+
className: `bg-secondary/30 shrink-0 rounded-full shadow-lg ${sizeClasses[size]} ${className}`,
|
|
1662
|
+
style: {
|
|
1663
|
+
borderColor: player.color || "hsl(var(--border))",
|
|
1664
|
+
boxShadow: shadowStyles[size]
|
|
2126
1665
|
}
|
|
2127
|
-
document.body.removeChild(textArea);
|
|
2128
1666
|
}
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
1667
|
+
);
|
|
1668
|
+
};
|
|
1669
|
+
var alertVariants = classVarianceAuthority.cva(
|
|
1670
|
+
"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",
|
|
1671
|
+
{
|
|
1672
|
+
variants: {
|
|
1673
|
+
variant: {
|
|
1674
|
+
default: "bg-card text-card-foreground",
|
|
1675
|
+
destructive: "text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"
|
|
1676
|
+
}
|
|
1677
|
+
},
|
|
1678
|
+
defaultVariants: {
|
|
1679
|
+
variant: "default"
|
|
1680
|
+
}
|
|
2132
1681
|
}
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
}
|
|
2161
|
-
) }),
|
|
2162
|
-
joinUrl && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 w-full max-w-md px-6 pb-2", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2163
|
-
"button",
|
|
2164
|
-
{
|
|
2165
|
-
type: "button",
|
|
2166
|
-
onClick: handleCopyUrl,
|
|
2167
|
-
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",
|
|
2168
|
-
children: copied ? "\u2713 Copied!" : joinUrl
|
|
2169
|
-
}
|
|
2170
|
-
) })
|
|
2171
|
-
] }),
|
|
2172
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-md gap-4 px-6 pb-6", children: [
|
|
2173
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2174
|
-
Button,
|
|
2175
|
-
{
|
|
2176
|
-
type: "button",
|
|
2177
|
-
variant: "outline",
|
|
2178
|
-
onClick: onClose,
|
|
2179
|
-
className: "flex-1 py-6",
|
|
2180
|
-
children: "Cancel"
|
|
2181
|
-
}
|
|
1682
|
+
);
|
|
1683
|
+
function Alert({
|
|
1684
|
+
className,
|
|
1685
|
+
variant,
|
|
1686
|
+
...props
|
|
1687
|
+
}) {
|
|
1688
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1689
|
+
"div",
|
|
1690
|
+
{
|
|
1691
|
+
"data-slot": "alert",
|
|
1692
|
+
role: "alert",
|
|
1693
|
+
className: cn(alertVariants({ variant }), className),
|
|
1694
|
+
...props
|
|
1695
|
+
}
|
|
1696
|
+
);
|
|
1697
|
+
}
|
|
1698
|
+
function AlertDescription({
|
|
1699
|
+
className,
|
|
1700
|
+
...props
|
|
1701
|
+
}) {
|
|
1702
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1703
|
+
"div",
|
|
1704
|
+
{
|
|
1705
|
+
"data-slot": "alert-description",
|
|
1706
|
+
className: cn(
|
|
1707
|
+
"text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",
|
|
1708
|
+
className
|
|
2182
1709
|
),
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
}
|
|
2201
|
-
var describeStatus = (status) => {
|
|
2202
|
-
switch (status) {
|
|
2203
|
-
case "connected":
|
|
2204
|
-
return "Connected to host";
|
|
2205
|
-
case "connecting":
|
|
2206
|
-
return "Connecting\u2026";
|
|
2207
|
-
case "reconnecting":
|
|
2208
|
-
return "Trying to reconnect\u2026";
|
|
2209
|
-
case "disconnected":
|
|
2210
|
-
return "Disconnected";
|
|
2211
|
-
case "idle":
|
|
2212
|
-
default:
|
|
2213
|
-
return "Idle";
|
|
1710
|
+
...props
|
|
1711
|
+
}
|
|
1712
|
+
);
|
|
1713
|
+
}
|
|
1714
|
+
var badgeVariants = classVarianceAuthority.cva(
|
|
1715
|
+
"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",
|
|
1716
|
+
{
|
|
1717
|
+
variants: {
|
|
1718
|
+
variant: {
|
|
1719
|
+
default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
|
1720
|
+
secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
|
1721
|
+
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",
|
|
1722
|
+
outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
|
|
1723
|
+
}
|
|
1724
|
+
},
|
|
1725
|
+
defaultVariants: {
|
|
1726
|
+
variant: "default"
|
|
1727
|
+
}
|
|
2214
1728
|
}
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
}
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
onRefresh,
|
|
2231
|
-
customActions
|
|
2232
|
-
}) => {
|
|
2233
|
-
const isChildMode = React.useMemo(() => detectRunMode() === "platform", []);
|
|
2234
|
-
const [isOrientationOk, setOrientationOk] = React.useState(
|
|
2235
|
-
() => orientationMatches(requiredOrientation)
|
|
1729
|
+
);
|
|
1730
|
+
function Badge({
|
|
1731
|
+
className,
|
|
1732
|
+
variant,
|
|
1733
|
+
asChild = false,
|
|
1734
|
+
...props
|
|
1735
|
+
}) {
|
|
1736
|
+
const Comp = asChild ? reactSlot.Slot : "span";
|
|
1737
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1738
|
+
Comp,
|
|
1739
|
+
{
|
|
1740
|
+
"data-slot": "badge",
|
|
1741
|
+
className: cn(badgeVariants({ variant }), className),
|
|
1742
|
+
...props
|
|
1743
|
+
}
|
|
2236
1744
|
);
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
1745
|
+
}
|
|
1746
|
+
function Card({ className, ...props }) {
|
|
1747
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1748
|
+
"div",
|
|
1749
|
+
{
|
|
1750
|
+
"data-slot": "card",
|
|
1751
|
+
className: cn(
|
|
1752
|
+
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
|
1753
|
+
className
|
|
1754
|
+
),
|
|
1755
|
+
...props
|
|
1756
|
+
}
|
|
2248
1757
|
);
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
return;
|
|
1758
|
+
}
|
|
1759
|
+
function CardTitle({ className, ...props }) {
|
|
1760
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1761
|
+
"div",
|
|
1762
|
+
{
|
|
1763
|
+
"data-slot": "card-title",
|
|
1764
|
+
className: cn("leading-none font-semibold", className),
|
|
1765
|
+
...props
|
|
2258
1766
|
}
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
case "connected":
|
|
2269
|
-
return "bg-green-500";
|
|
2270
|
-
case "connecting":
|
|
2271
|
-
case "reconnecting":
|
|
2272
|
-
return "bg-yellow-500";
|
|
2273
|
-
case "disconnected":
|
|
2274
|
-
default:
|
|
2275
|
-
return "bg-red-500";
|
|
1767
|
+
);
|
|
1768
|
+
}
|
|
1769
|
+
function CardDescription({ className, ...props }) {
|
|
1770
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1771
|
+
"div",
|
|
1772
|
+
{
|
|
1773
|
+
"data-slot": "card-description",
|
|
1774
|
+
className: cn("text-muted-foreground text-sm", className),
|
|
1775
|
+
...props
|
|
2276
1776
|
}
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
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
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
1777
|
+
);
|
|
1778
|
+
}
|
|
1779
|
+
function CardContent({ className, ...props }) {
|
|
1780
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1781
|
+
"div",
|
|
1782
|
+
{
|
|
1783
|
+
"data-slot": "card-content",
|
|
1784
|
+
className: cn("px-6", className),
|
|
1785
|
+
...props
|
|
1786
|
+
}
|
|
1787
|
+
);
|
|
1788
|
+
}
|
|
1789
|
+
function Tabs({
|
|
1790
|
+
className,
|
|
1791
|
+
...props
|
|
1792
|
+
}) {
|
|
1793
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1794
|
+
TabsPrimitive__namespace.Root,
|
|
1795
|
+
{
|
|
1796
|
+
"data-slot": "tabs",
|
|
1797
|
+
className: cn("flex flex-col gap-2", className),
|
|
1798
|
+
...props
|
|
1799
|
+
}
|
|
1800
|
+
);
|
|
1801
|
+
}
|
|
1802
|
+
function TabsList({
|
|
1803
|
+
className,
|
|
1804
|
+
...props
|
|
1805
|
+
}) {
|
|
1806
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1807
|
+
TabsPrimitive__namespace.List,
|
|
1808
|
+
{
|
|
1809
|
+
"data-slot": "tabs-list",
|
|
1810
|
+
className: cn(
|
|
1811
|
+
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
|
1812
|
+
className
|
|
1813
|
+
),
|
|
1814
|
+
...props
|
|
1815
|
+
}
|
|
1816
|
+
);
|
|
1817
|
+
}
|
|
1818
|
+
function TabsTrigger({
|
|
1819
|
+
className,
|
|
1820
|
+
...props
|
|
1821
|
+
}) {
|
|
1822
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1823
|
+
TabsPrimitive__namespace.Trigger,
|
|
1824
|
+
{
|
|
1825
|
+
"data-slot": "tabs-trigger",
|
|
1826
|
+
className: cn(
|
|
1827
|
+
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
1828
|
+
className
|
|
1829
|
+
),
|
|
1830
|
+
...props
|
|
1831
|
+
}
|
|
1832
|
+
);
|
|
1833
|
+
}
|
|
1834
|
+
function TabsContent({
|
|
1835
|
+
className,
|
|
1836
|
+
...props
|
|
1837
|
+
}) {
|
|
1838
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1839
|
+
TabsPrimitive__namespace.Content,
|
|
1840
|
+
{
|
|
1841
|
+
"data-slot": "tabs-content",
|
|
1842
|
+
className: cn("flex-1 outline-none", className),
|
|
1843
|
+
...props
|
|
1844
|
+
}
|
|
1845
|
+
);
|
|
1846
|
+
}
|
|
1847
|
+
function Slider({
|
|
1848
|
+
className,
|
|
1849
|
+
defaultValue,
|
|
1850
|
+
value,
|
|
1851
|
+
min = 0,
|
|
1852
|
+
max = 100,
|
|
1853
|
+
...props
|
|
1854
|
+
}) {
|
|
1855
|
+
const _values = React__namespace.useMemo(
|
|
1856
|
+
() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
|
|
1857
|
+
[value, defaultValue, min, max]
|
|
1858
|
+
);
|
|
1859
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1860
|
+
SliderPrimitive__namespace.Root,
|
|
1861
|
+
{
|
|
1862
|
+
"data-slot": "slider",
|
|
1863
|
+
defaultValue,
|
|
1864
|
+
value,
|
|
1865
|
+
min,
|
|
1866
|
+
max,
|
|
1867
|
+
className: cn(
|
|
1868
|
+
"relative flex w-full cursor-pointer touch-none items-center select-none data-disabled:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
|
|
1869
|
+
className
|
|
1870
|
+
),
|
|
1871
|
+
...props,
|
|
1872
|
+
children: [
|
|
1873
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1874
|
+
SliderPrimitive__namespace.Track,
|
|
2351
1875
|
{
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
disabled: connectionStatus === "connecting" || connectionStatus === "reconnecting",
|
|
2357
|
-
"aria-label": "Reconnect",
|
|
2358
|
-
title: "Reconnect to room",
|
|
1876
|
+
"data-slot": "slider-track",
|
|
1877
|
+
className: cn(
|
|
1878
|
+
"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"
|
|
1879
|
+
),
|
|
2359
1880
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2360
|
-
|
|
1881
|
+
SliderPrimitive__namespace.Range,
|
|
2361
1882
|
{
|
|
1883
|
+
"data-slot": "slider-range",
|
|
2362
1884
|
className: cn(
|
|
2363
|
-
"h-
|
|
2364
|
-
(connectionStatus === "connecting" || connectionStatus === "reconnecting") && "animate-spin"
|
|
1885
|
+
"bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
|
|
2365
1886
|
)
|
|
2366
1887
|
}
|
|
2367
1888
|
)
|
|
2368
1889
|
}
|
|
2369
1890
|
),
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
{
|
|
2373
|
-
type: "button",
|
|
2374
|
-
variant: "outline",
|
|
2375
|
-
size: "icon",
|
|
2376
|
-
onClick: () => setIsScannerOpen(true),
|
|
2377
|
-
"aria-label": "Scan QR code to reconnect",
|
|
2378
|
-
title: "Scan QR code to reconnect",
|
|
2379
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.QrCode, { className: "h-5 w-5" })
|
|
2380
|
-
}
|
|
2381
|
-
),
|
|
2382
|
-
onTogglePlayPause && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2383
|
-
Button,
|
|
2384
|
-
{
|
|
2385
|
-
type: "button",
|
|
2386
|
-
variant: "outline",
|
|
2387
|
-
size: "icon",
|
|
2388
|
-
onClick: onTogglePlayPause,
|
|
2389
|
-
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
2390
|
-
title: gameState === "playing" ? "Pause" : "Play",
|
|
2391
|
-
children: gameState === "playing" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, { className: "h-5 w-5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "h-5 w-5" })
|
|
2392
|
-
}
|
|
2393
|
-
),
|
|
2394
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2395
|
-
Button,
|
|
1891
|
+
Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1892
|
+
SliderPrimitive__namespace.Thumb,
|
|
2396
1893
|
{
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
1894
|
+
"data-slot": "slider-thumb",
|
|
1895
|
+
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"
|
|
1896
|
+
},
|
|
1897
|
+
index
|
|
1898
|
+
))
|
|
1899
|
+
]
|
|
1900
|
+
}
|
|
1901
|
+
);
|
|
1902
|
+
}
|
|
1903
|
+
function VolumeControls({ className, compact }) {
|
|
1904
|
+
const {
|
|
1905
|
+
masterVolume,
|
|
1906
|
+
musicVolume,
|
|
1907
|
+
sfxVolume,
|
|
1908
|
+
setMasterVolume,
|
|
1909
|
+
setMusicVolume,
|
|
1910
|
+
setSfxVolume
|
|
1911
|
+
} = useVolumeStore();
|
|
1912
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col gap-3", compact && "gap-1", className), children: [
|
|
1913
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1914
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Volume2, { className: "text-muted-foreground h-4 w-4" }),
|
|
1915
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: "Volume" })
|
|
2407
1916
|
] }),
|
|
2408
|
-
/* @__PURE__ */ jsxRuntime.
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
/* @__PURE__ */ jsxRuntime.
|
|
2412
|
-
|
|
2413
|
-
"
|
|
2414
|
-
requiredOrientation,
|
|
2415
|
-
" ",
|
|
2416
|
-
"orientation."
|
|
1917
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
|
|
1918
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1919
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-muted-foreground text-xs", children: "Master" }),
|
|
1920
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
1921
|
+
Math.round(masterVolume * 100),
|
|
1922
|
+
"%"
|
|
2417
1923
|
] })
|
|
2418
1924
|
] }),
|
|
2419
1925
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2420
|
-
|
|
1926
|
+
Slider,
|
|
2421
1927
|
{
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
1928
|
+
value: [masterVolume * 100],
|
|
1929
|
+
onValueChange: (values) => setMasterVolume(values[0] / 100),
|
|
1930
|
+
min: 0,
|
|
1931
|
+
max: 100,
|
|
1932
|
+
step: 1,
|
|
1933
|
+
className: "w-full",
|
|
1934
|
+
"aria-label": "Master volume"
|
|
2427
1935
|
}
|
|
2428
1936
|
)
|
|
2429
|
-
] })
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
}
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
}
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
LAUNCH_GAME: "system:launchGame",
|
|
2487
|
-
/**
|
|
2488
|
-
* Arcade closes a game
|
|
2489
|
-
*/
|
|
2490
|
-
CLOSE_GAME: "system:closeGame"
|
|
2491
|
-
};
|
|
2492
|
-
var ServerEvents = {
|
|
2493
|
-
/**
|
|
2494
|
-
* Welcome message with room/controller info
|
|
2495
|
-
*/
|
|
2496
|
-
WELCOME: "server:welcome",
|
|
2497
|
-
/**
|
|
2498
|
-
* Room is ready
|
|
2499
|
-
*/
|
|
2500
|
-
ROOM_READY: "server:roomReady",
|
|
2501
|
-
/**
|
|
2502
|
-
* Controller joined notification
|
|
2503
|
-
*/
|
|
2504
|
-
CONTROLLER_JOINED: "server:controllerJoined",
|
|
2505
|
-
/**
|
|
2506
|
-
* Controller left notification
|
|
2507
|
-
*/
|
|
2508
|
-
CONTROLLER_LEFT: "server:controllerLeft",
|
|
2509
|
-
/**
|
|
2510
|
-
* Host left notification
|
|
2511
|
-
*/
|
|
2512
|
-
HOST_LEFT: "server:hostLeft",
|
|
2513
|
-
/**
|
|
2514
|
-
* Server error
|
|
2515
|
-
*/
|
|
2516
|
-
ERROR: "server:error",
|
|
2517
|
-
/**
|
|
2518
|
-
* Play sound on client
|
|
2519
|
-
*/
|
|
2520
|
-
PLAY_SOUND: "server:playSound"
|
|
2521
|
-
};
|
|
2522
|
-
var ClientEvents = {
|
|
2523
|
-
/**
|
|
2524
|
-
* Load a game UI in the controller iframe
|
|
2525
|
-
*/
|
|
2526
|
-
LOAD_UI: "client:loadUi",
|
|
2527
|
-
/**
|
|
2528
|
-
* Unload the game UI from the controller iframe
|
|
2529
|
-
*/
|
|
2530
|
-
UNLOAD_UI: "client:unloadUi",
|
|
2531
|
-
/**
|
|
2532
|
-
* Update game state display
|
|
2533
|
-
*/
|
|
2534
|
-
STATE: "client:state"
|
|
2535
|
-
};
|
|
2536
|
-
var ChildEvents = {
|
|
2537
|
-
/**
|
|
2538
|
-
* Server requests child to close
|
|
2539
|
-
*/
|
|
2540
|
-
CLOSE: "child:close"
|
|
2541
|
-
};
|
|
2542
|
-
var Events = {
|
|
2543
|
-
Host: HostEvents,
|
|
2544
|
-
Controller: ControllerEvents,
|
|
2545
|
-
System: SystemEvents,
|
|
2546
|
-
Server: ServerEvents,
|
|
2547
|
-
Client: ClientEvents,
|
|
2548
|
-
Child: ChildEvents
|
|
1937
|
+
] }),
|
|
1938
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
|
|
1939
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1940
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
1941
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Music, { className: "text-muted-foreground h-3 w-3" }),
|
|
1942
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-muted-foreground text-xs", children: "Music" })
|
|
1943
|
+
] }),
|
|
1944
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
1945
|
+
Math.round(musicVolume * 100),
|
|
1946
|
+
"%"
|
|
1947
|
+
] })
|
|
1948
|
+
] }),
|
|
1949
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1950
|
+
Slider,
|
|
1951
|
+
{
|
|
1952
|
+
value: [musicVolume * 100],
|
|
1953
|
+
onValueChange: (values) => setMusicVolume(values[0] / 100),
|
|
1954
|
+
min: 0,
|
|
1955
|
+
max: 100,
|
|
1956
|
+
step: 1,
|
|
1957
|
+
className: "w-full",
|
|
1958
|
+
"aria-label": "Music volume"
|
|
1959
|
+
}
|
|
1960
|
+
)
|
|
1961
|
+
] }),
|
|
1962
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
|
|
1963
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1964
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
1965
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Headphones, { className: "text-muted-foreground h-3 w-3" }),
|
|
1966
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-muted-foreground text-xs", children: "SFX" })
|
|
1967
|
+
] }),
|
|
1968
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground font-mono text-xs", children: [
|
|
1969
|
+
Math.round(sfxVolume * 100),
|
|
1970
|
+
"%"
|
|
1971
|
+
] })
|
|
1972
|
+
] }),
|
|
1973
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1974
|
+
Slider,
|
|
1975
|
+
{
|
|
1976
|
+
value: [sfxVolume * 100],
|
|
1977
|
+
onValueChange: (values) => setSfxVolume(values[0] / 100),
|
|
1978
|
+
min: 0,
|
|
1979
|
+
max: 100,
|
|
1980
|
+
step: 1,
|
|
1981
|
+
className: "w-full",
|
|
1982
|
+
"aria-label": "SFX volume"
|
|
1983
|
+
}
|
|
1984
|
+
)
|
|
1985
|
+
] })
|
|
1986
|
+
] });
|
|
1987
|
+
}
|
|
1988
|
+
var statusCopy = {
|
|
1989
|
+
idle: "Idle",
|
|
1990
|
+
connecting: "Waiting for server\u2026",
|
|
1991
|
+
connected: "Ready for controllers",
|
|
1992
|
+
disconnected: "Disconnected",
|
|
1993
|
+
reconnecting: "Reconnecting\u2026"
|
|
2549
1994
|
};
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
1995
|
+
var AirJamOverlay = () => {
|
|
1996
|
+
const host = useAirJamHost();
|
|
1997
|
+
const {
|
|
1998
|
+
roomId,
|
|
1999
|
+
joinUrl,
|
|
2000
|
+
connectionStatus,
|
|
2001
|
+
players,
|
|
2002
|
+
lastError,
|
|
2003
|
+
gameState,
|
|
2004
|
+
toggleGameState,
|
|
2005
|
+
isChildMode
|
|
2006
|
+
} = host;
|
|
2007
|
+
const [qrUrl, setQrUrl] = React.useState(null);
|
|
2008
|
+
const [qrError, setQrError] = React.useState(null);
|
|
2009
|
+
const [copied, setCopied] = React.useState(false);
|
|
2010
|
+
const [copiedPlayerId, setCopiedPlayerId] = React.useState(null);
|
|
2011
|
+
React.useEffect(() => {
|
|
2012
|
+
if (isChildMode) return;
|
|
2013
|
+
let mounted = true;
|
|
2014
|
+
QRCode__default.default.toDataURL(joinUrl, {
|
|
2015
|
+
margin: 1,
|
|
2016
|
+
color: {
|
|
2017
|
+
dark: "#0f172a",
|
|
2018
|
+
light: "#ffffff"
|
|
2019
|
+
},
|
|
2020
|
+
width: 320
|
|
2021
|
+
}).then((value) => {
|
|
2022
|
+
if (mounted) {
|
|
2023
|
+
setQrUrl(value);
|
|
2024
|
+
setQrError(null);
|
|
2025
|
+
}
|
|
2026
|
+
}).catch((err) => {
|
|
2027
|
+
if (mounted) {
|
|
2028
|
+
setQrError(err.message);
|
|
2029
|
+
}
|
|
2030
|
+
});
|
|
2031
|
+
return () => {
|
|
2032
|
+
mounted = false;
|
|
2033
|
+
};
|
|
2034
|
+
}, [joinUrl, isChildMode]);
|
|
2035
|
+
const handleCopyUrl = async () => {
|
|
2036
|
+
if (!joinUrl) return;
|
|
2037
|
+
try {
|
|
2038
|
+
await navigator.clipboard.writeText(joinUrl);
|
|
2039
|
+
setCopied(true);
|
|
2040
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
2041
|
+
} catch {
|
|
2042
|
+
const textArea = document.createElement("textarea");
|
|
2043
|
+
textArea.value = joinUrl;
|
|
2044
|
+
textArea.style.position = "fixed";
|
|
2045
|
+
textArea.style.opacity = "0";
|
|
2046
|
+
document.body.appendChild(textArea);
|
|
2047
|
+
textArea.select();
|
|
2048
|
+
try {
|
|
2049
|
+
document.execCommand("copy");
|
|
2050
|
+
setCopied(true);
|
|
2051
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
2052
|
+
} catch {
|
|
2053
|
+
}
|
|
2054
|
+
document.body.removeChild(textArea);
|
|
2560
2055
|
}
|
|
2561
|
-
}
|
|
2562
|
-
const
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
).join("");
|
|
2566
|
-
return roomCodeSchema.parse(code);
|
|
2567
|
-
};
|
|
2568
|
-
var generateControllerId = () => {
|
|
2569
|
-
const stamp = Math.floor(Date.now() % 1e5).toString().padStart(5, "0");
|
|
2570
|
-
const random = alphabet[Math.floor(Math.random() * alphabet.length)];
|
|
2571
|
-
return `C${random}${stamp}`;
|
|
2572
|
-
};
|
|
2573
|
-
|
|
2574
|
-
// src/hooks/use-air-jam-controller.ts
|
|
2575
|
-
var getRoomFromLocation = () => {
|
|
2576
|
-
if (typeof window === "undefined") {
|
|
2577
|
-
return null;
|
|
2578
|
-
}
|
|
2579
|
-
const params = new URLSearchParams(window.location.search);
|
|
2580
|
-
const code = params.get("room");
|
|
2581
|
-
return code ? code.toUpperCase() : null;
|
|
2582
|
-
};
|
|
2583
|
-
var useAirJamController = (options = {}) => {
|
|
2584
|
-
const { store, getSocket, disconnectSocket } = useAirJamContext();
|
|
2585
|
-
const nicknameRef = React.useRef(options.nickname ?? "");
|
|
2586
|
-
const subControllerParams = React.useMemo(() => {
|
|
2587
|
-
if (typeof window === "undefined") return null;
|
|
2588
|
-
const params = new URLSearchParams(window.location.search);
|
|
2589
|
-
const room = params.get("aj_room");
|
|
2590
|
-
const controllerId2 = params.get("aj_controller_id");
|
|
2591
|
-
if (room && controllerId2) {
|
|
2592
|
-
return { room, controllerId: controllerId2 };
|
|
2056
|
+
};
|
|
2057
|
+
const handleOpenInNewTab = () => {
|
|
2058
|
+
if (joinUrl) {
|
|
2059
|
+
window.open(joinUrl, "_blank", "noopener,noreferrer");
|
|
2593
2060
|
}
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
const parsedRoomId = React.useMemo(() => {
|
|
2597
|
-
const code = subControllerParams?.room ?? options.roomId ?? getRoomFromLocation();
|
|
2598
|
-
if (!code) return null;
|
|
2061
|
+
};
|
|
2062
|
+
const handleCopyPlayerId = async (playerId) => {
|
|
2599
2063
|
try {
|
|
2600
|
-
|
|
2064
|
+
await navigator.clipboard.writeText(playerId);
|
|
2065
|
+
console.log(`Copied player ID: ${playerId}`);
|
|
2066
|
+
setCopiedPlayerId(playerId);
|
|
2067
|
+
setTimeout(() => setCopiedPlayerId(null), 1e3);
|
|
2601
2068
|
} catch {
|
|
2602
|
-
|
|
2069
|
+
const textArea = document.createElement("textarea");
|
|
2070
|
+
textArea.value = playerId;
|
|
2071
|
+
textArea.style.position = "fixed";
|
|
2072
|
+
textArea.style.opacity = "0";
|
|
2073
|
+
document.body.appendChild(textArea);
|
|
2074
|
+
textArea.select();
|
|
2075
|
+
try {
|
|
2076
|
+
document.execCommand("copy");
|
|
2077
|
+
console.log(`Copied player ID: ${playerId}`);
|
|
2078
|
+
setCopiedPlayerId(playerId);
|
|
2079
|
+
setTimeout(() => setCopiedPlayerId(null), 1e3);
|
|
2080
|
+
} catch {
|
|
2081
|
+
}
|
|
2082
|
+
document.body.removeChild(textArea);
|
|
2603
2083
|
}
|
|
2604
|
-
}
|
|
2605
|
-
const
|
|
2606
|
-
|
|
2607
|
-
|
|
2084
|
+
};
|
|
2085
|
+
const connectionVariant = React.useMemo(() => {
|
|
2086
|
+
switch (connectionStatus) {
|
|
2087
|
+
case "connected":
|
|
2088
|
+
return "default";
|
|
2089
|
+
case "connecting":
|
|
2090
|
+
case "reconnecting":
|
|
2091
|
+
return "secondary";
|
|
2092
|
+
default:
|
|
2093
|
+
return "destructive";
|
|
2608
2094
|
}
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
);
|
|
2636
|
-
const [reconnectKey, setReconnectKey] = React.useState(0);
|
|
2637
|
-
const reconnect = React.useCallback(() => {
|
|
2638
|
-
if (!parsedRoomId) return;
|
|
2639
|
-
disconnectSocket("controller");
|
|
2640
|
-
setReconnectKey((prev) => prev + 1);
|
|
2641
|
-
}, [parsedRoomId, disconnectSocket]);
|
|
2642
|
-
const isChildMode = React.useMemo(() => {
|
|
2643
|
-
if (typeof window === "undefined") return false;
|
|
2644
|
-
const params = new URLSearchParams(window.location.search);
|
|
2645
|
-
return params.get("airjam_mode") === "child";
|
|
2646
|
-
}, []);
|
|
2647
|
-
const shouldConnect = React.useMemo(() => {
|
|
2648
|
-
if (options.forceConnect) return true;
|
|
2649
|
-
if (subControllerParams) return true;
|
|
2650
|
-
if (typeof window !== "undefined") {
|
|
2651
|
-
const params = new URLSearchParams(window.location.search);
|
|
2652
|
-
return params.get("airjam_force_connect") === "true";
|
|
2653
|
-
}
|
|
2654
|
-
return false;
|
|
2655
|
-
}, [options.forceConnect, subControllerParams]);
|
|
2656
|
-
const canConnect = React.useMemo(
|
|
2657
|
-
() => !isChildMode || shouldConnect,
|
|
2658
|
-
[isChildMode, shouldConnect]
|
|
2659
|
-
);
|
|
2660
|
-
const socket = React.useMemo(
|
|
2661
|
-
() => canConnect && parsedRoomId ? getSocket("controller") : null,
|
|
2662
|
-
[canConnect, parsedRoomId, getSocket]
|
|
2663
|
-
);
|
|
2664
|
-
React.useEffect(() => {
|
|
2665
|
-
if (!socket) return;
|
|
2666
|
-
const handleSignal = (signal) => {
|
|
2667
|
-
if (signal.type !== "HAPTIC") return;
|
|
2668
|
-
if (typeof navigator === "undefined" || !navigator.vibrate) return;
|
|
2669
|
-
const payload = signal.payload;
|
|
2670
|
-
switch (payload.pattern) {
|
|
2671
|
-
case "light":
|
|
2672
|
-
navigator.vibrate(10);
|
|
2673
|
-
break;
|
|
2674
|
-
case "medium":
|
|
2675
|
-
navigator.vibrate(30);
|
|
2676
|
-
break;
|
|
2677
|
-
case "heavy":
|
|
2678
|
-
navigator.vibrate([50, 20, 50]);
|
|
2679
|
-
break;
|
|
2680
|
-
case "success":
|
|
2681
|
-
navigator.vibrate([10, 30, 10]);
|
|
2682
|
-
break;
|
|
2683
|
-
case "failure":
|
|
2684
|
-
navigator.vibrate([50, 50, 50, 50]);
|
|
2685
|
-
break;
|
|
2686
|
-
case "custom":
|
|
2687
|
-
if (Array.isArray(payload.sequence)) {
|
|
2688
|
-
navigator.vibrate(payload.sequence);
|
|
2689
|
-
} else if (typeof payload.sequence === "number") {
|
|
2690
|
-
navigator.vibrate(payload.sequence);
|
|
2095
|
+
}, [connectionStatus]);
|
|
2096
|
+
if (isChildMode) return null;
|
|
2097
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dark", children: [
|
|
2098
|
+
!isChildMode && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none absolute inset-x-0 top-0 z-99999", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mx-auto w-full", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
|
|
2099
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2100
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs tracking-[0.18em] uppercase", children: "Room" }),
|
|
2101
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-foreground text-lg font-semibold", children: roomId })
|
|
2102
|
+
] }) }),
|
|
2103
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
2104
|
+
players.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center -space-x-2", children: [
|
|
2105
|
+
players.slice(0, 4).map((player) => /* @__PURE__ */ jsxRuntime.jsx(PlayerAvatar, { player, size: "sm" }, player.id)),
|
|
2106
|
+
players.length > 4 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-background bg-muted flex h-8 w-8 items-center justify-center rounded-full border-2 text-xs font-medium", children: [
|
|
2107
|
+
"+",
|
|
2108
|
+
players.length - 4
|
|
2109
|
+
] })
|
|
2110
|
+
] }),
|
|
2111
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2112
|
+
Button,
|
|
2113
|
+
{
|
|
2114
|
+
type: "button",
|
|
2115
|
+
variant: "ghost",
|
|
2116
|
+
size: "icon",
|
|
2117
|
+
onClick: toggleGameState,
|
|
2118
|
+
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
2119
|
+
className: "h-8 w-8",
|
|
2120
|
+
children: gameState === "playing" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "h-4 w-4" })
|
|
2691
2121
|
}
|
|
2692
|
-
|
|
2122
|
+
)
|
|
2123
|
+
] })
|
|
2124
|
+
] }) }) }),
|
|
2125
|
+
gameState === "paused" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none fixed inset-0 z-99998 flex items-center justify-center p-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-auto w-full max-w-2xl", children: /* @__PURE__ */ jsxRuntime.jsx(Card, { className: "bg-card/20 flex max-h-[85vh] flex-col overflow-hidden border py-0 shadow-lg backdrop-blur-sm", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2126
|
+
Tabs,
|
|
2127
|
+
{
|
|
2128
|
+
defaultValue: isChildMode ? "settings" : "room-code",
|
|
2129
|
+
className: "flex h-full w-full flex-col gap-0",
|
|
2130
|
+
children: [
|
|
2131
|
+
/* @__PURE__ */ jsxRuntime.jsxs(TabsList, { className: "border-border grid w-full shrink-0 grid-cols-2 rounded-none border-b bg-transparent p-0", children: [
|
|
2132
|
+
!isChildMode && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2133
|
+
TabsTrigger,
|
|
2134
|
+
{
|
|
2135
|
+
value: "room-code",
|
|
2136
|
+
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2137
|
+
children: [
|
|
2138
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.QrCode, { className: "h-4 w-4" }),
|
|
2139
|
+
"Room Code"
|
|
2140
|
+
]
|
|
2141
|
+
}
|
|
2142
|
+
),
|
|
2143
|
+
isChildMode && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2144
|
+
TabsTrigger,
|
|
2145
|
+
{
|
|
2146
|
+
value: "info",
|
|
2147
|
+
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2148
|
+
children: [
|
|
2149
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.MonitorSmartphone, { className: "h-4 w-4" }),
|
|
2150
|
+
"Platform"
|
|
2151
|
+
]
|
|
2152
|
+
}
|
|
2153
|
+
),
|
|
2154
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2155
|
+
TabsTrigger,
|
|
2156
|
+
{
|
|
2157
|
+
value: "settings",
|
|
2158
|
+
className: "hover:bg-background/50 data-[state=active]:bg-background/50 flex items-center gap-2 rounded-none border-none bg-transparent",
|
|
2159
|
+
children: [
|
|
2160
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Settings, { className: "h-4 w-4" }),
|
|
2161
|
+
"Settings"
|
|
2162
|
+
]
|
|
2163
|
+
}
|
|
2164
|
+
)
|
|
2165
|
+
] }),
|
|
2166
|
+
!isChildMode && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2167
|
+
TabsContent,
|
|
2168
|
+
{
|
|
2169
|
+
value: "room-code",
|
|
2170
|
+
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2171
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-[auto_1fr]", children: [
|
|
2172
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start gap-4", children: [
|
|
2173
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
2174
|
+
/* @__PURE__ */ jsxRuntime.jsx(CardTitle, { className: "text-3xl font-bold tracking-wider", children: roomId }),
|
|
2175
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2176
|
+
Badge,
|
|
2177
|
+
{
|
|
2178
|
+
variant: connectionVariant,
|
|
2179
|
+
className: "w-fit",
|
|
2180
|
+
children: statusCopy[connectionStatus]
|
|
2181
|
+
}
|
|
2182
|
+
)
|
|
2183
|
+
] }),
|
|
2184
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-border bg-card w-48 shrink-0 overflow-hidden rounded-lg border-2 shadow-md", children: qrUrl ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2185
|
+
"img",
|
|
2186
|
+
{
|
|
2187
|
+
src: qrUrl,
|
|
2188
|
+
alt: `Join room ${roomId}`,
|
|
2189
|
+
className: "w-full rounded bg-white"
|
|
2190
|
+
}
|
|
2191
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-muted-foreground flex h-48 items-center justify-center text-sm", children: qrError ? `QR failed: ${qrError}` : "Generating QR code\u2026" }) })
|
|
2192
|
+
] }),
|
|
2193
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
2194
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
|
|
2195
|
+
/* @__PURE__ */ jsxRuntime.jsx(CardDescription, { className: "text-xs tracking-[0.18em] uppercase", children: "Join URL" }),
|
|
2196
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
2197
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2198
|
+
"input",
|
|
2199
|
+
{
|
|
2200
|
+
type: "text",
|
|
2201
|
+
readOnly: true,
|
|
2202
|
+
value: joinUrl,
|
|
2203
|
+
className: "bg-background border-input text-foreground focus:ring-ring flex h-10 w-full rounded-md border px-3 py-2 font-mono text-xs focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50"
|
|
2204
|
+
}
|
|
2205
|
+
),
|
|
2206
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2207
|
+
Button,
|
|
2208
|
+
{
|
|
2209
|
+
type: "button",
|
|
2210
|
+
variant: "outline",
|
|
2211
|
+
size: "icon",
|
|
2212
|
+
onClick: handleCopyUrl,
|
|
2213
|
+
className: "h-10 shrink-0",
|
|
2214
|
+
"aria-label": "Copy join URL",
|
|
2215
|
+
children: copied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "h-4 w-4" })
|
|
2216
|
+
}
|
|
2217
|
+
),
|
|
2218
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2219
|
+
Button,
|
|
2220
|
+
{
|
|
2221
|
+
type: "button",
|
|
2222
|
+
variant: "outline",
|
|
2223
|
+
size: "icon",
|
|
2224
|
+
onClick: handleOpenInNewTab,
|
|
2225
|
+
className: "h-10 shrink-0",
|
|
2226
|
+
"aria-label": "Open join URL in new tab",
|
|
2227
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ExternalLink, { className: "h-4 w-4" })
|
|
2228
|
+
}
|
|
2229
|
+
)
|
|
2230
|
+
] })
|
|
2231
|
+
] }),
|
|
2232
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: players.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-white", children: "Waiting for controllers to join\u2026" }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2233
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-foreground text-sm font-medium", children: [
|
|
2234
|
+
"Connected Players (",
|
|
2235
|
+
players.length,
|
|
2236
|
+
")"
|
|
2237
|
+
] }),
|
|
2238
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: players.map((player) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2239
|
+
"li",
|
|
2240
|
+
{
|
|
2241
|
+
className: "flex min-w-0 flex-col items-start gap-2",
|
|
2242
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full min-w-0 items-center gap-2", children: [
|
|
2243
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2244
|
+
PlayerAvatar,
|
|
2245
|
+
{
|
|
2246
|
+
player,
|
|
2247
|
+
size: "md"
|
|
2248
|
+
}
|
|
2249
|
+
),
|
|
2250
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5 overflow-hidden", children: [
|
|
2251
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-card-foreground truncate text-sm font-medium", children: player.label }),
|
|
2252
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2253
|
+
"div",
|
|
2254
|
+
{
|
|
2255
|
+
onClick: () => handleCopyPlayerId(player.id),
|
|
2256
|
+
className: "text-muted-foreground m-0 inline min-w-0 cursor-pointer truncate border-0 font-mono text-xs transition-colors hover:text-white",
|
|
2257
|
+
title: "Click to copy player ID",
|
|
2258
|
+
children: copiedPlayerId === player.id ? "Copied!" : player.id.slice(0, 8)
|
|
2259
|
+
}
|
|
2260
|
+
)
|
|
2261
|
+
] })
|
|
2262
|
+
] })
|
|
2263
|
+
},
|
|
2264
|
+
player.id
|
|
2265
|
+
)) })
|
|
2266
|
+
] }) }),
|
|
2267
|
+
lastError && /* @__PURE__ */ jsxRuntime.jsx(Alert, { variant: "destructive", className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsx(AlertDescription, { children: lastError }) }),
|
|
2268
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-auto flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2269
|
+
Button,
|
|
2270
|
+
{
|
|
2271
|
+
type: "button",
|
|
2272
|
+
onClick: toggleGameState,
|
|
2273
|
+
size: "lg",
|
|
2274
|
+
children: [
|
|
2275
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "mr-2 h-5 w-5" }),
|
|
2276
|
+
"Start Game"
|
|
2277
|
+
]
|
|
2278
|
+
}
|
|
2279
|
+
) })
|
|
2280
|
+
] })
|
|
2281
|
+
] }) })
|
|
2282
|
+
}
|
|
2283
|
+
),
|
|
2284
|
+
isChildMode && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2285
|
+
TabsContent,
|
|
2286
|
+
{
|
|
2287
|
+
value: "info",
|
|
2288
|
+
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2289
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6", children: [
|
|
2290
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
2291
|
+
/* @__PURE__ */ jsxRuntime.jsx(CardTitle, { className: "text-2xl font-bold tracking-wider", children: "Connected to Platform" }),
|
|
2292
|
+
/* @__PURE__ */ jsxRuntime.jsx(CardDescription, { children: "This game is running inside the Air Jam Platform." })
|
|
2293
|
+
] }),
|
|
2294
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
|
|
2295
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-foreground text-sm font-medium", children: [
|
|
2296
|
+
"Connected Players (",
|
|
2297
|
+
players.length,
|
|
2298
|
+
")"
|
|
2299
|
+
] }),
|
|
2300
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: players.map((player) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2301
|
+
"li",
|
|
2302
|
+
{
|
|
2303
|
+
className: "flex min-w-0 flex-col items-start gap-2",
|
|
2304
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full min-w-0 items-center gap-2", children: [
|
|
2305
|
+
/* @__PURE__ */ jsxRuntime.jsx(PlayerAvatar, { player, size: "md" }),
|
|
2306
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-card-foreground truncate text-sm font-medium", children: player.label }) })
|
|
2307
|
+
] })
|
|
2308
|
+
},
|
|
2309
|
+
player.id
|
|
2310
|
+
)) })
|
|
2311
|
+
] }),
|
|
2312
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2313
|
+
Button,
|
|
2314
|
+
{
|
|
2315
|
+
type: "button",
|
|
2316
|
+
onClick: toggleGameState,
|
|
2317
|
+
size: "lg",
|
|
2318
|
+
children: [
|
|
2319
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "mr-2 h-5 w-5" }),
|
|
2320
|
+
"Resume Game"
|
|
2321
|
+
]
|
|
2322
|
+
}
|
|
2323
|
+
) })
|
|
2324
|
+
] }) })
|
|
2325
|
+
}
|
|
2326
|
+
),
|
|
2327
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2328
|
+
TabsContent,
|
|
2329
|
+
{
|
|
2330
|
+
value: "settings",
|
|
2331
|
+
className: "mt-0 min-h-0 flex-1 overflow-y-auto",
|
|
2332
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(CardContent, { className: "pt-6 pb-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6", children: [
|
|
2333
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-4", children: /* @__PURE__ */ jsxRuntime.jsx(VolumeControls, {}) }),
|
|
2334
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
2335
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold", children: "Connection" }),
|
|
2336
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
2337
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2338
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Status" }),
|
|
2339
|
+
/* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: connectionVariant, children: statusCopy[connectionStatus] })
|
|
2340
|
+
] }),
|
|
2341
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2342
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Room ID" }),
|
|
2343
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono text-sm", children: roomId })
|
|
2344
|
+
] }),
|
|
2345
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2346
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Players" }),
|
|
2347
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: players.length })
|
|
2348
|
+
] })
|
|
2349
|
+
] })
|
|
2350
|
+
] }),
|
|
2351
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 border-t pt-4", children: [
|
|
2352
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold", children: "Display" }),
|
|
2353
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2354
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: "Game State" }),
|
|
2355
|
+
/* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "outline", className: "capitalize", children: gameState })
|
|
2356
|
+
] }) })
|
|
2357
|
+
] })
|
|
2358
|
+
] }) })
|
|
2359
|
+
}
|
|
2360
|
+
)
|
|
2361
|
+
]
|
|
2693
2362
|
}
|
|
2363
|
+
) }) }) })
|
|
2364
|
+
] });
|
|
2365
|
+
};
|
|
2366
|
+
var useFullscreen = () => {
|
|
2367
|
+
const [isFullscreen, setIsFullscreen] = React.useState(false);
|
|
2368
|
+
React.useEffect(() => {
|
|
2369
|
+
const handleFullscreenChange = () => {
|
|
2370
|
+
const doc = document;
|
|
2371
|
+
setIsFullscreen(
|
|
2372
|
+
!!(document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement)
|
|
2373
|
+
);
|
|
2694
2374
|
};
|
|
2695
|
-
|
|
2375
|
+
document.addEventListener("fullscreenchange", handleFullscreenChange);
|
|
2376
|
+
document.addEventListener("webkitfullscreenchange", handleFullscreenChange);
|
|
2377
|
+
document.addEventListener("mozfullscreenchange", handleFullscreenChange);
|
|
2378
|
+
document.addEventListener("msfullscreenchange", handleFullscreenChange);
|
|
2696
2379
|
return () => {
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
if (event.source !== window.parent) return;
|
|
2711
|
-
const data = event.data;
|
|
2712
|
-
if (data?.type === "AIRJAM_STATE") {
|
|
2713
|
-
const payload = data.payload;
|
|
2714
|
-
if (payload.gameState) storeState.setGameState(payload.gameState);
|
|
2715
|
-
if (payload.message !== void 0)
|
|
2716
|
-
storeState.setStateMessage(payload.message);
|
|
2717
|
-
onStateRef.current?.(payload);
|
|
2718
|
-
}
|
|
2719
|
-
};
|
|
2720
|
-
window.addEventListener("message", handleMessage);
|
|
2721
|
-
window.parent.postMessage({ type: "AIRJAM_READY" }, "*");
|
|
2722
|
-
return () => {
|
|
2723
|
-
window.removeEventListener("message", handleMessage);
|
|
2724
|
-
storeState.setStatus("disconnected");
|
|
2725
|
-
};
|
|
2726
|
-
}
|
|
2727
|
-
if (!parsedRoomId || !socket || !controllerId) {
|
|
2728
|
-
storeState.setStatus("idle");
|
|
2729
|
-
return;
|
|
2730
|
-
}
|
|
2731
|
-
storeState.setControllerId(controllerId);
|
|
2732
|
-
const handleConnect = () => {
|
|
2733
|
-
store.getState().setStatus("connected");
|
|
2734
|
-
if (subControllerParams) {
|
|
2735
|
-
return;
|
|
2736
|
-
}
|
|
2737
|
-
const payload = controllerJoinSchema.parse({
|
|
2738
|
-
roomId: parsedRoomId,
|
|
2739
|
-
controllerId,
|
|
2740
|
-
nickname: nicknameRef.current || void 0
|
|
2741
|
-
});
|
|
2742
|
-
socket.emit("controller:join", payload, (ack) => {
|
|
2743
|
-
const storeState2 = store.getState();
|
|
2744
|
-
if (!ack.ok) {
|
|
2745
|
-
storeState2.setError(ack.message ?? "Unable to join room");
|
|
2746
|
-
storeState2.setStatus("disconnected");
|
|
2747
|
-
return;
|
|
2748
|
-
}
|
|
2749
|
-
if (ack.controllerId) {
|
|
2750
|
-
storeState2.setControllerId(ack.controllerId);
|
|
2751
|
-
}
|
|
2752
|
-
storeState2.setStatus("connected");
|
|
2753
|
-
});
|
|
2754
|
-
};
|
|
2755
|
-
const handleDisconnect = () => {
|
|
2756
|
-
store.getState().setStatus("disconnected");
|
|
2757
|
-
};
|
|
2758
|
-
const handleWelcome = (payload) => {
|
|
2759
|
-
const storeState2 = store.getState();
|
|
2760
|
-
const storeRoomId = storeState2.roomId;
|
|
2761
|
-
if (storeRoomId && payload.roomId.toUpperCase() !== storeRoomId.toUpperCase()) {
|
|
2762
|
-
return;
|
|
2763
|
-
}
|
|
2764
|
-
if (!storeRoomId && payload.roomId) {
|
|
2765
|
-
storeState2.setRoomId(payload.roomId);
|
|
2766
|
-
}
|
|
2767
|
-
if (!payload.player) {
|
|
2768
|
-
storeState2.setError(
|
|
2769
|
-
"Welcome message received but no player profile included."
|
|
2770
|
-
);
|
|
2771
|
-
return;
|
|
2772
|
-
}
|
|
2773
|
-
storeState2.upsertPlayer(payload.player);
|
|
2774
|
-
};
|
|
2775
|
-
const handleState = (payload) => {
|
|
2776
|
-
if (payload.roomId !== parsedRoomId) return;
|
|
2777
|
-
const storeState2 = store.getState();
|
|
2778
|
-
if (payload.state.gameState) {
|
|
2779
|
-
storeState2.setGameState(payload.state.gameState);
|
|
2780
|
-
}
|
|
2781
|
-
if (payload.state.message !== void 0) {
|
|
2782
|
-
storeState2.setStateMessage(payload.state.message);
|
|
2783
|
-
}
|
|
2784
|
-
onStateRef.current?.(payload.state);
|
|
2785
|
-
};
|
|
2786
|
-
const handleHostLeft = (payload) => {
|
|
2787
|
-
const storeState2 = store.getState();
|
|
2788
|
-
storeState2.setError(payload.reason);
|
|
2789
|
-
storeState2.setStatus("disconnected");
|
|
2790
|
-
storeState2.resetGameState();
|
|
2791
|
-
setTimeout(() => {
|
|
2792
|
-
disconnectSocket("controller");
|
|
2793
|
-
setReconnectKey((prev) => prev + 1);
|
|
2794
|
-
}, 1e3);
|
|
2795
|
-
};
|
|
2796
|
-
const handleError = (payload) => {
|
|
2797
|
-
store.getState().setError(payload.message);
|
|
2798
|
-
};
|
|
2799
|
-
socket.on("connect", handleConnect);
|
|
2800
|
-
socket.on("disconnect", handleDisconnect);
|
|
2801
|
-
socket.on("server:welcome", handleWelcome);
|
|
2802
|
-
socket.on("server:state", handleState);
|
|
2803
|
-
socket.on("server:hostLeft", handleHostLeft);
|
|
2804
|
-
socket.on("server:error", handleError);
|
|
2805
|
-
socket.connect();
|
|
2806
|
-
return () => {
|
|
2807
|
-
socket.off("connect", handleConnect);
|
|
2808
|
-
socket.off("disconnect", handleDisconnect);
|
|
2809
|
-
socket.off("server:welcome", handleWelcome);
|
|
2810
|
-
socket.off("server:state", handleState);
|
|
2811
|
-
socket.off("server:hostLeft", handleHostLeft);
|
|
2812
|
-
socket.off("server:error", handleError);
|
|
2380
|
+
document.removeEventListener("fullscreenchange", handleFullscreenChange);
|
|
2381
|
+
document.removeEventListener(
|
|
2382
|
+
"webkitfullscreenchange",
|
|
2383
|
+
handleFullscreenChange
|
|
2384
|
+
);
|
|
2385
|
+
document.removeEventListener(
|
|
2386
|
+
"mozfullscreenchange",
|
|
2387
|
+
handleFullscreenChange
|
|
2388
|
+
);
|
|
2389
|
+
document.removeEventListener(
|
|
2390
|
+
"msfullscreenchange",
|
|
2391
|
+
handleFullscreenChange
|
|
2392
|
+
);
|
|
2813
2393
|
};
|
|
2814
|
-
}, [
|
|
2815
|
-
parsedRoomId,
|
|
2816
|
-
reconnectKey,
|
|
2817
|
-
canConnect,
|
|
2818
|
-
socket,
|
|
2819
|
-
controllerId,
|
|
2820
|
-
subControllerParams,
|
|
2821
|
-
store,
|
|
2822
|
-
disconnectSocket
|
|
2823
|
-
]);
|
|
2824
|
-
const setNickname = React.useCallback((value) => {
|
|
2825
|
-
nicknameRef.current = value;
|
|
2826
2394
|
}, []);
|
|
2827
|
-
const
|
|
2828
|
-
|
|
2829
|
-
const
|
|
2830
|
-
if (
|
|
2831
|
-
if (
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
);
|
|
2395
|
+
const exitFullscreen = React.useCallback(async () => {
|
|
2396
|
+
try {
|
|
2397
|
+
const doc = document;
|
|
2398
|
+
if (document.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement) {
|
|
2399
|
+
if (document.exitFullscreen) {
|
|
2400
|
+
await document.exitFullscreen();
|
|
2401
|
+
} else if (doc.webkitExitFullscreen) {
|
|
2402
|
+
await doc.webkitExitFullscreen();
|
|
2403
|
+
} else if (doc.mozCancelFullScreen) {
|
|
2404
|
+
await doc.mozCancelFullScreen();
|
|
2405
|
+
} else if (doc.msExitFullscreen) {
|
|
2406
|
+
await doc.msExitFullscreen();
|
|
2839
2407
|
}
|
|
2840
|
-
return true;
|
|
2841
|
-
}
|
|
2842
|
-
if (!parsedRoomId || !storeState.controllerId || !socket) {
|
|
2843
|
-
storeState.setError("Not connected to a room");
|
|
2844
|
-
return false;
|
|
2845
|
-
}
|
|
2846
|
-
if (!socket.connected) {
|
|
2847
|
-
return false;
|
|
2848
|
-
}
|
|
2849
|
-
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
2850
|
-
storeState.setError("Input must be an object");
|
|
2851
|
-
return false;
|
|
2852
2408
|
}
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2409
|
+
} catch (error) {
|
|
2410
|
+
console.error("Error exiting fullscreen:", error);
|
|
2411
|
+
}
|
|
2412
|
+
}, []);
|
|
2413
|
+
const enterFullscreen = React.useCallback(async (element) => {
|
|
2414
|
+
try {
|
|
2415
|
+
const elem = element || document.documentElement;
|
|
2416
|
+
if (elem.requestFullscreen) {
|
|
2417
|
+
await elem.requestFullscreen();
|
|
2418
|
+
} else if (elem.webkitRequestFullscreen) {
|
|
2419
|
+
await elem.webkitRequestFullscreen();
|
|
2420
|
+
} else if (elem.mozRequestFullScreen) {
|
|
2421
|
+
await elem.mozRequestFullScreen();
|
|
2422
|
+
} else if (elem.msRequestFullscreen) {
|
|
2423
|
+
await elem.msRequestFullscreen();
|
|
2861
2424
|
}
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
}
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
if (!socket.connected) return;
|
|
2873
|
-
const payload = controllerSystemSchema.safeParse({
|
|
2874
|
-
roomId: parsedRoomId,
|
|
2875
|
-
command
|
|
2876
|
-
});
|
|
2877
|
-
if (payload.success) {
|
|
2878
|
-
socket.emit("controller:system", payload.data);
|
|
2425
|
+
} catch (error) {
|
|
2426
|
+
console.error("Error entering fullscreen:", error);
|
|
2427
|
+
}
|
|
2428
|
+
}, []);
|
|
2429
|
+
const toggleFullscreen = React.useCallback(
|
|
2430
|
+
async (element) => {
|
|
2431
|
+
if (isFullscreen) {
|
|
2432
|
+
await exitFullscreen();
|
|
2433
|
+
} else {
|
|
2434
|
+
await enterFullscreen(element);
|
|
2879
2435
|
}
|
|
2880
2436
|
},
|
|
2881
|
-
[
|
|
2437
|
+
[isFullscreen, exitFullscreen, enterFullscreen]
|
|
2882
2438
|
);
|
|
2883
2439
|
return {
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
gameState: connectionState.gameState,
|
|
2889
|
-
stateMessage: connectionState.stateMessage,
|
|
2890
|
-
sendInput,
|
|
2891
|
-
sendSystemCommand,
|
|
2892
|
-
setNickname,
|
|
2893
|
-
reconnect,
|
|
2894
|
-
players: connectionState.players,
|
|
2895
|
-
socket
|
|
2440
|
+
isFullscreen,
|
|
2441
|
+
enterFullscreen,
|
|
2442
|
+
exitFullscreen,
|
|
2443
|
+
toggleFullscreen
|
|
2896
2444
|
};
|
|
2897
2445
|
};
|
|
2898
|
-
var
|
|
2899
|
-
|
|
2900
|
-
|
|
2446
|
+
var extractRoomCode = (text) => {
|
|
2447
|
+
try {
|
|
2448
|
+
const url = new URL(text);
|
|
2449
|
+
const roomParam = url.searchParams.get("room");
|
|
2450
|
+
if (roomParam) {
|
|
2451
|
+
const parsed2 = roomCodeSchema.safeParse(roomParam.toUpperCase());
|
|
2452
|
+
if (parsed2.success) {
|
|
2453
|
+
return parsed2.data;
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
} catch {
|
|
2457
|
+
}
|
|
2458
|
+
const parsed = roomCodeSchema.safeParse(text.trim().toUpperCase());
|
|
2459
|
+
if (parsed.success) {
|
|
2460
|
+
return parsed.data;
|
|
2461
|
+
}
|
|
2462
|
+
return null;
|
|
2463
|
+
};
|
|
2464
|
+
var QRScannerDialog = ({
|
|
2465
|
+
isOpen,
|
|
2466
|
+
onClose,
|
|
2467
|
+
onScan,
|
|
2468
|
+
currentRoomId
|
|
2469
|
+
}) => {
|
|
2470
|
+
const [code, setCode] = React.useState("");
|
|
2471
|
+
const [isCameraAvailable, setIsCameraAvailable] = React.useState(false);
|
|
2472
|
+
const [joinUrl, setJoinUrl] = React.useState("");
|
|
2473
|
+
const [copied, setCopied] = React.useState(false);
|
|
2474
|
+
const scannerRef = React.useRef(null);
|
|
2475
|
+
const inputRef = React.useRef(null);
|
|
2476
|
+
const prevIsOpenRef = React.useRef(false);
|
|
2477
|
+
React.useEffect(() => {
|
|
2478
|
+
if (isOpen && !prevIsOpenRef.current) {
|
|
2479
|
+
const initialCode = currentRoomId || "";
|
|
2480
|
+
setTimeout(() => {
|
|
2481
|
+
setIsCameraAvailable(false);
|
|
2482
|
+
setCode(initialCode);
|
|
2483
|
+
inputRef.current?.focus();
|
|
2484
|
+
inputRef.current?.select();
|
|
2485
|
+
}, 0);
|
|
2486
|
+
}
|
|
2487
|
+
prevIsOpenRef.current = isOpen;
|
|
2488
|
+
}, [isOpen, currentRoomId]);
|
|
2489
|
+
React.useEffect(() => {
|
|
2490
|
+
const buildUrl = async () => {
|
|
2491
|
+
const trimmed = code.trim().toUpperCase();
|
|
2492
|
+
const parsed = roomCodeSchema.safeParse(trimmed);
|
|
2493
|
+
if (parsed.success) {
|
|
2494
|
+
try {
|
|
2495
|
+
const url = await urlBuilder.buildControllerUrl(parsed.data);
|
|
2496
|
+
setJoinUrl(url);
|
|
2497
|
+
} catch {
|
|
2498
|
+
setJoinUrl("");
|
|
2499
|
+
}
|
|
2500
|
+
} else {
|
|
2501
|
+
setJoinUrl("");
|
|
2502
|
+
}
|
|
2503
|
+
};
|
|
2504
|
+
buildUrl();
|
|
2505
|
+
}, [code]);
|
|
2506
|
+
React.useEffect(() => {
|
|
2507
|
+
if (!isOpen) {
|
|
2508
|
+
setTimeout(() => {
|
|
2509
|
+
setIsCameraAvailable(false);
|
|
2510
|
+
}, 0);
|
|
2511
|
+
if (scannerRef.current) {
|
|
2512
|
+
const scanner = scannerRef.current;
|
|
2513
|
+
scanner.stop().catch(() => {
|
|
2514
|
+
}).finally(() => {
|
|
2515
|
+
try {
|
|
2516
|
+
scanner.clear();
|
|
2517
|
+
} catch {
|
|
2518
|
+
}
|
|
2519
|
+
});
|
|
2520
|
+
scannerRef.current = null;
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
}, [isOpen]);
|
|
2524
|
+
React.useEffect(() => {
|
|
2525
|
+
if (!isOpen) {
|
|
2526
|
+
return;
|
|
2527
|
+
}
|
|
2528
|
+
const containerId = "qr-reader";
|
|
2529
|
+
let scanner = null;
|
|
2530
|
+
let scannerRunning = false;
|
|
2531
|
+
let mounted = true;
|
|
2532
|
+
const startScanning = async () => {
|
|
2533
|
+
try {
|
|
2534
|
+
const container = document.getElementById(containerId);
|
|
2535
|
+
if (!container) {
|
|
2536
|
+
return;
|
|
2537
|
+
}
|
|
2538
|
+
const rect = container.getBoundingClientRect();
|
|
2539
|
+
if (rect.width === 0 || rect.height === 0) {
|
|
2540
|
+
return;
|
|
2541
|
+
}
|
|
2542
|
+
scanner = new html5Qrcode.Html5Qrcode(containerId);
|
|
2543
|
+
scannerRef.current = scanner;
|
|
2544
|
+
let cameraId = null;
|
|
2545
|
+
try {
|
|
2546
|
+
const devices = await html5Qrcode.Html5Qrcode.getCameras();
|
|
2547
|
+
if (devices && devices.length > 0) {
|
|
2548
|
+
const backCamera = devices.find(
|
|
2549
|
+
(d) => d.label.toLowerCase().includes("back") || d.label.toLowerCase().includes("rear")
|
|
2550
|
+
);
|
|
2551
|
+
const envCamera = devices.find((d) => {
|
|
2552
|
+
const label = d.label.toLowerCase();
|
|
2553
|
+
return label.includes("environment") || label.includes("facing back");
|
|
2554
|
+
});
|
|
2555
|
+
cameraId = (envCamera || backCamera || devices[0])?.id || null;
|
|
2556
|
+
}
|
|
2557
|
+
} catch {
|
|
2558
|
+
}
|
|
2559
|
+
const config = cameraId ? { deviceId: { exact: cameraId } } : { facingMode: "environment" };
|
|
2560
|
+
await scanner.start(
|
|
2561
|
+
config,
|
|
2562
|
+
{
|
|
2563
|
+
fps: 10,
|
|
2564
|
+
qrbox: (viewfinderWidth, viewfinderHeight) => {
|
|
2565
|
+
const minEdge = Math.min(viewfinderWidth, viewfinderHeight);
|
|
2566
|
+
const qrboxSize = Math.min(250, minEdge * 0.8);
|
|
2567
|
+
return {
|
|
2568
|
+
width: qrboxSize,
|
|
2569
|
+
height: qrboxSize
|
|
2570
|
+
};
|
|
2571
|
+
},
|
|
2572
|
+
aspectRatio: 1
|
|
2573
|
+
},
|
|
2574
|
+
(decodedText) => {
|
|
2575
|
+
if (!mounted) return;
|
|
2576
|
+
const roomCode = extractRoomCode(decodedText);
|
|
2577
|
+
if (roomCode) {
|
|
2578
|
+
setCode(roomCode);
|
|
2579
|
+
scannerRunning = false;
|
|
2580
|
+
scanner?.stop().catch(() => {
|
|
2581
|
+
}).finally(() => {
|
|
2582
|
+
if (mounted) {
|
|
2583
|
+
setIsCameraAvailable(false);
|
|
2584
|
+
}
|
|
2585
|
+
});
|
|
2586
|
+
}
|
|
2587
|
+
},
|
|
2588
|
+
() => {
|
|
2589
|
+
}
|
|
2590
|
+
);
|
|
2591
|
+
scannerRunning = true;
|
|
2592
|
+
if (mounted) {
|
|
2593
|
+
setIsCameraAvailable(true);
|
|
2594
|
+
}
|
|
2595
|
+
} catch {
|
|
2596
|
+
if (mounted) {
|
|
2597
|
+
setIsCameraAvailable(false);
|
|
2598
|
+
}
|
|
2599
|
+
if (scanner) {
|
|
2600
|
+
try {
|
|
2601
|
+
scanner.clear();
|
|
2602
|
+
} catch {
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
scannerRef.current = null;
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
const timeoutId = setTimeout(() => {
|
|
2609
|
+
startScanning();
|
|
2610
|
+
}, 200);
|
|
2611
|
+
return () => {
|
|
2612
|
+
mounted = false;
|
|
2613
|
+
clearTimeout(timeoutId);
|
|
2614
|
+
if (scanner && scannerRunning) {
|
|
2615
|
+
scanner.stop().catch(() => {
|
|
2616
|
+
}).finally(() => {
|
|
2617
|
+
try {
|
|
2618
|
+
scanner?.clear();
|
|
2619
|
+
} catch {
|
|
2620
|
+
}
|
|
2621
|
+
});
|
|
2622
|
+
} else if (scanner) {
|
|
2623
|
+
try {
|
|
2624
|
+
scanner.clear();
|
|
2625
|
+
} catch {
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
scannerRef.current = null;
|
|
2629
|
+
};
|
|
2630
|
+
}, [isOpen]);
|
|
2631
|
+
const handleSubmit = () => {
|
|
2632
|
+
const trimmed = code.trim().toUpperCase();
|
|
2633
|
+
const parsed = roomCodeSchema.safeParse(trimmed);
|
|
2634
|
+
if (parsed.success) {
|
|
2635
|
+
onScan(parsed.data);
|
|
2636
|
+
onClose();
|
|
2637
|
+
}
|
|
2638
|
+
};
|
|
2639
|
+
const handleInputFocus = (e) => {
|
|
2640
|
+
e.target.select();
|
|
2641
|
+
};
|
|
2642
|
+
const handleInputChange = (e) => {
|
|
2643
|
+
setCode(e.target.value.toUpperCase());
|
|
2644
|
+
setCopied(false);
|
|
2645
|
+
};
|
|
2646
|
+
const handleCopyUrl = async () => {
|
|
2647
|
+
if (!joinUrl) return;
|
|
2648
|
+
try {
|
|
2649
|
+
await navigator.clipboard.writeText(joinUrl);
|
|
2650
|
+
setCopied(true);
|
|
2651
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
2652
|
+
} catch {
|
|
2653
|
+
const textArea = document.createElement("textarea");
|
|
2654
|
+
textArea.value = joinUrl;
|
|
2655
|
+
textArea.style.position = "fixed";
|
|
2656
|
+
textArea.style.opacity = "0";
|
|
2657
|
+
document.body.appendChild(textArea);
|
|
2658
|
+
textArea.select();
|
|
2659
|
+
try {
|
|
2660
|
+
document.execCommand("copy");
|
|
2661
|
+
setCopied(true);
|
|
2662
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
2663
|
+
} catch {
|
|
2664
|
+
}
|
|
2665
|
+
document.body.removeChild(textArea);
|
|
2666
|
+
}
|
|
2667
|
+
};
|
|
2668
|
+
if (!isOpen) {
|
|
2669
|
+
return null;
|
|
2670
|
+
}
|
|
2671
|
+
const isValid = code.trim().length > 0;
|
|
2672
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-background fixed inset-0 z-50 flex flex-col items-center justify-center", children: [
|
|
2673
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col items-center justify-center", children: [
|
|
2674
|
+
isCameraAvailable && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative flex aspect-square w-full items-center justify-center overflow-hidden p-6", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2675
|
+
"div",
|
|
2676
|
+
{
|
|
2677
|
+
id: "qr-reader",
|
|
2678
|
+
className: "h-full w-full overflow-hidden rounded-lg bg-black"
|
|
2679
|
+
}
|
|
2680
|
+
) }),
|
|
2681
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full max-w-md px-6", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2682
|
+
"input",
|
|
2683
|
+
{
|
|
2684
|
+
ref: inputRef,
|
|
2685
|
+
type: "text",
|
|
2686
|
+
value: code,
|
|
2687
|
+
onChange: handleInputChange,
|
|
2688
|
+
onFocus: handleInputFocus,
|
|
2689
|
+
onKeyDown: (e) => {
|
|
2690
|
+
if (e.key === "Enter" && isValid) {
|
|
2691
|
+
handleSubmit();
|
|
2692
|
+
}
|
|
2693
|
+
},
|
|
2694
|
+
placeholder: "Enter room code",
|
|
2695
|
+
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",
|
|
2696
|
+
autoComplete: "off",
|
|
2697
|
+
autoCapitalize: "characters"
|
|
2698
|
+
}
|
|
2699
|
+
) }),
|
|
2700
|
+
joinUrl && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 w-full max-w-md px-6 pb-2", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2701
|
+
"button",
|
|
2702
|
+
{
|
|
2703
|
+
type: "button",
|
|
2704
|
+
onClick: handleCopyUrl,
|
|
2705
|
+
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",
|
|
2706
|
+
children: copied ? "\u2713 Copied!" : joinUrl
|
|
2707
|
+
}
|
|
2708
|
+
) })
|
|
2709
|
+
] }),
|
|
2710
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-md gap-4 px-6 pb-6", children: [
|
|
2711
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2712
|
+
Button,
|
|
2713
|
+
{
|
|
2714
|
+
type: "button",
|
|
2715
|
+
variant: "outline",
|
|
2716
|
+
onClick: onClose,
|
|
2717
|
+
className: "flex-1 py-6",
|
|
2718
|
+
children: "Cancel"
|
|
2719
|
+
}
|
|
2720
|
+
),
|
|
2721
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2722
|
+
Button,
|
|
2723
|
+
{
|
|
2724
|
+
type: "button",
|
|
2725
|
+
onClick: handleSubmit,
|
|
2726
|
+
disabled: !isValid,
|
|
2727
|
+
className: "flex-1 py-6",
|
|
2728
|
+
children: "Connect"
|
|
2729
|
+
}
|
|
2730
|
+
)
|
|
2731
|
+
] })
|
|
2732
|
+
] });
|
|
2733
|
+
};
|
|
2734
|
+
var describeStatus = (status) => {
|
|
2735
|
+
switch (status) {
|
|
2736
|
+
case "connected":
|
|
2737
|
+
return "Connected to host";
|
|
2738
|
+
case "connecting":
|
|
2739
|
+
return "Connecting\u2026";
|
|
2740
|
+
case "reconnecting":
|
|
2741
|
+
return "Trying to reconnect\u2026";
|
|
2742
|
+
case "disconnected":
|
|
2743
|
+
return "Disconnected";
|
|
2744
|
+
case "idle":
|
|
2745
|
+
default:
|
|
2746
|
+
return "Idle";
|
|
2747
|
+
}
|
|
2748
|
+
};
|
|
2749
|
+
var orientationMatches = (required) => {
|
|
2750
|
+
if (required === "any") return true;
|
|
2751
|
+
if (typeof window === "undefined" || !window.matchMedia) return true;
|
|
2752
|
+
const matcher = window.matchMedia(`(orientation: ${required})`);
|
|
2753
|
+
return matcher.matches;
|
|
2754
|
+
};
|
|
2755
|
+
var ControllerShell = ({
|
|
2756
|
+
roomId,
|
|
2757
|
+
connectionStatus,
|
|
2758
|
+
requiredOrientation = "landscape",
|
|
2759
|
+
children,
|
|
2760
|
+
gameState = "paused",
|
|
2761
|
+
onTogglePlayPause,
|
|
2762
|
+
onReconnect,
|
|
2763
|
+
onRefresh,
|
|
2764
|
+
customActions
|
|
2765
|
+
}) => {
|
|
2766
|
+
const isChildMode = React.useMemo(() => detectRunMode() === "platform", []);
|
|
2767
|
+
const [isOrientationOk, setOrientationOk] = React.useState(
|
|
2768
|
+
() => orientationMatches(requiredOrientation)
|
|
2769
|
+
);
|
|
2770
|
+
const [isScannerOpen, setIsScannerOpen] = React.useState(false);
|
|
2771
|
+
const { isFullscreen, toggleFullscreen } = useFullscreen();
|
|
2772
|
+
const { store } = useAirJamContext();
|
|
2773
|
+
const { controllerId, players } = zustand.useStore(
|
|
2774
|
+
store,
|
|
2775
|
+
shallow.useShallow(
|
|
2776
|
+
(state) => ({
|
|
2777
|
+
controllerId: state.controllerId,
|
|
2778
|
+
players: state.players
|
|
2779
|
+
})
|
|
2780
|
+
)
|
|
2781
|
+
);
|
|
2782
|
+
const currentPlayer = React.useMemo(() => {
|
|
2783
|
+
if (!controllerId) return null;
|
|
2784
|
+
const found = players.find((p) => p.id === controllerId);
|
|
2785
|
+
if (!found && connectionStatus === "connected" && players.length > 0) ;
|
|
2786
|
+
return found || null;
|
|
2787
|
+
}, [controllerId, players, connectionStatus]);
|
|
2788
|
+
React.useEffect(() => {
|
|
2789
|
+
if (requiredOrientation === "any") {
|
|
2790
|
+
return;
|
|
2791
|
+
}
|
|
2792
|
+
const media = window.matchMedia(`(orientation: ${requiredOrientation})`);
|
|
2793
|
+
const handleChange = () => setOrientationOk(media.matches);
|
|
2794
|
+
handleChange();
|
|
2795
|
+
media.addEventListener("change", handleChange);
|
|
2796
|
+
return () => media.removeEventListener("change", handleChange);
|
|
2797
|
+
}, [requiredOrientation]);
|
|
2798
|
+
const orientationOk = requiredOrientation === "any" ? true : isOrientationOk;
|
|
2799
|
+
const statusDotColor = React.useMemo(() => {
|
|
2800
|
+
switch (connectionStatus) {
|
|
2801
|
+
case "connected":
|
|
2802
|
+
return "bg-green-500";
|
|
2803
|
+
case "connecting":
|
|
2804
|
+
case "reconnecting":
|
|
2805
|
+
return "bg-yellow-500";
|
|
2806
|
+
case "disconnected":
|
|
2807
|
+
default:
|
|
2808
|
+
return "bg-red-500";
|
|
2809
|
+
}
|
|
2810
|
+
}, [connectionStatus]);
|
|
2811
|
+
if (isChildMode) {
|
|
2812
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dark", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden bg-transparent select-none", children: /* @__PURE__ */ jsxRuntime.jsxs("main", { className: "relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4", children: [
|
|
2813
|
+
!orientationOk && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-background/95 absolute inset-0 z-50 flex flex-col items-center justify-center p-6 text-center shadow-lg backdrop-blur-sm", children: [
|
|
2814
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-card-foreground text-xl font-semibold", children: "Rotate your device" }),
|
|
2815
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-muted-foreground mt-2 text-sm", children: [
|
|
2816
|
+
"This game is best experienced in ",
|
|
2817
|
+
requiredOrientation,
|
|
2818
|
+
" ",
|
|
2819
|
+
"orientation."
|
|
2820
|
+
] })
|
|
2821
|
+
] }),
|
|
2822
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2823
|
+
"div",
|
|
2824
|
+
{
|
|
2825
|
+
className: cn(
|
|
2826
|
+
"h-full w-full select-none",
|
|
2827
|
+
!orientationOk && "pointer-events-none opacity-30"
|
|
2828
|
+
),
|
|
2829
|
+
children
|
|
2830
|
+
}
|
|
2831
|
+
)
|
|
2832
|
+
] }) }) });
|
|
2833
|
+
}
|
|
2834
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dark", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-background text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden select-none", children: [
|
|
2835
|
+
/* @__PURE__ */ jsxRuntime.jsxs("header", { className: "pointer-events-none sticky top-0 z-50 flex items-center justify-between border-b px-6 py-2", children: [
|
|
2836
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
2837
|
+
typeof window !== "undefined" && (currentPlayer || controllerId) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", title: describeStatus(connectionStatus), children: [
|
|
2838
|
+
currentPlayer ? /* @__PURE__ */ jsxRuntime.jsx(PlayerAvatar, { player: currentPlayer, size: "sm" }) : controllerId ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2839
|
+
PlayerAvatar,
|
|
2840
|
+
{
|
|
2841
|
+
player: {
|
|
2842
|
+
id: controllerId,
|
|
2843
|
+
label: "Player"
|
|
2844
|
+
},
|
|
2845
|
+
size: "sm"
|
|
2846
|
+
}
|
|
2847
|
+
) : null,
|
|
2848
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2849
|
+
"span",
|
|
2850
|
+
{
|
|
2851
|
+
className: "absolute right-0 bottom-0 h-3 w-3 rounded-full bg-black",
|
|
2852
|
+
"aria-hidden": "true"
|
|
2853
|
+
}
|
|
2854
|
+
),
|
|
2855
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2856
|
+
"span",
|
|
2857
|
+
{
|
|
2858
|
+
className: cn(
|
|
2859
|
+
"absolute right-0.5 bottom-0.5 h-2 w-2 rounded-full",
|
|
2860
|
+
statusDotColor,
|
|
2861
|
+
connectionStatus === "connected" && "animate-pulse"
|
|
2862
|
+
),
|
|
2863
|
+
"aria-label": describeStatus(connectionStatus)
|
|
2864
|
+
}
|
|
2865
|
+
)
|
|
2866
|
+
] }),
|
|
2867
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2868
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs tracking-[0.24em] uppercase", children: "Room" }),
|
|
2869
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-foreground text-lg font-semibold", children: typeof window !== "undefined" ? roomId ?? "N/A" : "N/A" })
|
|
2870
|
+
] })
|
|
2871
|
+
] }),
|
|
2872
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pointer-events-auto flex items-center gap-3", children: [
|
|
2873
|
+
customActions,
|
|
2874
|
+
onRefresh && roomId && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2875
|
+
Button,
|
|
2876
|
+
{
|
|
2877
|
+
type: "button",
|
|
2878
|
+
variant: "outline",
|
|
2879
|
+
size: "icon",
|
|
2880
|
+
onClick: onRefresh,
|
|
2881
|
+
disabled: connectionStatus === "connecting" || connectionStatus === "reconnecting",
|
|
2882
|
+
"aria-label": "Reconnect",
|
|
2883
|
+
title: "Reconnect to room",
|
|
2884
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2885
|
+
lucideReact.RefreshCw,
|
|
2886
|
+
{
|
|
2887
|
+
className: cn(
|
|
2888
|
+
"h-5 w-5",
|
|
2889
|
+
(connectionStatus === "connecting" || connectionStatus === "reconnecting") && "animate-spin"
|
|
2890
|
+
)
|
|
2891
|
+
}
|
|
2892
|
+
)
|
|
2893
|
+
}
|
|
2894
|
+
),
|
|
2895
|
+
onReconnect && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2896
|
+
Button,
|
|
2897
|
+
{
|
|
2898
|
+
type: "button",
|
|
2899
|
+
variant: "outline",
|
|
2900
|
+
size: "icon",
|
|
2901
|
+
onClick: () => setIsScannerOpen(true),
|
|
2902
|
+
"aria-label": "Scan QR code to reconnect",
|
|
2903
|
+
title: "Scan QR code to reconnect",
|
|
2904
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.QrCode, { className: "h-5 w-5" })
|
|
2905
|
+
}
|
|
2906
|
+
),
|
|
2907
|
+
onTogglePlayPause && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2908
|
+
Button,
|
|
2909
|
+
{
|
|
2910
|
+
type: "button",
|
|
2911
|
+
variant: "outline",
|
|
2912
|
+
size: "icon",
|
|
2913
|
+
onClick: onTogglePlayPause,
|
|
2914
|
+
"aria-label": gameState === "playing" ? "Pause" : "Play",
|
|
2915
|
+
title: gameState === "playing" ? "Pause" : "Play",
|
|
2916
|
+
children: gameState === "playing" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, { className: "h-5 w-5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "h-5 w-5" })
|
|
2917
|
+
}
|
|
2918
|
+
),
|
|
2919
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2920
|
+
Button,
|
|
2921
|
+
{
|
|
2922
|
+
type: "button",
|
|
2923
|
+
variant: "outline",
|
|
2924
|
+
size: "icon",
|
|
2925
|
+
onClick: () => toggleFullscreen(),
|
|
2926
|
+
"aria-label": isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
|
|
2927
|
+
title: isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
|
|
2928
|
+
children: isFullscreen ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Minimize, { className: "h-5 w-5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Maximize, { className: "h-5 w-5" })
|
|
2929
|
+
}
|
|
2930
|
+
)
|
|
2931
|
+
] })
|
|
2932
|
+
] }),
|
|
2933
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none fixed right-4 bottom-4 z-50", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-auto", children: /* @__PURE__ */ jsxRuntime.jsx(VolumeControls, { compact: true }) }) }),
|
|
2934
|
+
/* @__PURE__ */ jsxRuntime.jsx("main", { className: "relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-card/95 absolute inset-0 z-10 flex flex-col items-center justify-center p-6 text-center shadow-lg backdrop-blur-sm", children: [
|
|
2935
|
+
!orientationOk && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-background/95 absolute inset-0 z-10 flex flex-col items-center justify-center p-6 text-center shadow-lg backdrop-blur-sm", children: [
|
|
2936
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-card-foreground text-xl font-semibold", children: "Rotate your device" }),
|
|
2937
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-muted-foreground mt-2 text-sm", children: [
|
|
2938
|
+
"This game is best experienced in ",
|
|
2939
|
+
requiredOrientation,
|
|
2940
|
+
" ",
|
|
2941
|
+
"orientation."
|
|
2942
|
+
] })
|
|
2943
|
+
] }),
|
|
2944
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2945
|
+
"div",
|
|
2946
|
+
{
|
|
2947
|
+
className: cn(
|
|
2948
|
+
"h-full w-full select-none",
|
|
2949
|
+
!orientationOk && "pointer-events-none opacity-30"
|
|
2950
|
+
),
|
|
2951
|
+
children
|
|
2952
|
+
}
|
|
2953
|
+
)
|
|
2954
|
+
] }) }),
|
|
2955
|
+
onReconnect && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2956
|
+
QRScannerDialog,
|
|
2957
|
+
{
|
|
2958
|
+
isOpen: isScannerOpen,
|
|
2959
|
+
onClose: () => setIsScannerOpen(false),
|
|
2960
|
+
onScan: (roomCode) => {
|
|
2961
|
+
onReconnect(roomCode);
|
|
2962
|
+
setIsScannerOpen(false);
|
|
2963
|
+
},
|
|
2964
|
+
currentRoomId: roomId
|
|
2965
|
+
}
|
|
2966
|
+
)
|
|
2967
|
+
] }) });
|
|
2968
|
+
};
|
|
2969
|
+
|
|
2970
|
+
// src/events.ts
|
|
2971
|
+
var HostEvents = {
|
|
2972
|
+
/**
|
|
2973
|
+
* Register as a master host (standalone mode)
|
|
2974
|
+
*/
|
|
2975
|
+
REGISTER: "host:register",
|
|
2976
|
+
/**
|
|
2977
|
+
* Register as the system/arcade master host
|
|
2978
|
+
*/
|
|
2979
|
+
REGISTER_SYSTEM: "host:registerSystem",
|
|
2980
|
+
/**
|
|
2981
|
+
* Join as a child host (game launched from arcade)
|
|
2982
|
+
*/
|
|
2983
|
+
JOIN_AS_CHILD: "host:joinAsChild"
|
|
2984
|
+
};
|
|
2985
|
+
var ControllerEvents = {
|
|
2986
|
+
/**
|
|
2987
|
+
* Controller joins a room
|
|
2988
|
+
*/
|
|
2989
|
+
JOIN: "controller:join",
|
|
2990
|
+
/**
|
|
2991
|
+
* Controller sends input
|
|
2992
|
+
*/
|
|
2993
|
+
INPUT: "controller:input",
|
|
2994
|
+
/**
|
|
2995
|
+
* Controller leaves a room
|
|
2996
|
+
*/
|
|
2997
|
+
LEAVE: "controller:leave",
|
|
2998
|
+
/**
|
|
2999
|
+
* Controller sends game state update
|
|
3000
|
+
*/
|
|
3001
|
+
STATE: "controller:state",
|
|
3002
|
+
/**
|
|
3003
|
+
* Controller sends system command
|
|
3004
|
+
*/
|
|
3005
|
+
SYSTEM: "controller:system"
|
|
3006
|
+
};
|
|
3007
|
+
var SystemEvents = {
|
|
3008
|
+
/**
|
|
3009
|
+
* Arcade launches a game
|
|
3010
|
+
*/
|
|
3011
|
+
LAUNCH_GAME: "system:launchGame",
|
|
3012
|
+
/**
|
|
3013
|
+
* Arcade closes a game
|
|
3014
|
+
*/
|
|
3015
|
+
CLOSE_GAME: "system:closeGame"
|
|
3016
|
+
};
|
|
3017
|
+
var ServerEvents = {
|
|
3018
|
+
/**
|
|
3019
|
+
* Welcome message with room/controller info
|
|
3020
|
+
*/
|
|
3021
|
+
WELCOME: "server:welcome",
|
|
3022
|
+
/**
|
|
3023
|
+
* Room is ready
|
|
3024
|
+
*/
|
|
3025
|
+
ROOM_READY: "server:roomReady",
|
|
3026
|
+
/**
|
|
3027
|
+
* Controller joined notification
|
|
3028
|
+
*/
|
|
3029
|
+
CONTROLLER_JOINED: "server:controllerJoined",
|
|
3030
|
+
/**
|
|
3031
|
+
* Controller left notification
|
|
3032
|
+
*/
|
|
3033
|
+
CONTROLLER_LEFT: "server:controllerLeft",
|
|
3034
|
+
/**
|
|
3035
|
+
* Host left notification
|
|
3036
|
+
*/
|
|
3037
|
+
HOST_LEFT: "server:hostLeft",
|
|
3038
|
+
/**
|
|
3039
|
+
* Server error
|
|
3040
|
+
*/
|
|
3041
|
+
ERROR: "server:error",
|
|
3042
|
+
/**
|
|
3043
|
+
* Play sound on client
|
|
3044
|
+
*/
|
|
3045
|
+
PLAY_SOUND: "server:playSound"
|
|
3046
|
+
};
|
|
3047
|
+
var ClientEvents = {
|
|
3048
|
+
/**
|
|
3049
|
+
* Load a game UI in the controller iframe
|
|
3050
|
+
*/
|
|
3051
|
+
LOAD_UI: "client:loadUi",
|
|
3052
|
+
/**
|
|
3053
|
+
* Unload the game UI from the controller iframe
|
|
3054
|
+
*/
|
|
3055
|
+
UNLOAD_UI: "client:unloadUi",
|
|
3056
|
+
/**
|
|
3057
|
+
* Update game state display
|
|
3058
|
+
*/
|
|
3059
|
+
STATE: "client:state"
|
|
3060
|
+
};
|
|
3061
|
+
var ChildEvents = {
|
|
3062
|
+
/**
|
|
3063
|
+
* Server requests child to close
|
|
3064
|
+
*/
|
|
3065
|
+
CLOSE: "child:close"
|
|
3066
|
+
};
|
|
3067
|
+
var Events = {
|
|
3068
|
+
Host: HostEvents,
|
|
3069
|
+
Controller: ControllerEvents,
|
|
3070
|
+
System: SystemEvents,
|
|
3071
|
+
Server: ServerEvents,
|
|
3072
|
+
Client: ClientEvents,
|
|
3073
|
+
Child: ChildEvents
|
|
3074
|
+
};
|
|
3075
|
+
var getRoomFromLocation = () => {
|
|
3076
|
+
if (typeof window === "undefined") {
|
|
3077
|
+
return null;
|
|
3078
|
+
}
|
|
3079
|
+
const params = new URLSearchParams(window.location.search);
|
|
3080
|
+
const code = params.get("room");
|
|
3081
|
+
return code ? code.toUpperCase() : null;
|
|
3082
|
+
};
|
|
3083
|
+
var useAirJamController = (options = {}) => {
|
|
3084
|
+
const { store, getSocket, disconnectSocket } = useAirJamContext();
|
|
3085
|
+
const nicknameRef = React.useRef(options.nickname ?? "");
|
|
3086
|
+
const subControllerParams = React.useMemo(() => {
|
|
2901
3087
|
if (typeof window === "undefined") return null;
|
|
2902
3088
|
const params = new URLSearchParams(window.location.search);
|
|
2903
3089
|
const room = params.get("aj_room");
|
|
2904
|
-
const
|
|
2905
|
-
if (room &&
|
|
2906
|
-
return { room,
|
|
3090
|
+
const controllerId2 = params.get("aj_controller_id");
|
|
3091
|
+
if (room && controllerId2) {
|
|
3092
|
+
return { room, controllerId: controllerId2 };
|
|
2907
3093
|
}
|
|
2908
3094
|
return null;
|
|
2909
3095
|
}, []);
|
|
2910
|
-
const isChildMode = !!arcadeParams;
|
|
2911
|
-
const shouldConnect = true;
|
|
2912
|
-
const [fallbackRoomId] = React.useState(() => generateRoomCode());
|
|
2913
3096
|
const parsedRoomId = React.useMemo(() => {
|
|
2914
|
-
|
|
2915
|
-
|
|
3097
|
+
const code = subControllerParams?.room ?? options.roomId ?? getRoomFromLocation();
|
|
3098
|
+
if (!code) return null;
|
|
3099
|
+
try {
|
|
3100
|
+
return roomCodeSchema.parse(code.toUpperCase());
|
|
3101
|
+
} catch {
|
|
3102
|
+
return null;
|
|
2916
3103
|
}
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
const result = roomCodeSchema.safeParse(paramRoom.toUpperCase());
|
|
2922
|
-
if (result.success) return result.data;
|
|
2923
|
-
}
|
|
3104
|
+
}, [options.roomId, subControllerParams]);
|
|
3105
|
+
const controllerId = React.useMemo(() => {
|
|
3106
|
+
if (subControllerParams?.controllerId) {
|
|
3107
|
+
return subControllerParams.controllerId;
|
|
2924
3108
|
}
|
|
2925
|
-
if (options.
|
|
2926
|
-
return
|
|
3109
|
+
if (options.controllerId) {
|
|
3110
|
+
return options.controllerId;
|
|
2927
3111
|
}
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
inputManager.setRoomId(parsedRoomId);
|
|
3112
|
+
if (typeof window !== "undefined") {
|
|
3113
|
+
const params = new URLSearchParams(window.location.search);
|
|
3114
|
+
const urlControllerId = params.get("controllerId");
|
|
3115
|
+
if (urlControllerId) return urlControllerId;
|
|
2933
3116
|
}
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
const
|
|
2937
|
-
|
|
2938
|
-
|
|
3117
|
+
return generateControllerId();
|
|
3118
|
+
}, [options.controllerId, subControllerParams]);
|
|
3119
|
+
const onStateRef = React.useRef(
|
|
3120
|
+
options.onState
|
|
3121
|
+
);
|
|
2939
3122
|
React.useEffect(() => {
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
onChildCloseRef.current = options.onChildClose;
|
|
2943
|
-
}, [options.onPlayerJoin, options.onPlayerLeave, options.onChildClose]);
|
|
3123
|
+
onStateRef.current = options.onState;
|
|
3124
|
+
}, [options.onState]);
|
|
2944
3125
|
const connectionState = zustand.useStore(
|
|
2945
3126
|
store,
|
|
2946
3127
|
shallow.useShallow((state) => ({
|
|
2947
3128
|
connectionStatus: state.connectionStatus,
|
|
2948
3129
|
lastError: state.lastError,
|
|
3130
|
+
controllerId: state.controllerId,
|
|
2949
3131
|
players: state.players,
|
|
2950
3132
|
gameState: state.gameState,
|
|
2951
|
-
|
|
3133
|
+
stateMessage: state.stateMessage
|
|
2952
3134
|
}))
|
|
2953
3135
|
);
|
|
2954
|
-
const
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
if (
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
});
|
|
2972
|
-
if (payload.success) {
|
|
2973
|
-
socket.emit("host:system", payload.data);
|
|
3136
|
+
const [reconnectKey, setReconnectKey] = React.useState(0);
|
|
3137
|
+
const reconnect = React.useCallback(() => {
|
|
3138
|
+
if (!parsedRoomId) return;
|
|
3139
|
+
disconnectSocket("controller");
|
|
3140
|
+
setReconnectKey((prev) => prev + 1);
|
|
3141
|
+
}, [parsedRoomId, disconnectSocket]);
|
|
3142
|
+
const isChildMode = React.useMemo(() => {
|
|
3143
|
+
if (typeof window === "undefined") return false;
|
|
3144
|
+
const params = new URLSearchParams(window.location.search);
|
|
3145
|
+
return params.get("airjam_mode") === "child";
|
|
3146
|
+
}, []);
|
|
3147
|
+
const shouldConnect = React.useMemo(() => {
|
|
3148
|
+
if (options.forceConnect) return true;
|
|
3149
|
+
if (subControllerParams) return true;
|
|
3150
|
+
if (typeof window !== "undefined") {
|
|
3151
|
+
const params = new URLSearchParams(window.location.search);
|
|
3152
|
+
return params.get("airjam_force_connect") === "true";
|
|
2974
3153
|
}
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
}
|
|
2981
|
-
const payload = controllerStateSchema.safeParse({
|
|
2982
|
-
roomId: parsedRoomId,
|
|
2983
|
-
state
|
|
2984
|
-
});
|
|
2985
|
-
if (!payload.success) {
|
|
2986
|
-
return false;
|
|
2987
|
-
}
|
|
2988
|
-
socket.emit("host:state", payload.data);
|
|
2989
|
-
return true;
|
|
2990
|
-
},
|
|
2991
|
-
[socket, parsedRoomId]
|
|
3154
|
+
return false;
|
|
3155
|
+
}, [options.forceConnect, subControllerParams]);
|
|
3156
|
+
const canConnect = React.useMemo(
|
|
3157
|
+
() => !isChildMode || shouldConnect,
|
|
3158
|
+
[isChildMode, shouldConnect]
|
|
2992
3159
|
);
|
|
2993
|
-
const
|
|
2994
|
-
(
|
|
2995
|
-
|
|
2996
|
-
return;
|
|
2997
|
-
}
|
|
2998
|
-
const signal = {
|
|
2999
|
-
targetId,
|
|
3000
|
-
type,
|
|
3001
|
-
payload
|
|
3002
|
-
};
|
|
3003
|
-
socket.emit("host:signal", signal);
|
|
3004
|
-
},
|
|
3005
|
-
[socket]
|
|
3160
|
+
const socket = React.useMemo(
|
|
3161
|
+
() => canConnect && parsedRoomId ? getSocket("controller") : null,
|
|
3162
|
+
[canConnect, parsedRoomId, getSocket]
|
|
3006
3163
|
);
|
|
3007
|
-
const reconnect = React.useCallback(() => {
|
|
3008
|
-
disconnectSocket("host");
|
|
3009
|
-
if (socket) {
|
|
3010
|
-
socket.connect();
|
|
3011
|
-
}
|
|
3012
|
-
}, [socket, disconnectSocket]);
|
|
3013
|
-
React.useEffect(() => {
|
|
3014
|
-
(async () => {
|
|
3015
|
-
const url = await urlBuilder.buildControllerUrl(parsedRoomId, {
|
|
3016
|
-
path: config.controllerPath,
|
|
3017
|
-
host: config.publicHost
|
|
3018
|
-
});
|
|
3019
|
-
setJoinUrl(url);
|
|
3020
|
-
})();
|
|
3021
|
-
}, [parsedRoomId, config.controllerPath, config.publicHost]);
|
|
3022
|
-
const setRegisteredRoomId = zustand.useStore(store, (s) => s.setRegisteredRoomId);
|
|
3023
3164
|
React.useEffect(() => {
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
storeState2.setError(ack.message ?? "Failed to join as child");
|
|
3051
|
-
storeState2.setStatus("disconnected");
|
|
3052
|
-
setRegisteredRoomId(null);
|
|
3053
|
-
return;
|
|
3054
|
-
}
|
|
3055
|
-
storeState2.setStatus("connected");
|
|
3056
|
-
storeState2.setRoomId(childRoomId);
|
|
3057
|
-
setRegisteredRoomId(childRoomId);
|
|
3058
|
-
});
|
|
3059
|
-
} else {
|
|
3060
|
-
const payload = hostRegistrationSchema.parse({
|
|
3061
|
-
roomId: parsedRoomId,
|
|
3062
|
-
maxPlayers: options.maxPlayers ?? config.maxPlayers,
|
|
3063
|
-
apiKey: options.apiKey ?? config.apiKey
|
|
3064
|
-
});
|
|
3065
|
-
socket.emit("host:register", payload, (ack) => {
|
|
3066
|
-
if (!ack.ok) {
|
|
3067
|
-
storeState2.setError(ack.message ?? "Failed to register host");
|
|
3068
|
-
storeState2.setStatus("disconnected");
|
|
3069
|
-
setRegisteredRoomId(null);
|
|
3070
|
-
return;
|
|
3071
|
-
}
|
|
3072
|
-
storeState2.setStatus("connected");
|
|
3073
|
-
if (ack.roomId) {
|
|
3074
|
-
storeState2.setRoomId(ack.roomId);
|
|
3075
|
-
setRegisteredRoomId(ack.roomId);
|
|
3076
|
-
} else {
|
|
3077
|
-
setRegisteredRoomId(parsedRoomId);
|
|
3165
|
+
if (!socket) return;
|
|
3166
|
+
const handleSignal = (signal) => {
|
|
3167
|
+
if (signal.type !== "HAPTIC") return;
|
|
3168
|
+
if (typeof navigator === "undefined" || !navigator.vibrate) return;
|
|
3169
|
+
const payload = signal.payload;
|
|
3170
|
+
switch (payload.pattern) {
|
|
3171
|
+
case "light":
|
|
3172
|
+
navigator.vibrate(10);
|
|
3173
|
+
break;
|
|
3174
|
+
case "medium":
|
|
3175
|
+
navigator.vibrate(30);
|
|
3176
|
+
break;
|
|
3177
|
+
case "heavy":
|
|
3178
|
+
navigator.vibrate([50, 20, 50]);
|
|
3179
|
+
break;
|
|
3180
|
+
case "success":
|
|
3181
|
+
navigator.vibrate([10, 30, 10]);
|
|
3182
|
+
break;
|
|
3183
|
+
case "failure":
|
|
3184
|
+
navigator.vibrate([50, 50, 50, 50]);
|
|
3185
|
+
break;
|
|
3186
|
+
case "custom":
|
|
3187
|
+
if (Array.isArray(payload.sequence)) {
|
|
3188
|
+
navigator.vibrate(payload.sequence);
|
|
3189
|
+
} else if (typeof payload.sequence === "number") {
|
|
3190
|
+
navigator.vibrate(payload.sequence);
|
|
3078
3191
|
}
|
|
3079
|
-
|
|
3192
|
+
break;
|
|
3080
3193
|
}
|
|
3081
3194
|
};
|
|
3195
|
+
socket.on("server:signal", handleSignal);
|
|
3196
|
+
return () => {
|
|
3197
|
+
socket.off("server:signal", handleSignal);
|
|
3198
|
+
};
|
|
3199
|
+
}, [socket]);
|
|
3200
|
+
React.useEffect(() => {
|
|
3201
|
+
const storeState = store.getState();
|
|
3202
|
+
storeState.setMode(detectRunMode());
|
|
3203
|
+
storeState.setRole("controller");
|
|
3204
|
+
storeState.setRoomId(parsedRoomId);
|
|
3205
|
+
storeState.setStatus(parsedRoomId ? "connecting" : "idle");
|
|
3206
|
+
storeState.setError(void 0);
|
|
3207
|
+
if (!canConnect) {
|
|
3208
|
+
storeState.setStatus("connected");
|
|
3209
|
+
const handleMessage = (event) => {
|
|
3210
|
+
if (event.source !== window.parent) return;
|
|
3211
|
+
const data = event.data;
|
|
3212
|
+
if (data?.type === "AIRJAM_STATE") {
|
|
3213
|
+
const payload = data.payload;
|
|
3214
|
+
if (payload.gameState) storeState.setGameState(payload.gameState);
|
|
3215
|
+
if (payload.message !== void 0)
|
|
3216
|
+
storeState.setStateMessage(payload.message);
|
|
3217
|
+
onStateRef.current?.(payload);
|
|
3218
|
+
}
|
|
3219
|
+
};
|
|
3220
|
+
window.addEventListener("message", handleMessage);
|
|
3221
|
+
window.parent.postMessage({ type: "AIRJAM_READY" }, "*");
|
|
3222
|
+
return () => {
|
|
3223
|
+
window.removeEventListener("message", handleMessage);
|
|
3224
|
+
storeState.setStatus("disconnected");
|
|
3225
|
+
};
|
|
3226
|
+
}
|
|
3227
|
+
if (!parsedRoomId || !socket || !controllerId) {
|
|
3228
|
+
storeState.setStatus("idle");
|
|
3229
|
+
return;
|
|
3230
|
+
}
|
|
3231
|
+
storeState.setControllerId(controllerId);
|
|
3082
3232
|
const handleConnect = () => {
|
|
3083
3233
|
store.getState().setStatus("connected");
|
|
3084
|
-
|
|
3234
|
+
if (subControllerParams) {
|
|
3235
|
+
return;
|
|
3236
|
+
}
|
|
3237
|
+
const payload = controllerJoinSchema.parse({
|
|
3238
|
+
roomId: parsedRoomId,
|
|
3239
|
+
controllerId,
|
|
3240
|
+
nickname: nicknameRef.current || void 0
|
|
3241
|
+
});
|
|
3242
|
+
socket.emit("controller:join", payload, (ack) => {
|
|
3243
|
+
const storeState2 = store.getState();
|
|
3244
|
+
if (!ack.ok) {
|
|
3245
|
+
storeState2.setError(ack.message ?? "Unable to join room");
|
|
3246
|
+
storeState2.setStatus("disconnected");
|
|
3247
|
+
return;
|
|
3248
|
+
}
|
|
3249
|
+
if (ack.controllerId) {
|
|
3250
|
+
storeState2.setControllerId(ack.controllerId);
|
|
3251
|
+
}
|
|
3252
|
+
storeState2.setStatus("connected");
|
|
3253
|
+
});
|
|
3085
3254
|
};
|
|
3086
3255
|
const handleDisconnect = () => {
|
|
3087
3256
|
store.getState().setStatus("disconnected");
|
|
3088
3257
|
};
|
|
3089
|
-
const
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
}, 0);
|
|
3258
|
+
const handleWelcome = (payload) => {
|
|
3259
|
+
const storeState2 = store.getState();
|
|
3260
|
+
const storeRoomId = storeState2.roomId;
|
|
3261
|
+
if (storeRoomId && payload.roomId.toUpperCase() !== storeRoomId.toUpperCase()) {
|
|
3262
|
+
return;
|
|
3095
3263
|
}
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
store.getState().removePlayer(payload.controllerId);
|
|
3099
|
-
onPlayerLeaveRef.current?.(payload.controllerId);
|
|
3100
|
-
};
|
|
3101
|
-
const handleInput = (payload) => {
|
|
3102
|
-
if (inputManager) {
|
|
3103
|
-
inputManager.handleInput(payload);
|
|
3264
|
+
if (!storeRoomId && payload.roomId) {
|
|
3265
|
+
storeState2.setRoomId(payload.roomId);
|
|
3104
3266
|
}
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3267
|
+
if (!payload.player) {
|
|
3268
|
+
storeState2.setError(
|
|
3269
|
+
"Welcome message received but no player profile included."
|
|
3270
|
+
);
|
|
3271
|
+
return;
|
|
3272
|
+
}
|
|
3273
|
+
storeState2.upsertPlayer(payload.player);
|
|
3108
3274
|
};
|
|
3109
3275
|
const handleState = (payload) => {
|
|
3110
3276
|
if (payload.roomId !== parsedRoomId) return;
|
|
@@ -3115,74 +3281,118 @@ var useAirJamHost = (options = {}) => {
|
|
|
3115
3281
|
if (payload.state.message !== void 0) {
|
|
3116
3282
|
storeState2.setStateMessage(payload.state.message);
|
|
3117
3283
|
}
|
|
3284
|
+
onStateRef.current?.(payload.state);
|
|
3285
|
+
};
|
|
3286
|
+
const handleHostLeft = (payload) => {
|
|
3287
|
+
const storeState2 = store.getState();
|
|
3288
|
+
storeState2.setError(payload.reason);
|
|
3289
|
+
storeState2.setStatus("disconnected");
|
|
3290
|
+
storeState2.resetGameState();
|
|
3291
|
+
setTimeout(() => {
|
|
3292
|
+
disconnectSocket("controller");
|
|
3293
|
+
setReconnectKey((prev) => prev + 1);
|
|
3294
|
+
}, 1e3);
|
|
3118
3295
|
};
|
|
3119
3296
|
const handleError = (payload) => {
|
|
3120
3297
|
store.getState().setError(payload.message);
|
|
3121
3298
|
};
|
|
3122
3299
|
socket.on("connect", handleConnect);
|
|
3123
3300
|
socket.on("disconnect", handleDisconnect);
|
|
3124
|
-
socket.on("server:
|
|
3125
|
-
socket.on("server:controllerLeft", handleLeave);
|
|
3126
|
-
socket.on("server:input", handleInput);
|
|
3127
|
-
socket.on("server:error", handleError);
|
|
3128
|
-
socket.on("server:closeChild", handleChildClose);
|
|
3301
|
+
socket.on("server:welcome", handleWelcome);
|
|
3129
3302
|
socket.on("server:state", handleState);
|
|
3303
|
+
socket.on("server:hostLeft", handleHostLeft);
|
|
3304
|
+
socket.on("server:error", handleError);
|
|
3130
3305
|
socket.connect();
|
|
3131
|
-
const currentRegisteredRoomId = store.getState().registeredRoomId;
|
|
3132
|
-
if (socket.connected && currentRegisteredRoomId !== parsedRoomId) {
|
|
3133
|
-
registerHost();
|
|
3134
|
-
}
|
|
3135
|
-
if (currentRegisteredRoomId && currentRegisteredRoomId !== parsedRoomId) {
|
|
3136
|
-
setRegisteredRoomId(null);
|
|
3137
|
-
}
|
|
3138
3306
|
return () => {
|
|
3139
3307
|
socket.off("connect", handleConnect);
|
|
3140
3308
|
socket.off("disconnect", handleDisconnect);
|
|
3141
|
-
socket.off("server:
|
|
3142
|
-
socket.off("server:controllerLeft", handleLeave);
|
|
3143
|
-
socket.off("server:input", handleInput);
|
|
3144
|
-
socket.off("server:error", handleError);
|
|
3145
|
-
socket.off("server:closeChild", handleChildClose);
|
|
3309
|
+
socket.off("server:welcome", handleWelcome);
|
|
3146
3310
|
socket.off("server:state", handleState);
|
|
3311
|
+
socket.off("server:hostLeft", handleHostLeft);
|
|
3312
|
+
socket.off("server:error", handleError);
|
|
3147
3313
|
};
|
|
3148
3314
|
}, [
|
|
3149
|
-
config.maxPlayers,
|
|
3150
|
-
config.apiKey,
|
|
3151
|
-
options.maxPlayers,
|
|
3152
|
-
options.apiKey,
|
|
3153
3315
|
parsedRoomId,
|
|
3154
|
-
|
|
3155
|
-
|
|
3316
|
+
reconnectKey,
|
|
3317
|
+
canConnect,
|
|
3156
3318
|
socket,
|
|
3319
|
+
controllerId,
|
|
3320
|
+
subControllerParams,
|
|
3157
3321
|
store,
|
|
3158
|
-
|
|
3159
|
-
setRegisteredRoomId
|
|
3322
|
+
disconnectSocket
|
|
3160
3323
|
]);
|
|
3161
|
-
const
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3324
|
+
const setNickname = React.useCallback((value) => {
|
|
3325
|
+
nicknameRef.current = value;
|
|
3326
|
+
}, []);
|
|
3327
|
+
const sendInput = React.useCallback(
|
|
3328
|
+
(input) => {
|
|
3329
|
+
const storeState = store.getState();
|
|
3330
|
+
if (!canConnect) {
|
|
3331
|
+
if (typeof window !== "undefined") {
|
|
3332
|
+
window.parent.postMessage(
|
|
3333
|
+
{
|
|
3334
|
+
type: "AIRJAM_INPUT",
|
|
3335
|
+
payload: input
|
|
3336
|
+
},
|
|
3337
|
+
"*"
|
|
3338
|
+
);
|
|
3339
|
+
}
|
|
3340
|
+
return true;
|
|
3166
3341
|
}
|
|
3167
|
-
|
|
3342
|
+
if (!parsedRoomId || !storeState.controllerId || !socket) {
|
|
3343
|
+
storeState.setError("Not connected to a room");
|
|
3344
|
+
return false;
|
|
3345
|
+
}
|
|
3346
|
+
if (!socket.connected) {
|
|
3347
|
+
return false;
|
|
3348
|
+
}
|
|
3349
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
3350
|
+
storeState.setError("Input must be an object");
|
|
3351
|
+
return false;
|
|
3352
|
+
}
|
|
3353
|
+
const payload = controllerInputSchema.safeParse({
|
|
3354
|
+
roomId: parsedRoomId,
|
|
3355
|
+
controllerId: storeState.controllerId,
|
|
3356
|
+
input
|
|
3357
|
+
});
|
|
3358
|
+
if (!payload.success) {
|
|
3359
|
+
storeState.setError(payload.error.message);
|
|
3360
|
+
return false;
|
|
3361
|
+
}
|
|
3362
|
+
socket.emit("controller:input", payload.data);
|
|
3363
|
+
return true;
|
|
3168
3364
|
},
|
|
3169
|
-
[
|
|
3365
|
+
[parsedRoomId, canConnect, socket, store]
|
|
3366
|
+
);
|
|
3367
|
+
const sendSystemCommand = React.useCallback(
|
|
3368
|
+
(command) => {
|
|
3369
|
+
const storeState = store.getState();
|
|
3370
|
+
if (!canConnect) return;
|
|
3371
|
+
if (!parsedRoomId || !storeState.controllerId || !socket) return;
|
|
3372
|
+
if (!socket.connected) return;
|
|
3373
|
+
const payload = controllerSystemSchema.safeParse({
|
|
3374
|
+
roomId: parsedRoomId,
|
|
3375
|
+
command
|
|
3376
|
+
});
|
|
3377
|
+
if (payload.success) {
|
|
3378
|
+
socket.emit("controller:system", payload.data);
|
|
3379
|
+
}
|
|
3380
|
+
},
|
|
3381
|
+
[parsedRoomId, canConnect, socket, store]
|
|
3170
3382
|
);
|
|
3171
3383
|
return {
|
|
3172
3384
|
roomId: parsedRoomId,
|
|
3173
|
-
|
|
3385
|
+
controllerId: connectionState.controllerId,
|
|
3174
3386
|
connectionStatus: connectionState.connectionStatus,
|
|
3175
|
-
players: connectionState.players,
|
|
3176
3387
|
lastError: connectionState.lastError,
|
|
3177
|
-
mode: connectionState.mode,
|
|
3178
3388
|
gameState: connectionState.gameState,
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3389
|
+
stateMessage: connectionState.stateMessage,
|
|
3390
|
+
sendInput,
|
|
3391
|
+
sendSystemCommand,
|
|
3392
|
+
setNickname,
|
|
3182
3393
|
reconnect,
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
getInput
|
|
3394
|
+
players: connectionState.players,
|
|
3395
|
+
socket
|
|
3186
3396
|
};
|
|
3187
3397
|
};
|
|
3188
3398
|
var getRoomFromLocation2 = () => {
|
|
@@ -3453,9 +3663,112 @@ var useSendSignal = () => {
|
|
|
3453
3663
|
);
|
|
3454
3664
|
return sendSignal;
|
|
3455
3665
|
};
|
|
3666
|
+
function createAirJamStore2(initializer) {
|
|
3667
|
+
const store = zustand.create((set, get, api) => {
|
|
3668
|
+
const baseState = initializer(set, get, api);
|
|
3669
|
+
return {
|
|
3670
|
+
...baseState,
|
|
3671
|
+
actions: {
|
|
3672
|
+
...baseState.actions,
|
|
3673
|
+
_syncState: (partial) => {
|
|
3674
|
+
set(partial);
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
};
|
|
3678
|
+
});
|
|
3679
|
+
const useSyncedStore = (selector = (s) => s) => {
|
|
3680
|
+
const slice = store(selector);
|
|
3681
|
+
const { getSocket } = useAirJamContext();
|
|
3682
|
+
const role = useAirJamState((state) => state.role);
|
|
3683
|
+
const roomId = useAirJamState((state) => state.roomId);
|
|
3684
|
+
const controllerId = useAirJamState((state) => state.controllerId);
|
|
3685
|
+
const socket = role === "host" ? getSocket("host") : getSocket("controller");
|
|
3686
|
+
React.useEffect(() => {
|
|
3687
|
+
if (!socket || !roomId || !role) {
|
|
3688
|
+
return;
|
|
3689
|
+
}
|
|
3690
|
+
if (role === "host") {
|
|
3691
|
+
const unsubscribe = store.subscribe((newState) => {
|
|
3692
|
+
const { actions, ...stateData } = newState;
|
|
3693
|
+
socket.emit("host:state_sync", { roomId, data: stateData });
|
|
3694
|
+
});
|
|
3695
|
+
const handleAction = (payload) => {
|
|
3696
|
+
const { actionName, args, controllerId: controllerId2 } = payload;
|
|
3697
|
+
const actionFn = store.getState().actions[actionName];
|
|
3698
|
+
if (actionFn) {
|
|
3699
|
+
actionFn(...args, controllerId2);
|
|
3700
|
+
}
|
|
3701
|
+
};
|
|
3702
|
+
socket.on("airjam:action_rpc", handleAction);
|
|
3703
|
+
return () => {
|
|
3704
|
+
unsubscribe();
|
|
3705
|
+
socket.off("airjam:action_rpc", handleAction);
|
|
3706
|
+
};
|
|
3707
|
+
}
|
|
3708
|
+
if (role === "controller") {
|
|
3709
|
+
const handleSync = (payload) => {
|
|
3710
|
+
const { data } = payload;
|
|
3711
|
+
const currentState = store.getState();
|
|
3712
|
+
const actions = currentState.actions;
|
|
3713
|
+
if (actions._syncState) {
|
|
3714
|
+
actions._syncState(data);
|
|
3715
|
+
} else {
|
|
3716
|
+
store.setState(data);
|
|
3717
|
+
}
|
|
3718
|
+
};
|
|
3719
|
+
socket.on("airjam:state_sync", handleSync);
|
|
3720
|
+
return () => socket.off("airjam:state_sync", handleSync);
|
|
3721
|
+
}
|
|
3722
|
+
}, [socket, role, roomId]);
|
|
3723
|
+
if (role === "controller" && socket && roomId) {
|
|
3724
|
+
let originalActions = null;
|
|
3725
|
+
if (typeof slice === "object" && slice !== null && "actions" in slice) {
|
|
3726
|
+
originalActions = slice.actions;
|
|
3727
|
+
} else if (typeof slice === "object" && slice !== null) {
|
|
3728
|
+
const fullState = store.getState();
|
|
3729
|
+
if (fullState.actions) {
|
|
3730
|
+
const sliceKeys = Object.keys(slice);
|
|
3731
|
+
const actionKeys = Object.keys(fullState.actions);
|
|
3732
|
+
if (sliceKeys.length > 0 && sliceKeys.every(
|
|
3733
|
+
(key) => typeof slice[key] === "function" && actionKeys.includes(key)
|
|
3734
|
+
)) {
|
|
3735
|
+
originalActions = slice;
|
|
3736
|
+
}
|
|
3737
|
+
}
|
|
3738
|
+
}
|
|
3739
|
+
if (originalActions) {
|
|
3740
|
+
const proxyActions = {};
|
|
3741
|
+
Object.keys(originalActions).forEach((key) => {
|
|
3742
|
+
proxyActions[key] = (...args) => {
|
|
3743
|
+
if (!controllerId) {
|
|
3744
|
+
console.warn(
|
|
3745
|
+
"[AirJamStore] Cannot send action RPC: controllerId not set"
|
|
3746
|
+
);
|
|
3747
|
+
return;
|
|
3748
|
+
}
|
|
3749
|
+
socket.emit("controller:action_rpc", {
|
|
3750
|
+
roomId,
|
|
3751
|
+
actionName: key,
|
|
3752
|
+
args,
|
|
3753
|
+
controllerId
|
|
3754
|
+
});
|
|
3755
|
+
};
|
|
3756
|
+
});
|
|
3757
|
+
if (typeof slice === "object" && slice !== null && "actions" in slice) {
|
|
3758
|
+
return { ...slice, actions: proxyActions };
|
|
3759
|
+
} else {
|
|
3760
|
+
return proxyActions;
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
return slice;
|
|
3765
|
+
};
|
|
3766
|
+
return useSyncedStore;
|
|
3767
|
+
}
|
|
3456
3768
|
|
|
3457
3769
|
exports.AIRJAM_PROXY_PREFIX = AIRJAM_PROXY_PREFIX;
|
|
3458
3770
|
exports.AirJamContext = AirJamContext;
|
|
3771
|
+
exports.AirJamDebug = AirJamDebug;
|
|
3459
3772
|
exports.AirJamOverlay = AirJamOverlay;
|
|
3460
3773
|
exports.AirJamProvider = AirJamProvider;
|
|
3461
3774
|
exports.AudioManager = AudioManager;
|
|
@@ -3468,10 +3781,12 @@ exports.ControllerShell = ControllerShell;
|
|
|
3468
3781
|
exports.DEFAULT_CONTROLLER_PATH = DEFAULT_CONTROLLER_PATH;
|
|
3469
3782
|
exports.DEFAULT_MAX_PLAYERS = DEFAULT_MAX_PLAYERS;
|
|
3470
3783
|
exports.DEFAULT_SERVER_PORT = DEFAULT_SERVER_PORT;
|
|
3784
|
+
exports.DebugStateDialog = DebugStateDialog;
|
|
3471
3785
|
exports.ErrorCode = ErrorCode;
|
|
3472
3786
|
exports.Events = Events;
|
|
3473
3787
|
exports.HostEvents = HostEvents;
|
|
3474
3788
|
exports.INPUT_DEBOUNCE_MS = INPUT_DEBOUNCE_MS;
|
|
3789
|
+
exports.PlayerAvatar = PlayerAvatar;
|
|
3475
3790
|
exports.SOCKET_CONFIG = SOCKET_CONFIG;
|
|
3476
3791
|
exports.ServerEvents = ServerEvents;
|
|
3477
3792
|
exports.Slider = Slider;
|
|
@@ -3486,6 +3801,7 @@ exports.controllerJoinSchema = controllerJoinSchema;
|
|
|
3486
3801
|
exports.controllerLeaveSchema = controllerLeaveSchema;
|
|
3487
3802
|
exports.controllerStateSchema = controllerStateSchema;
|
|
3488
3803
|
exports.controllerSystemSchema = controllerSystemSchema;
|
|
3804
|
+
exports.createAirJamStore = createAirJamStore2;
|
|
3489
3805
|
exports.createAudioManager = createAudioManager;
|
|
3490
3806
|
exports.detectSoundCategory = detectSoundCategory;
|
|
3491
3807
|
exports.generateControllerId = generateControllerId;
|