Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updates to examples/multiroomchat_example: Added package.json; Added …

…count of others in room; Improved JS.
  • Loading branch information...
commit 35da8b93fe354f3b3c3d24b9842dae81664f5c06 1 parent ec78b9e
@mrienstra mrienstra authored
View
14 examples/multiroomchat_example/multiroomchat.html
@@ -15,13 +15,21 @@
now.distributeMessage($("#text-input").val());
$("#text-input").val("");
});
-
+
$(".change").click(function(){
now.changeRoom($(this).text());
});
-
+
+ $("#text-input").keypress(function (e) {
+ if (e.which && e.which === 13) {
+ $("#send-button").click();
+ return false;
+ }
+ });
+
now.name = prompt("What's your name?", "");
-
+
+ $("#text-input").focus();
});
</script>
</head>
View
3  examples/multiroomchat_example/multiroomchat_server.js
@@ -28,7 +28,8 @@ everyone.now.changeRoom = function(newRoom){
nowjs.getGroup(this.now.room).removeUser(this.user.clientId);
nowjs.getGroup(newRoom).addUser(this.user.clientId);
this.now.room = newRoom;
- this.now.receiveMessage("SERVER", "You're now in " + this.now.room);
+ 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).");
}
everyone.now.distributeMessage = function(message){
View
16 examples/multiroomchat_example/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "nowjs-helloworld-example",
+ "version": "0.0.6",
+ "author": "ericz (Eric Zhang) <eric@nowjs.com>",
+ "description": "'Hello world' example for NowJS.",
+ "keywords": [
+ "nowjs",
+ "example"
+ ],
+ "dependencies" : {
+ "now" : ">=0.7"
+ },
+ "engine": {
+ "node": ">=0.4"
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.