@kelnishi/satmouse-client 0.9.5 → 0.9.7
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 +118 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# @kelnishi/satmouse-client
|
|
2
|
+
|
|
3
|
+
Client SDK for [SatMouse](https://kelnishi.github.io/SatMouse/) — stream 6DOF spatial input from SpaceMouse and other devices to web apps and PWAs.
|
|
4
|
+
|
|
5
|
+
Three tree-shakeable modules:
|
|
6
|
+
|
|
7
|
+
| Module | Import | Purpose |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| **core** | `@kelnishi/satmouse-client` | Connection, discovery, binary decode. Zero dependencies. |
|
|
10
|
+
| **utils** | `@kelnishi/satmouse-client/utils` | InputManager, transforms, per-device config, action mapping, persistence |
|
|
11
|
+
| **react** | `@kelnishi/satmouse-client/react` | Provider, hooks, headless components |
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @kelnishi/satmouse-client
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Vanilla
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { SatMouseConnection } from "@kelnishi/satmouse-client";
|
|
23
|
+
import { InputManager } from "@kelnishi/satmouse-client/utils";
|
|
24
|
+
|
|
25
|
+
const connection = new SatMouseConnection();
|
|
26
|
+
const manager = new InputManager();
|
|
27
|
+
manager.addConnection(connection);
|
|
28
|
+
|
|
29
|
+
manager.onSpatialData((data) => {
|
|
30
|
+
console.log(data.translation, data.rotation);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await connection.connect();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### React
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { SatMouseProvider, useSpatialData } from "@kelnishi/satmouse-client/react";
|
|
40
|
+
|
|
41
|
+
function App() {
|
|
42
|
+
return (
|
|
43
|
+
<SatMouseProvider>
|
|
44
|
+
<Scene />
|
|
45
|
+
</SatMouseProvider>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function Scene() {
|
|
50
|
+
const data = useSpatialData();
|
|
51
|
+
// data.translation.x/y/z, data.rotation.x/y/z
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Per-Device Configuration
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const manager = new InputManager({
|
|
59
|
+
sensitivity: { translation: 0.001, rotation: 0.001 },
|
|
60
|
+
devices: {
|
|
61
|
+
"hid-054c-*": { sensitivity: { translation: 0.002 } },
|
|
62
|
+
"spacemouse-c635": { flip: { rz: false } },
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Query devices and their resolved config
|
|
67
|
+
const devices = manager.getDevicesWithConfig();
|
|
68
|
+
|
|
69
|
+
// Update per-device
|
|
70
|
+
manager.updateDeviceConfig("spacemouse-c635", {
|
|
71
|
+
sensitivity: { rotation: 0.005 },
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Action Mapping
|
|
76
|
+
|
|
77
|
+
Remap input axes to named actions. Default passes through 1:1.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { InputManager, swapActions, DEFAULT_ACTION_MAP } from "@kelnishi/satmouse-client/utils";
|
|
81
|
+
|
|
82
|
+
// Swap ty and tz
|
|
83
|
+
const manager = new InputManager({
|
|
84
|
+
actionMap: swapActions(DEFAULT_ACTION_MAP, "ty", "tz"),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Per-device remapping
|
|
88
|
+
manager.updateDeviceConfig("hid-054c-*", {
|
|
89
|
+
actionMap: {
|
|
90
|
+
tx: { source: "tx" },
|
|
91
|
+
tz: { source: "ty", invert: true },
|
|
92
|
+
ry: { source: "rx", scale: 2.0 },
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Named action values
|
|
97
|
+
manager.onActionValues((values) => {
|
|
98
|
+
scene.pan(values.tx, values.ty);
|
|
99
|
+
scene.zoom(values.tz);
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Connection Options
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// Auto-discover via Thing Description
|
|
107
|
+
new SatMouseConnection();
|
|
108
|
+
|
|
109
|
+
// Direct URL
|
|
110
|
+
new SatMouseConnection({ wsUrl: "ws://192.168.1.42:18945/spatial" });
|
|
111
|
+
|
|
112
|
+
// Via satmouse:// URI
|
|
113
|
+
new SatMouseConnection({ uri: "satmouse://connect?host=192.168.1.42" });
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
MIT — [GitHub](https://github.com/kelnishi/SatMouse)
|