Skip to content

Commit

Permalink
Retrieving room count in a better way (using Group count method inste…
Browse files Browse the repository at this point in the history
…ad of counting the Group users property). Added notification of leaving and entering -- though this is a bit crude, may be better to leave it out, rather than show it being done somewhat poorly.
  • Loading branch information
mrienstra committed Feb 20, 2012
1 parent 35da8b9 commit 424243d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/multiroomchat_example/multiroomchat.html
Expand Up @@ -8,7 +8,7 @@
<script>
$(document).ready(function(){
now.receiveMessage = function(name, message){
$("#messages").append("<br>" + name + ": " + message);
$("#messages").append("<br><b>" + name + "</b>: " + message);
}

$("#send-button").click(function(){
Expand Down
9 changes: 7 additions & 2 deletions examples/multiroomchat_example/multiroomchat_server.js
Expand Up @@ -25,11 +25,16 @@ nowjs.on('disconnect', function(){
});

everyone.now.changeRoom = function(newRoom){
this.now.distributeMessage("[leaving " + this.now.room + "]");
nowjs.getGroup(this.now.room).removeUser(this.user.clientId);
nowjs.getGroup(newRoom).addUser(this.user.clientId);
this.now.room = newRoom;
var others = Object.keys(nowjs.getGroup(this.now.room).users).length - 1;
this.now.receiveMessage("SERVER", "You're now in " + this.now.room + " (" + others + " other(s) in this room).");
this.now.distributeMessage("[entering " + this.now.room + "]");
var that = this;
nowjs.getGroup(this.now.room).count(function(count){
var prettyCount = (count === 1) ? "Room is empty." : (count - 1) + " other(s) in room.";
that.now.receiveMessage("SERVER", "You're now in " + that.now.room + ". " + prettyCount);
});
}

everyone.now.distributeMessage = function(message){
Expand Down

0 comments on commit 424243d

Please sign in to comment.