javascript - Iterate over sockets in socket.io v1? "...has no method 'clients'" -
before able write this:
io.sockets.clients().foreach(function (socket) { socket.emit(signal,data); });
now, cannot , error object #<namespace> has no method 'clients'
is there way this? socket v1.0. (or 1.0.2 think).
for know can use io.emit()
, iterate on sockets , perform functions on them in timer. can refactor callbacks , set timer on io.on()
, think need able use references (i think javascript make copy of object socket
in case instead of referencing it?)
here's example
setinterval(function(){ io.sockets.clients().foreach(function (socket) { socket.emit('newmessage',somecalculations()); }); },1000);
if info connected sockets has send single socket
(var in io.sockets.connected) { var s = io.sockets.connected[i]; if (socket.id === s.id) { continue; } socket.emit('notify_user_state', s.notify_user_state_data) }
Comments
Post a Comment