什么是"有效的方式"检查某个房间是否有连接客户端甚至存在?
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);
}
});
使用socket.io和redis适配器的多个实例是否有效的方法? 我希望可以使用这样的东西:
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);
});
}
});