From b0daf560da8dffe2ae466bb480394f598aab9473 Mon Sep 17 00:00:00 2001
From: Kasalehlia <kasalehlia@clonejo.de>
Date: Mon, 16 Jan 2017 16:20:52 +0100
Subject: [PATCH] added auto reload when server restarted

---
 main.js                  | 10 +++++++---
 public/js/infodisplay.js |  9 ++++++++-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/main.js b/main.js
index 24c12b2..349ea00 100644
--- a/main.js
+++ b/main.js
@@ -7,8 +7,14 @@ server.listen(8000);
 
 app.use(express.static(__dirname + '/public'));
 
+var instanceClients = [];
 io.on('connection', function (socket) {
-  //socket.emit('meta', 'reload');
+    socket.on('ident', function (client) {
+        if (instanceClients.indexOf(client) === -1) {
+            instanceClients.push(client);
+            socket.emit('meta', 'reload');
+        }
+    })
 });
 
 function endsWith(str, suffix) {
@@ -35,5 +41,3 @@ require("fs").readdirSync(normalizedPath).forEach(function(file) {
         }
     }
 });
-
-
diff --git a/public/js/infodisplay.js b/public/js/infodisplay.js
index 3c680e6..d741dac 100644
--- a/public/js/infodisplay.js
+++ b/public/js/infodisplay.js
@@ -11,6 +11,14 @@ $(function () {
             document.location.reload();
         }
     });
+    socket.on('connect', function () {
+        var ident = sessionStorage.getItem('ident');
+        if (!ident) {
+            ident = Math.random().toString().substr(2);
+            sessionStorage.setItem('ident', ident);
+        }
+        socket.emit('ident', ident);
+    });
     socket.on('disconnect', function () {
         setIntervals.forEach(function (interval) {
             window.clearInterval(interval);
@@ -35,4 +43,3 @@ $(function () {
         });
     });
 });
-
-- 
GitLab