From b3d5baa46ed695344b08bd3e27be3b9f84bf6f0d Mon Sep 17 00:00:00 2001 From: Hans Krywalsky Date: Thu, 19 Nov 2020 08:34:14 +0100 Subject: [PATCH] feat(bluetooth-le): Allow specifying transport mode for Android (#3571) --- .../plugins/bluetooth-le/index.ts | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/@ionic-native/plugins/bluetooth-le/index.ts b/src/@ionic-native/plugins/bluetooth-le/index.ts index 4c378008f..8e73a03cd 100644 --- a/src/@ionic-native/plugins/bluetooth-le/index.ts +++ b/src/@ionic-native/plugins/bluetooth-le/index.ts @@ -99,6 +99,38 @@ export interface RespondParams { offset?: number; } +export interface ConnectionParams { + /** The address/identifier provided by the scan's return object */ + address: string; + /** Automatically connect as soon as the remote device becomes available (Android) */ + autoConnect?: boolean; + /** + * Transport mode. Available from API 23 (Android). + * If none is specified the default behavior is TRANSPORT_AUTO + * + * Note: On Android 10, TRANSPORT_AUTO can lead to connection errors with Status code 133. + * In this case TRANSPORT_LE can be used. + */ + transport?: AndroidGattTransportMode; +} + +export enum AndroidGattTransportMode { + /** + * No preference of physical transport for GATT connections to remote dual-mode devices + */ + TRANSPORT_AUTO = 0, + + /** + * Prefer BR/EDR transport for GATT connections to remote dual-mode devices + */ + TRANSPORT_BREDR = 1, + + /** + * Prefer LE transport for GATT connections to remote dual-mode devices + */ + TRANSPORT_LE = 2, +} + export interface CharacteristicParams extends Params { /** An array of characteristic IDs to discover or empty array / null */ characteristics?: string[]; @@ -543,15 +575,15 @@ export class BluetoothLE extends IonicNativePlugin { * Connect to a Bluetooth LE device * @param connectSuccess The success callback that is passed with device object * @param connectError The callback that will be triggered when the connect operation fails - * @param params The address/identifier + * @param params The connection params * - * @param {{address: string, autoConnect: boolean}} params + * @param {ConnectionParams} params * @returns {(Observable<{ status: DeviceInfo }>)} * success: device object with status * error: The callback that will be triggered when the unbond operation fails */ @Cordova({ callbackOrder: 'reverse', observable: true }) - connect(params: { address: string; autoConnect?: boolean }): Observable { + connect(params: ConnectionParams): Observable { return; }