Pārlūkot izejas kodu

trigger set shortid after connect

Hongcai Deng 9 gadi atpakaļ
vecāks
revīzija
c2e3fb67ce
1 mainītis faili ar 13 papildinājumiem un 11 dzēšanām
  1. 13 11
      public/js/app.js

+ 13 - 11
public/js/app.js

@@ -31,21 +31,23 @@ $(function(){
     $('#shortid').val(mailaddress).parent().siblings('button').find('.mail').attr('data-clipboard-text', mailaddress);
   };
 
-  if(('localStorage' in window)) {
-    var shortid = localStorage.getItem('shortid');
-    if(!shortid) {
-      socket.emit('request shortid', true);
-    }
-    else {
-      socket.emit('set shortid', true);
-      setMailAddress(shortid);
-    }
-  }
-
   $('#refreshShortid').click(function() {
     socket.emit('request shortid', true);
   });
 
+  socket.on('connect', function() {
+    if(('localStorage' in window)) {
+      var shortid = localStorage.getItem('shortid');
+      if(!shortid) {
+        socket.emit('request shortid', true);
+      }
+      else {
+        socket.emit('set shortid', true);
+        setMailAddress(shortid);
+      }
+    }
+  });
+
   socket.on('shortid', function(id) {
     setMailAddress(id);
   });