From d380e0f39805e2c13a9caaf221c925546665c125 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 9 Apr 2018 23:14:59 +0200 Subject: [PATCH] Keep trying to connect in case the websocket goes down --- platypush/backend/http/static/js/application.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/platypush/backend/http/static/js/application.js b/platypush/backend/http/static/js/application.js index abb5f6b83..b2562c2b7 100644 --- a/platypush/backend/http/static/js/application.js +++ b/platypush/backend/http/static/js/application.js @@ -1,7 +1,7 @@ $(document).ready(function() { var websocket, dateTimeInterval, - websocketReconnectTimeout, + websocketReconnectInterval, eventListeners = []; var initWebsocket = function() { @@ -19,6 +19,10 @@ $(document).ready(function() { websocket.onopen = function(event) { console.log('Websocket connection successful'); + if (websocketReconnectInterval) { + clearInterval(websocketReconnectInterval); + websocketReconnectInterval = undefined; + } }; websocket.onerror = function(event) { @@ -27,7 +31,7 @@ $(document).ready(function() { websocket.onclose = function(event) { console.log('Websocket closed, code: ' + event.code); - websocketReconnectTimeout = setTimeout(function() { + websocketReconnectInterval = setInterval(function() { initWebsocket(); }, 5000); };