UNPKG

jcc_rpc

Version:
93 lines 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var assert = require("assert"); var JcBase = /** @class */ (function () { /** * Creates an instance of JcBase. * @param {*} args * @memberof JcBase */ function JcBase() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } assert(args.length === 1 || args.length === 3, "arguments length should be 1 or 3"); if (args.length === 1) { var urls = args[0]; assert(Array.isArray(urls), 'the type of "urls" should be an array'); this._urls = urls; } else { var hosts = args[0], port = args[1], https = args[2]; assert(Array.isArray(hosts), 'the type of "hosts" should be an array'); assert(Number.isInteger(port) && port > 0 && port <= 65535, 'the "port" should be valid'); assert(typeof https === "boolean", 'the type of "https" should be boolean'); this._hosts = hosts; this._port = port; this._https = https; } } Object.defineProperty(JcBase.prototype, "urls", { get: function () { return this._urls; }, set: function (urls) { assert(Array.isArray(urls), 'the type of "urls" should be an array'); this._urls = urls; }, enumerable: true, configurable: true }); Object.defineProperty(JcBase.prototype, "hosts", { get: function () { return this._hosts; }, set: function (hosts) { assert(Array.isArray(hosts), 'the type of "hosts" should be an array'); this._hosts = hosts; }, enumerable: true, configurable: true }); Object.defineProperty(JcBase.prototype, "port", { get: function () { return this._port; }, set: function (port) { assert(Number.isInteger(port) && port > 0 && port <= 65535, 'the "port" should be valid'); this._port = port; }, enumerable: true, configurable: true }); Object.defineProperty(JcBase.prototype, "https", { get: function () { return this._https; }, set: function (https) { assert(typeof https === "boolean", 'the type of "https" should be boolean'); this._https = https; }, enumerable: true, configurable: true }); JcBase.prototype.getUrl = function () { var url; if (Array.isArray(this._urls) && this._urls.length > 0) { url = this._urls[Math.floor(Math.random() * this._urls.length)]; } else if (Array.isArray(this._hosts) && this._hosts.length > 0) { var host = this._hosts[Math.floor(Math.random() * this._hosts.length)]; var protocol = this._https ? "https://" : "http://"; url = "" + protocol + host + ":" + this._port; } else { url = ""; } return url; }; return JcBase; }()); exports.default = JcBase; //# sourceMappingURL=base.js.map