@air-jam/sdk 0.1.4 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +627 -57
- package/dist/agent-tooling-BSMGBix9.d.cts +123 -0
- package/dist/agent-tooling-BSMGBix9.d.ts +123 -0
- package/dist/agent-tooling.cjs +83 -0
- package/dist/agent-tooling.cjs.map +1 -0
- package/dist/agent-tooling.d.cts +2 -0
- package/dist/agent-tooling.d.ts +2 -0
- package/dist/agent-tooling.js +17 -0
- package/dist/agent-tooling.js.map +1 -0
- package/dist/arcade/bridge/controller.cjs +749 -0
- package/dist/arcade/bridge/controller.cjs.map +1 -0
- package/dist/arcade/bridge/controller.d.cts +85 -0
- package/dist/arcade/bridge/controller.d.ts +85 -0
- package/dist/arcade/bridge/controller.js +33 -0
- package/dist/arcade/bridge/controller.js.map +1 -0
- package/dist/arcade/bridge/host.cjs +421 -0
- package/dist/arcade/bridge/host.cjs.map +1 -0
- package/dist/arcade/bridge/host.d.cts +73 -0
- package/dist/arcade/bridge/host.d.ts +73 -0
- package/dist/arcade/bridge/host.js +25 -0
- package/dist/arcade/bridge/host.js.map +1 -0
- package/dist/arcade/bridge/iframe.cjs +453 -0
- package/dist/arcade/bridge/iframe.cjs.map +1 -0
- package/dist/arcade/bridge/iframe.d.cts +80 -0
- package/dist/arcade/bridge/iframe.d.ts +80 -0
- package/dist/arcade/bridge/iframe.js +28 -0
- package/dist/arcade/bridge/iframe.js.map +1 -0
- package/dist/arcade/bridge.cjs +1067 -0
- package/dist/arcade/bridge.cjs.map +1 -0
- package/dist/arcade/bridge.d.cts +11 -0
- package/dist/arcade/bridge.d.ts +11 -0
- package/dist/arcade/bridge.js +76 -0
- package/dist/arcade/bridge.js.map +1 -0
- package/dist/arcade/host.cjs +481 -0
- package/dist/arcade/host.cjs.map +1 -0
- package/dist/arcade/host.d.cts +19 -0
- package/dist/arcade/host.d.ts +19 -0
- package/dist/arcade/host.js +14 -0
- package/dist/arcade/host.js.map +1 -0
- package/dist/arcade/surface.cjs +113 -0
- package/dist/arcade/surface.cjs.map +1 -0
- package/dist/arcade/surface.d.cts +14 -0
- package/dist/arcade/surface.d.ts +14 -0
- package/dist/arcade/surface.js +27 -0
- package/dist/arcade/surface.js.map +1 -0
- package/dist/arcade/url.cjs +544 -0
- package/dist/arcade/url.cjs.map +1 -0
- package/dist/arcade/url.d.cts +68 -0
- package/dist/arcade/url.d.ts +68 -0
- package/dist/arcade/url.js +29 -0
- package/dist/arcade/url.js.map +1 -0
- package/dist/arcade-runtime-url-BW-MUAOY.d.cts +28 -0
- package/dist/arcade-runtime-url-l8qj01Pg.d.ts +28 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.cts +16 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.ts +16 -0
- package/dist/arcade.cjs +1737 -0
- package/dist/arcade.cjs.map +1 -0
- package/dist/arcade.d.cts +18 -0
- package/dist/arcade.d.ts +18 -0
- package/dist/arcade.js +123 -0
- package/dist/arcade.js.map +1 -0
- package/dist/capabilities.cjs +39 -0
- package/dist/capabilities.cjs.map +1 -0
- package/dist/capabilities.d.cts +31 -0
- package/dist/capabilities.d.ts +31 -0
- package/dist/capabilities.js +12 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/chunk-32NYL7XI.js +539 -0
- package/dist/chunk-32NYL7XI.js.map +1 -0
- package/dist/chunk-3USU7GY2.js +54 -0
- package/dist/chunk-3USU7GY2.js.map +1 -0
- package/dist/chunk-7UXSWCZZ.js +32 -0
- package/dist/chunk-7UXSWCZZ.js.map +1 -0
- package/dist/chunk-BE6Z4SIT.js +65 -0
- package/dist/chunk-BE6Z4SIT.js.map +1 -0
- package/dist/chunk-CABEUV65.js +184 -0
- package/dist/chunk-CABEUV65.js.map +1 -0
- package/dist/chunk-CEJ5RFSG.js +288 -0
- package/dist/chunk-CEJ5RFSG.js.map +1 -0
- package/dist/chunk-EDRQIOCV.js +25 -0
- package/dist/chunk-EDRQIOCV.js.map +1 -0
- package/dist/chunk-EVZJA6RN.js +140 -0
- package/dist/chunk-EVZJA6RN.js.map +1 -0
- package/dist/chunk-FAT2KJ3K.js +238 -0
- package/dist/chunk-FAT2KJ3K.js.map +1 -0
- package/dist/chunk-IKKDONQL.js +1 -0
- package/dist/chunk-IKKDONQL.js.map +1 -0
- package/dist/chunk-JEHV5C2X.js +249 -0
- package/dist/chunk-JEHV5C2X.js.map +1 -0
- package/dist/chunk-JO2HR5PV.js +43 -0
- package/dist/chunk-JO2HR5PV.js.map +1 -0
- package/dist/chunk-JTF47B56.js +1 -0
- package/dist/chunk-JTF47B56.js.map +1 -0
- package/dist/chunk-KXAFI5OP.js +193 -0
- package/dist/chunk-KXAFI5OP.js.map +1 -0
- package/dist/chunk-LIXPF4P6.js +22 -0
- package/dist/chunk-LIXPF4P6.js.map +1 -0
- package/dist/chunk-MPDMJIX5.js +1 -0
- package/dist/chunk-MPDMJIX5.js.map +1 -0
- package/dist/chunk-NCL6WJCL.js +91 -0
- package/dist/chunk-NCL6WJCL.js.map +1 -0
- package/dist/chunk-NUJBMV3O.js +1435 -0
- package/dist/chunk-NUJBMV3O.js.map +1 -0
- package/dist/chunk-TGRTEWYV.js +195 -0
- package/dist/chunk-TGRTEWYV.js.map +1 -0
- package/dist/chunk-UWJOIVON.js +369 -0
- package/dist/chunk-UWJOIVON.js.map +1 -0
- package/dist/chunk-VKBMZHMQ.js +216 -0
- package/dist/chunk-VKBMZHMQ.js.map +1 -0
- package/dist/chunk-W2VK36RO.js +11 -0
- package/dist/chunk-W2VK36RO.js.map +1 -0
- package/dist/chunk-W3YA5BWR.js +126 -0
- package/dist/chunk-W3YA5BWR.js.map +1 -0
- package/dist/chunk-X24K52DG.js +12 -0
- package/dist/chunk-X24K52DG.js.map +1 -0
- package/dist/chunk-YXHH3MQT.js +230 -0
- package/dist/chunk-YXHH3MQT.js.map +1 -0
- package/dist/chunk-ZLPL2R3R.js +183 -0
- package/dist/chunk-ZLPL2R3R.js.map +1 -0
- package/dist/chunk-ZTQ5SP4H.js +9 -0
- package/dist/chunk-ZTQ5SP4H.js.map +1 -0
- package/dist/controller-Bod8YYr1.d.cts +172 -0
- package/dist/controller-DxVchfiA.d.ts +172 -0
- package/dist/dev-log-events-CVAM29hx.d.cts +123 -0
- package/dist/dev-log-events-CVAM29hx.d.ts +123 -0
- package/dist/handshake-CC_LrK5g.d.cts +31 -0
- package/dist/handshake-CC_LrK5g.d.ts +31 -0
- package/dist/host-8hmq_Sgc.d.cts +109 -0
- package/dist/host-Cw-N6e-5.d.ts +109 -0
- package/dist/index.cjs +8730 -3426
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +676 -1070
- package/dist/index.d.ts +676 -1070
- package/dist/index.js +4892 -3196
- package/dist/index.js.map +1 -1
- package/dist/metadata.cjs +114 -0
- package/dist/metadata.cjs.map +1 -0
- package/dist/metadata.d.cts +95 -0
- package/dist/metadata.d.ts +95 -0
- package/dist/metadata.js +83 -0
- package/dist/metadata.js.map +1 -0
- package/dist/notices-CnGaaS8B.d.ts +38 -0
- package/dist/notices-NyDM5Mtz.d.cts +38 -0
- package/dist/platform-machine.cjs +425 -0
- package/dist/platform-machine.cjs.map +1 -0
- package/dist/platform-machine.d.cts +1183 -0
- package/dist/platform-machine.d.ts +1183 -0
- package/dist/platform-machine.js +309 -0
- package/dist/platform-machine.js.map +1 -0
- package/dist/platform-settings-cuor3i11.d.cts +48 -0
- package/dist/platform-settings-cuor3i11.d.ts +48 -0
- package/dist/prefabs.cjs +36 -0
- package/dist/prefabs.cjs.map +1 -0
- package/dist/prefabs.d.cts +49 -0
- package/dist/prefabs.d.ts +49 -0
- package/dist/prefabs.js +8 -0
- package/dist/prefabs.js.map +1 -0
- package/dist/preview.cjs +2620 -0
- package/dist/preview.cjs.map +1 -0
- package/dist/preview.d.cts +155 -0
- package/dist/preview.d.ts +155 -0
- package/dist/preview.js +1671 -0
- package/dist/preview.js.map +1 -0
- package/dist/protocol.cjs +621 -54
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +76 -240
- package/dist/protocol.d.ts +76 -240
- package/dist/protocol.js +100 -2
- package/dist/protocol.js.map +1 -1
- package/dist/realtime-client-Cu8yVJFw.d.cts +15 -0
- package/dist/realtime-client-Cu8yVJFw.d.ts +15 -0
- package/dist/release.cjs +143 -0
- package/dist/release.cjs.map +1 -0
- package/dist/release.d.cts +64 -0
- package/dist/release.d.ts +64 -0
- package/dist/release.js +43 -0
- package/dist/release.js.map +1 -0
- package/dist/runtime-topology.cjs +405 -0
- package/dist/runtime-topology.cjs.map +1 -0
- package/dist/runtime-topology.d.cts +59 -0
- package/dist/runtime-topology.d.ts +59 -0
- package/dist/runtime-topology.js +31 -0
- package/dist/runtime-topology.js.map +1 -0
- package/dist/standard-match-phase-BucA5dYo.d.ts +44 -0
- package/dist/standard-match-phase-U2ra8J-0.d.cts +44 -0
- package/dist/sync-B6QsNrXz.d.cts +125 -0
- package/dist/sync-B6QsNrXz.d.ts +125 -0
- package/dist/ui.cjs +3061 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.cts +320 -0
- package/dist/ui.d.ts +320 -0
- package/dist/ui.js +1719 -0
- package/dist/ui.js.map +1 -0
- package/dist/url-policy-C89zxgw9.d.cts +9 -0
- package/dist/url-policy-C89zxgw9.d.ts +9 -0
- package/package.json +155 -10
- package/src/agent/agent-action.ts +304 -0
- package/src/agent/agent-contract.ts +180 -0
- package/src/agent-tooling.ts +20 -0
- package/src/arcade/bridge/controller.ts +15 -0
- package/src/arcade/bridge/host.ts +12 -0
- package/src/arcade/bridge/iframe.ts +61 -0
- package/src/arcade/bridge.ts +3 -0
- package/src/arcade/host.ts +1 -0
- package/src/arcade/surface.ts +4 -0
- package/src/arcade/url.ts +60 -0
- package/src/arcade.ts +4 -0
- package/src/audio/audio-manager.ts +162 -171
- package/src/audio/hooks.tsx +218 -97
- package/src/audio/index.ts +1 -1
- package/src/audio/music.tsx +139 -0
- package/src/capabilities/manifest.ts +71 -0
- package/src/capabilities.ts +12 -0
- package/src/components/connection-status-pill.tsx +55 -0
- package/src/components/controller-player-name-field.tsx +119 -0
- package/src/components/controller-primary-action.tsx +58 -0
- package/src/components/host-mute-button.tsx +49 -0
- package/src/components/join-qr-overlay.tsx +133 -0
- package/src/components/join-url-action-buttons.tsx +95 -0
- package/src/components/join-url-controls.tsx +58 -0
- package/src/components/join-url-field.tsx +52 -0
- package/src/components/lifecycle-action-group.tsx +129 -0
- package/src/components/player-avatar-strip.tsx +65 -0
- package/src/components/player-avatar.tsx +42 -13
- package/src/components/room-qr-code.tsx +125 -0
- package/src/components/runtime-shell-header.tsx +37 -0
- package/src/components/shell-classes.ts +19 -0
- package/src/components/surface-orientation-layout.ts +60 -0
- package/src/components/surface-viewport-layout.ts +268 -0
- package/src/components/surface-viewport.tsx +314 -0
- package/src/components/ui/button.tsx +4 -6
- package/src/components/ui/slider.tsx +1 -1
- package/src/components/volume-controls.tsx +65 -6
- package/src/context/air-jam-context.tsx +209 -161
- package/src/context/index.ts +2 -2
- package/src/context/session-providers.tsx +77 -0
- package/src/context/session-scope.ts +64 -0
- package/src/context/socket-manager.ts +6 -24
- package/src/contracts/v2/bridge.ts +261 -0
- package/src/contracts/v2/handshake.ts +40 -0
- package/src/contracts/v2/index.ts +2 -0
- package/src/dev/browser-log-sink.ts +912 -0
- package/src/diagnostics.ts +128 -0
- package/src/events.ts +7 -34
- package/src/hooks/internal/use-controller-runtime-api.ts +875 -0
- package/src/hooks/internal/use-host-runtime-api.ts +1051 -0
- package/src/hooks/internal/use-runtime-control-contract.ts +15 -0
- package/src/hooks/internal/use-runtime-inspection-contract.ts +16 -0
- package/src/hooks/internal/use-runtime-observability-contract.ts +24 -0
- package/src/hooks/use-air-jam-controller.ts +155 -475
- package/src/hooks/use-air-jam-host.ts +156 -485
- package/src/hooks/use-connection-status.ts +8 -0
- package/src/hooks/use-controller-lifecycle-intents.ts +27 -0
- package/src/hooks/use-controller-lifecycle-permissions.ts +36 -0
- package/src/hooks/use-controller-shell-status.ts +40 -0
- package/src/hooks/use-controller-tick.ts +65 -0
- package/src/hooks/use-controller-toasts.ts +116 -0
- package/src/hooks/use-get-input.ts +8 -5
- package/src/hooks/use-host-arcade-restore.ts +30 -0
- package/src/hooks/use-host-join-controls.ts +152 -0
- package/src/hooks/use-host-tick.ts +171 -0
- package/src/hooks/use-input-writer.ts +83 -0
- package/src/hooks/use-lifecycle-action-group-model.ts +98 -0
- package/src/hooks/use-players.ts +12 -0
- package/src/hooks/use-room.ts +22 -0
- package/src/hooks/use-send-signal.ts +6 -2
- package/src/index.ts +205 -31
- package/src/internal/input-manager.ts +195 -215
- package/src/lifecycle/index.ts +9 -0
- package/src/lifecycle/standard-match-phase.ts +32 -0
- package/src/metadata/manifest.ts +152 -0
- package/src/metadata.ts +12 -0
- package/src/platform-machine.ts +475 -0
- package/src/prefabs/types.ts +82 -0
- package/src/prefabs.ts +12 -0
- package/src/preview/host-workspace.tsx +59 -0
- package/src/preview/identity.ts +66 -0
- package/src/preview/layout.ts +223 -0
- package/src/preview/manager.ts +577 -0
- package/src/preview/messages.ts +26 -0
- package/src/preview/ownership.ts +81 -0
- package/src/preview/url.ts +117 -0
- package/src/preview/window.tsx +490 -0
- package/src/preview/workspace.tsx +678 -0
- package/src/preview.ts +42 -0
- package/src/protocol/arcade-platform-actions.ts +29 -0
- package/src/protocol/controller.ts +187 -0
- package/src/protocol/core.ts +23 -0
- package/src/protocol/dev-log-events.ts +222 -0
- package/src/protocol/errors.ts +21 -0
- package/src/protocol/host-grant.ts +185 -0
- package/src/protocol/host.ts +138 -0
- package/src/protocol/notices.ts +43 -0
- package/src/protocol/signals.ts +38 -0
- package/src/protocol/socket-events.ts +154 -0
- package/src/protocol/sync.ts +121 -0
- package/src/protocol/url-policy.ts +63 -0
- package/src/protocol.ts +12 -386
- package/src/qrcode.d.ts +16 -0
- package/src/release.ts +99 -0
- package/src/runtime/air-jam-config.ts +287 -0
- package/src/runtime/air-jam-error-boundary.tsx +672 -0
- package/src/runtime/arcade-bridge-request-surface.ts +15 -0
- package/src/runtime/arcade-runtime-url.ts +95 -0
- package/src/runtime/arcade-surface-identity.ts +16 -0
- package/src/runtime/contracts/control.ts +68 -0
- package/src/runtime/contracts/inspection.ts +165 -0
- package/src/runtime/contracts/observability.ts +94 -0
- package/src/runtime/controller-bridge.ts +451 -0
- package/src/runtime/controller-identity.ts +132 -0
- package/src/runtime/controller-presentation.ts +24 -0
- package/src/runtime/controller-realtime-client.ts +591 -0
- package/src/runtime/create-air-jam-app.tsx +260 -0
- package/src/runtime/dev-runtime-events.ts +36 -0
- package/src/runtime/embedded-runtime-adapters.ts +68 -0
- package/src/runtime/host-bridge.ts +388 -0
- package/src/runtime/host-realtime-client.ts +550 -0
- package/src/runtime/iframe-bridge.ts +135 -0
- package/src/runtime/realtime-client.ts +20 -0
- package/src/runtime/router-basename.ts +25 -0
- package/src/runtime/runtime-owner-contexts.tsx +4 -0
- package/src/runtime/runtime-session-params.ts +169 -0
- package/src/runtime/sdk-version.ts +6 -0
- package/src/runtime/session-runtimes.tsx +188 -0
- package/src/runtime/validate-arcade-bridge-attach.ts +14 -0
- package/src/runtime-control.ts +10 -0
- package/src/runtime-inspection.ts +14 -0
- package/src/runtime-observability.ts +9 -0
- package/src/runtime-topology.ts +569 -0
- package/src/settings/platform-settings-bridge.ts +336 -0
- package/src/settings/platform-settings-runtime.tsx +387 -0
- package/src/settings/platform-settings.ts +288 -0
- package/src/state/connection-store.ts +80 -12
- package/src/store/air-jam-store-domain-constants.ts +4 -0
- package/src/store/create-air-jam-store.ts +1094 -227
- package/src/styles.css +4 -38
- package/src/ui.ts +29 -0
- package/src/utils/is-rpc-serializable.ts +56 -0
- package/src/utils/player-avatar-url.ts +48 -0
- package/src/utils/url-builder.ts +7 -0
- package/dist/.tsbuildinfo +0 -1
- package/dist/chunk-B5DURUWT.js +0 -80
- package/dist/chunk-B5DURUWT.js.map +0 -1
- package/src/AirJamClient.ts +0 -224
- package/src/audio/volume-store.ts +0 -124
- package/src/components/controller-shell.tsx +0 -346
- package/src/components/host-shell.tsx +0 -520
- package/src/components/qr-scanner-dialog.tsx +0 -373
- package/src/components/ui/alert.tsx +0 -66
- package/src/components/ui/avatar.tsx +0 -46
- package/src/components/ui/badge.tsx +0 -47
- package/src/components/ui/card.tsx +0 -92
- package/src/components/ui/dialog.tsx +0 -122
- package/src/components/ui/tabs.tsx +0 -64
- package/src/hooks/use-air-jam-shell.ts +0 -379
- package/src/hooks/use-fullscreen.ts +0 -108
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Howl, Howler } from "howler";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
2
|
+
import type { ConnectionRole } from "../protocol";
|
|
3
|
+
import type { AirJamRealtimeClient } from "../runtime/realtime-client";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_PLATFORM_SETTINGS,
|
|
6
|
+
type PlatformAudioSettings,
|
|
7
|
+
getEffectiveAudioVolume,
|
|
8
|
+
} from "../settings/platform-settings";
|
|
5
9
|
|
|
6
10
|
export type SoundCategory = "music" | "sfx";
|
|
7
11
|
|
|
@@ -9,27 +13,20 @@ export interface SoundConfig {
|
|
|
9
13
|
src: string[];
|
|
10
14
|
volume?: number;
|
|
11
15
|
loop?: boolean;
|
|
12
|
-
html5?: boolean;
|
|
16
|
+
html5?: boolean;
|
|
13
17
|
sprite?: {
|
|
14
18
|
[key: string]: [number, number];
|
|
15
19
|
};
|
|
16
|
-
category?: SoundCategory;
|
|
20
|
+
category?: SoundCategory;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
export type SoundManifest = Record<string, SoundConfig>;
|
|
20
24
|
|
|
21
|
-
/**
|
|
22
|
-
* Auto-detect sound category based on config heuristics
|
|
23
|
-
* - If explicitly set, use it
|
|
24
|
-
* - If loop=true and html5=true, likely music
|
|
25
|
-
* - Otherwise, default to sfx
|
|
26
|
-
*/
|
|
27
25
|
export function detectSoundCategory(config: SoundConfig): SoundCategory {
|
|
28
26
|
if (config.category) {
|
|
29
27
|
return config.category;
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
// Heuristic: loop + html5 typically indicates music
|
|
33
30
|
if (config.loop && config.html5) {
|
|
34
31
|
return "music";
|
|
35
32
|
}
|
|
@@ -38,114 +35,81 @@ export function detectSoundCategory(config: SoundConfig): SoundCategory {
|
|
|
38
35
|
}
|
|
39
36
|
|
|
40
37
|
export interface PlayOptions {
|
|
41
|
-
remote?: boolean;
|
|
42
|
-
target?: string;
|
|
38
|
+
remote?: boolean;
|
|
39
|
+
target?: string;
|
|
43
40
|
volume?: number;
|
|
44
41
|
loop?: boolean;
|
|
45
42
|
sprite?: string;
|
|
46
43
|
pitch?: number;
|
|
44
|
+
fadeInMs?: number;
|
|
45
|
+
onEnd?: (soundId: number) => void;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
export
|
|
48
|
+
export interface AudioHandle<T extends string = string> {
|
|
49
|
+
init(): Promise<boolean>;
|
|
50
|
+
isReady(): boolean;
|
|
51
|
+
play(id: T, options?: PlayOptions): number | null;
|
|
52
|
+
stop(id?: T, soundId?: number): void;
|
|
53
|
+
fadeOutAndStop(id: T, soundId: number, durationMs: number): void;
|
|
54
|
+
mute(muted: boolean, id?: T, soundId?: number): void;
|
|
55
|
+
isMuted(): boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export class AudioManager<T extends string = string> implements AudioHandle<T> {
|
|
50
59
|
private sounds: Map<string, Howl> = new Map();
|
|
51
60
|
private categories: Map<string, SoundCategory> = new Map();
|
|
52
61
|
private manifest: SoundManifest = {};
|
|
53
|
-
private _muted
|
|
54
|
-
private socket:
|
|
55
|
-
null;
|
|
62
|
+
private _muted = false;
|
|
63
|
+
private socket: AirJamRealtimeClient | null = null;
|
|
56
64
|
private roomId: string | null = null;
|
|
65
|
+
private role: ConnectionRole | null = null;
|
|
57
66
|
private activeSoundIds: Map<
|
|
58
67
|
number,
|
|
59
68
|
{ soundId: string; category: SoundCategory }
|
|
60
69
|
> = new Map();
|
|
61
|
-
private
|
|
70
|
+
private audioSettings: PlatformAudioSettings =
|
|
71
|
+
DEFAULT_PLATFORM_SETTINGS.audio;
|
|
62
72
|
|
|
63
73
|
constructor(manifest?: SoundManifest) {
|
|
64
|
-
// Initialize volume store FIRST to ensure values are loaded from localStorage
|
|
65
|
-
// This must happen before loading sounds so they can use the stored volumes
|
|
66
|
-
const initialState = useVolumeStore.getState();
|
|
67
|
-
|
|
68
|
-
// Set up volume change subscription
|
|
69
|
-
const updateAllSounds = (
|
|
70
|
-
state: ReturnType<typeof useVolumeStore.getState>,
|
|
71
|
-
) => {
|
|
72
|
-
// Update all currently playing sounds
|
|
73
|
-
this.activeSoundIds.forEach((info, howlSoundId) => {
|
|
74
|
-
const sound = this.sounds.get(info.soundId);
|
|
75
|
-
if (sound) {
|
|
76
|
-
const config = this.manifest[info.soundId];
|
|
77
|
-
const baseVolume = config?.volume ?? 1.0;
|
|
78
|
-
const effectiveVolume = state.getEffectiveVolume(info.category);
|
|
79
|
-
const finalVolume = baseVolume * effectiveVolume;
|
|
80
|
-
sound.volume(finalVolume, howlSoundId);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Also update the default volume for all loaded sounds (for future plays)
|
|
85
|
-
this.sounds.forEach((sound, soundId) => {
|
|
86
|
-
const category = this.categories.get(soundId) ?? "sfx";
|
|
87
|
-
const config = this.manifest[soundId];
|
|
88
|
-
const baseVolume = config?.volume ?? 1.0;
|
|
89
|
-
const effectiveVolume = state.getEffectiveVolume(category);
|
|
90
|
-
const newVolume = baseVolume * effectiveVolume;
|
|
91
|
-
// Update default volume for the sound
|
|
92
|
-
sound.volume(newVolume);
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// Subscribe to future changes
|
|
97
|
-
this.volumeUnsubscribe = useVolumeStore.subscribe(updateAllSounds);
|
|
98
|
-
|
|
99
|
-
// Now load sounds - they will use the stored volumes from the start
|
|
100
74
|
if (manifest) {
|
|
101
75
|
this.load(manifest);
|
|
102
|
-
// Apply initial volumes to all loaded sounds immediately
|
|
103
|
-
updateAllSounds(initialState);
|
|
104
76
|
}
|
|
105
77
|
}
|
|
106
78
|
|
|
107
|
-
/**
|
|
108
|
-
* Cleanup method to unsubscribe from volume changes
|
|
109
|
-
*/
|
|
110
79
|
public destroy() {
|
|
111
|
-
|
|
112
|
-
this.volumeUnsubscribe();
|
|
113
|
-
this.volumeUnsubscribe = null;
|
|
114
|
-
}
|
|
80
|
+
// No-op for now; retained for cleanup symmetry with other runtime owners.
|
|
115
81
|
}
|
|
116
82
|
|
|
117
|
-
/**
|
|
118
|
-
* Get the category for a sound (with auto-detection)
|
|
119
|
-
*/
|
|
120
83
|
public getCategory(soundId: string): SoundCategory {
|
|
121
84
|
return this.categories.get(soundId) ?? "sfx";
|
|
122
85
|
}
|
|
123
86
|
|
|
124
87
|
public setSocket(
|
|
125
|
-
socket:
|
|
88
|
+
socket: AirJamRealtimeClient | null,
|
|
126
89
|
roomId?: string,
|
|
90
|
+
role?: ConnectionRole,
|
|
127
91
|
) {
|
|
128
92
|
this.socket = socket;
|
|
129
93
|
if (roomId) this.roomId = roomId;
|
|
94
|
+
if (role) this.role = role;
|
|
130
95
|
}
|
|
131
96
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
*
|
|
136
|
-
* Note: Due to browser autoplay policies, audio context starts suspended
|
|
137
|
-
* and can only be resumed in response to a user gesture. The useAudio hook
|
|
138
|
-
* handles this automatically, and play() also calls init() internally.
|
|
139
|
-
*/
|
|
140
|
-
public init() {
|
|
141
|
-
if (Howler.ctx && Howler.ctx.state === "suspended") {
|
|
142
|
-
Howler.ctx.resume();
|
|
97
|
+
public async init(): Promise<boolean> {
|
|
98
|
+
if (!Howler.ctx) {
|
|
99
|
+
return false;
|
|
143
100
|
}
|
|
101
|
+
|
|
102
|
+
if (Howler.ctx.state === "suspended") {
|
|
103
|
+
try {
|
|
104
|
+
await Howler.ctx.resume();
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return Howler.ctx.state === "running";
|
|
144
111
|
}
|
|
145
112
|
|
|
146
|
-
/**
|
|
147
|
-
* Check if audio context is ready to play sounds
|
|
148
|
-
*/
|
|
149
113
|
public isReady(): boolean {
|
|
150
114
|
return Howler.ctx !== null && Howler.ctx.state === "running";
|
|
151
115
|
}
|
|
@@ -153,24 +117,21 @@ export class AudioManager<T extends string = string> {
|
|
|
153
117
|
public load(manifest: SoundManifest) {
|
|
154
118
|
this.manifest = { ...this.manifest, ...manifest };
|
|
155
119
|
|
|
156
|
-
// Get current volume store state to apply to new sounds
|
|
157
|
-
const volumeStore = useVolumeStore.getState();
|
|
158
|
-
|
|
159
120
|
Object.entries(manifest).forEach(([key, config]) => {
|
|
160
121
|
if (this.sounds.has(key)) return;
|
|
161
122
|
|
|
162
|
-
// Detect and store category
|
|
163
123
|
const category = detectSoundCategory(config);
|
|
164
124
|
this.categories.set(key, category);
|
|
165
125
|
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
126
|
+
const baseVolume = config.volume ?? 1;
|
|
127
|
+
const effectiveVolume = getEffectiveAudioVolume(
|
|
128
|
+
this.audioSettings,
|
|
129
|
+
category,
|
|
130
|
+
);
|
|
170
131
|
|
|
171
132
|
const sound = new Howl({
|
|
172
133
|
src: config.src,
|
|
173
|
-
volume:
|
|
134
|
+
volume: baseVolume * effectiveVolume,
|
|
174
135
|
loop: config.loop ?? false,
|
|
175
136
|
html5: config.html5 ?? false,
|
|
176
137
|
sprite: config.sprite,
|
|
@@ -181,6 +142,30 @@ export class AudioManager<T extends string = string> {
|
|
|
181
142
|
});
|
|
182
143
|
}
|
|
183
144
|
|
|
145
|
+
public applyPlatformAudioSettings(settings: PlatformAudioSettings) {
|
|
146
|
+
this.audioSettings = settings;
|
|
147
|
+
|
|
148
|
+
this.activeSoundIds.forEach((info, howlSoundId) => {
|
|
149
|
+
const sound = this.sounds.get(info.soundId);
|
|
150
|
+
if (!sound) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const config = this.manifest[info.soundId];
|
|
155
|
+
const baseVolume = config?.volume ?? 1;
|
|
156
|
+
const effectiveVolume = getEffectiveAudioVolume(settings, info.category);
|
|
157
|
+
sound.volume(baseVolume * effectiveVolume, howlSoundId);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
this.sounds.forEach((sound, soundId) => {
|
|
161
|
+
const category = this.categories.get(soundId) ?? "sfx";
|
|
162
|
+
const config = this.manifest[soundId];
|
|
163
|
+
const baseVolume = config?.volume ?? 1;
|
|
164
|
+
const effectiveVolume = getEffectiveAudioVolume(settings, category);
|
|
165
|
+
sound.volume(baseVolume * effectiveVolume);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
184
169
|
public play(id: T, options?: PlayOptions): number | null {
|
|
185
170
|
const {
|
|
186
171
|
remote = false,
|
|
@@ -189,17 +174,18 @@ export class AudioManager<T extends string = string> {
|
|
|
189
174
|
loop,
|
|
190
175
|
sprite,
|
|
191
176
|
pitch,
|
|
177
|
+
fadeInMs,
|
|
178
|
+
onEnd,
|
|
192
179
|
} = options || {};
|
|
193
180
|
|
|
194
|
-
|
|
195
|
-
this.init();
|
|
181
|
+
void this.init();
|
|
196
182
|
|
|
197
183
|
if (remote) {
|
|
198
184
|
this.playRemote(id, target, volume, loop);
|
|
199
|
-
return null;
|
|
200
|
-
} else {
|
|
201
|
-
return this.playLocal(id, volume, loop, sprite, pitch);
|
|
185
|
+
return null;
|
|
202
186
|
}
|
|
187
|
+
|
|
188
|
+
return this.playLocal(id, volume, loop, sprite, pitch, fadeInMs, onEnd);
|
|
203
189
|
}
|
|
204
190
|
|
|
205
191
|
private playLocal(
|
|
@@ -208,7 +194,13 @@ export class AudioManager<T extends string = string> {
|
|
|
208
194
|
loop?: boolean,
|
|
209
195
|
sprite?: string,
|
|
210
196
|
pitch?: number,
|
|
197
|
+
fadeInMs?: number,
|
|
198
|
+
onEnd?: (soundId: number) => void,
|
|
211
199
|
): number | null {
|
|
200
|
+
if (!this.isReady()) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
|
|
212
204
|
const sound = this.sounds.get(id);
|
|
213
205
|
if (!sound) {
|
|
214
206
|
console.warn(`Sound "${id}" not found`);
|
|
@@ -217,31 +209,34 @@ export class AudioManager<T extends string = string> {
|
|
|
217
209
|
|
|
218
210
|
const category = this.getCategory(id);
|
|
219
211
|
const config = this.manifest[id];
|
|
220
|
-
const baseVolume = config?.volume ?? 1
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
// Calculate final volume BEFORE playing
|
|
212
|
+
const baseVolume = config?.volume ?? 1;
|
|
213
|
+
const effectiveVolume = getEffectiveAudioVolume(
|
|
214
|
+
this.audioSettings,
|
|
215
|
+
category,
|
|
216
|
+
);
|
|
227
217
|
const finalVolume =
|
|
228
218
|
volume !== undefined
|
|
229
219
|
? volume * effectiveVolume
|
|
230
220
|
: baseVolume * effectiveVolume;
|
|
231
221
|
|
|
232
|
-
// Play the sound
|
|
233
222
|
const soundId = sound.play(sprite);
|
|
234
|
-
|
|
235
|
-
// Store active sound ID for volume updates (do this before setting volume)
|
|
236
223
|
this.activeSoundIds.set(soundId, { soundId: id, category });
|
|
237
224
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
225
|
+
sound.once(
|
|
226
|
+
"end",
|
|
227
|
+
() => {
|
|
228
|
+
this.activeSoundIds.delete(soundId);
|
|
229
|
+
onEnd?.(soundId);
|
|
230
|
+
},
|
|
231
|
+
soundId,
|
|
232
|
+
);
|
|
242
233
|
|
|
243
|
-
|
|
244
|
-
|
|
234
|
+
if (fadeInMs && fadeInMs > 0) {
|
|
235
|
+
sound.volume(0, soundId);
|
|
236
|
+
sound.fade(0, finalVolume, fadeInMs, soundId);
|
|
237
|
+
} else {
|
|
238
|
+
sound.volume(finalVolume, soundId);
|
|
239
|
+
}
|
|
245
240
|
|
|
246
241
|
if (loop !== undefined) sound.loop(loop, soundId);
|
|
247
242
|
if (pitch !== undefined) sound.rate(pitch, soundId);
|
|
@@ -258,61 +253,40 @@ export class AudioManager<T extends string = string> {
|
|
|
258
253
|
if (!this.socket || !this.roomId) return;
|
|
259
254
|
|
|
260
255
|
if (this.isHost()) {
|
|
261
|
-
// Host -> Controller(s)
|
|
262
256
|
this.socket.emit("host:play_sound", {
|
|
263
257
|
roomId: this.roomId,
|
|
264
|
-
targetControllerId: target,
|
|
265
|
-
soundId: id,
|
|
266
|
-
volume,
|
|
267
|
-
loop,
|
|
268
|
-
});
|
|
269
|
-
} else {
|
|
270
|
-
// Controller -> Host
|
|
271
|
-
this.socket.emit("controller:play_sound", {
|
|
272
|
-
roomId: this.roomId,
|
|
258
|
+
targetControllerId: target,
|
|
273
259
|
soundId: id,
|
|
274
260
|
volume,
|
|
275
261
|
loop,
|
|
276
262
|
});
|
|
263
|
+
return;
|
|
277
264
|
}
|
|
265
|
+
|
|
266
|
+
this.socket.emit("controller:play_sound", {
|
|
267
|
+
roomId: this.roomId,
|
|
268
|
+
soundId: id,
|
|
269
|
+
volume,
|
|
270
|
+
loop,
|
|
271
|
+
});
|
|
278
272
|
}
|
|
279
273
|
|
|
280
274
|
private isHost(): boolean {
|
|
281
|
-
|
|
282
|
-
// Or we can just check if we are running in a browser environment that looks like host?
|
|
283
|
-
// Better: The socket instance usually has query params or we can pass a flag.
|
|
284
|
-
// For now, let's assume if we are calling playRemote with a target, we are likely host.
|
|
285
|
-
// Actually, we can just rely on the fact that `host:play_sound` is only available on Host socket type?
|
|
286
|
-
// No, both share types.
|
|
287
|
-
|
|
288
|
-
// Let's add a role property to AudioManager or infer from socket.
|
|
289
|
-
const query = this.socket?.io?.opts?.query;
|
|
290
|
-
return (
|
|
291
|
-
(query &&
|
|
292
|
-
typeof query === "object" &&
|
|
293
|
-
"role" in query &&
|
|
294
|
-
query.role === "host") ||
|
|
295
|
-
false
|
|
296
|
-
);
|
|
275
|
+
return this.role === "host";
|
|
297
276
|
}
|
|
298
277
|
|
|
299
|
-
/**
|
|
300
|
-
* Play a sound at a specific 3D position
|
|
301
|
-
*/
|
|
302
278
|
public playSpatial(
|
|
303
279
|
id: T,
|
|
304
280
|
pos: { x: number; y: number; z: number },
|
|
305
281
|
sprite?: string,
|
|
306
282
|
): number | null {
|
|
307
|
-
|
|
308
|
-
this.init();
|
|
283
|
+
void this.init();
|
|
309
284
|
|
|
310
285
|
const soundId = this.playLocal(id, undefined, undefined, sprite);
|
|
311
286
|
if (soundId !== null) {
|
|
312
287
|
const sound = this.sounds.get(id);
|
|
313
288
|
if (sound) {
|
|
314
289
|
sound.pos(pos.x, pos.y, pos.z, soundId);
|
|
315
|
-
// Enable 3D spatialization for this sound instance
|
|
316
290
|
sound.pannerAttr(
|
|
317
291
|
{
|
|
318
292
|
panningModel: "HRTF",
|
|
@@ -332,63 +306,84 @@ export class AudioManager<T extends string = string> {
|
|
|
332
306
|
if (id) {
|
|
333
307
|
const sound = this.sounds.get(id);
|
|
334
308
|
sound?.stop(soundId);
|
|
335
|
-
// Clean up active sound tracking
|
|
336
309
|
if (soundId !== undefined) {
|
|
337
310
|
this.activeSoundIds.delete(soundId);
|
|
338
311
|
} else {
|
|
339
|
-
// Remove all instances of this sound
|
|
340
312
|
this.activeSoundIds.forEach((info, howlSoundId) => {
|
|
341
313
|
if (info.soundId === id) {
|
|
342
314
|
this.activeSoundIds.delete(howlSoundId);
|
|
343
315
|
}
|
|
344
316
|
});
|
|
345
317
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
Howler.stop();
|
|
322
|
+
this.activeSoundIds.clear();
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
public fadeOutAndStop(id: T, soundId: number, durationMs: number) {
|
|
326
|
+
const sound = this.sounds.get(id);
|
|
327
|
+
if (!sound) {
|
|
328
|
+
this.activeSoundIds.delete(soundId);
|
|
329
|
+
return;
|
|
350
330
|
}
|
|
331
|
+
|
|
332
|
+
if (durationMs <= 0) {
|
|
333
|
+
sound.stop(soundId);
|
|
334
|
+
this.activeSoundIds.delete(soundId);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const config = this.manifest[id];
|
|
339
|
+
const category = this.getCategory(id);
|
|
340
|
+
const fromVolume =
|
|
341
|
+
(config?.volume ?? 1) *
|
|
342
|
+
getEffectiveAudioVolume(this.audioSettings, category);
|
|
343
|
+
|
|
344
|
+
sound.fade(fromVolume, 0, durationMs, soundId);
|
|
345
|
+
globalThis.setTimeout(() => {
|
|
346
|
+
sound.stop(soundId);
|
|
347
|
+
this.activeSoundIds.delete(soundId);
|
|
348
|
+
}, durationMs);
|
|
351
349
|
}
|
|
352
350
|
|
|
353
351
|
public volume(vol: number, id?: T, soundId?: number) {
|
|
354
352
|
if (id) {
|
|
355
353
|
const sound = this.sounds.get(id);
|
|
356
|
-
if (sound) {
|
|
357
|
-
|
|
358
|
-
sound.volume(vol, soundId);
|
|
359
|
-
} else {
|
|
360
|
-
sound.volume(vol);
|
|
361
|
-
}
|
|
354
|
+
if (!sound) {
|
|
355
|
+
return;
|
|
362
356
|
}
|
|
363
|
-
|
|
364
|
-
|
|
357
|
+
if (soundId !== undefined) {
|
|
358
|
+
sound.volume(vol, soundId);
|
|
359
|
+
} else {
|
|
360
|
+
sound.volume(vol);
|
|
361
|
+
}
|
|
362
|
+
return;
|
|
365
363
|
}
|
|
364
|
+
|
|
365
|
+
Howler.volume(vol);
|
|
366
366
|
}
|
|
367
367
|
|
|
368
368
|
public mute(muted: boolean, id?: T, soundId?: number) {
|
|
369
369
|
if (id) {
|
|
370
370
|
const sound = this.sounds.get(id);
|
|
371
371
|
sound?.mute(muted, soundId);
|
|
372
|
-
|
|
373
|
-
this._muted = muted;
|
|
374
|
-
Howler.mute(muted);
|
|
372
|
+
return;
|
|
375
373
|
}
|
|
374
|
+
|
|
375
|
+
this._muted = muted;
|
|
376
|
+
Howler.mute(muted);
|
|
376
377
|
}
|
|
377
378
|
|
|
378
379
|
public isMuted(): boolean {
|
|
379
380
|
return this._muted;
|
|
380
381
|
}
|
|
381
382
|
|
|
382
|
-
/**
|
|
383
|
-
* Update the listener position for spatial audio
|
|
384
|
-
*/
|
|
385
383
|
public setListenerPos(x: number, y: number, z: number) {
|
|
386
384
|
Howler.pos(x, y, z);
|
|
387
385
|
}
|
|
388
386
|
|
|
389
|
-
/**
|
|
390
|
-
* Update the listener orientation for spatial audio
|
|
391
|
-
*/
|
|
392
387
|
public setListenerOrientation(
|
|
393
388
|
x: number,
|
|
394
389
|
y: number,
|
|
@@ -400,7 +395,3 @@ export class AudioManager<T extends string = string> {
|
|
|
400
395
|
Howler.orientation(x, y, z, xUp, yUp, zUp);
|
|
401
396
|
}
|
|
402
397
|
}
|
|
403
|
-
|
|
404
|
-
export const createAudioManager = <T extends string = string>(
|
|
405
|
-
manifest?: SoundManifest,
|
|
406
|
-
) => new AudioManager<T>(manifest);
|