Skip to content

Instantly share code, notes, and snippets.

@ericz
Created May 3, 2011 20:30
Show Gist options
  • Save ericz/954159 to your computer and use it in GitHub Desktop.
Save ericz/954159 to your computer and use it in GitHub Desktop.
Test for read122
<!DOCTYPE html>
<html lang="en">
<head>
<title>nowjs test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="/nowjs/now.js"></script>
<script>
$(function(){
now.receiveMessage = function(name, message){
$("#messages").append("<br>" + name + ": " + message);
}
now.ready(function(){
now.testGroups();
});
});
</script>
</head>
<body>
<div id="messages"></div>
</body>
</html>
var fs = require('fs');
var server = require('http').createServer(function(req, response){
fs.readFile(__dirname+'/test.html', function(err, data){
response.writeHead(200, {'Content-Type':'text/html'});
response.write(data);
response.end();
});
});
server.listen(8080);
var nowjs = require("now");
var everyone = nowjs.initialize(server);
everyone.connected(function(){
var clientId = this.user.clientId;
nowjs.getGroup(clientId).addUser(clientId);
console.log("Joined: " + clientId);
});
everyone.disconnected(function(){
console.log("Left: " + this.user.clientId);
});
everyone.now.testGroups = function() {
var group = nowjs.getGroup(this.user.clientId);
group.now.receiveMessage(this.user.clientId, "Test success!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment