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
package/src/index.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
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
|
-
export * from './client/
|
|
10
|
-
export * from './client/ButtplugClientDevice';
|
|
11
|
-
export * from './client/ButtplugBrowserWebsocketClientConnector';
|
|
12
|
-
export * from './client/ButtplugNodeWebsocketClientConnector';
|
|
13
|
-
export * from './client/ButtplugClientConnectorException';
|
|
14
|
-
export * from './utils/ButtplugMessageSorter';
|
|
15
|
-
export * from './client/
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './core/
|
|
18
|
-
export * from './core/
|
|
19
|
-
export * from './core/
|
|
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
|
+
export * from './client/ButtplugClient';
|
|
10
|
+
export * from './client/ButtplugClientDevice';
|
|
11
|
+
export * from './client/ButtplugBrowserWebsocketClientConnector';
|
|
12
|
+
export * from './client/ButtplugNodeWebsocketClientConnector';
|
|
13
|
+
export * from './client/ButtplugClientConnectorException';
|
|
14
|
+
export * from './utils/ButtplugMessageSorter';
|
|
15
|
+
export * from './client/ButtplugClientDeviceCommand';
|
|
16
|
+
export * from './client/IButtplugClientConnector';
|
|
17
|
+
//export * from './core/MessageClasses';
|
|
18
|
+
export * from './core/Messages';
|
|
19
|
+
//export * from './core/MessageUtils';
|
|
20
|
+
export * from './core/Logging';
|
|
21
|
+
export * from './core/Exceptions';
|
|
@@ -1,89 +1,89 @@
|
|
|
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 { EventEmitter } from 'eventemitter3';
|
|
12
|
-
import { ButtplugMessage } from '../core/Messages';
|
|
13
|
-
import { fromJSON } from '../core/MessageUtils';
|
|
14
|
-
|
|
15
|
-
export class ButtplugBrowserWebsocketConnector extends EventEmitter {
|
|
16
|
-
protected _ws: WebSocket | undefined;
|
|
17
|
-
protected _websocketConstructor: typeof WebSocket | null = null;
|
|
18
|
-
|
|
19
|
-
public constructor(private _url: string) {
|
|
20
|
-
super();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public get Connected(): boolean {
|
|
24
|
-
return this._ws !== undefined;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public connect = async (): Promise<void> => {
|
|
28
|
-
return new Promise<void>((resolve, reject) => {
|
|
29
|
-
const ws = new (this._websocketConstructor ?? WebSocket)(this._url);
|
|
30
|
-
const onErrorCallback = (event: Event) => {reject(event)}
|
|
31
|
-
const onCloseCallback = (event: CloseEvent) => reject(event.reason)
|
|
32
|
-
ws.addEventListener('open', async () => {
|
|
33
|
-
this._ws = ws;
|
|
34
|
-
try {
|
|
35
|
-
await this.initialize();
|
|
36
|
-
this._ws.addEventListener('message', (msg) => {
|
|
37
|
-
this.parseIncomingMessage(msg);
|
|
38
|
-
});
|
|
39
|
-
this._ws.removeEventListener('close', onCloseCallback);
|
|
40
|
-
this._ws.removeEventListener('error', onErrorCallback);
|
|
41
|
-
this._ws.addEventListener('close', this.disconnect);
|
|
42
|
-
resolve();
|
|
43
|
-
} catch (e) {
|
|
44
|
-
reject(e);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
// In websockets, our error rarely tells us much, as for security reasons
|
|
48
|
-
// browsers usually only throw Error Code 1006. It's up to those using this
|
|
49
|
-
// library to state what the problem might be.
|
|
50
|
-
|
|
51
|
-
ws.addEventListener('error', onErrorCallback)
|
|
52
|
-
ws.addEventListener('close', onCloseCallback);
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
public disconnect = async (): Promise<void> => {
|
|
57
|
-
if (!this.Connected) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
this._ws!.close();
|
|
61
|
-
this._ws = undefined;
|
|
62
|
-
this.emit('disconnect');
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
public sendMessage(msg: ButtplugMessage) {
|
|
66
|
-
if (!this.Connected) {
|
|
67
|
-
throw new Error('ButtplugBrowserWebsocketConnector not connected');
|
|
68
|
-
}
|
|
69
|
-
this._ws!.send('[' +
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public initialize = async (): Promise<void> => {
|
|
73
|
-
return Promise.resolve();
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
protected parseIncomingMessage(event: MessageEvent) {
|
|
77
|
-
if (typeof event.data === 'string') {
|
|
78
|
-
const msgs =
|
|
79
|
-
this.emit('message', msgs);
|
|
80
|
-
} else if (event.data instanceof Blob) {
|
|
81
|
-
// No-op, we only use text message types.
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
protected onReaderLoad(event: Event) {
|
|
86
|
-
const msgs =
|
|
87
|
-
this.emit('message', msgs);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
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 { EventEmitter } from 'eventemitter3';
|
|
12
|
+
import { ButtplugMessage } from '../core/Messages';
|
|
13
|
+
//import { fromJSON } from '../core/MessageUtils';
|
|
14
|
+
|
|
15
|
+
export class ButtplugBrowserWebsocketConnector extends EventEmitter {
|
|
16
|
+
protected _ws: WebSocket | undefined;
|
|
17
|
+
protected _websocketConstructor: typeof WebSocket | null = null;
|
|
18
|
+
|
|
19
|
+
public constructor(private _url: string) {
|
|
20
|
+
super();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public get Connected(): boolean {
|
|
24
|
+
return this._ws !== undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public connect = async (): Promise<void> => {
|
|
28
|
+
return new Promise<void>((resolve, reject) => {
|
|
29
|
+
const ws = new (this._websocketConstructor ?? WebSocket)(this._url);
|
|
30
|
+
const onErrorCallback = (event: Event) => {reject(event)}
|
|
31
|
+
const onCloseCallback = (event: CloseEvent) => reject(event.reason)
|
|
32
|
+
ws.addEventListener('open', async () => {
|
|
33
|
+
this._ws = ws;
|
|
34
|
+
try {
|
|
35
|
+
await this.initialize();
|
|
36
|
+
this._ws.addEventListener('message', (msg) => {
|
|
37
|
+
this.parseIncomingMessage(msg);
|
|
38
|
+
});
|
|
39
|
+
this._ws.removeEventListener('close', onCloseCallback);
|
|
40
|
+
this._ws.removeEventListener('error', onErrorCallback);
|
|
41
|
+
this._ws.addEventListener('close', this.disconnect);
|
|
42
|
+
resolve();
|
|
43
|
+
} catch (e) {
|
|
44
|
+
reject(e);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
// In websockets, our error rarely tells us much, as for security reasons
|
|
48
|
+
// browsers usually only throw Error Code 1006. It's up to those using this
|
|
49
|
+
// library to state what the problem might be.
|
|
50
|
+
|
|
51
|
+
ws.addEventListener('error', onErrorCallback)
|
|
52
|
+
ws.addEventListener('close', onCloseCallback);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
public disconnect = async (): Promise<void> => {
|
|
57
|
+
if (!this.Connected) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
this._ws!.close();
|
|
61
|
+
this._ws = undefined;
|
|
62
|
+
this.emit('disconnect');
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
public sendMessage(msg: ButtplugMessage) {
|
|
66
|
+
if (!this.Connected) {
|
|
67
|
+
throw new Error('ButtplugBrowserWebsocketConnector not connected');
|
|
68
|
+
}
|
|
69
|
+
this._ws!.send('[' + JSON.stringify(msg) + ']');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public initialize = async (): Promise<void> => {
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
protected parseIncomingMessage(event: MessageEvent) {
|
|
77
|
+
if (typeof event.data === 'string') {
|
|
78
|
+
const msgs: ButtplugMessage[] = JSON.parse(event.data);
|
|
79
|
+
this.emit('message', msgs);
|
|
80
|
+
} else if (event.data instanceof Blob) {
|
|
81
|
+
// No-op, we only use text message types.
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
protected onReaderLoad(event: Event) {
|
|
86
|
+
const msgs: ButtplugMessage[] = JSON.parse((event.target as FileReader).result as string);
|
|
87
|
+
this.emit('message', msgs);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1,65 +1,66 @@
|
|
|
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 '../core/Messages';
|
|
10
|
-
import { ButtplugError } from '../core/Exceptions';
|
|
11
|
-
|
|
12
|
-
export class ButtplugMessageSorter {
|
|
13
|
-
protected _counter = 1;
|
|
14
|
-
protected _waitingMsgs: Map<
|
|
15
|
-
number,
|
|
16
|
-
[(val: Messages.ButtplugMessage) => void, (err: Error) => void]
|
|
17
|
-
> = new Map();
|
|
18
|
-
|
|
19
|
-
public constructor(private _useCounter: boolean) {}
|
|
20
|
-
|
|
21
|
-
// One of the places we should actually return a promise, as we need to store
|
|
22
|
-
// them while waiting for them to return across the line.
|
|
23
|
-
// tslint:disable:promise-function-async
|
|
24
|
-
public PrepareOutgoingMessage(
|
|
25
|
-
msg: Messages.ButtplugMessage
|
|
26
|
-
): Promise<Messages.ButtplugMessage> {
|
|
27
|
-
if (this._useCounter) {
|
|
28
|
-
msg
|
|
29
|
-
// Always increment last, otherwise we might lose sync
|
|
30
|
-
this._counter += 1;
|
|
31
|
-
}
|
|
32
|
-
let res;
|
|
33
|
-
let rej;
|
|
34
|
-
const msgPromise = new Promise<Messages.ButtplugMessage>(
|
|
35
|
-
(resolve, reject) => {
|
|
36
|
-
res = resolve;
|
|
37
|
-
rej = reject;
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
this._waitingMsgs.set(msg
|
|
41
|
-
return msgPromise;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public ParseIncomingMessages(
|
|
45
|
-
msgs: Messages.ButtplugMessage[]
|
|
46
|
-
): Messages.ButtplugMessage[] {
|
|
47
|
-
const noMatch: Messages.ButtplugMessage[] = [];
|
|
48
|
-
for (const x of msgs) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
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 '../core/Messages';
|
|
10
|
+
import { ButtplugError } from '../core/Exceptions';
|
|
11
|
+
|
|
12
|
+
export class ButtplugMessageSorter {
|
|
13
|
+
protected _counter = 1;
|
|
14
|
+
protected _waitingMsgs: Map<
|
|
15
|
+
number,
|
|
16
|
+
[(val: Messages.ButtplugMessage) => void, (err: Error) => void]
|
|
17
|
+
> = new Map();
|
|
18
|
+
|
|
19
|
+
public constructor(private _useCounter: boolean) {}
|
|
20
|
+
|
|
21
|
+
// One of the places we should actually return a promise, as we need to store
|
|
22
|
+
// them while waiting for them to return across the line.
|
|
23
|
+
// tslint:disable:promise-function-async
|
|
24
|
+
public PrepareOutgoingMessage(
|
|
25
|
+
msg: Messages.ButtplugMessage
|
|
26
|
+
): Promise<Messages.ButtplugMessage> {
|
|
27
|
+
if (this._useCounter) {
|
|
28
|
+
Messages.setMsgId(msg, this._counter);
|
|
29
|
+
// Always increment last, otherwise we might lose sync
|
|
30
|
+
this._counter += 1;
|
|
31
|
+
}
|
|
32
|
+
let res;
|
|
33
|
+
let rej;
|
|
34
|
+
const msgPromise = new Promise<Messages.ButtplugMessage>(
|
|
35
|
+
(resolve, reject) => {
|
|
36
|
+
res = resolve;
|
|
37
|
+
rej = reject;
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
this._waitingMsgs.set(Messages.msgId(msg), [res, rej]);
|
|
41
|
+
return msgPromise;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public ParseIncomingMessages(
|
|
45
|
+
msgs: Messages.ButtplugMessage[]
|
|
46
|
+
): Messages.ButtplugMessage[] {
|
|
47
|
+
const noMatch: Messages.ButtplugMessage[] = [];
|
|
48
|
+
for (const x of msgs) {
|
|
49
|
+
let id = Messages.msgId(x);
|
|
50
|
+
if (id !== Messages.SYSTEM_MESSAGE_ID && this._waitingMsgs.has(id)) {
|
|
51
|
+
const [res, rej] = this._waitingMsgs.get(id)!;
|
|
52
|
+
// If we've gotten back an error, reject the related promise using a
|
|
53
|
+
// ButtplugException derived type.
|
|
54
|
+
if (x.Error !== undefined) {
|
|
55
|
+
rej(ButtplugError.FromError(x.Error!));
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
res(x);
|
|
59
|
+
continue;
|
|
60
|
+
} else {
|
|
61
|
+
noMatch.push(x);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return noMatch;
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/utils/Utils.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export function getRandomInt(max: number) {
|
|
2
|
-
return Math.floor(Math.random() * Math.floor(max));
|
|
3
|
-
}
|
|
1
|
+
export function getRandomInt(max: number) {
|
|
2
|
+
return Math.floor(Math.random() * Math.floor(max));
|
|
3
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions" : {
|
|
3
|
-
"baseUrl": "./src",
|
|
4
|
-
"lib": ["
|
|
5
|
-
"target": "
|
|
6
|
-
"module": "commonjs",
|
|
7
|
-
"moduleResolution": "node",
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"emitDecoratorMetadata": true,
|
|
10
|
-
"experimentalDecorators": true,
|
|
11
|
-
"strictNullChecks": true,
|
|
12
|
-
"noImplicitThis": true,
|
|
13
|
-
"declaration": true,
|
|
14
|
-
"outDir": "./dist/main",
|
|
15
|
-
"esModuleInterop": true
|
|
16
|
-
},
|
|
17
|
-
"include": [
|
|
18
|
-
"./src/*.ts",
|
|
19
|
-
"./src/**/*.ts",
|
|
20
|
-
"./tests/**/*.ts"
|
|
21
|
-
]
|
|
22
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions" : {
|
|
3
|
+
"baseUrl": "./src",
|
|
4
|
+
"lib": ["esnext", "dom"],
|
|
5
|
+
"target": "esnext",
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"emitDecoratorMetadata": true,
|
|
10
|
+
"experimentalDecorators": true,
|
|
11
|
+
"strictNullChecks": true,
|
|
12
|
+
"noImplicitThis": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"outDir": "./dist/main",
|
|
15
|
+
"esModuleInterop": true
|
|
16
|
+
},
|
|
17
|
+
"include": [
|
|
18
|
+
"./src/*.ts",
|
|
19
|
+
"./src/**/*.ts",
|
|
20
|
+
"./tests/**/*.ts"
|
|
21
|
+
]
|
|
22
|
+
}
|
package/tsfmt.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
"indentSize": 2,
|
|
3
|
-
"tabSize": 2,
|
|
4
|
-
"convertTabsToSpaces": true,
|
|
5
|
-
"insertSpaceAfterCommaDelimiter": true,
|
|
6
|
-
"insertSpaceAfterSemicolonInForStatements": true,
|
|
7
|
-
"insertSpaceBeforeAndAfterBinaryOperators": true,
|
|
8
|
-
"insertSpaceAfterKeywordsInControlFlowStatements": true,
|
|
9
|
-
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
|
|
10
|
-
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
|
|
11
|
-
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
|
|
12
|
-
"placeOpenBraceOnNewLineForFunctions": false,
|
|
13
|
-
"placeOpenBraceOnNewLineForControlBlocks": false
|
|
14
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"indentSize": 2,
|
|
3
|
+
"tabSize": 2,
|
|
4
|
+
"convertTabsToSpaces": true,
|
|
5
|
+
"insertSpaceAfterCommaDelimiter": true,
|
|
6
|
+
"insertSpaceAfterSemicolonInForStatements": true,
|
|
7
|
+
"insertSpaceBeforeAndAfterBinaryOperators": true,
|
|
8
|
+
"insertSpaceAfterKeywordsInControlFlowStatements": true,
|
|
9
|
+
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
|
|
10
|
+
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
|
|
11
|
+
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
|
|
12
|
+
"placeOpenBraceOnNewLineForFunctions": false,
|
|
13
|
+
"placeOpenBraceOnNewLineForControlBlocks": false
|
|
14
|
+
}
|
package/tslint.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": [
|
|
3
|
-
"tslint:recommended"
|
|
4
|
-
],
|
|
5
|
-
"linterOptions": {
|
|
6
|
-
"exclude": [
|
|
7
|
-
"**/buttplug-gui-proto.d.ts"
|
|
8
|
-
]
|
|
9
|
-
},
|
|
10
|
-
"jsRules": {},
|
|
11
|
-
"rules": {
|
|
12
|
-
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"],
|
|
13
|
-
"only-arrow-functions": [false],
|
|
14
|
-
"indent": [true, "spaces", 2],
|
|
15
|
-
"no-var-requires": [false],
|
|
16
|
-
"ordered-imports": [false],
|
|
17
|
-
"no-console": [false],
|
|
18
|
-
"object-literal-sort-keys": [false],
|
|
19
|
-
"max-classes-per-file": [false],
|
|
20
|
-
"no-bitwise": [false],
|
|
21
|
-
"semicolon": [true, "always"],
|
|
22
|
-
"promise-function-async": true,
|
|
23
|
-
"no-invalid-template-strings": true,
|
|
24
|
-
"no-floating-promises": true
|
|
25
|
-
},
|
|
26
|
-
"rulesDirectory": []
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"tslint:recommended"
|
|
4
|
+
],
|
|
5
|
+
"linterOptions": {
|
|
6
|
+
"exclude": [
|
|
7
|
+
"**/buttplug-gui-proto.d.ts"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"jsRules": {},
|
|
11
|
+
"rules": {
|
|
12
|
+
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"],
|
|
13
|
+
"only-arrow-functions": [false],
|
|
14
|
+
"indent": [true, "spaces", 2],
|
|
15
|
+
"no-var-requires": [false],
|
|
16
|
+
"ordered-imports": [false],
|
|
17
|
+
"no-console": [false],
|
|
18
|
+
"object-literal-sort-keys": [false],
|
|
19
|
+
"max-classes-per-file": [false],
|
|
20
|
+
"no-bitwise": [false],
|
|
21
|
+
"semicolon": [true, "always"],
|
|
22
|
+
"promise-function-async": true,
|
|
23
|
+
"no-invalid-template-strings": true,
|
|
24
|
+
"no-floating-promises": true
|
|
25
|
+
},
|
|
26
|
+
"rulesDirectory": []
|
|
27
|
+
}
|
package/typedocconfig.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/** @type {import('typedoc').TypeDocOptions} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
exclude: '**/+(test|example|node_modules)/**/*.ts',
|
|
4
|
-
excludeExternals: true,
|
|
5
|
-
excludePrivate: true,
|
|
6
|
-
};
|
|
1
|
+
/** @type {import('typedoc').TypeDocOptions} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
exclude: '**/+(test|example|node_modules)/**/*.ts',
|
|
4
|
+
excludeExternals: true,
|
|
5
|
+
excludePrivate: true,
|
|
6
|
+
};
|
package/vite.config.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
2
|
-
import { defineConfig } from 'vite';
|
|
3
|
-
import dts from 'vite-plugin-dts';
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
build: {
|
|
7
|
-
lib: {
|
|
8
|
-
// Could also be a dictionary or array of multiple entry points
|
|
9
|
-
entry: resolve(__dirname, 'src/index.ts'),
|
|
10
|
-
name: 'buttplug',
|
|
11
|
-
// the proper extensions will be added
|
|
12
|
-
fileName: (format): string => {
|
|
13
|
-
if (format === 'umd') {
|
|
14
|
-
return 'buttplug.js';
|
|
15
|
-
}
|
|
16
|
-
return 'buttplug.mjs';
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
outDir: 'dist/web',
|
|
20
|
-
},
|
|
21
|
-
plugins: [
|
|
22
|
-
dts({
|
|
23
|
-
exclude: ['tests'],
|
|
24
|
-
}),
|
|
25
|
-
],
|
|
26
|
-
});
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import dts from 'vite-plugin-dts';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
build: {
|
|
7
|
+
lib: {
|
|
8
|
+
// Could also be a dictionary or array of multiple entry points
|
|
9
|
+
entry: resolve(__dirname, 'src/index.ts'),
|
|
10
|
+
name: 'buttplug',
|
|
11
|
+
// the proper extensions will be added
|
|
12
|
+
fileName: (format): string => {
|
|
13
|
+
if (format === 'umd') {
|
|
14
|
+
return 'buttplug.js';
|
|
15
|
+
}
|
|
16
|
+
return 'buttplug.mjs';
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
outDir: 'dist/web',
|
|
20
|
+
},
|
|
21
|
+
plugins: [
|
|
22
|
+
dts({
|
|
23
|
+
exclude: ['tests'],
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
});
|