mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix WebSocketModule not closing connections on reload
Summary: Saw in the logs an ever increasing number of warnings coming from WebSocketModule about requesting an instance that has already gone away. On module invalidation we should close all outstanding websockets, as they will no longer be able to send events to JS. Changelog: [Android][Fixed] On instance destroy, websockets are correctly closed Reviewed By: mdvacca Differential Revision: D40897255 fbshipit-source-id: 1578de8baa342479d14ee1070c3314d45c7fbd8d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6a23b131e5
commit
b5ea5a2c4d
+11
-3
@@ -58,10 +58,18 @@ public final class WebSocketModule extends NativeWebSocketModuleSpec {
|
||||
mCookieHandler = new ForwardingCookieHandler(context);
|
||||
}
|
||||
|
||||
private void sendEvent(String eventName, WritableMap params) {
|
||||
ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
|
||||
@Override
|
||||
public void invalidate() {
|
||||
for (WebSocket socket : mWebSocketConnections.values()) {
|
||||
socket.close(1001 /* endpoint is going away */, null);
|
||||
}
|
||||
mWebSocketConnections.clear();
|
||||
mContentHandlers.clear();
|
||||
}
|
||||
|
||||
if (reactApplicationContext != null) {
|
||||
private void sendEvent(String eventName, WritableMap params) {
|
||||
ReactApplicationContext reactApplicationContext = getReactApplicationContext();
|
||||
if (reactApplicationContext.hasActiveReactInstance()) {
|
||||
reactApplicationContext
|
||||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
||||
.emit(eventName, params);
|
||||
|
||||
Reference in New Issue
Block a user