react-native-ble-manager 10.1.2 → 10.1.4
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 +9 -1
- package/android/src/main/java/it/innove/DefaultPeripheral.java +6 -0
- package/android/src/main/java/it/innove/NotifyBufferContainer.java +7 -4
- package/android/src/main/java/it/innove/Peripheral.java +2 -7
- package/dist/cjs/types.d.ts +1 -1
- package/dist/esm/types.d.ts +1 -1
- package/ios/BleManager.m +16 -7
- package/package.json +1 -1
- package/src/types.ts +2 -2
|
@@ -175,7 +175,15 @@ class BleManager extends ReactContextBaseJavaModule {
|
|
|
175
175
|
if (getCurrentActivity() == null)
|
|
176
176
|
callback.invoke("Current activity not available");
|
|
177
177
|
else
|
|
178
|
-
|
|
178
|
+
{
|
|
179
|
+
try{
|
|
180
|
+
getCurrentActivity().startActivityForResult(intentEnable, ENABLE_REQUEST);
|
|
181
|
+
}catch(Exception e){
|
|
182
|
+
callback.invoke("Current activity not available");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
179
187
|
} else
|
|
180
188
|
callback.invoke();
|
|
181
189
|
}
|
|
@@ -5,6 +5,7 @@ import android.bluetooth.le.ScanRecord;
|
|
|
5
5
|
import android.bluetooth.le.ScanResult;
|
|
6
6
|
import android.os.Build;
|
|
7
7
|
import android.os.ParcelUuid;
|
|
8
|
+
import android.annotation.SuppressLint;
|
|
8
9
|
|
|
9
10
|
import com.facebook.react.bridge.Arguments;
|
|
10
11
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
@@ -15,6 +16,7 @@ import com.facebook.react.bridge.WritableMap;
|
|
|
15
16
|
import java.util.Map;
|
|
16
17
|
|
|
17
18
|
|
|
19
|
+
@SuppressLint("MissingPermission")
|
|
18
20
|
public class DefaultPeripheral extends Peripheral {
|
|
19
21
|
|
|
20
22
|
private ScanRecord advertisingData;
|
|
@@ -36,6 +38,10 @@ public class DefaultPeripheral extends Peripheral {
|
|
|
36
38
|
WritableMap advertising = Arguments.createMap();
|
|
37
39
|
|
|
38
40
|
try {
|
|
41
|
+
map.putString("name", device.getName());
|
|
42
|
+
map.putString("id", device.getAddress()); // mac address
|
|
43
|
+
map.putInt("rssi", advertisingRSSI);
|
|
44
|
+
|
|
39
45
|
advertising.putMap("manufacturerData", byteArrayToWritableMap(advertisingDataBytes));
|
|
40
46
|
|
|
41
47
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
@@ -12,18 +12,21 @@ public class NotifyBufferContainer {
|
|
|
12
12
|
this.items.clear();
|
|
13
13
|
}
|
|
14
14
|
public byte[] put(byte[] value){
|
|
15
|
-
int restLength = value.length - this.items.remaining();
|
|
16
15
|
byte[] toInsert = null;
|
|
17
16
|
byte[] rest = null;
|
|
18
|
-
|
|
17
|
+
|
|
18
|
+
if (value.length > this.items.remaining()) {
|
|
19
|
+
int restLength = value.length - this.items.remaining();
|
|
19
20
|
rest = new byte[restLength];
|
|
20
|
-
toInsert = new byte[
|
|
21
|
+
toInsert = new byte[this.items.remaining()];
|
|
21
22
|
System.arraycopy(value, 0, toInsert, 0, toInsert.length);
|
|
22
|
-
System.arraycopy(value, toInsert.length, rest,
|
|
23
|
+
System.arraycopy(value, toInsert.length, rest, 0, rest.length);
|
|
23
24
|
} else {
|
|
24
25
|
toInsert = value;
|
|
25
26
|
}
|
|
27
|
+
|
|
26
28
|
this.items.put(toInsert);
|
|
29
|
+
|
|
27
30
|
return rest;
|
|
28
31
|
}
|
|
29
32
|
public boolean isBufferFull(){
|
|
@@ -52,7 +52,7 @@ public class Peripheral extends BluetoothGattCallback {
|
|
|
52
52
|
public static final int GATT_INSUFFICIENT_AUTHENTICATION = 5;
|
|
53
53
|
public static final int GATT_AUTH_FAIL = 137;
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
protected final BluetoothDevice device;
|
|
56
56
|
private final Map<String, NotifyBufferContainer> bufferedCharacteristics;
|
|
57
57
|
protected volatile byte[] advertisingDataBytes = new byte[0];
|
|
58
58
|
protected volatile int advertisingRSSI;
|
|
@@ -435,11 +435,7 @@ public class Peripheral extends BluetoothGattCallback {
|
|
|
435
435
|
byte[] rest = null;
|
|
436
436
|
if (buffer != null) {
|
|
437
437
|
rest = buffer.put(dataValue);
|
|
438
|
-
Log.d(BleManager.LOG_TAG, "onCharacteristicChanged-buffering: " +
|
|
439
|
-
buffer.size() + " from peripheral: " + device.getAddress());
|
|
440
|
-
|
|
441
438
|
if (buffer.isBufferFull()) {
|
|
442
|
-
Log.d(BleManager.LOG_TAG, "onCharacteristicChanged sending buffered data " + buffer.size());
|
|
443
439
|
|
|
444
440
|
// fetch and reset
|
|
445
441
|
dataValue = buffer.items.array();
|
|
@@ -448,8 +444,7 @@ public class Peripheral extends BluetoothGattCallback {
|
|
|
448
444
|
return;
|
|
449
445
|
}
|
|
450
446
|
}
|
|
451
|
-
|
|
452
|
-
+ " from peripheral: " + device.getAddress());
|
|
447
|
+
|
|
453
448
|
WritableMap map = Arguments.createMap();
|
|
454
449
|
map.putString("peripheral", device.getAddress());
|
|
455
450
|
map.putString("characteristic", charString);
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface AdvertisingData {
|
|
|
37
37
|
isConnectable?: boolean;
|
|
38
38
|
localName?: string;
|
|
39
39
|
manufacturerData?: CustomAdvertisingData;
|
|
40
|
-
serviceData?: CustomAdvertisingData
|
|
40
|
+
serviceData?: Record<string, CustomAdvertisingData>;
|
|
41
41
|
serviceUUIDs?: string[];
|
|
42
42
|
txPowerLevel?: number;
|
|
43
43
|
}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface AdvertisingData {
|
|
|
37
37
|
isConnectable?: boolean;
|
|
38
38
|
localName?: string;
|
|
39
39
|
manufacturerData?: CustomAdvertisingData;
|
|
40
|
-
serviceData?: CustomAdvertisingData
|
|
40
|
+
serviceData?: Record<string, CustomAdvertisingData>;
|
|
41
41
|
serviceUUIDs?: string[];
|
|
42
42
|
txPowerLevel?: number;
|
|
43
43
|
}
|
package/ios/BleManager.m
CHANGED
|
@@ -112,11 +112,19 @@ static bool hasListeners = NO;
|
|
|
112
112
|
[self invokeAndClearDictionary:readDescriptorCallbacks withKey:key usingParameters:@[error, [NSNull null]]];
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
|
-
|
|
115
|
+
|
|
116
|
+
if ([descriptor.value isKindOfClass:[NSData class]]) {
|
|
117
|
+
NSLog(@"Read value [descriptor: %@, characteristic: %@]: (%lu) %@",
|
|
118
|
+
descriptor.UUID,
|
|
119
|
+
descriptor.characteristic.UUID,
|
|
120
|
+
[(NSData *)descriptor.value length],
|
|
121
|
+
descriptor.value);
|
|
122
|
+
} else {
|
|
123
|
+
NSLog(@"Read value [descriptor: %@, characteristic: %@]: %@",
|
|
116
124
|
descriptor.UUID,
|
|
117
125
|
descriptor.characteristic.UUID,
|
|
118
|
-
[descriptor.value length],
|
|
119
126
|
descriptor.value);
|
|
127
|
+
}
|
|
120
128
|
|
|
121
129
|
NSMutableArray* peripheralReadDescriptorCallbacks = [readDescriptorCallbacks objectForKey:key];
|
|
122
130
|
if (peripheralReadDescriptorCallbacks != NULL) {
|
|
@@ -185,7 +193,7 @@ static bool hasListeners = NO;
|
|
|
185
193
|
|
|
186
194
|
|
|
187
195
|
|
|
188
|
-
- (NSString *) centralManagerStateToString: (
|
|
196
|
+
- (NSString *) centralManagerStateToString: (CBManagerState)state
|
|
189
197
|
{
|
|
190
198
|
switch (state) {
|
|
191
199
|
case CBManagerStateUnknown:
|
|
@@ -406,9 +414,11 @@ RCT_EXPORT_METHOD(scan:(NSArray *)serviceUUIDStrings timeoutSeconds:(nonnull NSN
|
|
|
406
414
|
}
|
|
407
415
|
[manager scanForPeripheralsWithServices:serviceUUIDs options:options];
|
|
408
416
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
417
|
+
if ([timeoutSeconds floatValue] > 0) {
|
|
418
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
419
|
+
self.scanTimer = [NSTimer scheduledTimerWithTimeInterval:[timeoutSeconds floatValue] target:self selector:@selector(stopScanTimer:) userInfo: nil repeats:NO];
|
|
420
|
+
});
|
|
421
|
+
}
|
|
412
422
|
callback(@[]);
|
|
413
423
|
}
|
|
414
424
|
|
|
@@ -972,7 +982,6 @@ RCT_EXPORT_METHOD(requestMTU:(NSString *)deviceUUID mtu:(NSInteger)mtu callback:
|
|
|
972
982
|
}
|
|
973
983
|
NSLog(@"Characteristics For Service Discover");
|
|
974
984
|
|
|
975
|
-
NSString *peripheralUUIDString = [peripheral uuidAsString];
|
|
976
985
|
NSMutableSet *characteristicsForService = [NSMutableSet new];
|
|
977
986
|
[characteristicsForService addObjectsFromArray:service.characteristics];
|
|
978
987
|
[retrieveServicesLatches setObject:characteristicsForService forKey:service.UUID.UUIDString];
|
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -39,7 +39,7 @@ export interface AdvertisingData {
|
|
|
39
39
|
isConnectable?: boolean;
|
|
40
40
|
localName?: string;
|
|
41
41
|
manufacturerData?: CustomAdvertisingData;
|
|
42
|
-
serviceData?: CustomAdvertisingData
|
|
42
|
+
serviceData?: Record<string, CustomAdvertisingData>;
|
|
43
43
|
serviceUUIDs?: string[];
|
|
44
44
|
txPowerLevel?: number;
|
|
45
45
|
}
|
|
@@ -76,7 +76,7 @@ export interface StartOptions {
|
|
|
76
76
|
forceLegacy?: boolean;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export interface ConnectOptions {
|
|
79
|
+
export interface ConnectOptions {
|
|
80
80
|
/**
|
|
81
81
|
* [android only]
|
|
82
82
|
*/
|