How to use nativescript-bluetooth - 2 common examples

To help you get started, we’ve selected a few nativescript-bluetooth 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 EddyVerbruggen / nativescript-bluetooth / demo / app / main-view-model.ts View on Github external
constructor() {
        super();
        // enables the console.logs from the Bluetooth source code
        this._bluetooth.debug = true;

        // using an event listener instead of the 'onDiscovered' callback of 'startScanning'
        this._bluetooth.on(Bluetooth.device_discovered_event, (eventData: any) => {
            const perip = eventData.data as Peripheral;
            let index = -1;
            this.peripherals.some((p, i) => {
                if (p.UUID === perip.UUID) {
                    index = i;
                    return true;
                }
                return false;
            });
            console.log('Peripheral found:', JSON.stringify(eventData.data), index);
            if (index === -1) {
                this.peripherals.push(perip);
            } else {
                this.peripherals.setItem(index, perip);
            }
        });
github EddyVerbruggen / nativescript-bluetooth / demo-ng / app / services / bluetooth.service.ts View on Github external
import { Injectable, NgZone } from '@angular/core';
import { Observable, Subscription, fromEventPattern } from 'rxjs';
import { takeWhile } from 'rxjs/operators';
import * as dialogs from '@nativescript/core/ui/dialogs';
import { Bluetooth, Peripheral, Service, Characteristic, ReadResult } from 'nativescript-bluetooth';

const bluetooth = new Bluetooth();
bluetooth.debug = true;

export interface IPeripheral extends Peripheral {
    isConnected?: boolean;
}
export interface IService extends Service {
    peripheralRef?: IPeripheral; // retain a reference to the parent peripheral
}
export interface ICharacteristic extends Characteristic {
    serviceRef?: IService; // retain a reference to the parent service
    isExpandedView?: boolean; // toggle for view component to show/hide the read/write/notify properties
    isNotifying?: boolean;
    readResult?: CharOpResult;
    writeResult?: CharOpResult;
    writeWithoutResponseResult?: CharOpResult;
    notifyResult?: CharOpResult;

nativescript-bluetooth

Connect to and interact with Bluetooth LE peripherals

MIT
Latest version published 4 years ago

Package Health Score

52 / 100
Full package analysis