react-native-ble-manager 12.1.0 → 12.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/android/src/main/java/it/innove/BleManager.java +66 -34
- package/android/src/main/java/it/innove/Peripheral.java +1 -1
- package/dist/cjs/NativeBleManager.d.ts +1 -0
- package/dist/cjs/NativeBleManager.js.map +1 -1
- package/dist/esm/NativeBleManager.d.ts +1 -0
- package/dist/esm/NativeBleManager.js.map +1 -1
- package/ios/BleManager.mm +12 -0
- package/ios/SwiftBleManager.swift +304 -294
- package/package.json +1 -1
- package/src/NativeBleManager.ts +8 -0
|
@@ -446,8 +446,8 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
446
446
|
}
|
|
447
447
|
|
|
448
448
|
@ReactMethod
|
|
449
|
-
public void
|
|
450
|
-
double
|
|
449
|
+
public void startNotificationWithBuffer(String deviceUUID, String serviceUUID, String characteristicUUID,
|
|
450
|
+
double bufferLength, Callback callback) {
|
|
451
451
|
Log.d(LOG_TAG, "startNotification");
|
|
452
452
|
if (serviceUUID == null || characteristicUUID == null) {
|
|
453
453
|
callback.invoke("ServiceUUID and characteristicUUID required.");
|
|
@@ -456,7 +456,7 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
456
456
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
457
457
|
if (peripheral != null) {
|
|
458
458
|
peripheral.registerNotify(UUIDHelper.uuidFromString(serviceUUID),
|
|
459
|
-
UUIDHelper.uuidFromString(characteristicUUID), (int)
|
|
459
|
+
UUIDHelper.uuidFromString(characteristicUUID), (int) bufferLength, callback);
|
|
460
460
|
} else
|
|
461
461
|
callback.invoke("Peripheral not found");
|
|
462
462
|
}
|
|
@@ -470,8 +470,12 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
470
470
|
}
|
|
471
471
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
472
472
|
if (peripheral != null) {
|
|
473
|
-
peripheral.
|
|
474
|
-
|
|
473
|
+
if (peripheral.isConnected()) {
|
|
474
|
+
peripheral.registerNotify(UUIDHelper.uuidFromString(serviceUUID),
|
|
475
|
+
UUIDHelper.uuidFromString(characteristicUUID), 1, callback);
|
|
476
|
+
} else {
|
|
477
|
+
callback.invoke("Peripheral not connected", null);
|
|
478
|
+
}
|
|
475
479
|
} else
|
|
476
480
|
callback.invoke("Peripheral not found");
|
|
477
481
|
}
|
|
@@ -485,8 +489,12 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
485
489
|
}
|
|
486
490
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
487
491
|
if (peripheral != null) {
|
|
488
|
-
peripheral.
|
|
489
|
-
|
|
492
|
+
if (peripheral.isConnected()) {
|
|
493
|
+
peripheral.removeNotify(UUIDHelper.uuidFromString(serviceUUID),
|
|
494
|
+
UUIDHelper.uuidFromString(characteristicUUID), callback);
|
|
495
|
+
} else {
|
|
496
|
+
callback.invoke("Peripheral not connected", null);
|
|
497
|
+
}
|
|
490
498
|
} else
|
|
491
499
|
callback.invoke("Peripheral not found");
|
|
492
500
|
}
|
|
@@ -501,13 +509,17 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
501
509
|
}
|
|
502
510
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
503
511
|
if (peripheral != null) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
512
|
+
if (peripheral.isConnected()) {
|
|
513
|
+
byte[] decoded = new byte[message.size()];
|
|
514
|
+
for (int i = 0; i < message.size(); i++) {
|
|
515
|
+
decoded[i] = Integer.valueOf(message.getInt(i)).byteValue();
|
|
516
|
+
}
|
|
517
|
+
Log.d(LOG_TAG, "Message(" + decoded.length + "): " + bytesToHex(decoded));
|
|
518
|
+
peripheral.write(UUIDHelper.uuidFromString(serviceUUID), UUIDHelper.uuidFromString(characteristicUUID),
|
|
519
|
+
decoded, (int) maxByteSize, null, callback, BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
|
|
520
|
+
} else {
|
|
521
|
+
callback.invoke("Peripheral not connected", null);
|
|
507
522
|
}
|
|
508
|
-
Log.d(LOG_TAG, "Message(" + decoded.length + "): " + bytesToHex(decoded));
|
|
509
|
-
peripheral.write(UUIDHelper.uuidFromString(serviceUUID), UUIDHelper.uuidFromString(characteristicUUID),
|
|
510
|
-
decoded, (int) maxByteSize, null, callback, BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
|
|
511
523
|
} else
|
|
512
524
|
callback.invoke("Peripheral not found");
|
|
513
525
|
}
|
|
@@ -522,13 +534,17 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
522
534
|
}
|
|
523
535
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
524
536
|
if (peripheral != null) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
537
|
+
if (peripheral.isConnected()) {
|
|
538
|
+
byte[] decoded = new byte[message.size()];
|
|
539
|
+
for (int i = 0; i < message.size(); i++) {
|
|
540
|
+
decoded[i] = Integer.valueOf(message.getInt(i)).byteValue();
|
|
541
|
+
}
|
|
542
|
+
Log.d(LOG_TAG, "Message(" + decoded.length + "): " + bytesToHex(decoded));
|
|
543
|
+
peripheral.write(UUIDHelper.uuidFromString(serviceUUID), UUIDHelper.uuidFromString(characteristicUUID),
|
|
544
|
+
decoded, (int) maxByteSize, (int) queueSleepTime, callback, BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
|
|
545
|
+
} else {
|
|
546
|
+
callback.invoke("Peripheral not connected", null);
|
|
528
547
|
}
|
|
529
|
-
Log.d(LOG_TAG, "Message(" + decoded.length + "): " + bytesToHex(decoded));
|
|
530
|
-
peripheral.write(UUIDHelper.uuidFromString(serviceUUID), UUIDHelper.uuidFromString(characteristicUUID),
|
|
531
|
-
decoded, (int) maxByteSize, (int) queueSleepTime, callback, BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
|
|
532
548
|
} else
|
|
533
549
|
callback.invoke("Peripheral not found");
|
|
534
550
|
}
|
|
@@ -542,8 +558,12 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
542
558
|
}
|
|
543
559
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
544
560
|
if (peripheral != null) {
|
|
545
|
-
peripheral.
|
|
546
|
-
|
|
561
|
+
if (peripheral.isConnected()) {
|
|
562
|
+
peripheral.read(UUIDHelper.uuidFromString(serviceUUID), UUIDHelper.uuidFromString(characteristicUUID),
|
|
563
|
+
callback);
|
|
564
|
+
} else {
|
|
565
|
+
callback.invoke("Peripheral not connected", null);
|
|
566
|
+
}
|
|
547
567
|
} else
|
|
548
568
|
callback.invoke("Peripheral not found", null);
|
|
549
569
|
}
|
|
@@ -559,13 +579,15 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
559
579
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
560
580
|
if (peripheral == null) {
|
|
561
581
|
callback.invoke("Peripheral not found", null);
|
|
582
|
+
} else if (!peripheral.isConnected()) {
|
|
583
|
+
callback.invoke("Peripheral not connected", null);
|
|
584
|
+
} else {
|
|
585
|
+
peripheral.readDescriptor(
|
|
586
|
+
UUIDHelper.uuidFromString(serviceUUID),
|
|
587
|
+
UUIDHelper.uuidFromString(characteristicUUID),
|
|
588
|
+
UUIDHelper.uuidFromString(descriptorUUID),
|
|
589
|
+
callback);
|
|
562
590
|
}
|
|
563
|
-
|
|
564
|
-
peripheral.readDescriptor(
|
|
565
|
-
UUIDHelper.uuidFromString(serviceUUID),
|
|
566
|
-
UUIDHelper.uuidFromString(characteristicUUID),
|
|
567
|
-
UUIDHelper.uuidFromString(descriptorUUID),
|
|
568
|
-
callback);
|
|
569
591
|
}
|
|
570
592
|
|
|
571
593
|
@ReactMethod
|
|
@@ -579,6 +601,8 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
579
601
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
580
602
|
if (peripheral == null) {
|
|
581
603
|
callback.invoke("Peripheral not found", null);
|
|
604
|
+
} else if (!peripheral.isConnected()) {
|
|
605
|
+
callback.invoke("Peripheral not connected", null);
|
|
582
606
|
} else {
|
|
583
607
|
byte[] decoded = new byte[message.size()];
|
|
584
608
|
for (int i = 0; i < message.size(); i++) {
|
|
@@ -594,7 +618,11 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
594
618
|
Log.d(LOG_TAG, "Retrieve services from: " + deviceUUID);
|
|
595
619
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
596
620
|
if (peripheral != null) {
|
|
597
|
-
peripheral.
|
|
621
|
+
if (peripheral.isConnected()) {
|
|
622
|
+
peripheral.retrieveServices(callback);
|
|
623
|
+
} else {
|
|
624
|
+
callback.invoke("Peripheral not connected", null);
|
|
625
|
+
}
|
|
598
626
|
} else
|
|
599
627
|
callback.invoke("Peripheral not found", null);
|
|
600
628
|
}
|
|
@@ -604,7 +632,11 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
604
632
|
Log.d(LOG_TAG, "Refreshing cache for: " + deviceUUID);
|
|
605
633
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
606
634
|
if (peripheral != null) {
|
|
607
|
-
peripheral.
|
|
635
|
+
if (peripheral.isConnected()) {
|
|
636
|
+
peripheral.refreshCache(callback);
|
|
637
|
+
} else {
|
|
638
|
+
callback.invoke("Peripheral not connected", null);
|
|
639
|
+
}
|
|
608
640
|
} else
|
|
609
641
|
callback.invoke("Peripheral not found");
|
|
610
642
|
}
|
|
@@ -614,7 +646,11 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
614
646
|
Log.d(LOG_TAG, "Read RSSI from: " + deviceUUID);
|
|
615
647
|
Peripheral peripheral = peripherals.get(deviceUUID);
|
|
616
648
|
if (peripheral != null) {
|
|
617
|
-
peripheral.
|
|
649
|
+
if (peripheral.isConnected()) {
|
|
650
|
+
peripheral.readRSSI(callback);
|
|
651
|
+
} else {
|
|
652
|
+
callback.invoke("Peripheral not connected", null);
|
|
653
|
+
}
|
|
618
654
|
} else
|
|
619
655
|
callback.invoke("Peripheral not found", null);
|
|
620
656
|
}
|
|
@@ -949,8 +985,4 @@ class BleManager extends NativeBleManagerSpec {
|
|
|
949
985
|
}
|
|
950
986
|
}
|
|
951
987
|
|
|
952
|
-
@Override
|
|
953
|
-
public void onCatalystInstanceDestroy() {
|
|
954
|
-
invalidate();
|
|
955
|
-
}
|
|
956
988
|
}
|
|
@@ -209,7 +209,7 @@ public class Peripheral extends BluetoothGattCallback {
|
|
|
209
209
|
|
|
210
210
|
map.putMap("advertising", advertising);
|
|
211
211
|
} catch (Exception e) { // this shouldn't happen
|
|
212
|
-
e.
|
|
212
|
+
Log.e(BleManager.LOG_TAG, "Unexpected error on asWritableMap", e);
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
return map;
|
|
@@ -22,6 +22,7 @@ export interface Spec extends TurboModule {
|
|
|
22
22
|
write(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, message: object[], maxByteSize: number, callback: (error: string | null) => void): void;
|
|
23
23
|
writeWithoutResponse(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, message: object[], maxByteSize: number, queueSleepTime: number, callback: (error: string | null) => void): void;
|
|
24
24
|
read(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, callback: (error: string | null, data: number[]) => void): void;
|
|
25
|
+
startNotificationWithBuffer(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, bufferLength: number, callback: (error: string | null) => void): void;
|
|
25
26
|
startNotification(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, callback: (error: string | null) => void): void;
|
|
26
27
|
stopNotification(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, callback: (error: string | null) => void): void;
|
|
27
28
|
getConnectedPeripherals(serviceUUIDStrings: string[], callback: (error: string | null, result: Peripheral[] | null) => void): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeBleManager.js","sourceRoot":"","sources":["../../src/NativeBleManager.ts"],"names":[],"mappings":";;AAAA,+CAAgE;
|
|
1
|
+
{"version":3,"file":"NativeBleManager.js","sourceRoot":"","sources":["../../src/NativeBleManager.ts"],"names":[],"mappings":";;AAAA,+CAAgE;AAsNhE,kBAAe,kCAAmB,CAAC,GAAG,CAAO,YAAY,CAAS,CAAC"}
|
|
@@ -22,6 +22,7 @@ export interface Spec extends TurboModule {
|
|
|
22
22
|
write(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, message: object[], maxByteSize: number, callback: (error: string | null) => void): void;
|
|
23
23
|
writeWithoutResponse(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, message: object[], maxByteSize: number, queueSleepTime: number, callback: (error: string | null) => void): void;
|
|
24
24
|
read(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, callback: (error: string | null, data: number[]) => void): void;
|
|
25
|
+
startNotificationWithBuffer(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, bufferLength: number, callback: (error: string | null) => void): void;
|
|
25
26
|
startNotification(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, callback: (error: string | null) => void): void;
|
|
26
27
|
stopNotification(peripheralUUID: string, serviceUUID: string, characteristicUUID: string, callback: (error: string | null) => void): void;
|
|
27
28
|
getConnectedPeripherals(serviceUUIDStrings: string[], callback: (error: string | null, result: Peripheral[] | null) => void): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeBleManager.js","sourceRoot":"","sources":["../../src/NativeBleManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,mBAAmB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"NativeBleManager.js","sourceRoot":"","sources":["../../src/NativeBleManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAsNhE,eAAe,mBAAmB,CAAC,GAAG,CAAO,YAAY,CAAS,CAAC"}
|
package/ios/BleManager.mm
CHANGED
|
@@ -206,6 +206,18 @@ RCT_EXPORT_MODULE()
|
|
|
206
206
|
[_swBleManager start:options callback:callback];
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
- (void)startNotificationWithBuffer:(NSString *)peripheralUUID
|
|
210
|
+
serviceUUID:(NSString *)serviceUUID
|
|
211
|
+
characteristicUUID:(NSString *)characteristicUUID
|
|
212
|
+
bufferLength:(double)bufferLength
|
|
213
|
+
callback:(RCTResponseSenderBlock)callback {
|
|
214
|
+
[_swBleManager startNotificationWithBuffer:peripheralUUID
|
|
215
|
+
serviceUUID:serviceUUID
|
|
216
|
+
characteristicUUID:characteristicUUID
|
|
217
|
+
bufferLength:(double)bufferLength
|
|
218
|
+
callback:callback];
|
|
219
|
+
}
|
|
220
|
+
|
|
209
221
|
- (void)startNotification:(NSString *)peripheralUUID
|
|
210
222
|
serviceUUID:(NSString *)serviceUUID
|
|
211
223
|
characteristicUUID:(NSString *)characteristicUUID
|