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