Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
if (!device) {
throw new CantOpenDevice();
}
} else {
device = deviceOrId;
}
if (!(await device.isConnected())) {
log("ble-verbose", "not connected. connecting...");
try {
await device.connect(connectOptions);
} catch (e) {
if (e.errorCode === BleErrorCode.DeviceMTUChangeFailed) {
// eslint-disable-next-line require-atomic-updates
connectOptions = {};
await device.connect();
} else {
throw e;
}
}
}
await device.discoverAllServicesAndCharacteristics();
let res = retrieveInfos(device);
let characteristics;
if (!res) {
for (const uuid of getBluetoothServiceUuids()) {
try {
if (!device) {
throw new CantOpenDevice();
}
} else {
device = deviceOrId;
}
if (!(await device.isConnected())) {
logSubject.next({
type: "verbose",
message: "not connected. connecting...",
});
try {
await device.connect(connectOptions);
} catch (e) {
if (e.errorCode === BleErrorCode.DeviceMTUChangeFailed) {
connectOptions = {};
await device.connect();
} else {
throw e;
}
}
}
await device.discoverAllServicesAndCharacteristics();
const characteristics = await device.characteristicsForService(ServiceUuid);
if (!characteristics) {
throw new TransportError("service not found", "BLEServiceNotFound");
}
let writeC;
let notifyC;