buttplug 3.1.1 → 3.2.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.
Files changed (68) hide show
  1. package/.eslintrc.js +13 -8
  2. package/CHANGELOG.md +16 -0
  3. package/README.md +24 -25
  4. package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.d.ts +13 -16
  5. package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js +23 -52
  6. package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js.map +1 -1
  7. package/dist/main/src/client/ButtplugClientConnectorException.d.ts +11 -11
  8. package/dist/main/src/client/ButtplugClientConnectorException.js +41 -41
  9. package/dist/main/src/client/ButtplugClientDevice.d.ts +67 -67
  10. package/dist/main/src/client/ButtplugClientDevice.js +324 -324
  11. package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.d.ts +18 -18
  12. package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.js +19 -19
  13. package/dist/main/src/client/Client.d.ts +41 -40
  14. package/dist/main/src/client/Client.js +240 -235
  15. package/dist/main/src/client/Client.js.map +1 -1
  16. package/dist/main/src/client/IButtplugClientConnector.d.ts +16 -16
  17. package/dist/main/src/client/IButtplugClientConnector.js +9 -9
  18. package/dist/main/src/core/Exceptions.d.ts +36 -36
  19. package/dist/main/src/core/Exceptions.js +106 -106
  20. package/dist/main/src/core/Logging.d.ts +112 -112
  21. package/dist/main/src/core/Logging.js +170 -170
  22. package/dist/main/src/core/Logging.js.map +1 -1
  23. package/dist/main/src/core/MessageUtils.d.ts +9 -9
  24. package/dist/main/src/core/MessageUtils.js +58 -58
  25. package/dist/main/src/core/Messages.d.ts +275 -275
  26. package/dist/main/src/core/Messages.js +429 -429
  27. package/dist/main/src/core/Messages.js.map +1 -1
  28. package/dist/main/src/index.d.ts +18 -18
  29. package/dist/main/src/index.js +34 -34
  30. package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.d.ts +22 -22
  31. package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.js +95 -95
  32. package/dist/main/src/utils/ButtplugMessageSorter.d.ts +19 -19
  33. package/dist/main/src/utils/ButtplugMessageSorter.js +81 -81
  34. package/dist/main/src/utils/Utils.d.ts +1 -1
  35. package/dist/main/src/utils/Utils.js +7 -7
  36. package/dist/web/buttplug.js +38 -7126
  37. package/dist/web/buttplug.mjs +2254 -0
  38. package/dist/web/client/ButtplugBrowserWebsocketClientConnector.d.ts +13 -0
  39. package/dist/web/client/ButtplugClientConnectorException.d.ts +11 -0
  40. package/dist/web/client/ButtplugClientDevice.d.ts +67 -0
  41. package/dist/web/client/ButtplugNodeWebsocketClientConnector.d.ts +18 -0
  42. package/dist/web/client/Client.d.ts +41 -0
  43. package/dist/web/client/IButtplugClientConnector.d.ts +16 -0
  44. package/dist/web/core/Exceptions.d.ts +36 -0
  45. package/dist/web/core/Logging.d.ts +112 -0
  46. package/dist/web/core/MessageUtils.d.ts +9 -0
  47. package/dist/web/core/Messages.d.ts +274 -0
  48. package/dist/web/index.d.ts +18 -0
  49. package/dist/web/utils/ButtplugBrowserWebsocketConnector.d.ts +22 -0
  50. package/dist/web/utils/ButtplugMessageSorter.d.ts +19 -0
  51. package/dist/web/utils/Utils.d.ts +1 -0
  52. package/package.json +23 -53
  53. package/src/client/ButtplugBrowserWebsocketClientConnector.ts +2 -24
  54. package/src/client/ButtplugClientDevice.ts +1 -1
  55. package/src/client/Client.ts +12 -6
  56. package/src/client/IButtplugClientConnector.ts +4 -4
  57. package/src/core/MessageUtils.ts +1 -1
  58. package/src/utils/ButtplugBrowserWebsocketConnector.ts +12 -12
  59. package/vite.config.ts +26 -0
  60. package/.github/FUNDING.yml +0 -5
  61. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -17
  62. package/.github/workflows/docs.yaml +0 -29
  63. package/azure-pipelines.yml +0 -19
  64. package/dist/web/buttplug.min.js +0 -3
  65. package/dist/web/buttplug.min.js.LICENSE.txt +0 -31
  66. package/dist/web/buttplug.min.js.map +0 -1
  67. package/jest-puppeteer.config.js +0 -5
  68. package/rollup.config.js +0 -55
@@ -1,430 +1,430 @@
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
- // tslint:disable:max-classes-per-file
9
- 'use strict';
10
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
11
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
12
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
13
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
14
- return c > 3 && r && Object.defineProperty(target, key, r), r;
15
- };
16
- var __metadata = (this && this.__metadata) || function (k, v) {
17
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.RawReading = exports.RawUnsubscribeCmd = exports.RawSubscribeCmd = exports.RawWriteCmd = exports.RawReadCmd = exports.SensorReading = exports.SensorReadCmd = exports.LinearCmd = exports.VectorSubcommand = exports.RotateCmd = exports.RotateSubcommand = exports.ScalarCmd = exports.ScalarSubcommand = exports.GenericMessageSubcommand = exports.StopAllDevices = exports.StopDeviceCmd = exports.ServerInfo = exports.RequestServerInfo = exports.ScanningFinished = exports.StopScanning = exports.StartScanning = exports.RequestDeviceList = exports.DeviceRemoved = exports.DeviceAdded = exports.DeviceList = exports.DeviceInfo = exports.Error = exports.ErrorClass = exports.Ping = exports.Ok = exports.ButtplugSystemMessage = exports.ButtplugDeviceMessage = exports.ButtplugMessage = exports.SensorDeviceMessageAttributes = exports.RawDeviceMessageAttributes = exports.GenericDeviceMessageAttributes = exports.SensorType = exports.ActuatorType = exports.MessageAttributes = exports.MESSAGE_SPEC_VERSION = exports.MAX_ID = exports.DEFAULT_MESSAGE_ID = exports.SYSTEM_MESSAGE_ID = void 0;
21
- const class_transformer_1 = require("class-transformer");
22
- require("reflect-metadata");
23
- exports.SYSTEM_MESSAGE_ID = 0;
24
- exports.DEFAULT_MESSAGE_ID = 1;
25
- exports.MAX_ID = 4294967295;
26
- exports.MESSAGE_SPEC_VERSION = 3;
27
- class MessageAttributes {
28
- constructor(data) {
29
- Object.assign(this, data);
30
- }
31
- update() {
32
- var _a, _b, _c, _d, _e;
33
- (_a = this.ScalarCmd) === null || _a === void 0 ? void 0 : _a.forEach((x, i) => (x.Index = i));
34
- (_b = this.RotateCmd) === null || _b === void 0 ? void 0 : _b.forEach((x, i) => (x.Index = i));
35
- (_c = this.LinearCmd) === null || _c === void 0 ? void 0 : _c.forEach((x, i) => (x.Index = i));
36
- (_d = this.SensorReadCmd) === null || _d === void 0 ? void 0 : _d.forEach((x, i) => (x.Index = i));
37
- (_e = this.SensorSubscribeCmd) === null || _e === void 0 ? void 0 : _e.forEach((x, i) => (x.Index = i));
38
- }
39
- }
40
- exports.MessageAttributes = MessageAttributes;
41
- var ActuatorType;
42
- (function (ActuatorType) {
43
- ActuatorType["Unknown"] = "Unknown";
44
- ActuatorType["Vibrate"] = "Vibrate";
45
- ActuatorType["Rotate"] = "Rotate";
46
- ActuatorType["Oscillate"] = "Oscillate";
47
- ActuatorType["Constrict"] = "Constrict";
48
- ActuatorType["Inflate"] = "Inflate";
49
- ActuatorType["Position"] = "Position";
50
- })(ActuatorType = exports.ActuatorType || (exports.ActuatorType = {}));
51
- var SensorType;
52
- (function (SensorType) {
53
- SensorType["Unknown"] = "Unknown";
54
- SensorType["Battery"] = "Battery";
55
- SensorType["RSSI"] = "RSSI";
56
- SensorType["Button"] = "Button";
57
- SensorType["Pressure"] = "Pressure";
58
- // Temperature,
59
- // Accelerometer,
60
- // Gyro,
61
- })(SensorType = exports.SensorType || (exports.SensorType = {}));
62
- class GenericDeviceMessageAttributes {
63
- constructor(data) {
64
- this.Index = 0;
65
- Object.assign(this, data);
66
- }
67
- }
68
- exports.GenericDeviceMessageAttributes = GenericDeviceMessageAttributes;
69
- class RawDeviceMessageAttributes {
70
- constructor(Endpoints) {
71
- this.Endpoints = Endpoints;
72
- }
73
- }
74
- exports.RawDeviceMessageAttributes = RawDeviceMessageAttributes;
75
- class SensorDeviceMessageAttributes {
76
- constructor(data) {
77
- this.Index = 0;
78
- Object.assign(this, data);
79
- }
80
- }
81
- exports.SensorDeviceMessageAttributes = SensorDeviceMessageAttributes;
82
- class ButtplugMessage {
83
- constructor(Id) {
84
- this.Id = Id;
85
- }
86
- // tslint:disable-next-line:ban-types
87
- get Type() {
88
- return this.constructor;
89
- }
90
- toJSON() {
91
- return JSON.stringify(this.toProtocolFormat());
92
- }
93
- toProtocolFormat() {
94
- const jsonObj = {};
95
- jsonObj[this.constructor.Name] =
96
- (0, class_transformer_1.instanceToPlain)(this);
97
- return jsonObj;
98
- }
99
- update() { }
100
- }
101
- exports.ButtplugMessage = ButtplugMessage;
102
- class ButtplugDeviceMessage extends ButtplugMessage {
103
- constructor(DeviceIndex, Id) {
104
- super(Id);
105
- this.DeviceIndex = DeviceIndex;
106
- this.Id = Id;
107
- }
108
- }
109
- exports.ButtplugDeviceMessage = ButtplugDeviceMessage;
110
- class ButtplugSystemMessage extends ButtplugMessage {
111
- constructor(Id = exports.SYSTEM_MESSAGE_ID) {
112
- super(Id);
113
- this.Id = Id;
114
- }
115
- }
116
- exports.ButtplugSystemMessage = ButtplugSystemMessage;
117
- class Ok extends ButtplugSystemMessage {
118
- constructor(Id = exports.DEFAULT_MESSAGE_ID) {
119
- super(Id);
120
- this.Id = Id;
121
- }
122
- }
123
- exports.Ok = Ok;
124
- Ok.Name = 'Ok';
125
- class Ping extends ButtplugMessage {
126
- constructor(Id = exports.DEFAULT_MESSAGE_ID) {
127
- super(Id);
128
- this.Id = Id;
129
- }
130
- }
131
- exports.Ping = Ping;
132
- Ping.Name = 'Ping';
133
- var ErrorClass;
134
- (function (ErrorClass) {
135
- ErrorClass[ErrorClass["ERROR_UNKNOWN"] = 0] = "ERROR_UNKNOWN";
136
- ErrorClass[ErrorClass["ERROR_INIT"] = 1] = "ERROR_INIT";
137
- ErrorClass[ErrorClass["ERROR_PING"] = 2] = "ERROR_PING";
138
- ErrorClass[ErrorClass["ERROR_MSG"] = 3] = "ERROR_MSG";
139
- ErrorClass[ErrorClass["ERROR_DEVICE"] = 4] = "ERROR_DEVICE";
140
- })(ErrorClass = exports.ErrorClass || (exports.ErrorClass = {}));
141
- class Error extends ButtplugMessage {
142
- constructor(ErrorMessage, ErrorCode = ErrorClass.ERROR_UNKNOWN, Id = exports.DEFAULT_MESSAGE_ID) {
143
- super(Id);
144
- this.ErrorMessage = ErrorMessage;
145
- this.ErrorCode = ErrorCode;
146
- this.Id = Id;
147
- }
148
- get Schemversion() {
149
- return 0;
150
- }
151
- }
152
- exports.Error = Error;
153
- Error.Name = 'Error';
154
- class DeviceInfo {
155
- constructor(data) {
156
- Object.assign(this, data);
157
- }
158
- }
159
- __decorate([
160
- (0, class_transformer_1.Type)(() => MessageAttributes),
161
- __metadata("design:type", MessageAttributes)
162
- ], DeviceInfo.prototype, "DeviceMessages", void 0);
163
- exports.DeviceInfo = DeviceInfo;
164
- class DeviceList extends ButtplugMessage {
165
- constructor(devices, id = exports.DEFAULT_MESSAGE_ID) {
166
- super(id);
167
- this.Devices = devices;
168
- this.Id = id;
169
- }
170
- update() {
171
- for (const device of this.Devices) {
172
- device.DeviceMessages.update();
173
- }
174
- }
175
- }
176
- DeviceList.Name = 'DeviceList';
177
- __decorate([
178
- (0, class_transformer_1.Type)(() => DeviceInfo),
179
- __metadata("design:type", Array)
180
- ], DeviceList.prototype, "Devices", void 0);
181
- exports.DeviceList = DeviceList;
182
- class DeviceAdded extends ButtplugSystemMessage {
183
- constructor(data) {
184
- super();
185
- Object.assign(this, data);
186
- }
187
- update() {
188
- this.DeviceMessages.update();
189
- }
190
- }
191
- DeviceAdded.Name = 'DeviceAdded';
192
- __decorate([
193
- (0, class_transformer_1.Type)(() => MessageAttributes),
194
- __metadata("design:type", MessageAttributes)
195
- ], DeviceAdded.prototype, "DeviceMessages", void 0);
196
- exports.DeviceAdded = DeviceAdded;
197
- class DeviceRemoved extends ButtplugSystemMessage {
198
- constructor(DeviceIndex) {
199
- super();
200
- this.DeviceIndex = DeviceIndex;
201
- }
202
- }
203
- exports.DeviceRemoved = DeviceRemoved;
204
- DeviceRemoved.Name = 'DeviceRemoved';
205
- class RequestDeviceList extends ButtplugMessage {
206
- constructor(Id = exports.DEFAULT_MESSAGE_ID) {
207
- super(Id);
208
- this.Id = Id;
209
- }
210
- }
211
- exports.RequestDeviceList = RequestDeviceList;
212
- RequestDeviceList.Name = 'RequestDeviceList';
213
- class StartScanning extends ButtplugMessage {
214
- constructor(Id = exports.DEFAULT_MESSAGE_ID) {
215
- super(Id);
216
- this.Id = Id;
217
- }
218
- }
219
- exports.StartScanning = StartScanning;
220
- StartScanning.Name = 'StartScanning';
221
- class StopScanning extends ButtplugMessage {
222
- constructor(Id = exports.DEFAULT_MESSAGE_ID) {
223
- super(Id);
224
- this.Id = Id;
225
- }
226
- }
227
- exports.StopScanning = StopScanning;
228
- StopScanning.Name = 'StopScanning';
229
- class ScanningFinished extends ButtplugSystemMessage {
230
- constructor() {
231
- super();
232
- }
233
- }
234
- exports.ScanningFinished = ScanningFinished;
235
- ScanningFinished.Name = 'ScanningFinished';
236
- class RequestServerInfo extends ButtplugMessage {
237
- constructor(ClientName, MessageVersion = 0, Id = exports.DEFAULT_MESSAGE_ID) {
238
- super(Id);
239
- this.ClientName = ClientName;
240
- this.MessageVersion = MessageVersion;
241
- this.Id = Id;
242
- }
243
- }
244
- exports.RequestServerInfo = RequestServerInfo;
245
- RequestServerInfo.Name = 'RequestServerInfo';
246
- class ServerInfo extends ButtplugSystemMessage {
247
- constructor(MessageVersion, MaxPingTime, ServerName, Id = exports.DEFAULT_MESSAGE_ID) {
248
- super();
249
- this.MessageVersion = MessageVersion;
250
- this.MaxPingTime = MaxPingTime;
251
- this.ServerName = ServerName;
252
- this.Id = Id;
253
- }
254
- }
255
- exports.ServerInfo = ServerInfo;
256
- ServerInfo.Name = 'ServerInfo';
257
- class StopDeviceCmd extends ButtplugDeviceMessage {
258
- constructor(DeviceIndex = -1, Id = exports.DEFAULT_MESSAGE_ID) {
259
- super(DeviceIndex, Id);
260
- this.DeviceIndex = DeviceIndex;
261
- this.Id = Id;
262
- }
263
- }
264
- exports.StopDeviceCmd = StopDeviceCmd;
265
- StopDeviceCmd.Name = 'StopDeviceCmd';
266
- class StopAllDevices extends ButtplugMessage {
267
- constructor(Id = exports.DEFAULT_MESSAGE_ID) {
268
- super(Id);
269
- this.Id = Id;
270
- }
271
- }
272
- exports.StopAllDevices = StopAllDevices;
273
- StopAllDevices.Name = 'StopAllDevices';
274
- class GenericMessageSubcommand {
275
- constructor(Index) {
276
- this.Index = Index;
277
- }
278
- }
279
- exports.GenericMessageSubcommand = GenericMessageSubcommand;
280
- class ScalarSubcommand extends GenericMessageSubcommand {
281
- constructor(Index, Scalar, ActuatorType) {
282
- super(Index);
283
- this.Scalar = Scalar;
284
- this.ActuatorType = ActuatorType;
285
- }
286
- }
287
- exports.ScalarSubcommand = ScalarSubcommand;
288
- class ScalarCmd extends ButtplugDeviceMessage {
289
- constructor(Scalars, DeviceIndex = -1, Id = exports.DEFAULT_MESSAGE_ID) {
290
- super(DeviceIndex, Id);
291
- this.Scalars = Scalars;
292
- this.DeviceIndex = DeviceIndex;
293
- this.Id = Id;
294
- }
295
- }
296
- exports.ScalarCmd = ScalarCmd;
297
- ScalarCmd.Name = 'ScalarCmd';
298
- class RotateSubcommand extends GenericMessageSubcommand {
299
- constructor(Index, Speed, Clockwise) {
300
- super(Index);
301
- this.Speed = Speed;
302
- this.Clockwise = Clockwise;
303
- }
304
- }
305
- exports.RotateSubcommand = RotateSubcommand;
306
- class RotateCmd extends ButtplugDeviceMessage {
307
- static Create(deviceIndex, commands) {
308
- const cmdList = new Array();
309
- let i = 0;
310
- for (const [speed, clockwise] of commands) {
311
- cmdList.push(new RotateSubcommand(i, speed, clockwise));
312
- ++i;
313
- }
314
- return new RotateCmd(cmdList, deviceIndex);
315
- }
316
- constructor(Rotations, DeviceIndex = -1, Id = exports.DEFAULT_MESSAGE_ID) {
317
- super(DeviceIndex, Id);
318
- this.Rotations = Rotations;
319
- this.DeviceIndex = DeviceIndex;
320
- this.Id = Id;
321
- }
322
- }
323
- exports.RotateCmd = RotateCmd;
324
- RotateCmd.Name = 'RotateCmd';
325
- class VectorSubcommand extends GenericMessageSubcommand {
326
- constructor(Index, Position, Duration) {
327
- super(Index);
328
- this.Position = Position;
329
- this.Duration = Duration;
330
- }
331
- }
332
- exports.VectorSubcommand = VectorSubcommand;
333
- class LinearCmd extends ButtplugDeviceMessage {
334
- static Create(deviceIndex, commands) {
335
- const cmdList = new Array();
336
- let i = 0;
337
- for (const cmd of commands) {
338
- cmdList.push(new VectorSubcommand(i, cmd[0], cmd[1]));
339
- ++i;
340
- }
341
- return new LinearCmd(cmdList, deviceIndex);
342
- }
343
- constructor(Vectors, DeviceIndex = -1, Id = exports.DEFAULT_MESSAGE_ID) {
344
- super(DeviceIndex, Id);
345
- this.Vectors = Vectors;
346
- this.DeviceIndex = DeviceIndex;
347
- this.Id = Id;
348
- }
349
- }
350
- exports.LinearCmd = LinearCmd;
351
- LinearCmd.Name = 'LinearCmd';
352
- class SensorReadCmd extends ButtplugDeviceMessage {
353
- constructor(DeviceIndex, SensorIndex, SensorType, Id = exports.DEFAULT_MESSAGE_ID) {
354
- super(DeviceIndex, Id);
355
- this.DeviceIndex = DeviceIndex;
356
- this.SensorIndex = SensorIndex;
357
- this.SensorType = SensorType;
358
- this.Id = Id;
359
- }
360
- }
361
- exports.SensorReadCmd = SensorReadCmd;
362
- SensorReadCmd.Name = 'SensorReadCmd';
363
- class SensorReading extends ButtplugDeviceMessage {
364
- constructor(DeviceIndex, SensorIndex, SensorType, Data, Id = exports.DEFAULT_MESSAGE_ID) {
365
- super(DeviceIndex, Id);
366
- this.DeviceIndex = DeviceIndex;
367
- this.SensorIndex = SensorIndex;
368
- this.SensorType = SensorType;
369
- this.Data = Data;
370
- this.Id = Id;
371
- }
372
- }
373
- exports.SensorReading = SensorReading;
374
- SensorReading.Name = 'SensorReading';
375
- class RawReadCmd extends ButtplugDeviceMessage {
376
- constructor(DeviceIndex, Endpoint, ExpectedLength, Timeout, Id = exports.DEFAULT_MESSAGE_ID) {
377
- super(DeviceIndex, Id);
378
- this.DeviceIndex = DeviceIndex;
379
- this.Endpoint = Endpoint;
380
- this.ExpectedLength = ExpectedLength;
381
- this.Timeout = Timeout;
382
- this.Id = Id;
383
- }
384
- }
385
- exports.RawReadCmd = RawReadCmd;
386
- RawReadCmd.Name = 'RawReadCmd';
387
- class RawWriteCmd extends ButtplugDeviceMessage {
388
- constructor(DeviceIndex, Endpoint, Data, WriteWithResponse, Id = exports.DEFAULT_MESSAGE_ID) {
389
- super(DeviceIndex, Id);
390
- this.DeviceIndex = DeviceIndex;
391
- this.Endpoint = Endpoint;
392
- this.Data = Data;
393
- this.WriteWithResponse = WriteWithResponse;
394
- this.Id = Id;
395
- }
396
- }
397
- exports.RawWriteCmd = RawWriteCmd;
398
- RawWriteCmd.Name = 'RawWriteCmd';
399
- class RawSubscribeCmd extends ButtplugDeviceMessage {
400
- constructor(DeviceIndex, Endpoint, Id = exports.DEFAULT_MESSAGE_ID) {
401
- super(DeviceIndex, Id);
402
- this.DeviceIndex = DeviceIndex;
403
- this.Endpoint = Endpoint;
404
- this.Id = Id;
405
- }
406
- }
407
- exports.RawSubscribeCmd = RawSubscribeCmd;
408
- RawSubscribeCmd.Name = 'RawSubscribeCmd';
409
- class RawUnsubscribeCmd extends ButtplugDeviceMessage {
410
- constructor(DeviceIndex, Endpoint, Id = exports.DEFAULT_MESSAGE_ID) {
411
- super(DeviceIndex, Id);
412
- this.DeviceIndex = DeviceIndex;
413
- this.Endpoint = Endpoint;
414
- this.Id = Id;
415
- }
416
- }
417
- exports.RawUnsubscribeCmd = RawUnsubscribeCmd;
418
- RawUnsubscribeCmd.Name = 'RawUnsubscribeCmd';
419
- class RawReading extends ButtplugDeviceMessage {
420
- constructor(DeviceIndex, Endpoint, Data, Id = exports.DEFAULT_MESSAGE_ID) {
421
- super(DeviceIndex, Id);
422
- this.DeviceIndex = DeviceIndex;
423
- this.Endpoint = Endpoint;
424
- this.Data = Data;
425
- this.Id = Id;
426
- }
427
- }
428
- exports.RawReading = RawReading;
429
- RawReading.Name = 'RawReading';
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
+ // tslint:disable:max-classes-per-file
9
+ 'use strict';
10
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
11
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
12
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
13
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
14
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
15
+ };
16
+ var __metadata = (this && this.__metadata) || function (k, v) {
17
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.RawReading = exports.RawUnsubscribeCmd = exports.RawSubscribeCmd = exports.RawWriteCmd = exports.RawReadCmd = exports.SensorReading = exports.SensorReadCmd = exports.LinearCmd = exports.VectorSubcommand = exports.RotateCmd = exports.RotateSubcommand = exports.ScalarCmd = exports.ScalarSubcommand = exports.GenericMessageSubcommand = exports.StopAllDevices = exports.StopDeviceCmd = exports.ServerInfo = exports.RequestServerInfo = exports.ScanningFinished = exports.StopScanning = exports.StartScanning = exports.RequestDeviceList = exports.DeviceRemoved = exports.DeviceAdded = exports.DeviceList = exports.DeviceInfo = exports.Error = exports.ErrorClass = exports.Ping = exports.Ok = exports.ButtplugSystemMessage = exports.ButtplugDeviceMessage = exports.ButtplugMessage = exports.SensorDeviceMessageAttributes = exports.RawDeviceMessageAttributes = exports.GenericDeviceMessageAttributes = exports.SensorType = exports.ActuatorType = exports.MessageAttributes = exports.MESSAGE_SPEC_VERSION = exports.MAX_ID = exports.DEFAULT_MESSAGE_ID = exports.SYSTEM_MESSAGE_ID = void 0;
21
+ const class_transformer_1 = require("class-transformer");
22
+ require("reflect-metadata");
23
+ exports.SYSTEM_MESSAGE_ID = 0;
24
+ exports.DEFAULT_MESSAGE_ID = 1;
25
+ exports.MAX_ID = 4294967295;
26
+ exports.MESSAGE_SPEC_VERSION = 3;
27
+ class MessageAttributes {
28
+ constructor(data) {
29
+ Object.assign(this, data);
30
+ }
31
+ update() {
32
+ var _a, _b, _c, _d, _e;
33
+ (_a = this.ScalarCmd) === null || _a === void 0 ? void 0 : _a.forEach((x, i) => (x.Index = i));
34
+ (_b = this.RotateCmd) === null || _b === void 0 ? void 0 : _b.forEach((x, i) => (x.Index = i));
35
+ (_c = this.LinearCmd) === null || _c === void 0 ? void 0 : _c.forEach((x, i) => (x.Index = i));
36
+ (_d = this.SensorReadCmd) === null || _d === void 0 ? void 0 : _d.forEach((x, i) => (x.Index = i));
37
+ (_e = this.SensorSubscribeCmd) === null || _e === void 0 ? void 0 : _e.forEach((x, i) => (x.Index = i));
38
+ }
39
+ }
40
+ exports.MessageAttributes = MessageAttributes;
41
+ var ActuatorType;
42
+ (function (ActuatorType) {
43
+ ActuatorType["Unknown"] = "Unknown";
44
+ ActuatorType["Vibrate"] = "Vibrate";
45
+ ActuatorType["Rotate"] = "Rotate";
46
+ ActuatorType["Oscillate"] = "Oscillate";
47
+ ActuatorType["Constrict"] = "Constrict";
48
+ ActuatorType["Inflate"] = "Inflate";
49
+ ActuatorType["Position"] = "Position";
50
+ })(ActuatorType || (exports.ActuatorType = ActuatorType = {}));
51
+ var SensorType;
52
+ (function (SensorType) {
53
+ SensorType["Unknown"] = "Unknown";
54
+ SensorType["Battery"] = "Battery";
55
+ SensorType["RSSI"] = "RSSI";
56
+ SensorType["Button"] = "Button";
57
+ SensorType["Pressure"] = "Pressure";
58
+ // Temperature,
59
+ // Accelerometer,
60
+ // Gyro,
61
+ })(SensorType || (exports.SensorType = SensorType = {}));
62
+ class GenericDeviceMessageAttributes {
63
+ constructor(data) {
64
+ this.Index = 0;
65
+ Object.assign(this, data);
66
+ }
67
+ }
68
+ exports.GenericDeviceMessageAttributes = GenericDeviceMessageAttributes;
69
+ class RawDeviceMessageAttributes {
70
+ constructor(Endpoints) {
71
+ this.Endpoints = Endpoints;
72
+ }
73
+ }
74
+ exports.RawDeviceMessageAttributes = RawDeviceMessageAttributes;
75
+ class SensorDeviceMessageAttributes {
76
+ constructor(data) {
77
+ this.Index = 0;
78
+ Object.assign(this, data);
79
+ }
80
+ }
81
+ exports.SensorDeviceMessageAttributes = SensorDeviceMessageAttributes;
82
+ class ButtplugMessage {
83
+ constructor(Id) {
84
+ this.Id = Id;
85
+ }
86
+ // tslint:disable-next-line:ban-types
87
+ get Type() {
88
+ return this.constructor;
89
+ }
90
+ toJSON() {
91
+ return JSON.stringify(this.toProtocolFormat());
92
+ }
93
+ toProtocolFormat() {
94
+ const jsonObj = {};
95
+ jsonObj[this.constructor.Name] =
96
+ (0, class_transformer_1.instanceToPlain)(this);
97
+ return jsonObj;
98
+ }
99
+ update() { }
100
+ }
101
+ exports.ButtplugMessage = ButtplugMessage;
102
+ class ButtplugDeviceMessage extends ButtplugMessage {
103
+ constructor(DeviceIndex, Id) {
104
+ super(Id);
105
+ this.DeviceIndex = DeviceIndex;
106
+ this.Id = Id;
107
+ }
108
+ }
109
+ exports.ButtplugDeviceMessage = ButtplugDeviceMessage;
110
+ class ButtplugSystemMessage extends ButtplugMessage {
111
+ constructor(Id = exports.SYSTEM_MESSAGE_ID) {
112
+ super(Id);
113
+ this.Id = Id;
114
+ }
115
+ }
116
+ exports.ButtplugSystemMessage = ButtplugSystemMessage;
117
+ class Ok extends ButtplugSystemMessage {
118
+ constructor(Id = exports.DEFAULT_MESSAGE_ID) {
119
+ super(Id);
120
+ this.Id = Id;
121
+ }
122
+ }
123
+ exports.Ok = Ok;
124
+ Ok.Name = 'Ok';
125
+ class Ping extends ButtplugMessage {
126
+ constructor(Id = exports.DEFAULT_MESSAGE_ID) {
127
+ super(Id);
128
+ this.Id = Id;
129
+ }
130
+ }
131
+ exports.Ping = Ping;
132
+ Ping.Name = 'Ping';
133
+ var ErrorClass;
134
+ (function (ErrorClass) {
135
+ ErrorClass[ErrorClass["ERROR_UNKNOWN"] = 0] = "ERROR_UNKNOWN";
136
+ ErrorClass[ErrorClass["ERROR_INIT"] = 1] = "ERROR_INIT";
137
+ ErrorClass[ErrorClass["ERROR_PING"] = 2] = "ERROR_PING";
138
+ ErrorClass[ErrorClass["ERROR_MSG"] = 3] = "ERROR_MSG";
139
+ ErrorClass[ErrorClass["ERROR_DEVICE"] = 4] = "ERROR_DEVICE";
140
+ })(ErrorClass || (exports.ErrorClass = ErrorClass = {}));
141
+ class Error extends ButtplugMessage {
142
+ constructor(ErrorMessage, ErrorCode = ErrorClass.ERROR_UNKNOWN, Id = exports.DEFAULT_MESSAGE_ID) {
143
+ super(Id);
144
+ this.ErrorMessage = ErrorMessage;
145
+ this.ErrorCode = ErrorCode;
146
+ this.Id = Id;
147
+ }
148
+ get Schemversion() {
149
+ return 0;
150
+ }
151
+ }
152
+ exports.Error = Error;
153
+ Error.Name = 'Error';
154
+ class DeviceInfo {
155
+ constructor(data) {
156
+ Object.assign(this, data);
157
+ }
158
+ }
159
+ exports.DeviceInfo = DeviceInfo;
160
+ __decorate([
161
+ (0, class_transformer_1.Type)(() => MessageAttributes),
162
+ __metadata("design:type", MessageAttributes)
163
+ ], DeviceInfo.prototype, "DeviceMessages", void 0);
164
+ class DeviceList extends ButtplugMessage {
165
+ constructor(devices, id = exports.DEFAULT_MESSAGE_ID) {
166
+ super(id);
167
+ this.Devices = devices;
168
+ this.Id = id;
169
+ }
170
+ update() {
171
+ for (const device of this.Devices) {
172
+ device.DeviceMessages.update();
173
+ }
174
+ }
175
+ }
176
+ exports.DeviceList = DeviceList;
177
+ DeviceList.Name = 'DeviceList';
178
+ __decorate([
179
+ (0, class_transformer_1.Type)(() => DeviceInfo),
180
+ __metadata("design:type", Array)
181
+ ], DeviceList.prototype, "Devices", void 0);
182
+ class DeviceAdded extends ButtplugSystemMessage {
183
+ constructor(data) {
184
+ super();
185
+ Object.assign(this, data);
186
+ }
187
+ update() {
188
+ this.DeviceMessages.update();
189
+ }
190
+ }
191
+ exports.DeviceAdded = DeviceAdded;
192
+ DeviceAdded.Name = 'DeviceAdded';
193
+ __decorate([
194
+ (0, class_transformer_1.Type)(() => MessageAttributes),
195
+ __metadata("design:type", MessageAttributes)
196
+ ], DeviceAdded.prototype, "DeviceMessages", void 0);
197
+ class DeviceRemoved extends ButtplugSystemMessage {
198
+ constructor(DeviceIndex) {
199
+ super();
200
+ this.DeviceIndex = DeviceIndex;
201
+ }
202
+ }
203
+ exports.DeviceRemoved = DeviceRemoved;
204
+ DeviceRemoved.Name = 'DeviceRemoved';
205
+ class RequestDeviceList extends ButtplugMessage {
206
+ constructor(Id = exports.DEFAULT_MESSAGE_ID) {
207
+ super(Id);
208
+ this.Id = Id;
209
+ }
210
+ }
211
+ exports.RequestDeviceList = RequestDeviceList;
212
+ RequestDeviceList.Name = 'RequestDeviceList';
213
+ class StartScanning extends ButtplugMessage {
214
+ constructor(Id = exports.DEFAULT_MESSAGE_ID) {
215
+ super(Id);
216
+ this.Id = Id;
217
+ }
218
+ }
219
+ exports.StartScanning = StartScanning;
220
+ StartScanning.Name = 'StartScanning';
221
+ class StopScanning extends ButtplugMessage {
222
+ constructor(Id = exports.DEFAULT_MESSAGE_ID) {
223
+ super(Id);
224
+ this.Id = Id;
225
+ }
226
+ }
227
+ exports.StopScanning = StopScanning;
228
+ StopScanning.Name = 'StopScanning';
229
+ class ScanningFinished extends ButtplugSystemMessage {
230
+ constructor() {
231
+ super();
232
+ }
233
+ }
234
+ exports.ScanningFinished = ScanningFinished;
235
+ ScanningFinished.Name = 'ScanningFinished';
236
+ class RequestServerInfo extends ButtplugMessage {
237
+ constructor(ClientName, MessageVersion = 0, Id = exports.DEFAULT_MESSAGE_ID) {
238
+ super(Id);
239
+ this.ClientName = ClientName;
240
+ this.MessageVersion = MessageVersion;
241
+ this.Id = Id;
242
+ }
243
+ }
244
+ exports.RequestServerInfo = RequestServerInfo;
245
+ RequestServerInfo.Name = 'RequestServerInfo';
246
+ class ServerInfo extends ButtplugSystemMessage {
247
+ constructor(MessageVersion, MaxPingTime, ServerName, Id = exports.DEFAULT_MESSAGE_ID) {
248
+ super();
249
+ this.MessageVersion = MessageVersion;
250
+ this.MaxPingTime = MaxPingTime;
251
+ this.ServerName = ServerName;
252
+ this.Id = Id;
253
+ }
254
+ }
255
+ exports.ServerInfo = ServerInfo;
256
+ ServerInfo.Name = 'ServerInfo';
257
+ class StopDeviceCmd extends ButtplugDeviceMessage {
258
+ constructor(DeviceIndex = -1, Id = exports.DEFAULT_MESSAGE_ID) {
259
+ super(DeviceIndex, Id);
260
+ this.DeviceIndex = DeviceIndex;
261
+ this.Id = Id;
262
+ }
263
+ }
264
+ exports.StopDeviceCmd = StopDeviceCmd;
265
+ StopDeviceCmd.Name = 'StopDeviceCmd';
266
+ class StopAllDevices extends ButtplugMessage {
267
+ constructor(Id = exports.DEFAULT_MESSAGE_ID) {
268
+ super(Id);
269
+ this.Id = Id;
270
+ }
271
+ }
272
+ exports.StopAllDevices = StopAllDevices;
273
+ StopAllDevices.Name = 'StopAllDevices';
274
+ class GenericMessageSubcommand {
275
+ constructor(Index) {
276
+ this.Index = Index;
277
+ }
278
+ }
279
+ exports.GenericMessageSubcommand = GenericMessageSubcommand;
280
+ class ScalarSubcommand extends GenericMessageSubcommand {
281
+ constructor(Index, Scalar, ActuatorType) {
282
+ super(Index);
283
+ this.Scalar = Scalar;
284
+ this.ActuatorType = ActuatorType;
285
+ }
286
+ }
287
+ exports.ScalarSubcommand = ScalarSubcommand;
288
+ class ScalarCmd extends ButtplugDeviceMessage {
289
+ constructor(Scalars, DeviceIndex = -1, Id = exports.DEFAULT_MESSAGE_ID) {
290
+ super(DeviceIndex, Id);
291
+ this.Scalars = Scalars;
292
+ this.DeviceIndex = DeviceIndex;
293
+ this.Id = Id;
294
+ }
295
+ }
296
+ exports.ScalarCmd = ScalarCmd;
297
+ ScalarCmd.Name = 'ScalarCmd';
298
+ class RotateSubcommand extends GenericMessageSubcommand {
299
+ constructor(Index, Speed, Clockwise) {
300
+ super(Index);
301
+ this.Speed = Speed;
302
+ this.Clockwise = Clockwise;
303
+ }
304
+ }
305
+ exports.RotateSubcommand = RotateSubcommand;
306
+ class RotateCmd extends ButtplugDeviceMessage {
307
+ static Create(deviceIndex, commands) {
308
+ const cmdList = new Array();
309
+ let i = 0;
310
+ for (const [speed, clockwise] of commands) {
311
+ cmdList.push(new RotateSubcommand(i, speed, clockwise));
312
+ ++i;
313
+ }
314
+ return new RotateCmd(cmdList, deviceIndex);
315
+ }
316
+ constructor(Rotations, DeviceIndex = -1, Id = exports.DEFAULT_MESSAGE_ID) {
317
+ super(DeviceIndex, Id);
318
+ this.Rotations = Rotations;
319
+ this.DeviceIndex = DeviceIndex;
320
+ this.Id = Id;
321
+ }
322
+ }
323
+ exports.RotateCmd = RotateCmd;
324
+ RotateCmd.Name = 'RotateCmd';
325
+ class VectorSubcommand extends GenericMessageSubcommand {
326
+ constructor(Index, Position, Duration) {
327
+ super(Index);
328
+ this.Position = Position;
329
+ this.Duration = Duration;
330
+ }
331
+ }
332
+ exports.VectorSubcommand = VectorSubcommand;
333
+ class LinearCmd extends ButtplugDeviceMessage {
334
+ static Create(deviceIndex, commands) {
335
+ const cmdList = new Array();
336
+ let i = 0;
337
+ for (const cmd of commands) {
338
+ cmdList.push(new VectorSubcommand(i, cmd[0], cmd[1]));
339
+ ++i;
340
+ }
341
+ return new LinearCmd(cmdList, deviceIndex);
342
+ }
343
+ constructor(Vectors, DeviceIndex = -1, Id = exports.DEFAULT_MESSAGE_ID) {
344
+ super(DeviceIndex, Id);
345
+ this.Vectors = Vectors;
346
+ this.DeviceIndex = DeviceIndex;
347
+ this.Id = Id;
348
+ }
349
+ }
350
+ exports.LinearCmd = LinearCmd;
351
+ LinearCmd.Name = 'LinearCmd';
352
+ class SensorReadCmd extends ButtplugDeviceMessage {
353
+ constructor(DeviceIndex, SensorIndex, SensorType, Id = exports.DEFAULT_MESSAGE_ID) {
354
+ super(DeviceIndex, Id);
355
+ this.DeviceIndex = DeviceIndex;
356
+ this.SensorIndex = SensorIndex;
357
+ this.SensorType = SensorType;
358
+ this.Id = Id;
359
+ }
360
+ }
361
+ exports.SensorReadCmd = SensorReadCmd;
362
+ SensorReadCmd.Name = 'SensorReadCmd';
363
+ class SensorReading extends ButtplugDeviceMessage {
364
+ constructor(DeviceIndex, SensorIndex, SensorType, Data, Id = exports.DEFAULT_MESSAGE_ID) {
365
+ super(DeviceIndex, Id);
366
+ this.DeviceIndex = DeviceIndex;
367
+ this.SensorIndex = SensorIndex;
368
+ this.SensorType = SensorType;
369
+ this.Data = Data;
370
+ this.Id = Id;
371
+ }
372
+ }
373
+ exports.SensorReading = SensorReading;
374
+ SensorReading.Name = 'SensorReading';
375
+ class RawReadCmd extends ButtplugDeviceMessage {
376
+ constructor(DeviceIndex, Endpoint, ExpectedLength, Timeout, Id = exports.DEFAULT_MESSAGE_ID) {
377
+ super(DeviceIndex, Id);
378
+ this.DeviceIndex = DeviceIndex;
379
+ this.Endpoint = Endpoint;
380
+ this.ExpectedLength = ExpectedLength;
381
+ this.Timeout = Timeout;
382
+ this.Id = Id;
383
+ }
384
+ }
385
+ exports.RawReadCmd = RawReadCmd;
386
+ RawReadCmd.Name = 'RawReadCmd';
387
+ class RawWriteCmd extends ButtplugDeviceMessage {
388
+ constructor(DeviceIndex, Endpoint, Data, WriteWithResponse, Id = exports.DEFAULT_MESSAGE_ID) {
389
+ super(DeviceIndex, Id);
390
+ this.DeviceIndex = DeviceIndex;
391
+ this.Endpoint = Endpoint;
392
+ this.Data = Data;
393
+ this.WriteWithResponse = WriteWithResponse;
394
+ this.Id = Id;
395
+ }
396
+ }
397
+ exports.RawWriteCmd = RawWriteCmd;
398
+ RawWriteCmd.Name = 'RawWriteCmd';
399
+ class RawSubscribeCmd extends ButtplugDeviceMessage {
400
+ constructor(DeviceIndex, Endpoint, Id = exports.DEFAULT_MESSAGE_ID) {
401
+ super(DeviceIndex, Id);
402
+ this.DeviceIndex = DeviceIndex;
403
+ this.Endpoint = Endpoint;
404
+ this.Id = Id;
405
+ }
406
+ }
407
+ exports.RawSubscribeCmd = RawSubscribeCmd;
408
+ RawSubscribeCmd.Name = 'RawSubscribeCmd';
409
+ class RawUnsubscribeCmd extends ButtplugDeviceMessage {
410
+ constructor(DeviceIndex, Endpoint, Id = exports.DEFAULT_MESSAGE_ID) {
411
+ super(DeviceIndex, Id);
412
+ this.DeviceIndex = DeviceIndex;
413
+ this.Endpoint = Endpoint;
414
+ this.Id = Id;
415
+ }
416
+ }
417
+ exports.RawUnsubscribeCmd = RawUnsubscribeCmd;
418
+ RawUnsubscribeCmd.Name = 'RawUnsubscribeCmd';
419
+ class RawReading extends ButtplugDeviceMessage {
420
+ constructor(DeviceIndex, Endpoint, Data, Id = exports.DEFAULT_MESSAGE_ID) {
421
+ super(DeviceIndex, Id);
422
+ this.DeviceIndex = DeviceIndex;
423
+ this.Endpoint = Endpoint;
424
+ this.Data = Data;
425
+ this.Id = Id;
426
+ }
427
+ }
428
+ exports.RawReading = RawReading;
429
+ RawReading.Name = 'RawReading';
430
430
  //# sourceMappingURL=Messages.js.map