Skip to content

Instantly share code, notes, and snippets.

@alkema
Created June 14, 2011 16:40
Show Gist options
  • Save alkema/1025295 to your computer and use it in GitHub Desktop.
Save alkema/1025295 to your computer and use it in GitHub Desktop.
nowjs join path based group
// Client
now.ready = function() {
now.changeGroup(window.location.pathname)
}
// Server
var app = express.createServer();
var nowjs = require("now");
var everyone = nowjs.initialize(app);
app.get('/', function(req, res){
hash = hashForPath(req.socket.remoteAddress);
res.redirect('/' + hash);
});
app.get('/:pathname', function(req, res){
res.render('show');
});
everyone.now.changeGroup = function(pathname){
groupId = pathname.replace( /\//, '' )
nowjs.getGroup(groupId).addUser(this.user.clientId);
console.log("Joined: " + groupId);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment