- Websocket ping interval 1 -> 5 seconds

- JS client websocket reconnect logic
This commit is contained in:
Fabio Manganiello 2018-02-07 22:14:38 +01:00
parent c47d910465
commit b675f631e9
2 changed files with 16 additions and 4 deletions

View file

@ -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)

View file

@ -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() {