From 259c72e7dad7e1b23db8b56ae11230c80e61f03f Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 6 Mar 2013 19:38:16 -0600 Subject: [PATCH] Add usercount indicator --- channel.js | 8 ++++++++ www/assets/js/callbacks.js | 4 ++++ www/index.html | 1 + 3 files changed, 13 insertions(+) diff --git a/channel.js b/channel.js index 4a796f0b..987c418e 100644 --- a/channel.js +++ b/channel.js @@ -208,6 +208,7 @@ Channel.prototype.userJoin = function(user) { if(user.name != "") { this.broadcastNewUser(user); } + this.updateUsercount(); // Set the new guy up this.sendPlaylist(user); this.sendUserlist(user); @@ -220,6 +221,7 @@ Channel.prototype.userJoin = function(user) { // Called when a user leaves the channel Channel.prototype.userLeave = function(user) { this.users.splice(this.users.indexOf(user), 1); + this.updateUsercount(); if(user.name != "") { this.sendAll('userLeave', { name: user.name @@ -506,6 +508,12 @@ Channel.prototype.sendUserlist = function(user) { user.socket.emit('userlist', users) } +Channel.prototype.updateUsercount = function() { + this.sendAll('usercount', { + count: this.users.length + }); +} + // Send the play queue Channel.prototype.sendPlaylist = function(user) { user.socket.emit('playlist', { diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index dd974bf9..1acc4553 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -42,6 +42,10 @@ function initCallbacks() { } }); + socket.on('usercount', function(data) { + $('#usercount').text(data.count + " connected users"); + }); + socket.on('chatMsg', function(data) { var div = formatChatMessage(data); $('#messagebuffer')[0].appendChild(div); diff --git a/www/index.html b/www/index.html index c33844bf..a62adfe1 100644 --- a/www/index.html +++ b/www/index.html @@ -54,6 +54,7 @@
+