@air-jam/sdk 0.1.3 → 0.9.0
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 +488 -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 +13 -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 +363 -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 +28 -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 +1565 -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 +122 -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-2432OL7L.js +193 -0
- package/dist/chunk-2432OL7L.js.map +1 -0
- package/dist/chunk-2J65FXEP.js +41 -0
- package/dist/chunk-2J65FXEP.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-BE6Z4SIT.js +65 -0
- package/dist/chunk-BE6Z4SIT.js.map +1 -0
- package/dist/chunk-CQUG24WX.js +249 -0
- package/dist/chunk-CQUG24WX.js.map +1 -0
- package/dist/chunk-D3X4MN4U.js +288 -0
- package/dist/chunk-D3X4MN4U.js.map +1 -0
- package/dist/chunk-EVZJA6RN.js +140 -0
- package/dist/chunk-EVZJA6RN.js.map +1 -0
- package/dist/chunk-HFWRZVZ3.js +1438 -0
- package/dist/chunk-HFWRZVZ3.js.map +1 -0
- package/dist/chunk-IKKDONQL.js +1 -0
- package/dist/chunk-IKKDONQL.js.map +1 -0
- package/dist/chunk-JTF47B56.js +1 -0
- package/dist/chunk-JTF47B56.js.map +1 -0
- package/dist/chunk-LIXPF4P6.js +22 -0
- package/dist/chunk-LIXPF4P6.js.map +1 -0
- package/dist/chunk-MKBASO6X.js +216 -0
- package/dist/chunk-MKBASO6X.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-NU5W6VAV.js +126 -0
- package/dist/chunk-NU5W6VAV.js.map +1 -0
- package/dist/chunk-TGRTEWYV.js +195 -0
- package/dist/chunk-TGRTEWYV.js.map +1 -0
- package/dist/chunk-VDRNNGHX.js +184 -0
- package/dist/chunk-VDRNNGHX.js.map +1 -0
- package/dist/chunk-VN5LDWVN.js +32 -0
- package/dist/chunk-VN5LDWVN.js.map +1 -0
- package/dist/chunk-W2VK36RO.js +11 -0
- package/dist/chunk-W2VK36RO.js.map +1 -0
- package/dist/chunk-X24K52DG.js +12 -0
- package/dist/chunk-X24K52DG.js.map +1 -0
- package/dist/chunk-XLUWV45V.js +25 -0
- package/dist/chunk-XLUWV45V.js.map +1 -0
- package/dist/chunk-Y4RAPKKB.js +238 -0
- package/dist/chunk-Y4RAPKKB.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 +8512 -3518
- 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 -3188
- 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 +2609 -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/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 +2827 -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 +1718 -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 +154 -13
- 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 -14
- 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 -141
- 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 -25
- 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/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 -521
- 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
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CONTROLLER_PATH,
|
|
3
|
+
DEFAULT_SERVER_PORT
|
|
4
|
+
} from "./chunk-W2VK36RO.js";
|
|
5
|
+
|
|
6
|
+
// src/utils/network-ip.ts
|
|
7
|
+
var isVirtualNetwork = (ip) => {
|
|
8
|
+
if (ip.startsWith("192.168.64.") || ip.startsWith("192.168.65.")) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (ip.startsWith("172.17.")) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (ip.startsWith("172.18.") || ip.startsWith("172.19.")) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (ip.startsWith("169.254.")) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
var scoreIp = (ip) => {
|
|
23
|
+
if (ip.startsWith("192.168.")) {
|
|
24
|
+
const parts = ip.split(".");
|
|
25
|
+
const thirdOctet = parseInt(parts[2] || "0", 10);
|
|
26
|
+
if (thirdOctet < 64) {
|
|
27
|
+
return 100 - thirdOctet;
|
|
28
|
+
}
|
|
29
|
+
return 10;
|
|
30
|
+
}
|
|
31
|
+
if (ip.startsWith("10.")) {
|
|
32
|
+
return 50;
|
|
33
|
+
}
|
|
34
|
+
if (/^172\.(1[6-9]|2[0-9]|3[01])\./.test(ip)) {
|
|
35
|
+
return 30;
|
|
36
|
+
}
|
|
37
|
+
return 0;
|
|
38
|
+
};
|
|
39
|
+
var getLocalNetworkIp = () => {
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
if (typeof window === "undefined" || typeof RTCPeerConnection === "undefined") {
|
|
42
|
+
resolve(null);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const pc = new RTCPeerConnection({
|
|
46
|
+
iceServers: [{ urls: "stun:stun.l.google.com:19302" }]
|
|
47
|
+
});
|
|
48
|
+
const candidates = [];
|
|
49
|
+
let candidateGatheringComplete = false;
|
|
50
|
+
const resolveOnce = (ip) => {
|
|
51
|
+
pc.close();
|
|
52
|
+
resolve(ip);
|
|
53
|
+
};
|
|
54
|
+
const timeout = setTimeout(() => {
|
|
55
|
+
if (candidateGatheringComplete) {
|
|
56
|
+
pickBestCandidate();
|
|
57
|
+
} else {
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
pickBestCandidate();
|
|
60
|
+
}, 500);
|
|
61
|
+
}
|
|
62
|
+
}, 3e3);
|
|
63
|
+
const pickBestCandidate = () => {
|
|
64
|
+
if (candidates.length === 0) {
|
|
65
|
+
resolveOnce(null);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
candidates.sort((a, b) => b.score - a.score);
|
|
69
|
+
const best = candidates[0];
|
|
70
|
+
clearTimeout(timeout);
|
|
71
|
+
resolveOnce(best.ip);
|
|
72
|
+
};
|
|
73
|
+
pc.onicecandidate = (event) => {
|
|
74
|
+
if (event.candidate) {
|
|
75
|
+
const candidate = event.candidate.candidate;
|
|
76
|
+
const match = candidate.match(/([0-9]{1,3}(\.[0-9]{1,3}){3})/);
|
|
77
|
+
if (match) {
|
|
78
|
+
const ip = match[1];
|
|
79
|
+
if (ip === "127.0.0.1") {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const isPrivate = ip.startsWith("192.168.") || ip.startsWith("10.") || /^172\.(1[6-9]|2[0-9]|3[01])\./.test(ip);
|
|
83
|
+
if (isPrivate && !isVirtualNetwork(ip)) {
|
|
84
|
+
const score = scoreIp(ip);
|
|
85
|
+
candidates.push({ ip, score });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
candidateGatheringComplete = true;
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
pickBestCandidate();
|
|
92
|
+
}, 200);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
pc.createDataChannel("");
|
|
96
|
+
pc.createOffer().then((offer) => pc.setLocalDescription(offer)).catch(() => {
|
|
97
|
+
clearTimeout(timeout);
|
|
98
|
+
resolveOnce(null);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/utils/url-builder.ts
|
|
104
|
+
var UrlBuilder = class {
|
|
105
|
+
cachedLocalIp = null;
|
|
106
|
+
ipDetectionPromise = null;
|
|
107
|
+
/**
|
|
108
|
+
* Get the local network IP address with caching.
|
|
109
|
+
* First call triggers detection, subsequent calls return cached value.
|
|
110
|
+
*/
|
|
111
|
+
async getLocalIp() {
|
|
112
|
+
if (this.cachedLocalIp !== null) {
|
|
113
|
+
return this.cachedLocalIp;
|
|
114
|
+
}
|
|
115
|
+
if (this.ipDetectionPromise !== null) {
|
|
116
|
+
return this.ipDetectionPromise;
|
|
117
|
+
}
|
|
118
|
+
this.ipDetectionPromise = getLocalNetworkIp().then((ip) => {
|
|
119
|
+
this.cachedLocalIp = ip;
|
|
120
|
+
this.ipDetectionPromise = null;
|
|
121
|
+
return ip;
|
|
122
|
+
});
|
|
123
|
+
return this.ipDetectionPromise;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Clear the cached IP address.
|
|
127
|
+
* Useful for testing or when network changes are detected.
|
|
128
|
+
*/
|
|
129
|
+
clearCache() {
|
|
130
|
+
this.cachedLocalIp = null;
|
|
131
|
+
this.ipDetectionPromise = null;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Normalize a URL for mobile access.
|
|
135
|
+
* Replaces localhost with the local network IP.
|
|
136
|
+
*/
|
|
137
|
+
async normalizeForMobile(url) {
|
|
138
|
+
if (typeof window === "undefined") return url;
|
|
139
|
+
try {
|
|
140
|
+
const urlObj = new URL(url);
|
|
141
|
+
if (urlObj.hostname === "localhost" || urlObj.hostname === "127.0.0.1") {
|
|
142
|
+
const localIp = await this.getLocalIp();
|
|
143
|
+
if (localIp) {
|
|
144
|
+
urlObj.hostname = localIp;
|
|
145
|
+
return urlObj.toString();
|
|
146
|
+
}
|
|
147
|
+
urlObj.hostname = window.location.hostname;
|
|
148
|
+
return urlObj.toString();
|
|
149
|
+
}
|
|
150
|
+
return url;
|
|
151
|
+
} catch {
|
|
152
|
+
return url;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Build a controller URL with room code.
|
|
157
|
+
* Controller is always at {baseUrl}/controller (standardized convention).
|
|
158
|
+
* Automatically uses local IP when running on localhost.
|
|
159
|
+
*/
|
|
160
|
+
async buildControllerUrl(roomId, options) {
|
|
161
|
+
const path = CONTROLLER_PATH;
|
|
162
|
+
if (options?.host) {
|
|
163
|
+
const url2 = new URL(path, this.normalizeOrigin(options.host));
|
|
164
|
+
url2.searchParams.set("room", roomId);
|
|
165
|
+
if (options.capabilityToken) {
|
|
166
|
+
url2.searchParams.set("aj_controller_cap", options.capabilityToken);
|
|
167
|
+
}
|
|
168
|
+
return url2.toString();
|
|
169
|
+
}
|
|
170
|
+
let base;
|
|
171
|
+
if (typeof window === "undefined") {
|
|
172
|
+
base = `http://localhost:${DEFAULT_SERVER_PORT}`;
|
|
173
|
+
} else {
|
|
174
|
+
const currentUrl = new URL(window.location.href);
|
|
175
|
+
if (!this.isLocalhost(currentUrl.hostname)) {
|
|
176
|
+
base = currentUrl.origin;
|
|
177
|
+
} else {
|
|
178
|
+
const localIp = await this.getLocalIp();
|
|
179
|
+
if (localIp) {
|
|
180
|
+
const port = currentUrl.port;
|
|
181
|
+
base = port ? `http://${localIp}:${port}` : `http://${localIp}`;
|
|
182
|
+
} else {
|
|
183
|
+
base = currentUrl.origin;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const url = new URL(path, base);
|
|
188
|
+
url.searchParams.set("room", roomId);
|
|
189
|
+
if (options?.capabilityToken) {
|
|
190
|
+
url.searchParams.set("aj_controller_cap", options.capabilityToken);
|
|
191
|
+
}
|
|
192
|
+
return url.toString();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Resolve the server URL.
|
|
196
|
+
* Uses explicit URL if provided, otherwise infers from window location.
|
|
197
|
+
*/
|
|
198
|
+
resolveServerUrl(explicit) {
|
|
199
|
+
if (explicit) {
|
|
200
|
+
return this.normalizeOrigin(explicit);
|
|
201
|
+
}
|
|
202
|
+
if (typeof window !== "undefined") {
|
|
203
|
+
const url = new URL(window.location.href);
|
|
204
|
+
url.port = String(DEFAULT_SERVER_PORT);
|
|
205
|
+
return url.origin;
|
|
206
|
+
}
|
|
207
|
+
return `http://localhost:${DEFAULT_SERVER_PORT}`;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Check if a hostname is localhost.
|
|
211
|
+
*/
|
|
212
|
+
isLocalhost(hostname) {
|
|
213
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Normalize an origin string to ensure it has a protocol.
|
|
217
|
+
*/
|
|
218
|
+
normalizeOrigin(origin) {
|
|
219
|
+
if (!origin.includes("://")) {
|
|
220
|
+
return `http://${origin}`;
|
|
221
|
+
}
|
|
222
|
+
return origin;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
var urlBuilder = new UrlBuilder();
|
|
226
|
+
|
|
227
|
+
export {
|
|
228
|
+
urlBuilder
|
|
229
|
+
};
|
|
230
|
+
//# sourceMappingURL=chunk-YXHH3MQT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/network-ip.ts","../src/utils/url-builder.ts"],"sourcesContent":["/**\n * Checks if an IP is from a virtual network interface (Docker, VMs, etc.)\n */\nconst isVirtualNetwork = (ip: string): boolean => {\n // Docker Desktop on Mac uses 192.168.64.x and 192.168.65.x\n if (ip.startsWith(\"192.168.64.\") || ip.startsWith(\"192.168.65.\")) {\n return true;\n }\n // Docker default bridge network\n if (ip.startsWith(\"172.17.\")) {\n return true;\n }\n // Other common virtual network ranges\n if (ip.startsWith(\"172.18.\") || ip.startsWith(\"172.19.\")) {\n return true;\n }\n // Link-local addresses\n if (ip.startsWith(\"169.254.\")) {\n return true;\n }\n return false;\n};\n\n/**\n * Scores an IP address to determine preference.\n * Higher score = more preferred.\n */\nconst scoreIp = (ip: string): number => {\n // Prefer 192.168.0.x - 192.168.63.x (common home network ranges, excluding virtual networks)\n if (ip.startsWith(\"192.168.\")) {\n const parts = ip.split(\".\");\n const thirdOctet = parseInt(parts[2] || \"0\", 10);\n // Prefer lower third octets (0-63) as they're more likely to be real networks\n if (thirdOctet < 64) {\n return 100 - thirdOctet; // Higher score for lower numbers\n }\n // 64+ are often virtual, but we'll still consider them if nothing else\n return 10;\n }\n // Prefer 10.x.x.x networks\n if (ip.startsWith(\"10.\")) {\n return 50;\n }\n // 172.16-31.x.x networks (but not 172.17.x.x which is Docker)\n if (/^172\\.(1[6-9]|2[0-9]|3[01])\\./.test(ip)) {\n return 30;\n }\n return 0;\n};\n\n/**\n * Gets the local network IP address using WebRTC.\n * Filters out virtual network interfaces and prefers real network IPs.\n * Returns null if unable to determine the IP.\n */\nexport const getLocalNetworkIp = (): Promise<string | null> => {\n return new Promise((resolve) => {\n // If not in browser, return null\n if (\n typeof window === \"undefined\" ||\n typeof RTCPeerConnection === \"undefined\"\n ) {\n resolve(null);\n return;\n }\n\n const pc = new RTCPeerConnection({\n iceServers: [{ urls: \"stun:stun.l.google.com:19302\" }],\n });\n\n const candidates: Array<{ ip: string; score: number }> = [];\n let candidateGatheringComplete = false;\n\n const resolveOnce = (ip: string | null) => {\n pc.close();\n resolve(ip);\n };\n\n // Timeout after 3 seconds\n const timeout = setTimeout(() => {\n if (candidateGatheringComplete) {\n pickBestCandidate();\n } else {\n // Wait a bit more for candidates to arrive\n setTimeout(() => {\n pickBestCandidate();\n }, 500);\n }\n }, 3000);\n\n const pickBestCandidate = () => {\n if (candidates.length === 0) {\n resolveOnce(null);\n return;\n }\n\n // Sort by score (highest first), then pick the best one\n candidates.sort((a, b) => b.score - a.score);\n const best = candidates[0];\n clearTimeout(timeout);\n resolveOnce(best.ip);\n };\n\n pc.onicecandidate = (event) => {\n if (event.candidate) {\n const candidate = event.candidate.candidate;\n const match = candidate.match(/([0-9]{1,3}(\\.[0-9]{1,3}){3})/);\n if (match) {\n const ip = match[1];\n // Filter out localhost\n if (ip === \"127.0.0.1\") {\n return;\n }\n\n // Check if it's a private network IP\n const isPrivate =\n ip.startsWith(\"192.168.\") ||\n ip.startsWith(\"10.\") ||\n /^172\\.(1[6-9]|2[0-9]|3[01])\\./.test(ip);\n\n if (isPrivate && !isVirtualNetwork(ip)) {\n const score = scoreIp(ip);\n candidates.push({ ip, score });\n }\n }\n } else {\n // No more candidates - gathering is complete\n candidateGatheringComplete = true;\n // Give it a moment for any last candidates to arrive, then pick the best\n setTimeout(() => {\n pickBestCandidate();\n }, 200);\n }\n };\n\n // Create a data channel to trigger candidate gathering\n pc.createDataChannel(\"\");\n pc.createOffer()\n .then((offer) => pc.setLocalDescription(offer))\n .catch(() => {\n clearTimeout(timeout);\n resolveOnce(null);\n });\n });\n};\n","import { CONTROLLER_PATH, DEFAULT_SERVER_PORT } from \"../constants\";\nimport type { RoomCode } from \"../protocol\";\nimport { getLocalNetworkIp } from \"./network-ip\";\n\n/**\n * Centralized URL builder service for Air Jam.\n * Handles IP detection, URL normalization, and construction of all URL types.\n */\nclass UrlBuilder {\n private cachedLocalIp: string | null = null;\n private ipDetectionPromise: Promise<string | null> | null = null;\n\n /**\n * Get the local network IP address with caching.\n * First call triggers detection, subsequent calls return cached value.\n */\n async getLocalIp(): Promise<string | null> {\n // Return cached value if available\n if (this.cachedLocalIp !== null) {\n return this.cachedLocalIp;\n }\n\n // If detection is already in progress, wait for it\n if (this.ipDetectionPromise !== null) {\n return this.ipDetectionPromise;\n }\n\n // Start IP detection\n this.ipDetectionPromise = getLocalNetworkIp().then((ip) => {\n this.cachedLocalIp = ip;\n this.ipDetectionPromise = null;\n return ip;\n });\n\n return this.ipDetectionPromise;\n }\n\n /**\n * Clear the cached IP address.\n * Useful for testing or when network changes are detected.\n */\n clearCache(): void {\n this.cachedLocalIp = null;\n this.ipDetectionPromise = null;\n }\n\n /**\n * Normalize a URL for mobile access.\n * Replaces localhost with the local network IP.\n */\n async normalizeForMobile(url: string): Promise<string> {\n if (typeof window === \"undefined\") return url;\n\n try {\n const urlObj = new URL(url);\n\n // If URL uses localhost, replace with local network IP\n if (urlObj.hostname === \"localhost\" || urlObj.hostname === \"127.0.0.1\") {\n const localIp = await this.getLocalIp();\n\n if (localIp) {\n urlObj.hostname = localIp;\n return urlObj.toString();\n }\n\n // Fallback to current hostname if IP detection fails\n urlObj.hostname = window.location.hostname;\n return urlObj.toString();\n }\n\n return url;\n } catch {\n return url;\n }\n }\n\n /**\n * Build a controller URL with room code.\n * Controller is always at {baseUrl}/controller (standardized convention).\n * Automatically uses local IP when running on localhost.\n */\n async buildControllerUrl(\n roomId: RoomCode,\n options?: {\n host?: string;\n capabilityToken?: string;\n },\n ): Promise<string> {\n const path = CONTROLLER_PATH;\n\n // If explicit host is provided, use it\n if (options?.host) {\n const url = new URL(path, this.normalizeOrigin(options.host));\n url.searchParams.set(\"room\", roomId);\n if (options.capabilityToken) {\n url.searchParams.set(\"aj_controller_cap\", options.capabilityToken);\n }\n return url.toString();\n }\n\n // Determine base URL\n let base: string;\n if (typeof window === \"undefined\") {\n base = `http://localhost:${DEFAULT_SERVER_PORT}`;\n } else {\n const currentUrl = new URL(window.location.href);\n\n // If not localhost, use the current origin\n if (!this.isLocalhost(currentUrl.hostname)) {\n base = currentUrl.origin;\n } else {\n // If localhost, try to get the local network IP\n const localIp = await this.getLocalIp();\n if (localIp) {\n // Preserve the port from the current URL\n const port = currentUrl.port;\n base = port ? `http://${localIp}:${port}` : `http://${localIp}`;\n } else {\n // Fallback to localhost if we can't determine the IP\n base = currentUrl.origin;\n }\n }\n }\n\n const url = new URL(path, base);\n url.searchParams.set(\"room\", roomId);\n if (options?.capabilityToken) {\n url.searchParams.set(\"aj_controller_cap\", options.capabilityToken);\n }\n return url.toString();\n }\n\n /**\n * Resolve the server URL.\n * Uses explicit URL if provided, otherwise infers from window location.\n */\n resolveServerUrl(explicit?: string): string {\n if (explicit) {\n return this.normalizeOrigin(explicit);\n }\n\n if (typeof window !== \"undefined\") {\n const url = new URL(window.location.href);\n url.port = String(DEFAULT_SERVER_PORT);\n return url.origin;\n }\n\n return `http://localhost:${DEFAULT_SERVER_PORT}`;\n }\n\n /**\n * Check if a hostname is localhost.\n */\n private isLocalhost(hostname: string): boolean {\n return (\n hostname === \"localhost\" ||\n hostname === \"127.0.0.1\" ||\n hostname === \"[::1]\"\n );\n }\n\n /**\n * Normalize an origin string to ensure it has a protocol.\n */\n private normalizeOrigin(origin: string): string {\n if (!origin.includes(\"://\")) {\n return `http://${origin}`;\n }\n return origin;\n }\n}\n\n// Export singleton instance\nexport const urlBuilder = new UrlBuilder();\n\n// Export class for testing/advanced usage\nexport { UrlBuilder };\n"],"mappings":";;;;;;AAGA,IAAM,mBAAmB,CAAC,OAAwB;AAEhD,MAAI,GAAG,WAAW,aAAa,KAAK,GAAG,WAAW,aAAa,GAAG;AAChE,WAAO;AAAA,EACT;AAEA,MAAI,GAAG,WAAW,SAAS,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,GAAG,WAAW,SAAS,KAAK,GAAG,WAAW,SAAS,GAAG;AACxD,WAAO;AAAA,EACT;AAEA,MAAI,GAAG,WAAW,UAAU,GAAG;AAC7B,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAMA,IAAM,UAAU,CAAC,OAAuB;AAEtC,MAAI,GAAG,WAAW,UAAU,GAAG;AAC7B,UAAM,QAAQ,GAAG,MAAM,GAAG;AAC1B,UAAM,aAAa,SAAS,MAAM,CAAC,KAAK,KAAK,EAAE;AAE/C,QAAI,aAAa,IAAI;A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MA,iBAAiB,UAA2B;AAC1C,QAAI,UAAU;AACZ,aAAO,KAAK,gBAAgB,QAAQ;AAAA,IACtC;AAEA,QAAI,OAAO,WAAW,aAAa;AACjC,YAAM,MAAM,IAAI,IAAI,OAAO,SAAS,IAAI;AACxC,UAAI,OAAO,OAAO,mBAAmB;AACrC,aAAO,IAAI;AAAA,IACb;AAEA,WAAO,oBAAoB,mBAAmB;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKQ,YAAY,UAA2B;AAC7C,WACE,aAAa,eACb,aAAa,eACb,aAAa;AAAA,EAEjB;AAAA;AAAA;AAAA;AAAA,EAKQ,gBAAgB,QAAwB;AAC9C,QAAI,CAAC,OAAO,SAAS,KAAK,GAAG;AAC3B,aAAO,UAAU,MAAM;AAAA,IACzB;AACA,WAAO;AAAA,EACT;AACF;AAGO,IAAM,aAAa,IAAI,WAAW;","names":["url"]}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// src/settings/platform-settings.ts
|
|
2
|
+
var PLATFORM_SETTINGS_STORAGE_KEY = "air-jam-platform-settings";
|
|
3
|
+
var LEGACY_AUDIO_SETTINGS_STORAGE_KEY = "air-jam-volume-settings";
|
|
4
|
+
var DEFAULT_PLATFORM_SETTINGS = {
|
|
5
|
+
audio: {
|
|
6
|
+
masterVolume: 1,
|
|
7
|
+
musicVolume: 0.8,
|
|
8
|
+
sfxVolume: 1
|
|
9
|
+
},
|
|
10
|
+
accessibility: {
|
|
11
|
+
reducedMotion: false,
|
|
12
|
+
highContrast: false
|
|
13
|
+
},
|
|
14
|
+
feedback: {
|
|
15
|
+
hapticsEnabled: true
|
|
16
|
+
},
|
|
17
|
+
previewControllers: {
|
|
18
|
+
activeOpacity: 1
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var DEFAULT_ROOM_PLATFORM_SETTINGS = {
|
|
22
|
+
audio: DEFAULT_PLATFORM_SETTINGS.audio,
|
|
23
|
+
previewControllers: DEFAULT_PLATFORM_SETTINGS.previewControllers
|
|
24
|
+
};
|
|
25
|
+
var isRecord = (value) => typeof value === "object" && value !== null;
|
|
26
|
+
var clamp01 = (value) => Math.max(0, Math.min(1, value));
|
|
27
|
+
var normalizeBoolean = (value, fallback) => typeof value === "boolean" ? value : fallback;
|
|
28
|
+
var normalizeAudioSettings = (value, fallback) => {
|
|
29
|
+
if (!isRecord(value)) {
|
|
30
|
+
return fallback;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
masterVolume: typeof value.masterVolume === "number" ? clamp01(value.masterVolume) : fallback.masterVolume,
|
|
34
|
+
musicVolume: typeof value.musicVolume === "number" ? clamp01(value.musicVolume) : fallback.musicVolume,
|
|
35
|
+
sfxVolume: typeof value.sfxVolume === "number" ? clamp01(value.sfxVolume) : fallback.sfxVolume
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
var normalizePreviewControllerSettings = (value, fallback) => {
|
|
39
|
+
if (!isRecord(value)) {
|
|
40
|
+
return fallback;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
activeOpacity: typeof value.activeOpacity === "number" ? clamp01(value.activeOpacity) : fallback.activeOpacity
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
var normalizePlatformSettings = (value) => {
|
|
47
|
+
if (!isRecord(value)) {
|
|
48
|
+
return DEFAULT_PLATFORM_SETTINGS;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
audio: normalizeAudioSettings(value.audio, DEFAULT_PLATFORM_SETTINGS.audio),
|
|
52
|
+
accessibility: {
|
|
53
|
+
reducedMotion: normalizeBoolean(
|
|
54
|
+
isRecord(value.accessibility) ? value.accessibility.reducedMotion : null,
|
|
55
|
+
DEFAULT_PLATFORM_SETTINGS.accessibility.reducedMotion
|
|
56
|
+
),
|
|
57
|
+
highContrast: normalizeBoolean(
|
|
58
|
+
isRecord(value.accessibility) ? value.accessibility.highContrast : null,
|
|
59
|
+
DEFAULT_PLATFORM_SETTINGS.accessibility.highContrast
|
|
60
|
+
)
|
|
61
|
+
},
|
|
62
|
+
feedback: {
|
|
63
|
+
hapticsEnabled: normalizeBoolean(
|
|
64
|
+
isRecord(value.feedback) ? value.feedback.hapticsEnabled : null,
|
|
65
|
+
DEFAULT_PLATFORM_SETTINGS.feedback.hapticsEnabled
|
|
66
|
+
)
|
|
67
|
+
},
|
|
68
|
+
previewControllers: normalizePreviewControllerSettings(
|
|
69
|
+
value.previewControllers,
|
|
70
|
+
DEFAULT_PLATFORM_SETTINGS.previewControllers
|
|
71
|
+
)
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
var mergePlatformSettings = (current, patch) => normalizePlatformSettings({
|
|
75
|
+
audio: { ...current.audio, ...patch.audio },
|
|
76
|
+
accessibility: {
|
|
77
|
+
...current.accessibility,
|
|
78
|
+
...patch.accessibility
|
|
79
|
+
},
|
|
80
|
+
feedback: { ...current.feedback, ...patch.feedback },
|
|
81
|
+
previewControllers: {
|
|
82
|
+
...current.previewControllers,
|
|
83
|
+
...patch.previewControllers
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
var getEffectiveAudioVolume = (settings, category) => {
|
|
87
|
+
const categoryVolume = category === "music" ? settings.musicVolume : settings.sfxVolume;
|
|
88
|
+
return clamp01(settings.masterVolume) * clamp01(categoryVolume);
|
|
89
|
+
};
|
|
90
|
+
var toRoomPlatformSettingsSnapshot = (settings) => ({
|
|
91
|
+
audio: settings.audio,
|
|
92
|
+
previewControllers: settings.previewControllers
|
|
93
|
+
});
|
|
94
|
+
var mergeRoomPlatformSettingsSnapshot = (current, patch) => ({
|
|
95
|
+
audio: normalizeAudioSettings(
|
|
96
|
+
{ ...current.audio, ...patch.audio },
|
|
97
|
+
current.audio
|
|
98
|
+
),
|
|
99
|
+
previewControllers: normalizePreviewControllerSettings(
|
|
100
|
+
{
|
|
101
|
+
...current.previewControllers,
|
|
102
|
+
...patch.previewControllers
|
|
103
|
+
},
|
|
104
|
+
current.previewControllers
|
|
105
|
+
)
|
|
106
|
+
});
|
|
107
|
+
var tryParseJson = (raw) => {
|
|
108
|
+
if (!raw) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
return JSON.parse(raw);
|
|
113
|
+
} catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var readLegacyAudioSettings = () => {
|
|
118
|
+
const parsed = tryParseJson(
|
|
119
|
+
window.localStorage.getItem(LEGACY_AUDIO_SETTINGS_STORAGE_KEY)
|
|
120
|
+
);
|
|
121
|
+
if (!isRecord(parsed)) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return normalizePlatformSettings({
|
|
125
|
+
...DEFAULT_PLATFORM_SETTINGS,
|
|
126
|
+
audio: {
|
|
127
|
+
masterVolume: parsed.masterVolume,
|
|
128
|
+
musicVolume: parsed.musicVolume,
|
|
129
|
+
sfxVolume: parsed.sfxVolume
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
var readPersistedPlatformSettings = () => {
|
|
134
|
+
if (typeof window === "undefined") {
|
|
135
|
+
return DEFAULT_PLATFORM_SETTINGS;
|
|
136
|
+
}
|
|
137
|
+
const current = tryParseJson(
|
|
138
|
+
window.localStorage.getItem(PLATFORM_SETTINGS_STORAGE_KEY)
|
|
139
|
+
);
|
|
140
|
+
if (current) {
|
|
141
|
+
return normalizePlatformSettings(current);
|
|
142
|
+
}
|
|
143
|
+
const migrated = readLegacyAudioSettings();
|
|
144
|
+
if (!migrated) {
|
|
145
|
+
return DEFAULT_PLATFORM_SETTINGS;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
window.localStorage.setItem(
|
|
149
|
+
PLATFORM_SETTINGS_STORAGE_KEY,
|
|
150
|
+
JSON.stringify(migrated)
|
|
151
|
+
);
|
|
152
|
+
window.localStorage.removeItem(LEGACY_AUDIO_SETTINGS_STORAGE_KEY);
|
|
153
|
+
} catch {
|
|
154
|
+
}
|
|
155
|
+
return migrated;
|
|
156
|
+
};
|
|
157
|
+
var persistPlatformSettings = (snapshot) => {
|
|
158
|
+
if (typeof window === "undefined") {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
window.localStorage.setItem(
|
|
163
|
+
PLATFORM_SETTINGS_STORAGE_KEY,
|
|
164
|
+
JSON.stringify(snapshot)
|
|
165
|
+
);
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export {
|
|
171
|
+
PLATFORM_SETTINGS_STORAGE_KEY,
|
|
172
|
+
LEGACY_AUDIO_SETTINGS_STORAGE_KEY,
|
|
173
|
+
DEFAULT_PLATFORM_SETTINGS,
|
|
174
|
+
DEFAULT_ROOM_PLATFORM_SETTINGS,
|
|
175
|
+
normalizePlatformSettings,
|
|
176
|
+
mergePlatformSettings,
|
|
177
|
+
getEffectiveAudioVolume,
|
|
178
|
+
toRoomPlatformSettingsSnapshot,
|
|
179
|
+
mergeRoomPlatformSettingsSnapshot,
|
|
180
|
+
readPersistedPlatformSettings,
|
|
181
|
+
persistPlatformSettings
|
|
182
|
+
};
|
|
183
|
+
//# sourceMappingURL=chunk-ZLPL2R3R.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/settings/platform-settings.ts"],"sourcesContent":["export type PlatformSettingsPersistence = \"local\" | \"none\";\n\nexport interface PlatformAudioSettings {\n masterVolume: number;\n musicVolume: number;\n sfxVolume: number;\n}\n\nexport interface PlatformAccessibilitySettings {\n reducedMotion: boolean;\n highContrast: boolean;\n}\n\nexport interface PlatformFeedbackSettings {\n hapticsEnabled: boolean;\n}\n\nexport interface PlatformPreviewControllerSettings {\n activeOpacity: number;\n}\n\nexport interface PlatformSettings {\n audio: PlatformAudioSettings;\n accessibility: PlatformAccessibilitySettings;\n feedback: PlatformFeedbackSettings;\n previewControllers: PlatformPreviewControllerSettings;\n}\n\nexport type PlatformSettingsSnapshot = PlatformSettings;\nexport interface RoomPlatformSettingsSnapshot {\n audio: PlatformAudioSettings;\n previewControllers: PlatformPreviewControllerSettings;\n}\n\nexport interface PartialRoomPlatformSettingsPatch {\n audio?: Partial<PlatformAudioSettings>;\n previewControllers?: Partial<PlatformPreviewControllerSettings>;\n}\n\nexport const PLATFORM_SETTINGS_STORAGE_KEY = \"air-jam-platform-settings\";\nexport const LEGACY_AUDIO_SETTINGS_STORAGE_KEY = \"air-jam-volume-settings\";\n\nexport const DEFAULT_PLATFORM_SETTINGS: PlatformSettingsSnapshot = {\n audio: {\n masterVolume: 1,\n musicVolume: 0.8,\n sfxVolume: 1,\n },\n accessibility: {\n reducedMotion: false,\n highContrast: false,\n },\n feedback: {\n hapticsEnabled: true,\n },\n previewControllers: {\n activeOpacity: 1,\n },\n};\n\nexport const DEFAULT_ROOM_PLATFORM_SETTINGS: RoomPlatformSettingsSnapshot = {\n audio: DEFAULT_PLATFORM_SETTINGS.audio,\n previewControllers: DEFAULT_PLATFORM_SETTINGS.previewControllers,\n};\n\ntype PartialPlatformAudioSettings = Partial<PlatformAudioSettings>;\ntype PartialPlatformAccessibilitySettings =\n Partial<PlatformAccessibilitySettings>;\ntype PartialPlatformFeedbackSettings = Partial<PlatformFeedbackSettings>;\ntype PartialPlatformPreviewControllerSettings =\n Partial<PlatformPreviewControllerSettings>;\n\nexport interface PartialPlatformSettings {\n audio?: PartialPlatformAudioSettings;\n accessibility?: PartialPlatformAccessibilitySettings;\n feedback?: PartialPlatformFeedbackSettings;\n previewControllers?: PartialPlatformPreviewControllerSettings;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst clamp01 = (value: number): number => Math.max(0, Math.min(1, value));\n\nconst normalizeBoolean = (value: unknown, fallback: boolean): boolean =>\n typeof value === \"boolean\" ? value : fallback;\n\nconst normalizeAudioSettings = (\n value: unknown,\n fallback: PlatformAudioSettings,\n): PlatformAudioSettings => {\n if (!isRecord(value)) {\n return fallback;\n }\n\n return {\n masterVolume:\n typeof value.masterVolume === \"number\"\n ? clamp01(value.masterVolume)\n : fallback.masterVolume,\n musicVolume:\n typeof value.musicVolume === \"number\"\n ? clamp01(value.musicVolume)\n : fallback.musicVolume,\n sfxVolume:\n typeof value.sfxVolume === \"number\"\n ? clamp01(value.sfxVolume)\n : fallback.sfxVolume,\n };\n};\n\nconst normalizePreviewControllerSettings = (\n value: unknown,\n fallback: PlatformPreviewControllerSettings,\n): PlatformPreviewControllerSettings => {\n if (!isRecord(value)) {\n return fallback;\n }\n\n return {\n activeOpacity:\n typeof value.activeOpacity === \"number\"\n ? clamp01(value.activeOpacity)\n : fallback.activeOpacity,\n };\n};\n\nexport const normalizePlatformSettings = (\n value: unknown,\n): PlatformSettingsSnapshot => {\n if (!isRecord(value)) {\n return DEFAULT_PLATFORM_SETTINGS;\n }\n\n return {\n audio: normalizeAudioSettings(value.audio, DEFAULT_PLATFORM_SETTINGS.audio),\n accessibility: {\n reducedMotion: normalizeBoolean(\n isRecord(value.accessibility)\n ? value.accessibility.reducedMotion\n : null,\n DEFAULT_PLATFORM_SETTINGS.accessibility.reducedMotion,\n ),\n highContrast: normalizeBoolean(\n isRecord(value.accessibility) ? value.accessibility.highContrast : null,\n DEFAULT_PLATFORM_SETTINGS.accessibility.highContrast,\n ),\n },\n feedback: {\n hapticsEnabled: normalizeBoolean(\n isRecord(value.feedback) ? value.feedback.hapticsEnabled : null,\n DEFAULT_PLATFORM_SETTINGS.feedback.hapticsEnabled,\n ),\n },\n previewControllers: normalizePreviewControllerSettings(\n value.previewControllers,\n DEFAULT_PLATFORM_SETTINGS.previewControllers,\n ),\n };\n};\n\nexport const mergePlatformSettings = (\n current: PlatformSettingsSnapshot,\n patch: PartialPlatformSettings,\n): PlatformSettingsSnapshot =>\n normalizePlatformSettings({\n audio: { ...current.audio, ...patch.audio },\n accessibility: {\n ...current.accessibility,\n ...patch.accessibility,\n },\n feedback: { ...current.feedback, ...patch.feedback },\n previewControllers: {\n ...current.previewControllers,\n ...patch.previewControllers,\n },\n });\n\nexport const getEffectiveAudioVolume = (\n settings: PlatformAudioSettings,\n category: \"music\" | \"sfx\",\n): number => {\n const categoryVolume =\n category === \"music\" ? settings.musicVolume : settings.sfxVolume;\n return clamp01(settings.masterVolume) * clamp01(categoryVolume);\n};\n\nexport const toRoomPlatformSettingsSnapshot = (\n settings: PlatformSettingsSnapshot,\n): RoomPlatformSettingsSnapshot => ({\n audio: settings.audio,\n previewControllers: settings.previewControllers,\n});\n\nexport const mergeRoomPlatformSettingsSnapshot = (\n current: RoomPlatformSettingsSnapshot,\n patch: PartialRoomPlatformSettingsPatch,\n): RoomPlatformSettingsSnapshot => ({\n audio: normalizeAudioSettings(\n { ...current.audio, ...patch.audio },\n current.audio,\n ),\n previewControllers: normalizePreviewControllerSettings(\n {\n ...current.previewControllers,\n ...patch.previewControllers,\n },\n current.previewControllers,\n ),\n});\n\nconst tryParseJson = (raw: string | null): unknown => {\n if (!raw) {\n return null;\n }\n\n try {\n return JSON.parse(raw) as unknown;\n } catch {\n return null;\n }\n};\n\nconst readLegacyAudioSettings = (): PlatformSettingsSnapshot | null => {\n const parsed = tryParseJson(\n window.localStorage.getItem(LEGACY_AUDIO_SETTINGS_STORAGE_KEY),\n );\n\n if (!isRecord(parsed)) {\n return null;\n }\n\n return normalizePlatformSettings({\n ...DEFAULT_PLATFORM_SETTINGS,\n audio: {\n masterVolume: parsed.masterVolume,\n musicVolume: parsed.musicVolume,\n sfxVolume: parsed.sfxVolume,\n },\n });\n};\n\nexport const readPersistedPlatformSettings = (): PlatformSettingsSnapshot => {\n if (typeof window === \"undefined\") {\n return DEFAULT_PLATFORM_SETTINGS;\n }\n\n const current = tryParseJson(\n window.localStorage.getItem(PLATFORM_SETTINGS_STORAGE_KEY),\n );\n if (current) {\n return normalizePlatformSettings(current);\n }\n\n const migrated = readLegacyAudioSettings();\n if (!migrated) {\n return DEFAULT_PLATFORM_SETTINGS;\n }\n\n try {\n window.localStorage.setItem(\n PLATFORM_SETTINGS_STORAGE_KEY,\n JSON.stringify(migrated),\n );\n window.localStorage.removeItem(LEGACY_AUDIO_SETTINGS_STORAGE_KEY);\n } catch {\n // Best-effort only.\n }\n\n return migrated;\n};\n\nexport const persistPlatformSettings = (\n snapshot: PlatformSettingsSnapshot,\n): void => {\n if (typeof window === \"undefined\") {\n return;\n }\n\n try {\n window.localStorage.setItem(\n PLATFORM_SETTINGS_STORAGE_KEY,\n JSON.stringify(snapshot),\n );\n } catch {\n // Ignore storage failures.\n }\n};\n"],"mappings":";AAuCO,IAAM,gCAAgC;AACtC,IAAM,oCAAoC;AAE1C,IAAM,4BAAsD;AAAA,EACjE,OAAO;AAAA,IACL,cAAc;AAAA,IACd,aAAa;AAAA,IACb,WAAW;AAAA,EACb;AAAA,EACA,eAAe;AAAA,IACb,eAAe;AAAA,IACf,cAAc;AAAA,EAChB;AAAA,EACA,UAAU;AAAA,IACR,gBAAgB;AAAA,EAClB;AAAA,EACA,oBAAoB;AAAA,IAClB,eAAe;AAAA,EACjB;AACF;AAEO,IAAM,iCAA+D;AAAA,EAC1E,OAAO,0BAA0B;AAAA,EACjC,oBAAoB,0BAA0B;AAChD;AAgBA,IAAM,WAAW,CAAC,UAChB,OAAO,UAAU,YAAY,UAAU;AAEzC,IAAM,UAAU,CAAC,UAA0B,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,CAAC;AAEzE,IAAM,mBAAmB,CAAC,OAAgB,aACxC,OAAO,UAAU,YAAY,QAAQ;AAEvC,IAAM,yBAAyB,CAC7B,OACA,aAC0B;AAC1B,MAAI,CAAC,SAAS,KAAK,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,cACE,OAAO,MAAM,iBAAiB,WAC1B,QAAQ,MAAM,YAAY,IAC1B,SAAS;AAAA,IACf,aACE,OAAO,MAAM,gBAAgB,WACzB,QAAQ,MAAM,WAAW,IACzB,SAAS;AAAA,IACf,WACE,OAAO,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AC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,MAAI;AACF,WAAO,aAAa;AAAA,MAClB;AAAA,MACA,KAAK,UAAU,QAAQ;AAAA,IACzB;AACA,WAAO,aAAa,WAAW,iCAAiC;AAAA,EAClE,QAAQ;AAAA,EAER;AAEA,SAAO;AACT;AAEO,IAAM,0BAA0B,CACrC,aACS;AACT,MAAI,OAAO,WAAW,aAAa;AACjC;AAAA,EACF;AAEA,MAAI;AACF,WAAO,aAAa;AAAA,MAClB;AAAA,MACA,KAAK,UAAU,QAAQ;AAAA,IACzB;AAAA,EACF,QAAQ;AAAA,EAER;AACF;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// src/runtime/arcade-bridge-request-surface.ts
|
|
2
|
+
var isArcadeSurfaceMismatch = (active, request) => {
|
|
3
|
+
return request.epoch !== active.epoch || request.kind !== active.kind || request.gameId !== active.gameId;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
isArcadeSurfaceMismatch
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=chunk-ZTQ5SP4H.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/arcade-bridge-request-surface.ts"],"sourcesContent":["import type { ArcadeSurfaceRuntimeIdentity } from \"./arcade-surface-identity\";\n\n/**\n * Returns true when the iframe surface identity does not match the parent's active surface.\n */\nexport const isArcadeSurfaceMismatch = (\n active: ArcadeSurfaceRuntimeIdentity,\n request: ArcadeSurfaceRuntimeIdentity,\n): boolean => {\n return (\n request.epoch !== active.epoch ||\n request.kind !== active.kind ||\n request.gameId !== active.gameId\n );\n};\n"],"mappings":";AAKO,IAAM,0BAA0B,CACrC,QACA,YACY;AACZ,SACE,QAAQ,UAAU,OAAO,SACzB,QAAQ,SAAS,OAAO,QACxB,QAAQ,WAAW,OAAO;AAE9B;","names":[]}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { R as RoomPlatformSettingsSnapshot } from './platform-settings-cuor3i11.cjs';
|
|
3
|
+
|
|
4
|
+
type RoomCode = string;
|
|
5
|
+
type ConnectionRole = "host" | "controller";
|
|
6
|
+
type ConnectionStatus = "idle" | "connecting" | "connected" | "disconnected" | "reconnecting";
|
|
7
|
+
type RunMode = "standalone" | "platform";
|
|
8
|
+
type RuntimeState = "paused" | "playing";
|
|
9
|
+
declare const roomCodeSchema: z.ZodString;
|
|
10
|
+
|
|
11
|
+
declare enum ErrorCode {
|
|
12
|
+
ROOM_NOT_FOUND = "ROOM_NOT_FOUND",
|
|
13
|
+
ROOM_FULL = "ROOM_FULL",
|
|
14
|
+
INVALID_APP_ID = "INVALID_APP_ID",
|
|
15
|
+
UNAUTHORIZED = "UNAUTHORIZED",
|
|
16
|
+
INVALID_TOKEN = "INVALID_TOKEN",
|
|
17
|
+
TOKEN_EXPIRED = "TOKEN_EXPIRED",
|
|
18
|
+
CONNECTION_FAILED = "CONNECTION_FAILED",
|
|
19
|
+
ALREADY_CONNECTED = "ALREADY_CONNECTED",
|
|
20
|
+
INVALID_PAYLOAD = "INVALID_PAYLOAD",
|
|
21
|
+
INVALID_ROOM_CODE = "INVALID_ROOM_CODE",
|
|
22
|
+
INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR",
|
|
23
|
+
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
|
|
24
|
+
UNKNOWN_ERROR = "UNKNOWN_ERROR"
|
|
25
|
+
}
|
|
26
|
+
interface ServerErrorPayload {
|
|
27
|
+
code: ErrorCode | string;
|
|
28
|
+
message: string;
|
|
29
|
+
details?: unknown;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare const controllerInputSchema: z.ZodObject<{
|
|
33
|
+
roomId: z.ZodString;
|
|
34
|
+
controllerId: z.ZodString;
|
|
35
|
+
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
type ControllerInputPayload = Record<string, unknown>;
|
|
38
|
+
interface ControllerInputEvent {
|
|
39
|
+
roomId: RoomCode;
|
|
40
|
+
controllerId: string;
|
|
41
|
+
input: ControllerInputPayload;
|
|
42
|
+
}
|
|
43
|
+
declare const controllerOrientationSchema: z.ZodEnum<{
|
|
44
|
+
portrait: "portrait";
|
|
45
|
+
landscape: "landscape";
|
|
46
|
+
}>;
|
|
47
|
+
type ControllerOrientation = z.infer<typeof controllerOrientationSchema>;
|
|
48
|
+
declare const controllerSourceSchema: z.ZodEnum<{
|
|
49
|
+
phone: "phone";
|
|
50
|
+
preview: "preview";
|
|
51
|
+
virtual: "virtual";
|
|
52
|
+
}>;
|
|
53
|
+
type ControllerSource = z.infer<typeof controllerSourceSchema>;
|
|
54
|
+
declare const PREVIEW_CONTROLLER_DEVICE_ID_PREFIX = "pd_";
|
|
55
|
+
declare const VIRTUAL_CONTROLLER_DEVICE_ID_PREFIX = "aj-mcp-device-";
|
|
56
|
+
declare const inferControllerSourceFromDeviceId: (deviceId: string | null | undefined) => ControllerSource;
|
|
57
|
+
declare const controllerStateSchema: z.ZodObject<{
|
|
58
|
+
roomId: z.ZodString;
|
|
59
|
+
state: z.ZodObject<{
|
|
60
|
+
orientation: z.ZodOptional<z.ZodEnum<{
|
|
61
|
+
portrait: "portrait";
|
|
62
|
+
landscape: "landscape";
|
|
63
|
+
}>>;
|
|
64
|
+
message: z.ZodOptional<z.ZodString>;
|
|
65
|
+
roomSettings: z.ZodOptional<z.ZodObject<{
|
|
66
|
+
audio: z.ZodObject<{
|
|
67
|
+
masterVolume: z.ZodNumber;
|
|
68
|
+
musicVolume: z.ZodNumber;
|
|
69
|
+
sfxVolume: z.ZodNumber;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
previewControllers: z.ZodObject<{
|
|
72
|
+
activeOpacity: z.ZodNumber;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
}, z.core.$strip>>;
|
|
75
|
+
runtimeState: z.ZodOptional<z.ZodEnum<{
|
|
76
|
+
paused: "paused";
|
|
77
|
+
playing: "playing";
|
|
78
|
+
}>>;
|
|
79
|
+
stateVersion: z.ZodOptional<z.ZodNumber>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
type ControllerStateMessage = z.infer<typeof controllerStateSchema>;
|
|
83
|
+
type ControllerStatePayload = z.infer<typeof controllerStateSchema>["state"];
|
|
84
|
+
type ControllerRoomSettingsState = RoomPlatformSettingsSnapshot;
|
|
85
|
+
declare const controllerJoinSchema: z.ZodObject<{
|
|
86
|
+
roomId: z.ZodString;
|
|
87
|
+
controllerId: z.ZodString;
|
|
88
|
+
deviceId: z.ZodOptional<z.ZodString>;
|
|
89
|
+
nickname: z.ZodOptional<z.ZodString>;
|
|
90
|
+
avatarId: z.ZodOptional<z.ZodString>;
|
|
91
|
+
capabilityToken: z.ZodOptional<z.ZodString>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
type ControllerJoinPayload = z.infer<typeof controllerJoinSchema>;
|
|
94
|
+
declare const controllerLeaveSchema: z.ZodObject<{
|
|
95
|
+
roomId: z.ZodString;
|
|
96
|
+
controllerId: z.ZodString;
|
|
97
|
+
}, z.core.$strip>;
|
|
98
|
+
type ControllerLeavePayload = z.infer<typeof controllerLeaveSchema>;
|
|
99
|
+
interface ControllerLeaveAck {
|
|
100
|
+
ok: boolean;
|
|
101
|
+
message?: string;
|
|
102
|
+
code?: ErrorCode | string;
|
|
103
|
+
}
|
|
104
|
+
declare const controllerSystemSchema: z.ZodObject<{
|
|
105
|
+
roomId: z.ZodString;
|
|
106
|
+
command: z.ZodEnum<{
|
|
107
|
+
exit: "exit";
|
|
108
|
+
pause: "pause";
|
|
109
|
+
resume: "resume";
|
|
110
|
+
}>;
|
|
111
|
+
}, z.core.$strip>;
|
|
112
|
+
type ControllerSystemPayload = z.infer<typeof controllerSystemSchema>;
|
|
113
|
+
interface PlayerProfile {
|
|
114
|
+
id: string;
|
|
115
|
+
label: string;
|
|
116
|
+
color?: string;
|
|
117
|
+
/** Preset avatar id chosen by the player (platform resolves to artwork). */
|
|
118
|
+
avatarId?: string;
|
|
119
|
+
}
|
|
120
|
+
declare const playerProfilePatchSchema: z.ZodObject<{
|
|
121
|
+
label: z.ZodOptional<z.ZodString>;
|
|
122
|
+
avatarId: z.ZodOptional<z.ZodString>;
|
|
123
|
+
}, z.core.$strict>;
|
|
124
|
+
type PlayerProfilePatch = z.infer<typeof playerProfilePatchSchema>;
|
|
125
|
+
declare const controllerUpdatePlayerProfileSchema: z.ZodObject<{
|
|
126
|
+
roomId: z.ZodString;
|
|
127
|
+
controllerId: z.ZodString;
|
|
128
|
+
patch: z.ZodObject<{
|
|
129
|
+
label: z.ZodOptional<z.ZodString>;
|
|
130
|
+
avatarId: z.ZodOptional<z.ZodString>;
|
|
131
|
+
}, z.core.$strict>;
|
|
132
|
+
}, z.core.$strip>;
|
|
133
|
+
type ControllerUpdatePlayerProfilePayload = z.infer<typeof controllerUpdatePlayerProfileSchema>;
|
|
134
|
+
interface ControllerUpdatePlayerProfileAck {
|
|
135
|
+
ok: boolean;
|
|
136
|
+
message?: string;
|
|
137
|
+
player?: PlayerProfile;
|
|
138
|
+
code?: ErrorCode | string;
|
|
139
|
+
}
|
|
140
|
+
interface ControllerJoinAck {
|
|
141
|
+
ok: boolean;
|
|
142
|
+
controllerId?: string;
|
|
143
|
+
roomId?: RoomCode;
|
|
144
|
+
resumed?: boolean;
|
|
145
|
+
message?: string;
|
|
146
|
+
code?: ErrorCode | string;
|
|
147
|
+
}
|
|
148
|
+
declare const controllerPrivilegedGrantSchema: z.ZodEnum<{
|
|
149
|
+
system: "system";
|
|
150
|
+
play_sound: "play_sound";
|
|
151
|
+
action_rpc: "action_rpc";
|
|
152
|
+
}>;
|
|
153
|
+
type ControllerPrivilegedGrant = z.infer<typeof controllerPrivilegedGrantSchema>;
|
|
154
|
+
declare const controllerPrivilegedCapabilitySchema: z.ZodObject<{
|
|
155
|
+
token: z.ZodString;
|
|
156
|
+
expiresAt: z.ZodNumber;
|
|
157
|
+
grants: z.ZodArray<z.ZodEnum<{
|
|
158
|
+
system: "system";
|
|
159
|
+
play_sound: "play_sound";
|
|
160
|
+
action_rpc: "action_rpc";
|
|
161
|
+
}>>;
|
|
162
|
+
}, z.core.$strip>;
|
|
163
|
+
type ControllerPrivilegedCapability = z.infer<typeof controllerPrivilegedCapabilitySchema>;
|
|
164
|
+
interface ControllerSocketAuthority {
|
|
165
|
+
roomId: RoomCode;
|
|
166
|
+
controllerId: string;
|
|
167
|
+
deviceId: string;
|
|
168
|
+
joinedAt: number;
|
|
169
|
+
privilegedGrants: ControllerPrivilegedGrant[];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { controllerUpdatePlayerProfileSchema as A, controllerPrivilegedGrantSchema as B, type ControllerPrivilegedCapability as C, type ControllerPrivilegedGrant as D, ErrorCode as E, controllerPrivilegedCapabilitySchema as F, type ConnectionRole as G, type ConnectionStatus as H, type RunMode as I, type RuntimeState as J, roomCodeSchema as K, type PlayerProfile as P, type RoomCode as R, type ServerErrorPayload as S, VIRTUAL_CONTROLLER_DEVICE_ID_PREFIX as V, type ControllerSource as a, type ControllerStateMessage as b, type ControllerJoinPayload as c, type ControllerJoinAck as d, type ControllerUpdatePlayerProfilePayload as e, type ControllerUpdatePlayerProfileAck as f, type ControllerLeavePayload as g, type ControllerLeaveAck as h, type ControllerInputEvent as i, type ControllerSystemPayload as j, type ControllerSocketAuthority as k, controllerInputSchema as l, type ControllerInputPayload as m, controllerOrientationSchema as n, type ControllerOrientation as o, controllerSourceSchema as p, PREVIEW_CONTROLLER_DEVICE_ID_PREFIX as q, inferControllerSourceFromDeviceId as r, controllerStateSchema as s, type ControllerStatePayload as t, type ControllerRoomSettingsState as u, controllerJoinSchema as v, controllerLeaveSchema as w, controllerSystemSchema as x, playerProfilePatchSchema as y, type PlayerProfilePatch as z };
|