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.
Files changed (179) hide show
  1. package/.eslintrc.js +25 -25
  2. package/.jscsrc +2 -2
  3. package/.jshintrc +5 -5
  4. package/.prettierrc.json +3 -3
  5. package/.yarnrc.yml +5 -5
  6. package/CHANGELOG.md +591 -577
  7. package/LICENSE +27 -27
  8. package/README.md +105 -97
  9. package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js +6 -9
  10. package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js.map +1 -1
  11. package/dist/main/src/client/{Client.d.ts → ButtplugClient.d.ts} +3 -4
  12. package/dist/main/src/client/ButtplugClient.js +232 -0
  13. package/dist/main/src/client/ButtplugClient.js.map +1 -0
  14. package/dist/main/src/client/ButtplugClientConnectorException.js +17 -7
  15. package/dist/main/src/client/ButtplugClientConnectorException.js.map +1 -1
  16. package/dist/main/src/client/ButtplugClientDevice.d.ts +13 -28
  17. package/dist/main/src/client/ButtplugClientDevice.js +105 -247
  18. package/dist/main/src/client/ButtplugClientDevice.js.map +1 -1
  19. package/dist/main/src/client/ButtplugClientDeviceCommand.d.ts +42 -0
  20. package/dist/main/src/client/ButtplugClientDeviceCommand.js +105 -0
  21. package/dist/main/src/client/ButtplugClientDeviceCommand.js.map +1 -0
  22. package/dist/main/src/client/ButtplugClientDeviceFeature.d.ts +18 -0
  23. package/dist/main/src/client/ButtplugClientDeviceFeature.js +166 -0
  24. package/dist/main/src/client/ButtplugClientDeviceFeature.js.map +1 -0
  25. package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.d.ts +1 -8
  26. package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.js +1 -4
  27. package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.js.map +1 -1
  28. package/dist/main/src/core/Exceptions.js +27 -9
  29. package/dist/main/src/core/Exceptions.js.map +1 -1
  30. package/dist/main/src/core/Logging.js +12 -6
  31. package/dist/main/src/core/Logging.js.map +1 -1
  32. package/dist/main/src/core/Messages.d.ts +119 -230
  33. package/dist/main/src/core/Messages.js +50 -404
  34. package/dist/main/src/core/Messages.js.map +1 -1
  35. package/dist/main/src/index.d.ts +2 -2
  36. package/dist/main/src/index.js +4 -2
  37. package/dist/main/src/index.js.map +1 -1
  38. package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.js +40 -52
  39. package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.js.map +1 -1
  40. package/dist/main/src/utils/ButtplugMessageSorter.js +27 -15
  41. package/dist/main/src/utils/ButtplugMessageSorter.js.map +1 -1
  42. package/dist/main/src/utils/Utils.js +1 -2
  43. package/dist/main/src/utils/Utils.js.map +1 -1
  44. package/dist/web/buttplug.js +1 -38
  45. package/dist/web/buttplug.mjs +595 -1984
  46. package/dist/web/client/ButtplugBrowserWebsocketClientConnector.d.ts +0 -7
  47. package/dist/web/client/{Client.d.ts → ButtplugClient.d.ts} +3 -11
  48. package/dist/web/client/ButtplugClientConnectorException.d.ts +0 -7
  49. package/dist/web/client/ButtplugClientDevice.d.ts +14 -29
  50. package/dist/web/client/ButtplugClientDeviceCommand.d.ts +42 -0
  51. package/dist/web/client/ButtplugClientDeviceFeature.d.ts +18 -0
  52. package/dist/web/client/ButtplugNodeWebsocketClientConnector.d.ts +1 -15
  53. package/dist/web/client/IButtplugClientConnector.d.ts +0 -7
  54. package/dist/web/core/Exceptions.d.ts +1 -1
  55. package/dist/web/core/Logging.d.ts +0 -7
  56. package/dist/web/core/Messages.d.ts +119 -229
  57. package/dist/web/index.d.ts +2 -2
  58. package/dist/web/utils/ButtplugBrowserWebsocketConnector.d.ts +0 -7
  59. package/examples/node/SYNC_MANIFEST.md +105 -0
  60. package/examples/node/application-example.ts +213 -0
  61. package/examples/node/async-example.ts +124 -0
  62. package/examples/node/connection-example.ts +76 -0
  63. package/examples/node/device-control-example.ts +131 -0
  64. package/examples/node/device-enumeration-example.ts +86 -0
  65. package/examples/node/device-info-example.ts +131 -0
  66. package/examples/node/errors-example.ts +166 -0
  67. package/examples/node/package-lock.json +281 -0
  68. package/examples/node/package.json +25 -0
  69. package/examples/node/remote-connector-example.ts +84 -0
  70. package/examples/node/tsconfig.json +14 -0
  71. package/examples/web/application-example.js +197 -0
  72. package/examples/web/async-example.js +90 -0
  73. package/examples/web/device-control-example.js +87 -0
  74. package/examples/web/device-enumeration-example.js +49 -0
  75. package/examples/web/device-info-example.js +100 -0
  76. package/examples/web/errors-example.js +110 -0
  77. package/examples/web/index.html +55 -0
  78. package/examples/web/logging.js +42 -0
  79. package/examples/web/ping-timeout-example.js +59 -0
  80. package/examples/web/remote-connector-example.js +68 -0
  81. package/node-test.js +24 -0
  82. package/node-test.ts +23 -5
  83. package/package.json +85 -87
  84. package/src/client/ButtplugBrowserWebsocketClientConnector.ts +25 -25
  85. package/src/client/ButtplugClient.ts +242 -0
  86. package/src/client/ButtplugClientConnectorException.ts +16 -16
  87. package/src/client/ButtplugClientDevice.ts +178 -401
  88. package/src/client/ButtplugClientDeviceCommand.ts +112 -0
  89. package/src/client/ButtplugClientDeviceFeature.ts +138 -0
  90. package/src/client/ButtplugNodeWebsocketClientConnector.ts +17 -17
  91. package/src/client/IButtplugClientConnector.ts +18 -18
  92. package/src/core/Exceptions.ts +107 -101
  93. package/src/core/Logging.ts +197 -197
  94. package/src/core/Messages.ts +205 -480
  95. package/src/core/index.d.ts +4 -4
  96. package/src/index.ts +21 -19
  97. package/src/utils/ButtplugBrowserWebsocketConnector.ts +89 -89
  98. package/src/utils/ButtplugMessageSorter.ts +66 -65
  99. package/src/utils/Utils.ts +3 -3
  100. package/tsconfig.json +22 -22
  101. package/tsfmt.json +14 -14
  102. package/tslint.json +27 -27
  103. package/typedocconfig.js +6 -6
  104. package/vite.config.ts +26 -26
  105. package/dist/main/src/client/Client.js +0 -242
  106. package/dist/main/src/client/Client.js.map +0 -1
  107. package/dist/main/src/core/MessageUtils.d.ts +0 -10
  108. package/dist/main/src/core/MessageUtils.js +0 -65
  109. package/dist/main/src/core/MessageUtils.js.map +0 -1
  110. package/dist/web/core/MessageUtils.d.ts +0 -10
  111. package/doc/.nojekyll +0 -1
  112. package/doc/assets/highlight.css +0 -22
  113. package/doc/assets/main.js +0 -58
  114. package/doc/assets/search.js +0 -1
  115. package/doc/assets/style.css +0 -1280
  116. package/doc/classes/ButtplugBrowserWebsocketClientConnector.html +0 -234
  117. package/doc/classes/ButtplugClient.html +0 -331
  118. package/doc/classes/ButtplugClientConnectorException.html +0 -216
  119. package/doc/classes/ButtplugClientDevice.html +0 -489
  120. package/doc/classes/ButtplugDeviceError.html +0 -218
  121. package/doc/classes/ButtplugDeviceMessage.html +0 -165
  122. package/doc/classes/ButtplugError.html +0 -220
  123. package/doc/classes/ButtplugInitError.html +0 -218
  124. package/doc/classes/ButtplugLogger.html +0 -288
  125. package/doc/classes/ButtplugMessage.html +0 -147
  126. package/doc/classes/ButtplugMessageError.html +0 -218
  127. package/doc/classes/ButtplugMessageSorter.html +0 -128
  128. package/doc/classes/ButtplugNodeWebsocketClientConnector.html +0 -239
  129. package/doc/classes/ButtplugPingError.html +0 -218
  130. package/doc/classes/ButtplugSystemMessage.html +0 -150
  131. package/doc/classes/ButtplugUnknownError.html +0 -218
  132. package/doc/classes/DeviceAdded.html +0 -186
  133. package/doc/classes/DeviceInfo.html +0 -114
  134. package/doc/classes/DeviceList.html +0 -160
  135. package/doc/classes/DeviceRemoved.html +0 -158
  136. package/doc/classes/Error.html +0 -179
  137. package/doc/classes/GenericDeviceMessageAttributes.html +0 -107
  138. package/doc/classes/GenericMessageSubcommand.html +0 -90
  139. package/doc/classes/LinearCmd.html +0 -187
  140. package/doc/classes/LogMessage.html +0 -134
  141. package/doc/classes/MessageAttributes.html +0 -160
  142. package/doc/classes/Ok.html +0 -151
  143. package/doc/classes/Ping.html +0 -151
  144. package/doc/classes/RawDeviceMessageAttributes.html +0 -86
  145. package/doc/classes/RawReadCmd.html +0 -188
  146. package/doc/classes/RawReading.html +0 -179
  147. package/doc/classes/RawSubscribeCmd.html +0 -170
  148. package/doc/classes/RawUnsubscribeCmd.html +0 -170
  149. package/doc/classes/RawWriteCmd.html +0 -188
  150. package/doc/classes/RequestDeviceList.html +0 -151
  151. package/doc/classes/RequestServerInfo.html +0 -169
  152. package/doc/classes/RotateCmd.html +0 -187
  153. package/doc/classes/RotateSubcommand.html +0 -108
  154. package/doc/classes/ScalarCmd.html +0 -170
  155. package/doc/classes/ScalarSubcommand.html +0 -108
  156. package/doc/classes/ScanningFinished.html +0 -146
  157. package/doc/classes/SensorDeviceMessageAttributes.html +0 -107
  158. package/doc/classes/SensorReadCmd.html +0 -179
  159. package/doc/classes/SensorReading.html +0 -188
  160. package/doc/classes/ServerInfo.html +0 -178
  161. package/doc/classes/StartScanning.html +0 -151
  162. package/doc/classes/StopAllDevices.html +0 -151
  163. package/doc/classes/StopDeviceCmd.html +0 -161
  164. package/doc/classes/StopScanning.html +0 -151
  165. package/doc/classes/VectorSubcommand.html +0 -108
  166. package/doc/enums/ActuatorType.html +0 -104
  167. package/doc/enums/ButtplugLogLevel.html +0 -97
  168. package/doc/enums/ErrorClass.html +0 -90
  169. package/doc/enums/SensorType.html +0 -90
  170. package/doc/functions/FromJSON.html +0 -113
  171. package/doc/index.html +0 -184
  172. package/doc/interfaces/IButtplugClientConnector.html +0 -137
  173. package/doc/modules.html +0 -176
  174. package/doc/variables/DEFAULT_MESSAGE_ID.html +0 -104
  175. package/doc/variables/MAX_ID.html +0 -104
  176. package/doc/variables/MESSAGE_SPEC_VERSION.html +0 -104
  177. package/doc/variables/SYSTEM_MESSAGE_ID.html +0 -104
  178. package/src/client/Client.ts +0 -276
  179. package/src/core/MessageUtils.ts +0 -48
@@ -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 { instanceToPlain, Type } from 'class-transformer';
13
- import 'reflect-metadata';
14
-
15
- export const SYSTEM_MESSAGE_ID = 0;
16
- export const DEFAULT_MESSAGE_ID = 1;
17
- export const MAX_ID = 4294967295;
18
- export const MESSAGE_SPEC_VERSION = 3;
19
-
20
- export class MessageAttributes {
21
- public ScalarCmd?: Array<GenericDeviceMessageAttributes>;
22
- public RotateCmd?: Array<GenericDeviceMessageAttributes>;
23
- public LinearCmd?: Array<GenericDeviceMessageAttributes>;
24
- public RawReadCmd?: RawDeviceMessageAttributes;
25
- public RawWriteCmd?: RawDeviceMessageAttributes;
26
- public RawSubscribeCmd?: RawDeviceMessageAttributes;
27
- public SensorReadCmd?: Array<SensorDeviceMessageAttributes>;
28
- public SensorSubscribeCmd?: Array<SensorDeviceMessageAttributes>;
29
- public StopDeviceCmd: {};
30
-
31
- constructor(data: Partial<MessageAttributes>) {
32
- Object.assign(this, data);
33
- }
34
-
35
- public update() {
36
- this.ScalarCmd?.forEach((x, i) => (x.Index = i));
37
- this.RotateCmd?.forEach((x, i) => (x.Index = i));
38
- this.LinearCmd?.forEach((x, i) => (x.Index = i));
39
- this.SensorReadCmd?.forEach((x, i) => (x.Index = i));
40
- this.SensorSubscribeCmd?.forEach((x, i) => (x.Index = i));
41
- }
42
- }
43
-
44
- export enum ActuatorType {
45
- Unknown = 'Unknown',
46
- Vibrate = 'Vibrate',
47
- Rotate = 'Rotate',
48
- Oscillate = 'Oscillate',
49
- Constrict = 'Constrict',
50
- Inflate = 'Inflate',
51
- Position = 'Position',
52
- }
53
-
54
- export enum SensorType {
55
- Unknown = 'Unknown',
56
- Battery = 'Battery',
57
- RSSI = 'RSSI',
58
- Button = 'Button',
59
- Pressure = 'Pressure',
60
- // Temperature,
61
- // Accelerometer,
62
- // Gyro,
63
- }
64
-
65
- export class GenericDeviceMessageAttributes {
66
- public FeatureDescriptor: string;
67
- public ActuatorType: ActuatorType;
68
- public StepCount: number;
69
- public Index = 0;
70
- constructor(data: Partial<GenericDeviceMessageAttributes>) {
71
- Object.assign(this, data);
72
- }
73
- }
74
-
75
- export class RawDeviceMessageAttributes {
76
- constructor(public Endpoints: Array<string>) {}
77
- }
78
-
79
- export class SensorDeviceMessageAttributes {
80
- public FeatureDescriptor: string;
81
- public SensorType: SensorType;
82
- public StepRange: Array<number>;
83
- public Index = 0;
84
- constructor(data: Partial<GenericDeviceMessageAttributes>) {
85
- Object.assign(this, data);
86
- }
87
- }
88
-
89
- export abstract class ButtplugMessage {
90
- constructor(public Id: number) {}
91
-
92
- // tslint:disable-next-line:ban-types
93
- public get Type(): Function {
94
- return this.constructor;
95
- }
96
-
97
- public toJSON(): string {
98
- return JSON.stringify(this.toProtocolFormat());
99
- }
100
-
101
- public toProtocolFormat(): object {
102
- const jsonObj = {};
103
- jsonObj[(this.constructor as unknown as { Name: string }).Name] =
104
- instanceToPlain(this);
105
- return jsonObj;
106
- }
107
-
108
- public update() {}
109
- }
110
-
111
- export abstract class ButtplugDeviceMessage extends ButtplugMessage {
112
- constructor(public DeviceIndex: number, public Id: number) {
113
- super(Id);
114
- }
115
- }
116
-
117
- export abstract class ButtplugSystemMessage extends ButtplugMessage {
118
- constructor(public Id: number = SYSTEM_MESSAGE_ID) {
119
- super(Id);
120
- }
121
- }
122
-
123
- export class Ok extends ButtplugSystemMessage {
124
- static Name = 'Ok';
125
-
126
- constructor(public Id: number = DEFAULT_MESSAGE_ID) {
127
- super(Id);
128
- }
129
- }
130
-
131
- export class Ping extends ButtplugMessage {
132
- static Name = 'Ping';
133
-
134
- constructor(public Id: number = DEFAULT_MESSAGE_ID) {
135
- super(Id);
136
- }
137
- }
138
-
139
- export enum ErrorClass {
140
- ERROR_UNKNOWN,
141
- ERROR_INIT,
142
- ERROR_PING,
143
- ERROR_MSG,
144
- ERROR_DEVICE,
145
- }
146
-
147
- export class Error extends ButtplugMessage {
148
- static Name = 'Error';
149
-
150
- constructor(
151
- public ErrorMessage: string,
152
- public ErrorCode: ErrorClass = ErrorClass.ERROR_UNKNOWN,
153
- public Id: number = DEFAULT_MESSAGE_ID
154
- ) {
155
- super(Id);
156
- }
157
-
158
- get Schemversion() {
159
- return 0;
160
- }
161
- }
162
-
163
- export class DeviceInfo {
164
- public DeviceIndex: number;
165
- public DeviceName: string;
166
- @Type(() => MessageAttributes)
167
- public DeviceMessages: MessageAttributes;
168
- public DeviceDisplayName?: string;
169
- public DeviceMessageTimingGap?: number;
170
-
171
- constructor(data: Partial<DeviceInfo>) {
172
- Object.assign(this, data);
173
- }
174
- }
175
-
176
- export class DeviceList extends ButtplugMessage {
177
- static Name = 'DeviceList';
178
-
179
- @Type(() => DeviceInfo)
180
- public Devices: DeviceInfo[];
181
- public Id: number;
182
-
183
- constructor(devices: DeviceInfo[], id: number = DEFAULT_MESSAGE_ID) {
184
- super(id);
185
- this.Devices = devices;
186
- this.Id = id;
187
- }
188
-
189
- public update() {
190
- for (const device of this.Devices) {
191
- device.DeviceMessages.update();
192
- }
193
- }
194
- }
195
-
196
- export class DeviceAdded extends ButtplugSystemMessage {
197
- static Name = 'DeviceAdded';
198
-
199
- public DeviceIndex: number;
200
- public DeviceName: string;
201
- @Type(() => MessageAttributes)
202
- public DeviceMessages: MessageAttributes;
203
- public DeviceDisplayName?: string;
204
- public DeviceMessageTimingGap?: number;
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
+ }
@@ -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
+ }