How to use the @abandonware/noble.state function in @abandonware/noble

To help you get started, we’ve selected a few @abandonware/noble 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 thegecko / webbluetooth / src / adapter.ts View on Github external
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);
            }
        });
    }
github LedgerHQ / ledgerjs / packages / hw-transport-node-ble / src / platform.js View on Github external
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);
  };
});
github thegecko / webbluetooth / src / adapter.ts View on Github external
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);
        }
    }
github CANDY-LINE / node-red-contrib-generic-ble / src / generic-ble.js View on Github external
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);
  }
}
github mKeRix / room-assistant / services / bluetooth.service.js View on Github external
.then(() => {
                    this.handleScanStateChange(noble.state);
                    this.handleAdvertiseStateChange(bleno.state);
                });
        },