@air-jam/sdk 0.1.1 → 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-7M5D3Y3L.js → chunk-B5DURUWT.js} +11 -3
- package/dist/chunk-B5DURUWT.js.map +1 -0
- package/dist/index.cjs +226 -127
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -27
- package/dist/index.d.ts +19 -27
- package/dist/index.js +218 -129
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs +10 -0
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +19 -1
- package/dist/protocol.d.ts +19 -1
- package/dist/protocol.js +1 -1
- package/package.json +4 -1
- package/src/AirJamClient.ts +1 -552
- package/src/audio/audio-manager.ts +12 -1
- package/src/audio/volume-store.ts +47 -0
- package/src/components/air-jam-overlay.tsx +1 -1
- package/src/components/controller-shell.tsx +170 -171
- package/src/components/qr-scanner-dialog.tsx +2 -2
- package/src/constants.ts +3 -2
- package/src/context/air-jam-context.tsx +3 -14
- package/src/hooks/use-air-jam-controller.ts +1 -1
- package/src/hooks/use-air-jam-host.ts +94 -49
- package/src/hooks/use-air-jam-shell.ts +36 -0
- package/src/internal/input-manager.ts +28 -14
- package/src/protocol.ts +28 -0
- package/src/store/create-air-jam-store.ts +69 -7
- package/src/utils/url-builder.ts +3 -3
- package/dist/chunk-7M5D3Y3L.js.map +0 -1
|
@@ -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();
|
|
@@ -15,17 +15,15 @@ import { useFullscreen } from "../hooks/use-fullscreen";
|
|
|
15
15
|
import type { ConnectionStatus, PlayerProfile } from "../protocol";
|
|
16
16
|
import { cn } from "../utils/cn";
|
|
17
17
|
import { detectRunMode } from "../utils/mode";
|
|
18
|
+
import { PlayerAvatar } from "./player-avatar";
|
|
18
19
|
import { QRScannerDialog } from "./qr-scanner-dialog";
|
|
19
20
|
import { Button } from "./ui/button";
|
|
20
|
-
import { PlayerAvatar } from "./player-avatar";
|
|
21
|
-
import { VolumeControls } from "./volume-controls";
|
|
22
|
-
|
|
23
|
-
type OrientationRequirement = "portrait" | "landscape" | "any";
|
|
24
21
|
|
|
25
22
|
interface ControllerShellProps {
|
|
26
23
|
roomId?: string | null;
|
|
27
24
|
connectionStatus: ConnectionStatus;
|
|
28
|
-
|
|
25
|
+
/** Optional forced orientation. If not set, no orientation enforcement is applied. */
|
|
26
|
+
forceOrientation?: "portrait" | "landscape";
|
|
29
27
|
children: ReactNode;
|
|
30
28
|
gameState?: "paused" | "playing";
|
|
31
29
|
onTogglePlayPause?: () => void;
|
|
@@ -50,8 +48,10 @@ const describeStatus = (status: ConnectionStatus): string => {
|
|
|
50
48
|
}
|
|
51
49
|
};
|
|
52
50
|
|
|
53
|
-
const orientationMatches = (
|
|
54
|
-
|
|
51
|
+
const orientationMatches = (
|
|
52
|
+
required: "portrait" | "landscape" | undefined,
|
|
53
|
+
): boolean => {
|
|
54
|
+
if (!required) return true;
|
|
55
55
|
if (typeof window === "undefined" || !window.matchMedia) return true;
|
|
56
56
|
const matcher = window.matchMedia(`(orientation: ${required})`);
|
|
57
57
|
return matcher.matches;
|
|
@@ -60,7 +60,7 @@ const orientationMatches = (required: OrientationRequirement): boolean => {
|
|
|
60
60
|
export const ControllerShell = ({
|
|
61
61
|
roomId,
|
|
62
62
|
connectionStatus,
|
|
63
|
-
|
|
63
|
+
forceOrientation,
|
|
64
64
|
children,
|
|
65
65
|
gameState = "paused",
|
|
66
66
|
onTogglePlayPause,
|
|
@@ -70,7 +70,7 @@ export const ControllerShell = ({
|
|
|
70
70
|
}: ControllerShellProps): JSX.Element => {
|
|
71
71
|
const isChildMode = useMemo(() => detectRunMode() === "platform", []);
|
|
72
72
|
const [isOrientationOk, setOrientationOk] = useState(() =>
|
|
73
|
-
orientationMatches(
|
|
73
|
+
orientationMatches(forceOrientation),
|
|
74
74
|
);
|
|
75
75
|
const [isScannerOpen, setIsScannerOpen] = useState(false);
|
|
76
76
|
const { isFullscreen, toggleFullscreen } = useFullscreen();
|
|
@@ -103,18 +103,20 @@ export const ControllerShell = ({
|
|
|
103
103
|
}, [controllerId, players, connectionStatus]);
|
|
104
104
|
|
|
105
105
|
useEffect(() => {
|
|
106
|
-
if (
|
|
106
|
+
if (!forceOrientation) {
|
|
107
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
108
|
+
setOrientationOk(true);
|
|
107
109
|
return;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
const media = window.matchMedia(`(orientation: ${
|
|
112
|
+
const media = window.matchMedia(`(orientation: ${forceOrientation})`);
|
|
111
113
|
const handleChange = (): void => setOrientationOk(media.matches);
|
|
112
114
|
handleChange();
|
|
113
115
|
media.addEventListener("change", handleChange);
|
|
114
116
|
return () => media.removeEventListener("change", handleChange);
|
|
115
|
-
}, [
|
|
117
|
+
}, [forceOrientation]);
|
|
116
118
|
|
|
117
|
-
const orientationOk =
|
|
119
|
+
const orientationOk = !forceOrientation ? true : isOrientationOk;
|
|
118
120
|
|
|
119
121
|
const statusDotColor = useMemo(() => {
|
|
120
122
|
switch (connectionStatus) {
|
|
@@ -135,28 +137,28 @@ export const ControllerShell = ({
|
|
|
135
137
|
return (
|
|
136
138
|
<div className="dark">
|
|
137
139
|
<div className="text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden bg-transparent select-none">
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
)}
|
|
150
|
-
<div
|
|
151
|
-
className={cn(
|
|
152
|
-
"h-full w-full select-none",
|
|
153
|
-
!orientationOk && "pointer-events-none opacity-30",
|
|
140
|
+
<main className="relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4">
|
|
141
|
+
{!orientationOk && (
|
|
142
|
+
<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">
|
|
143
|
+
<p className="text-card-foreground text-xl font-semibold">
|
|
144
|
+
Rotate your device
|
|
145
|
+
</p>
|
|
146
|
+
<p className="text-muted-foreground mt-2 text-sm">
|
|
147
|
+
This game is best experienced in {forceOrientation}{" "}
|
|
148
|
+
orientation.
|
|
149
|
+
</p>
|
|
150
|
+
</div>
|
|
154
151
|
)}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
152
|
+
<div
|
|
153
|
+
className={cn(
|
|
154
|
+
"h-full w-full select-none",
|
|
155
|
+
!orientationOk && "pointer-events-none opacity-30",
|
|
156
|
+
)}
|
|
157
|
+
>
|
|
158
|
+
{children}
|
|
159
|
+
</div>
|
|
160
|
+
</main>
|
|
161
|
+
</div>
|
|
160
162
|
</div>
|
|
161
163
|
);
|
|
162
164
|
}
|
|
@@ -164,158 +166,155 @@ export const ControllerShell = ({
|
|
|
164
166
|
return (
|
|
165
167
|
<div className="dark">
|
|
166
168
|
<div className="bg-background text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden select-none">
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
169
|
+
<header className="pointer-events-none sticky top-0 z-50 flex items-center justify-between border-b px-6 py-2">
|
|
170
|
+
<div className="pointer-events-auto flex items-center gap-3">
|
|
171
|
+
{typeof window !== "undefined" &&
|
|
172
|
+
(currentPlayer || controllerId) && (
|
|
173
|
+
<div
|
|
174
|
+
className="relative"
|
|
175
|
+
title={describeStatus(connectionStatus)}
|
|
176
|
+
>
|
|
177
|
+
{currentPlayer ? (
|
|
178
|
+
<PlayerAvatar player={currentPlayer} size="sm" />
|
|
179
|
+
) : controllerId ? (
|
|
180
|
+
<PlayerAvatar
|
|
181
|
+
player={{
|
|
182
|
+
id: controllerId,
|
|
183
|
+
label: "Player",
|
|
184
|
+
}}
|
|
185
|
+
size="sm"
|
|
186
|
+
/>
|
|
187
|
+
) : null}
|
|
188
|
+
{/* Black border circle - always visible behind */}
|
|
189
|
+
<span
|
|
190
|
+
className="absolute right-0 bottom-0 h-3 w-3 rounded-full bg-black"
|
|
191
|
+
aria-hidden="true"
|
|
192
|
+
/>
|
|
193
|
+
{/* Colored status dot - on top */}
|
|
194
|
+
<span
|
|
195
|
+
className={cn(
|
|
196
|
+
"absolute right-0.5 bottom-0.5 h-2 w-2 rounded-full",
|
|
197
|
+
statusDotColor,
|
|
198
|
+
connectionStatus === "connected" && "animate-pulse",
|
|
199
|
+
)}
|
|
200
|
+
aria-label={describeStatus(connectionStatus)}
|
|
201
|
+
/>
|
|
202
|
+
</div>
|
|
203
|
+
)}
|
|
204
|
+
<div>
|
|
205
|
+
<p className="text-muted-foreground text-xs tracking-[0.24em] uppercase">
|
|
206
|
+
Room
|
|
207
|
+
</p>
|
|
208
|
+
<p className="text-foreground text-lg font-semibold">
|
|
209
|
+
{typeof window !== "undefined" ? (roomId ?? "N/A") : "N/A"}
|
|
210
|
+
</p>
|
|
196
211
|
</div>
|
|
197
|
-
)}
|
|
198
|
-
<div>
|
|
199
|
-
<p className="text-muted-foreground text-xs tracking-[0.24em] uppercase">
|
|
200
|
-
Room
|
|
201
|
-
</p>
|
|
202
|
-
<p className="text-foreground text-lg font-semibold">
|
|
203
|
-
{typeof window !== "undefined" ? (roomId ?? "N/A") : "N/A"}
|
|
204
|
-
</p>
|
|
205
212
|
</div>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
213
|
+
<div className="pointer-events-auto flex items-center gap-3">
|
|
214
|
+
{customActions}
|
|
215
|
+
{onRefresh && roomId && (
|
|
216
|
+
<Button
|
|
217
|
+
type="button"
|
|
218
|
+
variant="outline"
|
|
219
|
+
size="icon"
|
|
220
|
+
onClick={onRefresh}
|
|
221
|
+
disabled={
|
|
222
|
+
connectionStatus === "connecting" ||
|
|
223
|
+
connectionStatus === "reconnecting"
|
|
224
|
+
}
|
|
225
|
+
aria-label="Reconnect"
|
|
226
|
+
title="Reconnect to room"
|
|
227
|
+
>
|
|
228
|
+
<RefreshCw
|
|
229
|
+
className={cn(
|
|
230
|
+
"h-5 w-5",
|
|
231
|
+
(connectionStatus === "connecting" ||
|
|
232
|
+
connectionStatus === "reconnecting") &&
|
|
233
|
+
"animate-spin",
|
|
234
|
+
)}
|
|
235
|
+
/>
|
|
236
|
+
</Button>
|
|
237
|
+
)}
|
|
238
|
+
{onReconnect && (
|
|
239
|
+
<Button
|
|
240
|
+
type="button"
|
|
241
|
+
variant="outline"
|
|
242
|
+
size="icon"
|
|
243
|
+
onClick={() => setIsScannerOpen(true)}
|
|
244
|
+
aria-label="Scan QR code to reconnect"
|
|
245
|
+
title="Scan QR code to reconnect"
|
|
246
|
+
>
|
|
247
|
+
<QrCode className="h-5 w-5" />
|
|
248
|
+
</Button>
|
|
249
|
+
)}
|
|
250
|
+
{onTogglePlayPause && (
|
|
251
|
+
<Button
|
|
252
|
+
type="button"
|
|
253
|
+
variant="outline"
|
|
254
|
+
size="icon"
|
|
255
|
+
onClick={onTogglePlayPause}
|
|
256
|
+
aria-label={gameState === "playing" ? "Pause" : "Play"}
|
|
257
|
+
title={gameState === "playing" ? "Pause" : "Play"}
|
|
258
|
+
>
|
|
259
|
+
{gameState === "playing" ? (
|
|
260
|
+
<Pause className="h-5 w-5" />
|
|
261
|
+
) : (
|
|
262
|
+
<Play className="h-5 w-5" />
|
|
228
263
|
)}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
)}
|
|
232
|
-
{onReconnect && (
|
|
233
|
-
<Button
|
|
234
|
-
type="button"
|
|
235
|
-
variant="outline"
|
|
236
|
-
size="icon"
|
|
237
|
-
onClick={() => setIsScannerOpen(true)}
|
|
238
|
-
aria-label="Scan QR code to reconnect"
|
|
239
|
-
title="Scan QR code to reconnect"
|
|
240
|
-
>
|
|
241
|
-
<QrCode className="h-5 w-5" />
|
|
242
|
-
</Button>
|
|
243
|
-
)}
|
|
244
|
-
{onTogglePlayPause && (
|
|
264
|
+
</Button>
|
|
265
|
+
)}
|
|
245
266
|
<Button
|
|
246
267
|
type="button"
|
|
247
268
|
variant="outline"
|
|
248
269
|
size="icon"
|
|
249
|
-
onClick={
|
|
250
|
-
aria-label={
|
|
251
|
-
title={
|
|
270
|
+
onClick={() => toggleFullscreen()}
|
|
271
|
+
aria-label={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
|
|
272
|
+
title={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
|
|
252
273
|
>
|
|
253
|
-
{
|
|
254
|
-
<
|
|
274
|
+
{isFullscreen ? (
|
|
275
|
+
<Minimize className="h-5 w-5" />
|
|
255
276
|
) : (
|
|
256
|
-
<
|
|
277
|
+
<Maximize className="h-5 w-5" />
|
|
257
278
|
)}
|
|
258
279
|
</Button>
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
type="button"
|
|
262
|
-
variant="outline"
|
|
263
|
-
size="icon"
|
|
264
|
-
onClick={() => toggleFullscreen()}
|
|
265
|
-
aria-label={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
|
|
266
|
-
title={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
|
|
267
|
-
>
|
|
268
|
-
{isFullscreen ? (
|
|
269
|
-
<Minimize className="h-5 w-5" />
|
|
270
|
-
) : (
|
|
271
|
-
<Maximize className="h-5 w-5" />
|
|
272
|
-
)}
|
|
273
|
-
</Button>
|
|
274
|
-
</div>
|
|
275
|
-
</header>
|
|
276
|
-
|
|
277
|
-
{/* Volume Controls - positioned absolutely for mobile */}
|
|
278
|
-
<div className="pointer-events-none fixed right-4 bottom-4 z-50">
|
|
279
|
-
<div className="pointer-events-auto">
|
|
280
|
-
<VolumeControls compact={true} />
|
|
281
|
-
</div>
|
|
282
|
-
</div>
|
|
280
|
+
</div>
|
|
281
|
+
</header>
|
|
283
282
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
)}
|
|
297
|
-
<div
|
|
298
|
-
className={cn(
|
|
299
|
-
"h-full w-full select-none",
|
|
300
|
-
!orientationOk && "pointer-events-none opacity-30",
|
|
283
|
+
<main className="relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4">
|
|
284
|
+
<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">
|
|
285
|
+
{!orientationOk && forceOrientation && (
|
|
286
|
+
<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">
|
|
287
|
+
<p className="text-card-foreground text-xl font-semibold">
|
|
288
|
+
Rotate your device
|
|
289
|
+
</p>
|
|
290
|
+
<p className="text-muted-foreground mt-2 text-sm">
|
|
291
|
+
This game is best experienced in {forceOrientation}{" "}
|
|
292
|
+
orientation.
|
|
293
|
+
</p>
|
|
294
|
+
</div>
|
|
301
295
|
)}
|
|
302
|
-
|
|
303
|
-
|
|
296
|
+
<div
|
|
297
|
+
className={cn(
|
|
298
|
+
"h-full w-full select-none",
|
|
299
|
+
!orientationOk && "pointer-events-none opacity-30",
|
|
300
|
+
)}
|
|
301
|
+
>
|
|
302
|
+
{children}
|
|
303
|
+
</div>
|
|
304
304
|
</div>
|
|
305
|
-
</
|
|
306
|
-
</main>
|
|
305
|
+
</main>
|
|
307
306
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
307
|
+
{onReconnect && (
|
|
308
|
+
<QRScannerDialog
|
|
309
|
+
isOpen={isScannerOpen}
|
|
310
|
+
onClose={() => setIsScannerOpen(false)}
|
|
311
|
+
onScan={(roomCode) => {
|
|
312
|
+
onReconnect(roomCode);
|
|
313
|
+
setIsScannerOpen(false);
|
|
314
|
+
}}
|
|
315
|
+
currentRoomId={roomId}
|
|
316
|
+
/>
|
|
317
|
+
)}
|
|
319
318
|
</div>
|
|
320
319
|
</div>
|
|
321
320
|
);
|
|
@@ -15,8 +15,8 @@ interface QRScannerDialogProps {
|
|
|
15
15
|
/**
|
|
16
16
|
* Extracts room code from a scanned URL or text.
|
|
17
17
|
* Supports formats like:
|
|
18
|
-
* - http://host/
|
|
19
|
-
* - https://host/
|
|
18
|
+
* - http://host/controller?room=CODE
|
|
19
|
+
* - https://host/controller?room=CODE
|
|
20
20
|
* - Just the room code itself
|
|
21
21
|
*/
|
|
22
22
|
const extractRoomCode = (text: string): string | null => {
|
package/src/constants.ts
CHANGED
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
export const DEFAULT_SERVER_PORT = 4000;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Standard path for controller endpoints.
|
|
12
|
+
* All Air Jam games use this convention - controller is always at {baseUrl}/controller
|
|
12
13
|
*/
|
|
13
|
-
export const
|
|
14
|
+
export const CONTROLLER_PATH = "/controller";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Input debounce time in milliseconds
|
|
@@ -54,7 +54,7 @@ import {
|
|
|
54
54
|
import type { z } from "zod";
|
|
55
55
|
import { useStore } from "zustand";
|
|
56
56
|
import { useShallow } from "zustand/react/shallow";
|
|
57
|
-
import {
|
|
57
|
+
import { DEFAULT_MAX_PLAYERS } from "../constants";
|
|
58
58
|
import { InputManager, type InputConfig } from "../internal/input-manager";
|
|
59
59
|
import type { ConnectionRole } from "../protocol";
|
|
60
60
|
import { createAirJamStore, type AirJamStore } from "../state/connection-store";
|
|
@@ -73,8 +73,6 @@ export interface AirJamConfig {
|
|
|
73
73
|
serverUrl?: string;
|
|
74
74
|
/** API key for production authentication */
|
|
75
75
|
apiKey?: string;
|
|
76
|
-
/** Path for controller page (default: /joypad) */
|
|
77
|
-
controllerPath: string;
|
|
78
76
|
/** Maximum players allowed in a room */
|
|
79
77
|
maxPlayers: number;
|
|
80
78
|
/** Public host for controller URLs (optional) */
|
|
@@ -98,7 +96,6 @@ export interface AirJamConfig {
|
|
|
98
96
|
* <AirJamProvider
|
|
99
97
|
* serverUrl="wss://your-server.com"
|
|
100
98
|
* apiKey="your-api-key"
|
|
101
|
-
* controllerPath="/controller"
|
|
102
99
|
* maxPlayers={4}
|
|
103
100
|
* input={{
|
|
104
101
|
* schema: myInputSchema,
|
|
@@ -124,12 +121,6 @@ export interface AirJamProviderProps<
|
|
|
124
121
|
* Falls back to VITE_AIR_JAM_API_KEY or NEXT_PUBLIC_AIR_JAM_API_KEY environment variables.
|
|
125
122
|
*/
|
|
126
123
|
apiKey?: string;
|
|
127
|
-
/**
|
|
128
|
-
* URL path for the controller page on your app.
|
|
129
|
-
* Controllers will be directed to this path with ?room=XXXX query parameter.
|
|
130
|
-
* @default "/joypad"
|
|
131
|
-
*/
|
|
132
|
-
controllerPath?: string;
|
|
133
124
|
/**
|
|
134
125
|
* Maximum number of players allowed in a room.
|
|
135
126
|
* @default 8
|
|
@@ -272,7 +263,7 @@ const getEnvApiKey = (): string | undefined => {
|
|
|
272
263
|
* <AirJamProvider>
|
|
273
264
|
* <Routes>
|
|
274
265
|
* <Route path="/" element={<HostView />} />
|
|
275
|
-
* <Route path="/
|
|
266
|
+
* <Route path="/controller" element={<ControllerView />} />
|
|
276
267
|
* </Routes>
|
|
277
268
|
* </AirJamProvider>
|
|
278
269
|
* );
|
|
@@ -309,7 +300,6 @@ export const AirJamProvider = <TSchema extends z.ZodSchema = z.ZodSchema>({
|
|
|
309
300
|
children,
|
|
310
301
|
serverUrl,
|
|
311
302
|
apiKey,
|
|
312
|
-
controllerPath = DEFAULT_CONTROLLER_PATH,
|
|
313
303
|
maxPlayers = DEFAULT_MAX_PLAYERS,
|
|
314
304
|
publicHost,
|
|
315
305
|
input,
|
|
@@ -319,11 +309,10 @@ export const AirJamProvider = <TSchema extends z.ZodSchema = z.ZodSchema>({
|
|
|
319
309
|
() => ({
|
|
320
310
|
serverUrl: serverUrl ?? getEnvServerUrl(),
|
|
321
311
|
apiKey: apiKey ?? getEnvApiKey(),
|
|
322
|
-
controllerPath,
|
|
323
312
|
maxPlayers,
|
|
324
313
|
publicHost,
|
|
325
314
|
}),
|
|
326
|
-
[serverUrl, apiKey,
|
|
315
|
+
[serverUrl, apiKey, maxPlayers, publicHost],
|
|
327
316
|
);
|
|
328
317
|
|
|
329
318
|
// Create InputManager from input config if provided
|
|
@@ -42,7 +42,7 @@ import { detectRunMode } from "../utils/mode";
|
|
|
42
42
|
*
|
|
43
43
|
* @example Basic usage (room from URL)
|
|
44
44
|
* ```tsx
|
|
45
|
-
* // URL: https://yourgame.com/
|
|
45
|
+
* // URL: https://yourgame.com/controller?room=ABCD
|
|
46
46
|
* const controller = useAirJamController();
|
|
47
47
|
* // Automatically joins room ABCD
|
|
48
48
|
* ```
|