Socket.io Changefeed Multiple Emits On Refresh / Reload
I'm having this exact problem: https://github.com/rethinkdb/rethinkdb/issues/6503 First time I connect, it console.logs 1 time. If I refresh it console.log 2 times. If I refresh ag
Solution 1:
I finally solved it!
I added:
io.removeAllListeners();
Right below:
io.on('connection', function(socket){
So now it looks like this:
io.on('connection', function(socket){
io.removeAllListeners();
console.log('a user connected: ' + socket.id);
r.table('Groups')
.filter(r.row("members")
.contains(req.user['id']))
.changes({ includeInitial: true })
.run()
.then(function(feed){
feed.each(function(err, item){
console.log(req.user['entra']);
//console.log(JSON.stringify(item, null, 2));
socket.emit('group',item.new_val);
})
})
});
And it works and I don't get multiple messages / console.logs or emits anymore.
Post a Comment for "Socket.io Changefeed Multiple Emits On Refresh / Reload"