buttplug 3.2.2 → 4.0.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/.eslintrc.js +25 -25
- package/.jscsrc +2 -2
- package/.jshintrc +5 -5
- package/.prettierrc.json +3 -3
- package/.yarnrc.yml +5 -5
- package/CHANGELOG.md +591 -577
- package/LICENSE +27 -27
- package/README.md +105 -97
- package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js +6 -9
- package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js.map +1 -1
- package/dist/main/src/client/{Client.d.ts → ButtplugClient.d.ts} +3 -4
- package/dist/main/src/client/ButtplugClient.js +232 -0
- package/dist/main/src/client/ButtplugClient.js.map +1 -0
- package/dist/main/src/client/ButtplugClientConnectorException.js +17 -7
- package/dist/main/src/client/ButtplugClientConnectorException.js.map +1 -1
- package/dist/main/src/client/ButtplugClientDevice.d.ts +13 -28
- package/dist/main/src/client/ButtplugClientDevice.js +105 -247
- package/dist/main/src/client/ButtplugClientDevice.js.map +1 -1
- package/dist/main/src/client/ButtplugClientDeviceCommand.d.ts +42 -0
- package/dist/main/src/client/ButtplugClientDeviceCommand.js +105 -0
- package/dist/main/src/client/ButtplugClientDeviceCommand.js.map +1 -0
- package/dist/main/src/client/ButtplugClientDeviceFeature.d.ts +18 -0
- package/dist/main/src/client/ButtplugClientDeviceFeature.js +166 -0
- package/dist/main/src/client/ButtplugClientDeviceFeature.js.map +1 -0
- package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.d.ts +1 -8
- package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.js +1 -4
- package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.js.map +1 -1
- package/dist/main/src/core/Exceptions.js +27 -9
- package/dist/main/src/core/Exceptions.js.map +1 -1
- package/dist/main/src/core/Logging.js +12 -6
- package/dist/main/src/core/Logging.js.map +1 -1
- package/dist/main/src/core/Messages.d.ts +119 -230
- package/dist/main/src/core/Messages.js +50 -404
- package/dist/main/src/core/Messages.js.map +1 -1
- package/dist/main/src/index.d.ts +2 -2
- package/dist/main/src/index.js +4 -2
- package/dist/main/src/index.js.map +1 -1
- package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.js +40 -52
- package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.js.map +1 -1
- package/dist/main/src/utils/ButtplugMessageSorter.js +27 -15
- package/dist/main/src/utils/ButtplugMessageSorter.js.map +1 -1
- package/dist/main/src/utils/Utils.js +1 -2
- package/dist/main/src/utils/Utils.js.map +1 -1
- package/dist/web/buttplug.js +1 -38
- package/dist/web/buttplug.mjs +595 -1984
- package/dist/web/client/ButtplugBrowserWebsocketClientConnector.d.ts +0 -7
- package/dist/web/client/{Client.d.ts → ButtplugClient.d.ts} +3 -11
- package/dist/web/client/ButtplugClientConnectorException.d.ts +0 -7
- package/dist/web/client/ButtplugClientDevice.d.ts +14 -29
- package/dist/web/client/ButtplugClientDeviceCommand.d.ts +42 -0
- package/dist/web/client/ButtplugClientDeviceFeature.d.ts +18 -0
- package/dist/web/client/ButtplugNodeWebsocketClientConnector.d.ts +1 -15
- package/dist/web/client/IButtplugClientConnector.d.ts +0 -7
- package/dist/web/core/Exceptions.d.ts +1 -1
- package/dist/web/core/Logging.d.ts +0 -7
- package/dist/web/core/Messages.d.ts +119 -229
- package/dist/web/index.d.ts +2 -2
- package/dist/web/utils/ButtplugBrowserWebsocketConnector.d.ts +0 -7
- package/examples/node/SYNC_MANIFEST.md +105 -0
- package/examples/node/application-example.ts +213 -0
- package/examples/node/async-example.ts +124 -0
- package/examples/node/connection-example.ts +76 -0
- package/examples/node/device-control-example.ts +131 -0
- package/examples/node/device-enumeration-example.ts +86 -0
- package/examples/node/device-info-example.ts +131 -0
- package/examples/node/errors-example.ts +166 -0
- package/examples/node/package-lock.json +281 -0
- package/examples/node/package.json +25 -0
- package/examples/node/remote-connector-example.ts +84 -0
- package/examples/node/tsconfig.json +14 -0
- package/examples/web/application-example.js +197 -0
- package/examples/web/async-example.js +90 -0
- package/examples/web/device-control-example.js +87 -0
- package/examples/web/device-enumeration-example.js +49 -0
- package/examples/web/device-info-example.js +100 -0
- package/examples/web/errors-example.js +110 -0
- package/examples/web/index.html +55 -0
- package/examples/web/logging.js +42 -0
- package/examples/web/ping-timeout-example.js +59 -0
- package/examples/web/remote-connector-example.js +68 -0
- package/node-test.js +24 -0
- package/node-test.ts +23 -5
- package/package.json +85 -87
- package/src/client/ButtplugBrowserWebsocketClientConnector.ts +25 -25
- package/src/client/ButtplugClient.ts +242 -0
- package/src/client/ButtplugClientConnectorException.ts +16 -16
- package/src/client/ButtplugClientDevice.ts +178 -401
- package/src/client/ButtplugClientDeviceCommand.ts +112 -0
- package/src/client/ButtplugClientDeviceFeature.ts +138 -0
- package/src/client/ButtplugNodeWebsocketClientConnector.ts +17 -17
- package/src/client/IButtplugClientConnector.ts +18 -18
- package/src/core/Exceptions.ts +107 -101
- package/src/core/Logging.ts +197 -197
- package/src/core/Messages.ts +205 -480
- package/src/core/index.d.ts +4 -4
- package/src/index.ts +21 -19
- package/src/utils/ButtplugBrowserWebsocketConnector.ts +89 -89
- package/src/utils/ButtplugMessageSorter.ts +66 -65
- package/src/utils/Utils.ts +3 -3
- package/tsconfig.json +22 -22
- package/tsfmt.json +14 -14
- package/tslint.json +27 -27
- package/typedocconfig.js +6 -6
- package/vite.config.ts +26 -26
- package/dist/main/src/client/Client.js +0 -242
- package/dist/main/src/client/Client.js.map +0 -1
- package/dist/main/src/core/MessageUtils.d.ts +0 -10
- package/dist/main/src/core/MessageUtils.js +0 -65
- package/dist/main/src/core/MessageUtils.js.map +0 -1
- package/dist/web/core/MessageUtils.d.ts +0 -10
- package/doc/.nojekyll +0 -1
- package/doc/assets/highlight.css +0 -22
- package/doc/assets/main.js +0 -58
- package/doc/assets/search.js +0 -1
- package/doc/assets/style.css +0 -1280
- package/doc/classes/ButtplugBrowserWebsocketClientConnector.html +0 -234
- package/doc/classes/ButtplugClient.html +0 -331
- package/doc/classes/ButtplugClientConnectorException.html +0 -216
- package/doc/classes/ButtplugClientDevice.html +0 -489
- package/doc/classes/ButtplugDeviceError.html +0 -218
- package/doc/classes/ButtplugDeviceMessage.html +0 -165
- package/doc/classes/ButtplugError.html +0 -220
- package/doc/classes/ButtplugInitError.html +0 -218
- package/doc/classes/ButtplugLogger.html +0 -288
- package/doc/classes/ButtplugMessage.html +0 -147
- package/doc/classes/ButtplugMessageError.html +0 -218
- package/doc/classes/ButtplugMessageSorter.html +0 -128
- package/doc/classes/ButtplugNodeWebsocketClientConnector.html +0 -239
- package/doc/classes/ButtplugPingError.html +0 -218
- package/doc/classes/ButtplugSystemMessage.html +0 -150
- package/doc/classes/ButtplugUnknownError.html +0 -218
- package/doc/classes/DeviceAdded.html +0 -186
- package/doc/classes/DeviceInfo.html +0 -114
- package/doc/classes/DeviceList.html +0 -160
- package/doc/classes/DeviceRemoved.html +0 -158
- package/doc/classes/Error.html +0 -179
- package/doc/classes/GenericDeviceMessageAttributes.html +0 -107
- package/doc/classes/GenericMessageSubcommand.html +0 -90
- package/doc/classes/LinearCmd.html +0 -187
- package/doc/classes/LogMessage.html +0 -134
- package/doc/classes/MessageAttributes.html +0 -160
- package/doc/classes/Ok.html +0 -151
- package/doc/classes/Ping.html +0 -151
- package/doc/classes/RawDeviceMessageAttributes.html +0 -86
- package/doc/classes/RawReadCmd.html +0 -188
- package/doc/classes/RawReading.html +0 -179
- package/doc/classes/RawSubscribeCmd.html +0 -170
- package/doc/classes/RawUnsubscribeCmd.html +0 -170
- package/doc/classes/RawWriteCmd.html +0 -188
- package/doc/classes/RequestDeviceList.html +0 -151
- package/doc/classes/RequestServerInfo.html +0 -169
- package/doc/classes/RotateCmd.html +0 -187
- package/doc/classes/RotateSubcommand.html +0 -108
- package/doc/classes/ScalarCmd.html +0 -170
- package/doc/classes/ScalarSubcommand.html +0 -108
- package/doc/classes/ScanningFinished.html +0 -146
- package/doc/classes/SensorDeviceMessageAttributes.html +0 -107
- package/doc/classes/SensorReadCmd.html +0 -179
- package/doc/classes/SensorReading.html +0 -188
- package/doc/classes/ServerInfo.html +0 -178
- package/doc/classes/StartScanning.html +0 -151
- package/doc/classes/StopAllDevices.html +0 -151
- package/doc/classes/StopDeviceCmd.html +0 -161
- package/doc/classes/StopScanning.html +0 -151
- package/doc/classes/VectorSubcommand.html +0 -108
- package/doc/enums/ActuatorType.html +0 -104
- package/doc/enums/ButtplugLogLevel.html +0 -97
- package/doc/enums/ErrorClass.html +0 -90
- package/doc/enums/SensorType.html +0 -90
- package/doc/functions/FromJSON.html +0 -113
- package/doc/index.html +0 -184
- package/doc/interfaces/IButtplugClientConnector.html +0 -137
- package/doc/modules.html +0 -176
- package/doc/variables/DEFAULT_MESSAGE_ID.html +0 -104
- package/doc/variables/MAX_ID.html +0 -104
- package/doc/variables/MESSAGE_SPEC_VERSION.html +0 -104
- package/doc/variables/SYSTEM_MESSAGE_ID.html +0 -104
- package/src/client/Client.ts +0 -276
- package/src/core/MessageUtils.ts +0 -48
package/src/core/Messages.ts
CHANGED
|
@@ -1,480 +1,205 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Buttplug JS Source Code File - Visit https://buttplug.io for more info about
|
|
3
|
-
* the project. Licensed under the BSD 3-Clause license. See LICENSE file in the
|
|
4
|
-
* project root for full license information.
|
|
5
|
-
*
|
|
6
|
-
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// tslint:disable:max-classes-per-file
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export const
|
|
16
|
-
export const
|
|
17
|
-
export const
|
|
18
|
-
export const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
constructor(data: Partial<DeviceAdded>) {
|
|
207
|
-
super();
|
|
208
|
-
Object.assign(this, data);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
public update() {
|
|
212
|
-
this.DeviceMessages.update();
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export class DeviceRemoved extends ButtplugSystemMessage {
|
|
217
|
-
static Name = 'DeviceRemoved';
|
|
218
|
-
|
|
219
|
-
constructor(public DeviceIndex: number) {
|
|
220
|
-
super();
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export class RequestDeviceList extends ButtplugMessage {
|
|
225
|
-
static Name = 'RequestDeviceList';
|
|
226
|
-
|
|
227
|
-
constructor(public Id: number = DEFAULT_MESSAGE_ID) {
|
|
228
|
-
super(Id);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export class StartScanning extends ButtplugMessage {
|
|
233
|
-
static Name = 'StartScanning';
|
|
234
|
-
|
|
235
|
-
constructor(public Id: number = DEFAULT_MESSAGE_ID) {
|
|
236
|
-
super(Id);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export class StopScanning extends ButtplugMessage {
|
|
241
|
-
static Name = 'StopScanning';
|
|
242
|
-
|
|
243
|
-
constructor(public Id: number = DEFAULT_MESSAGE_ID) {
|
|
244
|
-
super(Id);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export class ScanningFinished extends ButtplugSystemMessage {
|
|
249
|
-
static Name = 'ScanningFinished';
|
|
250
|
-
|
|
251
|
-
constructor() {
|
|
252
|
-
super();
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export class RequestServerInfo extends ButtplugMessage {
|
|
257
|
-
static Name = 'RequestServerInfo';
|
|
258
|
-
|
|
259
|
-
constructor(
|
|
260
|
-
public ClientName: string,
|
|
261
|
-
public MessageVersion: number = 0,
|
|
262
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
263
|
-
) {
|
|
264
|
-
super(Id);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export class ServerInfo extends ButtplugSystemMessage {
|
|
269
|
-
static Name = 'ServerInfo';
|
|
270
|
-
|
|
271
|
-
constructor(
|
|
272
|
-
public MessageVersion: number,
|
|
273
|
-
public MaxPingTime: number,
|
|
274
|
-
public ServerName: string,
|
|
275
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
276
|
-
) {
|
|
277
|
-
super();
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export class StopDeviceCmd extends ButtplugDeviceMessage {
|
|
282
|
-
static Name = 'StopDeviceCmd';
|
|
283
|
-
|
|
284
|
-
constructor(
|
|
285
|
-
public DeviceIndex: number = -1,
|
|
286
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
287
|
-
) {
|
|
288
|
-
super(DeviceIndex, Id);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export class StopAllDevices extends ButtplugMessage {
|
|
293
|
-
static Name = 'StopAllDevices';
|
|
294
|
-
|
|
295
|
-
constructor(public Id: number = DEFAULT_MESSAGE_ID) {
|
|
296
|
-
super(Id);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export class GenericMessageSubcommand {
|
|
301
|
-
protected constructor(public Index: number) {}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
export class ScalarSubcommand extends GenericMessageSubcommand {
|
|
305
|
-
constructor(
|
|
306
|
-
Index: number,
|
|
307
|
-
public Scalar: number,
|
|
308
|
-
public ActuatorType: ActuatorType
|
|
309
|
-
) {
|
|
310
|
-
super(Index);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
export class ScalarCmd extends ButtplugDeviceMessage {
|
|
315
|
-
static Name = 'ScalarCmd';
|
|
316
|
-
|
|
317
|
-
constructor(
|
|
318
|
-
public Scalars: ScalarSubcommand[],
|
|
319
|
-
public DeviceIndex: number = -1,
|
|
320
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
321
|
-
) {
|
|
322
|
-
super(DeviceIndex, Id);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
export class RotateSubcommand extends GenericMessageSubcommand {
|
|
327
|
-
constructor(Index: number, public Speed: number, public Clockwise: boolean) {
|
|
328
|
-
super(Index);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
export class RotateCmd extends ButtplugDeviceMessage {
|
|
333
|
-
static Name = 'RotateCmd';
|
|
334
|
-
|
|
335
|
-
public static Create(
|
|
336
|
-
deviceIndex: number,
|
|
337
|
-
commands: [number, boolean][]
|
|
338
|
-
): RotateCmd {
|
|
339
|
-
const cmdList: RotateSubcommand[] = new Array<RotateSubcommand>();
|
|
340
|
-
|
|
341
|
-
let i = 0;
|
|
342
|
-
for (const [speed, clockwise] of commands) {
|
|
343
|
-
cmdList.push(new RotateSubcommand(i, speed, clockwise));
|
|
344
|
-
++i;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return new RotateCmd(cmdList, deviceIndex);
|
|
348
|
-
}
|
|
349
|
-
constructor(
|
|
350
|
-
public Rotations: RotateSubcommand[],
|
|
351
|
-
public DeviceIndex: number = -1,
|
|
352
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
353
|
-
) {
|
|
354
|
-
super(DeviceIndex, Id);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
export class VectorSubcommand extends GenericMessageSubcommand {
|
|
359
|
-
constructor(Index: number, public Position: number, public Duration: number) {
|
|
360
|
-
super(Index);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
export class LinearCmd extends ButtplugDeviceMessage {
|
|
365
|
-
static Name = 'LinearCmd';
|
|
366
|
-
|
|
367
|
-
public static Create(
|
|
368
|
-
deviceIndex: number,
|
|
369
|
-
commands: [number, number][]
|
|
370
|
-
): LinearCmd {
|
|
371
|
-
const cmdList: VectorSubcommand[] = new Array<VectorSubcommand>();
|
|
372
|
-
|
|
373
|
-
let i = 0;
|
|
374
|
-
for (const cmd of commands) {
|
|
375
|
-
cmdList.push(new VectorSubcommand(i, cmd[0], cmd[1]));
|
|
376
|
-
++i;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
return new LinearCmd(cmdList, deviceIndex);
|
|
380
|
-
}
|
|
381
|
-
constructor(
|
|
382
|
-
public Vectors: VectorSubcommand[],
|
|
383
|
-
public DeviceIndex: number = -1,
|
|
384
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
385
|
-
) {
|
|
386
|
-
super(DeviceIndex, Id);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
export class SensorReadCmd extends ButtplugDeviceMessage {
|
|
391
|
-
static Name = 'SensorReadCmd';
|
|
392
|
-
|
|
393
|
-
constructor(
|
|
394
|
-
public DeviceIndex: number,
|
|
395
|
-
public SensorIndex: number,
|
|
396
|
-
public SensorType: SensorType,
|
|
397
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
398
|
-
) {
|
|
399
|
-
super(DeviceIndex, Id);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
export class SensorReading extends ButtplugDeviceMessage {
|
|
404
|
-
static Name = 'SensorReading';
|
|
405
|
-
|
|
406
|
-
constructor(
|
|
407
|
-
public DeviceIndex: number,
|
|
408
|
-
public SensorIndex: number,
|
|
409
|
-
public SensorType: SensorType,
|
|
410
|
-
public Data: number[],
|
|
411
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
412
|
-
) {
|
|
413
|
-
super(DeviceIndex, Id);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
export class RawReadCmd extends ButtplugDeviceMessage {
|
|
418
|
-
static Name = 'RawReadCmd';
|
|
419
|
-
|
|
420
|
-
constructor(
|
|
421
|
-
public DeviceIndex: number,
|
|
422
|
-
public Endpoint: string,
|
|
423
|
-
public ExpectedLength: number,
|
|
424
|
-
public Timeout: number,
|
|
425
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
426
|
-
) {
|
|
427
|
-
super(DeviceIndex, Id);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
export class RawWriteCmd extends ButtplugDeviceMessage {
|
|
432
|
-
static Name = 'RawWriteCmd';
|
|
433
|
-
|
|
434
|
-
constructor(
|
|
435
|
-
public DeviceIndex: number,
|
|
436
|
-
public Endpoint: string,
|
|
437
|
-
public Data: Uint8Array,
|
|
438
|
-
public WriteWithResponse: boolean,
|
|
439
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
440
|
-
) {
|
|
441
|
-
super(DeviceIndex, Id);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
export class RawSubscribeCmd extends ButtplugDeviceMessage {
|
|
446
|
-
static Name = 'RawSubscribeCmd';
|
|
447
|
-
|
|
448
|
-
constructor(
|
|
449
|
-
public DeviceIndex: number,
|
|
450
|
-
public Endpoint: string,
|
|
451
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
452
|
-
) {
|
|
453
|
-
super(DeviceIndex, Id);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
export class RawUnsubscribeCmd extends ButtplugDeviceMessage {
|
|
458
|
-
static Name = 'RawUnsubscribeCmd';
|
|
459
|
-
|
|
460
|
-
constructor(
|
|
461
|
-
public DeviceIndex: number,
|
|
462
|
-
public Endpoint: string,
|
|
463
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
464
|
-
) {
|
|
465
|
-
super(DeviceIndex, Id);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
export class RawReading extends ButtplugDeviceMessage {
|
|
470
|
-
static Name = 'RawReading';
|
|
471
|
-
|
|
472
|
-
constructor(
|
|
473
|
-
public DeviceIndex: number,
|
|
474
|
-
public Endpoint: string,
|
|
475
|
-
public Data: number[],
|
|
476
|
-
public Id: number = DEFAULT_MESSAGE_ID
|
|
477
|
-
) {
|
|
478
|
-
super(DeviceIndex, Id);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
1
|
+
/*!
|
|
2
|
+
* Buttplug JS Source Code File - Visit https://buttplug.io for more info about
|
|
3
|
+
* the project. Licensed under the BSD 3-Clause license. See LICENSE file in the
|
|
4
|
+
* project root for full license information.
|
|
5
|
+
*
|
|
6
|
+
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// tslint:disable:max-classes-per-file
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
import { ButtplugMessageError } from './Exceptions';
|
|
13
|
+
|
|
14
|
+
export const SYSTEM_MESSAGE_ID = 0;
|
|
15
|
+
export const DEFAULT_MESSAGE_ID = 1;
|
|
16
|
+
export const MAX_ID = 4294967295;
|
|
17
|
+
export const MESSAGE_SPEC_VERSION_MAJOR = 4;
|
|
18
|
+
export const MESSAGE_SPEC_VERSION_MINOR = 0;
|
|
19
|
+
|
|
20
|
+
// Base message interfaces
|
|
21
|
+
export interface ButtplugMessage {
|
|
22
|
+
Ok?: Ok;
|
|
23
|
+
Ping?: Ping;
|
|
24
|
+
Error?: Error;
|
|
25
|
+
RequestServerInfo?: RequestServerInfo;
|
|
26
|
+
ServerInfo?: ServerInfo;
|
|
27
|
+
RequestDeviceList?: RequestDeviceList;
|
|
28
|
+
StartScanning?: StartScanning;
|
|
29
|
+
StopScanning?: StopScanning;
|
|
30
|
+
ScanningFinished?: ScanningFinished;
|
|
31
|
+
StopCmd?: StopCmd;
|
|
32
|
+
InputCmd?: InputCmd;
|
|
33
|
+
InputReading?: InputReading;
|
|
34
|
+
OutputCmd?: OutputCmd;
|
|
35
|
+
DeviceList?: DeviceList;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function msgId(msg: ButtplugMessage): number {
|
|
39
|
+
for (let [_, entry] of Object.entries(msg)) {
|
|
40
|
+
if (entry != undefined) {
|
|
41
|
+
return entry.Id;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw new ButtplugMessageError(`Message ${msg} does not have an ID.`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function setMsgId(msg: ButtplugMessage, id: number) {
|
|
48
|
+
for (let [_, entry] of Object.entries(msg)) {
|
|
49
|
+
if (entry != undefined) {
|
|
50
|
+
entry.Id = id;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
throw new ButtplugMessageError(`Message ${msg} does not have an ID.`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface Ok {
|
|
58
|
+
Id: number | undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface Ping {
|
|
62
|
+
Id: number | undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export enum ErrorClass {
|
|
66
|
+
ERROR_UNKNOWN,
|
|
67
|
+
ERROR_INIT,
|
|
68
|
+
ERROR_PING,
|
|
69
|
+
ERROR_MSG,
|
|
70
|
+
ERROR_DEVICE,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface Error {
|
|
74
|
+
ErrorMessage: string;
|
|
75
|
+
ErrorCode: ErrorClass;
|
|
76
|
+
Id: number | undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface RequestDeviceList {
|
|
80
|
+
Id: number | undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface StartScanning {
|
|
84
|
+
Id: number | undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface StopScanning {
|
|
88
|
+
Id: number | undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ScanningFinished {
|
|
92
|
+
Id: number | undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface RequestServerInfo {
|
|
96
|
+
ClientName: string;
|
|
97
|
+
ProtocolVersionMajor: number;
|
|
98
|
+
ProtocolVersionMinor: number;
|
|
99
|
+
Id: number | undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface ServerInfo {
|
|
103
|
+
MaxPingTime: number;
|
|
104
|
+
ServerName: string;
|
|
105
|
+
ProtocolVersionMajor: number;
|
|
106
|
+
ProtocolVersionMinor: number;
|
|
107
|
+
Id: number | undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface DeviceFeature {
|
|
111
|
+
FeatureDescriptor: string;
|
|
112
|
+
Output: { [key: string]: DeviceFeatureOutput };
|
|
113
|
+
Input: { [key: string]: DeviceFeatureInput };
|
|
114
|
+
FeatureIndex: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface DeviceInfo {
|
|
118
|
+
DeviceIndex: number;
|
|
119
|
+
DeviceName: string;
|
|
120
|
+
DeviceFeatures: { [key: number]: DeviceFeature };
|
|
121
|
+
DeviceDisplayName?: string;
|
|
122
|
+
DeviceMessageTimingGap?: number;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface DeviceList {
|
|
126
|
+
Devices: { [key: number]: DeviceInfo };
|
|
127
|
+
Id: number | undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export enum OutputType {
|
|
131
|
+
Unknown = 'Unknown',
|
|
132
|
+
Vibrate = 'Vibrate',
|
|
133
|
+
Rotate = 'Rotate',
|
|
134
|
+
Oscillate = 'Oscillate',
|
|
135
|
+
Constrict = 'Constrict',
|
|
136
|
+
Inflate = 'Inflate',
|
|
137
|
+
Position = 'Position',
|
|
138
|
+
HwPositionWithDuration = 'HwPositionWithDuration',
|
|
139
|
+
Temperature = 'Temperature',
|
|
140
|
+
Spray = 'Spray',
|
|
141
|
+
Led = 'Led',
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export enum InputType {
|
|
145
|
+
Unknown = 'Unknown',
|
|
146
|
+
Battery = 'Battery',
|
|
147
|
+
RSSI = 'RSSI',
|
|
148
|
+
Button = 'Button',
|
|
149
|
+
Pressure = 'Pressure',
|
|
150
|
+
// Temperature,
|
|
151
|
+
// Accelerometer,
|
|
152
|
+
// Gyro,
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export enum InputCommandType {
|
|
156
|
+
Read = 'Read',
|
|
157
|
+
Subscribe = 'Subscribe',
|
|
158
|
+
Unsubscribe = 'Unsubscribe',
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface DeviceFeatureInput {
|
|
162
|
+
Value: number[];
|
|
163
|
+
Command: InputCommandType[];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface DeviceFeatureOutput {
|
|
167
|
+
Value: number;
|
|
168
|
+
Duration?: number;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface OutputCmd {
|
|
172
|
+
DeviceIndex: number;
|
|
173
|
+
FeatureIndex: number;
|
|
174
|
+
Command: { [key: string]: DeviceFeatureOutput };
|
|
175
|
+
Id: number | undefined;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Device Input Commands
|
|
179
|
+
|
|
180
|
+
export interface InputCmd {
|
|
181
|
+
DeviceIndex: number;
|
|
182
|
+
FeatureIndex: number;
|
|
183
|
+
Type: InputType;
|
|
184
|
+
Command: InputCommandType;
|
|
185
|
+
Id: number | undefined;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface InputValue {
|
|
189
|
+
Value: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface InputReading {
|
|
193
|
+
DeviceIndex: number;
|
|
194
|
+
FeatureIndex: number;
|
|
195
|
+
Reading: { [key: string]: InputValue };
|
|
196
|
+
Id: number | undefined;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface StopCmd {
|
|
200
|
+
Id: number | undefined;
|
|
201
|
+
DeviceIndex: number | undefined;
|
|
202
|
+
FeatureIndex: number | undefined;
|
|
203
|
+
Inputs: boolean | undefined;
|
|
204
|
+
Outputs: boolean | undefined;
|
|
205
|
+
}
|
package/src/core/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare module '*.json' {
|
|
2
|
-
const content: string;
|
|
3
|
-
export default content;
|
|
4
|
-
}
|
|
1
|
+
declare module '*.json' {
|
|
2
|
+
const content: string;
|
|
3
|
+
export default content;
|
|
4
|
+
}
|