Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const availability: Observable = Observable.create(observer => {
const onAvailabilityChanged = e => {
observer.next(e === POWERED_ON);
};
noble.addListener("stateChanged", onAvailabilityChanged); // events lib?
observer.next(noble.state === POWERED_ON);
return () => {
noble.removeListener("stateChanged", onAvailabilityChanged);
};
});
const onDiscover = peripheral => {
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();
};
});
function startBLEScanning(RED) {
RED.log.info(`[GenericBLE] Start BLE scanning`);
if (!onDiscover) {
onDiscover = onDiscoverFunc(RED);
}
noble.removeListener('stateChange', onStateChange);
noble.removeListener('discover', onDiscover);
noble.addListener('stateChange', onStateChange);
noble.addListener('discover', onDiscover);
if (noble.state === 'poweredOn') {
noble.startScanning([], true);
}
}
function startBLEScanning(RED) {
RED.log.info(`[GenericBLE] Start BLE scanning`);
if (!onDiscover) {
onDiscover = onDiscoverFunc(RED);
}
noble.removeListener('stateChange', onStateChange);
noble.removeListener('discover', onDiscover);
noble.addListener('stateChange', onStateChange);
noble.addListener('discover', onDiscover);
if (noble.state === 'poweredOn') {
noble.startScanning([], true);
}
}