"use strict";
var __importDefault = (this && this.__importDefault) || function(mod) {
    return (mod && mod.__esModule) ? mod : {
        "default": mod
    };
};
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.fetchBalancerConfig = void 0;
var websocket_client_utils_1 = require("@smartsupp/websocket-client-utils");
var isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));
var fetchBalancerConfig = function(url) {
    (0, websocket_client_utils_1.debug)("using balancer ".concat(url, " to get websocket url"));
    return (0, isomorphic_unfetch_1.default)("".concat(url)).then(function(res) {
        return res.json();
    }).then(function(data) {
        if ((data === null || data === void 0 ? void 0 : data.url) && (data === null || data === void 0 ? void 0 : data.token)) {
            (0, websocket_client_utils_1.debug)("balancer returns url ".concat(data === null || data === void 0 ? void 0 : data.url, " and token ").concat(data === null || data === void 0 ? void 0 : data.token));
            return data;
        } else {
            (0, websocket_client_utils_1.debug)('balancer returns invalid response');
            return null;
        }
    }).catch(function(err) {
        (0, websocket_client_utils_1.debug)("failed to resolve url: ".concat(err.message));
        return null;
    });
};
exports.fetchBalancerConfig = fetchBalancerConfig;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLDRFQUF5RDtBQUN6RCwwRUFBc0M7QUFFL0IsSUFBTSxtQkFBbUIsR0FBRyxVQUFDLEdBQVc7SUFDOUMsSUFBQSw4QkFBSyxFQUFDLHlCQUFrQixHQUFHLDBCQUF1QixDQUFDLENBQUE7SUFDbkQsT0FBTyxJQUFBLDRCQUFLLEVBQUMsVUFBRyxHQUFHLENBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxVQUFDLEdBQUc7UUFDL0IsT0FBTyxHQUFHLENBQUMsSUFBSSxFQUFFLENBQUE7SUFDbEIsQ0FBQyxDQUFD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