rb-sdk
Version:
rb client sdk
125 lines (101 loc) • 4.62 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Configuration = function () {
function Configuration(config, props) {
_classCallCheck(this, Configuration);
config = config || {};
var _config = { clientType: null, maxRetrys: 3, gateway: window.location.host, deviceMeta: { width: 375, height: 667 }, record: { supportRecord: true, sliceTime: 5000 } };
this.config = Object.assign(_config, config);
this.extProps = props || {};
this.clientType = this.config.clientType;
this.drainageChannel = this.config.channel;
this.maxRetrys = this.config.maxRetrys;
this.timeout = 3000;
this.heartbeatInterval = 10000;
this.gateway = this.config.gateway;
this.api = this.config.api;
this.ws = this.config.ws;
this.deviceMeta = this.config.deviceMeta;
this.record = this.config.record;
}
_createClass(Configuration, [{
key: "getRecord",
value: function getRecord() {
return this.record;
}
}, {
key: "getDeviceMeta",
value: function getDeviceMeta() {
return this.deviceMeta;
}
}, {
key: "getExtProps",
value: function getExtProps() {
return this.extProps;
}
}, {
key: "getWs",
value: function getWs() {
var ws = this.ws || null;
var gateway = this.gateway;
if ((typeof gateway === "undefined" ? "undefined" : _typeof(gateway)) == "object") {
gateway = gateway.url;
}
var _window$location = window.location,
protocol = _window$location.protocol,
host = _window$location.host,
port = _window$location.port;
if ("" != port) {
port += ":";
}
if (!ws && gateway) {
gateway = gateway.replace('http', 'ws');
ws = gateway + "/websocket/";
}
if (!ws) {
ws = protocol + "//" + host + port + "/websocket/";
}
return { url: ws, timeout: this.getWsTimeout(), heartbeatInterval: this.ws && this.ws.heartbeatInterval || this.heartbeatInterval };
}
}, {
key: "getWsTimeout",
value: function getWsTimeout() {
return this.ws && this.ws.timeout || this.gateway.timeout || this.timeout;
}
}, {
key: "getApiTimeout",
value: function getApiTimeout() {
return this.api && this.api.timeout || this.gateway.timeout || this.timeout;
}
}, {
key: "getApi",
value: function getApi(projectName) {
var api = this.api || null;
var gateway = this.gateway;
if ((typeof gateway === "undefined" ? "undefined" : _typeof(gateway)) == "object") {
gateway = gateway.url;
}
var _window$location2 = window.location,
protocol = _window$location2.protocol,
host = _window$location2.host,
port = _window$location2.port;
if ("" != port) {
port += ":";
}
if (!api && gateway) {
api = gateway + "/" + projectName + "/";
}
if (!api) {
api = protocol + "//" + host + port + "/" + projectName + "/";
}
return { url: api, timeout: this.getApiTimeout() };
}
}]);
return Configuration;
}();
exports.default = Configuration;