Add usercount indicator

This commit is contained in:
calzoneman 2013-03-06 19:38:16 -06:00
parent 5ca419d3e3
commit 259c72e7da
3 changed files with 13 additions and 0 deletions

View File

@ -208,6 +208,7 @@ Channel.prototype.userJoin = function(user) {
if(user.name != "") { if(user.name != "") {
this.broadcastNewUser(user); this.broadcastNewUser(user);
} }
this.updateUsercount();
// Set the new guy up // Set the new guy up
this.sendPlaylist(user); this.sendPlaylist(user);
this.sendUserlist(user); this.sendUserlist(user);
@ -220,6 +221,7 @@ Channel.prototype.userJoin = function(user) {
// Called when a user leaves the channel // Called when a user leaves the channel
Channel.prototype.userLeave = function(user) { Channel.prototype.userLeave = function(user) {
this.users.splice(this.users.indexOf(user), 1); this.users.splice(this.users.indexOf(user), 1);
this.updateUsercount();
if(user.name != "") { if(user.name != "") {
this.sendAll('userLeave', { this.sendAll('userLeave', {
name: user.name name: user.name
@ -506,6 +508,12 @@ Channel.prototype.sendUserlist = function(user) {
user.socket.emit('userlist', users) user.socket.emit('userlist', users)
} }
Channel.prototype.updateUsercount = function() {
this.sendAll('usercount', {
count: this.users.length
});
}
// Send the play queue // Send the play queue
Channel.prototype.sendPlaylist = function(user) { Channel.prototype.sendPlaylist = function(user) {
user.socket.emit('playlist', { user.socket.emit('playlist', {

View File

@ -42,6 +42,10 @@ function initCallbacks() {
} }
}); });
socket.on('usercount', function(data) {
$('#usercount').text(data.count + " connected users");
});
socket.on('chatMsg', function(data) { socket.on('chatMsg', function(data) {
var div = formatChatMessage(data); var div = formatChatMessage(data);
$('#messagebuffer')[0].appendChild(div); $('#messagebuffer')[0].appendChild(div);

View File

@ -54,6 +54,7 @@
</div> </div>
<div class="row" style="margin-top: 20px;"> <div class="row" style="margin-top: 20px;">
<div class="span6"> <div class="span6">
<p id="usercount"></p>
<div id="userlist"> <div id="userlist">
</div> </div>
<div id="messagebuffer"> <div id="messagebuffer">