From bd7cef3f00d5ea0778003a453c1341871a166c6a Mon Sep 17 00:00:00 2001 From: Oliver Gerlich Date: Thu, 19 Jul 2018 21:54:13 +0200 Subject: [PATCH] socket: don't notify user on every failed connection attempt Only notify user if the websocket connection was already established and is now closed. --- webroot/js/socket.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/webroot/js/socket.js b/webroot/js/socket.js index 5f3d808..0df0b3e 100644 --- a/webroot/js/socket.js +++ b/webroot/js/socket.js @@ -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'); - notify.send({ - 'header': 'Verbindung', - 'type': 'warning' - }, 'Verbindung zum Server beendet!'); + 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); }