@air-jam/sdk 0.9.1 → 0.9.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/arcade/bridge/controller.cjs +1 -1
- package/dist/arcade/bridge/controller.js +2 -2
- package/dist/arcade/bridge/host.cjs +1 -1
- package/dist/arcade/bridge/host.js +2 -2
- package/dist/arcade/bridge/iframe.cjs +1 -1
- package/dist/arcade/bridge/iframe.js +3 -3
- package/dist/arcade/bridge.cjs +1 -1
- package/dist/arcade/bridge.js +5 -5
- package/dist/arcade.cjs +1 -1
- package/dist/arcade.js +5 -5
- package/dist/{chunk-KXAFI5OP.js → chunk-6CMB356F.js} +2 -2
- package/dist/{chunk-FAT2KJ3K.js → chunk-7OTQTT6H.js} +2 -2
- package/dist/{chunk-CABEUV65.js → chunk-CVYR5RJT.js} +2 -2
- package/dist/{chunk-JEHV5C2X.js → chunk-DY67S3LR.js} +2 -2
- package/dist/{chunk-W3YA5BWR.js → chunk-E5PVHEAX.js} +2 -2
- package/dist/{chunk-VKBMZHMQ.js → chunk-KOB73SPD.js} +2 -2
- package/dist/{chunk-7UXSWCZZ.js → chunk-M4DKOI42.js} +2 -2
- package/dist/{chunk-CEJ5RFSG.js → chunk-Q4UALQO4.js} +2 -2
- package/dist/index.cjs +172 -100
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +160 -89
- package/dist/index.js.map +1 -1
- package/dist/preview.js +4 -4
- package/dist/ui.cjs +95 -18
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.cts +11 -1
- package/dist/ui.d.ts +11 -1
- package/dist/ui.js +106 -29
- package/dist/ui.js.map +1 -1
- package/package.json +1 -1
- package/src/components/join-qr-overlay.tsx +115 -31
- package/src/hooks/use-host-audio-mute-preference.ts +99 -0
- package/src/index.ts +4 -0
- /package/dist/{chunk-KXAFI5OP.js.map → chunk-6CMB356F.js.map} +0 -0
- /package/dist/{chunk-FAT2KJ3K.js.map → chunk-7OTQTT6H.js.map} +0 -0
- /package/dist/{chunk-CABEUV65.js.map → chunk-CVYR5RJT.js.map} +0 -0
- /package/dist/{chunk-JEHV5C2X.js.map → chunk-DY67S3LR.js.map} +0 -0
- /package/dist/{chunk-W3YA5BWR.js.map → chunk-E5PVHEAX.js.map} +0 -0
- /package/dist/{chunk-VKBMZHMQ.js.map → chunk-KOB73SPD.js.map} +0 -0
- /package/dist/{chunk-7UXSWCZZ.js.map → chunk-M4DKOI42.js.map} +0 -0
- /package/dist/{chunk-CEJ5RFSG.js.map → chunk-Q4UALQO4.js.map} +0 -0
|
@@ -1,39 +1,60 @@
|
|
|
1
|
-
import { useEffect, type JSX, type MouseEvent } from "react";
|
|
1
|
+
import { useEffect, useState, type JSX, type MouseEvent } from "react";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
2
3
|
import { cn } from "../utils/cn";
|
|
3
4
|
import { RoomQrCode } from "./room-qr-code";
|
|
4
|
-
import {
|
|
5
|
-
shellPanelClassName,
|
|
6
|
-
shellUtilityButtonClassName,
|
|
7
|
-
} from "./shell-classes";
|
|
5
|
+
import { shellUtilityButtonClassName } from "./shell-classes";
|
|
8
6
|
import { Button } from "./ui/button";
|
|
9
7
|
|
|
10
8
|
export interface JoinQrOverlayProps {
|
|
11
9
|
open: boolean;
|
|
12
10
|
value: string | null | undefined;
|
|
11
|
+
status?: "ready" | "loading" | "unavailable";
|
|
13
12
|
roomId?: string | null;
|
|
14
13
|
onClose?: () => void;
|
|
15
14
|
title?: string;
|
|
15
|
+
roomLabel?: string;
|
|
16
16
|
description?: string;
|
|
17
|
+
unavailableLabel?: string;
|
|
18
|
+
loadingLabel?: string;
|
|
19
|
+
qrAlt?: string;
|
|
20
|
+
showCloseButton?: boolean;
|
|
17
21
|
className?: string;
|
|
18
22
|
panelClassName?: string;
|
|
19
23
|
qrClassName?: string;
|
|
24
|
+
bodyClassName?: string;
|
|
25
|
+
messageClassName?: string;
|
|
26
|
+
descriptionClassName?: string;
|
|
27
|
+
closeButtonClassName?: string;
|
|
20
28
|
size?: number;
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
export const JoinQrOverlay = ({
|
|
24
32
|
open,
|
|
25
33
|
value,
|
|
34
|
+
status = "ready",
|
|
26
35
|
roomId,
|
|
27
36
|
onClose,
|
|
28
|
-
title = "Scan to join",
|
|
37
|
+
title = "Scan QR code to join as a controller",
|
|
38
|
+
roomLabel = "Join room",
|
|
29
39
|
description = "Scan with your phone to connect as a controller.",
|
|
40
|
+
unavailableLabel = "Join URL unavailable right now.",
|
|
41
|
+
loadingLabel = "Preparing join QR…",
|
|
42
|
+
qrAlt,
|
|
43
|
+
showCloseButton = false,
|
|
30
44
|
className,
|
|
31
45
|
panelClassName,
|
|
32
46
|
qrClassName,
|
|
33
|
-
|
|
47
|
+
bodyClassName,
|
|
48
|
+
messageClassName,
|
|
49
|
+
descriptionClassName,
|
|
50
|
+
closeButtonClassName,
|
|
51
|
+
size = 260,
|
|
34
52
|
}: JoinQrOverlayProps): JSX.Element | null => {
|
|
35
53
|
const joinUrlValue = value?.trim() ?? "";
|
|
36
|
-
const
|
|
54
|
+
const effectiveStatus =
|
|
55
|
+
status === "ready" && joinUrlValue.length === 0 ? "unavailable" : status;
|
|
56
|
+
const overlaySize = `min(72vw, ${size}px)`;
|
|
57
|
+
const [entered, setEntered] = useState(false);
|
|
37
58
|
|
|
38
59
|
useEffect(() => {
|
|
39
60
|
if (!open || typeof window === "undefined") {
|
|
@@ -52,6 +73,22 @@ export const JoinQrOverlay = ({
|
|
|
52
73
|
};
|
|
53
74
|
}, [onClose, open]);
|
|
54
75
|
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!open || typeof window === "undefined") {
|
|
78
|
+
setEntered(false);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setEntered(false);
|
|
83
|
+
const frame = window.requestAnimationFrame(() => {
|
|
84
|
+
setEntered(true);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return () => {
|
|
88
|
+
window.cancelAnimationFrame(frame);
|
|
89
|
+
};
|
|
90
|
+
}, [open]);
|
|
91
|
+
|
|
55
92
|
if (!open) {
|
|
56
93
|
return null;
|
|
57
94
|
}
|
|
@@ -60,74 +97,121 @@ export const JoinQrOverlay = ({
|
|
|
60
97
|
event.stopPropagation();
|
|
61
98
|
};
|
|
62
99
|
|
|
63
|
-
|
|
100
|
+
const dialog = (
|
|
64
101
|
<div
|
|
65
102
|
role="dialog"
|
|
66
103
|
aria-modal="true"
|
|
67
104
|
aria-label={roomId ? `Join room ${roomId}` : title}
|
|
68
105
|
className={cn(
|
|
69
|
-
"
|
|
106
|
+
"pointer-events-auto fixed inset-0 z-[120] flex cursor-pointer flex-col items-center justify-center bg-black/85 px-6 backdrop-blur-md transition-opacity duration-200 ease-out",
|
|
107
|
+
entered ? "opacity-100" : "opacity-0",
|
|
70
108
|
className,
|
|
71
109
|
)}
|
|
72
110
|
onClick={onClose}
|
|
73
111
|
>
|
|
74
112
|
<div
|
|
75
113
|
className={cn(
|
|
76
|
-
"flex
|
|
77
|
-
|
|
114
|
+
"flex cursor-default flex-col items-center gap-6 text-center transition-transform duration-200 ease-out",
|
|
115
|
+
entered ? "translate-y-0" : "-translate-y-4",
|
|
78
116
|
panelClassName,
|
|
79
117
|
)}
|
|
80
118
|
onClick={handlePanelClick}
|
|
81
119
|
>
|
|
82
120
|
<div className="space-y-1">
|
|
83
|
-
<p className="text-[
|
|
84
|
-
{
|
|
121
|
+
<p className="text-[11px] tracking-[0.18em] text-slate-400 uppercase">
|
|
122
|
+
{roomLabel}
|
|
85
123
|
</p>
|
|
86
124
|
{roomId ? (
|
|
87
|
-
<p className="text-
|
|
125
|
+
<p className="text-2xl font-semibold tracking-tight text-white tabular-nums">
|
|
88
126
|
{roomId}
|
|
89
127
|
</p>
|
|
90
128
|
) : null}
|
|
91
129
|
</div>
|
|
92
130
|
|
|
93
|
-
{
|
|
131
|
+
{effectiveStatus === "loading" ? (
|
|
132
|
+
<div
|
|
133
|
+
className={cn(
|
|
134
|
+
"flex flex-col items-center justify-center gap-3 rounded-lg border border-white/25 bg-white/6 px-5 py-10 text-sm text-white/70 shadow-sm",
|
|
135
|
+
bodyClassName,
|
|
136
|
+
)}
|
|
137
|
+
style={{
|
|
138
|
+
width: overlaySize,
|
|
139
|
+
height: "auto",
|
|
140
|
+
aspectRatio: "1 / 1",
|
|
141
|
+
}}
|
|
142
|
+
>
|
|
143
|
+
<span className="h-8 w-8 animate-spin rounded-full border-2 border-white/15 border-t-white/85" />
|
|
144
|
+
<span>{loadingLabel}</span>
|
|
145
|
+
</div>
|
|
146
|
+
) : effectiveStatus === "ready" ? (
|
|
94
147
|
<RoomQrCode
|
|
95
148
|
value={joinUrlValue}
|
|
96
149
|
size={size}
|
|
97
150
|
padding={2}
|
|
98
151
|
foregroundColor="#111827"
|
|
99
152
|
backgroundColor="#ffffff"
|
|
100
|
-
className={cn(
|
|
153
|
+
className={cn(
|
|
154
|
+
"rounded-lg border border-white/25 bg-white/6 shadow-sm",
|
|
155
|
+
qrClassName,
|
|
156
|
+
)}
|
|
101
157
|
style={{
|
|
102
|
-
width:
|
|
158
|
+
width: overlaySize,
|
|
103
159
|
height: "auto",
|
|
104
160
|
aspectRatio: "1 / 1",
|
|
105
161
|
}}
|
|
106
162
|
alt={
|
|
107
|
-
|
|
163
|
+
qrAlt ??
|
|
164
|
+
(roomId
|
|
108
165
|
? `QR code to join room ${roomId}`
|
|
109
|
-
: "QR code to join as a controller"
|
|
166
|
+
: "QR code to join as a controller")
|
|
110
167
|
}
|
|
111
168
|
/>
|
|
112
169
|
) : (
|
|
113
|
-
<div
|
|
114
|
-
|
|
170
|
+
<div
|
|
171
|
+
className={cn(
|
|
172
|
+
"flex items-center justify-center rounded-lg border border-white/25 bg-white/6 px-5 py-10 text-sm text-white/70 shadow-sm",
|
|
173
|
+
messageClassName,
|
|
174
|
+
)}
|
|
175
|
+
style={{
|
|
176
|
+
width: overlaySize,
|
|
177
|
+
height: "auto",
|
|
178
|
+
aspectRatio: "1 / 1",
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
{unavailableLabel}
|
|
115
182
|
</div>
|
|
116
183
|
)}
|
|
117
184
|
|
|
118
|
-
<p
|
|
185
|
+
<p
|
|
186
|
+
className={cn(
|
|
187
|
+
"max-w-xs text-center text-sm text-slate-400",
|
|
188
|
+
descriptionClassName,
|
|
189
|
+
)}
|
|
190
|
+
>
|
|
119
191
|
{description}
|
|
120
192
|
</p>
|
|
121
193
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
194
|
+
{showCloseButton ? (
|
|
195
|
+
<Button
|
|
196
|
+
type="button"
|
|
197
|
+
variant="outline"
|
|
198
|
+
onClick={onClose}
|
|
199
|
+
className={cn(
|
|
200
|
+
"rounded-2xl px-5",
|
|
201
|
+
shellUtilityButtonClassName,
|
|
202
|
+
closeButtonClassName,
|
|
203
|
+
)}
|
|
204
|
+
>
|
|
205
|
+
Close
|
|
206
|
+
</Button>
|
|
207
|
+
) : null}
|
|
130
208
|
</div>
|
|
131
209
|
</div>
|
|
132
210
|
);
|
|
211
|
+
|
|
212
|
+
if (typeof document === "undefined") {
|
|
213
|
+
return dialog;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return createPortal(dialog, document.body);
|
|
133
217
|
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
|
|
3
|
+
const HOST_AUDIO_MUTE_STORAGE_KEY_PREFIX = "air-jam-host-audio-muted:";
|
|
4
|
+
|
|
5
|
+
const getHostAudioMuteStorageKey = (scope: string): string =>
|
|
6
|
+
`${HOST_AUDIO_MUTE_STORAGE_KEY_PREFIX}${scope}`;
|
|
7
|
+
|
|
8
|
+
const readHostAudioMutePreference = (
|
|
9
|
+
storageKey: string,
|
|
10
|
+
fallback: boolean,
|
|
11
|
+
): boolean => {
|
|
12
|
+
if (typeof window === "undefined") {
|
|
13
|
+
return fallback;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const raw = window.localStorage.getItem(storageKey);
|
|
17
|
+
if (raw === "true") {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (raw === "false") {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return fallback;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const persistHostAudioMutePreference = (
|
|
27
|
+
storageKey: string,
|
|
28
|
+
muted: boolean,
|
|
29
|
+
): void => {
|
|
30
|
+
if (typeof window === "undefined") {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
window.localStorage.setItem(storageKey, muted ? "true" : "false");
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export interface HostAudioMutePreference {
|
|
38
|
+
muted: boolean;
|
|
39
|
+
setMuted: (muted: boolean) => void;
|
|
40
|
+
toggleMuted: () => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const useHostAudioMutePreference = (
|
|
44
|
+
scope: string,
|
|
45
|
+
defaultMuted = false,
|
|
46
|
+
): HostAudioMutePreference => {
|
|
47
|
+
const storageKey = useMemo(() => getHostAudioMuteStorageKey(scope), [scope]);
|
|
48
|
+
const [muted, setMutedState] = useState<boolean>(() =>
|
|
49
|
+
readHostAudioMutePreference(storageKey, defaultMuted),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
setMutedState(readHostAudioMutePreference(storageKey, defaultMuted));
|
|
54
|
+
}, [defaultMuted, storageKey]);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (typeof window === "undefined") {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const handleStorage = (event: StorageEvent) => {
|
|
62
|
+
if (event.storageArea !== window.localStorage) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (event.key !== storageKey) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
setMutedState(readHostAudioMutePreference(storageKey, defaultMuted));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
window.addEventListener("storage", handleStorage);
|
|
73
|
+
return () => {
|
|
74
|
+
window.removeEventListener("storage", handleStorage);
|
|
75
|
+
};
|
|
76
|
+
}, [defaultMuted, storageKey]);
|
|
77
|
+
|
|
78
|
+
const setMuted = useCallback(
|
|
79
|
+
(nextMuted: boolean) => {
|
|
80
|
+
setMutedState(nextMuted);
|
|
81
|
+
persistHostAudioMutePreference(storageKey, nextMuted);
|
|
82
|
+
},
|
|
83
|
+
[storageKey],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const toggleMuted = useCallback(() => {
|
|
87
|
+
setMutedState((current) => {
|
|
88
|
+
const nextMuted = !current;
|
|
89
|
+
persistHostAudioMutePreference(storageKey, nextMuted);
|
|
90
|
+
return nextMuted;
|
|
91
|
+
});
|
|
92
|
+
}, [storageKey]);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
muted,
|
|
96
|
+
setMuted,
|
|
97
|
+
toggleMuted,
|
|
98
|
+
};
|
|
99
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -90,6 +90,10 @@ export {
|
|
|
90
90
|
type HostTickInfo,
|
|
91
91
|
type HostTickOptions,
|
|
92
92
|
} from "./hooks/use-host-tick";
|
|
93
|
+
export {
|
|
94
|
+
useHostAudioMutePreference,
|
|
95
|
+
type HostAudioMutePreference,
|
|
96
|
+
} from "./hooks/use-host-audio-mute-preference";
|
|
93
97
|
export { useInputWriter } from "./hooks/use-input-writer";
|
|
94
98
|
export { usePlayers } from "./hooks/use-players";
|
|
95
99
|
export { useRoom, type RoomState } from "./hooks/use-room";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|