How to use the @ledgerhq/devices.getBluetoothServiceUuids function in @ledgerhq/devices

To help you get started, we’ve selected a few @ledgerhq/devices 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 / react-native-hw-transport-ble / src / BleTransport.js View on Github external
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 {
        characteristics = await device.characteristicsForService(uuid);
        res = getInfosForServiceUuid(uuid);
        break;
      } catch (e) {
        // we attempt to connect to service
      }
    }
  }
  if (!res) {
    throw new TransportError("service not found", "BLEServiceNotFound");
  }

  const { deviceModel, serviceUuid, writeUuid, notifyUuid } = res;

  if (!characteristics) {
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / BleTransport.js View on Github external
}

    log("ble-verbose", `open(${deviceOrId})`);

    await awaitsBleOn(bleManager);

    if (!device) {
      // works for iOS but not Android
      const devices = await bleManager.devices([deviceOrId]);
      log("ble-verbose", `found ${devices.length} devices`);
      [device] = devices;
    }

    if (!device) {
      const connectedDevices = await bleManager.connectedDevices(
        getBluetoothServiceUuids()
      );
      const connectedDevicesFiltered = connectedDevices.filter(
        d => d.id === deviceOrId
      );
      log(
        "ble-verbose",
        `found ${connectedDevicesFiltered.length} connected devices`
      );
      [device] = connectedDevicesFiltered;
    }

    if (!device) {
      log("ble-verbose", `connectToDevice(${deviceOrId})`);
      try {
        device = await bleManager.connectToDevice(deviceOrId, connectOptions);
      } catch (e) {
github LedgerHQ / ledger-live-desktop / src / hw-transport-node-ble / src / TransportNodeBLE.js View on Github external
if (!discoveredDevices[peripheral.uuid]) {
            discoveredDevices[peripheral.uuid] = peripheral
            observer.next({
              type: 'add',
              descriptor: peripheral,
              device: {
                id: peripheral.uuid,
                name: peripheral.advertisement.localName,
              },
            })
          }
        }
      }
      noble.addListener('discover', detectingDevices)

      noble.startScanning(getBluetoothServiceUuids(), allowDuplicates)

      function unsubscribe() {
        noble.removeListener('discover', detectingDevices)
        noble.stopScanning()
      }

      return unsubscribe
    }).subscribe(o)
  }
github LedgerHQ / ledgerjs / packages / hw-transport-web-ble / src / TransportWebBLE.js View on Github external
const requestDeviceParam = () => ({
  filters: getBluetoothServiceUuids().map(uuid => ({
    services: [uuid]
  }))
});
github LedgerHQ / ledgerjs / packages / hw-transport-node-ble / src / platform.js View on Github external
const { uuid: id } = peripheral;
      const { localName } = peripheral.advertisement;
      const name =
        localName ||
        (discoveredDevices[id] ? discoveredDevices[id].name : null);
      discoveredDevices[id] = { peripheral, name };
      log("ble-advertisement", id + " (" + String(name) + ")");
      observer.next({
        type: "add",
        descriptor: peripheral,
        device: { id, name }
      });
    };

    noble.addListener("discover", onDiscover);
    noble.startScanning(getBluetoothServiceUuids(), true);

    return () => {
      noble.removeListener("discover", onDiscover);
      noble.stopScanning();
    };
  });
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / BleTransport.js View on Github external
const stateSub = bleManager.onStateChange(async state => {
      if (state === "PoweredOn") {
        stateSub.remove();

        const devices = await bleManager.connectedDevices(
          getBluetoothServiceUuids()
        );
        if (unsubscribed) return;

        await Promise.all(
          devices.map(d => BluetoothTransport.disconnect(d.id).catch(() => {}))
        );
        if (unsubscribed) return;

        bleManager.startDeviceScan(
          getBluetoothServiceUuids(),
          null,
          (bleError, device) => {
            if (bleError) {
              observer.error(bleError);
              unsubscribe();
              return;
            }
            const res = retrieveInfos(device);
            const deviceModel = res && res.deviceModel;
            observer.next({ type: "add", descriptor: device, deviceModel });
          }
        );
      }
    }, true);
    const unsubscribe = () => {
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / BleTransport.js View on Github external
const stateSub = bleManager.onStateChange(async state => {
      if (state === "PoweredOn") {
        stateSub.remove();

        const devices = await bleManager.connectedDevices(
          getBluetoothServiceUuids()
        );
        if (unsubscribed) return;

        await Promise.all(
          devices.map(d => BluetoothTransport.disconnect(d.id).catch(() => {}))
        );
        if (unsubscribed) return;

        bleManager.startDeviceScan(
          getBluetoothServiceUuids(),
          null,
          (bleError, device) => {
            if (bleError) {
              observer.error(bleError);
              unsubscribe();
              return;