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.
Files changed (179) hide show
  1. package/.eslintrc.js +25 -25
  2. package/.jscsrc +2 -2
  3. package/.jshintrc +5 -5
  4. package/.prettierrc.json +3 -3
  5. package/.yarnrc.yml +5 -5
  6. package/CHANGELOG.md +591 -577
  7. package/LICENSE +27 -27
  8. package/README.md +105 -97
  9. package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js +6 -9
  10. package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js.map +1 -1
  11. package/dist/main/src/client/{Client.d.ts → ButtplugClient.d.ts} +3 -4
  12. package/dist/main/src/client/ButtplugClient.js +232 -0
  13. package/dist/main/src/client/ButtplugClient.js.map +1 -0
  14. package/dist/main/src/client/ButtplugClientConnectorException.js +17 -7
  15. package/dist/main/src/client/ButtplugClientConnectorException.js.map +1 -1
  16. package/dist/main/src/client/ButtplugClientDevice.d.ts +13 -28
  17. package/dist/main/src/client/ButtplugClientDevice.js +105 -247
  18. package/dist/main/src/client/ButtplugClientDevice.js.map +1 -1
  19. package/dist/main/src/client/ButtplugClientDeviceCommand.d.ts +42 -0
  20. package/dist/main/src/client/ButtplugClientDeviceCommand.js +105 -0
  21. package/dist/main/src/client/ButtplugClientDeviceCommand.js.map +1 -0
  22. package/dist/main/src/client/ButtplugClientDeviceFeature.d.ts +18 -0
  23. package/dist/main/src/client/ButtplugClientDeviceFeature.js +166 -0
  24. package/dist/main/src/client/ButtplugClientDeviceFeature.js.map +1 -0
  25. package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.d.ts +1 -8
  26. package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.js +1 -4
  27. package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.js.map +1 -1
  28. package/dist/main/src/core/Exceptions.js +27 -9
  29. package/dist/main/src/core/Exceptions.js.map +1 -1
  30. package/dist/main/src/core/Logging.js +12 -6
  31. package/dist/main/src/core/Logging.js.map +1 -1
  32. package/dist/main/src/core/Messages.d.ts +119 -230
  33. package/dist/main/src/core/Messages.js +50 -404
  34. package/dist/main/src/core/Messages.js.map +1 -1
  35. package/dist/main/src/index.d.ts +2 -2
  36. package/dist/main/src/index.js +4 -2
  37. package/dist/main/src/index.js.map +1 -1
  38. package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.js +40 -52
  39. package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.js.map +1 -1
  40. package/dist/main/src/utils/ButtplugMessageSorter.js +27 -15
  41. package/dist/main/src/utils/ButtplugMessageSorter.js.map +1 -1
  42. package/dist/main/src/utils/Utils.js +1 -2
  43. package/dist/main/src/utils/Utils.js.map +1 -1
  44. package/dist/web/buttplug.js +1 -38
  45. package/dist/web/buttplug.mjs +595 -1984
  46. package/dist/web/client/ButtplugBrowserWebsocketClientConnector.d.ts +0 -7
  47. package/dist/web/client/{Client.d.ts → ButtplugClient.d.ts} +3 -11
  48. package/dist/web/client/ButtplugClientConnectorException.d.ts +0 -7
  49. package/dist/web/client/ButtplugClientDevice.d.ts +14 -29
  50. package/dist/web/client/ButtplugClientDeviceCommand.d.ts +42 -0
  51. package/dist/web/client/ButtplugClientDeviceFeature.d.ts +18 -0
  52. package/dist/web/client/ButtplugNodeWebsocketClientConnector.d.ts +1 -15
  53. package/dist/web/client/IButtplugClientConnector.d.ts +0 -7
  54. package/dist/web/core/Exceptions.d.ts +1 -1
  55. package/dist/web/core/Logging.d.ts +0 -7
  56. package/dist/web/core/Messages.d.ts +119 -229
  57. package/dist/web/index.d.ts +2 -2
  58. package/dist/web/utils/ButtplugBrowserWebsocketConnector.d.ts +0 -7
  59. package/examples/node/SYNC_MANIFEST.md +105 -0
  60. package/examples/node/application-example.ts +213 -0
  61. package/examples/node/async-example.ts +124 -0
  62. package/examples/node/connection-example.ts +76 -0
  63. package/examples/node/device-control-example.ts +131 -0
  64. package/examples/node/device-enumeration-example.ts +86 -0
  65. package/examples/node/device-info-example.ts +131 -0
  66. package/examples/node/errors-example.ts +166 -0
  67. package/examples/node/package-lock.json +281 -0
  68. package/examples/node/package.json +25 -0
  69. package/examples/node/remote-connector-example.ts +84 -0
  70. package/examples/node/tsconfig.json +14 -0
  71. package/examples/web/application-example.js +197 -0
  72. package/examples/web/async-example.js +90 -0
  73. package/examples/web/device-control-example.js +87 -0
  74. package/examples/web/device-enumeration-example.js +49 -0
  75. package/examples/web/device-info-example.js +100 -0
  76. package/examples/web/errors-example.js +110 -0
  77. package/examples/web/index.html +55 -0
  78. package/examples/web/logging.js +42 -0
  79. package/examples/web/ping-timeout-example.js +59 -0
  80. package/examples/web/remote-connector-example.js +68 -0
  81. package/node-test.js +24 -0
  82. package/node-test.ts +23 -5
  83. package/package.json +85 -87
  84. package/src/client/ButtplugBrowserWebsocketClientConnector.ts +25 -25
  85. package/src/client/ButtplugClient.ts +242 -0
  86. package/src/client/ButtplugClientConnectorException.ts +16 -16
  87. package/src/client/ButtplugClientDevice.ts +178 -401
  88. package/src/client/ButtplugClientDeviceCommand.ts +112 -0
  89. package/src/client/ButtplugClientDeviceFeature.ts +138 -0
  90. package/src/client/ButtplugNodeWebsocketClientConnector.ts +17 -17
  91. package/src/client/IButtplugClientConnector.ts +18 -18
  92. package/src/core/Exceptions.ts +107 -101
  93. package/src/core/Logging.ts +197 -197
  94. package/src/core/Messages.ts +205 -480
  95. package/src/core/index.d.ts +4 -4
  96. package/src/index.ts +21 -19
  97. package/src/utils/ButtplugBrowserWebsocketConnector.ts +89 -89
  98. package/src/utils/ButtplugMessageSorter.ts +66 -65
  99. package/src/utils/Utils.ts +3 -3
  100. package/tsconfig.json +22 -22
  101. package/tsfmt.json +14 -14
  102. package/tslint.json +27 -27
  103. package/typedocconfig.js +6 -6
  104. package/vite.config.ts +26 -26
  105. package/dist/main/src/client/Client.js +0 -242
  106. package/dist/main/src/client/Client.js.map +0 -1
  107. package/dist/main/src/core/MessageUtils.d.ts +0 -10
  108. package/dist/main/src/core/MessageUtils.js +0 -65
  109. package/dist/main/src/core/MessageUtils.js.map +0 -1
  110. package/dist/web/core/MessageUtils.d.ts +0 -10
  111. package/doc/.nojekyll +0 -1
  112. package/doc/assets/highlight.css +0 -22
  113. package/doc/assets/main.js +0 -58
  114. package/doc/assets/search.js +0 -1
  115. package/doc/assets/style.css +0 -1280
  116. package/doc/classes/ButtplugBrowserWebsocketClientConnector.html +0 -234
  117. package/doc/classes/ButtplugClient.html +0 -331
  118. package/doc/classes/ButtplugClientConnectorException.html +0 -216
  119. package/doc/classes/ButtplugClientDevice.html +0 -489
  120. package/doc/classes/ButtplugDeviceError.html +0 -218
  121. package/doc/classes/ButtplugDeviceMessage.html +0 -165
  122. package/doc/classes/ButtplugError.html +0 -220
  123. package/doc/classes/ButtplugInitError.html +0 -218
  124. package/doc/classes/ButtplugLogger.html +0 -288
  125. package/doc/classes/ButtplugMessage.html +0 -147
  126. package/doc/classes/ButtplugMessageError.html +0 -218
  127. package/doc/classes/ButtplugMessageSorter.html +0 -128
  128. package/doc/classes/ButtplugNodeWebsocketClientConnector.html +0 -239
  129. package/doc/classes/ButtplugPingError.html +0 -218
  130. package/doc/classes/ButtplugSystemMessage.html +0 -150
  131. package/doc/classes/ButtplugUnknownError.html +0 -218
  132. package/doc/classes/DeviceAdded.html +0 -186
  133. package/doc/classes/DeviceInfo.html +0 -114
  134. package/doc/classes/DeviceList.html +0 -160
  135. package/doc/classes/DeviceRemoved.html +0 -158
  136. package/doc/classes/Error.html +0 -179
  137. package/doc/classes/GenericDeviceMessageAttributes.html +0 -107
  138. package/doc/classes/GenericMessageSubcommand.html +0 -90
  139. package/doc/classes/LinearCmd.html +0 -187
  140. package/doc/classes/LogMessage.html +0 -134
  141. package/doc/classes/MessageAttributes.html +0 -160
  142. package/doc/classes/Ok.html +0 -151
  143. package/doc/classes/Ping.html +0 -151
  144. package/doc/classes/RawDeviceMessageAttributes.html +0 -86
  145. package/doc/classes/RawReadCmd.html +0 -188
  146. package/doc/classes/RawReading.html +0 -179
  147. package/doc/classes/RawSubscribeCmd.html +0 -170
  148. package/doc/classes/RawUnsubscribeCmd.html +0 -170
  149. package/doc/classes/RawWriteCmd.html +0 -188
  150. package/doc/classes/RequestDeviceList.html +0 -151
  151. package/doc/classes/RequestServerInfo.html +0 -169
  152. package/doc/classes/RotateCmd.html +0 -187
  153. package/doc/classes/RotateSubcommand.html +0 -108
  154. package/doc/classes/ScalarCmd.html +0 -170
  155. package/doc/classes/ScalarSubcommand.html +0 -108
  156. package/doc/classes/ScanningFinished.html +0 -146
  157. package/doc/classes/SensorDeviceMessageAttributes.html +0 -107
  158. package/doc/classes/SensorReadCmd.html +0 -179
  159. package/doc/classes/SensorReading.html +0 -188
  160. package/doc/classes/ServerInfo.html +0 -178
  161. package/doc/classes/StartScanning.html +0 -151
  162. package/doc/classes/StopAllDevices.html +0 -151
  163. package/doc/classes/StopDeviceCmd.html +0 -161
  164. package/doc/classes/StopScanning.html +0 -151
  165. package/doc/classes/VectorSubcommand.html +0 -108
  166. package/doc/enums/ActuatorType.html +0 -104
  167. package/doc/enums/ButtplugLogLevel.html +0 -97
  168. package/doc/enums/ErrorClass.html +0 -90
  169. package/doc/enums/SensorType.html +0 -90
  170. package/doc/functions/FromJSON.html +0 -113
  171. package/doc/index.html +0 -184
  172. package/doc/interfaces/IButtplugClientConnector.html +0 -137
  173. package/doc/modules.html +0 -176
  174. package/doc/variables/DEFAULT_MESSAGE_ID.html +0 -104
  175. package/doc/variables/MAX_ID.html +0 -104
  176. package/doc/variables/MESSAGE_SPEC_VERSION.html +0 -104
  177. package/doc/variables/SYSTEM_MESSAGE_ID.html +0 -104
  178. package/src/client/Client.ts +0 -276
  179. package/src/core/MessageUtils.ts +0 -48
@@ -0,0 +1,110 @@
1
+ // Buttplug Web - Error Handling Example
2
+ //
3
+ // This example demonstrates the different error types in Buttplug
4
+ // and how to handle them. This is a reference for error handling patterns.
5
+ //
6
+ // Include Buttplug via CDN:
7
+ // <script src="https://cdn.jsdelivr.net/npm/buttplug@4.0.0/dist/web/buttplug.min.js"></script>
8
+
9
+ // All Buttplug errors inherit from ButtplugError.
10
+ // Here's the hierarchy:
11
+ //
12
+ // ButtplugError (base class)
13
+ // +-- ButtplugClientConnectorException - Connection/transport issues
14
+ // +-- ButtplugInitError - Client/server version mismatch
15
+ // +-- ButtplugDeviceError - Device communication errors
16
+ // +-- ButtplugMessageError - Invalid message format/content
17
+ // +-- ButtplugPingError - Server ping timeout
18
+
19
+ function handleButtplugError(e) {
20
+ if (e instanceof Buttplug.ButtplugClientConnectorException) {
21
+ // The connector couldn't establish or maintain connection.
22
+ // Causes: server not running, wrong address, network issues,
23
+ // SSL/TLS problems, connection dropped.
24
+ console.log(`[Connector Error] ${e.message}`);
25
+ console.log("Check that the server is running and accessible.");
26
+ } else if (e instanceof Buttplug.ButtplugInitError) {
27
+ // Client and server couldn't agree on protocol version.
28
+ // Usually means you need to upgrade client or server.
29
+ console.log(`[Init/Handshake Error] ${e.message}`);
30
+ console.log("Client and server versions may be incompatible.");
31
+ } else if (e instanceof Buttplug.ButtplugDeviceError) {
32
+ // Something went wrong communicating with a device.
33
+ // Causes: device disconnected, invalid command for device,
34
+ // device rejected command, hardware error.
35
+ console.log(`[Device Error] ${e.message}`);
36
+ console.log("The device may have disconnected or doesn't support this command.");
37
+ } else if (e instanceof Buttplug.ButtplugMessageError) {
38
+ // The message sent was invalid.
39
+ // Causes: malformed message, missing required fields,
40
+ // invalid parameter values.
41
+ console.log(`[Message Error] ${e.message}`);
42
+ console.log("This usually indicates a bug in the client library or application.");
43
+ } else if (e instanceof Buttplug.ButtplugPingError) {
44
+ // Server didn't receive ping in time, connection terminated.
45
+ // The ping system ensures dead connections are detected.
46
+ console.log(`[Ping Error] ${e.message}`);
47
+ console.log("Connection was lost due to ping timeout.");
48
+ } else if (e instanceof Buttplug.ButtplugError) {
49
+ // Unknown or future error type
50
+ console.log(`[Buttplug Error] ${e.message}`);
51
+ } else if (e instanceof Error) {
52
+ // Non-Buttplug error
53
+ console.log(`[System Error] ${e.message}`);
54
+ } else {
55
+ console.log(`[Unknown Error] ${e}`);
56
+ }
57
+ }
58
+
59
+ async function runErrorExample() {
60
+ console.log("Error Handling Example");
61
+ console.log("======================\n");
62
+
63
+ // Example 1: Connection error (server not running on wrong port)
64
+ console.log("1. Attempting to connect to non-existent server...");
65
+ const client1 = new Buttplug.ButtplugClient("Error Example");
66
+ try {
67
+ const badConnector = new Buttplug.ButtplugBrowserWebsocketClientConnector("ws://127.0.0.1:99999");
68
+ await client1.connect(badConnector);
69
+ } catch (e) {
70
+ handleButtplugError(e);
71
+ }
72
+
73
+ // Example 2: Demonstrating promise-based error handling
74
+ console.log("\n2. Demonstrating promise-based error handling...");
75
+ const client2 = new Buttplug.ButtplugClient("Promise Error Example");
76
+ const badConnector2 = new Buttplug.ButtplugBrowserWebsocketClientConnector("ws://127.0.0.1:99998");
77
+
78
+ // You can also catch errors using .catch() on promises
79
+ await client2
80
+ .connect(badConnector2)
81
+ .then(() => {
82
+ console.log("Connected (unexpected!)");
83
+ })
84
+ .catch((e) => {
85
+ console.log("Caught error using .catch():");
86
+ handleButtplugError(e);
87
+ });
88
+
89
+ // Example 3: Using try/catch with async/await
90
+ console.log("\n3. Using try/catch with async/await...");
91
+ const client3 = new Buttplug.ButtplugClient("Async Error Example");
92
+ const invalidConnector = new Buttplug.ButtplugBrowserWebsocketClientConnector("ws://notadomain.local");
93
+
94
+ try {
95
+ await client3.connect(invalidConnector);
96
+ } catch (e) {
97
+ // Check for specific Buttplug error types
98
+ console.log(`Error: ${e}`);
99
+ if (e instanceof Buttplug.ButtplugError) {
100
+ console.log("This is a Buttplug-specific error.");
101
+ if (e instanceof Buttplug.ButtplugClientConnectorException) {
102
+ console.log("Specifically, it's a connector error.");
103
+ }
104
+ } else {
105
+ console.log("This is a non-Buttplug error (system/network level).");
106
+ }
107
+ }
108
+
109
+ console.log("\nError handling example complete.");
110
+ }
@@ -0,0 +1,55 @@
1
+ <html>
2
+ <head>
3
+ <style>
4
+ button {
5
+ display: block;
6
+ margin-bottom: 5px;
7
+ }
8
+ </style>
9
+ </head>
10
+ <body>
11
+ <button id="async-example-button">Run Async Example</button>
12
+ <button id="errors-example-button">Run Errors Example</button>
13
+ <button id="remote-connector-example-button">Run Websocket Connection Example</button>
14
+ <button id="device-enumeration-example-button">Run Device Enumeration Example</button>
15
+ <button id="device-control-example-button">Run Device Control Example</button>
16
+ <button id="device-info-example-button">Run Device Info Example</button>
17
+ <button id="logging-example-button">Run Logging Example</button>
18
+ <button id="ping-timeout-example-button">Run Ping Timeout Example</button>
19
+ <script lang="javascript" src="https://cdn.jsdelivr.net/npm/buttplug@4.0.0/dist/web/buttplug.min.js"></script>
20
+ <script lang="javascript" src="async-example.js"></script>
21
+ <script lang="javascript" src="errors-example.js"></script>
22
+ <script lang="javascript" src="device-control-example.js"></script>
23
+ <script lang="javascript" src="device-enumeration-example.js"></script>
24
+ <script lang="javascript" src="device-info-example.js"></script>
25
+ <script lang="javascript" src="logging.js"></script>
26
+ <script lang="javascript" src="ping-timeout-example.js"></script>
27
+ <script lang="javascript" src="remote-connector-example.js"></script>
28
+ <script lang="javascript" defer>
29
+ document
30
+ .getElementById("async-example-button")
31
+ .addEventListener("click", async() => await runAsyncExample());
32
+ document
33
+ .getElementById("errors-example-button")
34
+ .addEventListener("click", async () => await runErrorExample());
35
+ document
36
+ .getElementById("remote-connector-example-button")
37
+ .addEventListener("click", async () => await runWebsocketConnectionExample());
38
+ document
39
+ .getElementById("device-enumeration-example-button")
40
+ .addEventListener("click", async() => await runDeviceEnumerationExample());
41
+ document
42
+ .getElementById("device-control-example-button")
43
+ .addEventListener("click", async () => await runDeviceControlExample());
44
+ document
45
+ .getElementById("device-info-example-button")
46
+ .addEventListener("click", async () => await runDeviceInfoExample());
47
+ document
48
+ .getElementById("logging-example-button")
49
+ .addEventListener("click", async () => await runLoggingExample());
50
+ document
51
+ .getElementById("ping-timeout-example-button")
52
+ .addEventListener("click", async () => await runPingTimeoutExample());
53
+ </script>
54
+ </body>
55
+ </html>
@@ -0,0 +1,42 @@
1
+ // Buttplug Web - Logging Example
2
+ //
3
+ // This example demonstrates basic connection with console logging.
4
+ //
5
+ // Include Buttplug via CDN:
6
+ // <script src="https://cdn.jsdelivr.net/npm/buttplug@4.0.0/dist/web/buttplug.min.js"></script>
7
+
8
+ async function runLoggingExample() {
9
+ console.log("Logging Example - Connecting with verbose logging");
10
+
11
+ const connector = new Buttplug.ButtplugBrowserWebsocketClientConnector("ws://127.0.0.1:12345");
12
+ const client = new Buttplug.ButtplugClient("Logging Example");
13
+
14
+ // Set up all event listeners to log activity
15
+ client.addListener("deviceadded", (device) => {
16
+ console.log(`[LOG] Device added: ${device.name}`);
17
+ });
18
+
19
+ client.addListener("deviceremoved", (device) => {
20
+ console.log(`[LOG] Device removed: ${device.name}`);
21
+ });
22
+
23
+ client.addListener("scanningfinished", () => {
24
+ console.log("[LOG] Scanning finished");
25
+ });
26
+
27
+ client.addListener("disconnect", () => {
28
+ console.log("[LOG] Disconnected from server");
29
+ });
30
+
31
+ try {
32
+ console.log("[LOG] Connecting...");
33
+ await client.connect(connector);
34
+ console.log("[LOG] Connected successfully!");
35
+
36
+ // Disconnect after brief demo
37
+ await client.disconnect();
38
+ console.log("[LOG] Disconnected.");
39
+ } catch (ex) {
40
+ console.log("[LOG] Connection error:", ex);
41
+ }
42
+ }
@@ -0,0 +1,59 @@
1
+ // Buttplug Web - Ping Timeout Example
2
+ //
3
+ // This example demonstrates how to handle ping timeouts and
4
+ // connection keepalive in Buttplug. The server uses a ping system
5
+ // to detect dead connections.
6
+ //
7
+ // Include Buttplug via CDN:
8
+ // <script src="https://cdn.jsdelivr.net/npm/buttplug@4.0.0/dist/web/buttplug.min.js"></script>
9
+
10
+ async function runPingTimeoutExample() {
11
+ console.log("Ping Timeout Example");
12
+ console.log("====================\n");
13
+
14
+ const client = new Buttplug.ButtplugClient("Ping Timeout Example");
15
+
16
+ // The 'disconnect' event is fired when the connection drops,
17
+ // including due to ping timeout.
18
+ client.addListener("disconnect", () => {
19
+ console.log("[Event] Connection lost!");
20
+ console.log("This could be due to:");
21
+ console.log(" - Server shutdown");
22
+ console.log(" - Network failure");
23
+ console.log(" - Ping timeout (client didn't respond in time)");
24
+ });
25
+
26
+ // Connect to server
27
+ const connector = new Buttplug.ButtplugBrowserWebsocketClientConnector("ws://127.0.0.1:12345");
28
+
29
+ try {
30
+ console.log("Connecting...");
31
+ await client.connect(connector);
32
+ console.log("Connected!");
33
+
34
+ // The ping system is handled automatically by the client.
35
+ // If the server requires ping responses and the client fails
36
+ // to respond in time, the connection will be terminated and
37
+ // a ButtplugPingError will be thrown or the disconnect event fires.
38
+
39
+ console.log("\nConnection is active. The client will automatically");
40
+ console.log("handle ping/pong with the server.");
41
+
42
+ console.log("\nTo test ping timeout:");
43
+ console.log("1. Open browser dev tools Network tab");
44
+ console.log("2. Enable 'Offline' mode or disconnect your network");
45
+ console.log("3. Wait for the disconnect event to fire");
46
+
47
+ // Keep connection open to demonstrate ping handling
48
+ console.log("\nConnection will stay open. Check console for disconnect event.");
49
+
50
+ } catch (e) {
51
+ if (e instanceof Buttplug.ButtplugPingError) {
52
+ console.log("Connection lost due to ping timeout:", e.message);
53
+ } else if (e instanceof Buttplug.ButtplugClientConnectorException) {
54
+ console.log("Could not connect to server:", e.message);
55
+ } else {
56
+ console.log("Error:", e);
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,68 @@
1
+ // Buttplug Web - Remote Websocket Connector Example
2
+ //
3
+ // This example demonstrates how to connect to a remote Buttplug server
4
+ // using the websocket connector. This is the standard way to connect
5
+ // from a browser to Intiface Central.
6
+ //
7
+ // Include Buttplug via CDN:
8
+ // <script src="https://cdn.jsdelivr.net/npm/buttplug@4.0.0/dist/web/buttplug.min.js"></script>
9
+
10
+ const runWebsocketConnectionExample = async () => {
11
+ // This is the default insecure address for Intiface Central (https://intiface.com/central).
12
+ // You can connect to it via most browsers.
13
+ const address = "ws://localhost:12345";
14
+
15
+ // Create the connector with the server address
16
+ const connector = new Buttplug.ButtplugBrowserWebsocketClientConnector(address);
17
+ const client = new Buttplug.ButtplugClient("Websocket Connection Example");
18
+
19
+ // Set up disconnect handler before connecting
20
+ client.addListener("disconnect", () => {
21
+ console.log("Server connection lost!");
22
+ });
23
+
24
+ // Now we connect. If anything goes wrong here, we'll either throw:
25
+ //
26
+ // - A ButtplugClientConnectorException if there's a problem with
27
+ // the connector, like the network address being wrong, server not
28
+ // being up, etc.
29
+ // - A ButtplugInitError if there is a client/server version mismatch.
30
+ try {
31
+ console.log(`Connecting to ${address}...`);
32
+ await client.connect(connector);
33
+ } catch (ex) {
34
+ // If our connection failed, because the server wasn't turned on, SSL/TLS
35
+ // wasn't turned off, etc, we'll just print and exit here.
36
+ //
37
+ // This could also mean our client is newer than our server, and we need to
38
+ // upgrade the server we're connecting to.
39
+ console.log("Connection failed:", ex);
40
+ return;
41
+ }
42
+
43
+ // We're connected!
44
+ console.log("Connected!");
45
+ console.log("Connection will disconnect automatically in 3 seconds...");
46
+
47
+ // Demonstrate we can use the connection
48
+ await client.startScanning();
49
+ console.log("Scanning for devices...");
50
+
51
+ // Disconnect after a delay
52
+ setTimeout(async () => {
53
+ console.log("Stopping scan...");
54
+ await client.stopScanning();
55
+
56
+ // Show any devices that were found
57
+ if (client.devices.size > 0) {
58
+ console.log("Devices found:");
59
+ for (const [index, device] of client.devices) {
60
+ console.log(` - ${device.name} (Index: ${index})`);
61
+ }
62
+ }
63
+
64
+ console.log("Disconnecting...");
65
+ await client.disconnect();
66
+ console.log("Disconnected.");
67
+ }, 3000);
68
+ };
package/node-test.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const _1 = require(".");
4
+ async function run() {
5
+ const client = new _1.ButtplugClient('Test Client');
6
+ await client.connect(new _1.ButtplugNodeWebsocketClientConnector('ws://127.0.0.1:12345'));
7
+ console.log(client.devices);
8
+ //console.log(client.devices.get(0)!.hasOutput(OutputType.Vibrate));
9
+ //console.log("Vibrating");
10
+ try {
11
+ //await client.devices.get(2)!.runOutput(DeviceOutput.Vibrate.percent(0.5));
12
+ console.log(await client.devices.get(1).battery());
13
+ await client.devices.get(1).features.get(0).runInput(_1.InputType.Pressure, _1.InputCommandType.Subscribe);
14
+ }
15
+ catch (e) {
16
+ console.log(e);
17
+ }
18
+ await new Promise((res, _) => setTimeout(() => res(true), 3000));
19
+ //await client.devices.get(1)!.features.get(0)!.runInput(InputType.Pressure, InputCommandType.Unsubscribe);
20
+ //console.log("stopping");
21
+ //console.log(await client.devices.get(1)!.features.get(0)!.runOutput(DeviceOutput.Vibrate.percent(0)));
22
+ }
23
+ run();
24
+ //testInterfaces();
package/node-test.ts CHANGED
@@ -1,5 +1,23 @@
1
- import { ButtplugClient, ButtplugNodeWebsocketClientConnector } from '.';
2
-
3
- const client = new ButtplugClient('Test Client');
4
- client.connect(new ButtplugNodeWebsocketClientConnector('ws://127.0.0.1:12345'));
5
-
1
+ import { ButtplugClient, ButtplugNodeWebsocketClientConnector, InputCommandType, InputType, OutputType } from '.';
2
+ import { DeviceOutput, DeviceOutputCommand } from './dist/main/src/client/ButtplugClientDeviceCommand';
3
+
4
+ async function run() {
5
+ const client = new ButtplugClient('Test Client');
6
+ await client.connect(new ButtplugNodeWebsocketClientConnector('ws://127.0.0.1:12345'));
7
+ console.log(client.devices);
8
+ //console.log(client.devices.get(0)!.hasOutput(OutputType.Vibrate));
9
+ //console.log("Vibrating");
10
+ try {
11
+ //await client.devices.get(2)!.runOutput(DeviceOutput.Vibrate.percent(0.5));
12
+ console.log(await client.devices.get(1)!.battery());
13
+ await client.devices.get(1)!.features.get(0)!.runInput(InputType.Pressure, InputCommandType.Subscribe);
14
+ } catch (e) {
15
+ console.log(e);
16
+ }
17
+ await new Promise((res, _) => setTimeout(() => res(true), 3000));
18
+ //await client.devices.get(1)!.features.get(0)!.runInput(InputType.Pressure, InputCommandType.Unsubscribe);
19
+ //console.log("stopping");
20
+ //console.log(await client.devices.get(1)!.features.get(0)!.runOutput(DeviceOutput.Vibrate.percent(0)));
21
+ }
22
+ run();
23
+ //testInterfaces();
package/package.json CHANGED
@@ -1,87 +1,85 @@
1
- {
2
- "name": "buttplug",
3
- "version": "3.2.2",
4
- "description": "Buttplug Client Implementation for Typescript/Javascript",
5
- "homepage": "https://github.com/buttplugio/buttplug-js/",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/buttplugio/buttplug-js.git"
9
- },
10
- "author": "Nonpolynomial Labs, LLC",
11
- "keywords": [
12
- "teledildonics",
13
- "hardware"
14
- ],
15
- "license": "BSD-3-Clause",
16
- "bugs": {
17
- "url": "https://github.com/buttplugio/buttplug-js/issues"
18
- },
19
- "main": "./dist/main/src/index.js",
20
- "types": "./dist/main/src/index.d.ts",
21
- "scripts": {
22
- "build": "trash dist dist-bundle && yarn build:all",
23
- "build:all": "yarn build:main && yarn build:web",
24
- "build:main": "tsc -p tsconfig.json",
25
- "build:doc": "typedoc --options typedocconfig.js --out doc ./src/index.ts",
26
- "build:web": "vite build",
27
- "pretest": "yarn build:main",
28
- "test": "jest tests/*",
29
- "web-test": "jest web-tests/test-web-library.ts",
30
- "web-test-ci": "jest --runInBand web-tests/test-web-library.ts"
31
- },
32
- "dependencies": {
33
- "class-transformer": "^0.5.1",
34
- "eventemitter3": "^5.0.1",
35
- "reflect-metadata": "^0.2.1",
36
- "ws": "^8.16.0"
37
- },
38
- "devDependencies": {
39
- "@types/commander": "^2.12.2",
40
- "@types/expect-puppeteer": "^5.0.6",
41
- "@types/jest": "^29.5.12",
42
- "@types/jest-environment-puppeteer": "^5.0.6",
43
- "@types/node": "^20.11.24",
44
- "@types/uuid-parse": "^1.0.2",
45
- "@types/ws": "^8.5.10",
46
- "@typescript-eslint/eslint-plugin": "^7.1.0",
47
- "@typescript-eslint/parser": "^7.1.0",
48
- "copyfiles": "^2.4.1",
49
- "cross-env": "^7.0.3",
50
- "eslint": "^8.57.0",
51
- "eslint-plugin-node": "^11.1.0",
52
- "gts": "^5.2.0",
53
- "jest": "^29.7.0",
54
- "mock-socket": "^9.3.1",
55
- "pkg": "^5.8.1",
56
- "tmp": "^0.2.3",
57
- "trash": "^8.1.1",
58
- "trash-cli": "^5.0.0",
59
- "ts-jest": "^29.1.2",
60
- "ts-node": "^10.9.2",
61
- "tslib": "^2.6.2",
62
- "typedoc": "^0.25.9",
63
- "typescript": "^5.3.3",
64
- "vite": "^5.1.4",
65
- "vite-plugin-dts": "^3.7.3",
66
- "yarn": "^1.22.21"
67
- },
68
- "jest": {
69
- "moduleFileExtensions": [
70
- "ts",
71
- "js",
72
- "json"
73
- ],
74
- "transform": {
75
- "^.+\\.ts$": "ts-jest"
76
- },
77
- "testMatch": [
78
- "<rootDir>/tests/**/test-*.ts",
79
- "<rootDir>/web-tests/**/test-*.ts"
80
- ],
81
- "coverageDirectory": "./coverage/",
82
- "coverageReporters": [
83
- "json"
84
- ],
85
- "collectCoverage": true
86
- }
87
- }
1
+ {
2
+ "name": "buttplug",
3
+ "version": "4.0.1",
4
+ "description": "Buttplug Client Implementation for Typescript/Javascript",
5
+ "homepage": "https://github.com/buttplugio/buttplug-js/",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/buttplugio/buttplug-js.git"
9
+ },
10
+ "author": "Nonpolynomial Labs, LLC",
11
+ "keywords": [
12
+ "teledildonics",
13
+ "hardware"
14
+ ],
15
+ "license": "BSD-3-Clause",
16
+ "bugs": {
17
+ "url": "https://github.com/buttplugio/buttplug-js/issues"
18
+ },
19
+ "main": "./dist/main/src/index.js",
20
+ "types": "./dist/main/src/index.d.ts",
21
+ "scripts": {
22
+ "build": "trash dist dist-bundle && yarn build:all",
23
+ "build:all": "yarn build:main && yarn build:web",
24
+ "build:main": "tsc -p tsconfig.json",
25
+ "build:doc": "typedoc --options typedocconfig.js --out doc ./src/index.ts",
26
+ "build:web": "vite build",
27
+ "pretest": "yarn build:main",
28
+ "test": "jest tests/*",
29
+ "web-test": "jest web-tests/test-web-library.ts",
30
+ "web-test-ci": "jest --runInBand web-tests/test-web-library.ts"
31
+ },
32
+ "dependencies": {
33
+ "eventemitter3": "^5.0.1",
34
+ "ws": "^8.18.3"
35
+ },
36
+ "devDependencies": {
37
+ "@types/commander": "^2.12.5",
38
+ "@types/expect-puppeteer": "^5.0.6",
39
+ "@types/jest": "^30.0.0",
40
+ "@types/jest-environment-puppeteer": "^5.0.6",
41
+ "@types/node": "^24.10.1",
42
+ "@types/uuid-parse": "^1.0.2",
43
+ "@types/ws": "^8.18.1",
44
+ "@typescript-eslint/eslint-plugin": "^8.47.0",
45
+ "@typescript-eslint/parser": "^8.47.0",
46
+ "copyfiles": "^2.4.1",
47
+ "cross-env": "^10.1.0",
48
+ "eslint": "^9.39.1",
49
+ "eslint-plugin-node": "^11.1.0",
50
+ "gts": "^6.0.2",
51
+ "jest": "^30.2.0",
52
+ "mock-socket": "^9.3.1",
53
+ "pkg": "^5.8.1",
54
+ "tmp": "^0.2.5",
55
+ "trash": "^10.0.0",
56
+ "trash-cli": "^7.0.0",
57
+ "ts-jest": "^29.4.5",
58
+ "ts-node": "^10.9.2",
59
+ "tslib": "^2.8.1",
60
+ "typedoc": "^0.28.14",
61
+ "typescript": "^5.9.3",
62
+ "vite": "^7.2.4",
63
+ "vite-plugin-dts": "^4.5.4",
64
+ "yarn": "^1.22.22"
65
+ },
66
+ "jest": {
67
+ "moduleFileExtensions": [
68
+ "ts",
69
+ "js",
70
+ "json"
71
+ ],
72
+ "transform": {
73
+ "^.+\\.ts$": "ts-jest"
74
+ },
75
+ "testMatch": [
76
+ "<rootDir>/tests/**/test-*.ts",
77
+ "<rootDir>/web-tests/**/test-*.ts"
78
+ ],
79
+ "coverageDirectory": "./coverage/",
80
+ "coverageReporters": [
81
+ "json"
82
+ ],
83
+ "collectCoverage": true
84
+ }
85
+ }
@@ -1,25 +1,25 @@
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 { IButtplugClientConnector } from './IButtplugClientConnector';
12
- import { ButtplugMessage } from '../core/Messages';
13
- import { ButtplugBrowserWebsocketConnector } from '../utils/ButtplugBrowserWebsocketConnector';
14
-
15
- export class ButtplugBrowserWebsocketClientConnector
16
- extends ButtplugBrowserWebsocketConnector
17
- implements IButtplugClientConnector
18
- {
19
- public send = (msg: ButtplugMessage): void => {
20
- if (!this.Connected) {
21
- throw new Error('ButtplugClient not connected');
22
- }
23
- this.sendMessage(msg);
24
- };
25
- }
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 { IButtplugClientConnector } from './IButtplugClientConnector';
12
+ import { ButtplugMessage } from '../core/Messages';
13
+ import { ButtplugBrowserWebsocketConnector } from '../utils/ButtplugBrowserWebsocketConnector';
14
+
15
+ export class ButtplugBrowserWebsocketClientConnector
16
+ extends ButtplugBrowserWebsocketConnector
17
+ implements IButtplugClientConnector
18
+ {
19
+ public send = (msg: ButtplugMessage): void => {
20
+ if (!this.Connected) {
21
+ throw new Error('ButtplugClient not connected');
22
+ }
23
+ this.sendMessage(msg);
24
+ };
25
+ }