@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.
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ // src/core/emitter.ts
4
+ var TypedEmitter = class {
5
+ listeners = /* @__PURE__ */ new Map();
6
+ on(event, listener) {
7
+ let set = this.listeners.get(event);
8
+ if (!set) {
9
+ set = /* @__PURE__ */ new Set();
10
+ this.listeners.set(event, set);
11
+ }
12
+ set.add(listener);
13
+ return this;
14
+ }
15
+ off(event, listener) {
16
+ this.listeners.get(event)?.delete(listener);
17
+ return this;
18
+ }
19
+ emit(event, ...args) {
20
+ const set = this.listeners.get(event);
21
+ if (set) {
22
+ for (const fn of set) {
23
+ fn(...args);
24
+ }
25
+ }
26
+ }
27
+ removeAllListeners() {
28
+ this.listeners.clear();
29
+ }
30
+ };
31
+
32
+ exports.TypedEmitter = TypedEmitter;
33
+ //# sourceMappingURL=chunk-I5MEZZOT.cjs.map
34
+ //# sourceMappingURL=chunk-I5MEZZOT.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/emitter.ts"],"names":[],"mappings":";;;AAEO,IAAM,eAAN,MAA2B;AAAA,EACxB,SAAA,uBAAgB,GAAA,EAA2B;AAAA,EAEnD,EAAA,CAAoC,OAAU,QAAA,EAAsC;AAClF,IAAA,IAAI,GAAA,GAAM,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA;AAClC,IAAA,IAAI,CAAC,GAAA,EAAK;AACR,MAAA,GAAA,uBAAU,GAAA,EAAI;AACd,MAAA,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAA,EAAO,GAAG,CAAA;AAAA,IAC/B;AACA,IAAA,GAAA,CAAI,IAAI,QAAQ,CAAA;AAChB,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EAEA,GAAA,CAAqC,OAAU,QAAA,EAAsC;AACnF,IAAA,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA,EAAG,OAAO,QAAQ,CAAA;AAC1C,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EAEU,IAAA,CACR,UACG,IAAA,EACG;AACN,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA;AACpC,IAAA,IAAI,GAAA,EAAK;AACP,MAAA,KAAA,MAAW,MAAM,GAAA,EAAK;AACpB,QAAC,EAAA,CAAgB,GAAG,IAAI,CAAA;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAAA,EAEA,kBAAA,GAA2B;AACzB,IAAA,IAAA,CAAK,UAAU,KAAA,EAAM;AAAA,EACvB;AACF","file":"chunk-I5MEZZOT.cjs","sourcesContent":["/** Minimal typed event emitter — no node:events dependency for browser compatibility */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class TypedEmitter<Events> {\n private listeners = new Map<string, Set<Function>>();\n\n on<K extends string & keyof Events>(event: K, listener: Events[K] & Function): this {\n let set = this.listeners.get(event);\n if (!set) {\n set = new Set();\n this.listeners.set(event, set);\n }\n set.add(listener);\n return this;\n }\n\n off<K extends string & keyof Events>(event: K, listener: Events[K] & Function): this {\n this.listeners.get(event)?.delete(listener);\n return this;\n }\n\n protected emit<K extends string & keyof Events>(\n event: K,\n ...args: Events[K] extends (...a: infer A) => void ? A : never\n ): void {\n const set = this.listeners.get(event);\n if (set) {\n for (const fn of set) {\n (fn as Function)(...args);\n }\n }\n }\n\n removeAllListeners(): void {\n this.listeners.clear();\n }\n}\n"]}
@@ -0,0 +1,32 @@
1
+ // src/core/emitter.ts
2
+ var TypedEmitter = class {
3
+ listeners = /* @__PURE__ */ new Map();
4
+ on(event, listener) {
5
+ let set = this.listeners.get(event);
6
+ if (!set) {
7
+ set = /* @__PURE__ */ new Set();
8
+ this.listeners.set(event, set);
9
+ }
10
+ set.add(listener);
11
+ return this;
12
+ }
13
+ off(event, listener) {
14
+ this.listeners.get(event)?.delete(listener);
15
+ return this;
16
+ }
17
+ emit(event, ...args) {
18
+ const set = this.listeners.get(event);
19
+ if (set) {
20
+ for (const fn of set) {
21
+ fn(...args);
22
+ }
23
+ }
24
+ }
25
+ removeAllListeners() {
26
+ this.listeners.clear();
27
+ }
28
+ };
29
+
30
+ export { TypedEmitter };
31
+ //# sourceMappingURL=chunk-X6NIARXW.js.map
32
+ //# sourceMappingURL=chunk-X6NIARXW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/emitter.ts"],"names":[],"mappings":";AAEO,IAAM,eAAN,MAA2B;AAAA,EACxB,SAAA,uBAAgB,GAAA,EAA2B;AAAA,EAEnD,EAAA,CAAoC,OAAU,QAAA,EAAsC;AAClF,IAAA,IAAI,GAAA,GAAM,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA;AAClC,IAAA,IAAI,CAAC,GAAA,EAAK;AACR,MAAA,GAAA,uBAAU,GAAA,EAAI;AACd,MAAA,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAA,EAAO,GAAG,CAAA;AAAA,IAC/B;AACA,IAAA,GAAA,CAAI,IAAI,QAAQ,CAAA;AAChB,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EAEA,GAAA,CAAqC,OAAU,QAAA,EAAsC;AACnF,IAAA,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA,EAAG,OAAO,QAAQ,CAAA;AAC1C,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EAEU,IAAA,CACR,UACG,IAAA,EACG;AACN,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA;AACpC,IAAA,IAAI,GAAA,EAAK;AACP,MAAA,KAAA,MAAW,MAAM,GAAA,EAAK;AACpB,QAAC,EAAA,CAAgB,GAAG,IAAI,CAAA;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAAA,EAEA,kBAAA,GAA2B;AACzB,IAAA,IAAA,CAAK,UAAU,KAAA,EAAM;AAAA,EACvB;AACF","file":"chunk-X6NIARXW.js","sourcesContent":["/** Minimal typed event emitter — no node:events dependency for browser compatibility */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class TypedEmitter<Events> {\n private listeners = new Map<string, Set<Function>>();\n\n on<K extends string & keyof Events>(event: K, listener: Events[K] & Function): this {\n let set = this.listeners.get(event);\n if (!set) {\n set = new Set();\n this.listeners.set(event, set);\n }\n set.add(listener);\n return this;\n }\n\n off<K extends string & keyof Events>(event: K, listener: Events[K] & Function): this {\n this.listeners.get(event)?.delete(listener);\n return this;\n }\n\n protected emit<K extends string & keyof Events>(\n event: K,\n ...args: Events[K] extends (...a: infer A) => void ? A : never\n ): void {\n const set = this.listeners.get(event);\n if (set) {\n for (const fn of set) {\n (fn as Function)(...args);\n }\n }\n }\n\n removeAllListeners(): void {\n this.listeners.clear();\n }\n}\n"]}
@@ -0,0 +1,144 @@
1
+ /** Minimal typed event emitter — no node:events dependency for browser compatibility */
2
+ declare class TypedEmitter<Events> {
3
+ private listeners;
4
+ on<K extends string & keyof Events>(event: K, listener: Events[K] & Function): this;
5
+ off<K extends string & keyof Events>(event: K, listener: Events[K] & Function): this;
6
+ protected emit<K extends string & keyof Events>(event: K, ...args: Events[K] extends (...a: infer A) => void ? A : never): void;
7
+ removeAllListeners(): void;
8
+ }
9
+
10
+ interface Vec3 {
11
+ x: number;
12
+ y: number;
13
+ z: number;
14
+ }
15
+ /** 6DOF spatial input frame — matches spatial-data.schema.json */
16
+ interface SpatialData {
17
+ translation: Vec3;
18
+ rotation: Vec3;
19
+ timestamp: number;
20
+ }
21
+ /** Button press/release event — matches button-event.schema.json */
22
+ interface ButtonEvent {
23
+ button: number;
24
+ pressed: boolean;
25
+ timestamp: number;
26
+ }
27
+ /** Device metadata from the bridge */
28
+ interface DeviceInfo {
29
+ id: string;
30
+ name: string;
31
+ model?: string;
32
+ vendor?: string;
33
+ vendorId?: number;
34
+ productId?: number;
35
+ connectionType?: "usb" | "wireless" | "bluetooth" | "unknown";
36
+ connected?: boolean;
37
+ }
38
+ type ConnectionState = "disconnected" | "connecting" | "connected";
39
+ type TransportProtocol = "webtransport" | "websocket" | "none";
40
+ interface SatMouseEvents {
41
+ spatialData: (data: SpatialData) => void;
42
+ buttonEvent: (data: ButtonEvent) => void;
43
+ stateChange: (state: ConnectionState, protocol: TransportProtocol) => void;
44
+ deviceStatus: (event: "connected" | "disconnected", device: DeviceInfo) => void;
45
+ error: (error: Error) => void;
46
+ }
47
+ interface ThingDescription {
48
+ title: string;
49
+ id: string;
50
+ base?: string;
51
+ version?: {
52
+ instance: string;
53
+ };
54
+ "satmouse:certHash"?: string;
55
+ properties?: {
56
+ deviceInfo?: {
57
+ forms: Array<{
58
+ href: string;
59
+ op: string;
60
+ }>;
61
+ };
62
+ };
63
+ events?: {
64
+ spatialData?: {
65
+ forms: Array<{
66
+ href: string;
67
+ subprotocol: string;
68
+ contentType: string;
69
+ }>;
70
+ };
71
+ buttonEvent?: {
72
+ forms: Array<{
73
+ href: string;
74
+ subprotocol: string;
75
+ contentType: string;
76
+ }>;
77
+ };
78
+ };
79
+ }
80
+ interface ConnectOptions {
81
+ /**
82
+ * SatMouse URI: satmouse://connect?host=<ip>&wsPort=<port>&wtPort=<port>
83
+ * When provided, host/ports are extracted and used for discovery + transport.
84
+ * All params are optional — defaults to localhost:4444/4443.
85
+ */
86
+ uri?: string;
87
+ /** URL to td.json. Defaults to /td.json relative to window.location */
88
+ tdUrl?: string;
89
+ /** Direct WebSocket URL (skips discovery) */
90
+ wsUrl?: string;
91
+ /** Direct WebTransport URL (skips discovery) */
92
+ wtUrl?: string;
93
+ /** Certificate hash for self-signed WebTransport certs (base64) */
94
+ certHash?: string;
95
+ /** Preferred transport order. Default: ["webtransport", "websocket"] */
96
+ transports?: TransportProtocol[];
97
+ /** Auto-reconnect delay in ms. 0 to disable. Default: 2000 */
98
+ reconnectDelay?: number;
99
+ /** WebSocket subprotocol. Default: "satmouse-json" */
100
+ wsSubprotocol?: "satmouse-json" | "satmouse-binary";
101
+ }
102
+
103
+ /**
104
+ * Build a satmouse:// connect URI from connection parameters.
105
+ */
106
+ declare function buildSatMouseUri(host?: string, wsPort?: number, wtPort?: number): string;
107
+ /**
108
+ * Parse a satmouse:// URI into connection parameters.
109
+ *
110
+ * Format: satmouse://connect?host=<ip>&wsPort=<port>&wtPort=<port>
111
+ * All query params are optional. Defaults: host=localhost, wsPort=4444, wtPort=4443.
112
+ */
113
+ declare function parseSatMouseUri(uri: string): {
114
+ tdUrl: string;
115
+ wsUrl: string;
116
+ wtUrl: string;
117
+ };
118
+ /**
119
+ * Core connection to a SatMouse bridge.
120
+ *
121
+ * Handles discovery (via WoT Thing Description), transport negotiation
122
+ * (WebTransport with WebSocket fallback), event dispatch, and auto-reconnect.
123
+ */
124
+ declare class SatMouseConnection extends TypedEmitter<SatMouseEvents> {
125
+ private options;
126
+ private transport;
127
+ private reconnectTimer;
128
+ private intentionalClose;
129
+ private deviceInfoUrl;
130
+ private _state;
131
+ private _protocol;
132
+ get state(): ConnectionState;
133
+ get protocol(): TransportProtocol;
134
+ constructor(options?: ConnectOptions);
135
+ connect(): Promise<void>;
136
+ disconnect(): void;
137
+ fetchDeviceInfo(): Promise<DeviceInfo[]>;
138
+ private tryTransport;
139
+ private setState;
140
+ private scheduleReconnect;
141
+ private clearReconnect;
142
+ }
143
+
144
+ export { type ButtonEvent as B, type ConnectOptions as C, type DeviceInfo as D, type SpatialData as S, type ThingDescription as T, type Vec3 as V, type ConnectionState as a, SatMouseConnection as b, type SatMouseEvents as c, type TransportProtocol as d, TypedEmitter as e, buildSatMouseUri as f, parseSatMouseUri as p };
@@ -0,0 +1,144 @@
1
+ /** Minimal typed event emitter — no node:events dependency for browser compatibility */
2
+ declare class TypedEmitter<Events> {
3
+ private listeners;
4
+ on<K extends string & keyof Events>(event: K, listener: Events[K] & Function): this;
5
+ off<K extends string & keyof Events>(event: K, listener: Events[K] & Function): this;
6
+ protected emit<K extends string & keyof Events>(event: K, ...args: Events[K] extends (...a: infer A) => void ? A : never): void;
7
+ removeAllListeners(): void;
8
+ }
9
+
10
+ interface Vec3 {
11
+ x: number;
12
+ y: number;
13
+ z: number;
14
+ }
15
+ /** 6DOF spatial input frame — matches spatial-data.schema.json */
16
+ interface SpatialData {
17
+ translation: Vec3;
18
+ rotation: Vec3;
19
+ timestamp: number;
20
+ }
21
+ /** Button press/release event — matches button-event.schema.json */
22
+ interface ButtonEvent {
23
+ button: number;
24
+ pressed: boolean;
25
+ timestamp: number;
26
+ }
27
+ /** Device metadata from the bridge */
28
+ interface DeviceInfo {
29
+ id: string;
30
+ name: string;
31
+ model?: string;
32
+ vendor?: string;
33
+ vendorId?: number;
34
+ productId?: number;
35
+ connectionType?: "usb" | "wireless" | "bluetooth" | "unknown";
36
+ connected?: boolean;
37
+ }
38
+ type ConnectionState = "disconnected" | "connecting" | "connected";
39
+ type TransportProtocol = "webtransport" | "websocket" | "none";
40
+ interface SatMouseEvents {
41
+ spatialData: (data: SpatialData) => void;
42
+ buttonEvent: (data: ButtonEvent) => void;
43
+ stateChange: (state: ConnectionState, protocol: TransportProtocol) => void;
44
+ deviceStatus: (event: "connected" | "disconnected", device: DeviceInfo) => void;
45
+ error: (error: Error) => void;
46
+ }
47
+ interface ThingDescription {
48
+ title: string;
49
+ id: string;
50
+ base?: string;
51
+ version?: {
52
+ instance: string;
53
+ };
54
+ "satmouse:certHash"?: string;
55
+ properties?: {
56
+ deviceInfo?: {
57
+ forms: Array<{
58
+ href: string;
59
+ op: string;
60
+ }>;
61
+ };
62
+ };
63
+ events?: {
64
+ spatialData?: {
65
+ forms: Array<{
66
+ href: string;
67
+ subprotocol: string;
68
+ contentType: string;
69
+ }>;
70
+ };
71
+ buttonEvent?: {
72
+ forms: Array<{
73
+ href: string;
74
+ subprotocol: string;
75
+ contentType: string;
76
+ }>;
77
+ };
78
+ };
79
+ }
80
+ interface ConnectOptions {
81
+ /**
82
+ * SatMouse URI: satmouse://connect?host=<ip>&wsPort=<port>&wtPort=<port>
83
+ * When provided, host/ports are extracted and used for discovery + transport.
84
+ * All params are optional — defaults to localhost:4444/4443.
85
+ */
86
+ uri?: string;
87
+ /** URL to td.json. Defaults to /td.json relative to window.location */
88
+ tdUrl?: string;
89
+ /** Direct WebSocket URL (skips discovery) */
90
+ wsUrl?: string;
91
+ /** Direct WebTransport URL (skips discovery) */
92
+ wtUrl?: string;
93
+ /** Certificate hash for self-signed WebTransport certs (base64) */
94
+ certHash?: string;
95
+ /** Preferred transport order. Default: ["webtransport", "websocket"] */
96
+ transports?: TransportProtocol[];
97
+ /** Auto-reconnect delay in ms. 0 to disable. Default: 2000 */
98
+ reconnectDelay?: number;
99
+ /** WebSocket subprotocol. Default: "satmouse-json" */
100
+ wsSubprotocol?: "satmouse-json" | "satmouse-binary";
101
+ }
102
+
103
+ /**
104
+ * Build a satmouse:// connect URI from connection parameters.
105
+ */
106
+ declare function buildSatMouseUri(host?: string, wsPort?: number, wtPort?: number): string;
107
+ /**
108
+ * Parse a satmouse:// URI into connection parameters.
109
+ *
110
+ * Format: satmouse://connect?host=<ip>&wsPort=<port>&wtPort=<port>
111
+ * All query params are optional. Defaults: host=localhost, wsPort=4444, wtPort=4443.
112
+ */
113
+ declare function parseSatMouseUri(uri: string): {
114
+ tdUrl: string;
115
+ wsUrl: string;
116
+ wtUrl: string;
117
+ };
118
+ /**
119
+ * Core connection to a SatMouse bridge.
120
+ *
121
+ * Handles discovery (via WoT Thing Description), transport negotiation
122
+ * (WebTransport with WebSocket fallback), event dispatch, and auto-reconnect.
123
+ */
124
+ declare class SatMouseConnection extends TypedEmitter<SatMouseEvents> {
125
+ private options;
126
+ private transport;
127
+ private reconnectTimer;
128
+ private intentionalClose;
129
+ private deviceInfoUrl;
130
+ private _state;
131
+ private _protocol;
132
+ get state(): ConnectionState;
133
+ get protocol(): TransportProtocol;
134
+ constructor(options?: ConnectOptions);
135
+ connect(): Promise<void>;
136
+ disconnect(): void;
137
+ fetchDeviceInfo(): Promise<DeviceInfo[]>;
138
+ private tryTransport;
139
+ private setState;
140
+ private scheduleReconnect;
141
+ private clearReconnect;
142
+ }
143
+
144
+ export { type ButtonEvent as B, type ConnectOptions as C, type DeviceInfo as D, type SpatialData as S, type ThingDescription as T, type Vec3 as V, type ConnectionState as a, SatMouseConnection as b, type SatMouseEvents as c, type TransportProtocol as d, TypedEmitter as e, buildSatMouseUri as f, parseSatMouseUri as p };