How to use the @ledgerhq/errors.DisconnectedDevice function in @ledgerhq/errors

To help you get started, we’ve selected a few @ledgerhq/errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LedgerHQ / ledgerjs / packages / hw-transport-web-ble / src / TransportWebBLE.js View on Github external
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();
github LedgerHQ / ledger-live-desktop / src / hw-transport-node-ble / src / TransportNodeBLE.js View on Github external
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);
github LedgerHQ / ledger-live-desktop / src / helpers / live-common-setup-internal-hw.js View on Github external
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)
})
github LedgerHQ / ledgerjs / packages / hw-transport-webusb / src / TransportWebUSB.js View on Github external
const onDisconnect = e => {
      if (device === e.device) {
        // $FlowFixMe
        navigator.usb.removeEventListener("disconnect", onDisconnect);
        transport._emitDisconnect(new DisconnectedDevice());
      }
    };
    // $FlowFixMe
github LedgerHQ / ledgerjs / packages / hw-transport-webhid / src / TransportWebHID.js View on Github external
const onDisconnect = e => {
      if (device === e.device) {
        getHID().removeEventListener("disconnect", onDisconnect);
        transport._emitDisconnect(new DisconnectedDevice());
      }
    };
    getHID().addEventListener("disconnect", onDisconnect);
github LedgerHQ / ledgerjs / packages / react-native-hid / src / index.js View on Github external
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;
    }
  }
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid-noevents / src / TransportNodeHid.js View on Github external
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);
        }
      })
    );
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid-noevents / src / TransportNodeHid.js View on Github external
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);
        }
      })
    );
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / receiveAPDU.js View on Github external
complete: () => {
        o.error(new DisconnectedDevice());
        sub.unsubscribe();
      },
      error: e => {