fix(ble): change signature for autoConnect (#2594)

* fix(ble): change signature for autoConnect (#2573)

* fix(ble): update usage for autoConnect (#2573)
This commit is contained in:
Don Coleman 2018-07-13 11:06:17 -04:00 committed by Daniel Sogl
parent 12ddf96705
commit d95a359719

View File

@ -290,25 +290,34 @@ export class BLE extends IonicNativePlugin {
}
/**
* Establish an automatic connection to a peripheral.
* Establish an automatic connection to a peripheral. The phone will automatically connect to the Bluetooth peripheral
* whenever it is in range. The autoConnect function uses callbacks instead of observables because connect and
* disconnect can each be called many times as a devices connects and disconnects.
*
* On Android you can pass a MAC address directly to autoConnect. With iOS, you need to get a device id by scanning,
* calling ble.peripheralsWithIdentifiers, or calling ble.connectedPeripheralsWithServices.
*
* @usage
* ```
* BLE.autoConnect('12:34:56:78:9A:BC').subscribe(peripheralData => {
* console.log(peripheralData);
* },
* peripheralData => {
* console.log('disconnected');
* });
* someFunction() {
* this.ble.autoConnect(deviceId, onConnected.bind(this), onDisconnected.bind(this));
* }
*
* onConnected(peripheral) {
* console.log(`Connected to ${peripheral.id}`)l
* }
*
* onDisconnected(peripheral) {
* console.log(`Disconnected from ${peripheral.id}`)l
* }
*
* ```
* @param {string} deviceId UUID or MAC address of the peripheral
* @return {Observable<any>} Returns an Observable that notifies of connect/disconnect.
* @param {function} connectCallback function that is called with peripheral data when the devices connects
* @param {function} disconnectCallback function that is called with peripheral data when the devices disconnects
*/
@Cordova({
observable: true,
clearFunction: 'disconnect',
clearWithArgs: true
})
autoConnect(deviceId: string): Observable<any> {
@Cordova({ sync: true })
autoConnect(deviceId: string, connectCallback: any, disconnectCallback: any) {
return;
}