UNPKG

@nebulae/angular-ble

Version:

A Web Bluetooth (Bluetooth Low Energy) module for angular (v2+)

186 lines (185 loc) 9.2 kB
/// <reference types="web-bluetooth" /> import { EventEmitter } from '@angular/core'; import { Observable, Subject } from 'rxjs'; import { BrowserWebBluetooth } from '../platform/browser'; import { CypherAesService } from '../cypher/cypher-aes.service'; import { ConsoleLoggerService } from '../logger.service'; export declare class BluetoothService extends Subject<BluetoothService> { _webBle: BrowserWebBluetooth; private cypherAesService; _console: ConsoleLoggerService; _device$: EventEmitter<BluetoothDevice>; private device; private serviceCharacteristicVsSubscriptionList; private notifierSubject; private notifierStartedSubject; private bluetoothAvailable; constructor(_webBle: BrowserWebBluetooth, cypherAesService: CypherAesService, _console: ConsoleLoggerService); isBluetoothAvailable(): boolean; /** * get the current device, if the device return null is because the connection has lost * @returns the current connceted device */ getDevice$(): Observable<BluetoothDevice>; getNotifierStartedSubject$(): Subject<{}>; /** * start a stream by notifiers characteristics * @param service The service to which the characteristic belongs * @param characteristic The characteristic whose value you want to listen * @param options object that contains the * startByte:number (required), stopByte:number (required), * lengthPosition: { start: number, end: number, lengthPadding: number } (required) * @returns A DataView than contains the characteristic value */ startNotifierListener$(service: any, characteristic: any, options: any): Observable<string>; stopNotifierListener$(service: any, characteristic: any): Observable<string>; private buildNotifierListener$(service, characteristic, options); /** * Send a request to the device and wait a unique response * @param message Message to send * @param service The service to which the characteristic belongs * @param characteristic The characteristic whose value you want to send the message * @param responseType filter to use to identify the response, Sample: [{position: 3, byteToMatch: 0x83}, * {position: 13, byteToMatch: 0x45}] * @param cypherMasterKey master key to decrypt the message, only use this para if the message to receive is encrypted */ sendAndWaitResponse$(message: any, service: any, characteristic: any, responseType: any, cypherMasterKey?: any): Observable<any>; /** * Subscribe to the notifiers filtering by byte checking * @param filterOptions must specific the position and the byte to match Sample: * [{position: 3, byteToMatch: 0x83}, {position: 13, byteToMatch: 0x45}] * @param cypherMasterKey master key to decrypt the message, only use this para if the message to receive is encrypted */ subscribeToNotifierListener(filterOptions: any, cypherMasterKey?: any): Observable<any>; /** * Start a request to the browser to list all available bluetooth devices * @param options Options to request the devices the structure is: * acceptAllDevices: true|false * filters: BluetoothDataFilterInit (see https://webbluetoothcg.github.io/web-bluetooth/#dictdef-bluetoothlescanfilterinit for more info) * optionalServices: [] (services that are going to be used in * communication with the device, must use the UIID or GATT identfier to list ther services) */ private discoverDevice$(options?); private configureDeviceDisconnection$(device); /** * Discover all available devices and connect to a selected device * @param options Options to request the devices the structure is: * acceptAllDevices: true|false * filters: BluetoothDataFilterInit (see https://webbluetoothcg.github.io/web-bluetooth/#dictdef-bluetoothlescanfilterinit for more info) * optionalServices: [] (services that are going to be used in * communication with the device, must use the UIID or GATT identfier to list ther services) * @returns the connected device */ connectDevice$(options?: RequestDeviceOptions): Observable<never>; /** * Disconnect the current device */ disconnectDevice(): void; /** * get a data from the device using the characteristic * @param service UUID or GATT identifier service * @param characteristic UUID or GATT identifier characteristic * @return The characteristic data in a DataView object */ readDeviceValue$(service: any, characteristic: any): Observable<DataView>; /** * write a value in the selected characteristic * @param characteristic the characterisitc where you want write the value * @param value value the value to write */ writeDeviceValue$(service: any, characteristic: any, value: any): Observable<void>; /** * get a primary service instance using the service UIID or GATT identifier * @param service service identifier * @return service instance */ getPrimaryService$(service: BluetoothServiceUUID): Observable<BluetoothRemoteGATTService>; /** * Get a characterisitic instance using the service instance and a characteristic UUID * @param primaryService service instance * @param characteristic characterisitic identifier * @return characteristic instance */ getCharacteristic$(primaryService: BluetoothRemoteGATTService, characteristic: BluetoothCharacteristicUUID): Observable<void | BluetoothRemoteGATTCharacteristic>; /** * read the characteristic value * @param characteristic characteristic instance * @return The characteristic data in a DataView object */ private readValue$(characteristic); /** * write a value in the selected characteristic * @param characteristic the characterisitc where you want write the value * @param value the value to write */ private writeValue$(characteristic, value); /** * change the state of the characteristic to enable it * @param service parent service of the characteristic * @param characteristic characteristic to change the state * @param state new state */ enableCharacteristic$(service: BluetoothServiceUUID, characteristic: BluetoothCharacteristicUUID, state?: any): Observable<Observable<void>>; /** * change the state of the characteristic to disable it * @param service parent service of the characteristic * @param characteristic characteristic to change the state * @param state new state */ disbaleCharacteristic$(service: BluetoothServiceUUID, characteristic: BluetoothCharacteristicUUID, state?: any): Observable<Observable<void>>; /** * set a state to an specific characteristic * @param service parent service of the characteristic * @param characteristic characteristic to change the state * @param state new state * @return */ setCharacteristicState$(service: BluetoothServiceUUID, characteristic: BluetoothCharacteristicUUID, state: ArrayBuffer): Observable<Observable<void>>; /** * Send a message using a notifier characteristic * @param message message to send * @param service service to which the characteristic belongs * @param characteristic feature in which you want to send the notification */ sendToNotifier$(message: any, service: any, characteristic: any): Observable<any>; /** * The Battery Level characteristic is read using the GATT Read Characteristic * Value sub-procedure and returns the current battery level as a percentage * from 0% to 100%; 0% represents a battery that is fully discharged, 100% * represents a battery that is fully charged */ getBatteryLevel$(): Observable<number>; /** * This characteristic represents the name of the manufacturer of the device. */ getManufacturerName$(): Observable<any>; /** * This characteristic represents the model number that is assigned by the device vendor. */ getModelNumber$(): Observable<any>; /** * This characteristic represents the serial number for a particular instance of the device. */ getSerialNumber$(): Observable<any>; /** * This characteristic represents the hardware revision for the hardware within the device. */ getHardwareRevision$(): Observable<any>; /** * This characteristic represents the firmware revision for the firmware within the device. */ getFirmwareRevision$(): Observable<any>; /** * This characteristic represents the software revision for the software within the device. */ getSoftwareRevision$(): Observable<any>; /** * This characteristic represents a structure containing an Organizationally Unique Identifier * (OUI) followed by a manufacturer-defined identifier and is unique for each individual instance of the product. */ getSystemId$(): Observable<DataView>; /** * The PnP_ID characteristic is a set of values used to create a device ID value that is unique for this device. */ getPnpId$(): Observable<DataView>; }