diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2013-06-12 14:16:57 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-06-12 14:51:27 +0000 |
commit | 15b217d26278471ee713f46340981c862e3839d2 (patch) | |
tree | aab44321fef486b7868080ef4372475065defb68 /WebContent | |
parent | 5f66766f02b86aeda0089b8bb15da5b2c6e40715 (diff) | |
download | vaadin-framework-15b217d26278471ee713f46340981c862e3839d2.tar.gz vaadin-framework-15b217d26278471ee713f46340981c862e3839d2.zip |
Handle push disconnections and reconnections more reliably (#11831, #11922)
Client-side:
* Call onOpen() also after a successful reconnection
* Reliably call onClose() and try to reconnect after disconnection
* Don't try to reconnect if !isApplicationRunning() after push
* Queue messages while trying to reconnect (state CONNECT_PENDING)
Server-side:
* Implement AtmosphereResourceEventListener.onDisconnect()
* Push marked as pending until client reconnects (if ever)
Change-Id: I1783eb72eb7005b07cae786d8ec8371da3903108
Diffstat (limited to 'WebContent')
-rw-r--r-- | WebContent/VAADIN/jquery.atmosphere.js | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/WebContent/VAADIN/jquery.atmosphere.js b/WebContent/VAADIN/jquery.atmosphere.js index 2b176668c1..eb57ed6d53 100644 --- a/WebContent/VAADIN/jquery.atmosphere.js +++ b/WebContent/VAADIN/jquery.atmosphere.js @@ -341,12 +341,7 @@ jQuery.atmosphere = function() { _request.ctime = jQuery.now(); if (_request.transport != 'websocket' && _request.transport != 'sse') { - // Gives a chance to the connection to be established before calling the callback - setTimeout(function() { - _open('opening', _request.transport, _request); - }, 500); _executeRequest(); - } else if (_request.transport == 'websocket') { if (!_supportWebsocket()) { _reconnectWithFallbackTransport("Websocket is not supported, using request.fallbackTransport (" + _request.fallbackTransport + ")"); @@ -685,6 +680,8 @@ jQuery.atmosphere = function() { _close(); }; + request.closed = false; + if (_response.error == null) { _response.request = request; var prevState = _response.state; @@ -1025,10 +1022,6 @@ jQuery.atmosphere = function() { jQuery.atmosphere.debug("Using URL: " + location); } - if (webSocketOpened) { - _open('re-opening', "websocket", _request); - } - if (webSocketOpened && !_request.reconnect) { if (_websocket != null) { _clearState(); @@ -1068,9 +1061,7 @@ jQuery.atmosphere = function() { jQuery.atmosphere.debug("Websocket successfully opened"); } - if (!webSocketOpened) { - _open('opening', "websocket", _request); - } + _open('opening', 'websocket', _request); webSocketOpened = true; _websocket.webSocketOpened = webSocketOpened; @@ -1445,10 +1436,14 @@ jQuery.atmosphere = function() { if (_abordingConnection) { return; } + _response.error = null; var skipCallbackInvocation = false; var update = false; + if (rq.transport == 'streaming' && ajaxRequest.readyState == 2) { + _open('opening', rq.transport, rq); + } // Opera doesn't call onerror if the server disconnect. if (jQuery.browser.opera @@ -1483,6 +1478,7 @@ jQuery.atmosphere = function() { // Prevent onerror callback to be called _response.errorHandled = true; _clearState(); + _invokeClose(true); reconnectF(); return; } @@ -1579,6 +1575,11 @@ jQuery.atmosphere = function() { } _verifyStreamingLength(ajaxRequest, rq); + + if (rq.transport == 'streaming' && rq.readyState == 4) { + _invokeClose(true); + reconnectF(); + } } }; ajaxRequest.send(rq.data); @@ -1669,16 +1670,12 @@ jQuery.atmosphere = function() { _response.status = status == 0 ? 204 : status; _response.reason = status == 0 ? "Server resumed the connection or down." : "OK"; - var reconnectInterval = (request.connectTimeout == -1) ? 0 : request.connectTimeout; + var reconnectInterval = request.reconnectInterval; // Reconnect immedialtely - if (!force) { - request.id = setTimeout(function () { - _executeRequest(request); - }, reconnectInterval); - } else { + request.id = setTimeout(function () { _executeRequest(request); - } + }, reconnectInterval); } } } |