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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ButtplugDeviceError } from "../core/Exceptions";
|
|
2
|
+
import { OutputType } from "../core/Messages";
|
|
3
|
+
|
|
4
|
+
class PercentOrSteps {
|
|
5
|
+
private _percent: number | undefined;
|
|
6
|
+
private _steps: number | undefined;
|
|
7
|
+
|
|
8
|
+
public get percent() {
|
|
9
|
+
return this._percent;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public get steps() {
|
|
13
|
+
return this._steps;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public static createSteps(s: number): PercentOrSteps {
|
|
17
|
+
let v = new PercentOrSteps;
|
|
18
|
+
v._steps = s;
|
|
19
|
+
return v;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static createPercent(p: number): PercentOrSteps {
|
|
23
|
+
if (p < 0 || p > 1.0) {
|
|
24
|
+
throw new ButtplugDeviceError(`Percent value ${p} is not in the range 0.0 <= x <= 1.0`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let v = new PercentOrSteps;
|
|
28
|
+
v._percent = p;
|
|
29
|
+
return v;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class DeviceOutputCommand {
|
|
34
|
+
public constructor(
|
|
35
|
+
private _outputType: OutputType,
|
|
36
|
+
private _value: PercentOrSteps,
|
|
37
|
+
private _duration?: number,
|
|
38
|
+
)
|
|
39
|
+
{}
|
|
40
|
+
|
|
41
|
+
public get outputType() {
|
|
42
|
+
return this._outputType;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public get value() {
|
|
46
|
+
return this._value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public get duration() {
|
|
50
|
+
return this._duration;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class DeviceOutputValueConstructor {
|
|
55
|
+
public constructor(
|
|
56
|
+
private _outputType: OutputType)
|
|
57
|
+
{}
|
|
58
|
+
|
|
59
|
+
public steps(steps: number): DeviceOutputCommand {
|
|
60
|
+
return new DeviceOutputCommand(this._outputType, PercentOrSteps.createSteps(steps), undefined);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public percent(percent: number): DeviceOutputCommand {
|
|
64
|
+
return new DeviceOutputCommand(this._outputType, PercentOrSteps.createPercent(percent), undefined);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export class DeviceOutputPositionWithDurationConstructor {
|
|
69
|
+
public steps(steps: number, duration: number): DeviceOutputCommand {
|
|
70
|
+
return new DeviceOutputCommand(OutputType.Position, PercentOrSteps.createSteps(steps), duration);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public percent(percent: number, duration: number): DeviceOutputCommand {
|
|
74
|
+
return new DeviceOutputCommand(OutputType.HwPositionWithDuration, PercentOrSteps.createPercent(percent), duration);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export class DeviceOutput {
|
|
79
|
+
private constructor() {}
|
|
80
|
+
|
|
81
|
+
public static get Vibrate() {
|
|
82
|
+
return new DeviceOutputValueConstructor(OutputType.Vibrate);
|
|
83
|
+
}
|
|
84
|
+
public static get Rotate() {
|
|
85
|
+
return new DeviceOutputValueConstructor(OutputType.Rotate);
|
|
86
|
+
}
|
|
87
|
+
public static get Oscillate() {
|
|
88
|
+
return new DeviceOutputValueConstructor(OutputType.Oscillate);
|
|
89
|
+
}
|
|
90
|
+
public static get Constrict() {
|
|
91
|
+
return new DeviceOutputValueConstructor(OutputType.Constrict);
|
|
92
|
+
}
|
|
93
|
+
public static get Inflate() {
|
|
94
|
+
return new DeviceOutputValueConstructor(OutputType.Inflate);
|
|
95
|
+
}
|
|
96
|
+
public static get Temperature() {
|
|
97
|
+
return new DeviceOutputValueConstructor(OutputType.Temperature);
|
|
98
|
+
}
|
|
99
|
+
public static get Led() {
|
|
100
|
+
return new DeviceOutputValueConstructor(OutputType.Led);
|
|
101
|
+
}
|
|
102
|
+
public static get Spray() {
|
|
103
|
+
return new DeviceOutputValueConstructor(OutputType.Spray);
|
|
104
|
+
}
|
|
105
|
+
public static get Position() {
|
|
106
|
+
return new DeviceOutputValueConstructor(OutputType.Position);
|
|
107
|
+
}
|
|
108
|
+
public static get PositionWithDuration() {
|
|
109
|
+
return new DeviceOutputPositionWithDurationConstructor();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { ButtplugDeviceError, ButtplugError, ButtplugMessageError } from "../core/Exceptions";
|
|
2
|
+
import * as Messages from "../core/Messages";
|
|
3
|
+
import { DeviceOutputCommand } from "./ButtplugClientDeviceCommand";
|
|
4
|
+
|
|
5
|
+
export class ButtplugClientDeviceFeature {
|
|
6
|
+
|
|
7
|
+
constructor(
|
|
8
|
+
private _deviceIndex: number,
|
|
9
|
+
private _deviceName: string,
|
|
10
|
+
private _feature: Messages.DeviceFeature,
|
|
11
|
+
private _sendClosure: (
|
|
12
|
+
msg: Messages.ButtplugMessage
|
|
13
|
+
) => Promise<Messages.ButtplugMessage>) {
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
protected send = async (msg: Messages.ButtplugMessage): Promise<Messages.ButtplugMessage> => {
|
|
17
|
+
return await this._sendClosure(msg);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected sendMsgExpectOk = async (
|
|
21
|
+
msg: Messages.ButtplugMessage
|
|
22
|
+
): Promise<void> => {
|
|
23
|
+
const response = await this.send(msg);
|
|
24
|
+
if (response.Ok !== undefined) {
|
|
25
|
+
return;
|
|
26
|
+
} else if (response.Error !== undefined) {
|
|
27
|
+
throw ButtplugError.FromError(response as Messages.Error);
|
|
28
|
+
} else {
|
|
29
|
+
throw new ButtplugMessageError("Expected Ok or Error, and didn't get either!");
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
protected isOutputValid(type: Messages.OutputType) {
|
|
34
|
+
if (this._feature.Output !== undefined && !this._feature.Output.hasOwnProperty(type)) {
|
|
35
|
+
throw new ButtplugDeviceError(`Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
protected isInputValid(type: Messages.InputType) {
|
|
40
|
+
if (this._feature.Input !== undefined && !this._feature.Input.hasOwnProperty(type)) {
|
|
41
|
+
throw new ButtplugDeviceError(`Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
protected async sendOutputCmd(command: DeviceOutputCommand): Promise<void> {
|
|
46
|
+
// Make sure the requested feature is valid
|
|
47
|
+
this.isOutputValid(command.outputType);
|
|
48
|
+
if (command.value === undefined) {
|
|
49
|
+
throw new ButtplugDeviceError(`${command.outputType} requires value defined`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let type = command.outputType;
|
|
53
|
+
let duration: undefined | number = undefined;
|
|
54
|
+
if (type == Messages.OutputType.HwPositionWithDuration) {
|
|
55
|
+
if (command.duration === undefined) {
|
|
56
|
+
throw new ButtplugDeviceError("PositionWithDuration requires duration defined");
|
|
57
|
+
}
|
|
58
|
+
duration = command.duration;
|
|
59
|
+
}
|
|
60
|
+
let value: number;
|
|
61
|
+
let p = command.value;
|
|
62
|
+
if (p.percent === undefined) {
|
|
63
|
+
// TODO Check step limits here
|
|
64
|
+
value = command.value.steps!;
|
|
65
|
+
} else {
|
|
66
|
+
value = Math.ceil(this._feature.Output[type]!.Value![1] * p.percent);
|
|
67
|
+
}
|
|
68
|
+
let newCommand: Messages.DeviceFeatureOutput = { Value: value, Duration: duration };
|
|
69
|
+
let outCommand = {};
|
|
70
|
+
outCommand[type.toString()] = newCommand;
|
|
71
|
+
|
|
72
|
+
let cmd: Messages.ButtplugMessage = {
|
|
73
|
+
OutputCmd: {
|
|
74
|
+
Id: 1,
|
|
75
|
+
DeviceIndex: this._deviceIndex,
|
|
76
|
+
FeatureIndex: this._feature.FeatureIndex,
|
|
77
|
+
Command: outCommand
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
await this.sendMsgExpectOk(cmd);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public hasOutput(type: Messages.OutputType): boolean {
|
|
84
|
+
if (this._feature.Output !== undefined) {
|
|
85
|
+
return this._feature.Output.hasOwnProperty(type.toString());
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public hasInput(type: Messages.InputType): boolean {
|
|
91
|
+
if (this._feature.Input !== undefined) {
|
|
92
|
+
return this._feature.Input.hasOwnProperty(type.toString());
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
public async runOutput(cmd: DeviceOutputCommand): Promise<void> {
|
|
99
|
+
if (this._feature.Output !== undefined && this._feature.Output.hasOwnProperty(cmd.outputType.toString())) {
|
|
100
|
+
return this.sendOutputCmd(cmd);
|
|
101
|
+
}
|
|
102
|
+
throw new ButtplugDeviceError(`Output type ${cmd.outputType} not supported by feature.`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public async runInput(inputType: Messages.InputType, inputCommand: Messages.InputCommandType): Promise<Messages.InputReading | undefined> {
|
|
106
|
+
// Make sure the requested feature is valid
|
|
107
|
+
this.isInputValid(inputType);
|
|
108
|
+
let inputAttributes = this._feature.Input[inputType];
|
|
109
|
+
console.log(this._feature.Input);
|
|
110
|
+
if ((inputCommand === Messages.InputCommandType.Unsubscribe && !inputAttributes.Command.includes(Messages.InputCommandType.Subscribe)) && !inputAttributes.Command.includes(inputCommand)) {
|
|
111
|
+
throw new ButtplugDeviceError(`${inputType} does not support command ${inputCommand}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let cmd: Messages.ButtplugMessage = {
|
|
115
|
+
InputCmd: {
|
|
116
|
+
Id: 1,
|
|
117
|
+
DeviceIndex: this._deviceIndex,
|
|
118
|
+
FeatureIndex: this._feature.FeatureIndex,
|
|
119
|
+
Type: inputType,
|
|
120
|
+
Command: inputCommand,
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
if (inputCommand == Messages.InputCommandType.Read) {
|
|
124
|
+
const response = await this.send(cmd);
|
|
125
|
+
if (response.InputReading !== undefined) {
|
|
126
|
+
return response.InputReading;
|
|
127
|
+
} else if (response.Error !== undefined) {
|
|
128
|
+
throw ButtplugError.FromError(response as Messages.Error);
|
|
129
|
+
} else {
|
|
130
|
+
throw new ButtplugMessageError("Expected InputReading or Error, and didn't get either!");
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
console.log(`Sending subscribe message: ${JSON.stringify(cmd)}`);
|
|
134
|
+
await this.sendMsgExpectOk(cmd);
|
|
135
|
+
console.log("Got back ok?");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
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
|
-
'use strict';
|
|
10
|
-
|
|
11
|
-
import { ButtplugBrowserWebsocketClientConnector } from './ButtplugBrowserWebsocketClientConnector';
|
|
12
|
-
import { WebSocket as NodeWebSocket } from 'ws';
|
|
13
|
-
|
|
14
|
-
export class ButtplugNodeWebsocketClientConnector extends ButtplugBrowserWebsocketClientConnector {
|
|
15
|
-
protected _websocketConstructor =
|
|
16
|
-
NodeWebSocket as unknown as typeof WebSocket;
|
|
17
|
-
}
|
|
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
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
import { ButtplugBrowserWebsocketClientConnector } from './ButtplugBrowserWebsocketClientConnector';
|
|
12
|
+
import { WebSocket as NodeWebSocket } from 'ws';
|
|
13
|
+
|
|
14
|
+
export class ButtplugNodeWebsocketClientConnector extends ButtplugBrowserWebsocketClientConnector {
|
|
15
|
+
protected _websocketConstructor =
|
|
16
|
+
NodeWebSocket as unknown as typeof WebSocket;
|
|
17
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
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
|
-
import { ButtplugMessage } from '../core/Messages';
|
|
10
|
-
import { EventEmitter } from 'eventemitter3';
|
|
11
|
-
|
|
12
|
-
export interface IButtplugClientConnector extends EventEmitter {
|
|
13
|
-
connect: () => Promise<void>;
|
|
14
|
-
disconnect: () => Promise<void>;
|
|
15
|
-
initialize: () => Promise<void>;
|
|
16
|
-
send: (msg: ButtplugMessage) => void;
|
|
17
|
-
readonly Connected: boolean;
|
|
18
|
-
}
|
|
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
|
+
import { ButtplugMessage } from '../core/Messages';
|
|
10
|
+
import { EventEmitter } from 'eventemitter3';
|
|
11
|
+
|
|
12
|
+
export interface IButtplugClientConnector extends EventEmitter {
|
|
13
|
+
connect: () => Promise<void>;
|
|
14
|
+
disconnect: () => Promise<void>;
|
|
15
|
+
initialize: () => Promise<void>;
|
|
16
|
+
send: (msg: ButtplugMessage) => void;
|
|
17
|
+
readonly Connected: boolean;
|
|
18
|
+
}
|
package/src/core/Exceptions.ts
CHANGED
|
@@ -1,101 +1,107 @@
|
|
|
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
|
-
import * as Messages from './Messages';
|
|
10
|
-
import { ButtplugLogger } from './Logging';
|
|
11
|
-
|
|
12
|
-
export class ButtplugError extends Error {
|
|
13
|
-
public get ErrorClass(): Messages.ErrorClass {
|
|
14
|
-
return this.errorClass;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public get InnerError(): Error | undefined {
|
|
18
|
-
return this.innerError;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public get Id(): number | undefined {
|
|
22
|
-
return this.messageId;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public get ErrorMessage(): Messages.ButtplugMessage {
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
case Messages.ErrorClass.
|
|
48
|
-
return new
|
|
49
|
-
case Messages.ErrorClass.
|
|
50
|
-
return new
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export class
|
|
80
|
-
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
81
|
-
super(message, Messages.ErrorClass.
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export class
|
|
86
|
-
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
87
|
-
super(message, Messages.ErrorClass.
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export class
|
|
92
|
-
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
93
|
-
super(message, Messages.ErrorClass.
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export class
|
|
98
|
-
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
99
|
-
super(message, Messages.ErrorClass.
|
|
100
|
-
}
|
|
101
|
-
}
|
|
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
|
+
import * as Messages from './Messages';
|
|
10
|
+
import { ButtplugLogger } from './Logging';
|
|
11
|
+
|
|
12
|
+
export class ButtplugError extends Error {
|
|
13
|
+
public get ErrorClass(): Messages.ErrorClass {
|
|
14
|
+
return this.errorClass;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public get InnerError(): Error | undefined {
|
|
18
|
+
return this.innerError;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public get Id(): number | undefined {
|
|
22
|
+
return this.messageId;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public get ErrorMessage(): Messages.ButtplugMessage {
|
|
26
|
+
return {
|
|
27
|
+
Error: {
|
|
28
|
+
Id: this.Id,
|
|
29
|
+
ErrorCode: this.ErrorClass,
|
|
30
|
+
ErrorMessage: this.message
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static LogAndError<T extends ButtplugError>(
|
|
36
|
+
constructor: new (str: string, num: number) => T,
|
|
37
|
+
logger: ButtplugLogger,
|
|
38
|
+
message: string,
|
|
39
|
+
id: number = Messages.SYSTEM_MESSAGE_ID
|
|
40
|
+
): T {
|
|
41
|
+
logger.Error(message);
|
|
42
|
+
return new constructor(message, id);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public static FromError(error: Messages.Error) {
|
|
46
|
+
switch (error.ErrorCode) {
|
|
47
|
+
case Messages.ErrorClass.ERROR_DEVICE:
|
|
48
|
+
return new ButtplugDeviceError(error.ErrorMessage, error.Id);
|
|
49
|
+
case Messages.ErrorClass.ERROR_INIT:
|
|
50
|
+
return new ButtplugInitError(error.ErrorMessage, error.Id);
|
|
51
|
+
case Messages.ErrorClass.ERROR_UNKNOWN:
|
|
52
|
+
return new ButtplugUnknownError(error.ErrorMessage, error.Id);
|
|
53
|
+
case Messages.ErrorClass.ERROR_PING:
|
|
54
|
+
return new ButtplugPingError(error.ErrorMessage, error.Id);
|
|
55
|
+
case Messages.ErrorClass.ERROR_MSG:
|
|
56
|
+
return new ButtplugMessageError(error.ErrorMessage, error.Id);
|
|
57
|
+
default:
|
|
58
|
+
throw new Error(`Message type ${error.ErrorCode} not handled`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public errorClass: Messages.ErrorClass = Messages.ErrorClass.ERROR_UNKNOWN;
|
|
63
|
+
public innerError: Error | undefined;
|
|
64
|
+
public messageId: number | undefined;
|
|
65
|
+
|
|
66
|
+
protected constructor(
|
|
67
|
+
message: string,
|
|
68
|
+
errorClass: Messages.ErrorClass,
|
|
69
|
+
id: number = Messages.SYSTEM_MESSAGE_ID,
|
|
70
|
+
inner?: Error
|
|
71
|
+
) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.errorClass = errorClass;
|
|
74
|
+
this.innerError = inner;
|
|
75
|
+
this.messageId = id;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export class ButtplugInitError extends ButtplugError {
|
|
80
|
+
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
81
|
+
super(message, Messages.ErrorClass.ERROR_INIT, id);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export class ButtplugDeviceError extends ButtplugError {
|
|
86
|
+
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
87
|
+
super(message, Messages.ErrorClass.ERROR_DEVICE, id);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class ButtplugMessageError extends ButtplugError {
|
|
92
|
+
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
93
|
+
super(message, Messages.ErrorClass.ERROR_MSG, id);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export class ButtplugPingError extends ButtplugError {
|
|
98
|
+
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
99
|
+
super(message, Messages.ErrorClass.ERROR_PING, id);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export class ButtplugUnknownError extends ButtplugError {
|
|
104
|
+
public constructor(message: string, id: number = Messages.SYSTEM_MESSAGE_ID) {
|
|
105
|
+
super(message, Messages.ErrorClass.ERROR_UNKNOWN, id);
|
|
106
|
+
}
|
|
107
|
+
}
|