@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,185 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const hostGrantScopeSchema = z.literal("host:bootstrap");
|
|
4
|
+
|
|
5
|
+
export const hostGrantClaimsSchema = z.object({
|
|
6
|
+
typ: z.literal("airjam.host_grant.v1"),
|
|
7
|
+
appId: z.string().min(1),
|
|
8
|
+
exp: z.number().int().positive(),
|
|
9
|
+
iat: z.number().int().positive().optional(),
|
|
10
|
+
scopes: z.array(hostGrantScopeSchema).min(1).default(["host:bootstrap"]),
|
|
11
|
+
origins: z.array(z.string().min(1)).optional(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export type HostGrantClaims = z.infer<typeof hostGrantClaimsSchema>;
|
|
15
|
+
|
|
16
|
+
const encoder = new TextEncoder();
|
|
17
|
+
const decoder = new TextDecoder();
|
|
18
|
+
|
|
19
|
+
const getSubtleCrypto = (): SubtleCrypto => {
|
|
20
|
+
const subtle = globalThis.crypto?.subtle;
|
|
21
|
+
if (!subtle) {
|
|
22
|
+
throw new Error("SubtleCrypto unavailable");
|
|
23
|
+
}
|
|
24
|
+
return subtle;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const getBtoa = (): ((value: string) => string) => {
|
|
28
|
+
if (typeof globalThis.btoa === "function") {
|
|
29
|
+
return globalThis.btoa.bind(globalThis);
|
|
30
|
+
}
|
|
31
|
+
throw new Error("Base64 encoding unavailable");
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getAtob = (): ((value: string) => string) => {
|
|
35
|
+
if (typeof globalThis.atob === "function") {
|
|
36
|
+
return globalThis.atob.bind(globalThis);
|
|
37
|
+
}
|
|
38
|
+
throw new Error("Base64 decoding unavailable");
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const toBase64Url = (bytes: Uint8Array): string => {
|
|
42
|
+
let binary = "";
|
|
43
|
+
bytes.forEach((byte) => {
|
|
44
|
+
binary += String.fromCharCode(byte);
|
|
45
|
+
});
|
|
46
|
+
return getBtoa()(binary)
|
|
47
|
+
.replace(/\+/g, "-")
|
|
48
|
+
.replace(/\//g, "_")
|
|
49
|
+
.replace(/=+$/g, "");
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const fromBase64Url = (value: string): Uint8Array => {
|
|
53
|
+
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
54
|
+
const padded = normalized.padEnd(
|
|
55
|
+
normalized.length + ((4 - (normalized.length % 4)) % 4),
|
|
56
|
+
"=",
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const binary = getAtob()(padded);
|
|
60
|
+
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const encodeJson = (value: unknown): string =>
|
|
64
|
+
toBase64Url(encoder.encode(JSON.stringify(value)));
|
|
65
|
+
|
|
66
|
+
const decodeJson = <T>(value: string): T =>
|
|
67
|
+
JSON.parse(decoder.decode(fromBase64Url(value))) as T;
|
|
68
|
+
|
|
69
|
+
const signHmacSha256 = async (
|
|
70
|
+
secret: string,
|
|
71
|
+
data: string,
|
|
72
|
+
): Promise<Uint8Array> => {
|
|
73
|
+
const subtle = getSubtleCrypto();
|
|
74
|
+
const key = await subtle.importKey(
|
|
75
|
+
"raw",
|
|
76
|
+
encoder.encode(secret),
|
|
77
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
78
|
+
false,
|
|
79
|
+
["sign"],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const signature = await subtle.sign("HMAC", key, encoder.encode(data));
|
|
83
|
+
return new Uint8Array(signature);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const timingSafeEqual = (a: Uint8Array, b: Uint8Array): boolean => {
|
|
87
|
+
if (a.length !== b.length) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let result = 0;
|
|
92
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
93
|
+
result |= a[i]! ^ b[i]!;
|
|
94
|
+
}
|
|
95
|
+
return result === 0;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export interface CreateHostGrantInput {
|
|
99
|
+
secret: string;
|
|
100
|
+
claims: Pick<HostGrantClaims, "appId" | "exp"> &
|
|
101
|
+
Partial<Pick<HostGrantClaims, "typ" | "iat" | "scopes" | "origins">>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const createHostGrant = async ({
|
|
105
|
+
secret,
|
|
106
|
+
claims,
|
|
107
|
+
}: CreateHostGrantInput): Promise<string> => {
|
|
108
|
+
const normalizedClaims = hostGrantClaimsSchema.parse({
|
|
109
|
+
typ: "airjam.host_grant.v1",
|
|
110
|
+
...claims,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const header = encodeJson({
|
|
114
|
+
alg: "HS256",
|
|
115
|
+
typ: "AIRJAM_HOST_GRANT",
|
|
116
|
+
});
|
|
117
|
+
const payload = encodeJson(normalizedClaims);
|
|
118
|
+
const signature = toBase64Url(
|
|
119
|
+
await signHmacSha256(secret, `${header}.${payload}`),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return `${header}.${payload}.${signature}`;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export interface VerifyHostGrantInput {
|
|
126
|
+
secret: string;
|
|
127
|
+
token: string;
|
|
128
|
+
now?: number;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface VerifyHostGrantResult {
|
|
132
|
+
ok: boolean;
|
|
133
|
+
claims?: HostGrantClaims;
|
|
134
|
+
error?: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const verifyHostGrant = async ({
|
|
138
|
+
secret,
|
|
139
|
+
token,
|
|
140
|
+
now = Math.floor(Date.now() / 1000),
|
|
141
|
+
}: VerifyHostGrantInput): Promise<VerifyHostGrantResult> => {
|
|
142
|
+
const parts = token.split(".");
|
|
143
|
+
if (parts.length !== 3) {
|
|
144
|
+
return { ok: false, error: "Malformed host grant" };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const [header, payload, signature] = parts;
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const parsedHeader = decodeJson<{ alg?: string; typ?: string }>(header!);
|
|
151
|
+
if (parsedHeader.alg !== "HS256") {
|
|
152
|
+
return { ok: false, error: "Unsupported host grant algorithm" };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const expectedSignature = await signHmacSha256(
|
|
156
|
+
secret,
|
|
157
|
+
`${header}.${payload}`,
|
|
158
|
+
);
|
|
159
|
+
if (!timingSafeEqual(expectedSignature, fromBase64Url(signature!))) {
|
|
160
|
+
return { ok: false, error: "Invalid host grant signature" };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const parsedClaims = hostGrantClaimsSchema.safeParse(
|
|
164
|
+
decodeJson<unknown>(payload!),
|
|
165
|
+
);
|
|
166
|
+
if (!parsedClaims.success) {
|
|
167
|
+
return { ok: false, error: "Invalid host grant payload" };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (parsedClaims.data.exp <= now) {
|
|
171
|
+
return { ok: false, error: "Host grant expired" };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!parsedClaims.data.scopes.includes("host:bootstrap")) {
|
|
175
|
+
return { ok: false, error: "Host grant missing bootstrap scope" };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
ok: true,
|
|
180
|
+
claims: parsedClaims.data,
|
|
181
|
+
};
|
|
182
|
+
} catch {
|
|
183
|
+
return { ok: false, error: "Malformed host grant" };
|
|
184
|
+
}
|
|
185
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type {
|
|
3
|
+
ControllerPrivilegedCapability,
|
|
4
|
+
PlayerProfile,
|
|
5
|
+
} from "./controller";
|
|
6
|
+
import { roomCodeSchema, type RoomCode } from "./core";
|
|
7
|
+
import type { ErrorCode } from "./errors";
|
|
8
|
+
import type { ControllerPresenceNotice } from "./notices";
|
|
9
|
+
|
|
10
|
+
export const hostSessionKindSchema = z.enum(["game", "system"]);
|
|
11
|
+
export type HostSessionKind = z.infer<typeof hostSessionKindSchema>;
|
|
12
|
+
|
|
13
|
+
export const childHostCapabilitySchema = z.object({
|
|
14
|
+
token: z.string().min(1),
|
|
15
|
+
expiresAt: z.number().int().positive(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export type ChildHostCapability = z.infer<typeof childHostCapabilitySchema>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Active arcade game session as seen by the server (launch capability + catalog id).
|
|
22
|
+
* Returned on host reconnect so the platform can restore iframe + replicated surface after refresh.
|
|
23
|
+
*/
|
|
24
|
+
export interface HostArcadeSessionSnapshot {
|
|
25
|
+
gameId: string;
|
|
26
|
+
launchCapability: ChildHostCapability;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface HostRegistrationAck {
|
|
30
|
+
ok: boolean;
|
|
31
|
+
roomId?: RoomCode;
|
|
32
|
+
message?: string;
|
|
33
|
+
code?: ErrorCode | string;
|
|
34
|
+
/** When reconnecting, present if the room still has a launched game (launch pending or active). */
|
|
35
|
+
arcadeSession?: HostArcadeSessionSnapshot;
|
|
36
|
+
/** Authoritative controller roster snapshot for the connected room. */
|
|
37
|
+
players?: PlayerProfile[];
|
|
38
|
+
/** Authoritative controller-session roster for the connected room. */
|
|
39
|
+
controllers?: ControllerPresenceNotice[];
|
|
40
|
+
/** Official Air Jam controller capability bundle for privileged controller channels. */
|
|
41
|
+
controllerCapability?: ControllerPrivilegedCapability;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface HostBootstrapAck {
|
|
45
|
+
ok: boolean;
|
|
46
|
+
message?: string;
|
|
47
|
+
code?: ErrorCode | string;
|
|
48
|
+
traceId?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface HostSocketAuthority {
|
|
52
|
+
appId?: string;
|
|
53
|
+
gameId?: string;
|
|
54
|
+
traceId: string;
|
|
55
|
+
verifiedAt: number;
|
|
56
|
+
verifiedVia?: "appId" | "hostGrant";
|
|
57
|
+
verifiedOrigin?: string;
|
|
58
|
+
hostSessionKind: HostSessionKind;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const hostBootstrapSchema = z.object({
|
|
62
|
+
appId: z.string().optional(),
|
|
63
|
+
hostGrant: z.string().min(1).optional(),
|
|
64
|
+
hostSessionKind: hostSessionKindSchema.default("system"),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export type HostBootstrapPayload = z.infer<typeof hostBootstrapSchema>;
|
|
68
|
+
|
|
69
|
+
export const hostRegisterSystemSchema = z.object({
|
|
70
|
+
roomId: roomCodeSchema,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export type HostRegisterSystemPayload = z.infer<
|
|
74
|
+
typeof hostRegisterSystemSchema
|
|
75
|
+
>;
|
|
76
|
+
|
|
77
|
+
export const systemLaunchGameSchema = z.object({
|
|
78
|
+
roomId: roomCodeSchema,
|
|
79
|
+
gameId: z.string(),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export type SystemLaunchGamePayload = z.infer<typeof systemLaunchGameSchema>;
|
|
83
|
+
|
|
84
|
+
export const hostJoinAsChildSchema = z.object({
|
|
85
|
+
roomId: roomCodeSchema,
|
|
86
|
+
capabilityToken: z.string().min(1),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export type HostJoinAsChildPayload = z.infer<typeof hostJoinAsChildSchema>;
|
|
90
|
+
|
|
91
|
+
export const hostActivateEmbeddedGameSchema = z.object({
|
|
92
|
+
roomId: roomCodeSchema,
|
|
93
|
+
capabilityToken: z.string().min(1),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export type HostActivateEmbeddedGamePayload = z.infer<
|
|
97
|
+
typeof hostActivateEmbeddedGameSchema
|
|
98
|
+
>;
|
|
99
|
+
|
|
100
|
+
export const hostCreateRoomSchema = z.object({
|
|
101
|
+
maxPlayers: z.number().int().min(1).max(16).default(8),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export type HostCreateRoomPayload = z.infer<typeof hostCreateRoomSchema>;
|
|
105
|
+
|
|
106
|
+
export const hostReconnectSchema = z.object({
|
|
107
|
+
roomId: roomCodeSchema,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
export type HostReconnectPayload = z.infer<typeof hostReconnectSchema>;
|
|
111
|
+
|
|
112
|
+
export const hostResetRoomSchema = z.object({
|
|
113
|
+
roomId: roomCodeSchema,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export type HostResetRoomPayload = z.infer<typeof hostResetRoomSchema>;
|
|
117
|
+
|
|
118
|
+
export const hostRemoveControllerSchema = z.object({
|
|
119
|
+
roomId: roomCodeSchema,
|
|
120
|
+
controllerId: z.string().min(3),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export type HostRemoveControllerPayload = z.infer<
|
|
124
|
+
typeof hostRemoveControllerSchema
|
|
125
|
+
>;
|
|
126
|
+
|
|
127
|
+
export interface HostControllerActionAck {
|
|
128
|
+
ok: boolean;
|
|
129
|
+
message?: string;
|
|
130
|
+
code?: ErrorCode | string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface SystemLaunchGameAck {
|
|
134
|
+
ok: boolean;
|
|
135
|
+
launchCapability?: ChildHostCapability;
|
|
136
|
+
message?: string;
|
|
137
|
+
code?: ErrorCode | string;
|
|
138
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ControllerSource, PlayerProfile } from "./controller";
|
|
2
|
+
import type { RoomCode } from "./core";
|
|
3
|
+
|
|
4
|
+
export interface ControllerPresenceNotice {
|
|
5
|
+
controllerId: string;
|
|
6
|
+
deviceId?: string;
|
|
7
|
+
nickname?: string;
|
|
8
|
+
source: ControllerSource;
|
|
9
|
+
connected: boolean;
|
|
10
|
+
resumeLeaseExpiresAt: number | null;
|
|
11
|
+
player?: PlayerProfile;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ControllerWelcomePayload {
|
|
15
|
+
controllerId: string;
|
|
16
|
+
roomId: RoomCode;
|
|
17
|
+
resumed?: boolean;
|
|
18
|
+
player?: PlayerProfile;
|
|
19
|
+
players?: PlayerProfile[];
|
|
20
|
+
controllers?: ControllerPresenceNotice[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ControllerJoinedNotice extends ControllerPresenceNotice {
|
|
24
|
+
resumed?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ControllerLeftNotice {
|
|
28
|
+
controllerId: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Emitted when a controller updates their profile (label / avatar) after join. */
|
|
32
|
+
export interface PlayerUpdatedNotice {
|
|
33
|
+
player: PlayerProfile;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface RoomReadyNotice {
|
|
37
|
+
roomId: RoomCode;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface HostLeftNotice {
|
|
41
|
+
roomId: RoomCode;
|
|
42
|
+
reason: string;
|
|
43
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type SignalType = "HAPTIC" | "TOAST";
|
|
2
|
+
|
|
3
|
+
export interface HapticSignalPayload {
|
|
4
|
+
pattern: "light" | "medium" | "heavy" | "success" | "failure" | "custom";
|
|
5
|
+
sequence?: number | number[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ToastSignalPayload {
|
|
9
|
+
message: string;
|
|
10
|
+
color?: string;
|
|
11
|
+
duration?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type SignalPayload =
|
|
15
|
+
| {
|
|
16
|
+
targetId?: string;
|
|
17
|
+
type: "HAPTIC";
|
|
18
|
+
payload: HapticSignalPayload;
|
|
19
|
+
}
|
|
20
|
+
| {
|
|
21
|
+
targetId?: string;
|
|
22
|
+
type: "TOAST";
|
|
23
|
+
payload: ToastSignalPayload;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export interface PlaySoundEventPayload {
|
|
27
|
+
roomId: string;
|
|
28
|
+
targetControllerId?: string;
|
|
29
|
+
soundId: string;
|
|
30
|
+
volume?: number;
|
|
31
|
+
loop?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PlaySoundPayload {
|
|
35
|
+
id: string;
|
|
36
|
+
volume?: number;
|
|
37
|
+
loop?: boolean;
|
|
38
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ControllerInputEvent,
|
|
3
|
+
ControllerJoinAck,
|
|
4
|
+
ControllerJoinPayload,
|
|
5
|
+
ControllerLeaveAck,
|
|
6
|
+
ControllerLeavePayload,
|
|
7
|
+
ControllerSocketAuthority,
|
|
8
|
+
ControllerStateMessage,
|
|
9
|
+
ControllerSystemPayload,
|
|
10
|
+
ControllerUpdatePlayerProfileAck,
|
|
11
|
+
ControllerUpdatePlayerProfilePayload,
|
|
12
|
+
} from "./controller";
|
|
13
|
+
import type { ServerErrorPayload } from "./errors";
|
|
14
|
+
import type {
|
|
15
|
+
HostActivateEmbeddedGamePayload,
|
|
16
|
+
HostBootstrapAck,
|
|
17
|
+
HostBootstrapPayload,
|
|
18
|
+
HostControllerActionAck,
|
|
19
|
+
HostCreateRoomPayload,
|
|
20
|
+
HostJoinAsChildPayload,
|
|
21
|
+
HostReconnectPayload,
|
|
22
|
+
HostRegisterSystemPayload,
|
|
23
|
+
HostRegistrationAck,
|
|
24
|
+
HostRemoveControllerPayload,
|
|
25
|
+
HostResetRoomPayload,
|
|
26
|
+
HostSocketAuthority,
|
|
27
|
+
SystemLaunchGameAck,
|
|
28
|
+
SystemLaunchGamePayload,
|
|
29
|
+
} from "./host";
|
|
30
|
+
import type {
|
|
31
|
+
ControllerJoinedNotice,
|
|
32
|
+
ControllerLeftNotice,
|
|
33
|
+
ControllerWelcomePayload,
|
|
34
|
+
HostLeftNotice,
|
|
35
|
+
PlayerUpdatedNotice,
|
|
36
|
+
RoomReadyNotice,
|
|
37
|
+
} from "./notices";
|
|
38
|
+
import type {
|
|
39
|
+
PlaySoundEventPayload,
|
|
40
|
+
PlaySoundPayload,
|
|
41
|
+
SignalPayload,
|
|
42
|
+
} from "./signals";
|
|
43
|
+
import type {
|
|
44
|
+
AirJamActionInvocationResult,
|
|
45
|
+
AirJamActionRpcPayload,
|
|
46
|
+
AirJamStateSyncPayload,
|
|
47
|
+
AirJamStateSyncRequestPayload,
|
|
48
|
+
ControllerActionRpcPayload,
|
|
49
|
+
ControllerStateSyncRequestPayload,
|
|
50
|
+
HostActionRpcPayload,
|
|
51
|
+
HostStateSyncPayload,
|
|
52
|
+
} from "./sync";
|
|
53
|
+
|
|
54
|
+
export interface ClientToServerEvents {
|
|
55
|
+
"host:bootstrap": (
|
|
56
|
+
payload: HostBootstrapPayload,
|
|
57
|
+
callback: (ack: HostBootstrapAck) => void,
|
|
58
|
+
) => void;
|
|
59
|
+
"host:registerSystem": (
|
|
60
|
+
payload: HostRegisterSystemPayload,
|
|
61
|
+
callback: (ack: HostRegistrationAck) => void,
|
|
62
|
+
) => void;
|
|
63
|
+
"host:createRoom": (
|
|
64
|
+
payload: HostCreateRoomPayload,
|
|
65
|
+
callback: (ack: HostRegistrationAck) => void,
|
|
66
|
+
) => void;
|
|
67
|
+
"host:reconnect": (
|
|
68
|
+
payload: HostReconnectPayload,
|
|
69
|
+
callback: (ack: HostRegistrationAck) => void,
|
|
70
|
+
) => void;
|
|
71
|
+
"host:resetRoom": (
|
|
72
|
+
payload: HostResetRoomPayload,
|
|
73
|
+
callback: (ack: HostRegistrationAck) => void,
|
|
74
|
+
) => void;
|
|
75
|
+
"host:removeController": (
|
|
76
|
+
payload: HostRemoveControllerPayload,
|
|
77
|
+
callback: (ack: HostControllerActionAck) => void,
|
|
78
|
+
) => void;
|
|
79
|
+
"system:launchGame": (
|
|
80
|
+
payload: SystemLaunchGamePayload,
|
|
81
|
+
callback: (ack: SystemLaunchGameAck) => void,
|
|
82
|
+
) => void;
|
|
83
|
+
"host:joinAsChild": (
|
|
84
|
+
payload: HostJoinAsChildPayload,
|
|
85
|
+
callback: (ack: HostRegistrationAck) => void,
|
|
86
|
+
) => void;
|
|
87
|
+
"host:activateEmbeddedGame": (
|
|
88
|
+
payload: HostActivateEmbeddedGamePayload,
|
|
89
|
+
callback: (ack: HostRegistrationAck) => void,
|
|
90
|
+
) => void;
|
|
91
|
+
"system:closeGame": (payload: { roomId: string }) => void;
|
|
92
|
+
"host:state": (payload: ControllerStateMessage) => void;
|
|
93
|
+
"controller:join": (
|
|
94
|
+
payload: ControllerJoinPayload,
|
|
95
|
+
callback: (ack: ControllerJoinAck) => void,
|
|
96
|
+
) => void;
|
|
97
|
+
"controller:updatePlayerProfile": (
|
|
98
|
+
payload: ControllerUpdatePlayerProfilePayload,
|
|
99
|
+
callback: (ack: ControllerUpdatePlayerProfileAck) => void,
|
|
100
|
+
) => void;
|
|
101
|
+
"controller:leave": (
|
|
102
|
+
payload: ControllerLeavePayload,
|
|
103
|
+
callback: (ack: ControllerLeaveAck) => void,
|
|
104
|
+
) => void;
|
|
105
|
+
"controller:input": (payload: ControllerInputEvent) => void;
|
|
106
|
+
"controller:system": (payload: ControllerSystemPayload) => void;
|
|
107
|
+
"host:system": (payload: ControllerSystemPayload) => void;
|
|
108
|
+
"host:signal": (payload: SignalPayload) => void;
|
|
109
|
+
"host:play_sound": (payload: PlaySoundEventPayload) => void;
|
|
110
|
+
"controller:play_sound": (payload: PlaySoundEventPayload) => void;
|
|
111
|
+
"host:state_sync": (payload: HostStateSyncPayload) => void;
|
|
112
|
+
"controller:action_rpc": (
|
|
113
|
+
payload: ControllerActionRpcPayload,
|
|
114
|
+
callback?: (ack: AirJamActionInvocationResult) => void,
|
|
115
|
+
) => void;
|
|
116
|
+
"controller:host_action_rpc": (
|
|
117
|
+
payload: HostActionRpcPayload,
|
|
118
|
+
callback?: (ack: AirJamActionInvocationResult) => void,
|
|
119
|
+
) => void;
|
|
120
|
+
"controller:state_sync_request": (
|
|
121
|
+
payload: ControllerStateSyncRequestPayload,
|
|
122
|
+
) => void;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface ServerToClientEvents {
|
|
126
|
+
"server:roomReady": (payload: RoomReadyNotice) => void;
|
|
127
|
+
"server:controllerJoined": (payload: ControllerJoinedNotice) => void;
|
|
128
|
+
"server:controllerLeft": (payload: ControllerLeftNotice) => void;
|
|
129
|
+
"server:playerUpdated": (payload: PlayerUpdatedNotice) => void;
|
|
130
|
+
"server:input": (payload: ControllerInputEvent) => void;
|
|
131
|
+
"server:error": (payload: ServerErrorPayload) => void;
|
|
132
|
+
"server:state": (payload: ControllerStateMessage) => void;
|
|
133
|
+
"server:welcome": (payload: ControllerWelcomePayload) => void;
|
|
134
|
+
"server:hostLeft": (payload: HostLeftNotice) => void;
|
|
135
|
+
"server:signal": (payload: SignalPayload) => void;
|
|
136
|
+
"server:playSound": (payload: PlaySoundPayload) => void;
|
|
137
|
+
"server:redirect": (url: string) => void;
|
|
138
|
+
"server:closeChild": () => void;
|
|
139
|
+
"airjam:state_sync": (payload: AirJamStateSyncPayload) => void;
|
|
140
|
+
"airjam:action_rpc": (
|
|
141
|
+
payload: AirJamActionRpcPayload,
|
|
142
|
+
callback?: (ack: AirJamActionInvocationResult) => void,
|
|
143
|
+
) => void;
|
|
144
|
+
"airjam:state_sync_request": (payload: AirJamStateSyncRequestPayload) => void;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface InterServerEvents {
|
|
148
|
+
ping: () => void;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface SocketData {
|
|
152
|
+
hostAuthority?: HostSocketAuthority;
|
|
153
|
+
controllerAuthority?: ControllerSocketAuthority;
|
|
154
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { roomCodeSchema } from "./core";
|
|
3
|
+
|
|
4
|
+
const stateSyncRequestIdSchema = z.string().trim().min(1).max(128);
|
|
5
|
+
|
|
6
|
+
export interface HostStateSyncPayload {
|
|
7
|
+
roomId: string;
|
|
8
|
+
data: Record<string, unknown>;
|
|
9
|
+
/** Separates concurrent replicated stores in the same room (e.g. arcade shell vs game). */
|
|
10
|
+
storeDomain: string;
|
|
11
|
+
revision: number;
|
|
12
|
+
requestId?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ControllerStateSyncRequestPayload {
|
|
16
|
+
roomId: string;
|
|
17
|
+
storeDomain: string;
|
|
18
|
+
requestId?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type AirJamActionActorRole = "controller" | "host";
|
|
22
|
+
|
|
23
|
+
export interface AirJamActionActor {
|
|
24
|
+
id: string;
|
|
25
|
+
role: AirJamActionActorRole;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type AirJamActionPayload = Record<string, unknown>;
|
|
29
|
+
|
|
30
|
+
export const airJamActionPayloadSchema = z.record(z.string(), z.unknown());
|
|
31
|
+
|
|
32
|
+
export interface AirJamActionAccepted<TResult = unknown> {
|
|
33
|
+
ok: true;
|
|
34
|
+
status: "accepted";
|
|
35
|
+
source: "client" | "host";
|
|
36
|
+
result?: TResult;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface AirJamActionRejected {
|
|
40
|
+
ok: false;
|
|
41
|
+
status: "rejected";
|
|
42
|
+
source: "client" | "server" | "host";
|
|
43
|
+
reason: string;
|
|
44
|
+
message: string;
|
|
45
|
+
details?: AirJamActionPayload;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type AirJamActionInvocationResult<TResult = unknown> =
|
|
49
|
+
| AirJamActionAccepted<TResult>
|
|
50
|
+
| AirJamActionRejected;
|
|
51
|
+
|
|
52
|
+
export interface ControllerActionRpcPayload {
|
|
53
|
+
roomId: string;
|
|
54
|
+
actionName: string;
|
|
55
|
+
payload: AirJamActionPayload | undefined;
|
|
56
|
+
storeDomain: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface HostActionRpcPayload {
|
|
60
|
+
roomId: string;
|
|
61
|
+
actionName: string;
|
|
62
|
+
payload: AirJamActionPayload | undefined;
|
|
63
|
+
storeDomain: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface AirJamStateSyncPayload {
|
|
67
|
+
roomId: string;
|
|
68
|
+
data: Record<string, unknown>;
|
|
69
|
+
storeDomain: string;
|
|
70
|
+
revision: number;
|
|
71
|
+
requestId?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface AirJamStateSyncRequestPayload {
|
|
75
|
+
roomId: string;
|
|
76
|
+
storeDomain: string;
|
|
77
|
+
requestId?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface AirJamActionRpcPayload {
|
|
81
|
+
actionName: string;
|
|
82
|
+
payload: AirJamActionPayload | undefined;
|
|
83
|
+
actor: AirJamActionActor;
|
|
84
|
+
storeDomain: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const controllerActionRpcSchema = z
|
|
88
|
+
.object({
|
|
89
|
+
roomId: roomCodeSchema,
|
|
90
|
+
actionName: z.string().trim().min(1),
|
|
91
|
+
payload: z.union([airJamActionPayloadSchema, z.undefined()]).optional(),
|
|
92
|
+
storeDomain: z.string().trim().min(1).max(128),
|
|
93
|
+
})
|
|
94
|
+
.strict();
|
|
95
|
+
|
|
96
|
+
export const hostActionRpcSchema = z
|
|
97
|
+
.object({
|
|
98
|
+
roomId: roomCodeSchema,
|
|
99
|
+
actionName: z.string().trim().min(1),
|
|
100
|
+
payload: z.union([airJamActionPayloadSchema, z.undefined()]).optional(),
|
|
101
|
+
storeDomain: z.string().trim().min(1).max(128),
|
|
102
|
+
})
|
|
103
|
+
.strict();
|
|
104
|
+
|
|
105
|
+
export const hostStateSyncSchema = z
|
|
106
|
+
.object({
|
|
107
|
+
roomId: roomCodeSchema,
|
|
108
|
+
data: z.record(z.string(), z.unknown()),
|
|
109
|
+
storeDomain: z.string().trim().min(1).max(128),
|
|
110
|
+
revision: z.number().int().nonnegative(),
|
|
111
|
+
requestId: stateSyncRequestIdSchema.optional(),
|
|
112
|
+
})
|
|
113
|
+
.strict();
|
|
114
|
+
|
|
115
|
+
export const controllerStateSyncRequestSchema = z
|
|
116
|
+
.object({
|
|
117
|
+
roomId: roomCodeSchema,
|
|
118
|
+
storeDomain: z.string().trim().min(1).max(128),
|
|
119
|
+
requestId: stateSyncRequestIdSchema.optional(),
|
|
120
|
+
})
|
|
121
|
+
.strict();
|