@capacitor-community/bluetooth-le 7.1.0 → 7.1.1
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/README.md +21 -12
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/BluetoothLe.kt +7 -0
- package/dist/docs.json +35 -1
- package/dist/esm/definitions.d.ts +17 -5
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +39 -41
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +39 -41
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
433
|
+
if (!(value === null || value === undefined ? undefined : value.buffer)) {
|
|
434
434
|
throw new Error('Invalid data.');
|
|
435
435
|
}
|
|
436
436
|
let writeValue = value;
|
|
@@ -450,9 +450,9 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
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 ===
|
|
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 ===
|
|
455
|
+
callback(this.convertValue(event === null || event === undefined ? undefined : event.value));
|
|
456
456
|
});
|
|
457
457
|
this.eventListeners.set(key, listener);
|
|
458
458
|
await BluetoothLe.startNotifications({
|
|
@@ -468,7 +468,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
468
468
|
await this.queue(async () => {
|
|
469
469
|
var _a;
|
|
470
470
|
const key = `notification|${deviceId}|${service}|${characteristic}`;
|
|
471
|
-
await ((_a = this.eventListeners.get(key)) === null || _a ===
|
|
471
|
+
await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
|
|
472
472
|
this.eventListeners.delete(key);
|
|
473
473
|
await BluetoothLe.stopNotifications({
|
|
474
474
|
deviceId,
|
|
@@ -576,7 +576,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
576
576
|
const filters = this.getFilters(options);
|
|
577
577
|
const device = await navigator.bluetooth.requestDevice({
|
|
578
578
|
filters: filters.length ? filters : undefined,
|
|
579
|
-
optionalServices: options === null || options ===
|
|
579
|
+
optionalServices: options === null || options === undefined ? undefined : options.optionalServices,
|
|
580
580
|
acceptAllDevices: filters.length === 0,
|
|
581
581
|
});
|
|
582
582
|
this.deviceMap.set(device.id, device);
|
|
@@ -593,7 +593,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
593
593
|
this.scan = await navigator.bluetooth.requestLEScan({
|
|
594
594
|
filters: filters.length ? filters : undefined,
|
|
595
595
|
acceptAllAdvertisements: filters.length === 0,
|
|
596
|
-
keepRepeatedDevices: options === null || options ===
|
|
596
|
+
keepRepeatedDevices: options === null || options === undefined ? undefined : options.allowDuplicates,
|
|
597
597
|
});
|
|
598
598
|
}
|
|
599
599
|
onAdvertisementReceived(event) {
|
|
@@ -601,7 +601,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
601
601
|
const deviceId = event.device.id;
|
|
602
602
|
this.deviceMap.set(deviceId, event.device);
|
|
603
603
|
const isNew = !this.discoveredDevices.has(deviceId);
|
|
604
|
-
if (isNew || ((_a = this.requestBleDeviceOptions) === null || _a ===
|
|
604
|
+
if (isNew || ((_a = this.requestBleDeviceOptions) === null || _a === undefined ? undefined : _a.allowDuplicates)) {
|
|
605
605
|
this.discoveredDevices.set(deviceId, true);
|
|
606
606
|
const device = this.getBleDevice(event.device);
|
|
607
607
|
const result = {
|
|
@@ -611,14 +611,14 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
611
611
|
txPower: event.txPower,
|
|
612
612
|
manufacturerData: mapToObject(event.manufacturerData),
|
|
613
613
|
serviceData: mapToObject(event.serviceData),
|
|
614
|
-
uuids: (_b = event.uuids) === null || _b ===
|
|
614
|
+
uuids: (_b = event.uuids) === null || _b === undefined ? undefined : _b.map(webUUIDToString),
|
|
615
615
|
};
|
|
616
616
|
this.notifyListeners('onScanResult', result);
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
619
|
async stopLEScan() {
|
|
620
620
|
var _a;
|
|
621
|
-
if ((_a = this.scan) === null || _a ===
|
|
621
|
+
if ((_a = this.scan) === null || _a === undefined ? undefined : _a.active) {
|
|
622
622
|
this.scan.stop();
|
|
623
623
|
}
|
|
624
624
|
this.scan = null;
|
|
@@ -639,7 +639,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
639
639
|
const bleDevices = devices
|
|
640
640
|
.filter((device) => {
|
|
641
641
|
var _a;
|
|
642
|
-
return (_a = device.gatt) === null || _a ===
|
|
642
|
+
return (_a = device.gatt) === null || _a === undefined ? undefined : _a.connected;
|
|
643
643
|
})
|
|
644
644
|
.map((device) => {
|
|
645
645
|
this.deviceMap.set(device.id, device);
|
|
@@ -667,7 +667,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
667
667
|
catch (error) {
|
|
668
668
|
// cancel pending connect call, does not work yet in chromium because of a bug:
|
|
669
669
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=684073
|
|
670
|
-
await ((_b = device.gatt) === null || _b ===
|
|
670
|
+
await ((_b = device.gatt) === null || _b === undefined ? undefined : _b.disconnect());
|
|
671
671
|
if (error === timeoutError) {
|
|
672
672
|
throw new Error('Connection timeout');
|
|
673
673
|
}
|
|
@@ -689,11 +689,11 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
689
689
|
}
|
|
690
690
|
async disconnect(options) {
|
|
691
691
|
var _a;
|
|
692
|
-
(_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a ===
|
|
692
|
+
(_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.disconnect();
|
|
693
693
|
}
|
|
694
694
|
async getServices(options) {
|
|
695
695
|
var _a, _b;
|
|
696
|
-
const services = (_b = (await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a ===
|
|
696
|
+
const services = (_b = (await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.getPrimaryServices()))) !== null && _b !== undefined ? _b : [];
|
|
697
697
|
const bleServices = [];
|
|
698
698
|
for (const service of services) {
|
|
699
699
|
const characteristics = await service.getCharacteristics();
|
|
@@ -735,12 +735,12 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
735
735
|
}
|
|
736
736
|
async getCharacteristic(options) {
|
|
737
737
|
var _a;
|
|
738
|
-
const service = await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a ===
|
|
739
|
-
return service === null || service ===
|
|
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);
|
|
740
740
|
}
|
|
741
741
|
async getDescriptor(options) {
|
|
742
742
|
const characteristic = await this.getCharacteristic(options);
|
|
743
|
-
return characteristic === null || characteristic ===
|
|
743
|
+
return characteristic === null || characteristic === undefined ? undefined : characteristic.getDescriptor(options === null || options === undefined ? undefined : options.descriptor);
|
|
744
744
|
}
|
|
745
745
|
async discoverServices(_options) {
|
|
746
746
|
throw this.unavailable('discoverServices is not available on web.');
|
|
@@ -756,7 +756,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
756
756
|
}
|
|
757
757
|
async read(options) {
|
|
758
758
|
const characteristic = await this.getCharacteristic(options);
|
|
759
|
-
const value = await (characteristic === null || characteristic ===
|
|
759
|
+
const value = await (characteristic === null || characteristic === undefined ? undefined : characteristic.readValue());
|
|
760
760
|
return { value };
|
|
761
761
|
}
|
|
762
762
|
async write(options) {
|
|
@@ -768,7 +768,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
768
768
|
else {
|
|
769
769
|
dataView = options.value;
|
|
770
770
|
}
|
|
771
|
-
await (characteristic === null || characteristic ===
|
|
771
|
+
await (characteristic === null || characteristic === undefined ? undefined : characteristic.writeValueWithResponse(dataView));
|
|
772
772
|
}
|
|
773
773
|
async writeWithoutResponse(options) {
|
|
774
774
|
const characteristic = await this.getCharacteristic(options);
|
|
@@ -779,11 +779,11 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
779
779
|
else {
|
|
780
780
|
dataView = options.value;
|
|
781
781
|
}
|
|
782
|
-
await (characteristic === null || characteristic ===
|
|
782
|
+
await (characteristic === null || characteristic === undefined ? undefined : characteristic.writeValueWithoutResponse(dataView));
|
|
783
783
|
}
|
|
784
784
|
async readDescriptor(options) {
|
|
785
785
|
const descriptor = await this.getDescriptor(options);
|
|
786
|
-
const value = await (descriptor === null || descriptor ===
|
|
786
|
+
const value = await (descriptor === null || descriptor === undefined ? undefined : descriptor.readValue());
|
|
787
787
|
return { value };
|
|
788
788
|
}
|
|
789
789
|
async writeDescriptor(options) {
|
|
@@ -795,43 +795,43 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
795
795
|
else {
|
|
796
796
|
dataView = options.value;
|
|
797
797
|
}
|
|
798
|
-
await (descriptor === null || descriptor ===
|
|
798
|
+
await (descriptor === null || descriptor === undefined ? undefined : descriptor.writeValue(dataView));
|
|
799
799
|
}
|
|
800
800
|
async startNotifications(options) {
|
|
801
801
|
const characteristic = await this.getCharacteristic(options);
|
|
802
|
-
characteristic === null || characteristic ===
|
|
803
|
-
characteristic === null || characteristic ===
|
|
804
|
-
await (characteristic === null || characteristic ===
|
|
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());
|
|
805
805
|
}
|
|
806
806
|
onCharacteristicValueChanged(event) {
|
|
807
807
|
var _a, _b;
|
|
808
808
|
const characteristic = event.target;
|
|
809
|
-
const key = `notification|${(_a = characteristic.service) === null || _a ===
|
|
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}`;
|
|
810
810
|
this.notifyListeners(key, {
|
|
811
811
|
value: characteristic.value,
|
|
812
812
|
});
|
|
813
813
|
}
|
|
814
814
|
async stopNotifications(options) {
|
|
815
815
|
const characteristic = await this.getCharacteristic(options);
|
|
816
|
-
await (characteristic === null || characteristic ===
|
|
816
|
+
await (characteristic === null || characteristic === undefined ? undefined : characteristic.stopNotifications());
|
|
817
817
|
}
|
|
818
818
|
getFilters(options) {
|
|
819
819
|
var _a, _b;
|
|
820
820
|
const filters = [];
|
|
821
|
-
for (const service of (_a = options === null || options ===
|
|
821
|
+
for (const service of (_a = options === null || options === undefined ? undefined : options.services) !== null && _a !== undefined ? _a : []) {
|
|
822
822
|
filters.push({
|
|
823
823
|
services: [service],
|
|
824
|
-
name: options === null || options ===
|
|
825
|
-
namePrefix: options === null || options ===
|
|
824
|
+
name: options === null || options === undefined ? undefined : options.name,
|
|
825
|
+
namePrefix: options === null || options === undefined ? undefined : options.namePrefix,
|
|
826
826
|
});
|
|
827
827
|
}
|
|
828
|
-
if (((options === null || options ===
|
|
828
|
+
if (((options === null || options === undefined ? undefined : options.name) || (options === null || options === undefined ? undefined : options.namePrefix)) && filters.length === 0) {
|
|
829
829
|
filters.push({
|
|
830
830
|
name: options.name,
|
|
831
831
|
namePrefix: options.namePrefix,
|
|
832
832
|
});
|
|
833
833
|
}
|
|
834
|
-
for (const manufacturerData of (_b = options === null || options ===
|
|
834
|
+
for (const manufacturerData of (_b = options === null || options === undefined ? undefined : options.manufacturerData) !== null && _b !== undefined ? _b : []) {
|
|
835
835
|
filters.push({
|
|
836
836
|
manufacturerData: [manufacturerData],
|
|
837
837
|
});
|
|
@@ -850,7 +850,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
850
850
|
const bleDevice = {
|
|
851
851
|
deviceId: device.id,
|
|
852
852
|
// use undefined instead of null if name is not available
|
|
853
|
-
name: (_a = device.name) !== null && _a !==
|
|
853
|
+
name: (_a = device.name) !== null && _a !== undefined ? _a : undefined,
|
|
854
854
|
};
|
|
855
855
|
return bleDevice;
|
|
856
856
|
}
|
|
@@ -873,8 +873,6 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
873
873
|
exports.textToDataView = textToDataView;
|
|
874
874
|
exports.webUUIDToString = webUUIDToString;
|
|
875
875
|
|
|
876
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
877
|
-
|
|
878
876
|
return exports;
|
|
879
877
|
|
|
880
878
|
})({}, capacitorExports);
|