local storage for color
local storage for color

file:a/index.js -> file:b/index.js
--- a/index.js
+++ b/index.js
@@ -26,13 +26,18 @@
             console.log ("admin connected " + id);
             admin.push(id);
         }
-        socket.emit('t:connected', {});
+        if (msg.color != null) {
+            color = msg.color;
+            socket.emit('t:connected', {});
+        } else {
+            socket.emit('t:connected', {color:color});
+        }
     });
 
     socket.on('disconnect', function () {
-        console.log ("admin disconnected " + id);
         index = admin.indexOf(id);
         if (index != -1) {
+            console.log ("admin disconnected " + id);
             admin.splice(index, 1);
         }
     });

--- a/public/js/a.js
+++ b/public/js/a.js
@@ -1,3 +1,5 @@
+var host = "/";
+
 function loadJs(i,s,o,g,c){
     a=s.createElement(o);m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m);
     a.onload=function(){
@@ -71,3 +73,4 @@
     aSocket.on('disconnect', function(){
     });
 }
+

--- a/public/js/c.js
+++ b/public/js/c.js
@@ -1,10 +1,12 @@
+var host = "/";
+
 function loadJs(i,s,o,g,c){
     a=s.createElement(o);m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m);
     a.onload=function(){
         c();
     }
 }
-loadJs(window,document,'script','/socket.io-client/socket.io.js', function(){NRTT()});
+loadJs(window,document,'script',host + 'socket.io-client/socket.io.js', function(){NRTT()});
 
 function NRTT() {
     var connected = false;
@@ -23,9 +25,18 @@
         }
     }
     var cSocket = io();
-    cSocket.emit('t:connect', {w:window.width, h:window.height});
+    var color = null;
+    if(typeof(Storage) !== "undefined") {
+        color = localStorage.getItem('tcolor');
+    }
+    cSocket.emit('t:connect', {w:window.width, h:window.height, color:color});
     cSocket.on('t:connected', function(msg){
         connected = true;
+        if(typeof(Storage) !== "undefined") {
+            if (msg.color) {
+                localStorage.setItem("tcolor", msg.color);
+            }
+        }
     });
     cSocket.on('disconnect', function(){
         connected = false;
@@ -44,3 +55,4 @@
         }
     }, mouseAction.interval);
 }
+

comments