Socket.IO checking if room contains clients with socket.io-redis
Asked Answered
T

0

6

What is "efficient way" to check if some room has connected clients or even 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 it efficient way to do it with multiple instances of socket.io and redis adapter? I wish something like this could be used:

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);
    });
    }
});
Theme answered 26/12, 2014 at 6:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.