Reputation: 305
Hi I'm trying to use dynamic namespace to create them on demand. It's working except that I get duplicate or more client for some reason
Server side :
io.of("/" + group ).on("connection", function(socket_group) {
socket_group.groupId = group;
socket_group.on("infos", function(){
console.log("on the group !");
})
socket_group.on('list', function () {
Urls.find({'group' : '...'}).sort({ '_id' : -1 }).limit(10).exec(function(err, data){
socket_group.emit('links', data);
});
})
[...]
})
Client Side :
socket.emit('list', { ... });
On the client side only one command is sent but the server is always responding with 2 or more responses. Every time I close/open my app the response is incremented.
Thanks if you find out.
Upvotes: 2
Views: 1048
Reputation: 11461
This could be correct behavior; just like if you were to stack event handlers in any other environment. To ensure you only execute the attachment of your function to the namespace once, check for its presence first (or define this someplace in your program that only runs once as needed).
Try the condition (!io.namespaces["/" + group])
Upvotes: 2