Skip to content

Commit

Permalink
FIX avoid crash when sendMessage is called when connection is closed (#…
Browse files Browse the repository at this point in the history
…79)

* ISSUE #66
* also referenced in ISSUE #32

Signed-off-by: Vinicius Cubas Brand <[email protected]>
  • Loading branch information
viniciuscb authored Mar 21, 2023
1 parent bf853d7 commit 585624d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions android/src/main/java/io/wifi/p2p/WiFiP2PManagerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ public void onFailure(int reasonCode) {

@ReactMethod
public void sendFile(String filePath, final Promise promise) {
sendFileTo(filePath, wifiP2pInfo.groupOwnerAddress.getHostAddress(), promise);
if (wifiP2pInfo.groupOwnerAddress != null) {
sendFileTo(filePath, wifiP2pInfo.groupOwnerAddress.getHostAddress(), promise);
} else {
promise.reject("CONNECTION_CLOSED");
}
}

@ReactMethod
Expand Down Expand Up @@ -331,7 +335,11 @@ public void invoke(Object object) {

@ReactMethod
public void sendMessage(String message, final Promise promise) {
sendMessageTo(message, wifiP2pInfo.groupOwnerAddress.getHostAddress(), promise);
if (wifiP2pInfo.groupOwnerAddress != null) {
sendMessageTo(message, wifiP2pInfo.groupOwnerAddress.getHostAddress(), promise);
} else {
promise.reject("CONNECTION_CLOSED");
}
}

@ReactMethod
Expand Down

0 comments on commit 585624d

Please sign in to comment.