Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Retrieving room count in a better way (using Group count method inste…

…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...
commit 424243d2ab05055bff32d9255c9c8d5c357ea8b1 1 parent 35da8b9
@mrienstra mrienstra authored
View
2  examples/multiroomchat_example/multiroomchat.html
@@ -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(){
View
9 examples/multiroomchat_example/multiroomchat_server.js
@@ -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){
Please sign in to comment.
Something went wrong with that request. Please try again.