2
0
Эх сурвалжийг харах

number of connected users show on admin panel

AkiraLaine 9 жил өмнө
parent
commit
897c1493d5

+ 31 - 0
app/app.js

@@ -623,6 +623,17 @@ if (Meteor.isClient) {
                 }
                 }
             });
             });
             return playlists;
             return playlists;
+        },
+        users: function(){
+            Meteor.setInterval(function(){
+                Meteor.call("getUserNum", function(err, num){
+                    if(err){
+                        console.log(err);
+                    }
+                    Session.set("userNum", num);
+                });
+            }, 1000)
+            return Session.get("userNum");
         }
         }
     });
     });
 
 
@@ -1024,6 +1035,23 @@ if (Meteor.isServer) {
         }
         }
     });
     });
 
 
+    var userNum = 0;
+
+    Meteor.onConnection(function(connection){
+        updateUserNum(true)
+        connection.onClose(function(){
+           updateUserNum(false);
+        })
+    });
+
+    function updateUserNum(increment){
+        if(increment === true){
+            userNum += 1;
+        } else if(increment === false){
+            userNum -= 1;
+        }
+    }
+
     var stations = [];
     var stations = [];
 
 
     var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_";
     var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_";
@@ -1554,6 +1582,9 @@ if (Meteor.isServer) {
             } else {
             } else {
                 throw new Meteor.Error(403, "Invalid permissions.");
                 throw new Meteor.Error(403, "Invalid permissions.");
             }
             }
+        },
+        getUserNum: function(){
+            return userNum;
         }
         }
     });
     });
 }
 }

+ 1 - 0
app/templates/admin.html

@@ -2,6 +2,7 @@
     <div class="landing">
     <div class="landing">
         {{> header}}
         {{> header}}
         <div class="row">
         <div class="row">
+            <h1 class="col-md-8 col-md-offset-2" style="color: white">Total Users: {{{users}}}</h1>
             <h1 class="col-md-8 col-md-offset-2 admin-header">Queues:</h1>
             <h1 class="col-md-8 col-md-offset-2 admin-header">Queues:</h1>
             {{#each queues}}
             {{#each queues}}
                 <div class="col-md-8 col-md-offset-2 admin-queue-panel">
                 <div class="col-md-8 col-md-offset-2 admin-queue-panel">

+ 3 - 3
app/templates/room.html

@@ -95,11 +95,11 @@
                                     <option name="soundcloud" id="soundcloud">SoundCloud</option>
                                     <option name="soundcloud" id="soundcloud">SoundCloud</option>
                                 </select>
                                 </select>
                                 <label for="id" class="song-input-label">Song ID</label>
                                 <label for="id" class="song-input-label">Song ID</label>
-                                <input class="song-input" name="id" id="id" type="text" />
+                                <input class="song-input" name="id" id="id" type="text"/>
                                 <label for="id" class="song-input-label">Song Artist</label>
                                 <label for="id" class="song-input-label">Song Artist</label>
-                                <input class="song-input" name="artist" id="artist" type="text" />
+                                <input class="song-input" name="artist" id="artist" type="text"/>
                                 <label for="title" class="song-input-label">Song Title</label>
                                 <label for="title" class="song-input-label">Song Title</label>
-                                <input class="song-input" name="title" id="title" type="text" />
+                                <input class="song-input" name="title" id="title" type="text"/>
                                 <label for="img" class="song-input-label">Song Img</label>
                                 <label for="img" class="song-input-label">Song Img</label>
                                 <input class="song-input" name="img" id="img" type="text" />
                                 <input class="song-input" name="img" id="img" type="text" />
                                 <button type="button" id="add-song-button" class="button">Add Song</button>
                                 <button type="button" id="add-song-button" class="button">Add Song</button>