@kelnishi/satmouse-client 0.1.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/dist/chunk-I5MEZZOT.cjs +34 -0
- package/dist/chunk-I5MEZZOT.cjs.map +1 -0
- package/dist/chunk-X6NIARXW.js +32 -0
- package/dist/chunk-X6NIARXW.js.map +1 -0
- package/dist/connection-CH2YsPn1.d.cts +144 -0
- package/dist/connection-CH2YsPn1.d.ts +144 -0
- package/dist/core/index.cjs +405 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +53 -0
- package/dist/core/index.d.ts +53 -0
- package/dist/core/index.js +392 -0
- package/dist/core/index.js.map +1 -0
- package/dist/react/index.cjs +1003 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +239 -0
- package/dist/react/index.d.ts +239 -0
- package/dist/react/index.js +992 -0
- package/dist/react/index.js.map +1 -0
- package/dist/utils/index.cjs +231 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +99 -0
- package/dist/utils/index.d.ts +99 -0
- package/dist/utils/index.js +219 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
/** Minimal typed event emitter — no node:events dependency for browser compatibility */
|
|
6
|
+
declare class TypedEmitter<Events> {
|
|
7
|
+
private listeners;
|
|
8
|
+
on<K extends string & keyof Events>(event: K, listener: Events[K] & Function): this;
|
|
9
|
+
off<K extends string & keyof Events>(event: K, listener: Events[K] & Function): this;
|
|
10
|
+
protected emit<K extends string & keyof Events>(event: K, ...args: Events[K] extends (...a: infer A) => void ? A : never): void;
|
|
11
|
+
removeAllListeners(): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Vec3 {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
z: number;
|
|
18
|
+
}
|
|
19
|
+
/** 6DOF spatial input frame — matches spatial-data.schema.json */
|
|
20
|
+
interface SpatialData {
|
|
21
|
+
translation: Vec3;
|
|
22
|
+
rotation: Vec3;
|
|
23
|
+
timestamp: number;
|
|
24
|
+
}
|
|
25
|
+
/** Button press/release event — matches button-event.schema.json */
|
|
26
|
+
interface ButtonEvent {
|
|
27
|
+
button: number;
|
|
28
|
+
pressed: boolean;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
}
|
|
31
|
+
/** Device metadata from the bridge */
|
|
32
|
+
interface DeviceInfo$1 {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
model?: string;
|
|
36
|
+
vendor?: string;
|
|
37
|
+
vendorId?: number;
|
|
38
|
+
productId?: number;
|
|
39
|
+
connectionType?: "usb" | "wireless" | "bluetooth" | "unknown";
|
|
40
|
+
connected?: boolean;
|
|
41
|
+
}
|
|
42
|
+
type ConnectionState = "disconnected" | "connecting" | "connected";
|
|
43
|
+
type TransportProtocol = "webtransport" | "websocket" | "none";
|
|
44
|
+
interface SatMouseEvents {
|
|
45
|
+
spatialData: (data: SpatialData) => void;
|
|
46
|
+
buttonEvent: (data: ButtonEvent) => void;
|
|
47
|
+
stateChange: (state: ConnectionState, protocol: TransportProtocol) => void;
|
|
48
|
+
deviceStatus: (event: "connected" | "disconnected", device: DeviceInfo$1) => void;
|
|
49
|
+
error: (error: Error) => void;
|
|
50
|
+
}
|
|
51
|
+
interface ConnectOptions {
|
|
52
|
+
/**
|
|
53
|
+
* SatMouse URI: satmouse://connect?host=<ip>&wsPort=<port>&wtPort=<port>
|
|
54
|
+
* When provided, host/ports are extracted and used for discovery + transport.
|
|
55
|
+
* All params are optional — defaults to localhost:4444/4443.
|
|
56
|
+
*/
|
|
57
|
+
uri?: string;
|
|
58
|
+
/** URL to td.json. Defaults to /td.json relative to window.location */
|
|
59
|
+
tdUrl?: string;
|
|
60
|
+
/** Direct WebSocket URL (skips discovery) */
|
|
61
|
+
wsUrl?: string;
|
|
62
|
+
/** Direct WebTransport URL (skips discovery) */
|
|
63
|
+
wtUrl?: string;
|
|
64
|
+
/** Certificate hash for self-signed WebTransport certs (base64) */
|
|
65
|
+
certHash?: string;
|
|
66
|
+
/** Preferred transport order. Default: ["webtransport", "websocket"] */
|
|
67
|
+
transports?: TransportProtocol[];
|
|
68
|
+
/** Auto-reconnect delay in ms. 0 to disable. Default: 2000 */
|
|
69
|
+
reconnectDelay?: number;
|
|
70
|
+
/** WebSocket subprotocol. Default: "satmouse-json" */
|
|
71
|
+
wsSubprotocol?: "satmouse-json" | "satmouse-binary";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Core connection to a SatMouse bridge.
|
|
76
|
+
*
|
|
77
|
+
* Handles discovery (via WoT Thing Description), transport negotiation
|
|
78
|
+
* (WebTransport with WebSocket fallback), event dispatch, and auto-reconnect.
|
|
79
|
+
*/
|
|
80
|
+
declare class SatMouseConnection extends TypedEmitter<SatMouseEvents> {
|
|
81
|
+
private options;
|
|
82
|
+
private transport;
|
|
83
|
+
private reconnectTimer;
|
|
84
|
+
private intentionalClose;
|
|
85
|
+
private deviceInfoUrl;
|
|
86
|
+
private _state;
|
|
87
|
+
private _protocol;
|
|
88
|
+
get state(): ConnectionState;
|
|
89
|
+
get protocol(): TransportProtocol;
|
|
90
|
+
constructor(options?: ConnectOptions);
|
|
91
|
+
connect(): Promise<void>;
|
|
92
|
+
disconnect(): void;
|
|
93
|
+
fetchDeviceInfo(): Promise<DeviceInfo$1[]>;
|
|
94
|
+
private tryTransport;
|
|
95
|
+
private setState;
|
|
96
|
+
private scheduleReconnect;
|
|
97
|
+
private clearReconnect;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface FlipConfig {
|
|
101
|
+
tx: boolean;
|
|
102
|
+
ty: boolean;
|
|
103
|
+
tz: boolean;
|
|
104
|
+
rx: boolean;
|
|
105
|
+
ry: boolean;
|
|
106
|
+
rz: boolean;
|
|
107
|
+
}
|
|
108
|
+
interface SensitivityConfig {
|
|
109
|
+
translation: number;
|
|
110
|
+
rotation: number;
|
|
111
|
+
}
|
|
112
|
+
/** Maps each input axis to an output axis. E.g., { tx: "tz", tz: "tx" } swaps X and Z translation. */
|
|
113
|
+
type AxisMap = {
|
|
114
|
+
tx: keyof Vec3;
|
|
115
|
+
ty: keyof Vec3;
|
|
116
|
+
tz: keyof Vec3;
|
|
117
|
+
rx: keyof Vec3;
|
|
118
|
+
ry: keyof Vec3;
|
|
119
|
+
rz: keyof Vec3;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
interface InputConfig {
|
|
123
|
+
sensitivity: SensitivityConfig;
|
|
124
|
+
flip: FlipConfig;
|
|
125
|
+
deadZone: number;
|
|
126
|
+
dominant: boolean;
|
|
127
|
+
axisRemap: AxisMap;
|
|
128
|
+
lockPosition: boolean;
|
|
129
|
+
lockRotation: boolean;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface StorageAdapter {
|
|
133
|
+
getItem(key: string): string | null;
|
|
134
|
+
setItem(key: string, value: string): void;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface InputManagerEvents {
|
|
138
|
+
/** Processed spatial data (after all transforms) */
|
|
139
|
+
spatialData: (data: SpatialData) => void;
|
|
140
|
+
/** Raw spatial data (before transforms) */
|
|
141
|
+
rawSpatialData: (data: SpatialData) => void;
|
|
142
|
+
/** Button event (pass-through from connection) */
|
|
143
|
+
buttonEvent: (data: ButtonEvent) => void;
|
|
144
|
+
/** Connection state changed */
|
|
145
|
+
stateChange: (state: ConnectionState, protocol: TransportProtocol) => void;
|
|
146
|
+
/** Device connected/disconnected */
|
|
147
|
+
deviceStatus: (event: "connected" | "disconnected", device: DeviceInfo$1) => void;
|
|
148
|
+
/** Configuration changed */
|
|
149
|
+
configChange: (config: InputConfig) => void;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Unified device service that wraps one or more SatMouseConnections
|
|
153
|
+
* and provides a single processed event stream.
|
|
154
|
+
*
|
|
155
|
+
* Applies a configurable transform pipeline to spatial data:
|
|
156
|
+
* deadZone → dominant → flip → axisRemap → sensitivity → lock
|
|
157
|
+
*
|
|
158
|
+
* Persists settings to storage (localStorage by default).
|
|
159
|
+
*/
|
|
160
|
+
declare class InputManager extends TypedEmitter<InputManagerEvents> {
|
|
161
|
+
private connections;
|
|
162
|
+
private storage?;
|
|
163
|
+
private _config;
|
|
164
|
+
get config(): InputConfig;
|
|
165
|
+
constructor(config?: Partial<InputConfig>, storage?: StorageAdapter);
|
|
166
|
+
/** Add a connection to the managed set */
|
|
167
|
+
addConnection(connection: SatMouseConnection): void;
|
|
168
|
+
/** Remove a connection */
|
|
169
|
+
removeConnection(connection: SatMouseConnection): void;
|
|
170
|
+
/** Connect all managed connections */
|
|
171
|
+
connect(): Promise<void>;
|
|
172
|
+
/** Disconnect all managed connections */
|
|
173
|
+
disconnect(): void;
|
|
174
|
+
/** Fetch device info from all connections */
|
|
175
|
+
fetchDeviceInfo(): Promise<DeviceInfo$1[]>;
|
|
176
|
+
/** Update configuration. Persists by default. */
|
|
177
|
+
updateConfig(partial: Partial<InputConfig>, persist?: boolean): void;
|
|
178
|
+
/** Register a callback for processed spatial data. Returns unsubscribe function. */
|
|
179
|
+
onSpatialData(callback: (data: SpatialData) => void): () => void;
|
|
180
|
+
/** Register a callback for button events. Returns unsubscribe function. */
|
|
181
|
+
onButtonEvent(callback: (data: ButtonEvent) => void): () => void;
|
|
182
|
+
private wireConnection;
|
|
183
|
+
private processSpatialData;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interface SatMouseContextValue {
|
|
187
|
+
manager: InputManager;
|
|
188
|
+
state: ConnectionState;
|
|
189
|
+
protocol: TransportProtocol;
|
|
190
|
+
config: InputConfig;
|
|
191
|
+
updateConfig: (partial: Partial<InputConfig>) => void;
|
|
192
|
+
}
|
|
193
|
+
declare const SatMouseContext: react.Context<SatMouseContextValue | null>;
|
|
194
|
+
interface SatMouseProviderProps {
|
|
195
|
+
connectOptions?: ConnectOptions;
|
|
196
|
+
config?: Partial<InputConfig>;
|
|
197
|
+
autoConnect?: boolean;
|
|
198
|
+
children: ReactNode;
|
|
199
|
+
}
|
|
200
|
+
declare function SatMouseProvider({ connectOptions, config: configOverrides, autoConnect, children, }: SatMouseProviderProps): react_jsx_runtime.JSX.Element;
|
|
201
|
+
|
|
202
|
+
/** Access the SatMouse context. Throws if used outside SatMouseProvider. */
|
|
203
|
+
declare function useSatMouse(): SatMouseContextValue;
|
|
204
|
+
/**
|
|
205
|
+
* Subscribe to processed spatial data.
|
|
206
|
+
* Batches updates to requestAnimationFrame to avoid re-rendering at device rate.
|
|
207
|
+
*/
|
|
208
|
+
declare function useSpatialData(): SpatialData | null;
|
|
209
|
+
/**
|
|
210
|
+
* Subscribe to raw (pre-transform) spatial data.
|
|
211
|
+
* Batches updates to requestAnimationFrame.
|
|
212
|
+
*/
|
|
213
|
+
declare function useRawSpatialData(): SpatialData | null;
|
|
214
|
+
/** Subscribe to button events via callback. Does not trigger re-renders. */
|
|
215
|
+
declare function useButtonEvent(callback: (event: ButtonEvent) => void): void;
|
|
216
|
+
|
|
217
|
+
interface ConnectionStatusProps {
|
|
218
|
+
className?: string;
|
|
219
|
+
}
|
|
220
|
+
declare function ConnectionStatus({ className }: ConnectionStatusProps): react_jsx_runtime.JSX.Element;
|
|
221
|
+
|
|
222
|
+
interface DeviceInfoProps {
|
|
223
|
+
className?: string;
|
|
224
|
+
/** Timeout in ms before showing "no device". Default: 5000 */
|
|
225
|
+
timeout?: number;
|
|
226
|
+
}
|
|
227
|
+
declare function DeviceInfo({ className, timeout }: DeviceInfoProps): react_jsx_runtime.JSX.Element;
|
|
228
|
+
|
|
229
|
+
interface SettingsPanelProps {
|
|
230
|
+
className?: string;
|
|
231
|
+
}
|
|
232
|
+
declare function SettingsPanel({ className }: SettingsPanelProps): react_jsx_runtime.JSX.Element;
|
|
233
|
+
|
|
234
|
+
interface DebugPanelProps {
|
|
235
|
+
className?: string;
|
|
236
|
+
}
|
|
237
|
+
declare function DebugPanel({ className }: DebugPanelProps): react_jsx_runtime.JSX.Element;
|
|
238
|
+
|
|
239
|
+
export { ConnectionStatus, type ConnectionStatusProps, DebugPanel, type DebugPanelProps, DeviceInfo, type DeviceInfoProps, SatMouseContext, type SatMouseContextValue, SatMouseProvider, type SatMouseProviderProps, SettingsPanel, type SettingsPanelProps, useButtonEvent, useRawSpatialData, useSatMouse, useSpatialData };
|