【发布时间】:2014-12-11 02:57:27
【问题描述】:
使用 angular 和 socket.io 每次服务器发出时,我都会在客户端上收到重复的事件。 Angular 只包含一次,只有一个 socket.io 连接,客户端上每个事件只有一个监听器。在服务器上接收到事件后,会记录数据,并且此过程只发生一次。然后发出数据并在客户端调用回调两次,尽管只在范围内一次(据我所知)。
client:
//inside a controller
var thing ='foo';
socket.emit('sentUp',thing)
socket.on('sentDown',function(thing){
console.log(thing)//this happens twice
});
server:
/*
node&express stuff here
*/
socket.on('connection',function(socket){
socket.on('sentUp',function(stuff){
console.log('this happened')//x1
socket.emit('sendDown',stuff);
});
})
【问题讨论】:
标签: javascript node.js angularjs socket.io duplicates