Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.init(() => {
this.deviceHandles = {};
function stateCB() {
if (this.state === true) {
// Noble doesn't correctly match short and canonical UUIDs on Linux, so we need to check ourselves
// Continually scan to pick up all advertised UUIDs
noble.startScanning([], true, this.checkForError(errorFn, completeFn));
} else {
errorFn("adapter not enabled");
}
}
if (noble.state === "unknown" || noble.state === "poweredOff") {
// tslint:disable-next-line:no-string-literal
noble["once"]("stateChange", stateCB.bind(this));
} else {
stateCB.call(this);
}
});
}
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);
};
});
public getEnabled(completeFn: (enabled: boolean) => void) {
function stateCB() {
completeFn(this.state);
}
if (noble.state === "unknown" || noble.state === "poweredOff") {
// tslint:disable-next-line:no-string-literal
noble["once"]("stateChange", stateCB.bind(this));
} else {
stateCB.call(this);
}
}
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);
}
}
.then(() => {
this.handleScanStateChange(noble.state);
this.handleAdvertiseStateChange(bleno.state);
});
},