Comparing version 3.0.0 to 3.1.0
@@ -0,0 +0,0 @@ module.exports = { |
@@ -0,3 +1,17 @@ | ||
# v3.1.0 (2023/02/11) | ||
## Features | ||
- Added support for Node Websockets via new connector class (#244) | ||
## Bugfixes | ||
- Fixed issues with using buttplug-js in minified projects (#246) | ||
- Changed from type-based class resolution to static naming, class name mangling should no longer | ||
be an issue. | ||
# v3.0.0 (2022/12/30) | ||
## Features | ||
- Back to pure Typescript. Back to the good shit. | ||
@@ -10,2 +24,4 @@ - Removed server | ||
## Whatever | ||
- There is no buttplug-js v2 | ||
@@ -12,0 +28,0 @@ - There is no Miss Zarves |
@@ -13,5 +13,2 @@ /*! | ||
private _sorter; | ||
protected _ws: WebSocket | undefined; | ||
constructor(_url: string); | ||
get Connected(): boolean; | ||
Send: (msg: ButtplugMessage) => Promise<ButtplugMessage>; | ||
@@ -18,0 +15,0 @@ protected ParseIncomingMessage: (event: MessageEvent) => void; |
@@ -24,4 +24,4 @@ /*! | ||
class ButtplugBrowserWebsocketClientConnector extends ButtplugBrowserWebsocketConnector_1.ButtplugBrowserWebsocketConnector { | ||
constructor(_url) { | ||
super(_url); | ||
constructor() { | ||
super(...arguments); | ||
this._sorter = new ButtplugMessageSorter_1.ButtplugMessageSorter(true); | ||
@@ -37,2 +37,3 @@ this.Send = (msg) => __awaiter(this, void 0, void 0, function* () { | ||
this.ParseIncomingMessage = (event) => { | ||
var _a; | ||
if (typeof event.data === 'string') { | ||
@@ -44,3 +45,3 @@ const msgs = (0, MessageUtils_1.FromJSON)(event.data); | ||
else if (event.data instanceof Blob) { | ||
const reader = new FileReader(); | ||
const reader = new ((_a = this._filereaderConstructor) !== null && _a !== void 0 ? _a : FileReader)(); | ||
reader.addEventListener('load', (ev) => { | ||
@@ -53,5 +54,2 @@ this.OnReaderLoad(ev); | ||
} | ||
get Connected() { | ||
return this._ws !== undefined; | ||
} | ||
OnReaderLoad(event) { | ||
@@ -58,0 +56,0 @@ const msgs = (0, MessageUtils_1.FromJSON)(event.target.result); |
@@ -63,11 +63,2 @@ /*! | ||
constructor(Id: number); | ||
/*** | ||
* Returns the message type name | ||
* | ||
* Usually, the message type name will be the same as the message class | ||
* constructor, so the constructor name is used by default. However, in | ||
* instances where a message has different versions (i.e. DeviceAddedVersion0 | ||
* and DeviceAddedVersion1), we will need to override this to set the message | ||
* name. | ||
*/ | ||
get Type(): Function; | ||
@@ -89,2 +80,3 @@ toJSON(): string; | ||
Id: number; | ||
static Name: string; | ||
constructor(Id?: number); | ||
@@ -94,2 +86,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(Id?: number); | ||
@@ -108,2 +101,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(ErrorMessage: string, ErrorCode?: ErrorClass, Id?: number); | ||
@@ -121,2 +115,3 @@ get Schemversion(): number; | ||
export declare class DeviceList extends ButtplugMessage { | ||
static Name: string; | ||
Devices: DeviceInfo[]; | ||
@@ -128,2 +123,3 @@ Id: number; | ||
export declare class DeviceAdded extends ButtplugSystemMessage { | ||
static Name: string; | ||
DeviceIndex: number; | ||
@@ -139,2 +135,3 @@ DeviceName: string; | ||
DeviceIndex: number; | ||
static Name: string; | ||
constructor(DeviceIndex: number); | ||
@@ -144,2 +141,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(Id?: number); | ||
@@ -149,2 +147,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(Id?: number); | ||
@@ -154,5 +153,7 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(Id?: number); | ||
} | ||
export declare class ScanningFinished extends ButtplugSystemMessage { | ||
static Name: string; | ||
constructor(); | ||
@@ -164,2 +165,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(ClientName: string, MessageVersion?: number, Id?: number); | ||
@@ -172,2 +174,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(MessageVersion: number, MaxPingTime: number, ServerName: string, Id?: number); | ||
@@ -178,2 +181,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(DeviceIndex?: number, Id?: number); | ||
@@ -183,2 +187,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(Id?: number); | ||
@@ -199,2 +204,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(Scalars: ScalarSubcommand[], DeviceIndex?: number, Id?: number); | ||
@@ -211,2 +217,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
static Create(deviceIndex: number, commands: [number, boolean][]): RotateCmd; | ||
@@ -224,2 +231,3 @@ constructor(Rotations: RotateSubcommand[], DeviceIndex?: number, Id?: number); | ||
Id: number; | ||
static Name: string; | ||
static Create(deviceIndex: number, commands: [number, number][]): LinearCmd; | ||
@@ -233,2 +241,3 @@ constructor(Vectors: VectorSubcommand[], DeviceIndex?: number, Id?: number); | ||
Id: number; | ||
static Name: string; | ||
constructor(DeviceIndex: number, SensorIndex: number, SensorType: SensorType, Id?: number); | ||
@@ -242,2 +251,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(DeviceIndex: number, SensorIndex: number, SensorType: SensorType, Data: number[], Id?: number); | ||
@@ -251,2 +261,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(DeviceIndex: number, Endpoint: string, ExpectedLength: number, Timeout: number, Id?: number); | ||
@@ -260,2 +271,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(DeviceIndex: number, Endpoint: string, Data: Uint8Array, WriteWithResponse: boolean, Id?: number); | ||
@@ -267,2 +279,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(DeviceIndex: number, Endpoint: string, Id?: number); | ||
@@ -274,2 +287,3 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(DeviceIndex: number, Endpoint: string, Id?: number); | ||
@@ -282,3 +296,4 @@ } | ||
Id: number; | ||
static Name: string; | ||
constructor(DeviceIndex: number, Endpoint: string, Data: number[], Id?: number); | ||
} |
@@ -86,11 +86,2 @@ /*! | ||
} | ||
/*** | ||
* Returns the message type name | ||
* | ||
* Usually, the message type name will be the same as the message class | ||
* constructor, so the constructor name is used by default. However, in | ||
* instances where a message has different versions (i.e. DeviceAddedVersion0 | ||
* and DeviceAddedVersion1), we will need to override this to set the message | ||
* name. | ||
*/ | ||
// tslint:disable-next-line:ban-types | ||
@@ -105,3 +96,4 @@ get Type() { | ||
const jsonObj = {}; | ||
jsonObj[this.constructor.name] = (0, class_transformer_1.instanceToPlain)(this); | ||
jsonObj[this.constructor.Name] = | ||
(0, class_transformer_1.instanceToPlain)(this); | ||
return jsonObj; | ||
@@ -134,2 +126,3 @@ } | ||
exports.Ok = Ok; | ||
Ok.Name = 'Ok'; | ||
class Ping extends ButtplugMessage { | ||
@@ -142,2 +135,3 @@ constructor(Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.Ping = Ping; | ||
Ping.Name = 'Ping'; | ||
var ErrorClass; | ||
@@ -163,2 +157,3 @@ (function (ErrorClass) { | ||
exports.Error = Error; | ||
Error.Name = 'Error'; | ||
class DeviceInfo { | ||
@@ -186,2 +181,3 @@ constructor(data) { | ||
} | ||
DeviceList.Name = 'DeviceList'; | ||
__decorate([ | ||
@@ -201,2 +197,3 @@ (0, class_transformer_1.Type)(() => DeviceInfo), | ||
} | ||
DeviceAdded.Name = 'DeviceAdded'; | ||
__decorate([ | ||
@@ -214,2 +211,3 @@ (0, class_transformer_1.Type)(() => MessageAttributes), | ||
exports.DeviceRemoved = DeviceRemoved; | ||
DeviceRemoved.Name = 'DeviceRemoved'; | ||
class RequestDeviceList extends ButtplugMessage { | ||
@@ -222,2 +220,3 @@ constructor(Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.RequestDeviceList = RequestDeviceList; | ||
RequestDeviceList.Name = 'RequestDeviceList'; | ||
class StartScanning extends ButtplugMessage { | ||
@@ -230,2 +229,3 @@ constructor(Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.StartScanning = StartScanning; | ||
StartScanning.Name = 'StartScanning'; | ||
class StopScanning extends ButtplugMessage { | ||
@@ -238,2 +238,3 @@ constructor(Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.StopScanning = StopScanning; | ||
StopScanning.Name = 'StopScanning'; | ||
class ScanningFinished extends ButtplugSystemMessage { | ||
@@ -245,2 +246,3 @@ constructor() { | ||
exports.ScanningFinished = ScanningFinished; | ||
ScanningFinished.Name = 'ScanningFinished'; | ||
class RequestServerInfo extends ButtplugMessage { | ||
@@ -255,2 +257,3 @@ constructor(ClientName, MessageVersion = 0, Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.RequestServerInfo = RequestServerInfo; | ||
RequestServerInfo.Name = 'RequestServerInfo'; | ||
class ServerInfo extends ButtplugSystemMessage { | ||
@@ -266,2 +269,3 @@ constructor(MessageVersion, MaxPingTime, ServerName, Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.ServerInfo = ServerInfo; | ||
ServerInfo.Name = 'ServerInfo'; | ||
class StopDeviceCmd extends ButtplugDeviceMessage { | ||
@@ -275,2 +279,3 @@ constructor(DeviceIndex = -1, Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.StopDeviceCmd = StopDeviceCmd; | ||
StopDeviceCmd.Name = 'StopDeviceCmd'; | ||
class StopAllDevices extends ButtplugMessage { | ||
@@ -283,2 +288,3 @@ constructor(Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.StopAllDevices = StopAllDevices; | ||
StopAllDevices.Name = 'StopAllDevices'; | ||
class GenericMessageSubcommand { | ||
@@ -307,2 +313,3 @@ constructor(Index) { | ||
exports.ScalarCmd = ScalarCmd; | ||
ScalarCmd.Name = 'ScalarCmd'; | ||
class RotateSubcommand extends GenericMessageSubcommand { | ||
@@ -334,2 +341,3 @@ constructor(Index, Speed, Clockwise) { | ||
exports.RotateCmd = RotateCmd; | ||
RotateCmd.Name = 'RotateCmd'; | ||
class VectorSubcommand extends GenericMessageSubcommand { | ||
@@ -361,2 +369,3 @@ constructor(Index, Position, Duration) { | ||
exports.LinearCmd = LinearCmd; | ||
LinearCmd.Name = 'LinearCmd'; | ||
class SensorReadCmd extends ButtplugDeviceMessage { | ||
@@ -372,2 +381,3 @@ constructor(DeviceIndex, SensorIndex, SensorType, Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.SensorReadCmd = SensorReadCmd; | ||
SensorReadCmd.Name = 'SensorReadCmd'; | ||
class SensorReading extends ButtplugDeviceMessage { | ||
@@ -384,2 +394,3 @@ constructor(DeviceIndex, SensorIndex, SensorType, Data, Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.SensorReading = SensorReading; | ||
SensorReading.Name = 'SensorReading'; | ||
class RawReadCmd extends ButtplugDeviceMessage { | ||
@@ -396,2 +407,3 @@ constructor(DeviceIndex, Endpoint, ExpectedLength, Timeout, Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.RawReadCmd = RawReadCmd; | ||
RawReadCmd.Name = 'RawReadCmd'; | ||
class RawWriteCmd extends ButtplugDeviceMessage { | ||
@@ -408,2 +420,3 @@ constructor(DeviceIndex, Endpoint, Data, WriteWithResponse, Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.RawWriteCmd = RawWriteCmd; | ||
RawWriteCmd.Name = 'RawWriteCmd'; | ||
class RawSubscribeCmd extends ButtplugDeviceMessage { | ||
@@ -418,2 +431,3 @@ constructor(DeviceIndex, Endpoint, Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.RawSubscribeCmd = RawSubscribeCmd; | ||
RawSubscribeCmd.Name = 'RawSubscribeCmd'; | ||
class RawUnsubscribeCmd extends ButtplugDeviceMessage { | ||
@@ -428,2 +442,3 @@ constructor(DeviceIndex, Endpoint, Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.RawUnsubscribeCmd = RawUnsubscribeCmd; | ||
RawUnsubscribeCmd.Name = 'RawUnsubscribeCmd'; | ||
class RawReading extends ButtplugDeviceMessage { | ||
@@ -439,2 +454,3 @@ constructor(DeviceIndex, Endpoint, Data, Id = exports.DEFAULT_MESSAGE_ID) { | ||
exports.RawReading = RawReading; | ||
RawReading.Name = 'RawReading'; | ||
//# sourceMappingURL=Messages.js.map |
@@ -36,2 +36,10 @@ /*! | ||
const Messages = __importStar(require("./Messages")); | ||
function getMessageClass(type) { | ||
for (const value of Object.values(Messages)) { | ||
if (typeof value === 'function' && 'Name' in value && value.Name === type) { | ||
return value; | ||
} | ||
} | ||
return null; | ||
} | ||
function FromJSON(str) { | ||
@@ -41,10 +49,9 @@ const msgarray = JSON.parse(str); | ||
for (const x of Array.from(msgarray)) { | ||
// Can't get this to resolve nicely as a type, so just start from any and cast | ||
// after. Not sure how to resolve plainToClass to a type since this is | ||
// dynamic. | ||
// | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const msg = (0, class_transformer_1.plainToInstance)(Messages[Object.getOwnPropertyNames(x)[0]], x[Object.getOwnPropertyNames(x)[0]]); | ||
msg.update(); | ||
msgs.push(msg); | ||
const type = Object.getOwnPropertyNames(x)[0]; | ||
const cls = getMessageClass(type); | ||
if (cls) { | ||
const msg = (0, class_transformer_1.plainToInstance)(cls, x[type]); | ||
msg.update(); | ||
msgs.push(msg); | ||
} | ||
} | ||
@@ -51,0 +58,0 @@ return msgs; |
@@ -11,2 +11,3 @@ /*! | ||
export * from './client/ButtplugBrowserWebsocketClientConnector'; | ||
export * from './client/ButtplugNodeWebsocketClientConnector'; | ||
export * from './client/ButtplugClientConnectorException'; | ||
@@ -13,0 +14,0 @@ export * from './utils/ButtplugMessageSorter'; |
@@ -27,2 +27,3 @@ "use strict"; | ||
__exportStar(require("./client/ButtplugBrowserWebsocketClientConnector"), exports); | ||
__exportStar(require("./client/ButtplugNodeWebsocketClientConnector"), exports); | ||
__exportStar(require("./client/ButtplugClientConnectorException"), exports); | ||
@@ -29,0 +30,0 @@ __exportStar(require("./utils/ButtplugMessageSorter"), exports); |
@@ -14,2 +14,4 @@ /*! | ||
protected _ws: WebSocket | undefined; | ||
protected _websocketConstructor: typeof WebSocket | null; | ||
protected _filereaderConstructor: typeof FileReader | null; | ||
constructor(_url: string); | ||
@@ -16,0 +18,0 @@ get Connected(): boolean; |
@@ -26,4 +26,7 @@ /*! | ||
this._url = _url; | ||
this._websocketConstructor = null; | ||
this._filereaderConstructor = null; | ||
this.Connect = () => __awaiter(this, void 0, void 0, function* () { | ||
const ws = new WebSocket(this._url); | ||
var _a; | ||
const ws = new ((_a = this._websocketConstructor) !== null && _a !== void 0 ? _a : WebSocket)(this._url); | ||
let res; | ||
@@ -81,2 +84,3 @@ let rej; | ||
ParseIncomingMessage(event) { | ||
var _a; | ||
console.log('Calling parent parse incoming'); | ||
@@ -88,3 +92,3 @@ if (typeof event.data === 'string') { | ||
else if (event.data instanceof Blob) { | ||
const reader = new FileReader(); | ||
const reader = new ((_a = this._filereaderConstructor) !== null && _a !== void 0 ? _a : FileReader)(); | ||
reader.addEventListener('load', (ev) => { | ||
@@ -91,0 +95,0 @@ this.OnReaderLoad(ev); |
{ | ||
"name": "buttplug", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Buttplug Client Implementation for Typescript/Javascript", | ||
@@ -25,3 +25,3 @@ "homepage": "https://github.com/buttplugio/buttplug-js/", | ||
"build:main": "tsc -p tsconfig.json", | ||
"build:doc": "typedoc --options typedoc.js --out doc .", | ||
"build:doc": "typedoc --options typedocconfig.js --out doc ./src/index.ts", | ||
"build:rollup": "rollup -c", | ||
@@ -40,3 +40,5 @@ "tslint": "tslint --project tsconfig.json --outputAbsolutePaths -c ../../tslint.json \"src/**/*.ts\" \"tests/**/*.ts\"", | ||
"class-transformer": "^0.5.1", | ||
"reflect-metadata": "^0.1.13" | ||
"filereader": "^0.10.3", | ||
"reflect-metadata": "^0.1.13", | ||
"ws": "^8.12.0" | ||
}, | ||
@@ -46,22 +48,22 @@ "devDependencies": { | ||
"@types/expect-puppeteer": "^5.0.2", | ||
"@types/jest": "^29.2.4", | ||
"@types/jest": "^29.4.0", | ||
"@types/jest-environment-puppeteer": "^5.0.3", | ||
"@types/node": "^18.11.18", | ||
"@types/node": "^18.13.0", | ||
"@types/uuid-parse": "^1.0.0", | ||
"@types/ws": "^8.5.3", | ||
"@typescript-eslint/eslint-plugin": "^5.47.1", | ||
"@typescript-eslint/parser": "^5.47.1", | ||
"@types/ws": "^8.5.4", | ||
"@typescript-eslint/eslint-plugin": "^5.51.0", | ||
"@typescript-eslint/parser": "^5.51.0", | ||
"copyfiles": "^2.4.1", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.30.0", | ||
"eslint": "^8.34.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"fork-ts-checker-webpack-plugin": "^7.2.14", | ||
"fork-ts-checker-webpack-plugin": "^7.3.0", | ||
"gts": "^3.1.1", | ||
"jest": "^29.3.1", | ||
"jest-puppeteer": "^6.2.0", | ||
"mock-socket": "^9.1.5", | ||
"jest": "^29.4.2", | ||
"jest-puppeteer": "^7.0.0", | ||
"mock-socket": "^9.2.0", | ||
"pkg": "^5.8.0", | ||
"puppeteer": "^19.4.1", | ||
"rollup": "^3.8.1", | ||
"puppeteer": "^19.6.3", | ||
"rollup": "^3.15.0", | ||
"rollup-plugin-auto-external": "^2.0.0", | ||
@@ -75,3 +77,3 @@ "rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-postcss": "^4.0.2", | ||
"rollup-plugin-postcss-modules": "^2.1.0", | ||
"rollup-plugin-postcss-modules": "^2.1.1", | ||
"rollup-plugin-terser": "^5.3.0", | ||
@@ -84,11 +86,11 @@ "rollup-plugin-typescript2": "^0.34.1", | ||
"tmp": "^0.2.1", | ||
"trash": "^8.1.0", | ||
"trash": "^8.1.1", | ||
"trash-cli": "^5.0.0", | ||
"ts-jest": "^29.0.3", | ||
"ts-jest": "^29.0.5", | ||
"ts-loader": "^8.x", | ||
"ts-node": "^10.9.1", | ||
"tslib": "^2.4.1", | ||
"tslib": "^2.5.0", | ||
"tslint": "^6.1.0", | ||
"typedoc": "^0.23.23", | ||
"typescript": "^4.9.4", | ||
"typedoc": "^0.23.25", | ||
"typescript": "^4.9.5", | ||
"url-loader": "^4.1.1", | ||
@@ -95,0 +97,0 @@ "webpack": "^4.42.1", |
@@ -15,4 +15,15 @@ # Buttplug Typescript/JS Client Implementation | ||
## What happened? Why is buttplug-csharp back? | ||
## Using buttplug-js with Node | ||
buttplug-js works with both pure web builds, as well as node applications. To use buttplug-js with node, use the `ButtplugNodeWebsocketClientConnector` class instead of the `ButtplugBrowserWebsocketClientConnector` class. That should be the only change needed, all of the API stays the same. See the Documentation section for more info. | ||
## Documentation | ||
Documentation on how to use Buttplug in general, as well as examples for buttplug-js, can be found in the [Buttplug Developer Guide](https://docs.buttplug.io/docs/dev-guide). | ||
API documentation for buttplug-js can be found at https://buttplugio.github.io/buttplug-js. | ||
## What happened? Why is buttplug-js back? | ||
For those of you that have been around a while, you may remember that this used to be the main | ||
@@ -35,1 +46,56 @@ Typescript/Javascript implementation. From 2017 to 2020, it was a reference version of the Buttplug | ||
will be optional. | ||
## Contributing | ||
If you have issues or feature requests, [please feel free to file an issue on this repo](issues/). | ||
We are not looking for code contributions or pull requests at this time, and will not accept pull | ||
requests that do not have a matching issue where the matter was previously discussed. Pull requests | ||
should only be submitted after talking to [qdot](https://github.com/qdot) via issues on this repo | ||
(or on [discourse](https://discuss.buttplug.io) or [discord](https://discord.buttplug.io) if you | ||
would like to stay anonymous and out of recorded info on the repo) before submitting PRs. Random PRs | ||
without matching issues and discussion are likely to be closed without merging. and receiving | ||
approval to develop code based on an issue. Any random or non-issue pull requests will most likely | ||
be closed without merging. | ||
If you'd like to contribute in a non-technical way, we need money to keep up with supporting the | ||
latest and greatest hardware. We have multiple ways to donate! | ||
- [Patreon](https://patreon.com/qdot) | ||
- [Github Sponsors](https://github.com/sponsors/qdot) | ||
- [Ko-Fi](https://ko-fi.com/qdot76367) | ||
## License | ||
This project is BSD 3-Clause licensed. | ||
```text | ||
Copyright (c) 2016-2023, Nonpolynomial, LLC | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
* Neither the name of buttplug nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
``` |
@@ -22,12 +22,3 @@ /*! | ||
private _sorter: ButtplugMessageSorter = new ButtplugMessageSorter(true); | ||
protected _ws: WebSocket | undefined; | ||
public constructor(_url: string) { | ||
super(_url); | ||
} | ||
public get Connected(): boolean { | ||
return this._ws !== undefined; | ||
} | ||
public Send = async (msg: ButtplugMessage): Promise<ButtplugMessage> => { | ||
@@ -48,3 +39,3 @@ if (!this.Connected) { | ||
} else if (event.data instanceof Blob) { | ||
const reader = new FileReader(); | ||
const reader = new (this._filereaderConstructor ?? FileReader)(); | ||
reader.addEventListener('load', (ev) => { | ||
@@ -51,0 +42,0 @@ this.OnReaderLoad(ev); |
@@ -88,14 +88,6 @@ /*! | ||
} | ||
export abstract class ButtplugMessage { | ||
constructor(public Id: number) {} | ||
/*** | ||
* Returns the message type name | ||
* | ||
* Usually, the message type name will be the same as the message class | ||
* constructor, so the constructor name is used by default. However, in | ||
* instances where a message has different versions (i.e. DeviceAddedVersion0 | ||
* and DeviceAddedVersion1), we will need to override this to set the message | ||
* name. | ||
*/ | ||
// tslint:disable-next-line:ban-types | ||
@@ -112,3 +104,4 @@ public get Type(): Function { | ||
const jsonObj = {}; | ||
jsonObj[this.constructor.name] = instanceToPlain(this); | ||
jsonObj[(this.constructor as unknown as { Name: string }).Name] = | ||
instanceToPlain(this); | ||
return jsonObj; | ||
@@ -133,2 +126,4 @@ } | ||
export class Ok extends ButtplugSystemMessage { | ||
static Name = 'Ok'; | ||
constructor(public Id: number = DEFAULT_MESSAGE_ID) { | ||
@@ -140,2 +135,4 @@ super(Id); | ||
export class Ping extends ButtplugMessage { | ||
static Name = 'Ping'; | ||
constructor(public Id: number = DEFAULT_MESSAGE_ID) { | ||
@@ -155,2 +152,4 @@ super(Id); | ||
export class Error extends ButtplugMessage { | ||
static Name = 'Error'; | ||
constructor( | ||
@@ -183,2 +182,4 @@ public ErrorMessage: string, | ||
export class DeviceList extends ButtplugMessage { | ||
static Name = 'DeviceList'; | ||
@Type(() => DeviceInfo) | ||
@@ -202,2 +203,4 @@ public Devices: DeviceInfo[]; | ||
export class DeviceAdded extends ButtplugSystemMessage { | ||
static Name = 'DeviceAdded'; | ||
public DeviceIndex: number; | ||
@@ -221,2 +224,4 @@ public DeviceName: string; | ||
export class DeviceRemoved extends ButtplugSystemMessage { | ||
static Name = 'DeviceRemoved'; | ||
constructor(public DeviceIndex: number) { | ||
@@ -228,2 +233,4 @@ super(); | ||
export class RequestDeviceList extends ButtplugMessage { | ||
static Name = 'RequestDeviceList'; | ||
constructor(public Id: number = DEFAULT_MESSAGE_ID) { | ||
@@ -235,2 +242,4 @@ super(Id); | ||
export class StartScanning extends ButtplugMessage { | ||
static Name = 'StartScanning'; | ||
constructor(public Id: number = DEFAULT_MESSAGE_ID) { | ||
@@ -242,2 +251,4 @@ super(Id); | ||
export class StopScanning extends ButtplugMessage { | ||
static Name = 'StopScanning'; | ||
constructor(public Id: number = DEFAULT_MESSAGE_ID) { | ||
@@ -249,2 +260,4 @@ super(Id); | ||
export class ScanningFinished extends ButtplugSystemMessage { | ||
static Name = 'ScanningFinished'; | ||
constructor() { | ||
@@ -256,2 +269,4 @@ super(); | ||
export class RequestServerInfo extends ButtplugMessage { | ||
static Name = 'RequestServerInfo'; | ||
constructor( | ||
@@ -267,2 +282,4 @@ public ClientName: string, | ||
export class ServerInfo extends ButtplugSystemMessage { | ||
static Name = 'ServerInfo'; | ||
constructor( | ||
@@ -279,2 +296,4 @@ public MessageVersion: number, | ||
export class StopDeviceCmd extends ButtplugDeviceMessage { | ||
static Name = 'StopDeviceCmd'; | ||
constructor( | ||
@@ -289,2 +308,4 @@ public DeviceIndex: number = -1, | ||
export class StopAllDevices extends ButtplugMessage { | ||
static Name = 'StopAllDevices'; | ||
constructor(public Id: number = DEFAULT_MESSAGE_ID) { | ||
@@ -310,2 +331,4 @@ super(Id); | ||
export class ScalarCmd extends ButtplugDeviceMessage { | ||
static Name = 'ScalarCmd'; | ||
constructor( | ||
@@ -327,2 +350,4 @@ public Scalars: ScalarSubcommand[], | ||
export class RotateCmd extends ButtplugDeviceMessage { | ||
static Name = 'RotateCmd'; | ||
public static Create( | ||
@@ -358,2 +383,4 @@ deviceIndex: number, | ||
export class LinearCmd extends ButtplugDeviceMessage { | ||
static Name = 'LinearCmd'; | ||
public static Create( | ||
@@ -383,2 +410,4 @@ deviceIndex: number, | ||
export class SensorReadCmd extends ButtplugDeviceMessage { | ||
static Name = 'SensorReadCmd'; | ||
constructor( | ||
@@ -395,2 +424,4 @@ public DeviceIndex: number, | ||
export class SensorReading extends ButtplugDeviceMessage { | ||
static Name = 'SensorReading'; | ||
constructor( | ||
@@ -408,2 +439,4 @@ public DeviceIndex: number, | ||
export class RawReadCmd extends ButtplugDeviceMessage { | ||
static Name = 'RawReadCmd'; | ||
constructor( | ||
@@ -421,2 +454,4 @@ public DeviceIndex: number, | ||
export class RawWriteCmd extends ButtplugDeviceMessage { | ||
static Name = 'RawWriteCmd'; | ||
constructor( | ||
@@ -434,2 +469,4 @@ public DeviceIndex: number, | ||
export class RawSubscribeCmd extends ButtplugDeviceMessage { | ||
static Name = 'RawSubscribeCmd'; | ||
constructor( | ||
@@ -445,2 +482,4 @@ public DeviceIndex: number, | ||
export class RawUnsubscribeCmd extends ButtplugDeviceMessage { | ||
static Name = 'RawUnsubscribeCmd'; | ||
constructor( | ||
@@ -456,2 +495,4 @@ public DeviceIndex: number, | ||
export class RawReading extends ButtplugDeviceMessage { | ||
static Name = 'RawReading'; | ||
constructor( | ||
@@ -458,0 +499,0 @@ public DeviceIndex: number, |
@@ -13,2 +13,13 @@ /*! | ||
function getMessageClass( | ||
type: string | ||
): (new (...args: unknown[]) => Messages.ButtplugMessage) | null { | ||
for (const value of Object.values(Messages)) { | ||
if (typeof value === 'function' && 'Name' in value && value.Name === type) { | ||
return value; | ||
} | ||
} | ||
return null; | ||
} | ||
export function FromJSON(str): Messages.ButtplugMessage[] { | ||
@@ -18,15 +29,14 @@ const msgarray: object[] = JSON.parse(str); | ||
for (const x of Array.from(msgarray)) { | ||
// Can't get this to resolve nicely as a type, so just start from any and cast | ||
// after. Not sure how to resolve plainToClass to a type since this is | ||
// dynamic. | ||
// | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const msg: any = plainToInstance( | ||
Messages[Object.getOwnPropertyNames(x)[0]], | ||
x[Object.getOwnPropertyNames(x)[0]] | ||
); | ||
(msg as Messages.ButtplugMessage).update(); | ||
msgs.push(msg as Messages.ButtplugMessage); | ||
const type = Object.getOwnPropertyNames(x)[0]; | ||
const cls = getMessageClass(type); | ||
if (cls) { | ||
const msg = plainToInstance<Messages.ButtplugMessage, unknown>( | ||
cls, | ||
x[type] | ||
); | ||
msg.update(); | ||
msgs.push(msg); | ||
} | ||
} | ||
return msgs; | ||
} |
@@ -12,2 +12,3 @@ /*! | ||
export * from './client/ButtplugBrowserWebsocketClientConnector'; | ||
export * from './client/ButtplugNodeWebsocketClientConnector'; | ||
export * from './client/ButtplugClientConnectorException'; | ||
@@ -14,0 +15,0 @@ export * from './utils/ButtplugMessageSorter'; |
@@ -17,2 +17,4 @@ /*! | ||
protected _ws: WebSocket | undefined; | ||
protected _websocketConstructor: typeof WebSocket | null = null; | ||
protected _filereaderConstructor: typeof FileReader | null = null; | ||
@@ -28,3 +30,3 @@ public constructor(private _url: string) { | ||
public Connect = async (): Promise<void> => { | ||
const ws = new WebSocket(this._url); | ||
const ws = new (this._websocketConstructor ?? WebSocket)(this._url); | ||
let res; | ||
@@ -86,3 +88,3 @@ let rej; | ||
} else if (event.data instanceof Blob) { | ||
const reader = new FileReader(); | ||
const reader = new (this._filereaderConstructor ?? FileReader)(); | ||
reader.addEventListener('load', (ev) => { | ||
@@ -89,0 +91,0 @@ this.OnReaderLoad(ev); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
3456189
148
12840
99
4
+ Addedfilereader@^0.10.3
+ Addedws@^8.12.0
+ Addedfilereader@0.10.3(transitive)
+ Addedws@8.18.0(transitive)