Skip to content

Commit

Permalink
fix(ble): change signature for autoConnect (#2594)
Browse files Browse the repository at this point in the history
* fix(ble): change signature for autoConnect (#2573)

* fix(ble): update usage for autoConnect (#2573)
  • Loading branch information
don authored and danielsogl committed Jul 13, 2018
1 parent 12ddf96 commit d95a359
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/@ionic-native/plugins/ble/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d95a359

Please sign in to comment.