@air-jam/sdk 0.9.1 → 0.9.3
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/README.md +25 -45
- package/dist/{agent-tooling-BSMGBix9.d.cts → agent-contract-CD2QnbBJ.d.cts} +1 -1
- package/dist/{agent-tooling-BSMGBix9.d.ts → agent-contract-CD2QnbBJ.d.ts} +1 -1
- package/dist/agent-tooling.cjs +139 -0
- package/dist/agent-tooling.cjs.map +1 -1
- package/dist/agent-tooling.d.cts +25 -1
- package/dist/agent-tooling.d.ts +25 -1
- package/dist/agent-tooling.js +138 -0
- package/dist/agent-tooling.js.map +1 -1
- package/dist/air-jam-context-BlLPvCup.d.cts +175 -0
- package/dist/air-jam-context-DTsxF-tP.d.ts +175 -0
- package/dist/arcade/bridge/controller.cjs +214 -194
- package/dist/arcade/bridge/controller.cjs.map +1 -1
- package/dist/arcade/bridge/controller.d.cts +2 -2
- package/dist/arcade/bridge/controller.d.ts +2 -2
- package/dist/arcade/bridge/controller.js +6 -4
- package/dist/arcade/bridge/host.cjs +1 -1
- package/dist/arcade/bridge/host.cjs.map +1 -1
- package/dist/arcade/bridge/host.d.cts +3 -3
- package/dist/arcade/bridge/host.d.ts +3 -3
- package/dist/arcade/bridge/host.js +4 -3
- package/dist/arcade/bridge/iframe.cjs +1 -1
- package/dist/arcade/bridge/iframe.cjs.map +1 -1
- package/dist/arcade/bridge/iframe.d.cts +2 -2
- package/dist/arcade/bridge/iframe.d.ts +2 -2
- package/dist/arcade/bridge/iframe.js +4 -4
- package/dist/arcade/bridge.cjs +251 -231
- package/dist/arcade/bridge.cjs.map +1 -1
- package/dist/arcade/bridge.d.cts +4 -4
- package/dist/arcade/bridge.d.ts +4 -4
- package/dist/arcade/bridge.js +9 -7
- package/dist/arcade/host.cjs +145 -122
- package/dist/arcade/host.cjs.map +1 -1
- package/dist/arcade/host.d.cts +5 -4
- package/dist/arcade/host.d.ts +5 -4
- package/dist/arcade/host.js +6 -5
- package/dist/arcade/runtime.cjs +6499 -0
- package/dist/arcade/runtime.cjs.map +1 -0
- package/dist/arcade/runtime.d.cts +22 -0
- package/dist/arcade/runtime.d.ts +22 -0
- package/dist/arcade/runtime.js +32 -0
- package/dist/arcade/runtime.js.map +1 -0
- package/dist/arcade/surface.cjs +9 -0
- package/dist/arcade/surface.cjs.map +1 -1
- package/dist/arcade/surface.d.cts +6 -1
- package/dist/arcade/surface.d.ts +6 -1
- package/dist/arcade/surface.js +6 -2
- package/dist/arcade/url.d.cts +4 -4
- package/dist/arcade/url.d.ts +4 -4
- package/dist/arcade/url.js +5 -5
- package/dist/arcade.cjs +322 -292
- package/dist/arcade.cjs.map +1 -1
- package/dist/arcade.d.cts +6 -6
- package/dist/arcade.d.ts +6 -6
- package/dist/arcade.js +35 -29
- package/dist/{chunk-CEJ5RFSG.js → chunk-2SZ2YYGJ.js} +8 -16
- package/dist/chunk-2SZ2YYGJ.js.map +1 -0
- package/dist/{chunk-VKBMZHMQ.js → chunk-32RSSFSF.js} +10 -12
- package/dist/chunk-32RSSFSF.js.map +1 -0
- package/dist/chunk-3YMUAKPU.js +10 -0
- package/dist/chunk-3YMUAKPU.js.map +1 -0
- package/dist/chunk-56DM2KEW.js +14 -0
- package/dist/chunk-56DM2KEW.js.map +1 -0
- package/dist/chunk-CM53YLT5.js +59 -0
- package/dist/chunk-CM53YLT5.js.map +1 -0
- package/dist/{chunk-JEHV5C2X.js → chunk-CV3PBXPT.js} +3 -3
- package/dist/chunk-D4VDEVTZ.js +80 -0
- package/dist/chunk-D4VDEVTZ.js.map +1 -0
- package/dist/{chunk-W3YA5BWR.js → chunk-FUA6EMSJ.js} +24 -60
- package/dist/chunk-FUA6EMSJ.js.map +1 -0
- package/dist/chunk-GMLU7RI5.js +70 -0
- package/dist/chunk-GMLU7RI5.js.map +1 -0
- package/dist/{chunk-NCL6WJCL.js → chunk-IG6GZZSS.js} +32 -1
- package/dist/chunk-IG6GZZSS.js.map +1 -0
- package/dist/{chunk-EDRQIOCV.js → chunk-ITMQSBTH.js} +3 -2
- package/dist/chunk-ITMQSBTH.js.map +1 -0
- package/dist/{chunk-32NYL7XI.js → chunk-J5MCII33.js} +189 -108
- package/dist/chunk-J5MCII33.js.map +1 -0
- package/dist/{chunk-ZLPL2R3R.js → chunk-K4OZ54UD.js} +7 -34
- package/dist/chunk-K4OZ54UD.js.map +1 -0
- package/dist/{chunk-KXAFI5OP.js → chunk-LIHEEAVE.js} +9 -11
- package/dist/chunk-LIHEEAVE.js.map +1 -0
- package/dist/{chunk-FAT2KJ3K.js → chunk-MIMPMB7O.js} +2 -2
- package/dist/{chunk-NUJBMV3O.js → chunk-O6X7FJ6N.js} +29 -32
- package/dist/chunk-O6X7FJ6N.js.map +1 -0
- package/dist/chunk-PSUYTD2L.js +16 -0
- package/dist/chunk-PSUYTD2L.js.map +1 -0
- package/dist/{chunk-7UXSWCZZ.js → chunk-QO4KFUEI.js} +2 -2
- package/dist/chunk-QTLYZADF.js +125 -0
- package/dist/chunk-QTLYZADF.js.map +1 -0
- package/dist/chunk-TTQDHKXL.js +3017 -0
- package/dist/chunk-TTQDHKXL.js.map +1 -0
- package/dist/chunk-UCPY7UJC.js +8 -0
- package/dist/chunk-UCPY7UJC.js.map +1 -0
- package/dist/{chunk-JO2HR5PV.js → chunk-UPV6YWT5.js} +4 -4
- package/dist/chunk-X35LLCWV.js +65 -0
- package/dist/chunk-X35LLCWV.js.map +1 -0
- package/dist/{controller-DxVchfiA.d.ts → controller-PZEM_1cH.d.ts} +6 -2
- package/dist/{controller-Bod8YYr1.d.cts → controller-vj82tKm4.d.cts} +6 -2
- package/dist/{dev-log-events-CVAM29hx.d.cts → dev-log-events-BCJKmygo.d.cts} +0 -3
- package/dist/{dev-log-events-CVAM29hx.d.ts → dev-log-events-BCJKmygo.d.ts} +0 -3
- package/dist/{host-8hmq_Sgc.d.cts → host-B9pRy0Aa.d.cts} +20 -7
- package/dist/{host-Cw-N6e-5.d.ts → host-DylGsX7p.d.ts} +20 -7
- package/dist/index.cjs +4275 -3813
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -642
- package/dist/index.d.ts +40 -642
- package/dist/index.js +1032 -3658
- package/dist/index.js.map +1 -1
- package/dist/metadata.cjs.map +1 -1
- package/dist/metadata.d.cts +2 -3
- package/dist/metadata.d.ts +2 -3
- package/dist/metadata.js.map +1 -1
- package/dist/{notices-CnGaaS8B.d.ts → notices-C4bao3oi.d.ts} +1 -1
- package/dist/{notices-NyDM5Mtz.d.cts → notices-DNdOjwtj.d.cts} +1 -1
- package/dist/platform-machine.cjs +115 -15
- package/dist/platform-machine.cjs.map +1 -1
- package/dist/platform-machine.d.cts +1338 -65
- package/dist/platform-machine.d.ts +1338 -65
- package/dist/platform-machine.js +88 -15
- package/dist/platform-machine.js.map +1 -1
- package/dist/{platform-settings-cuor3i11.d.cts → platform-settings-DUWs4JTy.d.cts} +1 -1
- package/dist/{platform-settings-cuor3i11.d.ts → platform-settings-DUWs4JTy.d.ts} +1 -1
- package/dist/preview.cjs +301 -253
- package/dist/preview.cjs.map +1 -1
- package/dist/preview.d.cts +6 -4
- package/dist/preview.d.ts +6 -4
- package/dist/preview.js +31 -21
- package/dist/preview.js.map +1 -1
- package/dist/protocol.cjs +282 -167
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +74 -21
- package/dist/protocol.d.ts +74 -21
- package/dist/protocol.js +28 -10
- package/dist/release.cjs +37 -0
- package/dist/release.cjs.map +1 -1
- package/dist/release.d.cts +27 -1
- package/dist/release.d.ts +27 -1
- package/dist/release.js +13 -1
- package/dist/runtime-control.cjs +46 -0
- package/dist/runtime-control.cjs.map +1 -0
- package/dist/runtime-control.d.cts +17 -0
- package/dist/runtime-control.d.ts +17 -0
- package/dist/runtime-control.js +8 -0
- package/dist/runtime-control.js.map +1 -0
- package/dist/runtime-inspection.cjs +655 -0
- package/dist/runtime-inspection.cjs.map +1 -0
- package/dist/runtime-inspection.d.cts +47 -0
- package/dist/runtime-inspection.d.ts +47 -0
- package/dist/runtime-inspection.js +30 -0
- package/dist/runtime-inspection.js.map +1 -0
- package/dist/runtime-reporting-pe-eryVz.d.cts +27 -0
- package/dist/runtime-reporting-pe-eryVz.d.ts +27 -0
- package/dist/signals-ZHftIKuc.d.cts +33 -0
- package/dist/signals-ZHftIKuc.d.ts +33 -0
- package/dist/{standard-match-phase-BucA5dYo.d.ts → standard-match-phase-BzSgBYFg.d.ts} +2 -2
- package/dist/{standard-match-phase-U2ra8J-0.d.cts → standard-match-phase-CvJUW8Oe.d.cts} +2 -2
- package/dist/{sync-B6QsNrXz.d.cts → sync-xtPfWhif.d.cts} +1 -45
- package/dist/{sync-B6QsNrXz.d.ts → sync-xtPfWhif.d.ts} +1 -45
- package/dist/ui.cjs +689 -629
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.cts +14 -4
- package/dist/ui.d.ts +14 -4
- package/dist/ui.js +117 -35
- package/dist/ui.js.map +1 -1
- package/dist/use-air-jam-host-COLy8t4s.d.ts +403 -0
- package/dist/use-air-jam-host-DM-ybB3C.d.cts +403 -0
- package/package.json +55 -21
- package/src/agent/agent-contract-conformance.ts +201 -0
- package/src/agent-tooling.ts +5 -0
- package/src/arcade/runtime.ts +6 -0
- package/src/arcade/surface.ts +1 -0
- package/src/components/join-qr-overlay.tsx +115 -31
- package/src/context/air-jam-context.tsx +8 -8
- package/src/context/socket-manager.ts +0 -7
- package/src/dev/browser-log-sink.ts +12 -15
- package/src/events.ts +0 -5
- package/src/hooks/internal/use-controller-runtime-api.ts +110 -21
- package/src/hooks/internal/use-host-runtime-api.ts +306 -49
- package/src/hooks/use-air-jam-controller.ts +9 -9
- package/src/hooks/use-air-jam-host.ts +7 -7
- package/src/hooks/use-get-input.ts +1 -1
- package/src/hooks/use-host-arcade-restore.ts +6 -1
- package/src/hooks/use-host-audio-mute-preference.ts +99 -0
- package/src/index.ts +6 -21
- package/src/metadata/manifest.ts +2 -3
- package/src/platform-machine.ts +109 -12
- package/src/preview/workspace.tsx +48 -29
- package/src/protocol/arcade-platform-actions.ts +19 -1
- package/src/protocol/controller.ts +8 -2
- package/src/protocol/dev-log-events.ts +0 -3
- package/src/protocol/host-grant.ts +58 -140
- package/src/protocol/host.ts +21 -9
- package/src/protocol/runtime-reporting.ts +32 -0
- package/src/protocol/signed-envelope.ts +176 -0
- package/src/protocol/socket-events.ts +8 -10
- package/src/protocol/sync.ts +0 -16
- package/src/protocol.ts +2 -0
- package/src/release.ts +32 -0
- package/src/runtime/admission-retry.ts +62 -0
- package/src/runtime/air-jam-config.ts +6 -16
- package/src/runtime/air-jam-error-boundary.tsx +46 -2
- package/src/runtime/bridge-envelope-args.ts +21 -0
- package/src/runtime/connected-runtime-error-boundary.tsx +31 -0
- package/src/runtime/contracts/control.ts +107 -59
- package/src/runtime/controller-bridge.ts +12 -24
- package/src/runtime/controller-identity.ts +55 -27
- package/src/runtime/controller-realtime-client.ts +8 -47
- package/src/runtime/create-air-jam-app.tsx +21 -13
- package/src/runtime/host-bridge.ts +16 -24
- package/src/runtime/local-reference-game-identity.ts +13 -0
- package/src/runtime/runtime-session-params.ts +4 -64
- package/src/runtime-control.ts +3 -8
- package/src/settings/platform-settings-runtime.tsx +1 -6
- package/src/settings/platform-settings.ts +7 -38
- package/src/state/connection-store.ts +13 -6
- package/src/store/create-air-jam-store.ts +59 -7
- package/src/utils/ids.ts +32 -5
- package/dist/capabilities.cjs +0 -39
- package/dist/capabilities.cjs.map +0 -1
- package/dist/capabilities.d.cts +0 -31
- package/dist/capabilities.d.ts +0 -31
- package/dist/capabilities.js +0 -12
- package/dist/capabilities.js.map +0 -1
- package/dist/chunk-32NYL7XI.js.map +0 -1
- package/dist/chunk-CABEUV65.js +0 -184
- package/dist/chunk-CABEUV65.js.map +0 -1
- package/dist/chunk-CEJ5RFSG.js.map +0 -1
- package/dist/chunk-EDRQIOCV.js.map +0 -1
- package/dist/chunk-KXAFI5OP.js.map +0 -1
- package/dist/chunk-NCL6WJCL.js.map +0 -1
- package/dist/chunk-NUJBMV3O.js.map +0 -1
- package/dist/chunk-VKBMZHMQ.js.map +0 -1
- package/dist/chunk-W3YA5BWR.js.map +0 -1
- package/dist/chunk-ZLPL2R3R.js.map +0 -1
- package/dist/chunk-ZTQ5SP4H.js +0 -9
- package/dist/chunk-ZTQ5SP4H.js.map +0 -1
- package/src/capabilities/manifest.ts +0 -71
- package/src/capabilities.ts +0 -12
- package/src/hooks/internal/use-runtime-control-contract.ts +0 -15
- package/src/hooks/internal/use-runtime-observability-contract.ts +0 -24
- package/src/runtime/contracts/observability.ts +0 -94
- package/src/runtime-observability.ts +0 -9
- /package/dist/{chunk-JEHV5C2X.js.map → chunk-CV3PBXPT.js.map} +0 -0
- /package/dist/{chunk-FAT2KJ3K.js.map → chunk-MIMPMB7O.js.map} +0 -0
- /package/dist/{chunk-7UXSWCZZ.js.map → chunk-QO4KFUEI.js.map} +0 -0
- /package/dist/{chunk-JO2HR5PV.js.map → chunk-UPV6YWT5.js.map} +0 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { R as RoomCode, b as ConnectionStatus, c as RuntimeState, d as ControllerOrientation, f as ControllerRoomSettingsState, g as PlayerProfilePatch, h as ControllerUpdatePlayerProfileAck, i as ControllerLeaveAck, P as PlayerProfile, j as ControllerStatePayload, e as RunMode } from './controller-vj82tKm4.cjs';
|
|
2
|
+
import { A as AirJamRealtimeClient } from './realtime-client-Cu8yVJFw.cjs';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { a as HostControllerActionAck, b as HostRegistrationAck } from './host-B9pRy0Aa.cjs';
|
|
5
|
+
import { C as ControllerPresenceNotice } from './notices-DNdOjwtj.cjs';
|
|
6
|
+
import { H as HapticSignalPayload, T as ToastSignalPayload } from './signals-ZHftIKuc.cjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options for configuring the controller runtime boundary.
|
|
10
|
+
*
|
|
11
|
+
* @example Basic runtime boundary usage (room from URL)
|
|
12
|
+
* ```tsx
|
|
13
|
+
* // URL: https://yourgame.com/controller?room=ABCD
|
|
14
|
+
* <airjam.Controller>
|
|
15
|
+
* <ControllerView />
|
|
16
|
+
* </airjam.Controller>
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example With nickname
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <airjam.Controller
|
|
22
|
+
* nickname={playerName}
|
|
23
|
+
* onState={(state) => {
|
|
24
|
+
* if (state.runtimeState === "playing") startGame();
|
|
25
|
+
* }}
|
|
26
|
+
* >
|
|
27
|
+
* <ControllerView />
|
|
28
|
+
* </airjam.Controller>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
interface AirJamControllerOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Room ID (4-character code) to join.
|
|
34
|
+
* Can also be provided via URL query parameter: `?room=XXXX`
|
|
35
|
+
* The URL parameter takes precedence if both are provided.
|
|
36
|
+
*/
|
|
37
|
+
roomId?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Player nickname to display in the game.
|
|
40
|
+
* If not provided, the server assigns a random label.
|
|
41
|
+
*/
|
|
42
|
+
nickname?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Preset avatar id sent on join (optional).
|
|
45
|
+
*/
|
|
46
|
+
avatarId?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Controller ID for this instance.
|
|
49
|
+
* Auto-generated if not provided. Persists across reconnects.
|
|
50
|
+
*/
|
|
51
|
+
controllerId?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Optional privileged controller capability token.
|
|
54
|
+
* Undefined falls back to `aj_controller_cap` from the URL; null explicitly disables URL token use.
|
|
55
|
+
*/
|
|
56
|
+
capabilityToken?: string | null;
|
|
57
|
+
/**
|
|
58
|
+
* Called when the host sends a state update (game state, messages, etc.)
|
|
59
|
+
*/
|
|
60
|
+
onState?: (state: ControllerStatePayload) => void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Return type of useAirJamController hook.
|
|
64
|
+
*
|
|
65
|
+
* Provides state and functions for a mobile/web controller interface.
|
|
66
|
+
*/
|
|
67
|
+
interface AirJamControllerApi {
|
|
68
|
+
/** Room code this controller is connected to (or attempting to join) */
|
|
69
|
+
roomId: RoomCode | null;
|
|
70
|
+
/** This controller's unique ID */
|
|
71
|
+
controllerId: string | null;
|
|
72
|
+
/** Current connection status */
|
|
73
|
+
connectionStatus: ConnectionStatus;
|
|
74
|
+
/** Last error message, if any */
|
|
75
|
+
lastError?: string;
|
|
76
|
+
/** Current game state (paused or playing) */
|
|
77
|
+
runtimeState: RuntimeState;
|
|
78
|
+
/** Intended controller presentation orientation for the active game UI. */
|
|
79
|
+
controllerOrientation: ControllerOrientation;
|
|
80
|
+
/** Optional message from the host (e.g., "Get Ready!") */
|
|
81
|
+
stateMessage?: string;
|
|
82
|
+
/** Current host-owned room settings mirrored onto the controller. */
|
|
83
|
+
roomSettings: ControllerRoomSettingsState;
|
|
84
|
+
/**
|
|
85
|
+
* Send a system command to the host.
|
|
86
|
+
*
|
|
87
|
+
* @example Pause or resume
|
|
88
|
+
* ```ts
|
|
89
|
+
* controller.sendSystemCommand("pause");
|
|
90
|
+
* controller.sendSystemCommand("resume");
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
sendSystemCommand: (command: "exit" | "pause" | "resume") => void;
|
|
94
|
+
/**
|
|
95
|
+
* Update the player nickname (local draft for next join).
|
|
96
|
+
*/
|
|
97
|
+
setNickname: (value: string) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Update preset avatar id (local draft for next join).
|
|
100
|
+
*/
|
|
101
|
+
setAvatarId: (value: string) => void;
|
|
102
|
+
/**
|
|
103
|
+
* Patch display name and/or avatar on the server without reconnecting.
|
|
104
|
+
* In Arcade (embedded iframe), updates are forwarded through the controller bridge; the room
|
|
105
|
+
* still learns the new name via `server:playerUpdated` (ack payload is not round-tripped).
|
|
106
|
+
*/
|
|
107
|
+
updatePlayerProfile: (patch: PlayerProfilePatch) => Promise<ControllerUpdatePlayerProfileAck>;
|
|
108
|
+
/** Explicitly leave the current room and release the controller binding. */
|
|
109
|
+
leave: () => Promise<ControllerLeaveAck>;
|
|
110
|
+
/** Force reconnection to the room */
|
|
111
|
+
reconnect: () => void;
|
|
112
|
+
/** List of all connected players in the room */
|
|
113
|
+
players: PlayerProfile[];
|
|
114
|
+
/** This controller's current player profile when known. */
|
|
115
|
+
selfPlayer: PlayerProfile | null;
|
|
116
|
+
/** Realtime client for controller events (socket-backed standalone, bridge-backed in arcade embeds) */
|
|
117
|
+
socket: AirJamRealtimeClient | null;
|
|
118
|
+
}
|
|
119
|
+
interface AirJamControllerState {
|
|
120
|
+
roomId: RoomCode | null;
|
|
121
|
+
controllerId: string | null;
|
|
122
|
+
connectionStatus: ConnectionStatus;
|
|
123
|
+
lastError?: string;
|
|
124
|
+
runtimeState: RuntimeState;
|
|
125
|
+
controllerOrientation: ControllerOrientation;
|
|
126
|
+
stateMessage?: string;
|
|
127
|
+
roomSettings: ControllerRoomSettingsState;
|
|
128
|
+
players: PlayerProfile[];
|
|
129
|
+
selfPlayer: PlayerProfile | null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Read the mounted controller runtime API.
|
|
133
|
+
*
|
|
134
|
+
* Use this inside the explicit `airjam.Controller` runtime boundary. Runtime
|
|
135
|
+
* ownership is mounted once at the
|
|
136
|
+
* boundary; child code reads from that runtime through this hook.
|
|
137
|
+
*
|
|
138
|
+
* **Typical usage flow:**
|
|
139
|
+
* 1. Player scans QR code on game screen
|
|
140
|
+
* 2. Opens controller URL with ?room=XXXX parameter
|
|
141
|
+
* 3. Controller auto-connects to the game session
|
|
142
|
+
* 4. Player uses joystick/buttons to send input
|
|
143
|
+
* 5. Receives haptic feedback on game events
|
|
144
|
+
*
|
|
145
|
+
* @returns Controller API with state and functions
|
|
146
|
+
*
|
|
147
|
+
* @example Basic controller setup
|
|
148
|
+
* ```tsx
|
|
149
|
+
* const ControllerView = () => {
|
|
150
|
+
* const controller = useAirJamController();
|
|
151
|
+
*
|
|
152
|
+
* if (controller.connectionStatus !== "connected") {
|
|
153
|
+
* return <div>Connecting to room {controller.roomId}...</div>;
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* return (
|
|
157
|
+
* <div>
|
|
158
|
+
* <p>Connected: {controller.controllerId}</p>
|
|
159
|
+
* <p>Game: {controller.runtimeState}</p>
|
|
160
|
+
* </div>
|
|
161
|
+
* );
|
|
162
|
+
* };
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @example With state callback
|
|
166
|
+
* ```tsx
|
|
167
|
+
* <airjam.Controller
|
|
168
|
+
* onState={(state) => {
|
|
169
|
+
* if (state.message) {
|
|
170
|
+
* showNotification(state.message);
|
|
171
|
+
* }
|
|
172
|
+
* }}
|
|
173
|
+
* >
|
|
174
|
+
* <ControllerView />
|
|
175
|
+
* </airjam.Controller>
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare function useAirJamController(): AirJamControllerApi;
|
|
179
|
+
declare function useAirJamController<TSelected>(selector: (state: AirJamControllerState) => TSelected): TSelected;
|
|
180
|
+
|
|
181
|
+
type JoinUrlStatus = "loading" | "ready" | "unavailable";
|
|
182
|
+
/**
|
|
183
|
+
* Options for configuring the host runtime boundary.
|
|
184
|
+
*
|
|
185
|
+
* @example Runtime boundary usage with callbacks
|
|
186
|
+
* ```tsx
|
|
187
|
+
* <airjam.Host
|
|
188
|
+
* onPlayerJoin={(player) => {
|
|
189
|
+
* console.log(`${player.label} joined!`);
|
|
190
|
+
* spawnPlayerShip(player.id);
|
|
191
|
+
* }}
|
|
192
|
+
* onPlayerLeave={(controllerId) => {
|
|
193
|
+
* console.log(`Player ${controllerId} left`);
|
|
194
|
+
* removePlayerShip(controllerId);
|
|
195
|
+
* }}
|
|
196
|
+
* >
|
|
197
|
+
* <HostView />
|
|
198
|
+
* </airjam.Host>
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @example With custom room ID
|
|
202
|
+
* ```tsx
|
|
203
|
+
* <airjam.Host roomId="GAME1">
|
|
204
|
+
* <HostView />
|
|
205
|
+
* </airjam.Host>
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
interface AirJamHostOptions {
|
|
209
|
+
/**
|
|
210
|
+
* Room ID (4-character code) to use for this session.
|
|
211
|
+
* If not provided, a random room code will be generated.
|
|
212
|
+
* Can also be set via URL query parameter: `?room=XXXX`
|
|
213
|
+
*/
|
|
214
|
+
roomId?: string;
|
|
215
|
+
/**
|
|
216
|
+
* Called when a player successfully joins the room.
|
|
217
|
+
* Use this to spawn player entities, update UI, etc.
|
|
218
|
+
*/
|
|
219
|
+
onPlayerJoin?: (player: PlayerProfile) => void;
|
|
220
|
+
/**
|
|
221
|
+
* Called when a player leaves the room (disconnects or exits).
|
|
222
|
+
* Use this to remove player entities, handle cleanup.
|
|
223
|
+
*/
|
|
224
|
+
onPlayerLeave?: (controllerId: string) => void;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Return type of useAirJamHost hook.
|
|
228
|
+
*
|
|
229
|
+
* Provides all the state and functions needed to run a multiplayer game session.
|
|
230
|
+
*
|
|
231
|
+
* @template TSchema - Zod schema type for input (inferred from provider)
|
|
232
|
+
*/
|
|
233
|
+
interface AirJamHostApi<TSchema extends z.ZodSchema = z.ZodSchema> {
|
|
234
|
+
/** The room code for this session (e.g., "ABCD") */
|
|
235
|
+
roomId: RoomCode;
|
|
236
|
+
/** Full URL for controllers to join (display as QR code) */
|
|
237
|
+
joinUrl: string;
|
|
238
|
+
/** Whether the join URL is still being resolved, ready to render, or unavailable */
|
|
239
|
+
joinUrlStatus: JoinUrlStatus;
|
|
240
|
+
/** Current connection status to the server */
|
|
241
|
+
connectionStatus: ConnectionStatus;
|
|
242
|
+
/** List of currently connected players */
|
|
243
|
+
players: PlayerProfile[];
|
|
244
|
+
/** Full controller-session roster for the current room, including source and lease state. */
|
|
245
|
+
controllers: ControllerPresenceNotice[];
|
|
246
|
+
/** Last error message, if any */
|
|
247
|
+
lastError?: string;
|
|
248
|
+
/** Current run mode (standalone, arcade, platform) */
|
|
249
|
+
mode: RunMode;
|
|
250
|
+
/** Current runtime pause/play state */
|
|
251
|
+
runtimeState: RuntimeState;
|
|
252
|
+
/** Pause the runtime for every connected surface. */
|
|
253
|
+
pauseRuntime: () => void;
|
|
254
|
+
/** Resume the runtime for every connected surface. */
|
|
255
|
+
resumeRuntime: () => void;
|
|
256
|
+
/** Set the runtime pause/play state explicitly. */
|
|
257
|
+
setRuntimeState: (state: RuntimeState) => void;
|
|
258
|
+
/**
|
|
259
|
+
* Send state update to all connected controllers.
|
|
260
|
+
* Use for syncing game state, messages, etc.
|
|
261
|
+
*/
|
|
262
|
+
sendState: (state: ControllerStatePayload) => boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Send a signal (haptic feedback or toast) to controllers.
|
|
265
|
+
*
|
|
266
|
+
* @example Send haptic to specific player
|
|
267
|
+
* ```ts
|
|
268
|
+
* host.sendSignal("HAPTIC", { pattern: "heavy" }, playerId);
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* @example Send toast to all players
|
|
272
|
+
* ```ts
|
|
273
|
+
* host.sendSignal("TOAST", {
|
|
274
|
+
* title: "Round Start!",
|
|
275
|
+
* message: "Game begins in 3 seconds",
|
|
276
|
+
* });
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
sendSignal: {
|
|
280
|
+
(type: "HAPTIC", payload: HapticSignalPayload, targetId?: string): void;
|
|
281
|
+
(type: "TOAST", payload: ToastSignalPayload, targetId?: string): void;
|
|
282
|
+
};
|
|
283
|
+
/** Reconnect to the server */
|
|
284
|
+
reconnect: () => void;
|
|
285
|
+
/** Remove one controller from the room immediately. */
|
|
286
|
+
removeController: (controllerId: string) => Promise<HostControllerActionAck>;
|
|
287
|
+
/** Tear down the current room and create a fresh empty room for this host. */
|
|
288
|
+
resetRoom: () => Promise<HostRegistrationAck>;
|
|
289
|
+
/** Realtime client for host events (socket-backed standalone, bridge-backed in arcade embeds) */
|
|
290
|
+
socket: AirJamRealtimeClient;
|
|
291
|
+
/**
|
|
292
|
+
* Get the latest input from a specific controller.
|
|
293
|
+
*
|
|
294
|
+
* Returns validated, typed input based on the schema provided to the session provider.
|
|
295
|
+
* Input behavior defaults are tap-safe booleans (`pulse`) and latest vectors (`latest`),
|
|
296
|
+
* with optional per-field overrides.
|
|
297
|
+
*
|
|
298
|
+
* @example In a game loop
|
|
299
|
+
* ```ts
|
|
300
|
+
* useFrame(() => {
|
|
301
|
+
* players.forEach((player) => {
|
|
302
|
+
* const input = host.getInput(player.id);
|
|
303
|
+
* if (input?.action) {
|
|
304
|
+
* fireWeapon(player.id);
|
|
305
|
+
* }
|
|
306
|
+
* movePlayer(player.id, input?.vector ?? { x: 0, y: 0 });
|
|
307
|
+
* });
|
|
308
|
+
* });
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
getInput: (controllerId: string) => z.infer<TSchema> | undefined;
|
|
312
|
+
}
|
|
313
|
+
interface AirJamHostState {
|
|
314
|
+
roomId: RoomCode | null;
|
|
315
|
+
connectionStatus: ConnectionStatus;
|
|
316
|
+
players: PlayerProfile[];
|
|
317
|
+
controllers: ControllerPresenceNotice[];
|
|
318
|
+
lastError?: string;
|
|
319
|
+
mode: RunMode;
|
|
320
|
+
runtimeState: RuntimeState;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Read the mounted host runtime API.
|
|
324
|
+
*
|
|
325
|
+
* Use this inside the explicit `airjam.Host` runtime boundary. Runtime ownership
|
|
326
|
+
* is mounted once at the boundary; child
|
|
327
|
+
* code reads from that runtime through this hook.
|
|
328
|
+
*
|
|
329
|
+
* This hook is runtime-aware:
|
|
330
|
+
* - standalone: creates/reconnects host rooms directly
|
|
331
|
+
* - arcade iframe runtime: auto-detects `aj_room` + `aj_cap` and bridges through the platform-owned host session
|
|
332
|
+
*
|
|
333
|
+
* This hook no longer creates host runtime side effects.
|
|
334
|
+
*
|
|
335
|
+
* **Features:**
|
|
336
|
+
* - Automatic room creation and management
|
|
337
|
+
* - Real-time player join/leave events
|
|
338
|
+
* - Typed input with validation and behavior defaults
|
|
339
|
+
* - Haptic feedback and toast notifications
|
|
340
|
+
* - Runtime state synchronization
|
|
341
|
+
*
|
|
342
|
+
* @template TSchema - Zod schema for input validation (from provider)
|
|
343
|
+
* @returns API object with state and functions
|
|
344
|
+
*
|
|
345
|
+
* @example Basic usage
|
|
346
|
+
* ```tsx
|
|
347
|
+
* const HostView = () => {
|
|
348
|
+
* const host = useAirJamHost();
|
|
349
|
+
*
|
|
350
|
+
* return (
|
|
351
|
+
* <div>
|
|
352
|
+
* <h1>Room: {host.roomId}</h1>
|
|
353
|
+
* <QRCode value={host.joinUrl} />
|
|
354
|
+
* <p>Players: {host.players.length}</p>
|
|
355
|
+
* <button
|
|
356
|
+
* onClick={
|
|
357
|
+
* host.runtimeState === "playing"
|
|
358
|
+
* ? host.pauseRuntime
|
|
359
|
+
* : host.resumeRuntime
|
|
360
|
+
* }
|
|
361
|
+
* >
|
|
362
|
+
* {host.runtimeState === "playing" ? "Pause" : "Resume"}
|
|
363
|
+
* </button>
|
|
364
|
+
* </div>
|
|
365
|
+
* );
|
|
366
|
+
* };
|
|
367
|
+
* ```
|
|
368
|
+
*
|
|
369
|
+
* @example Reading input in a game loop
|
|
370
|
+
* ```tsx
|
|
371
|
+
* const GameScene = () => {
|
|
372
|
+
* const host = useAirJamHost();
|
|
373
|
+
*
|
|
374
|
+
* useFrame(() => {
|
|
375
|
+
* host.players.forEach((player) => {
|
|
376
|
+
* const input = host.getInput(player.id);
|
|
377
|
+
* if (!input) return;
|
|
378
|
+
*
|
|
379
|
+
* // Move player based on joystick
|
|
380
|
+
* movePlayer(player.id, input.vector);
|
|
381
|
+
*
|
|
382
|
+
* // Handle button press (tap-safe pulse default)
|
|
383
|
+
* if (input.action) {
|
|
384
|
+
* playerShoot(player.id);
|
|
385
|
+
* }
|
|
386
|
+
* });
|
|
387
|
+
* });
|
|
388
|
+
*
|
|
389
|
+
* return <GameCanvas />;
|
|
390
|
+
* };
|
|
391
|
+
* ```
|
|
392
|
+
*
|
|
393
|
+
* @example Sending haptic feedback
|
|
394
|
+
* ```tsx
|
|
395
|
+
* const handleHit = (playerId: string) => {
|
|
396
|
+
* host.sendSignal("HAPTIC", { pattern: "heavy" }, playerId);
|
|
397
|
+
* };
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
declare function useAirJamHost<TSchema extends z.ZodSchema = z.ZodSchema>(): AirJamHostApi<TSchema>;
|
|
401
|
+
declare function useAirJamHost<TSelected>(selector: (state: AirJamHostState) => TSelected): TSelected;
|
|
402
|
+
|
|
403
|
+
export { type AirJamControllerOptions as A, type JoinUrlStatus as J, type AirJamHostOptions as a, type AirJamControllerApi as b, type AirJamHostApi as c, type AirJamControllerState as d, useAirJamHost as e, type AirJamHostState as f, useAirJamController as u };
|
package/package.json
CHANGED
|
@@ -1,34 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@air-jam/sdk",
|
|
3
|
-
"version": "0.9.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.9.3",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=22.0.0"
|
|
6
|
+
},
|
|
7
|
+
"description": "SDK for building Air Jam games — phone-controller multiplayer party games with React, host-authoritative state sync, and QR-code joining.",
|
|
5
8
|
"private": false,
|
|
6
9
|
"type": "module",
|
|
7
10
|
"license": "MIT",
|
|
8
11
|
"repository": {
|
|
9
12
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/vucinatim/
|
|
13
|
+
"url": "git+https://github.com/vucinatim/air-jam.git",
|
|
11
14
|
"directory": "packages/sdk"
|
|
12
15
|
},
|
|
13
|
-
"homepage": "https://github.com/vucinatim/
|
|
16
|
+
"homepage": "https://github.com/vucinatim/air-jam#readme",
|
|
14
17
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/vucinatim/
|
|
18
|
+
"url": "https://github.com/vucinatim/air-jam/issues"
|
|
16
19
|
},
|
|
17
20
|
"publishConfig": {
|
|
18
21
|
"access": "public"
|
|
19
22
|
},
|
|
20
23
|
"keywords": [
|
|
21
24
|
"air-jam",
|
|
22
|
-
"
|
|
25
|
+
"airjam",
|
|
26
|
+
"airconsole",
|
|
27
|
+
"airconsole-alternative",
|
|
23
28
|
"multiplayer",
|
|
29
|
+
"multiplayer-game",
|
|
30
|
+
"party-game",
|
|
31
|
+
"party-games",
|
|
32
|
+
"phone-controller",
|
|
33
|
+
"mobile-controller",
|
|
34
|
+
"qr-code",
|
|
35
|
+
"gyroscope",
|
|
24
36
|
"sdk",
|
|
25
37
|
"react",
|
|
26
38
|
"typescript",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
39
|
+
"zustand",
|
|
40
|
+
"zod",
|
|
41
|
+
"game",
|
|
42
|
+
"game-development",
|
|
43
|
+
"gamedev",
|
|
44
|
+
"gaming",
|
|
45
|
+
"websocket",
|
|
30
46
|
"socket.io",
|
|
31
|
-
"
|
|
47
|
+
"real-time",
|
|
48
|
+
"ai-native",
|
|
49
|
+
"vibe-coding"
|
|
32
50
|
],
|
|
33
51
|
"main": "./dist/index.cjs",
|
|
34
52
|
"module": "./dist/index.js",
|
|
@@ -74,6 +92,11 @@
|
|
|
74
92
|
"import": "./dist/arcade/host.js",
|
|
75
93
|
"require": "./dist/arcade/host.cjs"
|
|
76
94
|
},
|
|
95
|
+
"./arcade/runtime": {
|
|
96
|
+
"types": "./dist/arcade/runtime.d.ts",
|
|
97
|
+
"import": "./dist/arcade/runtime.js",
|
|
98
|
+
"require": "./dist/arcade/runtime.cjs"
|
|
99
|
+
},
|
|
77
100
|
"./arcade/surface": {
|
|
78
101
|
"types": "./dist/arcade/surface.d.ts",
|
|
79
102
|
"import": "./dist/arcade/surface.js",
|
|
@@ -89,11 +112,6 @@
|
|
|
89
112
|
"import": "./dist/protocol.js",
|
|
90
113
|
"require": "./dist/protocol.cjs"
|
|
91
114
|
},
|
|
92
|
-
"./capabilities": {
|
|
93
|
-
"types": "./dist/capabilities.d.ts",
|
|
94
|
-
"import": "./dist/capabilities.js",
|
|
95
|
-
"require": "./dist/capabilities.cjs"
|
|
96
|
-
},
|
|
97
115
|
"./metadata": {
|
|
98
116
|
"types": "./dist/metadata.d.ts",
|
|
99
117
|
"import": "./dist/metadata.js",
|
|
@@ -129,6 +147,16 @@
|
|
|
129
147
|
"import": "./dist/runtime-topology.js",
|
|
130
148
|
"require": "./dist/runtime-topology.cjs"
|
|
131
149
|
},
|
|
150
|
+
"./runtime-control": {
|
|
151
|
+
"types": "./dist/runtime-control.d.ts",
|
|
152
|
+
"import": "./dist/runtime-control.js",
|
|
153
|
+
"require": "./dist/runtime-control.cjs"
|
|
154
|
+
},
|
|
155
|
+
"./runtime-inspection": {
|
|
156
|
+
"types": "./dist/runtime-inspection.d.ts",
|
|
157
|
+
"import": "./dist/runtime-inspection.js",
|
|
158
|
+
"require": "./dist/runtime-inspection.cjs"
|
|
159
|
+
},
|
|
132
160
|
"./styles.css": "./src/styles.css"
|
|
133
161
|
},
|
|
134
162
|
"files": [
|
|
@@ -158,6 +186,9 @@
|
|
|
158
186
|
"arcade/host": [
|
|
159
187
|
"dist/arcade/host.d.ts"
|
|
160
188
|
],
|
|
189
|
+
"arcade/runtime": [
|
|
190
|
+
"dist/arcade/runtime.d.ts"
|
|
191
|
+
],
|
|
161
192
|
"arcade/surface": [
|
|
162
193
|
"dist/arcade/surface.d.ts"
|
|
163
194
|
],
|
|
@@ -167,9 +198,6 @@
|
|
|
167
198
|
"protocol": [
|
|
168
199
|
"dist/protocol.d.ts"
|
|
169
200
|
],
|
|
170
|
-
"capabilities": [
|
|
171
|
-
"dist/capabilities.d.ts"
|
|
172
|
-
],
|
|
173
201
|
"metadata": [
|
|
174
202
|
"dist/metadata.d.ts"
|
|
175
203
|
],
|
|
@@ -188,6 +216,12 @@
|
|
|
188
216
|
"runtime-topology": [
|
|
189
217
|
"dist/runtime-topology.d.ts"
|
|
190
218
|
],
|
|
219
|
+
"runtime-control": [
|
|
220
|
+
"dist/runtime-control.d.ts"
|
|
221
|
+
],
|
|
222
|
+
"runtime-inspection": [
|
|
223
|
+
"dist/runtime-inspection.d.ts"
|
|
224
|
+
],
|
|
191
225
|
"preview": [
|
|
192
226
|
"dist/preview.d.ts"
|
|
193
227
|
]
|
|
@@ -200,9 +234,9 @@
|
|
|
200
234
|
"clsx": "^2.1.1",
|
|
201
235
|
"howler": "^2.2.4",
|
|
202
236
|
"lucide-react": "^0.554.0",
|
|
203
|
-
"nanoid": "^5.1.
|
|
237
|
+
"nanoid": "^5.1.16",
|
|
204
238
|
"qrcode": "^1.5.4",
|
|
205
|
-
"socket.io-client": "^4.8.
|
|
239
|
+
"socket.io-client": "^4.8.3",
|
|
206
240
|
"tailwind-merge": "^2.5.5",
|
|
207
241
|
"zod": "^4.2.1",
|
|
208
242
|
"zustand": "^5.0.3"
|
|
@@ -228,6 +262,6 @@
|
|
|
228
262
|
"test": "vitest run --config vitest.config.ts",
|
|
229
263
|
"test:watch": "vitest --config vitest.config.ts",
|
|
230
264
|
"typecheck": "tsc --noEmit && tsc -p tests/tsconfig.json --noEmit",
|
|
231
|
-
"dev": "tsup --watch --no-clean"
|
|
265
|
+
"dev": "tsup --watch src --no-clean"
|
|
232
266
|
}
|
|
233
267
|
}
|