【发布时间】:2012-01-30 22:59:09
【问题描述】:
我将 expressjs 与 nowjs 一起使用,当访问路由时,我将一些事件绑定到路由内的 now 对象。这不是很干净,我感觉根目录访问的所有内容都执行了事件。
我不知道怎么做,但我想知道我是否可以把它移到别处?
app.get('/room/:name', function(req, res)
{
//Should this code be moved elsewhere?... how?
nowjs.on('connect', function()
{
this.now.room = req.params.name;
nowjs.getGroup(this.now.room).addUser(this.user.clientId);
console.log("Joined: " + this.now.name);
});
everyone.now.distributeMessage = function(message){
nowjs.getGroup(this.now.room).now.receiveMessage(this.now.name, message);
};
res.render('room', { user : user });
});
【问题讨论】:
标签: javascript node.js express nowjs-sockets