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