Skip to content

Commit

Permalink
Merge pull request #1306 from innoveit/fix/missing_method
Browse files Browse the repository at this point in the history
Fix - added missing startNotificationWithBuffer
  • Loading branch information
marcosinigaglia authored Dec 20, 2024
2 parents 87002cd + 964c250 commit 2d3809b
Show file tree
Hide file tree
Showing 5 changed files with 330 additions and 300 deletions.
6 changes: 3 additions & 3 deletions android/src/main/java/it/innove/BleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ public void disconnect(String peripheralUUID, boolean force, Callback callback)
}

@ReactMethod
public void startNotificationUseBuffer(String deviceUUID, String serviceUUID, String characteristicUUID,
double buffer, Callback callback) {
public void startNotificationWithBuffer(String deviceUUID, String serviceUUID, String characteristicUUID,
double bufferLength, Callback callback) {
Log.d(LOG_TAG, "startNotification");
if (serviceUUID == null || characteristicUUID == null) {
callback.invoke("ServiceUUID and characteristicUUID required.");
Expand All @@ -456,7 +456,7 @@ public void startNotificationUseBuffer(String deviceUUID, String serviceUUID, St
Peripheral peripheral = peripherals.get(deviceUUID);
if (peripheral != null) {
peripheral.registerNotify(UUIDHelper.uuidFromString(serviceUUID),
UUIDHelper.uuidFromString(characteristicUUID), (int) buffer, callback);
UUIDHelper.uuidFromString(characteristicUUID), (int) bufferLength, callback);
} else
callback.invoke("Peripheral not found");
}
Expand Down
6 changes: 3 additions & 3 deletions docs/methods.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ BleManager.startNotification(

---

## startNotificationUseBuffer(peripheralId, serviceUUID, characteristicUUID, buffer) [Android only]
## startNotificationWithBuffer(peripheralId, serviceUUID, characteristicUUID, buffer) [Android only]

Start the notification on the specified characteristic, you need to call `retrieveServices` method before. The buffer collect messages until the buffer of messages bytes reaches the limit defined with the `buffer` argument and then emit all the collected data. Helpful to reducing the number or js bridge crossings when a characteristic is sending a lot of messages.
Start the notification on the specified characteristic, you need to call `retrieveServices` method before. The buffer collect messages until the buffer of messages bytes reaches the limit defined with the `buffer` argument and then emit all the collected data. Useful to reduce the number of calls between the native and the react-native part in case of many messages.
Returns a `Promise` object.

**Arguments**
Expand All @@ -271,7 +271,7 @@ Returns a `Promise` object.
**Examples**

```js
BleManager.startNotification(
BleManager.startNotificationWithBuffer(
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
Expand Down
12 changes: 12 additions & 0 deletions ios/BleManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ - (void)start:(NSDictionary *)options
[_swBleManager start:options callback:callback];
}

- (void)startNotificationWithBuffer:(NSString *)peripheralUUID
serviceUUID:(NSString *)serviceUUID
characteristicUUID:(NSString *)characteristicUUID
bufferLength:(double)bufferLength
callback:(RCTResponseSenderBlock)callback {
[_swBleManager startNotificationWithBuffer:peripheralUUID
serviceUUID:serviceUUID
characteristicUUID:characteristicUUID
bufferLength:(double)bufferLength
callback:callback];
}

- (void)startNotification:(NSString *)peripheralUUID
serviceUUID:(NSString *)serviceUUID
characteristicUUID:(NSString *)characteristicUUID
Expand Down
Loading

0 comments on commit 2d3809b

Please sign in to comment.