SteamService.getGroupMembers = function(steam_id, callback) {
callback = callback || noop;
var url = 'http://steamcommunity.com';
if (/\d{3,10}/.test(steam_id)) {
steam_id = calculateSteamGroupId64(steam_id);
url += '/gid/';
} else {
url += '/groups/';
}
url += steam_id + '/memberslistxml/?xml=1';
getMemberList(url, 5, callback);
};
function getMemberList(url, retries_left, callback) {
var d = domain.create();
function parseMemberList(data) {
if (steamGroupError) {
console.log("No group found, quitting");
return callback(new Error("Invalid URL for group"), []);
}
d.run(function() {
parseString(data, function(err, result) {
if (err) {
console.error("Error while parsing xml, retrying");
setImmediate(getMemberList.bind(null, url, retries_left - 1, callback));
} else {
callback(null, result.memberList.members[0].steamID64);
}
});
});
}
d.on('error', function(err) {
console.error("Error while parsing xml, retrying");
getMemberList.bind(null, url, retries_left - 1, callback);
});
if (retries_left > 0) {
rest.get(url).on('complete', parseMemberList);
} else {
return callback(new Error("Problem with Steam API, please try again"), []);
}
}