react-native-ble-manager 8.4.3 → 8.5.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/README.md CHANGED
@@ -359,7 +359,7 @@ Returns a `Promise` object.
359
359
  - `serviceUUID` - `String` - the UUID of the service.
360
360
  - `characteristicUUID` - `String` - the UUID of the characteristic.
361
361
  - `data` - `Byte array` - the data to write.
362
- - `maxByteSize` - `Integer` - specify the max byte size before splitting message
362
+ - `maxByteSize` - `Integer` - specify the max byte size before splitting message, defaults to 20 bytes if not specified
363
363
 
364
364
  **Data preparation**
365
365
 
@@ -691,12 +691,12 @@ The scanning for peripherals is ended.
691
691
 
692
692
  **Arguments**
693
693
 
694
- - `none`
694
+ - `status` - `Number` - [iOS] the reason for stopping the scan. Error code 10 is used for timeouts, 0 covers everything else. [Android] the reason for stopping the scan (<https://developer.android.com/reference/android/bluetooth/le/ScanCallback#constants_1>). Error code 10 is used for timeouts
695
695
 
696
696
  **Examples**
697
697
 
698
698
  ```js
699
- bleManagerEmitter.addListener("BleManagerStopScan", () => {
699
+ bleManagerEmitter.addListener("BleManagerStopScan", (args) => {
700
700
  // Scanning is stopped
701
701
  });
702
702
  ```
@@ -218,6 +218,7 @@ class BleManager extends ReactContextBaseJavaModule {
218
218
  if (scanManager != null) {
219
219
  scanManager.stopScan(callback);
220
220
  WritableMap map = Arguments.createMap();
221
+ map.putInt("status", 0);
221
222
  sendEvent("BleManagerStopScan", map);
222
223
  }
223
224
  }
@@ -80,6 +80,7 @@ public class LegacyScanManager extends ScanManager {
80
80
  btAdapter.stopLeScan(mLeScanCallback);
81
81
  }
82
82
  WritableMap map = Arguments.createMap();
83
+ map.putInt("status", 0);
83
84
  bleManager.sendEvent("BleManagerStopScan", map);
84
85
  }
85
86
  }
@@ -39,7 +39,7 @@ public class LollipopScanManager extends ScanManager {
39
39
  ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder();
40
40
  List<ScanFilter> filters = new ArrayList<>();
41
41
 
42
- if (options.hasKey("legacy")) {
42
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && options.hasKey("legacy")) {
43
43
  scanSettingsBuilder.setLegacy(options.getBoolean("legacy"));
44
44
  }
45
45
 
@@ -101,6 +101,7 @@ public class LollipopScanManager extends ScanManager {
101
101
  btAdapter.getBluetoothLeScanner().stopScan(mScanCallback);
102
102
  }
103
103
  WritableMap map = Arguments.createMap();
104
+ map.putInt("status", 10);
104
105
  bleManager.sendEvent("BleManagerStopScan", map);
105
106
  }
106
107
  }
@@ -145,6 +146,7 @@ public class LollipopScanManager extends ScanManager {
145
146
  @Override
146
147
  public void onScanFailed(final int errorCode) {
147
148
  WritableMap map = Arguments.createMap();
149
+ map.putInt("status", errorCode);
148
150
  bleManager.sendEvent("BleManagerStopScan", map);
149
151
  }
150
152
  };
@@ -419,6 +419,7 @@ public class Peripheral extends BluetoothGattCallback {
419
419
  return;
420
420
  }
421
421
  sendBackrError(readCallback, "Error reading " + characteristic.getUuid() + " status=" + status);
422
+ readCallback = null;
422
423
  } else if (readCallback != null) {
423
424
  final byte[] dataValue = copyOf(characteristic.getValue());
424
425
  final Callback callback = readCallback;
@@ -449,6 +450,7 @@ public class Peripheral extends BluetoothGattCallback {
449
450
  return;
450
451
  }
451
452
  sendBackrError(writeCallback, "Error writing " + characteristic.getUuid() + " status=" + status);
453
+ writeCallback = null;
452
454
  } else if (writeCallback != null) {
453
455
  final Callback callback = writeCallback;
454
456
  mainHandler.post(new Runnable() {
@@ -470,8 +472,8 @@ public class Peripheral extends BluetoothGattCallback {
470
472
  registerNotifyCallback.invoke();
471
473
  Log.d(BleManager.LOG_TAG, "onDescriptorWrite success");
472
474
  } else {
473
- registerNotifyCallback.invoke("Error writing descriptor stats=" + status, null);
474
- Log.e(BleManager.LOG_TAG, "Error writing descriptor stats=" + status);
475
+ registerNotifyCallback.invoke("Error writing descriptor status=" + status, null);
476
+ Log.e(BleManager.LOG_TAG, "Error writing descriptor status=" + status);
475
477
  }
476
478
 
477
479
  registerNotifyCallback = null;
@@ -832,8 +834,11 @@ public class Peripheral extends BluetoothGattCallback {
832
834
  else
833
835
  writeCallback = null;
834
836
  if (!gatt.writeCharacteristic(characteristic)) {
835
- sendBackrError(writeCallback, "Write failed");
836
- writeCallback = null;
837
+ // For write without response the caller will handle all callback states
838
+ if (writeCallback != null) {
839
+ writeCallback.invoke("Write failed", writeCallback);
840
+ writeCallback = null;
841
+ }
837
842
  completedCommand();
838
843
  }
839
844
  }
package/ios/BleManager.m CHANGED
@@ -378,7 +378,7 @@ RCT_EXPORT_METHOD(stopScan:(nonnull RCTResponseSenderBlock)callback)
378
378
  }
379
379
  [manager stopScan];
380
380
  if (hasListeners) {
381
- [self sendEventWithName:@"BleManagerStopScan" body:@{}];
381
+ [self sendEventWithName:@"BleManagerStopScan" body:@{@"status": @0}];
382
382
  }
383
383
  callback(@[[NSNull null]]);
384
384
  }
@@ -390,7 +390,7 @@ RCT_EXPORT_METHOD(stopScan:(nonnull RCTResponseSenderBlock)callback)
390
390
  [manager stopScan];
391
391
  if (hasListeners) {
392
392
  if (self.bridge) {
393
- [self sendEventWithName:@"BleManagerStopScan" body:@{}];
393
+ [self sendEventWithName:@"BleManagerStopScan" body:@{@"status": @10}];
394
394
  }
395
395
  }
396
396
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-manager",
3
- "version": "8.4.3",
3
+ "version": "8.5.0",
4
4
  "description": "A BLE module for react native.",
5
5
  "main": "BleManager",
6
6
  "types": "./index.d.ts",