Skip to content

Commit

Permalink
ensure peripheral is connected when calling startNotification and sto…
Browse files Browse the repository at this point in the history
…pNotification See #343
  • Loading branch information
don committed Jan 5, 2017
1 parent 0d9024a commit f81c2cd
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/android/BLECentralPlugin.java
Expand Up @@ -416,6 +416,11 @@ private void registerNotifyCallback(CallbackContext callbackContext, String macA
Peripheral peripheral = peripherals.get(macAddress);
if (peripheral != null) {

if (!peripheral.isConnected()) {
callbackContext.error("Peripheral " + macAddress + " is not connected.");
return;
}

//peripheral.setOnDataCallback(serviceUUID, characteristicUUID, callbackContext);
peripheral.queueRegisterNotifyCallback(callbackContext, serviceUUID, characteristicUUID);

Expand All @@ -432,6 +437,11 @@ private void removeNotifyCallback(CallbackContext callbackContext, String macAdd
Peripheral peripheral = peripherals.get(macAddress);
if (peripheral != null) {

if (!peripheral.isConnected()) {
callbackContext.error("Peripheral " + macAddress + " is not connected.");
return;
}

peripheral.queueRemoveNotifyCallback(callbackContext, serviceUUID, characteristicUUID);

} else {
Expand Down

0 comments on commit f81c2cd

Please sign in to comment.