socket: don't notify user on every failed connection attempt

Only notify user if the websocket connection was already established and is
now closed.
This commit is contained in:
Oliver Gerlich 2018-07-19 21:54:13 +02:00
parent 2fca4b49fe
commit bd7cef3f00
1 changed files with 10 additions and 5 deletions

View File

@ -10,7 +10,8 @@ const RECONNECT_AFTER = 5000,
eventTo = {};
let connectionID = localStorage.getItem('session'),
socket = null;
socket = null,
connectionEstablished = false;
function newUUID () {
/* eslint-disable */
@ -42,6 +43,7 @@ function onerror (err) {
}
function onopen () {
connectionEstablished = true;
render();
}
@ -103,11 +105,14 @@ function onmessage (raw) {
function onclose () {
console.log('socket closed by server');
if (connectionEstablished) {
notify.send({
'header': 'Verbindung',
'type': 'warning'
}, 'Verbindung zum Server beendet!');
}
render();
connectionEstablished = false;
// eslint-disable-next-line no-use-before-define
window.setTimeout(connect, RECONNECT_AFTER);
}