@air-jam/sdk 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-XSXI3RIS.js → chunk-7M5D3Y3L.js} +2 -2
- package/dist/{chunk-XSXI3RIS.js.map → chunk-7M5D3Y3L.js.map} +1 -1
- package/dist/index.cjs +2209 -1893
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -16
- package/dist/index.d.ts +80 -16
- package/dist/index.js +1984 -1673
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +24 -1
- package/dist/protocol.d.ts +24 -1
- package/dist/protocol.js +1 -1
- package/package.json +2 -1
- package/src/components/air-jam-debug.tsx +77 -0
- package/src/components/air-jam-overlay.tsx +243 -186
- package/src/components/controller-shell.tsx +17 -24
- package/src/components/debug-state-dialog.tsx +83 -0
- package/src/components/player-avatar.tsx +64 -0
- package/src/components/ui/button.tsx +1 -1
- package/src/components/ui/dialog.tsx +122 -0
- package/src/index.ts +6 -0
- package/src/protocol.ts +27 -0
- package/src/store/create-air-jam-store.ts +212 -0
- package/src/store/index.ts +1 -0
package/dist/protocol.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocol.ts"],"names":["z","ErrorCode"],"mappings":";;;;;AAiBO,IAAM,iBAAiBA,KAAA,CAC3B,MAAA,EAAO,CACP,IAAA,GACA,GAAA,CAAI,CAAC,CAAA,CACL,GAAA,CAAI,CAAC,CAAA,CACL,KAAA,CAAM,eAAe,EAAE,OAAA,EAAS,0CAA0C;AAEtE,IAAM,qBAAA,GAAwBA,MAAE,MAAA,CAAO;AAAA,EAC5C,MAAA,EAAQ,cAAA;AAAA,EACR,YAAA,EAAcA,KAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EAC9B,KAAA,EAAOA,MAAE,MAAA,CAAOA,KAAA,CAAE,Q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AAQ,cAAA;AAAA,EACR,MAAA,EAAQA,MAAE,MAAA,EAAO;AAAA,EACjB,OAAA,EAASA,KAAA,CAAE,MAAA,EAAO,CAAE,GAAA;AACtB,CAAC;AAIM,IAAM,qBAAA,GAAwBA,MAAE,MAAA,CAAO;AAAA,EAC5C,MAAA,EAAQ,cAAA;AAAA,EACR,SAAA,EAAWA,MAAE,MAAA;AACf,CAAC;AAkFM,IAAM,mBAAA,GAAsB","file":"protocol.cjs","sourcesContent":["import { z } from \"zod\";\n\nexport type RoomCode = string;\n\nexport type ConnectionRole = \"host\" | \"controller\";\n\nexport type ConnectionStatus =\n | \"idle\"\n | \"connecting\"\n | \"connected\"\n | \"disconnected\"\n | \"reconnecting\";\n\nexport type RunMode = \"standalone\" | \"platform\";\n\nexport type GameState = \"paused\" | \"playing\";\n\nexport const roomCodeSchema = z\n .string()\n .trim()\n .min(4)\n .max(8)\n .regex(/^[A-Z0-9]+$/, { message: \"room code must contain only A-Z or 0-9\" });\n\nexport const controllerInputSchema = z.object({\n roomId: roomCodeSchema,\n controllerId: z.string().min(3),\n input: z.record(z.string(), z.unknown()), // Arbitrary JSON object - developers define their own structure\n});\n\nexport type ControllerInputPayload = Record<string, unknown>;\n\nexport interface ControllerInputEvent {\n roomId: RoomCode;\n controllerId: string;\n input: ControllerInputPayload;\n}\n\nexport const controllerStateSchema = z.object({\n roomId: roomCodeSchema,\n state: z.object({\n orientation: z.enum([\"portrait\", \"landscape\"]).optional(),\n message: z.string().optional(),\n gameState: z.enum([\"paused\", \"playing\"]).optional(),\n }),\n});\n\nexport type ControllerStateMessage = z.infer<typeof controllerStateSchema>;\n\nexport type ControllerStatePayload = z.infer<\n typeof controllerStateSchema\n>[\"state\"];\n\nexport const hostRegistrationSchema = z.object({\n roomId: roomCodeSchema,\n maxPlayers: z.number().int().min(1).max(16).default(8),\n apiKey: z.string().optional(),\n mode: z.enum([\"master\", \"child\"]).default(\"child\"),\n controllerUrl: z.string().url().optional(),\n});\n\nexport type HostRegistrationPayload = z.infer<typeof hostRegistrationSchema>;\n\nexport const controllerJoinSchema = z.object({\n roomId: roomCodeSchema,\n controllerId: z.string().min(3),\n nickname: z.string().trim().min(1).max(24).optional(),\n});\n\nexport type ControllerJoinPayload = z.infer<typeof controllerJoinSchema>;\n\nexport const controllerLeaveSchema = z.object({\n roomId: roomCodeSchema,\n controllerId: z.string().min(3),\n});\n\nexport type ControllerLeavePayload = z.infer<typeof controllerLeaveSchema>;\n\nexport interface PlayerProfile {\n id: string;\n label: string;\n color?: string;\n}\n\nexport interface HostRegistrationAck {\n ok: boolean;\n roomId?: RoomCode;\n message?: string;\n code?: ErrorCode | string;\n}\n\nexport interface ControllerJoinAck {\n ok: boolean;\n controllerId?: string;\n roomId?: RoomCode;\n message?: string;\n code?: ErrorCode | string;\n}\n\nexport const controllerSystemSchema = z.object({\n roomId: roomCodeSchema,\n command: z.enum([\"exit\", \"ready\", \"toggle_pause\"]),\n});\n\nexport type ControllerSystemPayload = z.infer<typeof controllerSystemSchema>;\n\n/**\n * Standard error codes for Air Jam\n */\nexport enum ErrorCode {\n // Room errors\n ROOM_NOT_FOUND = \"ROOM_NOT_FOUND\",\n ROOM_FULL = \"ROOM_FULL\",\n\n // Auth errors\n INVALID_API_KEY = \"INVALID_API_KEY\",\n UNAUTHORIZED = \"UNAUTHORIZED\",\n\n // Token errors\n INVALID_TOKEN = \"INVALID_TOKEN\",\n TOKEN_EXPIRED = \"TOKEN_EXPIRED\",\n\n // Connection errors\n CONNECTION_FAILED = \"CONNECTION_FAILED\",\n ALREADY_CONNECTED = \"ALREADY_CONNECTED\",\n\n // Validation errors\n INVALID_PAYLOAD = \"INVALID_PAYLOAD\",\n INVALID_ROOM_CODE = \"INVALID_ROOM_CODE\",\n\n // Server errors\n INTERNAL_SERVER_ERROR = \"INTERNAL_SERVER_ERROR\",\n SERVICE_UNAVAILABLE = \"SERVICE_UNAVAILABLE\",\n\n // Generic\n UNKNOWN_ERROR = \"UNKNOWN_ERROR\",\n}\n\n/**\n * Standardized error payload\n */\nexport interface ServerErrorPayload {\n code: ErrorCode | string; // Allow custom codes\n message: string;\n details?: unknown;\n}\n\nexport interface ControllerWelcomePayload {\n controllerId: string;\n roomId: RoomCode;\n player?: PlayerProfile;\n}\n\nexport interface ControllerJoinedNotice {\n controllerId: string;\n nickname?: string;\n player?: PlayerProfile;\n}\n\nexport interface ControllerLeftNotice {\n controllerId: string;\n}\n\nexport interface RoomReadyNotice {\n roomId: RoomCode;\n}\n\nexport interface HostLeftNotice {\n roomId: RoomCode;\n reason: string;\n}\n\nexport type SignalType = \"HAPTIC\" | \"TOAST\";\n\nexport interface HapticSignalPayload {\n pattern: \"light\" | \"medium\" | \"heavy\" | \"success\" | \"failure\" | \"custom\";\n sequence?: number | number[];\n}\n\nexport interface ToastSignalPayload {\n message: string;\n color?: string;\n duration?: number;\n}\n\nexport type SignalPayload =\n | {\n targetId?: string;\n type: \"HAPTIC\";\n payload: HapticSignalPayload;\n }\n | {\n targetId?: string;\n type: \"TOAST\";\n payload: ToastSignalPayload;\n };\n\nexport interface PlaySoundEventPayload {\n roomId: string;\n targetControllerId?: string; // If null, broadcast to all\n soundId: string;\n volume?: number;\n loop?: boolean;\n}\n\nexport const hostRegisterSystemSchema = z.object({\n roomId: roomCodeSchema,\n apiKey: z.string().optional(),\n});\n\nexport type HostRegisterSystemPayload = z.infer<\n typeof hostRegisterSystemSchema\n>;\n\nexport const systemLaunchGameSchema = z.object({\n roomId: roomCodeSchema,\n gameId: z.string(),\n gameUrl: z.string().url(),\n});\n\nexport type SystemLaunchGamePayload = z.infer<typeof systemLaunchGameSchema>;\n\nexport const hostJoinAsChildSchema = z.object({\n roomId: roomCodeSchema,\n joinToken: z.string(),\n});\n\nexport type HostJoinAsChildPayload = z.infer<typeof hostJoinAsChildSchema>;\n\nexport interface SystemLaunchGameAck {\n ok: boolean;\n joinToken?: string;\n message?: string;\n code?: ErrorCode | string;\n}\n\nexport interface ClientLoadUiPayload {\n url: string;\n}\n\nexport interface ClientToServerEvents {\n \"host:register\": (\n payload: z.infer<typeof hostRegistrationSchema>,\n callback: (ack: HostRegistrationAck) => void,\n ) => void;\n \"host:registerSystem\": (\n payload: HostRegisterSystemPayload,\n callback: (ack: HostRegistrationAck) => void,\n ) => void;\n \"system:launchGame\": (\n payload: SystemLaunchGamePayload,\n callback: (ack: SystemLaunchGameAck) => void,\n ) => void;\n \"host:joinAsChild\": (\n payload: HostJoinAsChildPayload,\n callback: (ack: HostRegistrationAck) => void,\n ) => void;\n \"system:closeGame\": (payload: { roomId: string }) => void;\n \"host:state\": (payload: z.infer<typeof controllerStateSchema>) => void;\n \"controller:join\": (\n payload: z.infer<typeof controllerJoinSchema>,\n callback: (ack: ControllerJoinAck) => void,\n ) => void;\n \"controller:leave\": (payload: z.infer<typeof controllerLeaveSchema>) => void;\n \"controller:input\": (payload: z.infer<typeof controllerInputSchema>) => void;\n \"controller:system\": (\n payload: z.infer<typeof controllerSystemSchema>,\n ) => void;\n \"host:system\": (payload: z.infer<typeof controllerSystemSchema>) => void;\n \"host:signal\": (payload: SignalPayload) => void;\n \"host:play_sound\": (payload: PlaySoundEventPayload) => void;\n \"controller:play_sound\": (payload: PlaySoundEventPayload) => void;\n}\n\nexport interface PlaySoundPayload {\n id: string;\n volume?: number;\n loop?: boolean;\n}\n\nexport interface ServerToClientEvents {\n \"server:roomReady\": (payload: RoomReadyNotice) => void;\n \"server:controllerJoined\": (payload: ControllerJoinedNotice) => void;\n \"server:controllerLeft\": (payload: ControllerLeftNotice) => void;\n \"server:input\": (payload: ControllerInputEvent) => void;\n \"server:error\": (payload: ServerErrorPayload) => void;\n \"server:state\": (payload: z.infer<typeof controllerStateSchema>) => void;\n \"server:welcome\": (payload: ControllerWelcomePayload) => void;\n \"server:hostLeft\": (payload: HostLeftNotice) => void;\n \"server:signal\": (payload: SignalPayload) => void;\n \"server:playSound\": (payload: PlaySoundPayload) => void;\n \"server:redirect\": (url: string) => void;\n \"server:closeChild\": () => void;\n \"client:loadUi\": (payload: ClientLoadUiPayload) => void;\n \"client:unloadUi\": () => void;\n}\n\nexport interface InterServerEvents {\n ping: () => void;\n}\n\nexport type SocketData = Record<string, unknown>;\n\n// --- Proxy Protocol (iframe <-> parent) ---\n// Note: Proxy protocol is largely deprecated in favor of Direct Connect (airjam_force_connect=true),\n// but might still be used for UI coordination (e.g. hiding headers).\n\nexport const AIRJAM_PROXY_PREFIX = \"AIRJAM_\";\n\nexport interface ProxyMessageBase {\n type: string;\n}\n\nexport interface ProxyReadyMessage extends ProxyMessageBase {\n type: \"AIRJAM_READY\";\n}\n\nexport interface ProxyInputMessage extends ProxyMessageBase {\n type: \"AIRJAM_INPUT\";\n payload: ControllerInputPayload;\n}\n\nexport interface ProxyStateMessage extends ProxyMessageBase {\n type: \"AIRJAM_STATE\";\n payload: ControllerStatePayload;\n}\n\nexport type AirJamProxyMessage =\n | ProxyReadyMessage\n | ProxyInputMessage\n | ProxyStateMessage;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts"],"names":["z","ErrorCode"],"mappings":";;;;;AAiBO,IAAM,iBAAiBA,KAAA,CAC3B,MAAA,EAAO,CACP,IAAA,GACA,GAAA,CAAI,CAAC,CAAA,CACL,GAAA,CAAI,CAAC,CAAA,CACL,KAAA,CAAM,eAAe,EAAE,OAAA,EAAS,0CAA0C;AAEtE,IAAM,qBAAA,GAAwBA,MAAE,MAAA,CAAO;AAAA,EAC5C,MAAA,EAAQ,cAAA;AAAA,EACR,YAAA,EAAcA,KAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EAC9B,KAAA,EAAOA,MAAE,MAAA,CAAOA,KAAA,CAAE,QAAO,EAAGA,KAAA,CAAE,SAAS;AAAA;AACzC,CAAC;AAUM,IAAM,qBAAA,GAAwBA,MAAE,MAAA,CAAO;AAAA,EAC5C,MAAA,EAAQ,cAAA;AAAA,EACR,KAAA,EAAOA,MAAE,MAAA,CAAO;AAAA,IACd,WAAA,EAAaA,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AAQ,cAAA;AAAA,EACR,SAAA,EAAWA,MAAE,MAAA;AACf,CAAC;AA6GM,IAAM,mBAAA,GAAsB","file":"protocol.cjs","sourcesContent":["import { z } from \"zod\";\n\nexport type RoomCode = string;\n\nexport type ConnectionRole = \"host\" | \"controller\";\n\nexport type ConnectionStatus =\n | \"idle\"\n | \"connecting\"\n | \"connected\"\n | \"disconnected\"\n | \"reconnecting\";\n\nexport type RunMode = \"standalone\" | \"platform\";\n\nexport type GameState = \"paused\" | \"playing\";\n\nexport const roomCodeSchema = z\n .string()\n .trim()\n .min(4)\n .max(8)\n .regex(/^[A-Z0-9]+$/, { message: \"room code must contain only A-Z or 0-9\" });\n\nexport const controllerInputSchema = z.object({\n roomId: roomCodeSchema,\n controllerId: z.string().min(3),\n input: z.record(z.string(), z.unknown()), // Arbitrary JSON object - developers define their own structure\n});\n\nexport type ControllerInputPayload = Record<string, unknown>;\n\nexport interface ControllerInputEvent {\n roomId: RoomCode;\n controllerId: string;\n input: ControllerInputPayload;\n}\n\nexport const controllerStateSchema = z.object({\n roomId: roomCodeSchema,\n state: z.object({\n orientation: z.enum([\"portrait\", \"landscape\"]).optional(),\n message: z.string().optional(),\n gameState: z.enum([\"paused\", \"playing\"]).optional(),\n }),\n});\n\nexport type ControllerStateMessage = z.infer<typeof controllerStateSchema>;\n\nexport type ControllerStatePayload = z.infer<\n typeof controllerStateSchema\n>[\"state\"];\n\nexport const hostRegistrationSchema = z.object({\n roomId: roomCodeSchema,\n maxPlayers: z.number().int().min(1).max(16).default(8),\n apiKey: z.string().optional(),\n mode: z.enum([\"master\", \"child\"]).default(\"child\"),\n controllerUrl: z.string().url().optional(),\n});\n\nexport type HostRegistrationPayload = z.infer<typeof hostRegistrationSchema>;\n\nexport const controllerJoinSchema = z.object({\n roomId: roomCodeSchema,\n controllerId: z.string().min(3),\n nickname: z.string().trim().min(1).max(24).optional(),\n});\n\nexport type ControllerJoinPayload = z.infer<typeof controllerJoinSchema>;\n\nexport const controllerLeaveSchema = z.object({\n roomId: roomCodeSchema,\n controllerId: z.string().min(3),\n});\n\nexport type ControllerLeavePayload = z.infer<typeof controllerLeaveSchema>;\n\nexport interface PlayerProfile {\n id: string;\n label: string;\n color?: string;\n}\n\nexport interface HostRegistrationAck {\n ok: boolean;\n roomId?: RoomCode;\n message?: string;\n code?: ErrorCode | string;\n}\n\nexport interface ControllerJoinAck {\n ok: boolean;\n controllerId?: string;\n roomId?: RoomCode;\n message?: string;\n code?: ErrorCode | string;\n}\n\nexport const controllerSystemSchema = z.object({\n roomId: roomCodeSchema,\n command: z.enum([\"exit\", \"ready\", \"toggle_pause\"]),\n});\n\nexport type ControllerSystemPayload = z.infer<typeof controllerSystemSchema>;\n\n/**\n * Standard error codes for Air Jam\n */\nexport enum ErrorCode {\n // Room errors\n ROOM_NOT_FOUND = \"ROOM_NOT_FOUND\",\n ROOM_FULL = \"ROOM_FULL\",\n\n // Auth errors\n INVALID_API_KEY = \"INVALID_API_KEY\",\n UNAUTHORIZED = \"UNAUTHORIZED\",\n\n // Token errors\n INVALID_TOKEN = \"INVALID_TOKEN\",\n TOKEN_EXPIRED = \"TOKEN_EXPIRED\",\n\n // Connection errors\n CONNECTION_FAILED = \"CONNECTION_FAILED\",\n ALREADY_CONNECTED = \"ALREADY_CONNECTED\",\n\n // Validation errors\n INVALID_PAYLOAD = \"INVALID_PAYLOAD\",\n INVALID_ROOM_CODE = \"INVALID_ROOM_CODE\",\n\n // Server errors\n INTERNAL_SERVER_ERROR = \"INTERNAL_SERVER_ERROR\",\n SERVICE_UNAVAILABLE = \"SERVICE_UNAVAILABLE\",\n\n // Generic\n UNKNOWN_ERROR = \"UNKNOWN_ERROR\",\n}\n\n/**\n * Standardized error payload\n */\nexport interface ServerErrorPayload {\n code: ErrorCode | string; // Allow custom codes\n message: string;\n details?: unknown;\n}\n\nexport interface ControllerWelcomePayload {\n controllerId: string;\n roomId: RoomCode;\n player?: PlayerProfile;\n}\n\nexport interface ControllerJoinedNotice {\n controllerId: string;\n nickname?: string;\n player?: PlayerProfile;\n}\n\nexport interface ControllerLeftNotice {\n controllerId: string;\n}\n\nexport interface RoomReadyNotice {\n roomId: RoomCode;\n}\n\nexport interface HostLeftNotice {\n roomId: RoomCode;\n reason: string;\n}\n\nexport type SignalType = \"HAPTIC\" | \"TOAST\";\n\nexport interface HapticSignalPayload {\n pattern: \"light\" | \"medium\" | \"heavy\" | \"success\" | \"failure\" | \"custom\";\n sequence?: number | number[];\n}\n\nexport interface ToastSignalPayload {\n message: string;\n color?: string;\n duration?: number;\n}\n\nexport type SignalPayload =\n | {\n targetId?: string;\n type: \"HAPTIC\";\n payload: HapticSignalPayload;\n }\n | {\n targetId?: string;\n type: \"TOAST\";\n payload: ToastSignalPayload;\n };\n\nexport interface PlaySoundEventPayload {\n roomId: string;\n targetControllerId?: string; // If null, broadcast to all\n soundId: string;\n volume?: number;\n loop?: boolean;\n}\n\nexport const hostRegisterSystemSchema = z.object({\n roomId: roomCodeSchema,\n apiKey: z.string().optional(),\n});\n\nexport type HostRegisterSystemPayload = z.infer<\n typeof hostRegisterSystemSchema\n>;\n\nexport const systemLaunchGameSchema = z.object({\n roomId: roomCodeSchema,\n gameId: z.string(),\n gameUrl: z.string().url(),\n});\n\nexport type SystemLaunchGamePayload = z.infer<typeof systemLaunchGameSchema>;\n\nexport const hostJoinAsChildSchema = z.object({\n roomId: roomCodeSchema,\n joinToken: z.string(),\n});\n\nexport type HostJoinAsChildPayload = z.infer<typeof hostJoinAsChildSchema>;\n\nexport interface SystemLaunchGameAck {\n ok: boolean;\n joinToken?: string;\n message?: string;\n code?: ErrorCode | string;\n}\n\nexport interface ClientLoadUiPayload {\n url: string;\n}\n\nexport interface HostStateSyncPayload {\n roomId: string;\n data: Record<string, unknown>;\n}\n\nexport interface ControllerActionRpcPayload {\n roomId: string;\n actionName: string;\n args: unknown[];\n controllerId: string;\n}\n\nexport interface AirJamStateSyncPayload {\n roomId: string;\n data: Record<string, unknown>;\n}\n\nexport interface AirJamActionRpcPayload {\n actionName: string;\n args: unknown[];\n controllerId: string;\n}\n\nexport interface ClientToServerEvents {\n \"host:register\": (\n payload: z.infer<typeof hostRegistrationSchema>,\n callback: (ack: HostRegistrationAck) => void,\n ) => void;\n \"host:registerSystem\": (\n payload: HostRegisterSystemPayload,\n callback: (ack: HostRegistrationAck) => void,\n ) => void;\n \"system:launchGame\": (\n payload: SystemLaunchGamePayload,\n callback: (ack: SystemLaunchGameAck) => void,\n ) => void;\n \"host:joinAsChild\": (\n payload: HostJoinAsChildPayload,\n callback: (ack: HostRegistrationAck) => void,\n ) => void;\n \"system:closeGame\": (payload: { roomId: string }) => void;\n \"host:state\": (payload: z.infer<typeof controllerStateSchema>) => void;\n \"controller:join\": (\n payload: z.infer<typeof controllerJoinSchema>,\n callback: (ack: ControllerJoinAck) => void,\n ) => void;\n \"controller:leave\": (payload: z.infer<typeof controllerLeaveSchema>) => void;\n \"controller:input\": (payload: z.infer<typeof controllerInputSchema>) => void;\n \"controller:system\": (\n payload: z.infer<typeof controllerSystemSchema>,\n ) => void;\n \"host:system\": (payload: z.infer<typeof controllerSystemSchema>) => void;\n \"host:signal\": (payload: SignalPayload) => void;\n \"host:play_sound\": (payload: PlaySoundEventPayload) => void;\n \"controller:play_sound\": (payload: PlaySoundEventPayload) => void;\n \"host:state_sync\": (payload: HostStateSyncPayload) => void;\n \"controller:action_rpc\": (payload: ControllerActionRpcPayload) => void;\n}\n\nexport interface PlaySoundPayload {\n id: string;\n volume?: number;\n loop?: boolean;\n}\n\nexport interface ServerToClientEvents {\n \"server:roomReady\": (payload: RoomReadyNotice) => void;\n \"server:controllerJoined\": (payload: ControllerJoinedNotice) => void;\n \"server:controllerLeft\": (payload: ControllerLeftNotice) => void;\n \"server:input\": (payload: ControllerInputEvent) => void;\n \"server:error\": (payload: ServerErrorPayload) => void;\n \"server:state\": (payload: z.infer<typeof controllerStateSchema>) => void;\n \"server:welcome\": (payload: ControllerWelcomePayload) => void;\n \"server:hostLeft\": (payload: HostLeftNotice) => void;\n \"server:signal\": (payload: SignalPayload) => void;\n \"server:playSound\": (payload: PlaySoundPayload) => void;\n \"server:redirect\": (url: string) => void;\n \"server:closeChild\": () => void;\n \"client:loadUi\": (payload: ClientLoadUiPayload) => void;\n \"client:unloadUi\": () => void;\n \"airjam:state_sync\": (payload: AirJamStateSyncPayload) => void;\n \"airjam:action_rpc\": (payload: AirJamActionRpcPayload) => void;\n}\n\nexport interface InterServerEvents {\n ping: () => void;\n}\n\nexport type SocketData = Record<string, unknown>;\n\n// --- Proxy Protocol (iframe <-> parent) ---\n// Note: Proxy protocol is largely deprecated in favor of Direct Connect (airjam_force_connect=true),\n// but might still be used for UI coordination (e.g. hiding headers).\n\nexport const AIRJAM_PROXY_PREFIX = \"AIRJAM_\";\n\nexport interface ProxyMessageBase {\n type: string;\n}\n\nexport interface ProxyReadyMessage extends ProxyMessageBase {\n type: \"AIRJAM_READY\";\n}\n\nexport interface ProxyInputMessage extends ProxyMessageBase {\n type: \"AIRJAM_INPUT\";\n payload: ControllerInputPayload;\n}\n\nexport interface ProxyStateMessage extends ProxyMessageBase {\n type: \"AIRJAM_STATE\";\n payload: ControllerStatePayload;\n}\n\nexport type AirJamProxyMessage =\n | ProxyReadyMessage\n | ProxyInputMessage\n | ProxyStateMessage;\n"]}
|
package/dist/protocol.d.cts
CHANGED
|
@@ -179,6 +179,25 @@ interface SystemLaunchGameAck {
|
|
|
179
179
|
interface ClientLoadUiPayload {
|
|
180
180
|
url: string;
|
|
181
181
|
}
|
|
182
|
+
interface HostStateSyncPayload {
|
|
183
|
+
roomId: string;
|
|
184
|
+
data: Record<string, unknown>;
|
|
185
|
+
}
|
|
186
|
+
interface ControllerActionRpcPayload {
|
|
187
|
+
roomId: string;
|
|
188
|
+
actionName: string;
|
|
189
|
+
args: unknown[];
|
|
190
|
+
controllerId: string;
|
|
191
|
+
}
|
|
192
|
+
interface AirJamStateSyncPayload {
|
|
193
|
+
roomId: string;
|
|
194
|
+
data: Record<string, unknown>;
|
|
195
|
+
}
|
|
196
|
+
interface AirJamActionRpcPayload {
|
|
197
|
+
actionName: string;
|
|
198
|
+
args: unknown[];
|
|
199
|
+
controllerId: string;
|
|
200
|
+
}
|
|
182
201
|
interface ClientToServerEvents {
|
|
183
202
|
"host:register": (payload: z.infer<typeof hostRegistrationSchema>, callback: (ack: HostRegistrationAck) => void) => void;
|
|
184
203
|
"host:registerSystem": (payload: HostRegisterSystemPayload, callback: (ack: HostRegistrationAck) => void) => void;
|
|
@@ -196,6 +215,8 @@ interface ClientToServerEvents {
|
|
|
196
215
|
"host:signal": (payload: SignalPayload) => void;
|
|
197
216
|
"host:play_sound": (payload: PlaySoundEventPayload) => void;
|
|
198
217
|
"controller:play_sound": (payload: PlaySoundEventPayload) => void;
|
|
218
|
+
"host:state_sync": (payload: HostStateSyncPayload) => void;
|
|
219
|
+
"controller:action_rpc": (payload: ControllerActionRpcPayload) => void;
|
|
199
220
|
}
|
|
200
221
|
interface PlaySoundPayload {
|
|
201
222
|
id: string;
|
|
@@ -217,6 +238,8 @@ interface ServerToClientEvents {
|
|
|
217
238
|
"server:closeChild": () => void;
|
|
218
239
|
"client:loadUi": (payload: ClientLoadUiPayload) => void;
|
|
219
240
|
"client:unloadUi": () => void;
|
|
241
|
+
"airjam:state_sync": (payload: AirJamStateSyncPayload) => void;
|
|
242
|
+
"airjam:action_rpc": (payload: AirJamActionRpcPayload) => void;
|
|
220
243
|
}
|
|
221
244
|
interface InterServerEvents {
|
|
222
245
|
ping: () => void;
|
|
@@ -239,4 +262,4 @@ interface ProxyStateMessage extends ProxyMessageBase {
|
|
|
239
262
|
}
|
|
240
263
|
type AirJamProxyMessage = ProxyReadyMessage | ProxyInputMessage | ProxyStateMessage;
|
|
241
264
|
|
|
242
|
-
export { AIRJAM_PROXY_PREFIX, type AirJamProxyMessage, type ClientLoadUiPayload, type ClientToServerEvents, type ConnectionRole, type ConnectionStatus, type ControllerInputEvent, type ControllerInputPayload, type ControllerJoinAck, type ControllerJoinPayload, type ControllerJoinedNotice, type ControllerLeavePayload, type ControllerLeftNotice, type ControllerStateMessage, type ControllerStatePayload, type ControllerSystemPayload, type ControllerWelcomePayload, ErrorCode, type GameState, type HapticSignalPayload, type HostJoinAsChildPayload, type HostLeftNotice, type HostRegisterSystemPayload, type HostRegistrationAck, type HostRegistrationPayload, type InterServerEvents, type PlaySoundEventPayload, type PlaySoundPayload, type PlayerProfile, type ProxyInputMessage, type ProxyMessageBase, type ProxyReadyMessage, type ProxyStateMessage, type RoomCode, type RoomReadyNotice, type RunMode, type ServerErrorPayload, type ServerToClientEvents, type SignalPayload, type SignalType, type SocketData, type SystemLaunchGameAck, type SystemLaunchGamePayload, type ToastSignalPayload, controllerInputSchema, controllerJoinSchema, controllerLeaveSchema, controllerStateSchema, controllerSystemSchema, hostJoinAsChildSchema, hostRegisterSystemSchema, hostRegistrationSchema, roomCodeSchema, systemLaunchGameSchema };
|
|
265
|
+
export { AIRJAM_PROXY_PREFIX, type AirJamActionRpcPayload, type AirJamProxyMessage, type AirJamStateSyncPayload, type ClientLoadUiPayload, type ClientToServerEvents, type ConnectionRole, type ConnectionStatus, type ControllerActionRpcPayload, type ControllerInputEvent, type ControllerInputPayload, type ControllerJoinAck, type ControllerJoinPayload, type ControllerJoinedNotice, type ControllerLeavePayload, type ControllerLeftNotice, type ControllerStateMessage, type ControllerStatePayload, type ControllerSystemPayload, type ControllerWelcomePayload, ErrorCode, type GameState, type HapticSignalPayload, type HostJoinAsChildPayload, type HostLeftNotice, type HostRegisterSystemPayload, type HostRegistrationAck, type HostRegistrationPayload, type HostStateSyncPayload, type InterServerEvents, type PlaySoundEventPayload, type PlaySoundPayload, type PlayerProfile, type ProxyInputMessage, type ProxyMessageBase, type ProxyReadyMessage, type ProxyStateMessage, type RoomCode, type RoomReadyNotice, type RunMode, type ServerErrorPayload, type ServerToClientEvents, type SignalPayload, type SignalType, type SocketData, type SystemLaunchGameAck, type SystemLaunchGamePayload, type ToastSignalPayload, controllerInputSchema, controllerJoinSchema, controllerLeaveSchema, controllerStateSchema, controllerSystemSchema, hostJoinAsChildSchema, hostRegisterSystemSchema, hostRegistrationSchema, roomCodeSchema, systemLaunchGameSchema };
|
package/dist/protocol.d.ts
CHANGED
|
@@ -179,6 +179,25 @@ interface SystemLaunchGameAck {
|
|
|
179
179
|
interface ClientLoadUiPayload {
|
|
180
180
|
url: string;
|
|
181
181
|
}
|
|
182
|
+
interface HostStateSyncPayload {
|
|
183
|
+
roomId: string;
|
|
184
|
+
data: Record<string, unknown>;
|
|
185
|
+
}
|
|
186
|
+
interface ControllerActionRpcPayload {
|
|
187
|
+
roomId: string;
|
|
188
|
+
actionName: string;
|
|
189
|
+
args: unknown[];
|
|
190
|
+
controllerId: string;
|
|
191
|
+
}
|
|
192
|
+
interface AirJamStateSyncPayload {
|
|
193
|
+
roomId: string;
|
|
194
|
+
data: Record<string, unknown>;
|
|
195
|
+
}
|
|
196
|
+
interface AirJamActionRpcPayload {
|
|
197
|
+
actionName: string;
|
|
198
|
+
args: unknown[];
|
|
199
|
+
controllerId: string;
|
|
200
|
+
}
|
|
182
201
|
interface ClientToServerEvents {
|
|
183
202
|
"host:register": (payload: z.infer<typeof hostRegistrationSchema>, callback: (ack: HostRegistrationAck) => void) => void;
|
|
184
203
|
"host:registerSystem": (payload: HostRegisterSystemPayload, callback: (ack: HostRegistrationAck) => void) => void;
|
|
@@ -196,6 +215,8 @@ interface ClientToServerEvents {
|
|
|
196
215
|
"host:signal": (payload: SignalPayload) => void;
|
|
197
216
|
"host:play_sound": (payload: PlaySoundEventPayload) => void;
|
|
198
217
|
"controller:play_sound": (payload: PlaySoundEventPayload) => void;
|
|
218
|
+
"host:state_sync": (payload: HostStateSyncPayload) => void;
|
|
219
|
+
"controller:action_rpc": (payload: ControllerActionRpcPayload) => void;
|
|
199
220
|
}
|
|
200
221
|
interface PlaySoundPayload {
|
|
201
222
|
id: string;
|
|
@@ -217,6 +238,8 @@ interface ServerToClientEvents {
|
|
|
217
238
|
"server:closeChild": () => void;
|
|
218
239
|
"client:loadUi": (payload: ClientLoadUiPayload) => void;
|
|
219
240
|
"client:unloadUi": () => void;
|
|
241
|
+
"airjam:state_sync": (payload: AirJamStateSyncPayload) => void;
|
|
242
|
+
"airjam:action_rpc": (payload: AirJamActionRpcPayload) => void;
|
|
220
243
|
}
|
|
221
244
|
interface InterServerEvents {
|
|
222
245
|
ping: () => void;
|
|
@@ -239,4 +262,4 @@ interface ProxyStateMessage extends ProxyMessageBase {
|
|
|
239
262
|
}
|
|
240
263
|
type AirJamProxyMessage = ProxyReadyMessage | ProxyInputMessage | ProxyStateMessage;
|
|
241
264
|
|
|
242
|
-
export { AIRJAM_PROXY_PREFIX, type AirJamProxyMessage, type ClientLoadUiPayload, type ClientToServerEvents, type ConnectionRole, type ConnectionStatus, type ControllerInputEvent, type ControllerInputPayload, type ControllerJoinAck, type ControllerJoinPayload, type ControllerJoinedNotice, type ControllerLeavePayload, type ControllerLeftNotice, type ControllerStateMessage, type ControllerStatePayload, type ControllerSystemPayload, type ControllerWelcomePayload, ErrorCode, type GameState, type HapticSignalPayload, type HostJoinAsChildPayload, type HostLeftNotice, type HostRegisterSystemPayload, type HostRegistrationAck, type HostRegistrationPayload, type InterServerEvents, type PlaySoundEventPayload, type PlaySoundPayload, type PlayerProfile, type ProxyInputMessage, type ProxyMessageBase, type ProxyReadyMessage, type ProxyStateMessage, type RoomCode, type RoomReadyNotice, type RunMode, type ServerErrorPayload, type ServerToClientEvents, type SignalPayload, type SignalType, type SocketData, type SystemLaunchGameAck, type SystemLaunchGamePayload, type ToastSignalPayload, controllerInputSchema, controllerJoinSchema, controllerLeaveSchema, controllerStateSchema, controllerSystemSchema, hostJoinAsChildSchema, hostRegisterSystemSchema, hostRegistrationSchema, roomCodeSchema, systemLaunchGameSchema };
|
|
265
|
+
export { AIRJAM_PROXY_PREFIX, type AirJamActionRpcPayload, type AirJamProxyMessage, type AirJamStateSyncPayload, type ClientLoadUiPayload, type ClientToServerEvents, type ConnectionRole, type ConnectionStatus, type ControllerActionRpcPayload, type ControllerInputEvent, type ControllerInputPayload, type ControllerJoinAck, type ControllerJoinPayload, type ControllerJoinedNotice, type ControllerLeavePayload, type ControllerLeftNotice, type ControllerStateMessage, type ControllerStatePayload, type ControllerSystemPayload, type ControllerWelcomePayload, ErrorCode, type GameState, type HapticSignalPayload, type HostJoinAsChildPayload, type HostLeftNotice, type HostRegisterSystemPayload, type HostRegistrationAck, type HostRegistrationPayload, type HostStateSyncPayload, type InterServerEvents, type PlaySoundEventPayload, type PlaySoundPayload, type PlayerProfile, type ProxyInputMessage, type ProxyMessageBase, type ProxyReadyMessage, type ProxyStateMessage, type RoomCode, type RoomReadyNotice, type RunMode, type ServerErrorPayload, type ServerToClientEvents, type SignalPayload, type SignalType, type SocketData, type SystemLaunchGameAck, type SystemLaunchGamePayload, type ToastSignalPayload, controllerInputSchema, controllerJoinSchema, controllerLeaveSchema, controllerStateSchema, controllerSystemSchema, hostJoinAsChildSchema, hostRegisterSystemSchema, hostRegistrationSchema, roomCodeSchema, systemLaunchGameSchema };
|
package/dist/protocol.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { AIRJAM_PROXY_PREFIX, ErrorCode, controllerInputSchema, controllerJoinSchema, controllerLeaveSchema, controllerStateSchema, controllerSystemSchema, hostJoinAsChildSchema, hostRegisterSystemSchema, hostRegistrationSchema, roomCodeSchema, systemLaunchGameSchema } from './chunk-
|
|
1
|
+
export { AIRJAM_PROXY_PREFIX, ErrorCode, controllerInputSchema, controllerJoinSchema, controllerLeaveSchema, controllerStateSchema, controllerSystemSchema, hostJoinAsChildSchema, hostRegisterSystemSchema, hostRegistrationSchema, roomCodeSchema, systemLaunchGameSchema } from './chunk-7M5D3Y3L.js';
|
|
2
2
|
//# sourceMappingURL=protocol.js.map
|
|
3
3
|
//# sourceMappingURL=protocol.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@air-jam/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "The core SDK for building Air Jam games and controllers",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"dev": "tsup --watch"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
+
"@radix-ui/react-dialog": "^1.1.15",
|
|
53
54
|
"@radix-ui/react-slider": "^1.3.6",
|
|
54
55
|
"@radix-ui/react-slot": "^1.2.4",
|
|
55
56
|
"@radix-ui/react-tabs": "^1.1.13",
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Bug } from "lucide-react";
|
|
2
|
+
import type { JSX } from "react";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { DebugStateDialog } from "./debug-state-dialog";
|
|
5
|
+
import { Button } from "./ui/button";
|
|
6
|
+
|
|
7
|
+
interface AirJamDebugProps {
|
|
8
|
+
state: unknown;
|
|
9
|
+
title?: string;
|
|
10
|
+
updateInterval?: number;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A debug component that displays state in a dialog.
|
|
16
|
+
* Place this component anywhere in your React tree and pass the state you want to debug.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const { phase, scores } = useGameStore((state) => state);
|
|
21
|
+
*
|
|
22
|
+
* return (
|
|
23
|
+
* <div>
|
|
24
|
+
* <AirJamDebug state={{ phase, scores }} />
|
|
25
|
+
* {/* Your game UI *\/}
|
|
26
|
+
* </div>
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export const AirJamDebug = ({
|
|
31
|
+
state,
|
|
32
|
+
title = "Debug State",
|
|
33
|
+
updateInterval = 100,
|
|
34
|
+
className,
|
|
35
|
+
}: AirJamDebugProps): JSX.Element => {
|
|
36
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
37
|
+
const [currentState, setCurrentState] = useState(state);
|
|
38
|
+
|
|
39
|
+
// Update state periodically when dialog is open
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!isOpen) return;
|
|
42
|
+
|
|
43
|
+
const interval = setInterval(() => {
|
|
44
|
+
setCurrentState(state);
|
|
45
|
+
}, updateInterval);
|
|
46
|
+
|
|
47
|
+
// Update immediately
|
|
48
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
49
|
+
setCurrentState(state);
|
|
50
|
+
|
|
51
|
+
return () => clearInterval(interval);
|
|
52
|
+
}, [isOpen, state, updateInterval]);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
<Button
|
|
57
|
+
type="button"
|
|
58
|
+
variant="ghost"
|
|
59
|
+
size="icon"
|
|
60
|
+
onClick={() => setIsOpen(true)}
|
|
61
|
+
aria-label="Debug state"
|
|
62
|
+
title={title}
|
|
63
|
+
className={`text-white hover:bg-white/20 hover:text-white ${className || ""}`}
|
|
64
|
+
>
|
|
65
|
+
<Bug className="h-4 w-4" />
|
|
66
|
+
</Button>
|
|
67
|
+
|
|
68
|
+
<DebugStateDialog
|
|
69
|
+
isOpen={isOpen}
|
|
70
|
+
onClose={() => setIsOpen(false)}
|
|
71
|
+
getState={() => currentState}
|
|
72
|
+
title={title}
|
|
73
|
+
updateInterval={updateInterval}
|
|
74
|
+
/>
|
|
75
|
+
</>
|
|
76
|
+
);
|
|
77
|
+
};
|