Merge pull request #55 from Mikxail/constructor-additional-options

additional options for SteamCommunity constructor
This commit is contained in:
Alexander Corn 2015-12-28 00:24:11 -05:00
commit 5c2666e0f4

View File

@ -11,25 +11,35 @@ module.exports = SteamCommunity;
SteamCommunity.SteamID = SteamID; SteamCommunity.SteamID = SteamID;
function SteamCommunity(localAddress) { function SteamCommunity(options) {
options = options || {};
this._jar = Request.jar(); this._jar = Request.jar();
this._captchaGid = -1; this._captchaGid = -1;
this.chatState = SteamCommunity.ChatState.Offline; this.chatState = SteamCommunity.ChatState.Offline;
var defaults = { var defaults = {
"jar": this._jar, "jar": this._jar,
"timeout": 50000, "timeout": options.timeout || 50000,
"headers": { "headers": {
"User-Agent": USER_AGENT "User-Agent": options.userAgent || USER_AGENT
} }
}; };
if(localAddress) { if (typeof options == "string") {
defaults.localAddress = localAddress; options = {
localAddress: options
};
}
this._options = options;
if (options.localAddress) {
defaults.localAddress = options.localAddress;
} }
this.request = Request.defaults(defaults); this.request = options.request || Request.defaults();
this.request = this.request.defaults(defaults);
// English // English
this._jar.setCookie(Request.cookie('Steam_Language=english'), 'https://steamcommunity.com'); this._jar.setCookie(Request.cookie('Steam_Language=english'), 'https://steamcommunity.com');