fix: buttplug lint errors
This commit is contained in:
@@ -51,7 +51,7 @@ export default ts.config(
|
|||||||
"**/dist/",
|
"**/dist/",
|
||||||
"**/node_modules/",
|
"**/node_modules/",
|
||||||
"**/migrations/",
|
"**/migrations/",
|
||||||
"packages/buttplug/**",
|
"**/wasm/",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import { IButtplugClientConnector } from "./IButtplugClientConnector";
|
import { type IButtplugClientConnector } from "./IButtplugClientConnector";
|
||||||
import { ButtplugMessage } from "../core/Messages";
|
import { type ButtplugMessage } from "../core/Messages";
|
||||||
import { ButtplugBrowserWebsocketConnector } from "../utils/ButtplugBrowserWebsocketConnector";
|
import { ButtplugBrowserWebsocketConnector } from "../utils/ButtplugBrowserWebsocketConnector";
|
||||||
|
|
||||||
export class ButtplugBrowserWebsocketClientConnector
|
export class ButtplugBrowserWebsocketClientConnector
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
import { ButtplugLogger } from "../core/Logging";
|
import { ButtplugLogger } from "../core/Logging";
|
||||||
import { EventEmitter } from "eventemitter3";
|
import { EventEmitter } from "eventemitter3";
|
||||||
import { ButtplugClientDevice } from "./ButtplugClientDevice";
|
import { ButtplugClientDevice } from "./ButtplugClientDevice";
|
||||||
import { IButtplugClientConnector } from "./IButtplugClientConnector";
|
import { type IButtplugClientConnector } from "./IButtplugClientConnector";
|
||||||
import { ButtplugMessageSorter } from "../utils/ButtplugMessageSorter";
|
import { ButtplugMessageSorter } from "../utils/ButtplugMessageSorter";
|
||||||
import * as Messages from "../core/Messages";
|
import * as Messages from "../core/Messages";
|
||||||
import { ButtplugError, ButtplugInitError, ButtplugMessageError } from "../core/Exceptions";
|
import { ButtplugError, ButtplugInitError, ButtplugMessageError } from "../core/Exceptions";
|
||||||
@@ -158,7 +158,7 @@ export class ButtplugClient extends EventEmitter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private parseDeviceList = (list: Messages.DeviceList) => {
|
private parseDeviceList = (list: Messages.DeviceList) => {
|
||||||
for (let [_, d] of Object.entries(list.Devices)) {
|
for (const [_, d] of Object.entries(list.Devices)) {
|
||||||
if (!this._devices.has(d.DeviceIndex)) {
|
if (!this._devices.has(d.DeviceIndex)) {
|
||||||
const device = ButtplugClientDevice.fromMsg(d, this.sendMessageClosure);
|
const device = ButtplugClientDevice.fromMsg(d, this.sendMessageClosure);
|
||||||
this._logger.Debug(`ButtplugClient: Adding Device: ${device}`);
|
this._logger.Debug(`ButtplugClient: Adding Device: ${device}`);
|
||||||
@@ -168,8 +168,8 @@ export class ButtplugClient extends EventEmitter {
|
|||||||
this._logger.Debug(`ButtplugClient: Device already added: ${d}`);
|
this._logger.Debug(`ButtplugClient: Device already added: ${d}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let [index, device] of this._devices.entries()) {
|
for (const [index, device] of this._devices.entries()) {
|
||||||
if (!list.Devices.hasOwnProperty(index.toString())) {
|
if (!Object.prototype.hasOwnProperty.call(list.Devices, index.toString())) {
|
||||||
this._devices.delete(index);
|
this._devices.delete(index);
|
||||||
this.emit("deviceremoved", device);
|
this.emit("deviceremoved", device);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import * as Messages from "../core/Messages";
|
|||||||
import { ButtplugDeviceError, ButtplugError, ButtplugMessageError } from "../core/Exceptions";
|
import { ButtplugDeviceError, ButtplugError, ButtplugMessageError } from "../core/Exceptions";
|
||||||
import { EventEmitter } from "eventemitter3";
|
import { EventEmitter } from "eventemitter3";
|
||||||
import { ButtplugClientDeviceFeature } from "./ButtplugClientDeviceFeature";
|
import { ButtplugClientDeviceFeature } from "./ButtplugClientDeviceFeature";
|
||||||
import { DeviceOutputCommand } from "./ButtplugClientDeviceCommand";
|
import { type DeviceOutputCommand } from "./ButtplugClientDeviceCommand";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an abstract device, capable of taking certain kinds of messages.
|
* Represents an abstract device, capable of taking certain kinds of messages.
|
||||||
@@ -105,14 +105,22 @@ export class ButtplugClientDevice extends EventEmitter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected isOutputValid(featureIndex: number, type: Messages.OutputType) {
|
protected isOutputValid(featureIndex: number, type: Messages.OutputType) {
|
||||||
if (!this._deviceInfo.DeviceFeatures.hasOwnProperty(featureIndex.toString())) {
|
if (
|
||||||
|
!Object.prototype.hasOwnProperty.call(
|
||||||
|
this._deviceInfo.DeviceFeatures,
|
||||||
|
featureIndex.toString(),
|
||||||
|
)
|
||||||
|
) {
|
||||||
throw new ButtplugDeviceError(
|
throw new ButtplugDeviceError(
|
||||||
`Feature index ${featureIndex} does not exist for device ${this.name}`,
|
`Feature index ${featureIndex} does not exist for device ${this.name}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs !== undefined &&
|
this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs !== undefined &&
|
||||||
!this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs.hasOwnProperty(type)
|
!Object.prototype.hasOwnProperty.call(
|
||||||
|
this._deviceInfo.DeviceFeatures[featureIndex.toString()].Outputs,
|
||||||
|
type,
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
throw new ButtplugDeviceError(
|
throw new ButtplugDeviceError(
|
||||||
`Feature index ${featureIndex} does not support type ${type} for device ${this.name}`,
|
`Feature index ${featureIndex} does not support type ${type} for device ${this.name}`,
|
||||||
@@ -139,8 +147,8 @@ export class ButtplugClientDevice extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async runOutput(cmd: DeviceOutputCommand): Promise<void> {
|
public async runOutput(cmd: DeviceOutputCommand): Promise<void> {
|
||||||
let p: Promise<void>[] = [];
|
const p: Promise<void>[] = [];
|
||||||
for (let f of this._features.values()) {
|
for (const f of this._features.values()) {
|
||||||
if (f.hasOutput(cmd.outputType)) {
|
if (f.hasOutput(cmd.outputType)) {
|
||||||
p.push(f.runOutput(cmd));
|
p.push(f.runOutput(cmd));
|
||||||
}
|
}
|
||||||
@@ -164,11 +172,14 @@ export class ButtplugClientDevice extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async battery(): Promise<number> {
|
public async battery(): Promise<number> {
|
||||||
let p: Promise<void>[] = [];
|
const _p: Promise<void>[] = [];
|
||||||
for (let f of this._features.values()) {
|
for (const f of this._features.values()) {
|
||||||
if (f.hasInput(Messages.InputType.Battery)) {
|
if (f.hasInput(Messages.InputType.Battery)) {
|
||||||
// Right now, we only have one battery per device, so assume the first one we find is it.
|
// Right now, we only have one battery per device, so assume the first one we find is it.
|
||||||
let response = await f.runInput(Messages.InputType.Battery, Messages.InputCommandType.Read);
|
const response = await f.runInput(
|
||||||
|
Messages.InputType.Battery,
|
||||||
|
Messages.InputCommandType.Read,
|
||||||
|
);
|
||||||
if (response === undefined) {
|
if (response === undefined) {
|
||||||
throw new ButtplugMessageError("Got incorrect message back.");
|
throw new ButtplugMessageError("Got incorrect message back.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class PercentOrSteps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static createSteps(s: number): PercentOrSteps {
|
public static createSteps(s: number): PercentOrSteps {
|
||||||
let v = new PercentOrSteps();
|
const v = new PercentOrSteps();
|
||||||
v._steps = s;
|
v._steps = s;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ class PercentOrSteps {
|
|||||||
throw new ButtplugDeviceError(`Percent value ${p} is not in the range 0.0 <= x <= 1.0`);
|
throw new ButtplugDeviceError(`Percent value ${p} is not in the range 0.0 <= x <= 1.0`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let v = new PercentOrSteps();
|
const v = new PercentOrSteps();
|
||||||
v._percent = p;
|
v._percent = p;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ButtplugDeviceError, ButtplugError, ButtplugMessageError } from "../core/Exceptions";
|
import { ButtplugDeviceError, ButtplugError, ButtplugMessageError } from "../core/Exceptions";
|
||||||
import * as Messages from "../core/Messages";
|
import * as Messages from "../core/Messages";
|
||||||
import { DeviceOutputCommand } from "./ButtplugClientDeviceCommand";
|
import { type DeviceOutputCommand } from "./ButtplugClientDeviceCommand";
|
||||||
|
|
||||||
export class ButtplugClientDeviceFeature {
|
export class ButtplugClientDeviceFeature {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -26,7 +26,10 @@ export class ButtplugClientDeviceFeature {
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected isOutputValid(type: Messages.OutputType) {
|
protected isOutputValid(type: Messages.OutputType) {
|
||||||
if (this._feature.Output !== undefined && !this._feature.Output.hasOwnProperty(type)) {
|
if (
|
||||||
|
this._feature.Output !== undefined &&
|
||||||
|
!Object.prototype.hasOwnProperty.call(this._feature.Output, type)
|
||||||
|
) {
|
||||||
throw new ButtplugDeviceError(
|
throw new ButtplugDeviceError(
|
||||||
`Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}`,
|
`Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}`,
|
||||||
);
|
);
|
||||||
@@ -34,7 +37,10 @@ export class ButtplugClientDeviceFeature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected isInputValid(type: Messages.InputType) {
|
protected isInputValid(type: Messages.InputType) {
|
||||||
if (this._feature.Input !== undefined && !this._feature.Input.hasOwnProperty(type)) {
|
if (
|
||||||
|
this._feature.Input !== undefined &&
|
||||||
|
!Object.prototype.hasOwnProperty.call(this._feature.Input, type)
|
||||||
|
) {
|
||||||
throw new ButtplugDeviceError(
|
throw new ButtplugDeviceError(
|
||||||
`Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}`,
|
`Feature index ${this._feature.FeatureIndex} does not support type ${type} for device ${this._deviceName}`,
|
||||||
);
|
);
|
||||||
@@ -48,7 +54,7 @@ export class ButtplugClientDeviceFeature {
|
|||||||
throw new ButtplugDeviceError(`${command.outputType} requires value defined`);
|
throw new ButtplugDeviceError(`${command.outputType} requires value defined`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let type = command.outputType;
|
const type = command.outputType;
|
||||||
let duration: undefined | number = undefined;
|
let duration: undefined | number = undefined;
|
||||||
if (type == Messages.OutputType.HwPositionWithDuration) {
|
if (type == Messages.OutputType.HwPositionWithDuration) {
|
||||||
if (command.duration === undefined) {
|
if (command.duration === undefined) {
|
||||||
@@ -57,18 +63,18 @@ export class ButtplugClientDeviceFeature {
|
|||||||
duration = command.duration;
|
duration = command.duration;
|
||||||
}
|
}
|
||||||
let value: number;
|
let value: number;
|
||||||
let p = command.value;
|
const p = command.value;
|
||||||
if (p.percent === undefined) {
|
if (p.percent === undefined) {
|
||||||
// TODO Check step limits here
|
// TODO Check step limits here
|
||||||
value = command.value.steps!;
|
value = command.value.steps!;
|
||||||
} else {
|
} else {
|
||||||
value = Math.ceil(this._feature.Output[type]!.Value![1] * p.percent);
|
value = Math.ceil(this._feature.Output[type]!.Value![1] * p.percent);
|
||||||
}
|
}
|
||||||
let newCommand: Messages.DeviceFeatureOutput = { Value: value, Duration: duration };
|
const newCommand: Messages.DeviceFeatureOutput = { Value: value, Duration: duration };
|
||||||
let outCommand = {};
|
const outCommand = {};
|
||||||
outCommand[type.toString()] = newCommand;
|
outCommand[type.toString()] = newCommand;
|
||||||
|
|
||||||
let cmd: Messages.ButtplugMessage = {
|
const cmd: Messages.ButtplugMessage = {
|
||||||
OutputCmd: {
|
OutputCmd: {
|
||||||
Id: 1,
|
Id: 1,
|
||||||
DeviceIndex: this._deviceIndex,
|
DeviceIndex: this._deviceIndex,
|
||||||
@@ -111,14 +117,14 @@ export class ButtplugClientDeviceFeature {
|
|||||||
|
|
||||||
public hasOutput(type: Messages.OutputType): boolean {
|
public hasOutput(type: Messages.OutputType): boolean {
|
||||||
if (this._feature.Output !== undefined) {
|
if (this._feature.Output !== undefined) {
|
||||||
return this._feature.Output.hasOwnProperty(type.toString());
|
return Object.prototype.hasOwnProperty.call(this._feature.Output, type.toString());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasInput(type: Messages.InputType): boolean {
|
public hasInput(type: Messages.InputType): boolean {
|
||||||
if (this._feature.Input !== undefined) {
|
if (this._feature.Input !== undefined) {
|
||||||
return this._feature.Input.hasOwnProperty(type.toString());
|
return Object.prototype.hasOwnProperty.call(this._feature.Input, type.toString());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -126,7 +132,7 @@ export class ButtplugClientDeviceFeature {
|
|||||||
public async runOutput(cmd: DeviceOutputCommand): Promise<void> {
|
public async runOutput(cmd: DeviceOutputCommand): Promise<void> {
|
||||||
if (
|
if (
|
||||||
this._feature.Output !== undefined &&
|
this._feature.Output !== undefined &&
|
||||||
this._feature.Output.hasOwnProperty(cmd.outputType.toString())
|
Object.prototype.hasOwnProperty.call(this._feature.Output, cmd.outputType.toString())
|
||||||
) {
|
) {
|
||||||
return this.sendOutputCmd(cmd);
|
return this.sendOutputCmd(cmd);
|
||||||
}
|
}
|
||||||
@@ -139,7 +145,7 @@ export class ButtplugClientDeviceFeature {
|
|||||||
): Promise<Messages.InputReading | undefined> {
|
): Promise<Messages.InputReading | undefined> {
|
||||||
// Make sure the requested feature is valid
|
// Make sure the requested feature is valid
|
||||||
this.isInputValid(inputType);
|
this.isInputValid(inputType);
|
||||||
let inputAttributes = this._feature.Input[inputType];
|
const inputAttributes = this._feature.Input[inputType];
|
||||||
console.log(this._feature.Input);
|
console.log(this._feature.Input);
|
||||||
if (
|
if (
|
||||||
inputCommand === Messages.InputCommandType.Unsubscribe &&
|
inputCommand === Messages.InputCommandType.Unsubscribe &&
|
||||||
@@ -149,7 +155,7 @@ export class ButtplugClientDeviceFeature {
|
|||||||
throw new ButtplugDeviceError(`${inputType} does not support command ${inputCommand}`);
|
throw new ButtplugDeviceError(`${inputType} does not support command ${inputCommand}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let cmd: Messages.ButtplugMessage = {
|
const cmd: Messages.ButtplugMessage = {
|
||||||
InputCmd: {
|
InputCmd: {
|
||||||
Id: 1,
|
Id: 1,
|
||||||
DeviceIndex: this._deviceIndex,
|
DeviceIndex: this._deviceIndex,
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
|
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ButtplugMessage } from "../core/Messages";
|
import { type ButtplugMessage } from "../core/Messages";
|
||||||
import { EventEmitter } from "eventemitter3";
|
import { type EventEmitter } from "eventemitter3";
|
||||||
|
|
||||||
export interface IButtplugClientConnector extends EventEmitter {
|
export interface IButtplugClientConnector extends EventEmitter {
|
||||||
connect: () => Promise<void>;
|
connect: () => Promise<void>;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as Messages from "./Messages";
|
import * as Messages from "./Messages";
|
||||||
import { ButtplugLogger } from "./Logging";
|
import { type ButtplugLogger } from "./Logging";
|
||||||
|
|
||||||
export class ButtplugError extends Error {
|
export class ButtplugError extends Error {
|
||||||
public get ErrorClass(): Messages.ErrorClass {
|
public get ErrorClass(): Messages.ErrorClass {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export interface ButtplugMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function msgId(msg: ButtplugMessage): number {
|
export function msgId(msg: ButtplugMessage): number {
|
||||||
for (let [_, entry] of Object.entries(msg)) {
|
for (const [_, entry] of Object.entries(msg)) {
|
||||||
if (entry != undefined) {
|
if (entry != undefined) {
|
||||||
return entry.Id;
|
return entry.Id;
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ export function msgId(msg: ButtplugMessage): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setMsgId(msg: ButtplugMessage, id: number) {
|
export function setMsgId(msg: ButtplugMessage, id: number) {
|
||||||
for (let [_, entry] of Object.entries(msg)) {
|
for (const [_, entry] of Object.entries(msg)) {
|
||||||
if (entry != undefined) {
|
if (entry != undefined) {
|
||||||
entry.Id = id;
|
entry.Id = id;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
|
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ButtplugMessage } from "./core/Messages";
|
import { type ButtplugMessage } from "./core/Messages";
|
||||||
import { IButtplugClientConnector } from "./client/IButtplugClientConnector";
|
import { type IButtplugClientConnector } from "./client/IButtplugClientConnector";
|
||||||
import { EventEmitter } from "eventemitter3";
|
import { EventEmitter } from "eventemitter3";
|
||||||
|
|
||||||
export * from "./client/ButtplugClient";
|
export * from "./client/ButtplugClient";
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import { EventEmitter } from "eventemitter3";
|
import { EventEmitter } from "eventemitter3";
|
||||||
import { ButtplugMessage } from "../core/Messages";
|
import { type ButtplugMessage } from "../core/Messages";
|
||||||
|
|
||||||
export class ButtplugBrowserWebsocketConnector extends EventEmitter {
|
export class ButtplugBrowserWebsocketConnector extends EventEmitter {
|
||||||
protected _ws: WebSocket | undefined;
|
protected _ws: WebSocket | undefined;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export class ButtplugMessageSorter {
|
|||||||
public ParseIncomingMessages(msgs: Messages.ButtplugMessage[]): Messages.ButtplugMessage[] {
|
public ParseIncomingMessages(msgs: Messages.ButtplugMessage[]): Messages.ButtplugMessage[] {
|
||||||
const noMatch: Messages.ButtplugMessage[] = [];
|
const noMatch: Messages.ButtplugMessage[] = [];
|
||||||
for (const x of msgs) {
|
for (const x of msgs) {
|
||||||
let id = Messages.msgId(x);
|
const id = Messages.msgId(x);
|
||||||
if (id !== Messages.SYSTEM_MESSAGE_ID && this._waitingMsgs.has(id)) {
|
if (id !== Messages.SYSTEM_MESSAGE_ID && this._waitingMsgs.has(id)) {
|
||||||
const [res, rej] = this._waitingMsgs.get(id)!;
|
const [res, rej] = this._waitingMsgs.get(id)!;
|
||||||
this._waitingMsgs.delete(id);
|
this._waitingMsgs.delete(id);
|
||||||
|
|||||||
Reference in New Issue
Block a user