How to use the react-native-ble-plx.BleManager function in react-native-ble-plx

To help you get started, we’ve selected a few react-native-ble-plx 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 / index.js View on Github external
static listen(observer: *) {
    let bleManager;
    try {
      bleManager = new BleManager();
    } catch (e) {
      // basically for the tests to pass
      console.warn(e);
      return { unsubscribe: () => {} };
    }
    const unsubscribe = () => {
      sub.remove();
      bleManager.stopDeviceScan();
    };
    const onBleStateChange = (state: string) => {
      if (state === "PoweredOn") {
        bleManager.startDeviceScan(null, null, (bleError, device) => {
          if (bleError) {
            observer.error(bleError);
            unsubscribe();
            return;
github LedgerHQ / ledger-live-mobile / src / react-native-hw-transport-ble / BleTransport.js View on Github external
import type { Device, Characteristic } from "./types";
import { sendAPDU } from "./sendAPDU";
import { receiveAPDU } from "./receiveAPDU";
import { monitorCharacteristic } from "./monitorCharacteristic";
import { awaitsBleOn } from "./awaitsBleOn";

const ServiceUuid = "d973f2e0-b19e-11e2-9e96-0800200c9a66";
const WriteCharacteristicUuid = "d973f2e2-b19e-11e2-9e96-0800200c9a66";
const NotifyCharacteristicUuid = "d973f2e1-b19e-11e2-9e96-0800200c9a66";

let connectOptions = {
  requestMTU: 156,
};

const transportsCache = {};
const bleManager = new BleManager();

if (Config.BLE_LOG_LEVEL) bleManager.setLogLevel(Config.BLE_LOG_LEVEL);

/**
 * react-native bluetooth BLE implementation
 * @example
 * import BluetoothTransport from "@ledgerhq/react-native-hw-transport-ble";
 */
export default class BluetoothTransport extends Transport {
  static isSupported = (): Promise =>
    Promise.resolve(typeof BleManager === "function");

  /**
   * TODO could add this concept in all transports
   * observe event with { available: bool, type: string } // available is generic, type is specific
   * an event is emit once and then listened
github jolocom / smartwallet-app / src / ui / generic / bleScanner.tsx View on Github external
constructor(props: Props) {
    super(props)
    this.state = {
      devices: {},
    }
    this.ble = new BleManager()
    this.ble.startDeviceScan(
      [serialUUIDs.serviceUUID],
      null,
      (error, device) => {
        if (error) console.log(error.toString())

        if (device && device.name) {
          this.setState({
            devices: {
              ...this.state.devices,
              [device.id]: device.name,
            },
          })
        }
      },
    )
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / BleTransport.js View on Github external
import {
  CantOpenDevice,
  TransportError,
  DisconnectedDeviceDuringOperation
} from "@ledgerhq/errors";
import type { Device, Characteristic } from "./types";
import { monitorCharacteristic } from "./monitorCharacteristic";
import { awaitsBleOn } from "./awaitsBleOn";
import { decoratePromiseErrors, remapError } from "./remapErrors";

let connectOptions = {
  requestMTU: 156
};

const transportsCache = {};
const bleManager = new BleManager();

const retrieveInfos = device => {
  if (!device || !device.serviceUUIDs) return;
  const [serviceUUID] = device.serviceUUIDs;
  if (!serviceUUID) return;
  const infos = getInfosForServiceUuid(serviceUUID);
  if (!infos) return;
  return infos;
};

type ReconnectionConfig = {
  pairingThreshold: number,
  delayAfterFirstPairing: number
};
let reconnectionConfig: ?ReconnectionConfig = {
  pairingThreshold: 1000,