@air-jam/sdk 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-XSXI3RIS.js → chunk-B5DURUWT.js} +11 -3
- package/dist/chunk-B5DURUWT.js.map +1 -0
- package/dist/index.cjs +2346 -1931
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +97 -41
- package/dist/index.d.ts +97 -41
- package/dist/index.js +2401 -2001
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs +10 -0
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +42 -1
- package/dist/protocol.d.ts +42 -1
- package/dist/protocol.js +1 -1
- package/package.json +5 -1
- package/src/AirJamClient.ts +1 -552
- package/src/audio/audio-manager.ts +12 -1
- package/src/audio/volume-store.ts +47 -0
- package/src/components/air-jam-debug.tsx +77 -0
- package/src/components/air-jam-overlay.tsx +243 -186
- package/src/components/controller-shell.tsx +174 -182
- package/src/components/debug-state-dialog.tsx +83 -0
- package/src/components/player-avatar.tsx +64 -0
- package/src/components/qr-scanner-dialog.tsx +2 -2
- package/src/components/ui/button.tsx +1 -1
- package/src/components/ui/dialog.tsx +122 -0
- package/src/constants.ts +3 -2
- package/src/context/air-jam-context.tsx +3 -14
- package/src/hooks/use-air-jam-controller.ts +1 -1
- package/src/hooks/use-air-jam-host.ts +94 -49
- package/src/hooks/use-air-jam-shell.ts +36 -0
- package/src/index.ts +6 -0
- package/src/internal/input-manager.ts +28 -14
- package/src/protocol.ts +55 -0
- package/src/store/create-air-jam-store.ts +274 -0
- package/src/store/index.ts +1 -0
- package/src/utils/url-builder.ts +3 -3
- package/dist/chunk-XSXI3RIS.js.map +0 -1
|
@@ -10,6 +10,19 @@ interface VolumeSettings {
|
|
|
10
10
|
getEffectiveVolume: (category: "music" | "sfx") => number;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Settings sync message from parent (arcade) to child (game) iframe.
|
|
15
|
+
* This allows the arcade overlay to control volume for embedded games.
|
|
16
|
+
*/
|
|
17
|
+
interface AirJamSettingsSyncMessage {
|
|
18
|
+
type: "AIRJAM_SETTINGS_SYNC";
|
|
19
|
+
payload: {
|
|
20
|
+
masterVolume: number;
|
|
21
|
+
musicVolume: number;
|
|
22
|
+
sfxVolume: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
const STORAGE_KEY = "air-jam-volume-settings";
|
|
14
27
|
|
|
15
28
|
// Load initial state from localStorage
|
|
@@ -75,3 +88,37 @@ export const useVolumeStore = create<VolumeSettings>((set, get) => ({
|
|
|
75
88
|
return masterVolume * categoryVolume;
|
|
76
89
|
},
|
|
77
90
|
}));
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Set up parent message listener for child mode (games running in arcade iframe).
|
|
94
|
+
* When the arcade sends AIRJAM_SETTINGS_SYNC messages, apply them to the volume store.
|
|
95
|
+
* This runs once at module load time and is completely transparent to game developers.
|
|
96
|
+
*/
|
|
97
|
+
const setupParentSettingsListener = () => {
|
|
98
|
+
if (typeof window === "undefined") return;
|
|
99
|
+
|
|
100
|
+
// Only listen if we're running inside an iframe (child mode)
|
|
101
|
+
const isInIframe = window.parent !== window;
|
|
102
|
+
if (!isInIframe) return;
|
|
103
|
+
|
|
104
|
+
const handleMessage = (event: MessageEvent<AirJamSettingsSyncMessage>) => {
|
|
105
|
+
// Only accept settings sync messages from parent
|
|
106
|
+
if (event.source !== window.parent) return;
|
|
107
|
+
if (event.data?.type !== "AIRJAM_SETTINGS_SYNC") return;
|
|
108
|
+
|
|
109
|
+
const { masterVolume, musicVolume, sfxVolume } = event.data.payload;
|
|
110
|
+
|
|
111
|
+
// Apply settings without saving to localStorage (arcade owns the settings)
|
|
112
|
+
const store = useVolumeStore.getState();
|
|
113
|
+
|
|
114
|
+
// Use setters to trigger AudioManager subscription updates
|
|
115
|
+
if (typeof masterVolume === "number") store.setMasterVolume(masterVolume);
|
|
116
|
+
if (typeof musicVolume === "number") store.setMusicVolume(musicVolume);
|
|
117
|
+
if (typeof sfxVolume === "number") store.setSfxVolume(sfxVolume);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
window.addEventListener("message", handleMessage);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// Initialize the parent settings listener
|
|
124
|
+
setupParentSettingsListener();
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Bug } from "lucide-react";
|
|
2
|
+
import type { JSX } from "react";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { DebugStateDialog } from "./debug-state-dialog";
|
|
5
|
+
import { Button } from "./ui/button";
|
|
6
|
+
|
|
7
|
+
interface AirJamDebugProps {
|
|
8
|
+
state: unknown;
|
|
9
|
+
title?: string;
|
|
10
|
+
updateInterval?: number;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A debug component that displays state in a dialog.
|
|
16
|
+
* Place this component anywhere in your React tree and pass the state you want to debug.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const { phase, scores } = useGameStore((state) => state);
|
|
21
|
+
*
|
|
22
|
+
* return (
|
|
23
|
+
* <div>
|
|
24
|
+
* <AirJamDebug state={{ phase, scores }} />
|
|
25
|
+
* {/* Your game UI *\/}
|
|
26
|
+
* </div>
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export const AirJamDebug = ({
|
|
31
|
+
state,
|
|
32
|
+
title = "Debug State",
|
|
33
|
+
updateInterval = 100,
|
|
34
|
+
className,
|
|
35
|
+
}: AirJamDebugProps): JSX.Element => {
|
|
36
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
37
|
+
const [currentState, setCurrentState] = useState(state);
|
|
38
|
+
|
|
39
|
+
// Update state periodically when dialog is open
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!isOpen) return;
|
|
42
|
+
|
|
43
|
+
const interval = setInterval(() => {
|
|
44
|
+
setCurrentState(state);
|
|
45
|
+
}, updateInterval);
|
|
46
|
+
|
|
47
|
+
// Update immediately
|
|
48
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
49
|
+
setCurrentState(state);
|
|
50
|
+
|
|
51
|
+
return () => clearInterval(interval);
|
|
52
|
+
}, [isOpen, state, updateInterval]);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
<Button
|
|
57
|
+
type="button"
|
|
58
|
+
variant="ghost"
|
|
59
|
+
size="icon"
|
|
60
|
+
onClick={() => setIsOpen(true)}
|
|
61
|
+
aria-label="Debug state"
|
|
62
|
+
title={title}
|
|
63
|
+
className={`text-white hover:bg-white/20 hover:text-white ${className || ""}`}
|
|
64
|
+
>
|
|
65
|
+
<Bug className="h-4 w-4" />
|
|
66
|
+
</Button>
|
|
67
|
+
|
|
68
|
+
<DebugStateDialog
|
|
69
|
+
isOpen={isOpen}
|
|
70
|
+
onClose={() => setIsOpen(false)}
|
|
71
|
+
getState={() => currentState}
|
|
72
|
+
title={title}
|
|
73
|
+
updateInterval={updateInterval}
|
|
74
|
+
/>
|
|
75
|
+
</>
|
|
76
|
+
);
|
|
77
|
+
};
|