Update cordova-plugin-ble-central to 1.2.2 (latest)

Types were found via direct code inspection of plugin.
This commit is contained in:
Philip Peitsch
2019-01-04 15:36:30 +11:00
parent ba83f54a74
commit 5c8bc25eca
2 changed files with 72 additions and 33 deletions
@@ -62,10 +62,10 @@ var demoExtendedData : BLECentralPlugin.PeripheralDataExtended = {
//get updates about the bluethooth states
ble.startStateNotifications((state) => log(`BLE state ${state}`));
ble.isEnabled(()=> log(`bluetooth is enabled`), ()=>log(`bluetooth is not enabled`));
ble.isEnabled(()=> log(`bluetooth is enabled`), err =>log(`bluetooth is not enabled: ${err}`));
//here we try to enable bluetooth
ble.enable(() => log(`yes it worked, or it was already enabled `), () => log(`nope it didn't work, the user pressed cancel, or we are in iOS`));
ble.enable(() => log(`yes it worked, or it was already enabled `), err => log(`nope it didn't work, the user pressed cancel, or we are in iOS: ${err}`));
ble.showBluetoothSettings(() => log(`yes it worked`), () => log(`nope it didn't work`))
@@ -73,13 +73,14 @@ ble.showBluetoothSettings(() => log(`yes it worked`), () => log(`nope it didn't
ble.stopStateNotifications()
//scan 5 seconds
ble.scan([], 5000, (data) => { devices.push(data); }, ()=> log('couldn\'t connect') );
ble.scan([], 5000, (data) => { devices.push(data); }, () => log(`couldn't connect`) );
ble.scan([], 5000, (data) => { devices.push(data); }, err => log(`couldn't connect: ${err}`) );
//scan continously
ble.startScan([], (data) => { devices.push(data); }, ()=> log('couldn\'t connect') )
////scan continously
ble.startScanWithOptions([], {reportDuplicates:false }, (data) => { devices.push(data); }, ()=> log('couldn\'t connect') )
ble.startScanWithOptions([], {reportDuplicates:false }, (data) => { devices.push(data); }, err => log(`couldn't connect: ${err}`) )
//stop scanning
ble.stopScan(()=> log('all good'), ()=> log('couldn\'t stop scanning'));
@@ -89,18 +90,19 @@ ble.isConnected(demoDevice.id, () => log(`already connected to this device`), ()
//connect to a specific device
var extendedData : BLECentralPlugin.PeripheralDataExtended;
ble.connect(demoDevice.id, (data)=> extendedData = data, () => log(`couldn't connect to the device`) );
ble.connect(demoDevice.id, (data)=> extendedData = data, err => log(`couldn't connect to the device: ${err}`) );
//read some data from a characteristic
var charsOfOneOfItsServices = demoExtendedData.characteristics.filter((value) => value.service == demoExtendedData.services[0]);
ble.read(demoDevice.id, charsOfOneOfItsServices[0].service, charsOfOneOfItsServices[0].characteristic, (data) => log(`we've received some data`), ()=> log(`couldn't read any data`));
//read the rssi
ble.readRSSI(demoDevice.id, (rssi)=>log(`Device ${demoDevice.name} has an RSSI of ${rssi}`));
ble.readRSSI(demoDevice.id, (rssi)=>log(`Device ${demoDevice.name} has an RSSI of ${rssi}`), err => log(`Unable to read RSSI: ${err}`));
var notificationsReceived : number = 0;
//get notified of changes for that characteristic
ble.startNotification(demoDevice.id, charsOfOneOfItsServices[0].service, charsOfOneOfItsServices[0].characteristic, (data)=> notificationsReceived++, ()=> log(`darn`));
ble.startNotification(demoDevice.id, charsOfOneOfItsServices[0].service, charsOfOneOfItsServices[0].characteristic,
(data)=> notificationsReceived++, err => log(`darn: ${err}`));
//write some data
ble.write(demoDevice.id, charsOfOneOfItsServices[0].service, charsOfOneOfItsServices[0].characteristic, new ArrayBuffer(40), ()=> log(`all good`), ()=> log(`could't write`));
+63 -26
View File
@@ -1,12 +1,13 @@
// Type definitions for cordova-plugin-ble-central 1.1.2
// Type definitions for cordova-plugin-ble-central 1.2.2
// Project: https://github.com/don/cordova-plugin-ble-central
// Definitions by: Gidon Junge <https://github.com/gjunge>
// Philip Peitsch <https://github.com/peitschie>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace BLECentralPlugin {
interface PeripheralCharacteristic {
interface PeripheralCharacteristic {
service: string;
characteristic: string;
properties: string[];
@@ -26,7 +27,12 @@ declare namespace BLECentralPlugin {
characteristics: PeripheralCharacteristic[]
}
interface BLEError {
name: string;
id: string;
errorMessage: string;
}
interface StartScanOptions {
@@ -35,74 +41,105 @@ declare namespace BLECentralPlugin {
export interface BLECentralPluginStatic {
scan(services: string[], seconds: number, success : (data: PeripheralData) => any): void;
scan(services: string[], seconds: number, success : (data: PeripheralData) => any, failure : () => any): void;
scan(services: string[], seconds: number, success : (data: PeripheralData) => any, failure : (error: string) => any): void;
startScan(services: string[], success: (data: PeripheralData) => any): void;
startScan(services: string[], success: (data: PeripheralData) => any, failure: () => any): void;
startScan(services: string[], success: (data: PeripheralData) => any, failure: (error: string|BLEError) => any): void;
startScanWithOptions(services: string[], options: StartScanOptions, success: (data: PeripheralData) => any): void;
startScanWithOptions(services: string[], options: StartScanOptions, success: (data: PeripheralData) => any, failure: () => any): void;
startScanWithOptions(services: string[], options: StartScanOptions, success: (data: PeripheralData) => any, failure: (error: string) => any): void;
stopScan(): void;
stopScan(success: () => any): void;
stopScan(success: () => any, failure: () => any): void;
connect(device_id:string, success: (data: PeripheralDataExtended) => any, failure: () => any): void;
connect(device_id:string, success: (data: PeripheralDataExtended) => any, failure: (error: string|BLEError) => any): void;
/* Automatically connect to a device when it is in range of the phone
[iOS] background notifications on ios must be enabled if you want to run in the background
[Android] this relies on the autoConnect argument of BluetoothDevice.connectGatt(). Not all Android devices implement this feature correctly. */
autoConnect(device_id:string, success: (data: PeripheralDataExtended) => any, failure: (error: string|BLEError) => any): void;
disconnect(device_id:string): void;
disconnect(device_id:string, success: () => any): void;
disconnect(device_id:string, success: () => any, failure: () => any): void;
disconnect(device_id:string, success: () => any, failure: (error: string|BLEError) => any): void;
read(device_id: string, service_uuid:string, characteristic_uuid:string): void;
read(device_id: string, service_uuid:string, characteristic_uuid:string, success: (rawData: ArrayBuffer) => any): void;
read(device_id: string, service_uuid:string, characteristic_uuid:string, success: (rawData: ArrayBuffer) => any, failure: () => any): void;
read(device_id: string, service_uuid:string, characteristic_uuid:string, success: (rawData: ArrayBuffer) => any, failure: (error: string|BLEError) => any): void;
write(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer): void;
write(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer, success : () => any): void;
write(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer, success : () => any, failure: () => any): void;
write(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer, success : () => any, failure: (error: string|BLEError) => any): void;
/* Writes data to a characteristic without a response from the peripheral. You are not notified if the write fails in the BLE stack.
/* Writes data to a characteristic without a response from the peripheral. You are not notified if the write fails in the BLE stack.
The success callback is be called when the characteristic is written.*/
writeWithoutResponse(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer): void;
writeWithoutResponse(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer, success : () => any): void;
writeWithoutResponse(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer, success : () => any, failure: () => any): void;
writeWithoutResponse(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer, success : () => any, failure: (error: string) => any): void;
/* Register to be notified when the value of a characteristic changes. */
startNotification(device_id: string, service_uuid:string, characteristic_uuid:string, success: (rawData: ArrayBuffer) => any): void;
startNotification(device_id: string, service_uuid:string, characteristic_uuid:string, success: (rawData: ArrayBuffer) => any, failure: () => any): void;
startNotification(device_id: string, service_uuid:string, characteristic_uuid:string, success: (rawData: ArrayBuffer) => any, failure: (error: string|BLEError) => any): void;
stopNotification(device_id: string, service_uuid:string, characteristic_uuid:string): void;
stopNotification(device_id: string, service_uuid:string, characteristic_uuid:string, success: () => any): void;
stopNotification(device_id: string, service_uuid:string, characteristic_uuid:string, success: () => any, failure: () => any): void;
stopNotification(device_id: string, service_uuid:string, characteristic_uuid:string, success: () => any, failure: (error: string|BLEError) => any): void;
/* Reports if bluetooth is enabled. */
isEnabled(success: () => any , failure: () => any): void;
isEnabled(success: () => any , failure: (error: string) => any): void;
/* Calls the success callback when the peripheral is connected and the failure callback when not connected. */
isConnected(device_id: string, success: () => any): void;
isConnected(device_id: string, success: () => any, failure: () => any): void;
isConnected(device_id: string, success: () => any, failure: (error: string) => any): void;
/* May be used to request (on Android) a larger MTU size to be able to send more data at once
[iOS] requestMtu is not supported on iOS. */
requestMtu(device_id: string, mtu: number): void;
requestMtu(device_id: string, mtu: number, success: () => any): void;
requestMtu(device_id: string, mtu: number, success: () => any, failure: () => any): void;
/* Clears cached services and characteristics info for some poorly behaved devices. Uses an undocumented API,
so it is not guaranteed to work.
[iOS] refreshDeviceCache is not supported on iOS. */
refreshDeviceCache(device_id: string, timeout_millis: number): void;
refreshDeviceCache(device_id: string, timeout_millis: number, success: (data: PeripheralDataExtended) => any): void;
refreshDeviceCache(device_id: string, timeout_millis: number, success: (data: PeripheralDataExtended) => any, failure: (error: string|BLEError) => any): void;
startStateNotifications(success: (state: string) => any): void;
startStateNotifications(success: (state: string) => any, failure: () => any): void;
startStateNotifications(success: (state: string) => any, failure: (error: string) => any): void;
stopStateNotifications(): void;
stopStateNotifications(success: () => any): void;
stopStateNotifications(success: () => any, failure: () => any): void;
/* Opens the Bluetooth settings for the operating systems.
[iOS] showBluetoothSettings is not supported on iOS. */
showBluetoothSettings(): void;
showBluetoothSettings(success: () => any): void;
showBluetoothSettings(success: () => any, failure: () => any): void;
/* Enable Bluetooth on the device.
[iOS] enable is not supported on iOS. */
enable(success: () => any, failure: () => any): void;
enable(success: () => any, failure: (error: string) => any): void;
readRSSI(device_id:string, success: (rssi: number) => any): void;
readRSSI(device_id:string, success: (rssi: number) => any, failure: () => any): void;
readRSSI(device_id:string, success: (rssi: number) => any, failure: (error: string) => any): void;
/* Find connected peripherals offering the listed service UUIDs.
This function wraps CBCentralManager.retrieveConnectedPeripheralsWithServices.
[Android] peripheralsWithIdentifiers is not supported on Android. */
connectedPeripheralsWithServices(services: string[], success: (data: PeripheralData[]) => any, failure: () => any): void;
/* Find known (but not necessarily connected) peripherals offering the listed service UUIDs.
This function wraps CBCentralManager.retrievePeripheralsWithIdentifiers
[Android] peripheralsWithIdentifiers is not supported on Android. */
peripheralsWithIdentifiers(services: string[], success: (data: PeripheralData[]) => any, failure: () => any): void;
/* Find the bonded devices.
[iOS] bondedDevices is not supported on iOS. */
bondedDevices(success: (data: PeripheralData[]) => any, failure: () => any): void;
}
}
declare var ble: BLECentralPlugin.BLECentralPluginStatic;
declare var ble: BLECentralPlugin.BLECentralPluginStatic;