Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async scan () {
try {
const device = await TransportWebBLE.create()
if (!this.devices[device.id]) {
this.devices[device.id] = new Device(device, this.emit)
device.on('disconnect', () => {
this.devices[device.id].disconnect()
delete this.devices[device.id]
// remove list
this.emit('ledger:scan') // Request scan
})
}
} catch (e) {
console.log(e)
}
}
return new Promise((resolve, reject) => {
const subscription = TransportWebBLE.listen({
next(event: DescriptorEvent): void {
if (event.type === 'add') {
subscription.unsubscribe();
resolve(event.descriptor);
}
},
error(error: any): void {
reject(error);
},
complete(): void {
// noop
}
});
});
}
return new Promise((resolve, reject) => {
const subscription = TransportWebBLE.listen({
next(event: DescriptorEvent): void {
if (event.type === 'add') {
subscription.unsubscribe();
resolve(event.descriptor);
}
},
error(error: any): void {
reject(error);
},
complete(): void {
// noop
}
});
});
}
open: (id: string): ?Promise<*> => {
if (id.startsWith("webble")) {
const existingDevice = webbleDevices[id];
return existingDevice
? TransportWebBLE.open(existingDevice)
: TransportWebBLE.create();
}
return null;
},
private async getTransport(): Promise {
const device = await this.getDevice();
const transport = await TransportWebBLE.open(device);
transport.on('disconnect', () => {
this.transport = null;
});
return transport;
}
private async getTransport(): Promise {
const device = await this.getDevice();
const transport = await TransportWebBLE.open(device);
transport.on('disconnect', () => {
this.transport = null;
});
return transport;
}
open: (id: string): ?Promise<*> => {
if (id.startsWith("webble")) {
const existingDevice = webbleDevices[id];
return existingDevice
? TransportWebBLE.open(existingDevice)
: TransportWebBLE.create();
}
return null;
},