Created
May 29, 2012 16:07
-
-
Save robcee/2829242 to your computer and use it in GitHub Desktop.
getChannelList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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