From 3a8ca56fb4c3ad9c182e64682302a48395affe8d Mon Sep 17 00:00:00 2001 From: Neal Manaktola Date: Tue, 31 May 2022 15:21:56 -0400 Subject: [PATCH 1/2] [android] implement invalidate() on WebSocketModule to match iOS --- .../react/modules/websocket/WebSocketModule.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java index 9fa81b6d0590ab..c034af41e09f12 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java @@ -42,6 +42,8 @@ public final class WebSocketModule extends NativeWebSocketModuleSpec { public static final String NAME = "WebSocketModule"; + public static final int STATUS_CODE_NORMAL = 1000; + public interface ContentHandler { void onMessage(String text, WritableMap params); @@ -418,4 +420,14 @@ public void addListener(String eventName) {} @Override public void removeListeners(double count) {} + + @Override + public void invalidate() { + mOnOpenHandler = null; + mContentHandlers.clear(); + for (WebSocket socket : mWebSocketConnections.values()) { + socket.close(STATUS_CODE_NORMAL, null); + } + mWebSocketConnections.clear(); + } } From 55687ed116a28e2e591cea822d98aa3f2cc369af Mon Sep 17 00:00:00 2001 From: Neal Manaktola Date: Tue, 31 May 2022 15:25:32 -0400 Subject: [PATCH 2/2] add super --- .../com/facebook/react/modules/websocket/WebSocketModule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java index c034af41e09f12..63adc75fbbe45b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java @@ -423,6 +423,7 @@ public void removeListeners(double count) {} @Override public void invalidate() { + super.invalidate(); mOnOpenHandler = null; mContentHandlers.clear(); for (WebSocket socket : mWebSocketConnections.values()) {