node.js - How do to do online and offline in socket.io? -
how online , offline in socket io? need redis store session or mongodb?
my attempt serverside
io.on('connection', function(socket) { socket.emit('connected', 'online'); socket.disconnect('disconnect', function() { socket.emit('connected', 'offline'); }); })
clientside
socket.on('connected', function(data) { $('#useronline').html(data); });
with code above not consistent, shows offline, not
the corrrect way listen when socket disconnect is:
socket.on('disconnect', function () { ...... });
and not emit socket inside callback.
for exact answer need know how make disconnection (server or client side) , should receive information, himself or others clients?
Comments
Post a Comment