UNPKG

@skyway-sdk/core

Version:

The official Next Generation JavaScript SDK for SkyWay

90 lines 3.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContextConfig = void 0; const common_1 = require("@skyway-sdk/common"); const deepmerge_1 = __importDefault(require("deepmerge")); const errors_1 = require("./errors"); const util_1 = require("./util"); const log = new common_1.Logger('packages/core/src/config.ts'); class ContextConfig { /**@internal */ constructor(options = {}) { var _a; /**@internal */ this.rtcApi = { domain: 'rtc-api.skyway.ntt.com', timeout: 30000, secure: true, eventSubscribeTimeout: 5000, }; /**@internal */ this.iceParamServer = { domain: 'ice-params.skyway.ntt.com', version: 1, secure: true, }; /**@internal */ this.signalingService = { domain: 'signaling.skyway.ntt.com', secure: true, }; /**@internal */ this.analyticsService = { domain: 'analytics-logging.skyway.ntt.com', secure: true, }; // stunPortsのデフォルトは443。未指定の場合443に接続する this.rtcConfig = { timeout: 30000, turnPolicy: 'enable', turnProtocol: 'all', stunPolicy: 'enable', stunPorts: [443], iceDisconnectBufferTimeout: 5000, }; this.token = { updateRemindSec: 30, }; this.log = { level: 'error', format: 'string', }; /**@internal */ this.internal = { disableDPlane: false, }; this.member = { keepaliveIntervalGapSec: 30, keepaliveIntervalSec: 30, preventAutoLeaveOnBeforeUnload: false, leaveWhenDisconnected: false, }; Object.assign(this, (0, deepmerge_1.default)(this, options)); // stunPortsはデフォルト[443]と結合せず、指定があれば上書きする if ((_a = options.rtcConfig) === null || _a === void 0 ? void 0 : _a.stunPorts) { this.rtcConfig.stunPorts = options.rtcConfig.stunPorts; } this._validateStunPorts(); } // stunPortsは443または3478を1つまたは2つ指定できる(空配列・3つ以上・重複・それ以外の値はエラー) _validateStunPorts() { const { stunPorts } = this.rtcConfig; const isValid = Array.isArray(stunPorts) && stunPorts.length >= 1 && stunPorts.length <= 2 && stunPorts.every((port) => [443, 3478].includes(port)) && new Set(stunPorts).size === stunPorts.length; if (!isValid) { throw (0, util_1.createError)({ operationName: 'ContextConfig._validateStunPorts', info: errors_1.errors.invalidStunPorts, path: log.prefix, }); } } } exports.ContextConfig = ContextConfig; //# sourceMappingURL=config.js.map