buttplug 3.1.1 → 3.2.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.
Files changed (68) hide show
  1. package/.eslintrc.js +13 -8
  2. package/CHANGELOG.md +16 -0
  3. package/README.md +24 -25
  4. package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.d.ts +13 -16
  5. package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js +23 -52
  6. package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js.map +1 -1
  7. package/dist/main/src/client/ButtplugClientConnectorException.d.ts +11 -11
  8. package/dist/main/src/client/ButtplugClientConnectorException.js +41 -41
  9. package/dist/main/src/client/ButtplugClientDevice.d.ts +67 -67
  10. package/dist/main/src/client/ButtplugClientDevice.js +324 -324
  11. package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.d.ts +18 -18
  12. package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.js +19 -19
  13. package/dist/main/src/client/Client.d.ts +41 -40
  14. package/dist/main/src/client/Client.js +240 -235
  15. package/dist/main/src/client/Client.js.map +1 -1
  16. package/dist/main/src/client/IButtplugClientConnector.d.ts +16 -16
  17. package/dist/main/src/client/IButtplugClientConnector.js +9 -9
  18. package/dist/main/src/core/Exceptions.d.ts +36 -36
  19. package/dist/main/src/core/Exceptions.js +106 -106
  20. package/dist/main/src/core/Logging.d.ts +112 -112
  21. package/dist/main/src/core/Logging.js +170 -170
  22. package/dist/main/src/core/Logging.js.map +1 -1
  23. package/dist/main/src/core/MessageUtils.d.ts +9 -9
  24. package/dist/main/src/core/MessageUtils.js +58 -58
  25. package/dist/main/src/core/Messages.d.ts +275 -275
  26. package/dist/main/src/core/Messages.js +429 -429
  27. package/dist/main/src/core/Messages.js.map +1 -1
  28. package/dist/main/src/index.d.ts +18 -18
  29. package/dist/main/src/index.js +34 -34
  30. package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.d.ts +22 -22
  31. package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.js +95 -95
  32. package/dist/main/src/utils/ButtplugMessageSorter.d.ts +19 -19
  33. package/dist/main/src/utils/ButtplugMessageSorter.js +81 -81
  34. package/dist/main/src/utils/Utils.d.ts +1 -1
  35. package/dist/main/src/utils/Utils.js +7 -7
  36. package/dist/web/buttplug.js +38 -7126
  37. package/dist/web/buttplug.mjs +2254 -0
  38. package/dist/web/client/ButtplugBrowserWebsocketClientConnector.d.ts +13 -0
  39. package/dist/web/client/ButtplugClientConnectorException.d.ts +11 -0
  40. package/dist/web/client/ButtplugClientDevice.d.ts +67 -0
  41. package/dist/web/client/ButtplugNodeWebsocketClientConnector.d.ts +18 -0
  42. package/dist/web/client/Client.d.ts +41 -0
  43. package/dist/web/client/IButtplugClientConnector.d.ts +16 -0
  44. package/dist/web/core/Exceptions.d.ts +36 -0
  45. package/dist/web/core/Logging.d.ts +112 -0
  46. package/dist/web/core/MessageUtils.d.ts +9 -0
  47. package/dist/web/core/Messages.d.ts +274 -0
  48. package/dist/web/index.d.ts +18 -0
  49. package/dist/web/utils/ButtplugBrowserWebsocketConnector.d.ts +22 -0
  50. package/dist/web/utils/ButtplugMessageSorter.d.ts +19 -0
  51. package/dist/web/utils/Utils.d.ts +1 -0
  52. package/package.json +23 -53
  53. package/src/client/ButtplugBrowserWebsocketClientConnector.ts +2 -24
  54. package/src/client/ButtplugClientDevice.ts +1 -1
  55. package/src/client/Client.ts +12 -6
  56. package/src/client/IButtplugClientConnector.ts +4 -4
  57. package/src/core/MessageUtils.ts +1 -1
  58. package/src/utils/ButtplugBrowserWebsocketConnector.ts +12 -12
  59. package/vite.config.ts +26 -0
  60. package/.github/FUNDING.yml +0 -5
  61. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -17
  62. package/.github/workflows/docs.yaml +0 -29
  63. package/azure-pipelines.yml +0 -19
  64. package/dist/web/buttplug.min.js +0 -3
  65. package/dist/web/buttplug.min.js.LICENSE.txt +0 -31
  66. package/dist/web/buttplug.min.js.map +0 -1
  67. package/jest-puppeteer.config.js +0 -5
  68. package/rollup.config.js +0 -55
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "buttplug",
3
- "version": "3.1.1",
3
+ "version": "3.2.0",
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 && yarn build:web:release",
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:rollup": "rollup -c",
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.0",
34
+ "eventemitter3": "^5.0.1",
40
35
  "reflect-metadata": "^0.1.13",
41
- "ws": "^8.12.0"
36
+ "ws": "^8.14.2"
42
37
  },
43
38
  "devDependencies": {
44
39
  "@types/commander": "^2.12.2",
45
- "@types/expect-puppeteer": "^5.0.2",
46
- "@types/jest": "^29.4.0",
47
- "@types/jest-environment-puppeteer": "^5.0.3",
48
- "@types/node": "^18.13.0",
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.4",
51
- "@typescript-eslint/eslint-plugin": "^5.51.0",
52
- "@typescript-eslint/parser": "^5.51.0",
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.34.0",
50
+ "eslint": "^8.50.0",
56
51
  "eslint-plugin-node": "^11.1.0",
57
- "eslint-plugin-prettier": "^4.2.1",
58
- "fork-ts-checker-webpack-plugin": "^7.3.0",
59
- "gts": "^3.1.1",
60
- "jest": "^29.4.2",
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.0.5",
85
- "ts-loader": "^8.x",
59
+ "ts-jest": "^29.1.1",
86
60
  "ts-node": "^10.9.1",
87
- "tslib": "^2.5.0",
88
- "tslint": "^6.1.0",
89
- "typedoc": "^0.23.25",
90
- "typescript": "^4.9.5",
91
- "url-loader": "^4.1.1",
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
- private _sorter: ButtplugMessageSorter = new ButtplugMessageSorter(true);
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
- const p = this._sorter.PrepareOutgoingMessage(msg);
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
  }
@@ -209,7 +209,7 @@ export class ButtplugClientDevice extends EventEmitter {
209
209
  }
210
210
 
211
211
  public get linearAttributes(): Messages.GenericDeviceMessageAttributes[] {
212
- return this.messageAttributes.RotateCmd ?? [];
212
+ return this.messageAttributes.LinearCmd ?? [];
213
213
  }
214
214
 
215
215
  public async linear(
@@ -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,
@@ -28,6 +30,7 @@ export class ButtplugClient extends EventEmitter {
28
30
  protected _clientName: string;
29
31
  protected _logger = ButtplugLogger.Logger;
30
32
  protected _isScanning = false;
33
+ private _sorter: ButtplugMessageSorter = new ButtplugMessageSorter(true);
31
34
 
32
35
  constructor(clientName = 'Generic Buttplug Client') {
33
36
  super();
@@ -58,7 +61,7 @@ export class ButtplugClient extends EventEmitter {
58
61
  this._logger.Info(
59
62
  `ButtplugClient: Connecting using ${connector.constructor.name}`
60
63
  );
61
- await connector.Connect();
64
+ await connector.connect();
62
65
  this._connector = connector;
63
66
  this._connector.addListener('message', this.parseMessages);
64
67
  this._connector.addListener('disconnect', this.disconnectHandler);
@@ -69,7 +72,7 @@ export class ButtplugClient extends EventEmitter {
69
72
  this._logger.Debug('ButtplugClient: Disconnect called');
70
73
  this.checkConnector();
71
74
  await this.shutdownConnection();
72
- await this._connector!.Disconnect();
75
+ await this._connector!.disconnect();
73
76
  };
74
77
 
75
78
  public startScanning = async () => {
@@ -112,7 +115,8 @@ export class ButtplugClient extends EventEmitter {
112
115
  };
113
116
 
114
117
  protected parseMessages = (msgs: Messages.ButtplugMessage[]) => {
115
- for (const x of msgs) {
118
+ const leftoverMsgs = this._sorter.ParseIncomingMessages(msgs);
119
+ for (const x of leftoverMsgs) {
116
120
  switch (x.constructor) {
117
121
  case Messages.DeviceAdded: {
118
122
  const addedMsg = x as Messages.DeviceAdded;
@@ -160,7 +164,7 @@ export class ButtplugClient extends EventEmitter {
160
164
  const ping = serverinfo.MaxPingTime;
161
165
  if (serverinfo.MessageVersion < Messages.MESSAGE_SPEC_VERSION) {
162
166
  // Disconnect and throw an exception explaining the version mismatch problem.
163
- await this._connector!.Disconnect();
167
+ await this._connector!.disconnect();
164
168
  throw ButtplugError.LogAndError(
165
169
  ButtplugInitError,
166
170
  this._logger,
@@ -186,7 +190,7 @@ export class ButtplugClient extends EventEmitter {
186
190
  // Disconnect and throw an exception with the error message we got back.
187
191
  // This will usually only error out if we have a version mismatch that the
188
192
  // server has detected.
189
- await this._connector!.Disconnect();
193
+ await this._connector!.disconnect();
190
194
  const err = msg as Messages.Error;
191
195
  throw ButtplugError.LogAndError(
192
196
  ButtplugInitError,
@@ -231,7 +235,9 @@ export class ButtplugClient extends EventEmitter {
231
235
  msg: Messages.ButtplugMessage
232
236
  ): Promise<Messages.ButtplugMessage> {
233
237
  this.checkConnector();
234
- return await this._connector!.Send(msg);
238
+ const p = this._sorter.PrepareOutgoingMessage(msg);
239
+ await this._connector!.send(msg);
240
+ return await p;
235
241
  }
236
242
 
237
243
  protected checkConnector() {
@@ -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
- Connect: () => Promise<void>;
14
- Disconnect: () => Promise<void>;
15
- Initialize: () => Promise<void>;
16
- Send: (msg: ButtplugMessage) => Promise<ButtplugMessage>;
13
+ connect: () => Promise<void>;
14
+ disconnect: () => Promise<void>;
15
+ initialize: () => Promise<void>;
16
+ send: (msg: ButtplugMessage) => void;
17
17
  readonly Connected: boolean;
18
18
  }
@@ -21,7 +21,7 @@ function getMessageClass(
21
21
  return null;
22
22
  }
23
23
 
24
- export function FromJSON(str): Messages.ButtplugMessage[] {
24
+ export function fromJSON(str): Messages.ButtplugMessage[] {
25
25
  const msgarray: object[] = JSON.parse(str);
26
26
  const msgs: Messages.ButtplugMessage[] = [];
27
27
  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 { FromJSON } from '../core/MessageUtils';
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 Connect = async (): Promise<void> => {
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.Initialize();
42
+ await this.initialize();
43
43
  this._ws.addEventListener('message', (msg) => {
44
- this.ParseIncomingMessage(msg);
44
+ this.parseIncomingMessage(msg);
45
45
  });
46
46
  this._ws.removeEventListener('close', conErrorCallback);
47
- this._ws.addEventListener('close', this.Disconnect);
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 Disconnect = async (): Promise<void> => {
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 SendMessage(msg: ButtplugMessage) {
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 Initialize = async (): Promise<void> => {
75
+ public initialize = async (): Promise<void> => {
76
76
  return Promise.resolve();
77
77
  };
78
78
 
79
- protected ParseIncomingMessage(event: MessageEvent) {
79
+ protected parseIncomingMessage(event: MessageEvent) {
80
80
  if (typeof event.data === 'string') {
81
- const msgs = FromJSON(event.data);
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 OnReaderLoad(event: Event) {
89
- const msgs = FromJSON((event.target as FileReader).result);
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
+ });
@@ -1,5 +0,0 @@
1
- # These are supported funding model platforms
2
-
3
- github: qdot
4
- patreon: qdot
5
- ko_fi: qdot76367
@@ -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/
@@ -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"