diff --git a/platypush/backend/http/__init__.py b/platypush/backend/http/__init__.py index 8637aa9f..ac42d937 100644 --- a/platypush/backend/http/__init__.py +++ b/platypush/backend/http/__init__.py @@ -123,7 +123,7 @@ class HttpBackend(Backend): try: waiter = await websocket.ping() await asyncio.wait_for(waiter, timeout=5) - time.sleep(1) + time.sleep(5) except (asyncio.TimeoutError, websockets.exceptions.ConnectionClosed) as e: logging.info('Client {} closed connection'.format(websocket.remote_address[0])) self.active_websockets.remove(websocket) diff --git a/platypush/backend/http/static/js/application.js b/platypush/backend/http/static/js/application.js index 72db7af1..2fd3084c 100644 --- a/platypush/backend/http/static/js/application.js +++ b/platypush/backend/http/static/js/application.js @@ -1,7 +1,8 @@ $(document).ready(function() { - var websocket; - var dateTimeInterval; - var eventListeners = []; + var websocket, + dateTimeInterval, + websocketReconnectTimeout, + eventListeners = []; var initWebsocket = function() { websocket = new WebSocket('ws://' + window.location.hostname + ':' + window.websocket_port); @@ -15,6 +16,17 @@ $(document).ready(function() { listener(data); } }; + + websocket.onerror = function(event) { + console.error(event); + }; + + websocket.onclose = function(event) { + console.log('Websocket closed, code: ' + event.code); + websocketReconnectTimeout = setTimeout(function() { + initWebsocket(); + }, 5000); + }; }; var initDateTime = function() {