@capacitor-community/bluetooth-le 8.0.0 → 8.0.2
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/CapacitorCommunityBluetoothLe.podspec +17 -17
- package/LICENSE +21 -21
- package/Package.swift +27 -27
- package/README.md +4 -2
- package/android/build.gradle +73 -73
- package/android/src/main/AndroidManifest.xml +22 -22
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/BluetoothLe.kt +1094 -1094
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/Conversion.kt +51 -51
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/Device.kt +771 -771
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/DeviceList.kt +28 -28
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/DeviceScanner.kt +189 -189
- package/dist/esm/bleClient.js.map +1 -1
- package/dist/esm/conversion.js.map +1 -1
- package/dist/esm/queue.js.map +1 -1
- package/dist/esm/validators.js.map +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +41 -41
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +41 -41
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/BluetoothLe/Conversion.swift +83 -83
- package/ios/Sources/BluetoothLe/Device.swift +422 -423
- package/ios/Sources/BluetoothLe/DeviceListView.swift +121 -121
- package/ios/Sources/BluetoothLe/DeviceManager.swift +409 -503
- package/ios/Sources/BluetoothLe/Logging.swift +8 -8
- package/ios/Sources/BluetoothLe/Plugin.swift +768 -775
- package/ios/Sources/BluetoothLe/ScanFilters.swift +114 -0
- package/ios/Sources/BluetoothLe/ThreadSafeDictionary.swift +61 -15
- package/ios/Tests/BluetoothLeTests/ConversionTests.swift +55 -55
- package/ios/Tests/BluetoothLeTests/PluginTests.swift +27 -27
- package/ios/Tests/BluetoothLeTests/ScanFiltersTests.swift +153 -0
- package/package.json +114 -115
package/dist/plugin.js
CHANGED
|
@@ -256,7 +256,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
256
256
|
await this.queue(async () => {
|
|
257
257
|
var _a;
|
|
258
258
|
const key = `onEnabledChanged`;
|
|
259
|
-
await ((_a = this.eventListeners.get(key)) === null || _a ===
|
|
259
|
+
await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
|
|
260
260
|
const listener = await BluetoothLe.addListener(key, (result) => {
|
|
261
261
|
callback(result.value);
|
|
262
262
|
});
|
|
@@ -268,7 +268,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
268
268
|
await this.queue(async () => {
|
|
269
269
|
var _a;
|
|
270
270
|
const key = `onEnabledChanged`;
|
|
271
|
-
await ((_a = this.eventListeners.get(key)) === null || _a ===
|
|
271
|
+
await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
|
|
272
272
|
this.eventListeners.delete(key);
|
|
273
273
|
await BluetoothLe.stopEnabledNotifications();
|
|
274
274
|
});
|
|
@@ -312,7 +312,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
312
312
|
options = this.validateRequestBleDeviceOptions(options);
|
|
313
313
|
await this.queue(async () => {
|
|
314
314
|
var _a;
|
|
315
|
-
await ((_a = this.scanListener) === null || _a ===
|
|
315
|
+
await ((_a = this.scanListener) === null || _a === undefined ? undefined : _a.remove());
|
|
316
316
|
this.scanListener = await BluetoothLe.addListener('onScanResult', (resultInternal) => {
|
|
317
317
|
const result = Object.assign(Object.assign({}, resultInternal), { manufacturerData: this.convertObject(resultInternal.manufacturerData), serviceData: this.convertObject(resultInternal.serviceData), rawAdvertisement: resultInternal.rawAdvertisement
|
|
318
318
|
? this.convertValue(resultInternal.rawAdvertisement)
|
|
@@ -325,7 +325,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
325
325
|
async stopLEScan() {
|
|
326
326
|
await this.queue(async () => {
|
|
327
327
|
var _a;
|
|
328
|
-
await ((_a = this.scanListener) === null || _a ===
|
|
328
|
+
await ((_a = this.scanListener) === null || _a === undefined ? undefined : _a.remove());
|
|
329
329
|
this.scanListener = null;
|
|
330
330
|
await BluetoothLe.stopLEScan();
|
|
331
331
|
});
|
|
@@ -360,7 +360,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
360
360
|
var _a;
|
|
361
361
|
if (onDisconnect) {
|
|
362
362
|
const key = `disconnected|${deviceId}`;
|
|
363
|
-
await ((_a = this.eventListeners.get(key)) === null || _a ===
|
|
363
|
+
await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
|
|
364
364
|
const listener = await BluetoothLe.addListener(key, () => {
|
|
365
365
|
onDisconnect(deviceId);
|
|
366
366
|
});
|
|
@@ -432,7 +432,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
432
432
|
service = parseUUID(service);
|
|
433
433
|
characteristic = parseUUID(characteristic);
|
|
434
434
|
return this.queue(async () => {
|
|
435
|
-
if (!(value === null || value ===
|
|
435
|
+
if (!(value === null || value === undefined ? undefined : value.buffer)) {
|
|
436
436
|
throw new Error('Invalid data.');
|
|
437
437
|
}
|
|
438
438
|
let writeValue = value;
|
|
@@ -449,7 +449,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
449
449
|
service = parseUUID(service);
|
|
450
450
|
characteristic = parseUUID(characteristic);
|
|
451
451
|
await this.queue(async () => {
|
|
452
|
-
if (!(value === null || value ===
|
|
452
|
+
if (!(value === null || value === undefined ? undefined : value.buffer)) {
|
|
453
453
|
throw new Error('Invalid data.');
|
|
454
454
|
}
|
|
455
455
|
let writeValue = value;
|
|
@@ -480,7 +480,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
480
480
|
characteristic = parseUUID(characteristic);
|
|
481
481
|
descriptor = parseUUID(descriptor);
|
|
482
482
|
return this.queue(async () => {
|
|
483
|
-
if (!(value === null || value ===
|
|
483
|
+
if (!(value === null || value === undefined ? undefined : value.buffer)) {
|
|
484
484
|
throw new Error('Invalid data.');
|
|
485
485
|
}
|
|
486
486
|
let writeValue = value;
|
|
@@ -500,9 +500,9 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
500
500
|
await this.queue(async () => {
|
|
501
501
|
var _a;
|
|
502
502
|
const key = `notification|${deviceId}|${service}|${characteristic}`;
|
|
503
|
-
await ((_a = this.eventListeners.get(key)) === null || _a ===
|
|
503
|
+
await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
|
|
504
504
|
const listener = await BluetoothLe.addListener(key, (event) => {
|
|
505
|
-
callback(this.convertValue(event === null || event ===
|
|
505
|
+
callback(this.convertValue(event === null || event === undefined ? undefined : event.value));
|
|
506
506
|
});
|
|
507
507
|
this.eventListeners.set(key, listener);
|
|
508
508
|
await BluetoothLe.startNotifications(Object.assign({ deviceId,
|
|
@@ -516,7 +516,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
516
516
|
await this.queue(async () => {
|
|
517
517
|
var _a;
|
|
518
518
|
const key = `notification|${deviceId}|${service}|${characteristic}`;
|
|
519
|
-
await ((_a = this.eventListeners.get(key)) === null || _a ===
|
|
519
|
+
await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
|
|
520
520
|
this.eventListeners.delete(key);
|
|
521
521
|
await BluetoothLe.stopNotifications({
|
|
522
522
|
deviceId,
|
|
@@ -638,7 +638,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
638
638
|
const filters = this.getFilters(options);
|
|
639
639
|
const device = await navigator.bluetooth.requestDevice({
|
|
640
640
|
filters: filters.length ? filters : undefined,
|
|
641
|
-
optionalServices: options === null || options ===
|
|
641
|
+
optionalServices: options === null || options === undefined ? undefined : options.optionalServices,
|
|
642
642
|
acceptAllDevices: filters.length === 0,
|
|
643
643
|
});
|
|
644
644
|
this.deviceMap.set(device.id, device);
|
|
@@ -655,7 +655,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
655
655
|
this.scan = await navigator.bluetooth.requestLEScan({
|
|
656
656
|
filters: filters.length ? filters : undefined,
|
|
657
657
|
acceptAllAdvertisements: filters.length === 0,
|
|
658
|
-
keepRepeatedDevices: options === null || options ===
|
|
658
|
+
keepRepeatedDevices: options === null || options === undefined ? undefined : options.allowDuplicates,
|
|
659
659
|
});
|
|
660
660
|
}
|
|
661
661
|
onAdvertisementReceived(event) {
|
|
@@ -664,10 +664,10 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
664
664
|
this.deviceMap.set(deviceId, event.device);
|
|
665
665
|
const isNew = !this.discoveredDevices.has(deviceId);
|
|
666
666
|
// Apply service data filtering client-side (Web Bluetooth API doesn't support it in scan filters)
|
|
667
|
-
if (((_a = this.requestBleDeviceOptions) === null || _a ===
|
|
667
|
+
if (((_a = this.requestBleDeviceOptions) === null || _a === undefined ? undefined : _a.serviceData) && !this.matchesServiceDataFilter(event)) {
|
|
668
668
|
return;
|
|
669
669
|
}
|
|
670
|
-
if (isNew || ((_b = this.requestBleDeviceOptions) === null || _b ===
|
|
670
|
+
if (isNew || ((_b = this.requestBleDeviceOptions) === null || _b === undefined ? undefined : _b.allowDuplicates)) {
|
|
671
671
|
this.discoveredDevices.set(deviceId, true);
|
|
672
672
|
const device = this.getBleDevice(event.device);
|
|
673
673
|
const result = {
|
|
@@ -677,14 +677,14 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
677
677
|
txPower: event.txPower,
|
|
678
678
|
manufacturerData: mapToObject(event.manufacturerData),
|
|
679
679
|
serviceData: mapToObject(event.serviceData),
|
|
680
|
-
uuids: (_c = event.uuids) === null || _c ===
|
|
680
|
+
uuids: (_c = event.uuids) === null || _c === undefined ? undefined : _c.map(webUUIDToString),
|
|
681
681
|
};
|
|
682
682
|
this.notifyListeners('onScanResult', result);
|
|
683
683
|
}
|
|
684
684
|
}
|
|
685
685
|
async stopLEScan() {
|
|
686
686
|
var _a;
|
|
687
|
-
if ((_a = this.scan) === null || _a ===
|
|
687
|
+
if ((_a = this.scan) === null || _a === undefined ? undefined : _a.active) {
|
|
688
688
|
this.scan.stop();
|
|
689
689
|
}
|
|
690
690
|
this.scan = null;
|
|
@@ -705,7 +705,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
705
705
|
const bleDevices = devices
|
|
706
706
|
.filter((device) => {
|
|
707
707
|
var _a;
|
|
708
|
-
return (_a = device.gatt) === null || _a ===
|
|
708
|
+
return (_a = device.gatt) === null || _a === undefined ? undefined : _a.connected;
|
|
709
709
|
})
|
|
710
710
|
.map((device) => {
|
|
711
711
|
this.deviceMap.set(device.id, device);
|
|
@@ -733,7 +733,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
733
733
|
catch (error) {
|
|
734
734
|
// cancel pending connect call, does not work yet in chromium because of a bug:
|
|
735
735
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=684073
|
|
736
|
-
await ((_b = device.gatt) === null || _b ===
|
|
736
|
+
await ((_b = device.gatt) === null || _b === undefined ? undefined : _b.disconnect());
|
|
737
737
|
if (error === timeoutError) {
|
|
738
738
|
throw new Error('Connection timeout');
|
|
739
739
|
}
|
|
@@ -755,11 +755,11 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
755
755
|
}
|
|
756
756
|
async disconnect(options) {
|
|
757
757
|
var _a;
|
|
758
|
-
(_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a ===
|
|
758
|
+
(_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.disconnect();
|
|
759
759
|
}
|
|
760
760
|
async getServices(options) {
|
|
761
761
|
var _a, _b;
|
|
762
|
-
const services = (_b = (await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a ===
|
|
762
|
+
const services = (_b = (await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.getPrimaryServices()))) !== null && _b !== undefined ? _b : [];
|
|
763
763
|
const bleServices = [];
|
|
764
764
|
for (const service of services) {
|
|
765
765
|
const characteristics = await service.getCharacteristics();
|
|
@@ -801,12 +801,12 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
801
801
|
}
|
|
802
802
|
async getCharacteristic(options) {
|
|
803
803
|
var _a;
|
|
804
|
-
const service = await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a ===
|
|
805
|
-
return service === null || service ===
|
|
804
|
+
const service = await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.getPrimaryService(options === null || options === undefined ? undefined : options.service));
|
|
805
|
+
return service === null || service === undefined ? undefined : service.getCharacteristic(options === null || options === undefined ? undefined : options.characteristic);
|
|
806
806
|
}
|
|
807
807
|
async getDescriptor(options) {
|
|
808
808
|
const characteristic = await this.getCharacteristic(options);
|
|
809
|
-
return characteristic === null || characteristic ===
|
|
809
|
+
return characteristic === null || characteristic === undefined ? undefined : characteristic.getDescriptor(options === null || options === undefined ? undefined : options.descriptor);
|
|
810
810
|
}
|
|
811
811
|
async discoverServices(_options) {
|
|
812
812
|
throw this.unavailable('discoverServices is not available on web.');
|
|
@@ -822,7 +822,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
822
822
|
}
|
|
823
823
|
async read(options) {
|
|
824
824
|
const characteristic = await this.getCharacteristic(options);
|
|
825
|
-
const value = await (characteristic === null || characteristic ===
|
|
825
|
+
const value = await (characteristic === null || characteristic === undefined ? undefined : characteristic.readValue());
|
|
826
826
|
return { value };
|
|
827
827
|
}
|
|
828
828
|
async write(options) {
|
|
@@ -834,7 +834,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
834
834
|
else {
|
|
835
835
|
dataView = options.value;
|
|
836
836
|
}
|
|
837
|
-
await (characteristic === null || characteristic ===
|
|
837
|
+
await (characteristic === null || characteristic === undefined ? undefined : characteristic.writeValueWithResponse(toArrayBufferDataView(dataView)));
|
|
838
838
|
}
|
|
839
839
|
async writeWithoutResponse(options) {
|
|
840
840
|
const characteristic = await this.getCharacteristic(options);
|
|
@@ -845,11 +845,11 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
845
845
|
else {
|
|
846
846
|
dataView = options.value;
|
|
847
847
|
}
|
|
848
|
-
await (characteristic === null || characteristic ===
|
|
848
|
+
await (characteristic === null || characteristic === undefined ? undefined : characteristic.writeValueWithoutResponse(toArrayBufferDataView(dataView)));
|
|
849
849
|
}
|
|
850
850
|
async readDescriptor(options) {
|
|
851
851
|
const descriptor = await this.getDescriptor(options);
|
|
852
|
-
const value = await (descriptor === null || descriptor ===
|
|
852
|
+
const value = await (descriptor === null || descriptor === undefined ? undefined : descriptor.readValue());
|
|
853
853
|
return { value };
|
|
854
854
|
}
|
|
855
855
|
async writeDescriptor(options) {
|
|
@@ -861,43 +861,43 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
861
861
|
else {
|
|
862
862
|
dataView = options.value;
|
|
863
863
|
}
|
|
864
|
-
await (descriptor === null || descriptor ===
|
|
864
|
+
await (descriptor === null || descriptor === undefined ? undefined : descriptor.writeValue(toArrayBufferDataView(dataView)));
|
|
865
865
|
}
|
|
866
866
|
async startNotifications(options) {
|
|
867
867
|
const characteristic = await this.getCharacteristic(options);
|
|
868
|
-
characteristic === null || characteristic ===
|
|
869
|
-
characteristic === null || characteristic ===
|
|
870
|
-
await (characteristic === null || characteristic ===
|
|
868
|
+
characteristic === null || characteristic === undefined ? undefined : characteristic.removeEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
|
|
869
|
+
characteristic === null || characteristic === undefined ? undefined : characteristic.addEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
|
|
870
|
+
await (characteristic === null || characteristic === undefined ? undefined : characteristic.startNotifications());
|
|
871
871
|
}
|
|
872
872
|
onCharacteristicValueChanged(event) {
|
|
873
873
|
var _a, _b;
|
|
874
874
|
const characteristic = event.target;
|
|
875
|
-
const key = `notification|${(_a = characteristic.service) === null || _a ===
|
|
875
|
+
const key = `notification|${(_a = characteristic.service) === null || _a === undefined ? undefined : _a.device.id}|${(_b = characteristic.service) === null || _b === undefined ? undefined : _b.uuid}|${characteristic.uuid}`;
|
|
876
876
|
this.notifyListeners(key, {
|
|
877
877
|
value: characteristic.value,
|
|
878
878
|
});
|
|
879
879
|
}
|
|
880
880
|
async stopNotifications(options) {
|
|
881
881
|
const characteristic = await this.getCharacteristic(options);
|
|
882
|
-
await (characteristic === null || characteristic ===
|
|
882
|
+
await (characteristic === null || characteristic === undefined ? undefined : characteristic.stopNotifications());
|
|
883
883
|
}
|
|
884
884
|
getFilters(options) {
|
|
885
885
|
var _a, _b;
|
|
886
886
|
const filters = [];
|
|
887
|
-
for (const service of (_a = options === null || options ===
|
|
887
|
+
for (const service of (_a = options === null || options === undefined ? undefined : options.services) !== null && _a !== undefined ? _a : []) {
|
|
888
888
|
filters.push({
|
|
889
889
|
services: [service],
|
|
890
|
-
name: options === null || options ===
|
|
891
|
-
namePrefix: options === null || options ===
|
|
890
|
+
name: options === null || options === undefined ? undefined : options.name,
|
|
891
|
+
namePrefix: options === null || options === undefined ? undefined : options.namePrefix,
|
|
892
892
|
});
|
|
893
893
|
}
|
|
894
|
-
if (((options === null || options ===
|
|
894
|
+
if (((options === null || options === undefined ? undefined : options.name) || (options === null || options === undefined ? undefined : options.namePrefix)) && filters.length === 0) {
|
|
895
895
|
filters.push({
|
|
896
896
|
name: options.name,
|
|
897
897
|
namePrefix: options.namePrefix,
|
|
898
898
|
});
|
|
899
899
|
}
|
|
900
|
-
for (const manufacturerData of (_b = options === null || options ===
|
|
900
|
+
for (const manufacturerData of (_b = options === null || options === undefined ? undefined : options.manufacturerData) !== null && _b !== undefined ? _b : []) {
|
|
901
901
|
// Cast to any to avoid type incompatibility - conversion is handled in bleClient.ts
|
|
902
902
|
filters.push({
|
|
903
903
|
manufacturerData: [manufacturerData],
|
|
@@ -910,7 +910,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
910
910
|
}
|
|
911
911
|
matchesServiceDataFilter(event) {
|
|
912
912
|
var _a;
|
|
913
|
-
const filters = (_a = this.requestBleDeviceOptions) === null || _a ===
|
|
913
|
+
const filters = (_a = this.requestBleDeviceOptions) === null || _a === undefined ? undefined : _a.serviceData;
|
|
914
914
|
if (!filters || filters.length === 0) {
|
|
915
915
|
return true; // No filters, accept all
|
|
916
916
|
}
|
|
@@ -975,7 +975,7 @@ var capacitorCommunityBluetoothLe = (function (exports, core) {
|
|
|
975
975
|
const bleDevice = {
|
|
976
976
|
deviceId: device.id,
|
|
977
977
|
// use undefined instead of null if name is not available
|
|
978
|
-
name: (_a = device.name) !== null && _a !==
|
|
978
|
+
name: (_a = device.name) !== null && _a !== undefined ? _a : undefined,
|
|
979
979
|
};
|
|
980
980
|
return bleDevice;
|
|
981
981
|
}
|