buttplug 3.1.1 → 3.2.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 +13 -8
- package/CHANGELOG.md +23 -0
- package/README.md +24 -25
- package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.d.ts +13 -16
- package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js +23 -52
- package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js.map +1 -1
- package/dist/main/src/client/ButtplugClientConnectorException.d.ts +11 -11
- package/dist/main/src/client/ButtplugClientConnectorException.js +41 -41
- package/dist/main/src/client/ButtplugClientDevice.d.ts +67 -67
- package/dist/main/src/client/ButtplugClientDevice.js +325 -324
- package/dist/main/src/client/ButtplugClientDevice.js.map +1 -1
- package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.d.ts +18 -18
- package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.js +19 -19
- package/dist/main/src/client/Client.d.ts +41 -40
- package/dist/main/src/client/Client.js +241 -235
- package/dist/main/src/client/Client.js.map +1 -1
- package/dist/main/src/client/IButtplugClientConnector.d.ts +16 -16
- package/dist/main/src/client/IButtplugClientConnector.js +9 -9
- package/dist/main/src/core/Exceptions.d.ts +36 -36
- package/dist/main/src/core/Exceptions.js +106 -106
- package/dist/main/src/core/Logging.d.ts +112 -112
- package/dist/main/src/core/Logging.js +170 -170
- package/dist/main/src/core/Logging.js.map +1 -1
- package/dist/main/src/core/MessageUtils.d.ts +10 -9
- package/dist/main/src/core/MessageUtils.js +64 -58
- package/dist/main/src/core/MessageUtils.js.map +1 -1
- package/dist/main/src/core/Messages.d.ts +275 -275
- package/dist/main/src/core/Messages.js +429 -429
- package/dist/main/src/core/Messages.js.map +1 -1
- package/dist/main/src/index.d.ts +18 -18
- package/dist/main/src/index.js +34 -34
- package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.d.ts +22 -22
- package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.js +95 -95
- package/dist/main/src/utils/ButtplugMessageSorter.d.ts +19 -19
- package/dist/main/src/utils/ButtplugMessageSorter.js +81 -81
- package/dist/main/src/utils/Utils.d.ts +1 -1
- package/dist/main/src/utils/Utils.js +7 -7
- package/dist/web/buttplug.js +38 -7126
- package/dist/web/buttplug.mjs +2258 -0
- package/dist/web/client/ButtplugBrowserWebsocketClientConnector.d.ts +13 -0
- package/dist/web/client/ButtplugClientConnectorException.d.ts +11 -0
- package/dist/web/client/ButtplugClientDevice.d.ts +67 -0
- package/dist/web/client/ButtplugNodeWebsocketClientConnector.d.ts +18 -0
- package/dist/web/client/Client.d.ts +41 -0
- package/dist/web/client/IButtplugClientConnector.d.ts +16 -0
- package/dist/web/core/Exceptions.d.ts +36 -0
- package/dist/web/core/Logging.d.ts +112 -0
- package/dist/web/core/MessageUtils.d.ts +10 -0
- package/dist/web/core/Messages.d.ts +274 -0
- package/dist/web/index.d.ts +18 -0
- package/dist/web/utils/ButtplugBrowserWebsocketConnector.d.ts +22 -0
- package/dist/web/utils/ButtplugMessageSorter.d.ts +19 -0
- package/dist/web/utils/Utils.d.ts +1 -0
- package/package.json +23 -53
- package/src/client/ButtplugBrowserWebsocketClientConnector.ts +2 -24
- package/src/client/ButtplugClientDevice.ts +5 -4
- package/src/client/Client.ts +17 -10
- package/src/client/IButtplugClientConnector.ts +4 -4
- package/src/core/MessageUtils.ts +9 -1
- package/src/utils/ButtplugBrowserWebsocketConnector.ts +12 -12
- package/vite.config.ts +26 -0
- package/.github/FUNDING.yml +0 -5
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -17
- package/.github/workflows/docs.yaml +0 -29
- package/azure-pipelines.yml +0 -19
- package/dist/web/buttplug.min.js +0 -3
- package/dist/web/buttplug.min.js.LICENSE.txt +0 -31
- package/dist/web/buttplug.min.js.map +0 -1
- package/jest-puppeteer.config.js +0 -5
- package/rollup.config.js +0 -55
- package/util/convert_device_config.js +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "buttplug",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Buttplug Client Implementation for Typescript/Javascript",
|
|
5
5
|
"homepage": "https://github.com/buttplugio/buttplug-js/",
|
|
6
6
|
"repository": {
|
|
@@ -20,15 +20,10 @@
|
|
|
20
20
|
"types": "./dist/main/src/index.d.ts",
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "trash dist dist-bundle && yarn build:all",
|
|
23
|
-
"build:all": "yarn build:main && yarn build:web
|
|
23
|
+
"build:all": "yarn build:main && yarn build:web",
|
|
24
24
|
"build:main": "tsc -p tsconfig.json",
|
|
25
25
|
"build:doc": "typedoc --options typedocconfig.js --out doc ./src/index.ts",
|
|
26
|
-
"build:
|
|
27
|
-
"tslint": "tslint --project tsconfig.json --outputAbsolutePaths -c ../../tslint.json \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
28
|
-
"tslint:fix": "tslint --project tsconfig.json --outputAbsolutePaths -c ../../tslint.json --fix semicolon,comma,no-var-keyword,ordered-imports \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
29
|
-
"build:web": "webpack --config=build/webpack.base.js",
|
|
30
|
-
"build:web:release": "webpack --progress --hide-modules --config=build/webpack.production.js",
|
|
31
|
-
"build:analyze": "webpack --hide-modules --config=build/webpack.analyzer.js",
|
|
26
|
+
"build:web": "vite build",
|
|
32
27
|
"pretest": "yarn build:main",
|
|
33
28
|
"test": "jest tests/*",
|
|
34
29
|
"web-test": "jest web-tests/test-web-library.ts",
|
|
@@ -36,63 +31,38 @@
|
|
|
36
31
|
},
|
|
37
32
|
"dependencies": {
|
|
38
33
|
"class-transformer": "^0.5.1",
|
|
39
|
-
"eventemitter3": "^5.0.
|
|
34
|
+
"eventemitter3": "^5.0.1",
|
|
40
35
|
"reflect-metadata": "^0.1.13",
|
|
41
|
-
"ws": "^8.
|
|
36
|
+
"ws": "^8.14.2"
|
|
42
37
|
},
|
|
43
38
|
"devDependencies": {
|
|
44
39
|
"@types/commander": "^2.12.2",
|
|
45
|
-
"@types/expect-puppeteer": "^5.0.
|
|
46
|
-
"@types/jest": "^29.
|
|
47
|
-
"@types/jest-environment-puppeteer": "^5.0.
|
|
48
|
-
"@types/node": "^
|
|
40
|
+
"@types/expect-puppeteer": "^5.0.4",
|
|
41
|
+
"@types/jest": "^29.5.5",
|
|
42
|
+
"@types/jest-environment-puppeteer": "^5.0.4",
|
|
43
|
+
"@types/node": "^20.6.3",
|
|
49
44
|
"@types/uuid-parse": "^1.0.0",
|
|
50
|
-
"@types/ws": "^8.5.
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
52
|
-
"@typescript-eslint/parser": "^
|
|
45
|
+
"@types/ws": "^8.5.5",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^6.7.2",
|
|
47
|
+
"@typescript-eslint/parser": "^6.7.2",
|
|
53
48
|
"copyfiles": "^2.4.1",
|
|
54
49
|
"cross-env": "^7.0.3",
|
|
55
|
-
"eslint": "^8.
|
|
50
|
+
"eslint": "^8.50.0",
|
|
56
51
|
"eslint-plugin-node": "^11.1.0",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"jest-puppeteer": "^7.0.0",
|
|
62
|
-
"mock-socket": "^9.2.0",
|
|
63
|
-
"pkg": "^5.8.0",
|
|
64
|
-
"puppeteer": "^19.6.3",
|
|
65
|
-
"rollup": "^3.15.0",
|
|
66
|
-
"rollup-plugin-auto-external": "^2.0.0",
|
|
67
|
-
"rollup-plugin-commonjs": "^10.1.0",
|
|
68
|
-
"rollup-plugin-html": "^0.2.1",
|
|
69
|
-
"rollup-plugin-json": "^4.0.0",
|
|
70
|
-
"rollup-plugin-node-builtins": "^2.1.2",
|
|
71
|
-
"rollup-plugin-node-globals": "^1.4.0",
|
|
72
|
-
"rollup-plugin-node-resolve": "^5.2.0",
|
|
73
|
-
"rollup-plugin-postcss": "^4.0.2",
|
|
74
|
-
"rollup-plugin-postcss-modules": "^2.1.1",
|
|
75
|
-
"rollup-plugin-terser": "^5.3.0",
|
|
76
|
-
"rollup-plugin-typescript2": "^0.34.1",
|
|
77
|
-
"selfsigned": "^2.1.1",
|
|
78
|
-
"style-loader": "^3.3.1",
|
|
79
|
-
"terser": "^4.x",
|
|
80
|
-
"terser-webpack-plugin": "^4.x",
|
|
52
|
+
"gts": "^5.0.1",
|
|
53
|
+
"jest": "^29.7.0",
|
|
54
|
+
"mock-socket": "^9.3.1",
|
|
55
|
+
"pkg": "^5.8.1",
|
|
81
56
|
"tmp": "^0.2.1",
|
|
82
57
|
"trash": "^8.1.1",
|
|
83
58
|
"trash-cli": "^5.0.0",
|
|
84
|
-
"ts-jest": "^29.
|
|
85
|
-
"ts-loader": "^8.x",
|
|
59
|
+
"ts-jest": "^29.1.1",
|
|
86
60
|
"ts-node": "^10.9.1",
|
|
87
|
-
"tslib": "^2.
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"webpack": "^4.42.1",
|
|
93
|
-
"webpack-bundle-analyzer": "^3.6.1",
|
|
94
|
-
"webpack-cli": "^3.3.11",
|
|
95
|
-
"webpack-merge": "^4.2.2",
|
|
61
|
+
"tslib": "^2.6.2",
|
|
62
|
+
"typedoc": "^0.25.1",
|
|
63
|
+
"typescript": "^5.2.2",
|
|
64
|
+
"vite": "^4.4.9",
|
|
65
|
+
"vite-plugin-dts": "^3.5.4",
|
|
96
66
|
"yarn": "^1.22.19"
|
|
97
67
|
},
|
|
98
68
|
"jest": {
|
|
@@ -10,38 +10,16 @@
|
|
|
10
10
|
|
|
11
11
|
import { IButtplugClientConnector } from './IButtplugClientConnector';
|
|
12
12
|
import { ButtplugMessage } from '../core/Messages';
|
|
13
|
-
import { FromJSON } from '../core/MessageUtils';
|
|
14
|
-
import { ButtplugMessageSorter } from '../utils/ButtplugMessageSorter';
|
|
15
13
|
import { ButtplugBrowserWebsocketConnector } from '../utils/ButtplugBrowserWebsocketConnector';
|
|
16
14
|
|
|
17
15
|
export class ButtplugBrowserWebsocketClientConnector
|
|
18
16
|
extends ButtplugBrowserWebsocketConnector
|
|
19
17
|
implements IButtplugClientConnector
|
|
20
18
|
{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
public Send = async (msg: ButtplugMessage): Promise<ButtplugMessage> => {
|
|
19
|
+
public send = (msg: ButtplugMessage): void => {
|
|
24
20
|
if (!this.Connected) {
|
|
25
21
|
throw new Error('ButtplugClient not connected');
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
this.SendMessage(msg);
|
|
29
|
-
return await p;
|
|
23
|
+
this.sendMessage(msg);
|
|
30
24
|
};
|
|
31
|
-
|
|
32
|
-
protected ParseIncomingMessage = (event: MessageEvent) => {
|
|
33
|
-
if (typeof event.data === 'string') {
|
|
34
|
-
const msgs = FromJSON(event.data);
|
|
35
|
-
const emitMsgs = this._sorter.ParseIncomingMessages(msgs);
|
|
36
|
-
this.emit('message', emitMsgs);
|
|
37
|
-
} else if (event.data instanceof Blob) {
|
|
38
|
-
// No-op, buttplug only uses text formatting.
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
protected OnReaderLoad(event: Event) {
|
|
43
|
-
const msgs = FromJSON((event.target as FileReader).result);
|
|
44
|
-
const emitMsgs = this._sorter.ParseIncomingMessages(msgs);
|
|
45
|
-
this.emit('message', emitMsgs);
|
|
46
|
-
}
|
|
47
25
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
ButtplugMessageError,
|
|
15
15
|
} from '../core/Exceptions';
|
|
16
16
|
import { EventEmitter } from 'eventemitter3';
|
|
17
|
+
import { getMessageClassFromMessage } from '../core/MessageUtils';
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Represents an abstract device, capable of taking certain kinds of messages.
|
|
@@ -98,7 +99,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
98
99
|
msg: Messages.ButtplugDeviceMessage
|
|
99
100
|
): Promise<void> {
|
|
100
101
|
const response = await this.send(msg);
|
|
101
|
-
switch (response
|
|
102
|
+
switch (getMessageClassFromMessage(response)) {
|
|
102
103
|
case Messages.Ok:
|
|
103
104
|
return;
|
|
104
105
|
case Messages.Error:
|
|
@@ -209,7 +210,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
209
210
|
}
|
|
210
211
|
|
|
211
212
|
public get linearAttributes(): Messages.GenericDeviceMessageAttributes[] {
|
|
212
|
-
return this.messageAttributes.
|
|
213
|
+
return this.messageAttributes.LinearCmd ?? [];
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
public async linear(
|
|
@@ -245,7 +246,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
245
246
|
const response = await this.send(
|
|
246
247
|
new Messages.SensorReadCmd(this.index, sensorIndex, sensorType)
|
|
247
248
|
);
|
|
248
|
-
switch (response
|
|
249
|
+
switch (getMessageClassFromMessage(response)) {
|
|
249
250
|
case Messages.SensorReading:
|
|
250
251
|
return (response as Messages.SensorReading).Data;
|
|
251
252
|
case Messages.Error:
|
|
@@ -323,7 +324,7 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
323
324
|
const response = await this.send(
|
|
324
325
|
new Messages.RawReadCmd(this.index, endpoint, expectedLength, timeout)
|
|
325
326
|
);
|
|
326
|
-
switch (response
|
|
327
|
+
switch (getMessageClassFromMessage(response)) {
|
|
327
328
|
case Messages.RawReading:
|
|
328
329
|
return new Uint8Array((response as Messages.RawReading).Data);
|
|
329
330
|
case Messages.Error:
|
package/src/client/Client.ts
CHANGED
|
@@ -12,6 +12,8 @@ import { ButtplugLogger } from '../core/Logging';
|
|
|
12
12
|
import { EventEmitter } from 'eventemitter3';
|
|
13
13
|
import { ButtplugClientDevice } from './ButtplugClientDevice';
|
|
14
14
|
import { IButtplugClientConnector } from './IButtplugClientConnector';
|
|
15
|
+
import { ButtplugMessageSorter } from '../utils/ButtplugMessageSorter';
|
|
16
|
+
|
|
15
17
|
import * as Messages from '../core/Messages';
|
|
16
18
|
import {
|
|
17
19
|
ButtplugDeviceError,
|
|
@@ -20,6 +22,7 @@ import {
|
|
|
20
22
|
ButtplugMessageError,
|
|
21
23
|
} from '../core/Exceptions';
|
|
22
24
|
import { ButtplugClientConnectorException } from './ButtplugClientConnectorException';
|
|
25
|
+
import { getMessageClassFromMessage } from '../core/MessageUtils';
|
|
23
26
|
|
|
24
27
|
export class ButtplugClient extends EventEmitter {
|
|
25
28
|
protected _pingTimer: NodeJS.Timeout | null = null;
|
|
@@ -28,6 +31,7 @@ export class ButtplugClient extends EventEmitter {
|
|
|
28
31
|
protected _clientName: string;
|
|
29
32
|
protected _logger = ButtplugLogger.Logger;
|
|
30
33
|
protected _isScanning = false;
|
|
34
|
+
private _sorter: ButtplugMessageSorter = new ButtplugMessageSorter(true);
|
|
31
35
|
|
|
32
36
|
constructor(clientName = 'Generic Buttplug Client') {
|
|
33
37
|
super();
|
|
@@ -58,7 +62,7 @@ export class ButtplugClient extends EventEmitter {
|
|
|
58
62
|
this._logger.Info(
|
|
59
63
|
`ButtplugClient: Connecting using ${connector.constructor.name}`
|
|
60
64
|
);
|
|
61
|
-
await connector.
|
|
65
|
+
await connector.connect();
|
|
62
66
|
this._connector = connector;
|
|
63
67
|
this._connector.addListener('message', this.parseMessages);
|
|
64
68
|
this._connector.addListener('disconnect', this.disconnectHandler);
|
|
@@ -69,7 +73,7 @@ export class ButtplugClient extends EventEmitter {
|
|
|
69
73
|
this._logger.Debug('ButtplugClient: Disconnect called');
|
|
70
74
|
this.checkConnector();
|
|
71
75
|
await this.shutdownConnection();
|
|
72
|
-
await this._connector!.
|
|
76
|
+
await this._connector!.disconnect();
|
|
73
77
|
};
|
|
74
78
|
|
|
75
79
|
public startScanning = async () => {
|
|
@@ -112,8 +116,9 @@ export class ButtplugClient extends EventEmitter {
|
|
|
112
116
|
};
|
|
113
117
|
|
|
114
118
|
protected parseMessages = (msgs: Messages.ButtplugMessage[]) => {
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
const leftoverMsgs = this._sorter.ParseIncomingMessages(msgs);
|
|
120
|
+
for (const x of leftoverMsgs) {
|
|
121
|
+
switch (getMessageClassFromMessage(x)) {
|
|
117
122
|
case Messages.DeviceAdded: {
|
|
118
123
|
const addedMsg = x as Messages.DeviceAdded;
|
|
119
124
|
const addedDevice = ButtplugClientDevice.fromMsg(
|
|
@@ -150,7 +155,7 @@ export class ButtplugClient extends EventEmitter {
|
|
|
150
155
|
Messages.MESSAGE_SPEC_VERSION
|
|
151
156
|
)
|
|
152
157
|
);
|
|
153
|
-
switch (msg
|
|
158
|
+
switch (getMessageClassFromMessage(msg)) {
|
|
154
159
|
case Messages.ServerInfo: {
|
|
155
160
|
const serverinfo = msg as Messages.ServerInfo;
|
|
156
161
|
this._logger.Info(
|
|
@@ -160,7 +165,7 @@ export class ButtplugClient extends EventEmitter {
|
|
|
160
165
|
const ping = serverinfo.MaxPingTime;
|
|
161
166
|
if (serverinfo.MessageVersion < Messages.MESSAGE_SPEC_VERSION) {
|
|
162
167
|
// Disconnect and throw an exception explaining the version mismatch problem.
|
|
163
|
-
await this._connector!.
|
|
168
|
+
await this._connector!.disconnect();
|
|
164
169
|
throw ButtplugError.LogAndError(
|
|
165
170
|
ButtplugInitError,
|
|
166
171
|
this._logger,
|
|
@@ -186,7 +191,7 @@ export class ButtplugClient extends EventEmitter {
|
|
|
186
191
|
// Disconnect and throw an exception with the error message we got back.
|
|
187
192
|
// This will usually only error out if we have a version mismatch that the
|
|
188
193
|
// server has detected.
|
|
189
|
-
await this._connector!.
|
|
194
|
+
await this._connector!.disconnect();
|
|
190
195
|
const err = msg as Messages.Error;
|
|
191
196
|
throw ButtplugError.LogAndError(
|
|
192
197
|
ButtplugInitError,
|
|
@@ -231,7 +236,9 @@ export class ButtplugClient extends EventEmitter {
|
|
|
231
236
|
msg: Messages.ButtplugMessage
|
|
232
237
|
): Promise<Messages.ButtplugMessage> {
|
|
233
238
|
this.checkConnector();
|
|
234
|
-
|
|
239
|
+
const p = this._sorter.PrepareOutgoingMessage(msg);
|
|
240
|
+
await this._connector!.send(msg);
|
|
241
|
+
return await p;
|
|
235
242
|
}
|
|
236
243
|
|
|
237
244
|
protected checkConnector() {
|
|
@@ -246,7 +253,7 @@ export class ButtplugClient extends EventEmitter {
|
|
|
246
253
|
msg: Messages.ButtplugMessage
|
|
247
254
|
): Promise<void> => {
|
|
248
255
|
const response = await this.sendMessage(msg);
|
|
249
|
-
switch (response
|
|
256
|
+
switch (getMessageClassFromMessage(response)) {
|
|
250
257
|
case Messages.Ok:
|
|
251
258
|
return;
|
|
252
259
|
case Messages.Error:
|
|
@@ -255,7 +262,7 @@ export class ButtplugClient extends EventEmitter {
|
|
|
255
262
|
throw ButtplugError.LogAndError(
|
|
256
263
|
ButtplugMessageError,
|
|
257
264
|
this._logger,
|
|
258
|
-
`Message type ${response
|
|
265
|
+
`Message type ${getMessageClassFromMessage(response)!.constructor} not handled by SendMsgExpectOk`
|
|
259
266
|
);
|
|
260
267
|
}
|
|
261
268
|
};
|
|
@@ -10,9 +10,9 @@ import { ButtplugMessage } from '../core/Messages';
|
|
|
10
10
|
import { EventEmitter } from 'eventemitter3';
|
|
11
11
|
|
|
12
12
|
export interface IButtplugClientConnector extends EventEmitter {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
connect: () => Promise<void>;
|
|
14
|
+
disconnect: () => Promise<void>;
|
|
15
|
+
initialize: () => Promise<void>;
|
|
16
|
+
send: (msg: ButtplugMessage) => void;
|
|
17
17
|
readonly Connected: boolean;
|
|
18
18
|
}
|
package/src/core/MessageUtils.ts
CHANGED
|
@@ -21,7 +21,15 @@ function getMessageClass(
|
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function
|
|
24
|
+
export function getMessageClassFromMessage(
|
|
25
|
+
msg: Messages.ButtplugMessage
|
|
26
|
+
): (new (...args: unknown[]) => Messages.ButtplugMessage) | null {
|
|
27
|
+
// Making the bold assumption all message classes have the Name static. Should define a
|
|
28
|
+
// requirement for this in the abstract class.
|
|
29
|
+
return getMessageClass(Object.getPrototypeOf(msg).constructor.Name);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function fromJSON(str): Messages.ButtplugMessage[] {
|
|
25
33
|
const msgarray: object[] = JSON.parse(str);
|
|
26
34
|
const msgs: Messages.ButtplugMessage[] = [];
|
|
27
35
|
for (const x of Array.from(msgarray)) {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { EventEmitter } from 'eventemitter3';
|
|
12
12
|
import { ButtplugMessage } from '../core/Messages';
|
|
13
|
-
import {
|
|
13
|
+
import { fromJSON } from '../core/MessageUtils';
|
|
14
14
|
|
|
15
15
|
export class ButtplugBrowserWebsocketConnector extends EventEmitter {
|
|
16
16
|
protected _ws: WebSocket | undefined;
|
|
@@ -24,7 +24,7 @@ export class ButtplugBrowserWebsocketConnector extends EventEmitter {
|
|
|
24
24
|
return this._ws !== undefined;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
public
|
|
27
|
+
public connect = async (): Promise<void> => {
|
|
28
28
|
const ws = new (this._websocketConstructor ?? WebSocket)(this._url);
|
|
29
29
|
let res;
|
|
30
30
|
let rej;
|
|
@@ -39,12 +39,12 @@ export class ButtplugBrowserWebsocketConnector extends EventEmitter {
|
|
|
39
39
|
ws.addEventListener('open', async () => {
|
|
40
40
|
this._ws = ws;
|
|
41
41
|
try {
|
|
42
|
-
await this.
|
|
42
|
+
await this.initialize();
|
|
43
43
|
this._ws.addEventListener('message', (msg) => {
|
|
44
|
-
this.
|
|
44
|
+
this.parseIncomingMessage(msg);
|
|
45
45
|
});
|
|
46
46
|
this._ws.removeEventListener('close', conErrorCallback);
|
|
47
|
-
this._ws.addEventListener('close', this.
|
|
47
|
+
this._ws.addEventListener('close', this.disconnect);
|
|
48
48
|
// TODO This doesn't really communicate the chain why our initializer failed
|
|
49
49
|
res();
|
|
50
50
|
} catch (e) {
|
|
@@ -56,7 +56,7 @@ export class ButtplugBrowserWebsocketConnector extends EventEmitter {
|
|
|
56
56
|
return p;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
public
|
|
59
|
+
public disconnect = async (): Promise<void> => {
|
|
60
60
|
if (!this.Connected) {
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
@@ -65,28 +65,28 @@ export class ButtplugBrowserWebsocketConnector extends EventEmitter {
|
|
|
65
65
|
this.emit('disconnect');
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
public
|
|
68
|
+
public sendMessage(msg: ButtplugMessage) {
|
|
69
69
|
if (!this.Connected) {
|
|
70
70
|
throw new Error('ButtplugBrowserWebsocketConnector not connected');
|
|
71
71
|
}
|
|
72
72
|
this._ws!.send('[' + msg.toJSON() + ']');
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
public
|
|
75
|
+
public initialize = async (): Promise<void> => {
|
|
76
76
|
return Promise.resolve();
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
-
protected
|
|
79
|
+
protected parseIncomingMessage(event: MessageEvent) {
|
|
80
80
|
if (typeof event.data === 'string') {
|
|
81
|
-
const msgs =
|
|
81
|
+
const msgs = fromJSON(event.data);
|
|
82
82
|
this.emit('message', msgs);
|
|
83
83
|
} else if (event.data instanceof Blob) {
|
|
84
84
|
// No-op, we only use text message types.
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
protected
|
|
89
|
-
const msgs =
|
|
88
|
+
protected onReaderLoad(event: Event) {
|
|
89
|
+
const msgs = fromJSON((event.target as FileReader).result);
|
|
90
90
|
this.emit('message', msgs);
|
|
91
91
|
}
|
|
92
92
|
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +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
|
+
});
|
package/.github/FUNDING.yml
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Bug report
|
|
3
|
-
about: Issues related to messages or system architecture
|
|
4
|
-
title: ''
|
|
5
|
-
labels: bug
|
|
6
|
-
assignees: ''
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
**Describe the bug**
|
|
11
|
-
A clear and concise description of what the bug is. Remember, this should only pertain to bugs at the protocol or general architecture level. Library or application specific bugs should be files in their respective repos.
|
|
12
|
-
|
|
13
|
-
**Expected behavior**
|
|
14
|
-
A clear and concise description of what you expected to happen.
|
|
15
|
-
|
|
16
|
-
**Additional context**
|
|
17
|
-
Add any other context about the problem here.
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
name: Doc Build
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- master
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
publish-docs:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v3
|
|
13
|
-
- name: Set Node.js 18.x
|
|
14
|
-
uses: actions/setup-node@v3
|
|
15
|
-
with:
|
|
16
|
-
node-version: 18.x
|
|
17
|
-
- name: Run install
|
|
18
|
-
uses: borales/actions-yarn@v4
|
|
19
|
-
with:
|
|
20
|
-
cmd: install # will run `yarn install` command
|
|
21
|
-
- name: Build production bundle
|
|
22
|
-
uses: borales/actions-yarn@v4
|
|
23
|
-
with:
|
|
24
|
-
cmd: build:doc
|
|
25
|
-
- name: Deploy
|
|
26
|
-
uses: peaceiris/actions-gh-pages@v3
|
|
27
|
-
with:
|
|
28
|
-
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
29
|
-
publish_dir: doc/
|
package/azure-pipelines.yml
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
trigger:
|
|
2
|
-
- master
|
|
3
|
-
- dev
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
# - job: "MacOS"
|
|
7
|
-
# pool:
|
|
8
|
-
# vmImage: 'macos-10.13'
|
|
9
|
-
# steps:
|
|
10
|
-
# - template: 'build/build-test-freeze.yml'
|
|
11
|
-
# parameters:
|
|
12
|
-
# platform: "macos-x64"
|
|
13
|
-
- job: "Linux"
|
|
14
|
-
pool:
|
|
15
|
-
vmImage: 'ubuntu-16.04'
|
|
16
|
-
steps:
|
|
17
|
-
- template: 'build/build-test-freeze.yml'
|
|
18
|
-
parameters:
|
|
19
|
-
platform: "linux-x64"
|