2016-04-30 03:13:07 +08:00
|
|
|
import {Plugin, Cordova} from './plugin';
|
2016-06-03 22:05:07 +08:00
|
|
|
import {Observable} from 'rxjs/Observable';
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Bluetooth Serial
|
|
|
|
* @description This plugin enables serial communication over Bluetooth. It was written for communicating between Android or iOS and an Arduino.
|
|
|
|
* @usage
|
|
|
|
*/
|
|
|
|
@Plugin({
|
|
|
|
repo: 'https://github.com/don/BluetoothSerial',
|
|
|
|
plugin: 'cordova-plugin-bluetooth-serial',
|
2016-04-30 05:18:40 +08:00
|
|
|
pluginRef: 'bluetoothSerial',
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone', 'Browser']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
|
|
|
export class BluetoothSerial {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Connect to a Bluetooth device
|
2016-05-13 10:14:27 +08:00
|
|
|
* Returns an Observable. Subscribe to connect, unsubscribe to disconnect.
|
2016-04-30 03:13:07 +08:00
|
|
|
* @param macAddress_or_uuid Identifier of the remote device
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-05-13 10:14:27 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone'],
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'disconnect'
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-05-13 10:14:27 +08:00
|
|
|
static connect (macAddress_or_uuid: string): Observable<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Connect insecurely to a Bluetooth device
|
2016-05-13 10:14:27 +08:00
|
|
|
* Returns an Observable. Subscribe to connect, unsubscribe to disconnect.
|
2016-04-30 03:13:07 +08:00
|
|
|
* @param macAddress Identifier of the remote device
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-05-13 10:14:27 +08:00
|
|
|
platforms: ['Android'],
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'disconnect'
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-05-13 10:14:27 +08:00
|
|
|
static connectInsecure (macAddress: string): Observable<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes data to the serial port
|
|
|
|
* @param data ArrayBuffer of data
|
|
|
|
* @usage
|
|
|
|
* ```ts
|
|
|
|
* // Write a string
|
|
|
|
* Bluetooth.write("hello world").then(success, failure);
|
|
|
|
*
|
|
|
|
* // Array of int or bytes
|
|
|
|
* Bluetooth.write([186, 220, 222]).then(success, failure);
|
|
|
|
*
|
|
|
|
* // Typed Array
|
|
|
|
* var data = new Uint8Array(4);
|
|
|
|
* data[0] = 0x41;
|
|
|
|
* data[1] = 0x42;
|
|
|
|
* data[2] = 0x43;
|
|
|
|
* data[3] = 0x44;
|
|
|
|
* Bluetooth.write(data).then(success, failure);
|
|
|
|
*
|
|
|
|
* // Array Buffer
|
|
|
|
* Bluetooth.write(data.buffer).then(success, failure);
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static write (data: any): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the number of bytes of data available
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
|
|
|
}) static available (): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads data from the buffer
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static read (): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads data from the buffer until it reaches a delimiter
|
|
|
|
* @param delimiter
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static readUntil (delimiter: string): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Subscribe to be notified when data is received
|
|
|
|
* @param delimiter
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone'],
|
2016-04-30 03:13:07 +08:00
|
|
|
observable: true,
|
|
|
|
clearFunction: 'unsubscribe'
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static subscribe (delimiter: string): Observable<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Subscribe to be notified when data is received
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone'],
|
2016-04-30 03:13:07 +08:00
|
|
|
observable: true,
|
|
|
|
clearFunction: 'unsubscribeRawData'
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static subscribeRawData (): Observable<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears data in buffer
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static clear (): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists bonded devices
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static list (): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reports if bluetooth is enabled
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static isEnabled (): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reports the connection status
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static isConnected (): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the RSSI from the connected peripheral
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static readRSSI (): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the Bluetooth settings on the device
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static showBluetoothSettings (): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable Bluetooth on the device
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static enable (): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Discover unpaired devices
|
|
|
|
* @usage
|
|
|
|
* ```ts
|
|
|
|
* [{
|
|
|
|
* "class": 276,
|
|
|
|
* "id": "10:BF:48:CB:00:00",
|
|
|
|
* "address": "10:BF:48:CB:00:00",
|
|
|
|
* "name": "Nexus 7"
|
|
|
|
* }, {
|
|
|
|
* "class": 7936,
|
|
|
|
* "id": "00:06:66:4D:00:00",
|
|
|
|
* "address": "00:06:66:4D:00:00",
|
|
|
|
* "name": "RN42"
|
|
|
|
* }]
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone']
|
2016-04-30 03:13:07 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static discoverUnpaired (): Promise<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Subscribe to be notified on Bluetooth device discovery. Discovery process must be initiated with the `discoverUnpaired` function.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-04-30 11:56:49 +08:00
|
|
|
platforms: ['Android', 'iOS', 'Windows Phone'],
|
2016-04-30 03:13:07 +08:00
|
|
|
observable: true,
|
|
|
|
clearFunction: 'clearDeviceDiscoveredListener'
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static setDeviceDiscoveredListener (): Observable<any> {return; }
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the human readable device name that is broadcasted to other devices
|
|
|
|
* @param newName Desired name of device
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
platforms: ['Android'],
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static setName (newName: string): void {}
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes the device discoverable by other devices
|
|
|
|
* @param discoverableDuration Desired number of seconds device should be discoverable for
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
platforms: ['Android'],
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static setDiscoverable (discoverableDuration: number): void {}
|
2016-04-30 03:13:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-21 04:59:18 +08:00
|
|
|
}
|