Skip to content

Instantly share code, notes, and snippets.

@robcee
Created May 29, 2012 16:07
Show Gist options
  • Save robcee/2829242 to your computer and use it in GitHub Desktop.
Save robcee/2829242 to your computer and use it in GitHub Desktop.
getChannelList
exports.getChannelList = function(client, io, callback) {
client.keys('channels:*', function(err, channels) {
try {
var channelList = [];
var counter = 0;
function getFunc(errChannel, channel) {
var channelHash = {
name: channel,
userCount: io.sockets.clients(channel).length
};
channelList.unshift(channelHash);
if (++counter === channels.length)
return callback(null, channelList);
});
for (var i = 0; i < channels.length; i ++) {
if (!channels[i].match(/^channels:private-[a-f0-9]{32}-[a-f0-9]{32}$/)) {
client.get(channels[i], getFunc);
}
}
} catch(err) {
return callback(err);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment