Updating Websocket readyState in case of websocketFailed event

Summary:
Fix for https://github.com/facebook/react-native/issues/9465

We are building a react-native based application which extensively uses WebSockets. The Android app crashes right after waking up being in suspended mode for a coupe of days and throws an exception:

"Cannot send a message. Unknown WebSocket id 1"

Before calling WebSocket.send(...) method from WebSocket.js we always check its readyState. I believe the problem is caused by not updating readyState if case of 'websocketFailed' event. this.close() cause the current used websocket ID to be removed from mWebSocketConnections HashMap (WebSocketModule.java), but readyState stays the same.
Closes https://github.com/facebook/react-native/pull/9487

Differential Revision: D3838675

Pulled By: mkonicek

fbshipit-source-id: e833cef9f1b94c6f7236077241cacf5a56f5824b
This commit is contained in:
Dmitry Petukhov 2016-09-08 17:01:10 -07:00 committed by Facebook Github Bot 2
parent b0c13ebe02
commit 6b42d5c952

View File

@ -189,6 +189,7 @@ class WebSocket extends EventTarget(...WEBSOCKET_EVENTS) {
if (ev.id !== this._socketId) {
return;
}
this.readyState = this.CLOSED;
this.dispatchEvent(new WebSocketEvent('error', {
message: ev.message,
}));