@air-jam/sdk 0.1.2 → 0.1.4

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