Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
log("ble-frame", "<= " + value.toString("hex"));
}),
share()
);
const notif = notifyObservable.subscribe();
const transport = new BluetoothTransport(
device,
writeC,
notifyObservable,
deviceModel
);
if (!device.gatt.connected) {
throw new DisconnectedDevice();
}
// eslint-disable-next-line require-atomic-updates
transportsCache[transport.id] = transport;
const onDisconnect = e => {
console.log("onDisconnect!", e);
delete transportsCache[transport.id];
transport.notYetDisconnected = false;
notif.unsubscribe();
device.removeEventListener("gattserverdisconnected", onDisconnect);
log("ble-verbose", `BleTransport(${transport.id}) disconnected`);
transport.emit("disconnect", e);
};
device.addEventListener("gattserverdisconnected", onDisconnect);
let beforeMTUTime = Date.now();
tap(value => {
logSubject.next({
type: 'ble-frame-read',
message: value.toString('hex'),
})
}),
share(),
)
const notif = notifyObservable.subscribe()
const deviceModel = null // FIXME
const transport = new BluetoothTransport(device, writeC, notifyObservable, deviceModel)
if (device.state === 'disconnected') {
throw new DisconnectedDevice()
}
transportsCache[transport.id] = transport
const onDisconnect = e => {
delete transportsCache[transport.id]
transport.notYetDisconnected = false
notif.unsubscribe()
device.removeListener('disconnect', onDisconnect)
logSubject.next({
type: 'verbose',
message: `BleTransport(${transport.id}) disconnected`,
})
transport.emit('disconnect', e)
}
device.addListener('disconnect', onDisconnect) // will it catch their own "on" events? peripheral.once('disconnect', callback);
setErrorRemapping(e => {
// NB ideally we should solve it in ledgerjs
if (e && e.message && e.message.indexOf('HID') >= 0) {
return throwError(new DisconnectedDevice(e.message))
}
return throwError(e)
})
const onDisconnect = e => {
if (device === e.device) {
// $FlowFixMe
navigator.usb.removeEventListener("disconnect", onDisconnect);
transport._emitDisconnect(new DisconnectedDevice());
}
};
// $FlowFixMe
const onDisconnect = e => {
if (device === e.device) {
getHID().removeEventListener("disconnect", onDisconnect);
transport._emitDisconnect(new DisconnectedDevice());
}
};
getHID().addEventListener("disconnect", onDisconnect);
static async open(deviceObj: DeviceObj) {
try {
const nativeObj = await NativeModules.HID.openDevice(deviceObj);
return new HIDTransport(nativeObj.id);
} catch (error) {
if (disconnectedErrors.includes(error.message)) {
throw new DisconnectedDevice(error.message);
}
throw error;
}
}
this.device.read((e, res) => {
if (!res) {
return reject(new DisconnectedDevice());
}
if (e) {
if (isDisconnectedError(e)) {
this.setDisconnected();
return reject(new DisconnectedDevice(e.message));
}
reject(e);
} else {
const buffer = Buffer.from(res);
resolve(buffer);
}
})
);
this.device.read((e, res) => {
if (!res) {
return reject(new DisconnectedDevice());
}
if (e) {
if (isDisconnectedError(e)) {
this.setDisconnected();
return reject(new DisconnectedDevice(e.message));
}
reject(e);
} else {
const buffer = Buffer.from(res);
resolve(buffer);
}
})
);
complete: () => {
o.error(new DisconnectedDevice());
sub.unsubscribe();
},
error: e => {