@capacitor-community/bluetooth-le 7.1.0 → 7.2.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
@@ -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
  });
@@ -310,7 +310,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
310
310
  var _a;
311
311
  if (onDisconnect) {
312
312
  const key = `disconnected|${deviceId}`;
313
- 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());
314
314
  const listener = await BluetoothLe.addListener(key, () => {
315
315
  onDisconnect(deviceId);
316
316
  });
@@ -382,7 +382,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
382
382
  service = parseUUID(service);
383
383
  characteristic = parseUUID(characteristic);
384
384
  return this.queue(async () => {
385
- if (!(value === null || value === void 0 ? void 0 : value.buffer)) {
385
+ if (!(value === null || value === undefined ? undefined : value.buffer)) {
386
386
  throw new Error('Invalid data.');
387
387
  }
388
388
  let writeValue = value;
@@ -399,7 +399,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
399
399
  service = parseUUID(service);
400
400
  characteristic = parseUUID(characteristic);
401
401
  await this.queue(async () => {
402
- if (!(value === null || value === void 0 ? void 0 : value.buffer)) {
402
+ if (!(value === null || value === undefined ? undefined : value.buffer)) {
403
403
  throw new Error('Invalid data.');
404
404
  }
405
405
  let writeValue = value;
@@ -430,7 +430,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
430
430
  characteristic = parseUUID(characteristic);
431
431
  descriptor = parseUUID(descriptor);
432
432
  return this.queue(async () => {
433
- if (!(value === null || value === void 0 ? void 0 : value.buffer)) {
433
+ if (!(value === null || value === undefined ? undefined : value.buffer)) {
434
434
  throw new Error('Invalid data.');
435
435
  }
436
436
  let writeValue = value;
@@ -444,22 +444,20 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
444
444
  descriptor, value: writeValue }, options));
445
445
  });
446
446
  }
447
- async startNotifications(deviceId, service, characteristic, callback) {
447
+ async startNotifications(deviceId, service, characteristic, callback, options) {
448
448
  service = parseUUID(service);
449
449
  characteristic = parseUUID(characteristic);
450
450
  await this.queue(async () => {
451
451
  var _a;
452
452
  const key = `notification|${deviceId}|${service}|${characteristic}`;
453
- 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());
454
454
  const listener = await BluetoothLe.addListener(key, (event) => {
455
- callback(this.convertValue(event === null || event === void 0 ? void 0 : event.value));
455
+ callback(this.convertValue(event === null || event === undefined ? undefined : event.value));
456
456
  });
457
457
  this.eventListeners.set(key, listener);
458
- await BluetoothLe.startNotifications({
459
- deviceId,
458
+ await BluetoothLe.startNotifications(Object.assign({ deviceId,
460
459
  service,
461
- characteristic,
462
- });
460
+ characteristic }, options));
463
461
  });
464
462
  }
465
463
  async stopNotifications(deviceId, service, characteristic) {
@@ -468,7 +466,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
468
466
  await this.queue(async () => {
469
467
  var _a;
470
468
  const key = `notification|${deviceId}|${service}|${characteristic}`;
471
- await ((_a = this.eventListeners.get(key)) === null || _a === void 0 ? void 0 : _a.remove());
469
+ await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
472
470
  this.eventListeners.delete(key);
473
471
  await BluetoothLe.stopNotifications({
474
472
  deviceId,
@@ -576,7 +574,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
576
574
  const filters = this.getFilters(options);
577
575
  const device = await navigator.bluetooth.requestDevice({
578
576
  filters: filters.length ? filters : undefined,
579
- optionalServices: options === null || options === void 0 ? void 0 : options.optionalServices,
577
+ optionalServices: options === null || options === undefined ? undefined : options.optionalServices,
580
578
  acceptAllDevices: filters.length === 0,
581
579
  });
582
580
  this.deviceMap.set(device.id, device);
@@ -593,7 +591,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
593
591
  this.scan = await navigator.bluetooth.requestLEScan({
594
592
  filters: filters.length ? filters : undefined,
595
593
  acceptAllAdvertisements: filters.length === 0,
596
- keepRepeatedDevices: options === null || options === void 0 ? void 0 : options.allowDuplicates,
594
+ keepRepeatedDevices: options === null || options === undefined ? undefined : options.allowDuplicates,
597
595
  });
598
596
  }
599
597
  onAdvertisementReceived(event) {
@@ -601,7 +599,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
601
599
  const deviceId = event.device.id;
602
600
  this.deviceMap.set(deviceId, event.device);
603
601
  const isNew = !this.discoveredDevices.has(deviceId);
604
- if (isNew || ((_a = this.requestBleDeviceOptions) === null || _a === void 0 ? void 0 : _a.allowDuplicates)) {
602
+ if (isNew || ((_a = this.requestBleDeviceOptions) === null || _a === undefined ? undefined : _a.allowDuplicates)) {
605
603
  this.discoveredDevices.set(deviceId, true);
606
604
  const device = this.getBleDevice(event.device);
607
605
  const result = {
@@ -611,14 +609,14 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
611
609
  txPower: event.txPower,
612
610
  manufacturerData: mapToObject(event.manufacturerData),
613
611
  serviceData: mapToObject(event.serviceData),
614
- uuids: (_b = event.uuids) === null || _b === void 0 ? void 0 : _b.map(webUUIDToString),
612
+ uuids: (_b = event.uuids) === null || _b === undefined ? undefined : _b.map(webUUIDToString),
615
613
  };
616
614
  this.notifyListeners('onScanResult', result);
617
615
  }
618
616
  }
619
617
  async stopLEScan() {
620
618
  var _a;
621
- if ((_a = this.scan) === null || _a === void 0 ? void 0 : _a.active) {
619
+ if ((_a = this.scan) === null || _a === undefined ? undefined : _a.active) {
622
620
  this.scan.stop();
623
621
  }
624
622
  this.scan = null;
@@ -639,7 +637,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
639
637
  const bleDevices = devices
640
638
  .filter((device) => {
641
639
  var _a;
642
- return (_a = device.gatt) === null || _a === void 0 ? void 0 : _a.connected;
640
+ return (_a = device.gatt) === null || _a === undefined ? undefined : _a.connected;
643
641
  })
644
642
  .map((device) => {
645
643
  this.deviceMap.set(device.id, device);
@@ -667,7 +665,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
667
665
  catch (error) {
668
666
  // cancel pending connect call, does not work yet in chromium because of a bug:
669
667
  // https://bugs.chromium.org/p/chromium/issues/detail?id=684073
670
- await ((_b = device.gatt) === null || _b === void 0 ? void 0 : _b.disconnect());
668
+ await ((_b = device.gatt) === null || _b === undefined ? undefined : _b.disconnect());
671
669
  if (error === timeoutError) {
672
670
  throw new Error('Connection timeout');
673
671
  }
@@ -689,11 +687,11 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
689
687
  }
690
688
  async disconnect(options) {
691
689
  var _a;
692
- (_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === void 0 ? void 0 : _a.disconnect();
690
+ (_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.disconnect();
693
691
  }
694
692
  async getServices(options) {
695
693
  var _a, _b;
696
- const services = (_b = (await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === void 0 ? void 0 : _a.getPrimaryServices()))) !== null && _b !== void 0 ? _b : [];
694
+ const services = (_b = (await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.getPrimaryServices()))) !== null && _b !== undefined ? _b : [];
697
695
  const bleServices = [];
698
696
  for (const service of services) {
699
697
  const characteristics = await service.getCharacteristics();
@@ -735,12 +733,12 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
735
733
  }
736
734
  async getCharacteristic(options) {
737
735
  var _a;
738
- 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));
739
- return service === null || service === void 0 ? void 0 : service.getCharacteristic(options === null || options === void 0 ? void 0 : options.characteristic);
736
+ const service = await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.getPrimaryService(options === null || options === undefined ? undefined : options.service));
737
+ return service === null || service === undefined ? undefined : service.getCharacteristic(options === null || options === undefined ? undefined : options.characteristic);
740
738
  }
741
739
  async getDescriptor(options) {
742
740
  const characteristic = await this.getCharacteristic(options);
743
- return characteristic === null || characteristic === void 0 ? void 0 : characteristic.getDescriptor(options === null || options === void 0 ? void 0 : options.descriptor);
741
+ return characteristic === null || characteristic === undefined ? undefined : characteristic.getDescriptor(options === null || options === undefined ? undefined : options.descriptor);
744
742
  }
745
743
  async discoverServices(_options) {
746
744
  throw this.unavailable('discoverServices is not available on web.');
@@ -756,7 +754,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
756
754
  }
757
755
  async read(options) {
758
756
  const characteristic = await this.getCharacteristic(options);
759
- const value = await (characteristic === null || characteristic === void 0 ? void 0 : characteristic.readValue());
757
+ const value = await (characteristic === null || characteristic === undefined ? undefined : characteristic.readValue());
760
758
  return { value };
761
759
  }
762
760
  async write(options) {
@@ -768,7 +766,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
768
766
  else {
769
767
  dataView = options.value;
770
768
  }
771
- await (characteristic === null || characteristic === void 0 ? void 0 : characteristic.writeValueWithResponse(dataView));
769
+ await (characteristic === null || characteristic === undefined ? undefined : characteristic.writeValueWithResponse(dataView));
772
770
  }
773
771
  async writeWithoutResponse(options) {
774
772
  const characteristic = await this.getCharacteristic(options);
@@ -779,11 +777,11 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
779
777
  else {
780
778
  dataView = options.value;
781
779
  }
782
- await (characteristic === null || characteristic === void 0 ? void 0 : characteristic.writeValueWithoutResponse(dataView));
780
+ await (characteristic === null || characteristic === undefined ? undefined : characteristic.writeValueWithoutResponse(dataView));
783
781
  }
784
782
  async readDescriptor(options) {
785
783
  const descriptor = await this.getDescriptor(options);
786
- const value = await (descriptor === null || descriptor === void 0 ? void 0 : descriptor.readValue());
784
+ const value = await (descriptor === null || descriptor === undefined ? undefined : descriptor.readValue());
787
785
  return { value };
788
786
  }
789
787
  async writeDescriptor(options) {
@@ -795,43 +793,43 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
795
793
  else {
796
794
  dataView = options.value;
797
795
  }
798
- await (descriptor === null || descriptor === void 0 ? void 0 : descriptor.writeValue(dataView));
796
+ await (descriptor === null || descriptor === undefined ? undefined : descriptor.writeValue(dataView));
799
797
  }
800
798
  async startNotifications(options) {
801
799
  const characteristic = await this.getCharacteristic(options);
802
- characteristic === null || characteristic === void 0 ? void 0 : characteristic.removeEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
803
- characteristic === null || characteristic === void 0 ? void 0 : characteristic.addEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
804
- await (characteristic === null || characteristic === void 0 ? void 0 : characteristic.startNotifications());
800
+ characteristic === null || characteristic === undefined ? undefined : characteristic.removeEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
801
+ characteristic === null || characteristic === undefined ? undefined : characteristic.addEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
802
+ await (characteristic === null || characteristic === undefined ? undefined : characteristic.startNotifications());
805
803
  }
806
804
  onCharacteristicValueChanged(event) {
807
805
  var _a, _b;
808
806
  const characteristic = event.target;
809
- 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}`;
807
+ const key = `notification|${(_a = characteristic.service) === null || _a === undefined ? undefined : _a.device.id}|${(_b = characteristic.service) === null || _b === undefined ? undefined : _b.uuid}|${characteristic.uuid}`;
810
808
  this.notifyListeners(key, {
811
809
  value: characteristic.value,
812
810
  });
813
811
  }
814
812
  async stopNotifications(options) {
815
813
  const characteristic = await this.getCharacteristic(options);
816
- await (characteristic === null || characteristic === void 0 ? void 0 : characteristic.stopNotifications());
814
+ await (characteristic === null || characteristic === undefined ? undefined : characteristic.stopNotifications());
817
815
  }
818
816
  getFilters(options) {
819
817
  var _a, _b;
820
818
  const filters = [];
821
- for (const service of (_a = options === null || options === void 0 ? void 0 : options.services) !== null && _a !== void 0 ? _a : []) {
819
+ for (const service of (_a = options === null || options === undefined ? undefined : options.services) !== null && _a !== undefined ? _a : []) {
822
820
  filters.push({
823
821
  services: [service],
824
- name: options === null || options === void 0 ? void 0 : options.name,
825
- namePrefix: options === null || options === void 0 ? void 0 : options.namePrefix,
822
+ name: options === null || options === undefined ? undefined : options.name,
823
+ namePrefix: options === null || options === undefined ? undefined : options.namePrefix,
826
824
  });
827
825
  }
828
- if (((options === null || options === void 0 ? void 0 : options.name) || (options === null || options === void 0 ? void 0 : options.namePrefix)) && filters.length === 0) {
826
+ if (((options === null || options === undefined ? undefined : options.name) || (options === null || options === undefined ? undefined : options.namePrefix)) && filters.length === 0) {
829
827
  filters.push({
830
828
  name: options.name,
831
829
  namePrefix: options.namePrefix,
832
830
  });
833
831
  }
834
- for (const manufacturerData of (_b = options === null || options === void 0 ? void 0 : options.manufacturerData) !== null && _b !== void 0 ? _b : []) {
832
+ for (const manufacturerData of (_b = options === null || options === undefined ? undefined : options.manufacturerData) !== null && _b !== undefined ? _b : []) {
835
833
  filters.push({
836
834
  manufacturerData: [manufacturerData],
837
835
  });
@@ -850,7 +848,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
850
848
  const bleDevice = {
851
849
  deviceId: device.id,
852
850
  // use undefined instead of null if name is not available
853
- name: (_a = device.name) !== null && _a !== void 0 ? _a : undefined,
851
+ name: (_a = device.name) !== null && _a !== undefined ? _a : undefined,
854
852
  };
855
853
  return bleDevice;
856
854
  }
@@ -873,8 +871,6 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
873
871
  exports.textToDataView = textToDataView;
874
872
  exports.webUUIDToString = webUUIDToString;
875
873
 
876
- Object.defineProperty(exports, '__esModule', { value: true });
877
-
878
874
  return exports;
879
875
 
880
876
  })({}, capacitorExports);