npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ble-wrapper

v1.4.0

Published

capacitor-community/bluetooth-le wrapper for quicker config. IOS/Android-native, & Web Bluetooth in one small package

Downloads

24

Readme

BLEClient wrapper class

npm i ble-wrapper

Convenience features for the @capacitor-community/bluetooth-le API for browser or native mobile usage without changing your code. See class usage below. Includes useful byte manipulation callbacks. 19.5kb dist

Instantiate with const BLE = new BLEClient(). See class details below.

The main dist includes a globalThis.BLEClient declaration for browser inclusion e.g. from jsdelivr. Only works in compatible browsers.


type DeviceOptions = {
    name?:string;
    namePrefix?: string;
    deviceId?: string;
    onConnect?: () => void;
    onDisconnect?: () => void;
    connectOptions?: TimeoutOptions;
    services: {
        [key: string]: { //service UUID
            UUID?:string, //define UUID here if not in object key (e.g. for easier reference keys e.g. 'heartrate')
            [key: string]: { //characteristic or a tagname
                characteristic?: string, //define characteristic here if not in object key
                read?: boolean;
                readOptions?: TimeoutOptions;
                readCallback?: ((result: DataView) => void);
                write?: string | number | ArrayBufferLike | DataView;
                writeOptions?: TimeoutOptions;
                writeCallback?: (() => void);
                notify?: boolean;
                notifyCallback?: ((result: DataView) => void);
                [key: string]: any;
            };
        };
    };
};

type DeviceInfo = {
    device: BleDevice;
    options: DeviceOptions;
};

class BLEClient {
    client: BleClientInterface;
    devices: {
        [key: string]: DeviceInfo;
    };
    location?: boolean;
    constructor(options: DeviceOptions, location?: boolean);
    setup(options: DeviceOptions, location?: boolean): Promise<DeviceInfo>;
    initialize(options: InitializeOptions): Promise<true>;
    requestDevice(request: RequestBleDeviceOptions, options: DeviceOptions): Promise<BleDevice>;
    setupDevice: (device: BleDevice, options: DeviceOptions) => Promise<DeviceInfo>;
    connect(device: BleDevice, options: DeviceOptions): Promise<BleDevice>;
    reconnect(deviceId: string): Promise<BleDevice>;
    disconnect(device: BleDevice): Promise<void>;
    write(device: BleDevice, service: string, characteristic: string, value: string | number | ArrayBufferLike | DataView | number[], callback?: () => void, options?: TimeoutOptions): Promise<void>;
    read(device: BleDevice, service: string, characteristic: string, ondata?: (result: DataView) => void, options?: TimeoutOptions): Promise<void> | Promise<DataView>;
    subscribe(device: BleDevice, service: string, characteristic: string, ondata: (result: DataView) => void): Promise<void>;
    unsubscribe(device: BleDevice, service: string, characteristic: string): Promise<void>;
    scan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void>;
    stopScanning(): Promise<void>;
    readDescriptor(device: BleDevice, service: string, characteristic: string, descriptor: string, options?: TimeoutOptions): Promise<DataView>;
    writeDescriptor(device: BleDevice, service: string, characteristic: string, descriptor: string, value: string | number | DataView | ArrayBufferLike | number[], options?: TimeoutOptions): Promise<void>;
    readRssi(device: BleDevice): Promise<number>;
    distance(device: BleDevice, txPower: any, x: number, exp: number, c: number): Promise<number>;
    distanceFromPhone(//https://github.com/kevindigi/android-iot-samples/blob/7fb4b91eb769a3dba06891286f4f2f3249dab2a6/app/src/main/java/com/digicorp/helper/DistanceManager.java#L48
    device: BleDevice, txPower: number, //signal strength at 1 meter, hardware-specific
    model?: string): Promise<number>;
    triangulate: (device: BleDevice, duration?: number, sampleRate?: number) => Promise<unknown>;
    static toDataView(value: string | number | ArrayBufferLike | DataView | number[]): DataView;
    static searchBuffer(buffer: number[] | ArrayBuffer, searchString: Uint8Array, limit?: number): any[];
    static bytesToInt16(x0: number, x1: number): number;
    static bytesToUInt16(x0: number, x1: number): number;
    static Uint16ToBytes(y: number): number[];
    static bytesToInt24(x0: number, x1: number, x2: number): number;
    static bytesToUInt24(x0: number, x1: number, x2: number): number;
    static Uint24ToBytes(y: number): number[];
    static bytesToInt32(x0: number, x1: number, x2: number, x3: number): number;
    static bytesToUInt32(x0: number, x1: number, x2: number, x3: number): number;
    static Uint32ToBytes(y: number): number[];
    static get2sCompliment(val: number, nbits: number): number;
    static getSignedInt(...args: number[]): number;
    static asUint8Array(input: any): Uint8Array;
    static boyerMoore(patternBuffer: any): any;
}

Build with tinybuild, or npm i -g tinybuild & tinybuild

Wrapper for @capacitor-community/bluetooth-le library just for quicker config of multiple devices/services with multiple characteristics per service and customizable responses to those characteristics.

Capacitor required to build mobile apps after bundling the library.

Capacitor instructions:

In your project root

npm i

Edit the index.js and optionally the index.html in the dist/ folder. All public asset files need to end up in dist/

Build step:

If no tinybuild installed globally: npm i -g tinybuild or to keep it in dev dependencies npm i --save-dev tinybuild

Build:

  • tinybuild

Android Studio (install it first)

  • npx cap copy or npx cap sync to sync the www/ dist to the platform-specific folders.
  • npx cap open android to open android studio ready to build and serve the apk.

Build the android project by click the Make Project hammer icon if it doesn't start automatically. Then if you see BUILD SUCCESSFUL, run with your android device connected or the built-in android emulators active.

XCode

  • npx cap copy or npx cap sync
  • npx cap open ios to open xcode ready to build and serve the app