Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private OpenDevice = async (device: noble.Peripheral): Promise => {
if (device === undefined) {
// TODO Throw here?
return;
}
// If the device doesn't even have a name, chances are we aren't interested.
if (device.advertisement.localName === undefined) {
return;
}
const devConfig = new BluetoothLEProtocolConfiguration([device.advertisement.localName]);
const foundConfig = DeviceConfigurationManager.Manager.Find(devConfig);
if (foundConfig === undefined) {
return;
}
this.logger.Debug(`Found configuration for device ${device.advertisement.localName}`);
const [config, protocolType] = foundConfig;
const bpDevImpl = new ButtplugNodeBluetoothLEDevice(config as BluetoothLEProtocolConfiguration, device);
this.logger.Debug(`Connecting to noble device ${device.advertisement.localName}`);
try {
await bpDevImpl.Connect();
} catch (e) {
let errStr: string;
switch (e) {
case ButtplugDeviceException: {
errStr = e.errorMessage;
break;
}