Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
*/
import * as noble from "noble-mac";
import { IDeviceSubtypeManager, ButtplugLogger, DeviceConfigurationManager,
BluetoothLEProtocolConfiguration, ButtplugDevice, ButtplugException,
ButtplugDeviceException } from "buttplug";
import { EventEmitter } from "events";
import { ButtplugNodeBluetoothLEDevice } from "./ButtplugNodeBluetoothLEDevice";
export class ButtplugNodeBluetoothLEDeviceManager extends EventEmitter implements IDeviceSubtypeManager {
private isScanning: boolean = false;
private initializerPromise: Promise | null;
// Set to default logger to make sure we have something at startup.
private logger: ButtplugLogger = ButtplugLogger.Logger;
constructor() {
super();
noble.on("discover", async (d: noble.Peripheral) => {
await this.OpenDevice(d);
});
}
public async Initialize() {
let res;
let rej;
this.initializerPromise = new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
noble.on("stateChange", function(state) {
private LogToConsole() {
ButtplugLogger.Logger.MaximumConsoleLogLevel = ButtplugLogLevel[commander.log as string];
}
constructor() {
this.logTextArea = document.getElementById("buttplugdevtoolslogtextarea")! as HTMLTextAreaElement;
this.panelLevelSelect = document.getElementById("buttplugdevtoolsloglevelpanelselect")! as HTMLSelectElement;
this.consoleLevelSelect = document.getElementById("buttplugdevtoolsloglevelconsoleselect")! as HTMLSelectElement;
const log = ButtplugLogger.Logger;
log.addListener("log", (msg) => {
this.addLogMessage(msg);
});
this.panelLevelSelect.addEventListener("change", () => {
log.MaximumEventLogLevel = ButtplugLogLevel[this.panelLevelSelect.value];
});
this.consoleLevelSelect.addEventListener("change", () => {
log.MaximumConsoleLogLevel = ButtplugLogLevel[this.consoleLevelSelect.value];
});
log.MaximumEventLogLevel = ButtplugLogLevel.Debug;
log.Debug("LogPanel: DevTools Log panel enabled.");
}
this.wsClient.on("error", (e) =>
ButtplugLogger.Logger.Info("Websocket Error (Happens on close, possibly ignorable): " + e));
res();
public static ShowTestDeviceManagerPanel(buttplugServer: ButtplugServer) {
let tdm: TestDeviceSubtypeManager | null = null;
for (const mgr of buttplugServer.DeviceManagers) {
if (mgr instanceof TestDeviceSubtypeManager) {
tdm = (mgr as TestDeviceSubtypeManager);
break;
}
}
if (tdm === null) {
ButtplugLogger.Logger.Error("TestDeviceSubtypeManagerPanel: Cannot get test device manager from server.");
throw new Error("Cannot get test device manager from server.");
}
jsPanel.jsPanel.create({
id: () => "buttplug-test-device-manager-panel",
theme: "primary",
headerTitle: "Test Device Manager",
position: "center-top 0 80",
contentSize: "400 250",
callback() {
this.content.innerHTML = testPanelHTML;
TestDeviceManagerPanel._panel = new TestDeviceManagerPanel(tdm!);
},
});
}