@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,83 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { useAirJamContext } from "../context/air-jam-context";
|
|
3
|
+
import { useAssertSessionScope } from "../context/session-scope";
|
|
4
|
+
import { emitAirJamDiagnostic } from "../diagnostics";
|
|
5
|
+
import {
|
|
6
|
+
controllerInputSchema,
|
|
7
|
+
type ControllerInputPayload,
|
|
8
|
+
} from "../protocol";
|
|
9
|
+
import { getControllerRealtimeClient } from "../runtime/controller-realtime-client";
|
|
10
|
+
import { isRpcSerializable } from "../utils/is-rpc-serializable";
|
|
11
|
+
|
|
12
|
+
export const useInputWriter = (): ((
|
|
13
|
+
input: ControllerInputPayload,
|
|
14
|
+
) => boolean) => {
|
|
15
|
+
useAssertSessionScope("controller", "useInputWriter");
|
|
16
|
+
|
|
17
|
+
const { store, getSocket } = useAirJamContext();
|
|
18
|
+
|
|
19
|
+
return useCallback(
|
|
20
|
+
(input: ControllerInputPayload): boolean => {
|
|
21
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
22
|
+
emitAirJamDiagnostic({
|
|
23
|
+
code: "AJ_INPUT_WRITER_INVALID_SHAPE",
|
|
24
|
+
severity: "warn",
|
|
25
|
+
message: "Input writer payload must be a plain object.",
|
|
26
|
+
});
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (!isRpcSerializable(input)) {
|
|
30
|
+
emitAirJamDiagnostic({
|
|
31
|
+
code: "AJ_INPUT_WRITER_NOT_SERIALIZABLE",
|
|
32
|
+
severity: "warn",
|
|
33
|
+
message: "Input writer payload must be RPC-serializable.",
|
|
34
|
+
});
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const state = store.getState();
|
|
39
|
+
if (!state.roomId || !state.controllerId) {
|
|
40
|
+
emitAirJamDiagnostic({
|
|
41
|
+
code: "AJ_INPUT_WRITER_SESSION_NOT_READY",
|
|
42
|
+
severity: "warn",
|
|
43
|
+
message:
|
|
44
|
+
"Input writer blocked: room/controller session is not ready.",
|
|
45
|
+
});
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const socket = getControllerRealtimeClient((role) => getSocket(role));
|
|
50
|
+
if (!socket.connected) {
|
|
51
|
+
emitAirJamDiagnostic({
|
|
52
|
+
code: "AJ_INPUT_WRITER_SOCKET_DISCONNECTED",
|
|
53
|
+
severity: "warn",
|
|
54
|
+
message: "Input writer blocked: controller socket is disconnected.",
|
|
55
|
+
});
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const payload = controllerInputSchema.safeParse({
|
|
60
|
+
roomId: state.roomId,
|
|
61
|
+
controllerId: state.controllerId,
|
|
62
|
+
input,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (!payload.success) {
|
|
66
|
+
emitAirJamDiagnostic({
|
|
67
|
+
code: "AJ_INPUT_WRITER_SCHEMA_INVALID",
|
|
68
|
+
severity: "warn",
|
|
69
|
+
message:
|
|
70
|
+
"Input writer payload failed controller input schema validation.",
|
|
71
|
+
details: {
|
|
72
|
+
issueCount: payload.error.issues.length,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
socket.emit("controller:input", payload.data);
|
|
79
|
+
return true;
|
|
80
|
+
},
|
|
81
|
+
[getSocket, store],
|
|
82
|
+
);
|
|
83
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { ShellMatchPhase } from "../lifecycle";
|
|
2
|
+
import type { RuntimeState } from "../protocol";
|
|
3
|
+
|
|
4
|
+
export type LifecycleVisualPhase = ShellMatchPhase;
|
|
5
|
+
|
|
6
|
+
export type LifecycleActionKind =
|
|
7
|
+
| "start"
|
|
8
|
+
| "pause-toggle"
|
|
9
|
+
| "restart"
|
|
10
|
+
| "back-to-lobby";
|
|
11
|
+
|
|
12
|
+
export interface LifecycleActionDescriptor {
|
|
13
|
+
kind: LifecycleActionKind;
|
|
14
|
+
label: string;
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
tone: "primary" | "secondary";
|
|
17
|
+
onPress?: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface UseLifecycleActionGroupModelProps {
|
|
21
|
+
phase: LifecycleVisualPhase;
|
|
22
|
+
runtimeState?: RuntimeState;
|
|
23
|
+
canInteract?: boolean;
|
|
24
|
+
onStart?: () => void;
|
|
25
|
+
onTogglePause?: () => void;
|
|
26
|
+
onBackToLobby?: () => void;
|
|
27
|
+
onRestart?: () => void;
|
|
28
|
+
startLabel?: string;
|
|
29
|
+
restartLabel?: string;
|
|
30
|
+
backLabel?: string;
|
|
31
|
+
pauseLabel?: string;
|
|
32
|
+
resumeLabel?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface LifecycleActionGroupModel {
|
|
36
|
+
isPaused: boolean;
|
|
37
|
+
actions: LifecycleActionDescriptor[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const useLifecycleActionGroupModel = ({
|
|
41
|
+
phase,
|
|
42
|
+
runtimeState,
|
|
43
|
+
canInteract = true,
|
|
44
|
+
onStart,
|
|
45
|
+
onTogglePause,
|
|
46
|
+
onBackToLobby,
|
|
47
|
+
onRestart,
|
|
48
|
+
startLabel = "Start",
|
|
49
|
+
restartLabel = "Restart",
|
|
50
|
+
backLabel = "Back to Lobby",
|
|
51
|
+
pauseLabel = "Pause",
|
|
52
|
+
resumeLabel = "Resume",
|
|
53
|
+
}: UseLifecycleActionGroupModelProps): LifecycleActionGroupModel => {
|
|
54
|
+
const isPaused = runtimeState === "paused";
|
|
55
|
+
const actions: LifecycleActionDescriptor[] = [];
|
|
56
|
+
|
|
57
|
+
if (phase === "lobby" && onStart) {
|
|
58
|
+
actions.push({
|
|
59
|
+
kind: "start",
|
|
60
|
+
label: startLabel,
|
|
61
|
+
disabled: !canInteract,
|
|
62
|
+
tone: "primary",
|
|
63
|
+
onPress: onStart,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (phase === "playing" && onTogglePause) {
|
|
68
|
+
actions.push({
|
|
69
|
+
kind: "pause-toggle",
|
|
70
|
+
label: isPaused ? resumeLabel : pauseLabel,
|
|
71
|
+
disabled: !canInteract,
|
|
72
|
+
tone: "secondary",
|
|
73
|
+
onPress: onTogglePause,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (phase === "ended" && (onRestart || onStart)) {
|
|
78
|
+
actions.push({
|
|
79
|
+
kind: "restart",
|
|
80
|
+
label: restartLabel,
|
|
81
|
+
disabled: !canInteract,
|
|
82
|
+
tone: "primary",
|
|
83
|
+
onPress: onRestart ?? onStart,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (phase !== "lobby" && onBackToLobby) {
|
|
88
|
+
actions.push({
|
|
89
|
+
kind: "back-to-lobby",
|
|
90
|
+
label: backLabel,
|
|
91
|
+
disabled: !canInteract,
|
|
92
|
+
tone: "secondary",
|
|
93
|
+
onPress: onBackToLobby,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return { isPaused, actions };
|
|
98
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useStore } from "zustand";
|
|
2
|
+
import { useShallow } from "zustand/react/shallow";
|
|
3
|
+
import { useAirJamContext } from "../context/air-jam-context";
|
|
4
|
+
import type { PlayerProfile } from "../protocol";
|
|
5
|
+
|
|
6
|
+
export const usePlayers = (): PlayerProfile[] => {
|
|
7
|
+
const { store } = useAirJamContext();
|
|
8
|
+
return useStore(
|
|
9
|
+
store,
|
|
10
|
+
useShallow((state) => state.players),
|
|
11
|
+
);
|
|
12
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useStore } from "zustand";
|
|
2
|
+
import { useShallow } from "zustand/react/shallow";
|
|
3
|
+
import { useAirJamContext } from "../context/air-jam-context";
|
|
4
|
+
import type { RoomCode } from "../protocol";
|
|
5
|
+
|
|
6
|
+
export interface RoomState {
|
|
7
|
+
roomId: RoomCode | null;
|
|
8
|
+
runtimeState: "paused" | "playing";
|
|
9
|
+
mode: "standalone" | "platform";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const useRoom = (): RoomState => {
|
|
13
|
+
const { store } = useAirJamContext();
|
|
14
|
+
return useStore(
|
|
15
|
+
store,
|
|
16
|
+
useShallow((state) => ({
|
|
17
|
+
roomId: state.roomId,
|
|
18
|
+
runtimeState: state.runtimeState,
|
|
19
|
+
mode: state.mode,
|
|
20
|
+
})),
|
|
21
|
+
);
|
|
22
|
+
};
|
|
@@ -12,16 +12,18 @@
|
|
|
12
12
|
*
|
|
13
13
|
* **When to use this vs useAirJamHost().sendSignal:**
|
|
14
14
|
* - Use `useSendSignal()` in components that render frequently (projectiles, collectibles)
|
|
15
|
-
* - Use `useAirJamHost().sendSignal` when you already
|
|
15
|
+
* - Use `useAirJamHost().sendSignal` when you already read host runtime state for other reasons
|
|
16
16
|
*/
|
|
17
17
|
import { useCallback } from "react";
|
|
18
18
|
import { useAirJamContext } from "../context/air-jam-context";
|
|
19
|
+
import { useAssertSessionScope } from "../context/session-scope";
|
|
19
20
|
import type {
|
|
20
21
|
HapticSignalPayload,
|
|
21
22
|
SignalPayload,
|
|
22
23
|
SignalType,
|
|
23
24
|
ToastSignalPayload,
|
|
24
25
|
} from "../protocol";
|
|
26
|
+
import { getHostRealtimeClient } from "../runtime/host-realtime-client";
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* Function signature for sending signals to controllers.
|
|
@@ -136,6 +138,8 @@ export interface SendSignalFn {
|
|
|
136
138
|
* ```
|
|
137
139
|
*/
|
|
138
140
|
export const useSendSignal = (): SendSignalFn => {
|
|
141
|
+
useAssertSessionScope("host", "useSendSignal");
|
|
142
|
+
|
|
139
143
|
const { getSocket } = useAirJamContext();
|
|
140
144
|
|
|
141
145
|
// Get socket directly without subscribing to store state
|
|
@@ -146,7 +150,7 @@ export const useSendSignal = (): SendSignalFn => {
|
|
|
146
150
|
payload: HapticSignalPayload | ToastSignalPayload,
|
|
147
151
|
targetId?: string,
|
|
148
152
|
): void => {
|
|
149
|
-
const socket = getSocket(
|
|
153
|
+
const socket = getHostRealtimeClient((role) => getSocket(role));
|
|
150
154
|
if (!socket || !socket.connected) {
|
|
151
155
|
return;
|
|
152
156
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,37 +1,211 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export type {
|
|
2
|
+
AudioHandle,
|
|
3
|
+
PlayOptions,
|
|
4
|
+
SoundCategory,
|
|
5
|
+
SoundConfig,
|
|
6
|
+
SoundManifest,
|
|
7
|
+
} from "./audio/audio-manager";
|
|
8
|
+
export {
|
|
9
|
+
AudioRuntime,
|
|
10
|
+
useAudio,
|
|
11
|
+
useAudioRuntimeControls,
|
|
12
|
+
useAudioRuntimeStatus,
|
|
13
|
+
type AudioRuntimeControls,
|
|
14
|
+
type AudioRuntimeProps,
|
|
15
|
+
type AudioRuntimeStatus,
|
|
16
|
+
} from "./audio/hooks";
|
|
17
|
+
export {
|
|
18
|
+
MusicPlaylist,
|
|
19
|
+
useAudioCategoryVolume,
|
|
20
|
+
useMusicVolume,
|
|
21
|
+
type AudioVolumeCategory,
|
|
22
|
+
type MusicPlaylistProps,
|
|
23
|
+
} from "./audio/music";
|
|
24
|
+
export {
|
|
25
|
+
DEFAULT_ROOM_PLATFORM_SETTINGS,
|
|
26
|
+
DEFAULT_PLATFORM_SETTINGS,
|
|
27
|
+
getEffectiveAudioVolume,
|
|
28
|
+
mergeRoomPlatformSettingsSnapshot,
|
|
29
|
+
toRoomPlatformSettingsSnapshot,
|
|
30
|
+
} from "./settings/platform-settings";
|
|
31
|
+
export type {
|
|
32
|
+
PlatformAccessibilitySettings,
|
|
33
|
+
PlatformAudioSettings,
|
|
34
|
+
PlatformFeedbackSettings,
|
|
35
|
+
PlatformPreviewControllerSettings,
|
|
36
|
+
PartialRoomPlatformSettingsPatch,
|
|
37
|
+
PlatformSettings,
|
|
38
|
+
PlatformSettingsPersistence,
|
|
39
|
+
PlatformSettingsSnapshot,
|
|
40
|
+
RoomPlatformSettingsSnapshot,
|
|
41
|
+
} from "./settings/platform-settings";
|
|
42
|
+
export {
|
|
43
|
+
PlatformSettingsBoundary,
|
|
44
|
+
PlatformSettingsRuntime,
|
|
45
|
+
useInheritedPlatformSettings,
|
|
46
|
+
usePlatformAudioSettings,
|
|
47
|
+
usePlatformSettings,
|
|
48
|
+
type PlatformAudioSettingsApi,
|
|
49
|
+
type PlatformSettingsBoundaryProps,
|
|
50
|
+
type PlatformSettingsOwnerApi,
|
|
51
|
+
type PlatformSettingsRuntimeProps,
|
|
52
|
+
} from "./settings/platform-settings-runtime";
|
|
3
53
|
|
|
4
|
-
|
|
5
|
-
|
|
54
|
+
export {
|
|
55
|
+
onAirJamDiagnostic,
|
|
56
|
+
setAirJamDiagnosticsEnabled,
|
|
57
|
+
type AirJamDiagnostic,
|
|
58
|
+
type AirJamDiagnosticCode,
|
|
59
|
+
type AirJamDiagnosticSeverity,
|
|
60
|
+
} from "./diagnostics";
|
|
6
61
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export
|
|
62
|
+
export {
|
|
63
|
+
useAirJamController,
|
|
64
|
+
type AirJamControllerApi,
|
|
65
|
+
type AirJamControllerOptions,
|
|
66
|
+
type AirJamControllerState,
|
|
67
|
+
} from "./hooks/use-air-jam-controller";
|
|
68
|
+
export {
|
|
69
|
+
useAirJamHost,
|
|
70
|
+
type AirJamHostApi,
|
|
71
|
+
type AirJamHostOptions,
|
|
72
|
+
type AirJamHostState,
|
|
73
|
+
type JoinUrlStatus,
|
|
74
|
+
} from "./hooks/use-air-jam-host";
|
|
75
|
+
export { useConnectionStatus } from "./hooks/use-connection-status";
|
|
76
|
+
export {
|
|
77
|
+
useControllerTick,
|
|
78
|
+
type ControllerTickInfo,
|
|
79
|
+
type ControllerTickOptions,
|
|
80
|
+
} from "./hooks/use-controller-tick";
|
|
81
|
+
export {
|
|
82
|
+
useControllerToasts,
|
|
83
|
+
type ControllerToast,
|
|
84
|
+
type UseControllerToastsOptions,
|
|
85
|
+
} from "./hooks/use-controller-toasts";
|
|
86
|
+
export { useGetInput } from "./hooks/use-get-input";
|
|
87
|
+
export {
|
|
88
|
+
useHostTick,
|
|
89
|
+
type HostFrameInfo,
|
|
90
|
+
type HostTickInfo,
|
|
91
|
+
type HostTickOptions,
|
|
92
|
+
} from "./hooks/use-host-tick";
|
|
93
|
+
export { useInputWriter } from "./hooks/use-input-writer";
|
|
94
|
+
export { usePlayers } from "./hooks/use-players";
|
|
95
|
+
export { useRoom, type RoomState } from "./hooks/use-room";
|
|
96
|
+
export { useSendSignal, type SendSignalFn } from "./hooks/use-send-signal";
|
|
97
|
+
export {
|
|
98
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY,
|
|
99
|
+
createControllerRuntimeInspectionContract,
|
|
100
|
+
createHostRuntimeInspectionContract,
|
|
101
|
+
publishRuntimeInspectionContract,
|
|
102
|
+
readRuntimeInspectionContract,
|
|
103
|
+
useControllerRuntimeInspectionContract,
|
|
104
|
+
useHostRuntimeInspectionContract,
|
|
105
|
+
type ControllerRuntimeInspectionContract,
|
|
106
|
+
type HostRuntimeInspectionContract,
|
|
107
|
+
type RuntimeInspectionContract,
|
|
108
|
+
} from "./runtime-inspection";
|
|
109
|
+
export {
|
|
110
|
+
AirJamControllerRuntime,
|
|
111
|
+
AirJamHostRuntime,
|
|
112
|
+
type AirJamControllerRuntimeProps,
|
|
113
|
+
type AirJamHostRuntimeProps,
|
|
114
|
+
} from "./runtime/session-runtimes";
|
|
14
115
|
|
|
15
|
-
|
|
16
|
-
|
|
116
|
+
export {
|
|
117
|
+
isActiveMatchPhase,
|
|
118
|
+
isEndedMatchPhase,
|
|
119
|
+
isStandardMatchPhase,
|
|
120
|
+
standardMatchPhases,
|
|
121
|
+
toShellMatchPhase,
|
|
122
|
+
} from "./lifecycle";
|
|
123
|
+
export type { ShellMatchPhase, StandardMatchPhase } from "./lifecycle";
|
|
124
|
+
export type {
|
|
125
|
+
AirJamActionAccepted,
|
|
126
|
+
AirJamActionInvocationResult,
|
|
127
|
+
AirJamActionRejected,
|
|
128
|
+
} from "./protocol";
|
|
129
|
+
export type {
|
|
130
|
+
ControllerOrientation,
|
|
131
|
+
ControllerStatePayload,
|
|
132
|
+
ControllerUpdatePlayerProfileAck,
|
|
133
|
+
PlayerProfile,
|
|
134
|
+
PlayerProfilePatch,
|
|
135
|
+
} from "./protocol/controller";
|
|
136
|
+
export type {
|
|
137
|
+
ConnectionStatus,
|
|
138
|
+
RoomCode,
|
|
139
|
+
RunMode,
|
|
140
|
+
RuntimeState,
|
|
141
|
+
} from "./protocol/core";
|
|
142
|
+
export type {
|
|
143
|
+
HapticSignalPayload,
|
|
144
|
+
SignalPayload,
|
|
145
|
+
SignalType,
|
|
146
|
+
ToastSignalPayload,
|
|
147
|
+
} from "./protocol/signals";
|
|
17
148
|
|
|
18
|
-
|
|
19
|
-
|
|
149
|
+
export {
|
|
150
|
+
AirJamErrorBoundary,
|
|
151
|
+
type AirJamErrorBoundaryProps,
|
|
152
|
+
type AirJamErrorFallbackRenderProps,
|
|
153
|
+
type AirJamErrorFallbackRenderer,
|
|
154
|
+
type AirJamRuntimeRole,
|
|
155
|
+
} from "./runtime/air-jam-error-boundary";
|
|
156
|
+
export {
|
|
157
|
+
createAirJamApp,
|
|
158
|
+
env,
|
|
159
|
+
type AirJamApp,
|
|
160
|
+
type AirJamAppErrorBoundaryOptions,
|
|
161
|
+
type AirJamRuntimeErrorBoundaryOptions,
|
|
162
|
+
type CreateAirJamAppOptions,
|
|
163
|
+
} from "./runtime/create-air-jam-app";
|
|
164
|
+
export { resolveAirJamBrowserRouterBasename } from "./runtime/router-basename";
|
|
20
165
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
166
|
+
export {
|
|
167
|
+
agentActionInput,
|
|
168
|
+
type AirJamAgentActionCustomOptions,
|
|
169
|
+
type AirJamAgentActionOptions,
|
|
170
|
+
type AirJamAgentActionPayloadKind,
|
|
171
|
+
type AirJamAgentActionPayloadMetadata,
|
|
172
|
+
type InferAirJamAgentActionInputPayload,
|
|
173
|
+
} from "./agent/agent-action";
|
|
174
|
+
export {
|
|
175
|
+
agentAction,
|
|
176
|
+
agentStore,
|
|
177
|
+
defineAirJamAgentContract,
|
|
178
|
+
defineAirJamAgentStores,
|
|
179
|
+
type AirJamAgentActionContract,
|
|
180
|
+
type AirJamAgentActionTarget,
|
|
181
|
+
type AirJamAgentContract,
|
|
182
|
+
type AirJamAgentContractActionOptions,
|
|
183
|
+
type AirJamAgentContractPayloadKind,
|
|
184
|
+
type AirJamAgentContractPayloadMetadata,
|
|
185
|
+
type AirJamAgentJsonObject,
|
|
186
|
+
type AirJamAgentResolvedActionContract,
|
|
187
|
+
type AirJamAgentSnapshotContext,
|
|
188
|
+
type AirJamAgentStoreDeclaration,
|
|
189
|
+
type AirJamAgentStoreDeclarations,
|
|
190
|
+
type AirJamAgentStores,
|
|
191
|
+
type AnyAirJamAgentContract,
|
|
192
|
+
type InferAirJamAgentStores,
|
|
193
|
+
} from "./agent/agent-contract";
|
|
194
|
+
export {
|
|
195
|
+
acceptAirJamAction,
|
|
196
|
+
createAirJamStore,
|
|
197
|
+
rejectAirJamAction,
|
|
198
|
+
type AirJamActionAcceptance,
|
|
199
|
+
type AirJamActionContext,
|
|
200
|
+
type AirJamActionRejection,
|
|
201
|
+
type AirJamHostActionEvent,
|
|
202
|
+
type AirJamHostActionListener,
|
|
203
|
+
type AirJamHostActionSubscriptionOptions,
|
|
204
|
+
type AirJamSyncedStoreHook,
|
|
205
|
+
type CreateAirJamStoreOptions,
|
|
206
|
+
} from "./store/create-air-jam-store";
|
|
27
207
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export * from "./store/create-air-jam-store";
|
|
33
|
-
|
|
34
|
-
// Utilities
|
|
35
|
-
export * from "./utils/ids";
|
|
36
|
-
export * from "./utils/network-ip";
|
|
37
|
-
export * from "./utils/url-builder";
|
|
208
|
+
export type {
|
|
209
|
+
DocumentWithFullscreen,
|
|
210
|
+
ElementWithFullscreen,
|
|
211
|
+
} from "./types/browser";
|