@capacitor-community/bluetooth-le 6.0.2 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plugin.js CHANGED
@@ -105,7 +105,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
105
105
  }
106
106
  return s;
107
107
  })
108
- .join(' ');
108
+ .join('');
109
109
  }
110
110
  function webUUIDToString(uuid) {
111
111
  if (typeof uuid === 'string') {
@@ -206,7 +206,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
206
206
  await this.queue(async () => {
207
207
  var _a;
208
208
  const key = `onEnabledChanged`;
209
- await ((_a = this.eventListeners.get(key)) === null || _a === void 0 ? void 0 : _a.remove());
209
+ await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
210
210
  const listener = await BluetoothLe.addListener(key, (result) => {
211
211
  callback(result.value);
212
212
  });
@@ -218,7 +218,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
218
218
  await this.queue(async () => {
219
219
  var _a;
220
220
  const key = `onEnabledChanged`;
221
- await ((_a = this.eventListeners.get(key)) === null || _a === void 0 ? void 0 : _a.remove());
221
+ await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
222
222
  this.eventListeners.delete(key);
223
223
  await BluetoothLe.stopEnabledNotifications();
224
224
  });
@@ -262,7 +262,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
262
262
  options = this.validateRequestBleDeviceOptions(options);
263
263
  await this.queue(async () => {
264
264
  var _a;
265
- await ((_a = this.scanListener) === null || _a === void 0 ? void 0 : _a.remove());
265
+ await ((_a = this.scanListener) === null || _a === undefined ? undefined : _a.remove());
266
266
  this.scanListener = await BluetoothLe.addListener('onScanResult', (resultInternal) => {
267
267
  const result = Object.assign(Object.assign({}, resultInternal), { manufacturerData: this.convertObject(resultInternal.manufacturerData), serviceData: this.convertObject(resultInternal.serviceData), rawAdvertisement: resultInternal.rawAdvertisement
268
268
  ? this.convertValue(resultInternal.rawAdvertisement)
@@ -275,7 +275,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
275
275
  async stopLEScan() {
276
276
  await this.queue(async () => {
277
277
  var _a;
278
- await ((_a = this.scanListener) === null || _a === void 0 ? void 0 : _a.remove());
278
+ await ((_a = this.scanListener) === null || _a === undefined ? undefined : _a.remove());
279
279
  this.scanListener = null;
280
280
  await BluetoothLe.stopLEScan();
281
281
  });
@@ -299,12 +299,18 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
299
299
  return result.devices;
300
300
  });
301
301
  }
302
+ async getBondedDevices() {
303
+ return this.queue(async () => {
304
+ const result = await BluetoothLe.getBondedDevices();
305
+ return result.devices;
306
+ });
307
+ }
302
308
  async connect(deviceId, onDisconnect, options) {
303
309
  await this.queue(async () => {
304
310
  var _a;
305
311
  if (onDisconnect) {
306
312
  const key = `disconnected|${deviceId}`;
307
- await ((_a = this.eventListeners.get(key)) === null || _a === void 0 ? void 0 : _a.remove());
313
+ await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
308
314
  const listener = await BluetoothLe.addListener(key, () => {
309
315
  onDisconnect(deviceId);
310
316
  });
@@ -376,7 +382,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
376
382
  service = parseUUID(service);
377
383
  characteristic = parseUUID(characteristic);
378
384
  return this.queue(async () => {
379
- if (!(value === null || value === void 0 ? void 0 : value.buffer)) {
385
+ if (!(value === null || value === undefined ? undefined : value.buffer)) {
380
386
  throw new Error('Invalid data.');
381
387
  }
382
388
  let writeValue = value;
@@ -393,7 +399,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
393
399
  service = parseUUID(service);
394
400
  characteristic = parseUUID(characteristic);
395
401
  await this.queue(async () => {
396
- if (!(value === null || value === void 0 ? void 0 : value.buffer)) {
402
+ if (!(value === null || value === undefined ? undefined : value.buffer)) {
397
403
  throw new Error('Invalid data.');
398
404
  }
399
405
  let writeValue = value;
@@ -424,7 +430,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
424
430
  characteristic = parseUUID(characteristic);
425
431
  descriptor = parseUUID(descriptor);
426
432
  return this.queue(async () => {
427
- if (!(value === null || value === void 0 ? void 0 : value.buffer)) {
433
+ if (!(value === null || value === undefined ? undefined : value.buffer)) {
428
434
  throw new Error('Invalid data.');
429
435
  }
430
436
  let writeValue = value;
@@ -444,9 +450,9 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
444
450
  await this.queue(async () => {
445
451
  var _a;
446
452
  const key = `notification|${deviceId}|${service}|${characteristic}`;
447
- await ((_a = this.eventListeners.get(key)) === null || _a === void 0 ? void 0 : _a.remove());
453
+ await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
448
454
  const listener = await BluetoothLe.addListener(key, (event) => {
449
- callback(this.convertValue(event === null || event === void 0 ? void 0 : event.value));
455
+ callback(this.convertValue(event === null || event === undefined ? undefined : event.value));
450
456
  });
451
457
  this.eventListeners.set(key, listener);
452
458
  await BluetoothLe.startNotifications({
@@ -462,7 +468,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
462
468
  await this.queue(async () => {
463
469
  var _a;
464
470
  const key = `notification|${deviceId}|${service}|${characteristic}`;
465
- await ((_a = this.eventListeners.get(key)) === null || _a === void 0 ? void 0 : _a.remove());
471
+ await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
466
472
  this.eventListeners.delete(key);
467
473
  await BluetoothLe.stopNotifications({
468
474
  deviceId,
@@ -570,7 +576,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
570
576
  const filters = this.getFilters(options);
571
577
  const device = await navigator.bluetooth.requestDevice({
572
578
  filters: filters.length ? filters : undefined,
573
- optionalServices: options === null || options === void 0 ? void 0 : options.optionalServices,
579
+ optionalServices: options === null || options === undefined ? undefined : options.optionalServices,
574
580
  acceptAllDevices: filters.length === 0,
575
581
  });
576
582
  this.deviceMap.set(device.id, device);
@@ -587,7 +593,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
587
593
  this.scan = await navigator.bluetooth.requestLEScan({
588
594
  filters: filters.length ? filters : undefined,
589
595
  acceptAllAdvertisements: filters.length === 0,
590
- keepRepeatedDevices: options === null || options === void 0 ? void 0 : options.allowDuplicates,
596
+ keepRepeatedDevices: options === null || options === undefined ? undefined : options.allowDuplicates,
591
597
  });
592
598
  }
593
599
  onAdvertisementReceived(event) {
@@ -595,7 +601,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
595
601
  const deviceId = event.device.id;
596
602
  this.deviceMap.set(deviceId, event.device);
597
603
  const isNew = !this.discoveredDevices.has(deviceId);
598
- if (isNew || ((_a = this.requestBleDeviceOptions) === null || _a === void 0 ? void 0 : _a.allowDuplicates)) {
604
+ if (isNew || ((_a = this.requestBleDeviceOptions) === null || _a === undefined ? undefined : _a.allowDuplicates)) {
599
605
  this.discoveredDevices.set(deviceId, true);
600
606
  const device = this.getBleDevice(event.device);
601
607
  const result = {
@@ -605,14 +611,14 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
605
611
  txPower: event.txPower,
606
612
  manufacturerData: mapToObject(event.manufacturerData),
607
613
  serviceData: mapToObject(event.serviceData),
608
- uuids: (_b = event.uuids) === null || _b === void 0 ? void 0 : _b.map(webUUIDToString),
614
+ uuids: (_b = event.uuids) === null || _b === undefined ? undefined : _b.map(webUUIDToString),
609
615
  };
610
616
  this.notifyListeners('onScanResult', result);
611
617
  }
612
618
  }
613
619
  async stopLEScan() {
614
620
  var _a;
615
- if ((_a = this.scan) === null || _a === void 0 ? void 0 : _a.active) {
621
+ if ((_a = this.scan) === null || _a === undefined ? undefined : _a.active) {
616
622
  this.scan.stop();
617
623
  }
618
624
  this.scan = null;
@@ -633,7 +639,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
633
639
  const bleDevices = devices
634
640
  .filter((device) => {
635
641
  var _a;
636
- return (_a = device.gatt) === null || _a === void 0 ? void 0 : _a.connected;
642
+ return (_a = device.gatt) === null || _a === undefined ? undefined : _a.connected;
637
643
  })
638
644
  .map((device) => {
639
645
  this.deviceMap.set(device.id, device);
@@ -642,6 +648,9 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
642
648
  });
643
649
  return { devices: bleDevices };
644
650
  }
651
+ async getBondedDevices() {
652
+ return {};
653
+ }
645
654
  async connect(options) {
646
655
  var _a, _b;
647
656
  const device = this.getDeviceFromMap(options.deviceId);
@@ -658,7 +667,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
658
667
  catch (error) {
659
668
  // cancel pending connect call, does not work yet in chromium because of a bug:
660
669
  // https://bugs.chromium.org/p/chromium/issues/detail?id=684073
661
- await ((_b = device.gatt) === null || _b === void 0 ? void 0 : _b.disconnect());
670
+ await ((_b = device.gatt) === null || _b === undefined ? undefined : _b.disconnect());
662
671
  if (error === timeoutError) {
663
672
  throw new Error('Connection timeout');
664
673
  }
@@ -680,11 +689,11 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
680
689
  }
681
690
  async disconnect(options) {
682
691
  var _a;
683
- (_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === void 0 ? void 0 : _a.disconnect();
692
+ (_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.disconnect();
684
693
  }
685
694
  async getServices(options) {
686
695
  var _a, _b;
687
- const services = (_b = (await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === void 0 ? void 0 : _a.getPrimaryServices()))) !== null && _b !== void 0 ? _b : [];
696
+ const services = (_b = (await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.getPrimaryServices()))) !== null && _b !== undefined ? _b : [];
688
697
  const bleServices = [];
689
698
  for (const service of services) {
690
699
  const characteristics = await service.getCharacteristics();
@@ -726,12 +735,12 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
726
735
  }
727
736
  async getCharacteristic(options) {
728
737
  var _a;
729
- const service = await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === void 0 ? void 0 : _a.getPrimaryService(options === null || options === void 0 ? void 0 : options.service));
730
- return service === null || service === void 0 ? void 0 : service.getCharacteristic(options === null || options === void 0 ? void 0 : options.characteristic);
738
+ const service = await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.getPrimaryService(options === null || options === undefined ? undefined : options.service));
739
+ return service === null || service === undefined ? undefined : service.getCharacteristic(options === null || options === undefined ? undefined : options.characteristic);
731
740
  }
732
741
  async getDescriptor(options) {
733
742
  const characteristic = await this.getCharacteristic(options);
734
- return characteristic === null || characteristic === void 0 ? void 0 : characteristic.getDescriptor(options === null || options === void 0 ? void 0 : options.descriptor);
743
+ return characteristic === null || characteristic === undefined ? undefined : characteristic.getDescriptor(options === null || options === undefined ? undefined : options.descriptor);
735
744
  }
736
745
  async discoverServices(_options) {
737
746
  throw this.unavailable('discoverServices is not available on web.');
@@ -747,7 +756,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
747
756
  }
748
757
  async read(options) {
749
758
  const characteristic = await this.getCharacteristic(options);
750
- const value = await (characteristic === null || characteristic === void 0 ? void 0 : characteristic.readValue());
759
+ const value = await (characteristic === null || characteristic === undefined ? undefined : characteristic.readValue());
751
760
  return { value };
752
761
  }
753
762
  async write(options) {
@@ -759,7 +768,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
759
768
  else {
760
769
  dataView = options.value;
761
770
  }
762
- await (characteristic === null || characteristic === void 0 ? void 0 : characteristic.writeValueWithResponse(dataView));
771
+ await (characteristic === null || characteristic === undefined ? undefined : characteristic.writeValueWithResponse(dataView));
763
772
  }
764
773
  async writeWithoutResponse(options) {
765
774
  const characteristic = await this.getCharacteristic(options);
@@ -770,11 +779,11 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
770
779
  else {
771
780
  dataView = options.value;
772
781
  }
773
- await (characteristic === null || characteristic === void 0 ? void 0 : characteristic.writeValueWithoutResponse(dataView));
782
+ await (characteristic === null || characteristic === undefined ? undefined : characteristic.writeValueWithoutResponse(dataView));
774
783
  }
775
784
  async readDescriptor(options) {
776
785
  const descriptor = await this.getDescriptor(options);
777
- const value = await (descriptor === null || descriptor === void 0 ? void 0 : descriptor.readValue());
786
+ const value = await (descriptor === null || descriptor === undefined ? undefined : descriptor.readValue());
778
787
  return { value };
779
788
  }
780
789
  async writeDescriptor(options) {
@@ -786,37 +795,37 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
786
795
  else {
787
796
  dataView = options.value;
788
797
  }
789
- await (descriptor === null || descriptor === void 0 ? void 0 : descriptor.writeValue(dataView));
798
+ await (descriptor === null || descriptor === undefined ? undefined : descriptor.writeValue(dataView));
790
799
  }
791
800
  async startNotifications(options) {
792
801
  const characteristic = await this.getCharacteristic(options);
793
- characteristic === null || characteristic === void 0 ? void 0 : characteristic.removeEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
794
- characteristic === null || characteristic === void 0 ? void 0 : characteristic.addEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
795
- await (characteristic === null || characteristic === void 0 ? void 0 : characteristic.startNotifications());
802
+ characteristic === null || characteristic === undefined ? undefined : characteristic.removeEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
803
+ characteristic === null || characteristic === undefined ? undefined : characteristic.addEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
804
+ await (characteristic === null || characteristic === undefined ? undefined : characteristic.startNotifications());
796
805
  }
797
806
  onCharacteristicValueChanged(event) {
798
807
  var _a, _b;
799
808
  const characteristic = event.target;
800
- const key = `notification|${(_a = characteristic.service) === null || _a === void 0 ? void 0 : _a.device.id}|${(_b = characteristic.service) === null || _b === void 0 ? void 0 : _b.uuid}|${characteristic.uuid}`;
809
+ const key = `notification|${(_a = characteristic.service) === null || _a === undefined ? undefined : _a.device.id}|${(_b = characteristic.service) === null || _b === undefined ? undefined : _b.uuid}|${characteristic.uuid}`;
801
810
  this.notifyListeners(key, {
802
811
  value: characteristic.value,
803
812
  });
804
813
  }
805
814
  async stopNotifications(options) {
806
815
  const characteristic = await this.getCharacteristic(options);
807
- await (characteristic === null || characteristic === void 0 ? void 0 : characteristic.stopNotifications());
816
+ await (characteristic === null || characteristic === undefined ? undefined : characteristic.stopNotifications());
808
817
  }
809
818
  getFilters(options) {
810
819
  var _a;
811
820
  const filters = [];
812
- for (const service of (_a = options === null || options === void 0 ? void 0 : options.services) !== null && _a !== void 0 ? _a : []) {
821
+ for (const service of (_a = options === null || options === undefined ? undefined : options.services) !== null && _a !== undefined ? _a : []) {
813
822
  filters.push({
814
823
  services: [service],
815
- name: options === null || options === void 0 ? void 0 : options.name,
816
- namePrefix: options === null || options === void 0 ? void 0 : options.namePrefix,
824
+ name: options === null || options === undefined ? undefined : options.name,
825
+ namePrefix: options === null || options === undefined ? undefined : options.namePrefix,
817
826
  });
818
827
  }
819
- if (((options === null || options === void 0 ? void 0 : options.name) || (options === null || options === void 0 ? void 0 : options.namePrefix)) && filters.length === 0) {
828
+ if (((options === null || options === undefined ? undefined : options.name) || (options === null || options === undefined ? undefined : options.namePrefix)) && filters.length === 0) {
820
829
  filters.push({
821
830
  name: options.name,
822
831
  namePrefix: options.namePrefix,
@@ -836,7 +845,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
836
845
  const bleDevice = {
837
846
  deviceId: device.id,
838
847
  // use undefined instead of null if name is not available
839
- name: (_a = device.name) !== null && _a !== void 0 ? _a : undefined,
848
+ name: (_a = device.name) !== null && _a !== undefined ? _a : undefined,
840
849
  };
841
850
  return bleDevice;
842
851
  }
@@ -859,8 +868,6 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
859
868
  exports.textToDataView = textToDataView;
860
869
  exports.webUUIDToString = webUUIDToString;
861
870
 
862
- Object.defineProperty(exports, '__esModule', { value: true });
863
-
864
871
  return exports;
865
872
 
866
873
  })({}, capacitorExports);