Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
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
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,
},
})
}
},
)
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,