How to use the @ledgerhq/hw-transport-node-hid-noevents.getDevices function in @ledgerhq/hw-transport-node-hid-noevents

To help you get started, weā€™ve selected a few @ledgerhq/hw-transport-node-hid-noevents 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-node-hid-singleton / src / TransportNodeHid.js View on Github external
return Promise.resolve().then(() => {
      if (transportInstance) {
        log("hid-verbose", "reusing opened transport instance");
        return transportInstance;
      }

      const device = getDevices()[0];
      if (!device) throw new CantOpenDevice("no device found");
      log("hid-verbose", "new HID transport");
      transportInstance = new TransportNodeHidSingleton(
        new HID.HID(device.path)
      );
      const unlisten = listenDevices(
        () => {},
        () => {
          // assume any ledger disconnection concerns current transport
          if (transportInstance) {
            transportInstance.emit("disconnect");
          }
        }
      );
      const onDisconnect = () => {
        if (!transportInstance) return;
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid-singleton / src / TransportNodeHid.js View on Github external
static listen = (observer: Observer>): Subscription => {
    let unsubscribed;
    Promise.resolve(getDevices()).then(devices => {
      // this needs to run asynchronously so the subscription is defined during this phase
      for (const device of devices) {
        if (!unsubscribed) {
          const deviceModel = identifyUSBProductId(device.productId);
          observer.next({
            type: "add",
            descriptor: "",
            device: { name: device.deviceName },
            deviceModel
          });
        }
      }
    });

    const onAdd = device => {
      const deviceModel = identifyUSBProductId(device.productId);
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid / src / TransportNodeHid.js View on Github external
static listen = (
    observer: Observer>
  ): Subscription => {
    let unsubscribed = false;
    Promise.resolve(getDevices()).then(devices => {
      // this needs to run asynchronously so the subscription is defined during this phase
      for (const device of devices) {
        if (!unsubscribed) {
          const descriptor: string = device.path;
          const deviceModel = identifyUSBProductId(device.productId);
          observer.next({ type: "add", descriptor, device, deviceModel });
        }
      }
    });
    const { events, stop } = listenDevices(
      listenDevicesDebounce,
      listenDevicesPollingSkip
    );

    const onAdd = device => {
      if (unsubscribed || !device) return;
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid / src / listenDevices.js View on Github external
const poll = () => {
    if (!listenDevicesPollingSkip()) {
      log("hid-listen", "Polling for added or removed devices");

      let changeFound = false;
      const currentDevices = getFlatDevices();
      const newDevices = currentDevices.filter(d => !lastDevices.includes(d));

      if (newDevices.length > 0) {
        log("hid-listen", "New device found:", newDevices);

        listDevices = getDevices();
        events.emit("add", getDeviceByPaths(newDevices));

        changeFound = true;
      } else {
        log("hid-listen", "No new device found");
      }

      const removeDevices = lastDevices.filter(
        d => !currentDevices.includes(d)
      );

      if (removeDevices.length > 0) {
        log("hid-listen", "Removed device found:", removeDevices);

        events.emit("remove", getDeviceByPaths(removeDevices));
        listDevices = listDevices.filter(
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid / src / TransportNodeHid.js View on Github external
return Promise.resolve().then(() => {
      if (path) {
        return new TransportNodeHid(new HID.HID(path));
      }
      const device = getDevices()[0];
      if (!device) throw new TransportError("NoDevice", "NoDevice");
      return new TransportNodeHid(new HID.HID(device.path));
    });
  }
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid / src / listenDevices.js View on Github external
export default (
  delay: number,
  listenDevicesPollingSkip: () => boolean
): ({
  events: EventEmitter,
  stop: () => void
}) => {
  const events = new EventEmitter();
  events.setMaxListeners(0);

  let listDevices = getDevices();

  const flatDevice = d => d.path;

  const getFlatDevices = () => [
    ...new Set(getDevices().map(d => flatDevice(d)))
  ];

  const getDeviceByPaths = paths =>
    listDevices.find(d => paths.includes(flatDevice(d)));

  let lastDevices = getFlatDevices();

  const poll = () => {
    if (!listenDevicesPollingSkip()) {
      log("hid-listen", "Polling for added or removed devices");
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid / src / listenDevices.js View on Github external
const getFlatDevices = () => [
    ...new Set(getDevices().map(d => flatDevice(d)))
  ];

@ledgerhq/hw-transport-node-hid-noevents

Ledger Hardware Wallet Node implementation of the communication layer, using node-hid. without usb events

MIT
Latest version published 1 month ago

Package Health Score

90 / 100
Full package analysis