From f3d725c8908880a332467e584303a7470a3dc540 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 10 Apr 2018 19:49:37 +0200 Subject: [PATCH] Making the websocket reconnect client-side logic a bit more consistent --- platypush/backend/http/static/js/application.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/platypush/backend/http/static/js/application.js b/platypush/backend/http/static/js/application.js index f712d18996..03a35596b7 100644 --- a/platypush/backend/http/static/js/application.js +++ b/platypush/backend/http/static/js/application.js @@ -4,7 +4,7 @@ $(document).ready(function() { openedWebsocket, dateTimeInterval, websocketTimeoutId, - websocketReconnectMsecs = 4000, + websocketReconnectMsecs = 5000, eventListeners = []; var initWebsocket = function() { @@ -15,14 +15,14 @@ $(document).ready(function() { return; } - pendingConnection = websocket; + pendingConnection = true; - var onWebsocketTimeout = function(sock) { + var onWebsocketTimeout = function(self) { return function() { console.log('Websocket reconnection timed out, retrying'); pendingConnection = false; - sock.close(); - sock.onclose({ code: 1000 }); + self.close(); + self.onclose(); }; }; @@ -65,7 +65,10 @@ $(document).ready(function() { }; websocket.onclose = function(event) { - console.log('Websocket closed, code: ' + event.code); + if (event) { + console.log('Websocket closed - code: ' + event.code + ' - reason: ' + event.reason); + } + openedWebsocket = undefined; if (!pendingConnection) {