buttplug 3.0.0-alpha.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -2
- package/dist/main/src/client/ButtplugClientConnectorException.d.ts +2 -2
- package/dist/main/src/client/ButtplugClientConnectorException.js +1 -1
- package/dist/main/src/client/ButtplugClientConnectorException.js.map +1 -1
- package/dist/main/src/client/ButtplugClientDevice.js +23 -23
- package/dist/main/src/client/ButtplugClientDevice.js.map +1 -1
- package/dist/main/src/client/Client.js +5 -5
- package/dist/main/src/client/Client.js.map +1 -1
- package/dist/main/src/core/Exceptions.d.ts +9 -9
- package/dist/main/src/core/Exceptions.js +19 -19
- package/dist/main/src/core/Exceptions.js.map +1 -1
- package/dist/main/src/utils/ButtplugMessageSorter.js +1 -1
- package/dist/main/src/utils/ButtplugMessageSorter.js.map +1 -1
- package/dist/web/buttplug.js +50 -50
- package/dist/web/buttplug.min.js +1 -1
- package/dist/web/buttplug.min.js.map +1 -1
- package/package.json +1 -1
- package/src/client/ButtplugClientConnectorException.ts +2 -2
- package/src/client/ButtplugClientDevice.ts +26 -26
- package/src/client/Client.ts +13 -13
- package/src/core/Exceptions.ts +13 -13
- package/src/utils/ButtplugMessageSorter.ts +2 -2
package/package.json
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { ButtplugError } from '../core/Exceptions';
|
|
10
10
|
import * as Messages from '../core/Messages';
|
|
11
11
|
|
|
12
|
-
export class ButtplugClientConnectorException extends
|
|
12
|
+
export class ButtplugClientConnectorException extends ButtplugError {
|
|
13
13
|
public constructor(message: string) {
|
|
14
14
|
super(message, Messages.ErrorClass.ERROR_UNKNOWN);
|
|
15
15
|
}
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
'use strict';
|
|
10
10
|
import * as Messages from '../core/Messages';
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
ButtplugDeviceError,
|
|
13
|
+
ButtplugError,
|
|
14
|
+
ButtplugMessageError,
|
|
15
15
|
} from '../core/Exceptions';
|
|
16
16
|
import { EventEmitter } from 'events';
|
|
17
17
|
|
|
@@ -102,9 +102,9 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
102
102
|
case Messages.Ok:
|
|
103
103
|
return;
|
|
104
104
|
case Messages.Error:
|
|
105
|
-
throw
|
|
105
|
+
throw ButtplugError.FromError(response as Messages.Error);
|
|
106
106
|
default:
|
|
107
|
-
throw new
|
|
107
|
+
throw new ButtplugMessageError(
|
|
108
108
|
`Message type ${response.constructor} not handled by SendMsgExpectOk`
|
|
109
109
|
);
|
|
110
110
|
}
|
|
@@ -128,7 +128,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
128
128
|
(x) => x.ActuatorType === actuator
|
|
129
129
|
);
|
|
130
130
|
if (!scalarAttrs || scalarAttrs.length === 0) {
|
|
131
|
-
throw new
|
|
131
|
+
throw new ButtplugDeviceError(
|
|
132
132
|
`Device ${this.name} has no ${actuator} capabilities`
|
|
133
133
|
);
|
|
134
134
|
}
|
|
@@ -139,7 +139,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
139
139
|
);
|
|
140
140
|
} else if (Array.isArray(speed)) {
|
|
141
141
|
if (speed.length > scalarAttrs.length) {
|
|
142
|
-
throw new
|
|
142
|
+
throw new ButtplugDeviceError(
|
|
143
143
|
`${speed.length} commands send to a device with ${scalarAttrs.length} vibrators`
|
|
144
144
|
);
|
|
145
145
|
}
|
|
@@ -147,7 +147,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
147
147
|
cmds.push(new Messages.ScalarSubcommand(x.Index, speed[i], actuator));
|
|
148
148
|
});
|
|
149
149
|
} else {
|
|
150
|
-
throw new
|
|
150
|
+
throw new ButtplugDeviceError(
|
|
151
151
|
`${actuator} can only take numbers or arrays of numbers.`
|
|
152
152
|
);
|
|
153
153
|
}
|
|
@@ -188,7 +188,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
188
188
|
): Promise<void> {
|
|
189
189
|
const rotateAttrs = this.messageAttributes.RotateCmd;
|
|
190
190
|
if (!rotateAttrs || rotateAttrs.length === 0) {
|
|
191
|
-
throw new
|
|
191
|
+
throw new ButtplugDeviceError(
|
|
192
192
|
`Device ${this.name} has no Rotate capabilities`
|
|
193
193
|
);
|
|
194
194
|
}
|
|
@@ -201,7 +201,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
201
201
|
} else if (Array.isArray(values)) {
|
|
202
202
|
msg = Messages.RotateCmd.Create(this.index, values);
|
|
203
203
|
} else {
|
|
204
|
-
throw new
|
|
204
|
+
throw new ButtplugDeviceError(
|
|
205
205
|
'SendRotateCmd can only take a number and boolean, or an array of number/boolean tuples'
|
|
206
206
|
);
|
|
207
207
|
}
|
|
@@ -218,7 +218,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
218
218
|
): Promise<void> {
|
|
219
219
|
const linearAttrs = this.messageAttributes.LinearCmd;
|
|
220
220
|
if (!linearAttrs || linearAttrs.length === 0) {
|
|
221
|
-
throw new
|
|
221
|
+
throw new ButtplugDeviceError(
|
|
222
222
|
`Device ${this.name} has no Linear capabilities`
|
|
223
223
|
);
|
|
224
224
|
}
|
|
@@ -231,7 +231,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
231
231
|
} else if (Array.isArray(values)) {
|
|
232
232
|
msg = Messages.LinearCmd.Create(this.index, values);
|
|
233
233
|
} else {
|
|
234
|
-
throw new
|
|
234
|
+
throw new ButtplugDeviceError(
|
|
235
235
|
'SendLinearCmd can only take a number and number, or an array of number/number tuples'
|
|
236
236
|
);
|
|
237
237
|
}
|
|
@@ -249,9 +249,9 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
249
249
|
case Messages.SensorReading:
|
|
250
250
|
return (response as Messages.SensorReading).Data;
|
|
251
251
|
case Messages.Error:
|
|
252
|
-
throw
|
|
252
|
+
throw ButtplugError.FromError(response as Messages.Error);
|
|
253
253
|
default:
|
|
254
|
-
throw new
|
|
254
|
+
throw new ButtplugMessageError(
|
|
255
255
|
`Message type ${response.constructor} not handled by sensorRead`
|
|
256
256
|
);
|
|
257
257
|
}
|
|
@@ -266,7 +266,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
266
266
|
|
|
267
267
|
public async battery(): Promise<number> {
|
|
268
268
|
if (!this.hasBattery) {
|
|
269
|
-
throw new
|
|
269
|
+
throw new ButtplugDeviceError(
|
|
270
270
|
`Device ${this.name} has no Battery capabilities`
|
|
271
271
|
);
|
|
272
272
|
}
|
|
@@ -290,7 +290,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
290
290
|
|
|
291
291
|
public async rssi(): Promise<number> {
|
|
292
292
|
if (!this.hasRssi) {
|
|
293
|
-
throw new
|
|
293
|
+
throw new ButtplugDeviceError(
|
|
294
294
|
`Device ${this.name} has no RSSI capabilities`
|
|
295
295
|
);
|
|
296
296
|
}
|
|
@@ -311,12 +311,12 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
311
311
|
timeout: number
|
|
312
312
|
): Promise<Uint8Array> {
|
|
313
313
|
if (!this.messageAttributes.RawReadCmd) {
|
|
314
|
-
throw new
|
|
314
|
+
throw new ButtplugDeviceError(
|
|
315
315
|
`Device ${this.name} has no raw read capabilities`
|
|
316
316
|
);
|
|
317
317
|
}
|
|
318
318
|
if (this.messageAttributes.RawReadCmd.Endpoints.indexOf(endpoint) === -1) {
|
|
319
|
-
throw new
|
|
319
|
+
throw new ButtplugDeviceError(
|
|
320
320
|
`Device ${this.name} has no raw readable endpoint ${endpoint}`
|
|
321
321
|
);
|
|
322
322
|
}
|
|
@@ -327,9 +327,9 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
327
327
|
case Messages.RawReading:
|
|
328
328
|
return new Uint8Array((response as Messages.RawReading).Data);
|
|
329
329
|
case Messages.Error:
|
|
330
|
-
throw
|
|
330
|
+
throw ButtplugError.FromError(response as Messages.Error);
|
|
331
331
|
default:
|
|
332
|
-
throw new
|
|
332
|
+
throw new ButtplugMessageError(
|
|
333
333
|
`Message type ${response.constructor} not handled by rawRead`
|
|
334
334
|
);
|
|
335
335
|
}
|
|
@@ -341,12 +341,12 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
341
341
|
writeWithResponse: boolean
|
|
342
342
|
): Promise<void> {
|
|
343
343
|
if (!this.messageAttributes.RawWriteCmd) {
|
|
344
|
-
throw new
|
|
344
|
+
throw new ButtplugDeviceError(
|
|
345
345
|
`Device ${this.name} has no raw write capabilities`
|
|
346
346
|
);
|
|
347
347
|
}
|
|
348
348
|
if (this.messageAttributes.RawWriteCmd.Endpoints.indexOf(endpoint) === -1) {
|
|
349
|
-
throw new
|
|
349
|
+
throw new ButtplugDeviceError(
|
|
350
350
|
`Device ${this.name} has no raw writable endpoint ${endpoint}`
|
|
351
351
|
);
|
|
352
352
|
}
|
|
@@ -357,14 +357,14 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
357
357
|
|
|
358
358
|
public async rawSubscribe(endpoint: string): Promise<void> {
|
|
359
359
|
if (!this.messageAttributes.RawSubscribeCmd) {
|
|
360
|
-
throw new
|
|
360
|
+
throw new ButtplugDeviceError(
|
|
361
361
|
`Device ${this.name} has no raw subscribe capabilities`
|
|
362
362
|
);
|
|
363
363
|
}
|
|
364
364
|
if (
|
|
365
365
|
this.messageAttributes.RawSubscribeCmd.Endpoints.indexOf(endpoint) === -1
|
|
366
366
|
) {
|
|
367
|
-
throw new
|
|
367
|
+
throw new ButtplugDeviceError(
|
|
368
368
|
`Device ${this.name} has no raw subscribable endpoint ${endpoint}`
|
|
369
369
|
);
|
|
370
370
|
}
|
|
@@ -374,14 +374,14 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
374
374
|
public async rawUnsubscribe(endpoint: string): Promise<void> {
|
|
375
375
|
// This reuses raw subscribe's info.
|
|
376
376
|
if (!this.messageAttributes.RawSubscribeCmd) {
|
|
377
|
-
throw new
|
|
377
|
+
throw new ButtplugDeviceError(
|
|
378
378
|
`Device ${this.name} has no raw unsubscribe capabilities`
|
|
379
379
|
);
|
|
380
380
|
}
|
|
381
381
|
if (
|
|
382
382
|
this.messageAttributes.RawSubscribeCmd.Endpoints.indexOf(endpoint) === -1
|
|
383
383
|
) {
|
|
384
|
-
throw new
|
|
384
|
+
throw new ButtplugDeviceError(
|
|
385
385
|
`Device ${this.name} has no raw unsubscribable endpoint ${endpoint}`
|
|
386
386
|
);
|
|
387
387
|
}
|
package/src/client/Client.ts
CHANGED
|
@@ -14,10 +14,10 @@ import { ButtplugClientDevice } from './ButtplugClientDevice';
|
|
|
14
14
|
import { IButtplugClientConnector } from './IButtplugClientConnector';
|
|
15
15
|
import * as Messages from '../core/Messages';
|
|
16
16
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
ButtplugDeviceError,
|
|
18
|
+
ButtplugError,
|
|
19
|
+
ButtplugInitError,
|
|
20
|
+
ButtplugMessageError,
|
|
21
21
|
} from '../core/Exceptions';
|
|
22
22
|
import { ButtplugClientConnectorException } from './ButtplugClientConnectorException';
|
|
23
23
|
|
|
@@ -96,8 +96,8 @@ export class ButtplugClient extends EventEmitter {
|
|
|
96
96
|
this.checkConnector();
|
|
97
97
|
const dev = this._devices.get(device.index);
|
|
98
98
|
if (dev === undefined) {
|
|
99
|
-
throw
|
|
100
|
-
|
|
99
|
+
throw ButtplugError.LogAndError(
|
|
100
|
+
ButtplugDeviceError,
|
|
101
101
|
this._logger,
|
|
102
102
|
`Device ${device.index} not available.`
|
|
103
103
|
);
|
|
@@ -161,8 +161,8 @@ export class ButtplugClient extends EventEmitter {
|
|
|
161
161
|
if (serverinfo.MessageVersion < Messages.MESSAGE_SPEC_VERSION) {
|
|
162
162
|
// Disconnect and throw an exception explaining the version mismatch problem.
|
|
163
163
|
await this._connector!.Disconnect();
|
|
164
|
-
throw
|
|
165
|
-
|
|
164
|
+
throw ButtplugError.LogAndError(
|
|
165
|
+
ButtplugInitError,
|
|
166
166
|
this._logger,
|
|
167
167
|
`Server protocol version ${serverinfo.MessageVersion} is older than client protocol version ${Messages.MESSAGE_SPEC_VERSION}. Please update server.`
|
|
168
168
|
);
|
|
@@ -188,8 +188,8 @@ export class ButtplugClient extends EventEmitter {
|
|
|
188
188
|
// server has detected.
|
|
189
189
|
await this._connector!.Disconnect();
|
|
190
190
|
const err = msg as Messages.Error;
|
|
191
|
-
throw
|
|
192
|
-
|
|
191
|
+
throw ButtplugError.LogAndError(
|
|
192
|
+
ButtplugInitError,
|
|
193
193
|
this._logger,
|
|
194
194
|
`Cannot connect to server. ${err.ErrorMessage}`
|
|
195
195
|
);
|
|
@@ -250,10 +250,10 @@ export class ButtplugClient extends EventEmitter {
|
|
|
250
250
|
case Messages.Ok:
|
|
251
251
|
return;
|
|
252
252
|
case Messages.Error:
|
|
253
|
-
throw
|
|
253
|
+
throw ButtplugError.FromError(response as Messages.Error);
|
|
254
254
|
default:
|
|
255
|
-
throw
|
|
256
|
-
|
|
255
|
+
throw ButtplugError.LogAndError(
|
|
256
|
+
ButtplugMessageError,
|
|
257
257
|
this._logger,
|
|
258
258
|
`Message type ${response.constructor} not handled by SendMsgExpectOk`
|
|
259
259
|
);
|
package/src/core/Exceptions.ts
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
import * as Messages from './Messages';
|
|
10
10
|
import { ButtplugLogger } from './Logging';
|
|
11
11
|
|
|
12
|
-
export class
|
|
12
|
+
export class ButtplugError extends Error {
|
|
13
13
|
public get ErrorClass(): Messages.ErrorClass {
|
|
14
14
|
return this.errorClass;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
public get
|
|
17
|
+
public get InnerError(): Error | undefined {
|
|
18
18
|
return this.innerError;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -26,7 +26,7 @@ export class ButtplugException extends Error {
|
|
|
26
26
|
return new Messages.Error(this.message, this.ErrorClass, this.Id);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
public static LogAndError<T extends
|
|
29
|
+
public static LogAndError<T extends ButtplugError>(
|
|
30
30
|
constructor: new (str: string, num: number) => T,
|
|
31
31
|
logger: ButtplugLogger,
|
|
32
32
|
message: string,
|
|
@@ -39,15 +39,15 @@ export class ButtplugException extends Error {
|
|
|
39
39
|
public static FromError(error: Messages.Error) {
|
|
40
40
|
switch (error.ErrorCode) {
|
|
41
41
|
case Messages.ErrorClass.ERROR_DEVICE:
|
|
42
|
-
return new
|
|
42
|
+
return new ButtplugDeviceError(error.ErrorMessage, error.Id);
|
|
43
43
|
case Messages.ErrorClass.ERROR_INIT:
|
|
44
|
-
return new
|
|
44
|
+
return new ButtplugInitError(error.ErrorMessage, error.Id);
|
|
45
45
|
case Messages.ErrorClass.ERROR_UNKNOWN:
|
|
46
|
-
return new
|
|
46
|
+
return new ButtplugUnknownError(error.ErrorMessage, error.Id);
|
|
47
47
|
case Messages.ErrorClass.ERROR_PING:
|
|
48
|
-
return new
|
|
48
|
+
return new ButtplugPingError(error.ErrorMessage, error.Id);
|
|
49
49
|
case Messages.ErrorClass.ERROR_MSG:
|
|
50
|
-
return new
|
|
50
|
+
return new ButtplugMessageError(error.ErrorMessage, error.Id);
|
|
51
51
|
default:
|
|
52
52
|
throw new Error(`Message type ${error.ErrorCode} not handled`);
|
|
53
53
|
}
|
|
@@ -70,31 +70,31 @@ export class ButtplugException extends Error {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
export class
|
|
73
|
+
export class ButtplugInitError extends ButtplugError {
|
|
74
74
|
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
75
75
|
super(message, Messages.ErrorClass.ERROR_INIT, id);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export class
|
|
79
|
+
export class ButtplugDeviceError extends ButtplugError {
|
|
80
80
|
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
81
81
|
super(message, Messages.ErrorClass.ERROR_DEVICE, id);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
export class
|
|
85
|
+
export class ButtplugMessageError extends ButtplugError {
|
|
86
86
|
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
87
87
|
super(message, Messages.ErrorClass.ERROR_MSG, id);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
export class
|
|
91
|
+
export class ButtplugPingError extends ButtplugError {
|
|
92
92
|
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
93
93
|
super(message, Messages.ErrorClass.ERROR_PING, id);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export class
|
|
97
|
+
export class ButtplugUnknownError extends ButtplugError {
|
|
98
98
|
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
99
99
|
super(message, Messages.ErrorClass.ERROR_UNKNOWN, id);
|
|
100
100
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as Messages from '../core/Messages';
|
|
10
|
-
import {
|
|
10
|
+
import { ButtplugError } from '../core/Exceptions';
|
|
11
11
|
|
|
12
12
|
export class ButtplugMessageSorter {
|
|
13
13
|
protected _counter = 1;
|
|
@@ -51,7 +51,7 @@ export class ButtplugMessageSorter {
|
|
|
51
51
|
// If we've gotten back an error, reject the related promise using a
|
|
52
52
|
// ButtplugException derived type.
|
|
53
53
|
if (x.Type === Messages.Error) {
|
|
54
|
-
rej(
|
|
54
|
+
rej(ButtplugError.FromError(x as Messages.Error));
|
|
55
55
|
continue;
|
|
56
56
|
}
|
|
57
57
|
res(x);
|