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
This commit is contained in:
Zack 2016-03-06 14:56:30 -08:00 коммит произвёл Facebook Github Bot 0
Родитель 4130f11b9d
Коммит 025281230d
1 изменённых файлов: 1 добавлений и 0 удалений

Просмотреть файл

@ -117,6 +117,7 @@ class WebSocket extends WebSocketBase {
var event = new WebSocketEvent('error'); var event = new WebSocketEvent('error');
event.message = ev.message; event.message = ev.message;
this.onerror && this.onerror(event); this.onerror && this.onerror(event);
this.onclose && this.onclose(event);
this.dispatchEvent(event); this.dispatchEvent(event);
this._unregisterEvents(); this._unregisterEvents();
this.close(); this.close();