Description
When subscribing to a BLE characteristic, if the peripheral device sends data immediately after the CCCD write (subscription enable) is completed, the first chunk of data is not received by the JavaScript callback. Subsequent notifications are received normally.
Environment
- **Node Version:22.22.3
- **Java Version:openjdk 17.0.2
- **React Native Version:0.83.9
- OS: [Android] Ios has not been tested
Steps To Reproduce
- Connect to a BLE peripheral that is configured to send a response immediately upon receiving a CCCD subscription enable command.
- Call
subscribeToCharacteristic for the target notify characteristic.
- Observe the logs. The first data packet sent by the device right after subscription is missing.
- Trigger another action on the device to send more data. Subsequent packets are received successfully.
Expected Behavior
All data sent by the peripheral after the subscription promise resolves should be captured by the callback.
Actual Behavior
The very first notification payload is dropped/lost. Only subsequent notifications trigger the callback.
Code Snippet
Here is the current subscription implementation:
private async subscribeToNotifications(): Promise<void> {
await this.unsubscribeFromNotifications();
const isSubscribed = bleManager.isSubscribedToCharacteristic(
this.deviceId,
this.serviceUUID,
this.notifyCharUUID,
);
logger.debug('transport', 'ble.notify.current_status', {
deviceId: this.deviceId,
isSubscribed,
});
this.notifySubscription = await bleManager.subscribeToCharacteristic(
this.deviceId,
this.serviceUUID,
this.notifyCharUUID,
(_characteristicId, data) => {
logger.debug('transport', 'ble.notify.received', {
deviceId: this.deviceId,
length: data.length,
});
this.receiveCallback?.(new Uint8Array(data));
},
);
logger.info('transport', 'ble.notify.subscribed', {
deviceId: this.deviceId,
});
}
Description
When subscribing to a BLE characteristic, if the peripheral device sends data immediately after the CCCD write (subscription enable) is completed, the first chunk of data is not received by the JavaScript callback. Subsequent notifications are received normally.
Environment
Steps To Reproduce
subscribeToCharacteristicfor the target notify characteristic.Expected Behavior
All data sent by the peripheral after the subscription promise resolves should be captured by the callback.
Actual Behavior
The very first notification payload is dropped/lost. Only subsequent notifications trigger the callback.
Code Snippet
Here is the current subscription implementation: