From 025281230de2e316f2770a2db71f8bec6fe43a07 Mon Sep 17 00:00:00 2001 From: Zack Date: Sun, 6 Mar 2016 14:56:30 -0800 Subject: [PATCH] WebSocket: call onclose before closing in event of error Summary:Motivation: Developer expects `onclose` to be called before/during close of the websocket. The `websocketFailed` event triggers a close but does not invoke onclose. Testplan: Connect to a websocket server from android, terminate the server, observe that onerror is called, the websocket is closed, but onclose is not called. Note: the observed bug is in android only because in iOS the underlying websocket implementation fires the `websocketClosed` rather than `websocketFailed` event when the server terminates. Nevertheless, the justification for this change stands that regardless of the cause of the close, if `this.close` is called it is expected this.onclose should be called as well. Closes https://github.com/facebook/react-native/pull/6307 Differential Revision: D3017458 fb-gh-sync-id: c9e2dfefa597b4e99ee85eaa991667c347f86d83 shipit-source-id: c9e2dfefa597b4e99ee85eaa991667c347f86d83 --- Libraries/WebSocket/WebSocket.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Libraries/WebSocket/WebSocket.js b/Libraries/WebSocket/WebSocket.js index 3814b4e55..ec6f722ef 100644 --- a/Libraries/WebSocket/WebSocket.js +++ b/Libraries/WebSocket/WebSocket.js @@ -117,6 +117,7 @@ class WebSocket extends WebSocketBase { var event = new WebSocketEvent('error'); event.message = ev.message; this.onerror && this.onerror(event); + this.onclose && this.onclose(event); this.dispatchEvent(event); this._unregisterEvents(); this.close();