@zendrex/buttplug.js 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zendrex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # @zendrex/buttplug.js
2
+
3
+ TypeScript client for the [Buttplug](https://buttplug.io) protocol v4. Connect to [Intiface Central](https://intiface.com/central/), discover devices, and control them with a type-safe API.
4
+
5
+ ## Features
6
+
7
+ - Buttplug protocol v4 over WebSocket
8
+ - 10 output types — vibration, rotation, position, oscillation, constriction, temperature, LED, spray, and more
9
+ - 5 sensor types — battery, RSSI, pressure, button, position (one-shot reads and subscriptions)
10
+ - Pattern engine with 7 built-in presets, custom keyframes, and easing curves
11
+ - Auto-reconnect with exponential backoff
12
+ - Zod-validated protocol messages
13
+ - Zero config — point at Intiface Central and go
14
+
15
+ ## Prerequisites
16
+
17
+ [Intiface Central](https://intiface.com/central/) must be running on your machine or network. It manages hardware connections and exposes a WebSocket server (default `ws://127.0.0.1:12345`).
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ bun add @zendrex/buttplug.js
23
+ # or
24
+ npm install @zendrex/buttplug.js
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```typescript
30
+ import { ButtplugClient, consoleLogger } from "@zendrex/buttplug.js";
31
+
32
+ const client = new ButtplugClient("ws://127.0.0.1:12345", {
33
+ logger: consoleLogger,
34
+ });
35
+
36
+ await client.connect();
37
+
38
+ client.on("deviceAdded", async ({ device }) => {
39
+ console.log(`Found: ${device.displayName ?? device.name}`);
40
+
41
+ if (device.canOutput("Vibrate")) {
42
+ await device.vibrate(0.5);
43
+ setTimeout(() => device.stop(), 2000);
44
+ }
45
+ });
46
+
47
+ await client.startScanning();
48
+ ```
49
+
50
+ ## API at a Glance
51
+
52
+ ### Client
53
+
54
+ ```typescript
55
+ const client = new ButtplugClient(url, options?);
56
+
57
+ await client.connect();
58
+ await client.startScanning();
59
+ await client.stopAll();
60
+ await client.disconnect();
61
+
62
+ client.connected; // boolean
63
+ client.devices; // Device[]
64
+ client.serverInfo; // ServerInfo | null
65
+ ```
66
+
67
+ **Events:** `connected`, `disconnected`, `reconnecting`, `reconnected`, `error`, `scanningFinished`, `deviceAdded`, `deviceRemoved`, `deviceUpdated`, `deviceList`, `inputReading`
68
+
69
+ ### Device
70
+
71
+ All output values are normalized to `0–1`. Pass a single number for all motors or an array for per-motor control.
72
+
73
+ ```typescript
74
+ await device.vibrate(0.5);
75
+ await device.rotate(0.5, { clockwise: true });
76
+ await device.position(0.8, { duration: 500 });
77
+ await device.oscillate(0.7);
78
+ await device.constrict(0.4);
79
+ await device.stop();
80
+
81
+ // Sensors
82
+ const battery = await device.readSensor("Battery");
83
+ const unsub = await device.subscribeSensor("RSSI", (value) => { /* ... */ });
84
+ await unsub();
85
+
86
+ // Capability checks
87
+ device.canOutput("Vibrate"); // boolean
88
+ device.canRead("Battery"); // boolean
89
+ device.canSubscribe("RSSI"); // boolean
90
+ ```
91
+
92
+ ### Pattern Engine
93
+
94
+ ```typescript
95
+ import { ButtplugClient, PatternEngine } from "@zendrex/buttplug.js";
96
+
97
+ const engine = new PatternEngine(client);
98
+
99
+ // Built-in preset
100
+ const id = await engine.play(deviceIndex, "wave", {
101
+ intensity: 0.8,
102
+ speed: 1.5,
103
+ loop: true,
104
+ });
105
+
106
+ // Custom keyframes
107
+ const id2 = await engine.play(deviceIndex, [
108
+ {
109
+ featureIndex: 0,
110
+ keyframes: [
111
+ { value: 0, duration: 0 },
112
+ { value: 1, duration: 1000, easing: "easeIn" },
113
+ { value: 0.2, duration: 500, easing: "easeOut" },
114
+ ],
115
+ },
116
+ ], { loop: 3, intensity: 0.6 });
117
+
118
+ await engine.stop(id);
119
+ engine.stopAll();
120
+ engine.dispose();
121
+ ```
122
+
123
+ **Presets:** `pulse`, `wave`, `ramp_up`, `ramp_down`, `heartbeat`, `surge`, `stroke`
124
+
125
+ **Easings:** `linear`, `easeIn`, `easeOut`, `easeInOut`, `step`
126
+
127
+ ### Error Handling
128
+
129
+ All errors extend `ButtplugError`:
130
+
131
+ | Error | Context |
132
+ |---|---|
133
+ | `ConnectionError` | WebSocket/transport failure |
134
+ | `HandshakeError` | Server rejected handshake |
135
+ | `ProtocolError` | Server protocol error (has `.code`) |
136
+ | `DeviceError` | Device operation failed (has `.deviceIndex`) |
137
+ | `TimeoutError` | Operation timed out (has `.operation`, `.timeoutMs`) |
138
+
139
+ ### Auto-Reconnect
140
+
141
+ ```typescript
142
+ const client = new ButtplugClient("ws://127.0.0.1:12345", {
143
+ autoReconnect: true,
144
+ reconnectDelay: 1000, // initial delay
145
+ maxReconnectDelay: 30000, // backoff cap
146
+ maxReconnectAttempts: 10,
147
+ });
148
+ ```
149
+
150
+ On reconnection, the client re-handshakes, reconciles the device list, and emits `reconnected`. The pattern engine automatically stops patterns for removed devices.
151
+
152
+ ## Documentation
153
+
154
+ Full API reference and guides are available in the [`docs/`](./docs) directory. To run locally:
155
+
156
+ ```bash
157
+ cd docs && bun run dev
158
+ ```
159
+
160
+ ## License
161
+
162
+ [MIT](./LICENSE)