Created
June 14, 2011 16:40
-
-
Save alkema/1025295 to your computer and use it in GitHub Desktop.
nowjs join path based group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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