From 43eb70a738fe581d5b127de8a275c0435797e59b Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sun, 29 May 2016 15:11:36 +0800 Subject: [PATCH] fix for hang on activity suspend/resume --- .../src/main/java/com/peel/react/TcpSockets.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/android/core/src/main/java/com/peel/react/TcpSockets.java b/android/core/src/main/java/com/peel/react/TcpSockets.java index 844cbe6..ef51671 100644 --- a/android/core/src/main/java/com/peel/react/TcpSockets.java +++ b/android/core/src/main/java/com/peel/react/TcpSockets.java @@ -142,6 +142,9 @@ public final class TcpSockets extends ReactContextBaseJavaModule implements TcpS @Override public void onConnection(Integer serverId, Integer clientId, InetSocketAddress socketAddress) { + if (mShuttingDown) { + return; + } WritableMap eventParams = Arguments.createMap(); eventParams.putInt("id", clientId); @@ -160,6 +163,9 @@ public final class TcpSockets extends ReactContextBaseJavaModule implements TcpS @Override public void onConnect(Integer id, InetSocketAddress address) { + if (mShuttingDown) { + return; + } WritableMap eventParams = Arguments.createMap(); eventParams.putString("address", address.getHostName()); eventParams.putInt("port", address.getPort()); @@ -173,6 +179,9 @@ public final class TcpSockets extends ReactContextBaseJavaModule implements TcpS @Override public void onData(Integer id, byte[] data) { + if (mShuttingDown) { + return; + } ReactContext reactContext = TcpSockets.this.getReactApplicationContext(); reactContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) @@ -181,6 +190,9 @@ public final class TcpSockets extends ReactContextBaseJavaModule implements TcpS @Override public void onClose(Integer id, String error) { + if (mShuttingDown) { + return; + } if (error != null) { onError(id, error); } @@ -193,6 +205,9 @@ public final class TcpSockets extends ReactContextBaseJavaModule implements TcpS @Override public void onError(Integer id, String error) { + if (mShuttingDown) { + return; + } ReactContext reactContext = TcpSockets.this.getReactApplicationContext(); reactContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)