Skip to content

Commit e345fed

Browse files
authored
feat(ble): add scan options interface
1 parent f11be24 commit e345fed

File tree

1 file changed

+65
-22
lines changed

1 file changed

+65
-22
lines changed

src/@ionic-native/plugins/ble/index.ts

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { Injectable } from '@angular/core';
2-
import { Cordova, Plugin, IonicNativePlugin } from '@ionic-native/core';
2+
import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core';
33
import { Observable } from 'rxjs/Observable';
44

5+
export interface BLEScanOptions {
6+
/** true if duplicate devices should be reported, false (default) if devices should only be reported once. */
7+
reportDuplicates?: boolean;
8+
}
9+
510
/**
611
* @name BLE
712
* @description
@@ -167,6 +172,8 @@ import { Observable } from 'rxjs/Observable';
167172
*
168173
* UUIDs are always strings and not numbers. Some 16-bit UUIDs, such as '2220' look like integers, but they're not. (The integer 2220 is 0x8AC in hex.) This isn't a problem with 128 bit UUIDs since they look like strings 82b9e6e1-593a-456f-be9b-9215160ebcac. All 16-bit UUIDs should also be passed to methods as strings.
169174
*
175+
* @interfaces
176+
* BLEScanOptions
170177
*/
171178
@Plugin({
172179
pluginName: 'BLE',
@@ -177,7 +184,6 @@ import { Observable } from 'rxjs/Observable';
177184
})
178185
@Injectable()
179186
export class BLE extends IonicNativePlugin {
180-
181187
/**
182188
* Scan and discover BLE peripherals for the specified amount of time.
183189
*
@@ -194,7 +200,9 @@ export class BLE extends IonicNativePlugin {
194200
@Cordova({
195201
observable: true
196202
})
197-
scan(services: string[], seconds: number): Observable<any> { return; }
203+
scan(services: string[], seconds: number): Observable<any> {
204+
return;
205+
}
198206

199207
/**
200208
* Scan and discover BLE peripherals until `stopScan` is called.
@@ -217,7 +225,9 @@ export class BLE extends IonicNativePlugin {
217225
clearFunction: 'stopScan',
218226
clearWithArgs: false
219227
})
220-
startScan(services: string[]): Observable<any> { return; }
228+
startScan(services: string[]): Observable<any> {
229+
return;
230+
}
221231

222232
/**
223233
* Scans for BLE devices. This function operates similarly to the `startScan` function, but allows you to specify extra options (like allowing duplicate device reports).
@@ -230,7 +240,12 @@ export class BLE extends IonicNativePlugin {
230240
clearFunction: 'stopScan',
231241
clearWithArgs: false
232242
})
233-
startScanWithOptions(services: string[], options: { reportDuplicates?: boolean } | any): Observable<any> { return; }
243+
startScanWithOptions(
244+
services: string[],
245+
options: BLEScanOptions
246+
): Observable<any> {
247+
return;
248+
}
234249

235250
/**
236251
* Stop a scan started by `startScan`.
@@ -247,7 +262,9 @@ export class BLE extends IonicNativePlugin {
247262
* @return returns a Promise.
248263
*/
249264
@Cordova()
250-
stopScan(): Promise<any> { return; }
265+
stopScan(): Promise<any> {
266+
return;
267+
}
251268

252269
/**
253270
* Connect to a peripheral.
@@ -268,7 +285,9 @@ export class BLE extends IonicNativePlugin {
268285
clearFunction: 'disconnect',
269286
clearWithArgs: true
270287
})
271-
connect(deviceId: string): Observable<any> { return; }
288+
connect(deviceId: string): Observable<any> {
289+
return;
290+
}
272291

273292
/**
274293
* Disconnect from a peripheral.
@@ -282,7 +301,9 @@ export class BLE extends IonicNativePlugin {
282301
* @return Returns a Promise
283302
*/
284303
@Cordova()
285-
disconnect(deviceId: string): Promise<any> { return; }
304+
disconnect(deviceId: string): Promise<any> {
305+
return;
306+
}
286307

287308
/**
288309
* Read the value of a characteristic.
@@ -297,7 +318,9 @@ export class BLE extends IonicNativePlugin {
297318
deviceId: string,
298319
serviceUUID: string,
299320
characteristicUUID: string
300-
): Promise<any> { return; };
321+
): Promise<any> {
322+
return;
323+
}
301324

302325
/**
303326
* Write the value of a characteristic.
@@ -333,7 +356,9 @@ export class BLE extends IonicNativePlugin {
333356
serviceUUID: string,
334357
characteristicUUID: string,
335358
value: ArrayBuffer
336-
): Promise<any> { return; }
359+
): Promise<any> {
360+
return;
361+
}
337362

338363
/**
339364
* Write the value of a characteristic without waiting for confirmation from the peripheral.
@@ -350,7 +375,9 @@ export class BLE extends IonicNativePlugin {
350375
serviceUUID: string,
351376
characteristicUUID: string,
352377
value: ArrayBuffer
353-
): Promise<any> { return; }
378+
): Promise<any> {
379+
return;
380+
}
354381

355382
/**
356383
* Register to be notified when the value of a characteristic changes.
@@ -376,7 +403,9 @@ export class BLE extends IonicNativePlugin {
376403
deviceId: string,
377404
serviceUUID: string,
378405
characteristicUUID: string
379-
): Observable<any> { return; }
406+
): Observable<any> {
407+
return;
408+
}
380409

381410
/**
382411
* Stop being notified when the value of a characteristic changes.
@@ -391,7 +420,9 @@ export class BLE extends IonicNativePlugin {
391420
deviceId: string,
392421
serviceUUID: string,
393422
characteristicUUID: string
394-
): Promise<any> { return; }
423+
): Promise<any> {
424+
return;
425+
}
395426

396427
/**
397428
* Report the connection status.
@@ -407,15 +438,19 @@ export class BLE extends IonicNativePlugin {
407438
* @returns {Promise<any>}
408439
*/
409440
@Cordova()
410-
isConnected(deviceId: string): Promise<any> { return; }
441+
isConnected(deviceId: string): Promise<any> {
442+
return;
443+
}
411444

412445
/**
413446
* Report if bluetooth is enabled.
414447
*
415448
* @returns {Promise<void>} Returns a Promise that resolves if Bluetooth is enabled, and rejects if disabled.
416449
*/
417450
@Cordova()
418-
isEnabled(): Promise<void> { return; }
451+
isEnabled(): Promise<void> {
452+
return;
453+
}
419454

420455
/**
421456
* Register to be notified when Bluetooth state changes on the device.
@@ -434,31 +469,39 @@ export class BLE extends IonicNativePlugin {
434469
clearFunction: 'stopStateNotifications',
435470
clearWithArgs: false
436471
})
437-
startStateNotifications(): Observable<any> { return; }
472+
startStateNotifications(): Observable<any> {
473+
return;
474+
}
438475

439476
/**
440477
* Stop state notifications.
441478
*
442479
* @returns {Promise<any>}
443480
*/
444481
@Cordova()
445-
stopStateNotifications(): Promise<any> { return; }
482+
stopStateNotifications(): Promise<any> {
483+
return;
484+
}
446485

447486
/**
448487
* Open System Bluetooth settings (Android only).
449488
*
450489
* @returns {Promise<any>}
451490
*/
452491
@Cordova()
453-
showBluetoothSettings(): Promise<any> { return; }
492+
showBluetoothSettings(): Promise<any> {
493+
return;
494+
}
454495

455496
/**
456497
* Enable Bluetooth on the device (Android only).
457498
*
458499
* @returns {Promise<any>}
459500
*/
460501
@Cordova()
461-
enable(): Promise<any> { return; }
502+
enable(): Promise<any> {
503+
return;
504+
}
462505

463506
/**
464507
* Read the RSSI value on the device connection.
@@ -468,7 +511,7 @@ export class BLE extends IonicNativePlugin {
468511
*@returns {Promise<any>}
469512
*/
470513
@Cordova()
471-
readRSSI(
472-
deviceId: string,
473-
): Promise<any> { return; }
514+
readRSSI(deviceId: string): Promise<any> {
515+
return;
516+
}
474517
}

0 commit comments

Comments
 (0)