buttplug 3.2.2 → 4.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/.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 +577 -577
- package/LICENSE +27 -27
- package/README.md +97 -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 +227 -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 +118 -228
- package/dist/main/src/core/Messages.js +51 -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 +118 -227
- 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 +209 -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
|
@@ -7,12 +7,15 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import * as Messages from '../core/Messages';
|
|
9
9
|
import { EventEmitter } from 'eventemitter3';
|
|
10
|
+
import { ButtplugClientDeviceFeature } from './ButtplugClientDeviceFeature';
|
|
11
|
+
import { DeviceOutputCommand } from './ButtplugClientDeviceCommand';
|
|
10
12
|
/**
|
|
11
13
|
* Represents an abstract device, capable of taking certain kinds of messages.
|
|
12
14
|
*/
|
|
13
15
|
export declare class ButtplugClientDevice extends EventEmitter {
|
|
14
16
|
private _deviceInfo;
|
|
15
17
|
private _sendClosure;
|
|
18
|
+
private _features;
|
|
16
19
|
/**
|
|
17
20
|
* Return the name of the device.
|
|
18
21
|
*/
|
|
@@ -29,39 +32,21 @@ export declare class ButtplugClientDevice extends EventEmitter {
|
|
|
29
32
|
* Return the index of the device.
|
|
30
33
|
*/
|
|
31
34
|
get messageTimingGap(): number | undefined;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*/
|
|
35
|
-
get messageAttributes(): Messages.MessageAttributes;
|
|
36
|
-
static fromMsg(msg: Messages.DeviceInfo, sendClosure: (device: ButtplugClientDevice, msg: Messages.ButtplugDeviceMessage) => Promise<Messages.ButtplugMessage>): ButtplugClientDevice;
|
|
37
|
-
private allowedMsgs;
|
|
35
|
+
get features(): Map<number, ButtplugClientDeviceFeature>;
|
|
36
|
+
static fromMsg(msg: Messages.DeviceInfo, sendClosure: (msg: Messages.ButtplugMessage) => Promise<Messages.ButtplugMessage>): ButtplugClientDevice;
|
|
38
37
|
/**
|
|
39
38
|
* @param _index Index of the device, as created by the device manager.
|
|
40
39
|
* @param _name Name of the device.
|
|
41
40
|
* @param allowedMsgs Buttplug messages the device can receive.
|
|
42
41
|
*/
|
|
43
|
-
constructor(
|
|
44
|
-
send(msg: Messages.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
get oscillateAttributes(): Messages.GenericDeviceMessageAttributes[];
|
|
51
|
-
oscillate(speed: number | number[]): Promise<void>;
|
|
52
|
-
get rotateAttributes(): Messages.GenericDeviceMessageAttributes[];
|
|
53
|
-
rotate(values: number | [number, boolean][], clockwise?: boolean): Promise<void>;
|
|
54
|
-
get linearAttributes(): Messages.GenericDeviceMessageAttributes[];
|
|
55
|
-
linear(values: number | [number, number][], duration?: number): Promise<void>;
|
|
56
|
-
sensorRead(sensorIndex: number, sensorType: Messages.SensorType): Promise<number[]>;
|
|
57
|
-
get hasBattery(): boolean;
|
|
58
|
-
battery(): Promise<number>;
|
|
59
|
-
get hasRssi(): boolean;
|
|
60
|
-
rssi(): Promise<number>;
|
|
61
|
-
rawRead(endpoint: string, expectedLength: number, timeout: number): Promise<Uint8Array>;
|
|
62
|
-
rawWrite(endpoint: string, data: Uint8Array, writeWithResponse: boolean): Promise<void>;
|
|
63
|
-
rawSubscribe(endpoint: string): Promise<void>;
|
|
64
|
-
rawUnsubscribe(endpoint: string): Promise<void>;
|
|
42
|
+
private constructor();
|
|
43
|
+
send(msg: Messages.ButtplugMessage): Promise<Messages.ButtplugMessage>;
|
|
44
|
+
protected sendMsgExpectOk: (msg: Messages.ButtplugMessage) => Promise<void>;
|
|
45
|
+
protected isOutputValid(featureIndex: number, type: Messages.OutputType): void;
|
|
46
|
+
hasOutput(type: Messages.OutputType): boolean;
|
|
47
|
+
hasInput(type: Messages.InputType): boolean;
|
|
48
|
+
runOutput(cmd: DeviceOutputCommand): Promise<void>;
|
|
65
49
|
stop(): Promise<void>;
|
|
50
|
+
battery(): Promise<number>;
|
|
66
51
|
emitDisconnected(): void;
|
|
67
52
|
}
|
|
@@ -22,32 +22,36 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
22
22
|
}) : function(o, v) {
|
|
23
23
|
o["default"] = v;
|
|
24
24
|
});
|
|
25
|
-
var __importStar = (this && this.__importStar) || function (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
41
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
43
|
exports.ButtplugClientDevice = void 0;
|
|
43
44
|
const Messages = __importStar(require("../core/Messages"));
|
|
44
45
|
const Exceptions_1 = require("../core/Exceptions");
|
|
45
46
|
const eventemitter3_1 = require("eventemitter3");
|
|
46
|
-
const
|
|
47
|
+
const ButtplugClientDeviceFeature_1 = require("./ButtplugClientDeviceFeature");
|
|
47
48
|
/**
|
|
48
49
|
* Represents an abstract device, capable of taking certain kinds of messages.
|
|
49
50
|
*/
|
|
50
51
|
class ButtplugClientDevice extends eventemitter3_1.EventEmitter {
|
|
52
|
+
_deviceInfo;
|
|
53
|
+
_sendClosure;
|
|
54
|
+
_features;
|
|
51
55
|
/**
|
|
52
56
|
* Return the name of the device.
|
|
53
57
|
*/
|
|
@@ -72,15 +76,26 @@ class ButtplugClientDevice extends eventemitter3_1.EventEmitter {
|
|
|
72
76
|
get messageTimingGap() {
|
|
73
77
|
return this._deviceInfo.DeviceMessageTimingGap;
|
|
74
78
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*/
|
|
78
|
-
get messageAttributes() {
|
|
79
|
-
return this._deviceInfo.DeviceMessages;
|
|
79
|
+
get features() {
|
|
80
|
+
return this._features;
|
|
80
81
|
}
|
|
82
|
+
// /**
|
|
83
|
+
// * Return a list of message types the device accepts.
|
|
84
|
+
// */
|
|
85
|
+
// public get messageAttributes(): Messages.MessageAttributes {
|
|
86
|
+
// return this._deviceInfo.DeviceMessages;
|
|
87
|
+
// }
|
|
88
|
+
//
|
|
81
89
|
static fromMsg(msg, sendClosure) {
|
|
82
90
|
return new ButtplugClientDevice(msg, sendClosure);
|
|
83
91
|
}
|
|
92
|
+
//
|
|
93
|
+
// // Map of messages and their attributes (feature count, etc...)
|
|
94
|
+
// private allowedMsgs: Map<string, Messages.MessageAttributes> = new Map<
|
|
95
|
+
// string,
|
|
96
|
+
// Messages.MessageAttributes
|
|
97
|
+
// >();
|
|
98
|
+
//
|
|
84
99
|
/**
|
|
85
100
|
* @param _index Index of the device, as created by the device manager.
|
|
86
101
|
* @param _name Name of the device.
|
|
@@ -90,233 +105,76 @@ class ButtplugClientDevice extends eventemitter3_1.EventEmitter {
|
|
|
90
105
|
super();
|
|
91
106
|
this._deviceInfo = _deviceInfo;
|
|
92
107
|
this._sendClosure = _sendClosure;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
108
|
+
this._features = new Map(Object.entries(_deviceInfo.DeviceFeatures).map(([index, v]) => [parseInt(index), new ButtplugClientDeviceFeature_1.ButtplugClientDeviceFeature(_deviceInfo.DeviceIndex, _deviceInfo.DeviceName, v, _sendClosure)]));
|
|
109
|
+
}
|
|
110
|
+
async send(msg) {
|
|
111
|
+
// Assume we're getting the closure from ButtplugClient, which does all of
|
|
112
|
+
// the index/existence/connection/message checks for us.
|
|
113
|
+
return await this._sendClosure(msg);
|
|
114
|
+
}
|
|
115
|
+
sendMsgExpectOk = async (msg) => {
|
|
116
|
+
const response = await this.send(msg);
|
|
117
|
+
if (response.Ok !== undefined) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
else if (response.Error !== undefined) {
|
|
121
|
+
throw Exceptions_1.ButtplugError.FromError(response);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
/*
|
|
125
|
+
throw ButtplugError.LogAndError(
|
|
126
|
+
ButtplugMessageError,
|
|
127
|
+
this._logger,
|
|
128
|
+
`Message ${response} not handled by SendMsgExpectOk`
|
|
129
|
+
);
|
|
130
|
+
*/
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
isOutputValid(featureIndex, type) {
|
|
134
|
+
if (!this._deviceInfo.DeviceFeatures.hasOwnProperty(featureIndex.toString())) {
|
|
135
|
+
throw new Exceptions_1.ButtplugDeviceError(`Feature index ${featureIndex} does not exist for device ${this.name}`);
|
|
136
|
+
}
|
|
137
|
+
if (this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs !== undefined && !this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs.hasOwnProperty(type)) {
|
|
138
|
+
throw new Exceptions_1.ButtplugDeviceError(`Feature index ${featureIndex} does not support type ${type} for device ${this.name}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
hasOutput(type) {
|
|
142
|
+
return this._features.values().filter((f) => f.hasOutput(type)).toArray().length > 0;
|
|
143
|
+
}
|
|
144
|
+
hasInput(type) {
|
|
145
|
+
return this._features.values().filter((f) => f.hasInput(type)).toArray().length > 0;
|
|
146
|
+
}
|
|
147
|
+
async runOutput(cmd) {
|
|
148
|
+
let p = [];
|
|
149
|
+
for (let f of this._features.values()) {
|
|
150
|
+
if (f.hasOutput(cmd.outputType)) {
|
|
151
|
+
p.push(f.runOutput(cmd));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (p.length == 0) {
|
|
155
|
+
return Promise.reject(`No features with output type ${cmd.outputType}`);
|
|
156
|
+
}
|
|
157
|
+
await Promise.all(p);
|
|
158
|
+
}
|
|
159
|
+
async stop() {
|
|
160
|
+
await this.sendMsgExpectOk({ StopDeviceCmd: { Id: 1, DeviceIndex: this.index } });
|
|
161
|
+
}
|
|
162
|
+
async battery() {
|
|
163
|
+
let p = [];
|
|
164
|
+
for (let f of this._features.values()) {
|
|
165
|
+
if (f.hasInput(Messages.InputType.Battery)) {
|
|
166
|
+
// Right now, we only have one battery per device, so assume the first one we find is it.
|
|
167
|
+
let response = await f.runInput(Messages.InputType.Battery, Messages.InputCommandType.Read);
|
|
168
|
+
if (response === undefined) {
|
|
169
|
+
throw new Exceptions_1.ButtplugMessageError("Got incorrect message back.");
|
|
141
170
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
else {
|
|
147
|
-
throw new Exceptions_1.ButtplugDeviceError(`${actuator} can only take numbers or arrays of numbers.`);
|
|
148
|
-
}
|
|
149
|
-
yield this.scalar(cmds);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
get vibrateAttributes() {
|
|
153
|
-
var _a, _b;
|
|
154
|
-
return ((_b = (_a = this.messageAttributes.ScalarCmd) === null || _a === void 0 ? void 0 : _a.filter((x) => x.ActuatorType === Messages.ActuatorType.Vibrate)) !== null && _b !== void 0 ? _b : []);
|
|
155
|
-
}
|
|
156
|
-
vibrate(speed) {
|
|
157
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
yield this.scalarCommandBuilder(speed, Messages.ActuatorType.Vibrate);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
get oscillateAttributes() {
|
|
162
|
-
var _a, _b;
|
|
163
|
-
return ((_b = (_a = this.messageAttributes.ScalarCmd) === null || _a === void 0 ? void 0 : _a.filter((x) => x.ActuatorType === Messages.ActuatorType.Oscillate)) !== null && _b !== void 0 ? _b : []);
|
|
164
|
-
}
|
|
165
|
-
oscillate(speed) {
|
|
166
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
yield this.scalarCommandBuilder(speed, Messages.ActuatorType.Oscillate);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
get rotateAttributes() {
|
|
171
|
-
var _a;
|
|
172
|
-
return (_a = this.messageAttributes.RotateCmd) !== null && _a !== void 0 ? _a : [];
|
|
173
|
-
}
|
|
174
|
-
rotate(values, clockwise) {
|
|
175
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
-
const rotateAttrs = this.messageAttributes.RotateCmd;
|
|
177
|
-
if (!rotateAttrs || rotateAttrs.length === 0) {
|
|
178
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no Rotate capabilities`);
|
|
179
|
-
}
|
|
180
|
-
let msg;
|
|
181
|
-
if (typeof values === 'number') {
|
|
182
|
-
msg = Messages.RotateCmd.Create(this.index, new Array(rotateAttrs.length).fill([values, clockwise]));
|
|
183
|
-
}
|
|
184
|
-
else if (Array.isArray(values)) {
|
|
185
|
-
msg = Messages.RotateCmd.Create(this.index, values);
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
throw new Exceptions_1.ButtplugDeviceError('SendRotateCmd can only take a number and boolean, or an array of number/boolean tuples');
|
|
189
|
-
}
|
|
190
|
-
yield this.sendExpectOk(msg);
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
get linearAttributes() {
|
|
194
|
-
var _a;
|
|
195
|
-
return (_a = this.messageAttributes.LinearCmd) !== null && _a !== void 0 ? _a : [];
|
|
196
|
-
}
|
|
197
|
-
linear(values, duration) {
|
|
198
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
const linearAttrs = this.messageAttributes.LinearCmd;
|
|
200
|
-
if (!linearAttrs || linearAttrs.length === 0) {
|
|
201
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no Linear capabilities`);
|
|
202
|
-
}
|
|
203
|
-
let msg;
|
|
204
|
-
if (typeof values === 'number') {
|
|
205
|
-
msg = Messages.LinearCmd.Create(this.index, new Array(linearAttrs.length).fill([values, duration]));
|
|
206
|
-
}
|
|
207
|
-
else if (Array.isArray(values)) {
|
|
208
|
-
msg = Messages.LinearCmd.Create(this.index, values);
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
throw new Exceptions_1.ButtplugDeviceError('SendLinearCmd can only take a number and number, or an array of number/number tuples');
|
|
212
|
-
}
|
|
213
|
-
yield this.sendExpectOk(msg);
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
sensorRead(sensorIndex, sensorType) {
|
|
217
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
-
const response = yield this.send(new Messages.SensorReadCmd(this.index, sensorIndex, sensorType));
|
|
219
|
-
switch ((0, MessageUtils_1.getMessageClassFromMessage)(response)) {
|
|
220
|
-
case Messages.SensorReading:
|
|
221
|
-
return response.Data;
|
|
222
|
-
case Messages.Error:
|
|
223
|
-
throw Exceptions_1.ButtplugError.FromError(response);
|
|
224
|
-
default:
|
|
225
|
-
throw new Exceptions_1.ButtplugMessageError(`Message type ${response.constructor} not handled by sensorRead`);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
get hasBattery() {
|
|
230
|
-
var _a;
|
|
231
|
-
const batteryAttrs = (_a = this.messageAttributes.SensorReadCmd) === null || _a === void 0 ? void 0 : _a.filter((x) => x.SensorType === Messages.SensorType.Battery);
|
|
232
|
-
return batteryAttrs !== undefined && batteryAttrs.length > 0;
|
|
233
|
-
}
|
|
234
|
-
battery() {
|
|
235
|
-
var _a;
|
|
236
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
-
if (!this.hasBattery) {
|
|
238
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no Battery capabilities`);
|
|
239
|
-
}
|
|
240
|
-
const batteryAttrs = (_a = this.messageAttributes.SensorReadCmd) === null || _a === void 0 ? void 0 : _a.filter((x) => x.SensorType === Messages.SensorType.Battery);
|
|
241
|
-
// Find the battery sensor, we'll need its index.
|
|
242
|
-
const result = yield this.sensorRead(batteryAttrs[0].Index, Messages.SensorType.Battery);
|
|
243
|
-
return result[0] / 100.0;
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
get hasRssi() {
|
|
247
|
-
var _a;
|
|
248
|
-
const rssiAttrs = (_a = this.messageAttributes.SensorReadCmd) === null || _a === void 0 ? void 0 : _a.filter((x) => x.SensorType === Messages.SensorType.RSSI);
|
|
249
|
-
return rssiAttrs !== undefined && rssiAttrs.length === 0;
|
|
250
|
-
}
|
|
251
|
-
rssi() {
|
|
252
|
-
var _a;
|
|
253
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
-
if (!this.hasRssi) {
|
|
255
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no RSSI capabilities`);
|
|
256
|
-
}
|
|
257
|
-
const rssiAttrs = (_a = this.messageAttributes.SensorReadCmd) === null || _a === void 0 ? void 0 : _a.filter((x) => x.SensorType === Messages.SensorType.RSSI);
|
|
258
|
-
// Find the battery sensor, we'll need its index.
|
|
259
|
-
const result = yield this.sensorRead(rssiAttrs[0].Index, Messages.SensorType.RSSI);
|
|
260
|
-
return result[0];
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
rawRead(endpoint, expectedLength, timeout) {
|
|
264
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
-
if (!this.messageAttributes.RawReadCmd) {
|
|
266
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no raw read capabilities`);
|
|
267
|
-
}
|
|
268
|
-
if (this.messageAttributes.RawReadCmd.Endpoints.indexOf(endpoint) === -1) {
|
|
269
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no raw readable endpoint ${endpoint}`);
|
|
270
|
-
}
|
|
271
|
-
const response = yield this.send(new Messages.RawReadCmd(this.index, endpoint, expectedLength, timeout));
|
|
272
|
-
switch ((0, MessageUtils_1.getMessageClassFromMessage)(response)) {
|
|
273
|
-
case Messages.RawReading:
|
|
274
|
-
return new Uint8Array(response.Data);
|
|
275
|
-
case Messages.Error:
|
|
276
|
-
throw Exceptions_1.ButtplugError.FromError(response);
|
|
277
|
-
default:
|
|
278
|
-
throw new Exceptions_1.ButtplugMessageError(`Message type ${response.constructor} not handled by rawRead`);
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
rawWrite(endpoint, data, writeWithResponse) {
|
|
283
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
-
if (!this.messageAttributes.RawWriteCmd) {
|
|
285
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no raw write capabilities`);
|
|
286
|
-
}
|
|
287
|
-
if (this.messageAttributes.RawWriteCmd.Endpoints.indexOf(endpoint) === -1) {
|
|
288
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no raw writable endpoint ${endpoint}`);
|
|
289
|
-
}
|
|
290
|
-
yield this.sendExpectOk(new Messages.RawWriteCmd(this.index, endpoint, data, writeWithResponse));
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
rawSubscribe(endpoint) {
|
|
294
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
-
if (!this.messageAttributes.RawSubscribeCmd) {
|
|
296
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no raw subscribe capabilities`);
|
|
297
|
-
}
|
|
298
|
-
if (this.messageAttributes.RawSubscribeCmd.Endpoints.indexOf(endpoint) === -1) {
|
|
299
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no raw subscribable endpoint ${endpoint}`);
|
|
300
|
-
}
|
|
301
|
-
yield this.sendExpectOk(new Messages.RawSubscribeCmd(this.index, endpoint));
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
rawUnsubscribe(endpoint) {
|
|
305
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
-
// This reuses raw subscribe's info.
|
|
307
|
-
if (!this.messageAttributes.RawSubscribeCmd) {
|
|
308
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no raw unsubscribe capabilities`);
|
|
309
|
-
}
|
|
310
|
-
if (this.messageAttributes.RawSubscribeCmd.Endpoints.indexOf(endpoint) === -1) {
|
|
311
|
-
throw new Exceptions_1.ButtplugDeviceError(`Device ${this.name} has no raw unsubscribable endpoint ${endpoint}`);
|
|
171
|
+
if (response.Reading[Messages.InputType.Battery] === undefined) {
|
|
172
|
+
throw new Exceptions_1.ButtplugMessageError("Got reading with no Battery info.");
|
|
173
|
+
}
|
|
174
|
+
return response.Reading[Messages.InputType.Battery].Value;
|
|
312
175
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
stop() {
|
|
317
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
318
|
-
yield this.sendExpectOk(new Messages.StopDeviceCmd(this.index));
|
|
319
|
-
});
|
|
176
|
+
}
|
|
177
|
+
throw new Exceptions_1.ButtplugDeviceError(`No battery present on this device.`);
|
|
320
178
|
}
|
|
321
179
|
emitDisconnected() {
|
|
322
180
|
this.emit('deviceremoved');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtplugClientDevice.js","sourceRoot":"","sources":["../../../../src/client/ButtplugClientDevice.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,CAAC
|
|
1
|
+
{"version":3,"file":"ButtplugClientDevice.js","sourceRoot":"","sources":["../../../../src/client/ButtplugClientDevice.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,2DAA6C;AAC7C,mDAI4B;AAC5B,iDAA6C;AAC7C,+EAA4E;AAG5E;;GAEG;AACH,MAAa,oBAAqB,SAAQ,4BAAY;IAgE1C;IACA;IA/DF,SAAS,CAA2C;IAE5D;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC;IACrC,CAAC;IA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AC,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;gBAC5F,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;oBAC3B,MAAM,IAAI,iCAAoB,CAAC,6BAA6B,CAAC,CAAC;gBAChE,CAAC;gBACD,IAAI,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC;oBAC/D,MAAM,IAAI,iCAAoB,CAAC,mCAAmC,CAAC,CAAC;gBACtE,CAAC;gBACD,OAAO,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;YAC5D,CAAC;QACH,CAAC;QACD,MAAM,IAAI,gCAAmB,CAAC,oCAAoC,CAAC,CAAC;IACtE,CAAC;IAEM,gBAAgB;QACrB,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC7B,CAAC;CACF;AA3JD,oDA2JC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { OutputType } from "../core/Messages";
|
|
2
|
+
declare class PercentOrSteps {
|
|
3
|
+
private _percent;
|
|
4
|
+
private _steps;
|
|
5
|
+
get percent(): number | undefined;
|
|
6
|
+
get steps(): number | undefined;
|
|
7
|
+
static createSteps(s: number): PercentOrSteps;
|
|
8
|
+
static createPercent(p: number): PercentOrSteps;
|
|
9
|
+
}
|
|
10
|
+
export declare class DeviceOutputCommand {
|
|
11
|
+
private _outputType;
|
|
12
|
+
private _value;
|
|
13
|
+
private _duration?;
|
|
14
|
+
constructor(_outputType: OutputType, _value: PercentOrSteps, _duration?: number | undefined);
|
|
15
|
+
get outputType(): OutputType;
|
|
16
|
+
get value(): PercentOrSteps;
|
|
17
|
+
get duration(): number | undefined;
|
|
18
|
+
}
|
|
19
|
+
export declare class DeviceOutputValueConstructor {
|
|
20
|
+
private _outputType;
|
|
21
|
+
constructor(_outputType: OutputType);
|
|
22
|
+
steps(steps: number): DeviceOutputCommand;
|
|
23
|
+
percent(percent: number): DeviceOutputCommand;
|
|
24
|
+
}
|
|
25
|
+
export declare class DeviceOutputPositionWithDurationConstructor {
|
|
26
|
+
steps(steps: number, duration: number): DeviceOutputCommand;
|
|
27
|
+
percent(percent: number, duration: number): DeviceOutputCommand;
|
|
28
|
+
}
|
|
29
|
+
export declare class DeviceOutput {
|
|
30
|
+
private constructor();
|
|
31
|
+
static get Vibrate(): DeviceOutputValueConstructor;
|
|
32
|
+
static get Rotate(): DeviceOutputValueConstructor;
|
|
33
|
+
static get Oscillate(): DeviceOutputValueConstructor;
|
|
34
|
+
static get Constrict(): DeviceOutputValueConstructor;
|
|
35
|
+
static get Inflate(): DeviceOutputValueConstructor;
|
|
36
|
+
static get Temperature(): DeviceOutputValueConstructor;
|
|
37
|
+
static get Led(): DeviceOutputValueConstructor;
|
|
38
|
+
static get Spray(): DeviceOutputValueConstructor;
|
|
39
|
+
static get Position(): DeviceOutputValueConstructor;
|
|
40
|
+
static get PositionWithDuration(): DeviceOutputPositionWithDurationConstructor;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeviceOutput = exports.DeviceOutputPositionWithDurationConstructor = exports.DeviceOutputValueConstructor = exports.DeviceOutputCommand = void 0;
|
|
4
|
+
const Exceptions_1 = require("../core/Exceptions");
|
|
5
|
+
const Messages_1 = require("../core/Messages");
|
|
6
|
+
class PercentOrSteps {
|
|
7
|
+
_percent;
|
|
8
|
+
_steps;
|
|
9
|
+
get percent() {
|
|
10
|
+
return this._percent;
|
|
11
|
+
}
|
|
12
|
+
get steps() {
|
|
13
|
+
return this._steps;
|
|
14
|
+
}
|
|
15
|
+
static createSteps(s) {
|
|
16
|
+
let v = new PercentOrSteps;
|
|
17
|
+
v._steps = s;
|
|
18
|
+
return v;
|
|
19
|
+
}
|
|
20
|
+
static createPercent(p) {
|
|
21
|
+
if (p < 0 || p > 1.0) {
|
|
22
|
+
throw new Exceptions_1.ButtplugDeviceError(`Percent value ${p} is not in the range 0.0 <= x <= 1.0`);
|
|
23
|
+
}
|
|
24
|
+
let v = new PercentOrSteps;
|
|
25
|
+
v._percent = p;
|
|
26
|
+
return v;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
class DeviceOutputCommand {
|
|
30
|
+
_outputType;
|
|
31
|
+
_value;
|
|
32
|
+
_duration;
|
|
33
|
+
constructor(_outputType, _value, _duration) {
|
|
34
|
+
this._outputType = _outputType;
|
|
35
|
+
this._value = _value;
|
|
36
|
+
this._duration = _duration;
|
|
37
|
+
}
|
|
38
|
+
get outputType() {
|
|
39
|
+
return this._outputType;
|
|
40
|
+
}
|
|
41
|
+
get value() {
|
|
42
|
+
return this._value;
|
|
43
|
+
}
|
|
44
|
+
get duration() {
|
|
45
|
+
return this._duration;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.DeviceOutputCommand = DeviceOutputCommand;
|
|
49
|
+
class DeviceOutputValueConstructor {
|
|
50
|
+
_outputType;
|
|
51
|
+
constructor(_outputType) {
|
|
52
|
+
this._outputType = _outputType;
|
|
53
|
+
}
|
|
54
|
+
steps(steps) {
|
|
55
|
+
return new DeviceOutputCommand(this._outputType, PercentOrSteps.createSteps(steps), undefined);
|
|
56
|
+
}
|
|
57
|
+
percent(percent) {
|
|
58
|
+
return new DeviceOutputCommand(this._outputType, PercentOrSteps.createPercent(percent), undefined);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.DeviceOutputValueConstructor = DeviceOutputValueConstructor;
|
|
62
|
+
class DeviceOutputPositionWithDurationConstructor {
|
|
63
|
+
steps(steps, duration) {
|
|
64
|
+
return new DeviceOutputCommand(Messages_1.OutputType.Position, PercentOrSteps.createSteps(steps), duration);
|
|
65
|
+
}
|
|
66
|
+
percent(percent, duration) {
|
|
67
|
+
return new DeviceOutputCommand(Messages_1.OutputType.PositionWithDuration, PercentOrSteps.createPercent(percent), duration);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.DeviceOutputPositionWithDurationConstructor = DeviceOutputPositionWithDurationConstructor;
|
|
71
|
+
class DeviceOutput {
|
|
72
|
+
constructor() { }
|
|
73
|
+
static get Vibrate() {
|
|
74
|
+
return new DeviceOutputValueConstructor(Messages_1.OutputType.Vibrate);
|
|
75
|
+
}
|
|
76
|
+
static get Rotate() {
|
|
77
|
+
return new DeviceOutputValueConstructor(Messages_1.OutputType.Rotate);
|
|
78
|
+
}
|
|
79
|
+
static get Oscillate() {
|
|
80
|
+
return new DeviceOutputValueConstructor(Messages_1.OutputType.Oscillate);
|
|
81
|
+
}
|
|
82
|
+
static get Constrict() {
|
|
83
|
+
return new DeviceOutputValueConstructor(Messages_1.OutputType.Constrict);
|
|
84
|
+
}
|
|
85
|
+
static get Inflate() {
|
|
86
|
+
return new DeviceOutputValueConstructor(Messages_1.OutputType.Inflate);
|
|
87
|
+
}
|
|
88
|
+
static get Temperature() {
|
|
89
|
+
return new DeviceOutputValueConstructor(Messages_1.OutputType.Temperature);
|
|
90
|
+
}
|
|
91
|
+
static get Led() {
|
|
92
|
+
return new DeviceOutputValueConstructor(Messages_1.OutputType.Led);
|
|
93
|
+
}
|
|
94
|
+
static get Spray() {
|
|
95
|
+
return new DeviceOutputValueConstructor(Messages_1.OutputType.Spray);
|
|
96
|
+
}
|
|
97
|
+
static get Position() {
|
|
98
|
+
return new DeviceOutputValueConstructor(Messages_1.OutputType.Position);
|
|
99
|
+
}
|
|
100
|
+
static get PositionWithDuration() {
|
|
101
|
+
return new DeviceOutputPositionWithDurationConstructor();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.DeviceOutput = DeviceOutput;
|
|
105
|
+
//# sourceMappingURL=ButtplugClientDeviceCommand.js.map
|