Before I could write something like this:
io.sockets.clients().forEach(function (socket) {
socket.emit(signal,data);
});
Now I can’t and get an error Object #<Namespace> has no method 'clients'
Is there any other way to do this? This is with socket v1.0. (or 1.0.2, I think).
For this, I know what I can use io.emit(), but I would like to iterate over sockets and perform functions on them in a timer. I can reorganize everything into callbacks and set the timer to io.on(), but I think I will need to use links (I think javascript will make a copy of the object socketin this case instead of referencing it?)
Here is an example
setInterval(function(){
io.sockets.clients().forEach(function (socket) {
socket.emit('newMessage',someCalculations());
});
},1000);
source
share