Check Socket.IO if there are clients with socket.io-redis in the room

What is the “efficient way” to check if any client number is connected or exists?

socket.on('pm', function(data) { data.from = socket.decoded_token._id; var to = data.to; if (_.isUndefined(io.sockets.adapter.rooms[to])) { debug("user [%s] is not connected", to); } else { socket.to(to).emit('pm', message); } }); 

Is this an efficient way to do this with multiple instances of socket.io and redis adapter? I would like something like this one could use:

 socket.on('pm', function(data) { data.from = socket.decoded_token._id; var to = data.to; socket.to(to).emit('pm', message, function(err){ //error callback, but callback aren't supported for broadcast messages debug("user [%s] is not connected", to); }); } }); 
+6
source share

Source: https://habr.com/ru/post/980160/


All Articles