agora-rte-sdk 3.8.1 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib-es/constant.js +64 -0
- package/lib-es/core/engine/ap-detector.js +663 -0
- package/lib-es/core/engine/index.js +450 -0
- package/lib-es/core/engine/plugin.js +84 -0
- package/lib-es/core/engine/registry.js +7 -0
- package/lib-es/core/media/base-track.js +22 -0
- package/lib-es/core/media/camera.js +234 -0
- package/lib-es/core/media/effect-enhancer.js +153 -0
- package/lib-es/core/media/index.js +317 -0
- package/lib-es/core/media/loopback.js +161 -0
- package/lib-es/core/media/microphone.js +210 -0
- package/lib-es/core/media/screen.js +196 -0
- package/lib-es/core/media/type.js +33 -0
- package/lib-es/core/monitor/index.js +1 -0
- package/lib-es/core/monitor/type.js +1 -0
- package/lib-es/core/processor/message-handler.js +850 -0
- package/lib-es/core/processor/sequence-msg/data.js +153 -0
- package/lib-es/core/processor/sequence-msg/message-parser.js +27 -0
- package/lib-es/core/processor/sequence-msg/synchronizer.js +328 -0
- package/lib-es/core/processor/struct.js +220 -0
- package/lib-es/core/processor/synchronizer/base-synchronizer.js +364 -0
- package/lib-es/core/processor/synchronizer/fallback-synchronizer.js +70 -0
- package/lib-es/core/processor/synchronizer/index.js +4 -0
- package/lib-es/core/processor/synchronizer/synchronizer-manager.js +497 -0
- package/lib-es/core/processor/synchronizer/types.js +84 -0
- package/lib-es/core/processor/type.js +59 -0
- package/lib-es/core/rtc/canvas.js +63 -0
- package/lib-es/core/rtc/capture-enhancement.js +5 -0
- package/lib-es/core/rtc/channel.js +45 -0
- package/lib-es/core/rtc/client.js +153 -0
- package/lib-es/core/rtc/constant.js +7 -0
- package/lib-es/core/rtc/index.js +3 -0
- package/lib-es/core/rtc/publish-pool.js +22 -0
- package/lib-es/core/rtc/publisher.js +30 -0
- package/lib-es/core/rtc/source-manager.js +23 -0
- package/lib-es/core/rtc/subscriber.js +5 -0
- package/lib-es/core/rtc/type.js +211 -0
- package/lib-es/core/rtm/channel.js +8 -0
- package/lib-es/core/rtm/client.js +8 -0
- package/lib-es/core/rtm/index.js +1 -0
- package/lib-es/core/rtm/type.js +15 -0
- package/lib-es/core/scene/helper.js +72 -0
- package/lib-es/core/scene/index.js +1885 -0
- package/lib-es/core/scene/local-user.js +447 -0
- package/lib-es/core/scene/state-sync.js +111 -0
- package/lib-es/core/scene/stream-player.js +196 -0
- package/lib-es/core/scene/type.js +40 -0
- package/lib-es/core/services/api.js +792 -0
- package/lib-es/core/services/auth-headers.js +51 -0
- package/lib-es/core/services/client.js +49 -0
- package/lib-es/core/services/domain-holder.js +67 -0
- package/lib-es/core/services/domain-region-map.js +4 -0
- package/lib-es/core/services/type.js +1 -0
- package/lib-es/core/utilities/clone.js +5 -0
- package/lib-es/core/utilities/constants.js +7 -0
- package/lib-es/core/utilities/diff.js +155 -0
- package/lib-es/core/utilities/error.js +129 -0
- package/lib-es/core/utilities/fetch.js +53 -0
- package/lib-es/core/utilities/logger.js +18 -0
- package/lib-es/core/utilities/package-info.js +4 -0
- package/lib-es/core/utilities/parameters.js +116 -0
- package/lib-es/imports.js +51 -0
- package/lib-es/index.js +3 -0
- package/lib-es/plugin/monitor/index.js +226 -0
- package/lib-es/plugin/monitor/log-upload/handler.js +244 -0
- package/lib-es/plugin/monitor/log-upload/scheduler.js +86 -0
- package/lib-es/plugin/monitor/log-upload/type.js +1 -0
- package/lib-es/plugin/monitor/type.js +1 -0
- package/lib-es/plugin/restful-client/index.js +333 -0
- package/lib-es/plugin/rtc/electron/canvas-helper.js +145 -0
- package/lib-es/plugin/rtc/electron/canvas-tag-pool.js +383 -0
- package/lib-es/plugin/rtc/electron/capture-enhancement.js +497 -0
- package/lib-es/plugin/rtc/electron/channel.js +734 -0
- package/lib-es/plugin/rtc/electron/client.js +1312 -0
- package/lib-es/plugin/rtc/electron/constants.js +121 -0
- package/lib-es/plugin/rtc/electron/convert-type.js +42 -0
- package/lib-es/plugin/rtc/electron/desc-type.js +8 -0
- package/lib-es/plugin/rtc/electron/downloadALD.js +186 -0
- package/lib-es/plugin/rtc/electron/index.js +49 -0
- package/lib-es/plugin/rtc/electron/polling.js +110 -0
- package/lib-es/plugin/rtc/electron/publish-pool.js +409 -0
- package/lib-es/plugin/rtc/electron/publisher.js +756 -0
- package/lib-es/plugin/rtc/electron/source-manager.js +1290 -0
- package/lib-es/plugin/rtc/electron/source-state-control/camera-state-control.js +197 -0
- package/lib-es/plugin/rtc/electron/source-state-control/loopback-state-control.js +123 -0
- package/lib-es/plugin/rtc/electron/source-state-control/microphone-state-control.js +131 -0
- package/lib-es/plugin/rtc/electron/source-state-control/screen-state-control.js +206 -0
- package/lib-es/plugin/rtc/electron/source-state-control/source-state-control.js +264 -0
- package/lib-es/plugin/rtc/electron/source-state-control/window-state-control.js +206 -0
- package/lib-es/plugin/rtc/electron/subscriber.js +263 -0
- package/lib-es/plugin/rtc/electron/type.js +227 -0
- package/lib-es/plugin/rtc/electron/utils.js +563 -0
- package/lib-es/plugin/rtc/web/assembler.js +116 -0
- package/lib-es/plugin/rtc/web/audio-player.js +285 -0
- package/lib-es/plugin/rtc/web/canvas-helper.js +139 -0
- package/lib-es/plugin/rtc/web/capture-enhancement.js +231 -0
- package/lib-es/plugin/rtc/web/channel.js +631 -0
- package/lib-es/plugin/rtc/web/client.js +560 -0
- package/lib-es/plugin/rtc/web/constants.js +5 -0
- package/lib-es/plugin/rtc/web/device.js +901 -0
- package/lib-es/plugin/rtc/web/effect-enabler.js +229 -0
- package/lib-es/plugin/rtc/web/extension.js +155 -0
- package/lib-es/plugin/rtc/web/index.js +50 -0
- package/lib-es/plugin/rtc/web/publish-pool.js +261 -0
- package/lib-es/plugin/rtc/web/publish.js +728 -0
- package/lib-es/plugin/rtc/web/publisher.js +662 -0
- package/lib-es/plugin/rtc/web/source-manager.js +506 -0
- package/lib-es/plugin/rtc/web/struct.js +75 -0
- package/lib-es/plugin/rtc/web/subscribe.js +748 -0
- package/lib-es/plugin/rtc/web/subscriber.js +166 -0
- package/lib-es/plugin/rtc/web/track-control/camera.js +599 -0
- package/lib-es/plugin/rtc/web/track-control/microphone.js +484 -0
- package/lib-es/plugin/rtc/web/track-control/screen.js +338 -0
- package/lib-es/plugin/rtc/web/type.js +1 -0
- package/lib-es/plugin/rtc/web/utils.js +6 -0
- package/lib-es/plugin/rtm/channel.js +241 -0
- package/lib-es/plugin/rtm/client.js +491 -0
- package/lib-es/plugin/rtm/constants.js +1 -0
- package/lib-es/plugin/rtm/convert-type.js +31 -0
- package/lib-es/plugin/rtm/index.js +64 -0
- package/lib-es/plugin/rtm/type.js +1 -0
- package/lib-es/plugin/rtm/utils.js +9 -0
- package/lib-es/plugin/synchronizer-worker/index.js +15 -0
- package/lib-es/plugin/synchronizer-worker/worker.js +153 -0
- package/lib-es/type.js +35 -0
- package/package.json +6 -5
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
4
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
5
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
6
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
7
|
+
var _AgoraRteApDetectorImpl;
|
|
8
|
+
var _initProto;
|
|
9
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
function _applyDecs(e, t, r, n, o, a) { function i(e, t, r) { return function (n, o) { return r && r(n), e[t].call(n, o); }; } function c(e, t) { for (var r = 0; r < e.length; r++) e[r].call(t); return t; } function s(e, t, r, n) { if ("function" != typeof e && (n || void 0 !== e)) throw new TypeError(t + " must " + (r || "be") + " a function" + (n ? "" : " or undefined")); return e; } function applyDec(e, t, r, n, o, a, c, u, l, f, p, d, h) { function m(e) { if (!h(e)) throw new TypeError("Attempted to access private element on non-instance"); } var y, v = t[0], g = t[3], b = !u; if (!b) { r || Array.isArray(v) || (v = [v]); var w = {}, S = [], A = 3 === o ? "get" : 4 === o || d ? "set" : "value"; f ? (p || d ? w = { get: _setFunctionName(function () { return g(this); }, n, "get"), set: function set(e) { t[4](this, e); } } : w[A] = g, p || _setFunctionName(w[A], n, 2 === o ? "" : A)) : p || (w = Object.getOwnPropertyDescriptor(e, n)); } for (var P = e, j = v.length - 1; j >= 0; j -= r ? 2 : 1) { var D = v[j], E = r ? v[j - 1] : void 0, I = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][o], name: n, metadata: a, addInitializer: function (e, t) { if (e.v) throw Error("attempted to call addInitializer after decoration was finished"); s(t, "An initializer", "be", !0), c.push(t); }.bind(null, I) }; try { if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y);else { var k, F; O["static"] = l, O["private"] = f, f ? 2 === o ? k = function k(e) { return m(e), w.value; } : (o < 4 && (k = i(w, "get", m)), 3 !== o && (F = i(w, "set", m))) : (k = function k(e) { return e[n]; }, (o < 2 || 4 === o) && (F = function F(e, t) { e[n] = t; })); var N = O.access = { has: f ? h.bind() : function (e) { return n in e; } }; if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? { get: w.get, set: w.set } : w[A], O), d) { if ("object" == _typeof(P) && P) (y = s(P.get, "accessor.get")) && (w.get = y), (y = s(P.set, "accessor.set")) && (w.set = y), (y = s(P.init, "accessor.init")) && S.push(y);else if (void 0 !== P) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0"); } else s(P, (p ? "field" : "method") + " decorators", "return") && (p ? S.push(P) : w[A] = P); } } finally { I.v = !0; } } return (p || d) && u.push(function (e, t) { for (var r = S.length - 1; r >= 0; r--) t = S[r].call(e, t); return t; }), p || b || (f ? d ? u.push(i(w, "get"), i(w, "set")) : u.push(2 === o ? w[A] : i.call.bind(w[A])) : Object.defineProperty(e, n, w)), P; } function u(e, t) { return Object.defineProperty(e, Symbol.metadata || Symbol["for"]("Symbol.metadata"), { configurable: !0, enumerable: !0, value: t }); } if (arguments.length >= 6) var l = a[Symbol.metadata || Symbol["for"]("Symbol.metadata")]; var f = Object.create(null == l ? null : l), p = function (e, t, r, n) { var o, a, i = [], s = function s(t) { return _checkInRHS(t) === e; }, u = new Map(); function l(e) { e && i.push(c.bind(null, e)); } for (var f = 0; f < t.length; f++) { var p = t[f]; if (Array.isArray(p)) { var d = p[1], h = p[2], m = p.length > 3, y = 16 & d, v = !!(8 & d), g = 0 == (d &= 7), b = h + "/" + v; if (!g && !m) { var w = u.get(b); if (!0 === w || 3 === w && 4 !== d || 4 === w && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h); u.set(b, !(d > 2) || d); } applyDec(v ? e : e.prototype, p, y, m ? "#" + h : _toPropertyKey(h), d, n, v ? a = a || [] : o = o || [], i, v, m, g, 1 === d, v && m ? s : r); } } return l(o), l(a), i; }(e, t, o, f); return r.length || u(e, f), { e: p, get c() { var t = []; return r.length && [u(applyDec(e, [r], n, e.name, 5, f, t), f), c.bind(null, t, e)]; } }; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
+
function _setFunctionName(e, t, n) { "symbol" == _typeof(t) && (t = (t = t.description) ? "[" + t + "]" : ""); try { Object.defineProperty(e, "name", { configurable: !0, value: n ? n + " " + t : t }); } catch (e) {} return e; }
|
|
16
|
+
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? _typeof(e) : "null")); return e; }
|
|
17
|
+
import "core-js/modules/es.symbol.js";
|
|
18
|
+
import "core-js/modules/es.symbol.description.js";
|
|
19
|
+
import "core-js/modules/es.symbol.to-primitive.js";
|
|
20
|
+
import "core-js/modules/es.error.cause.js";
|
|
21
|
+
import "core-js/modules/es.error.to-string.js";
|
|
22
|
+
import "core-js/modules/es.array.concat.js";
|
|
23
|
+
import "core-js/modules/es.array.filter.js";
|
|
24
|
+
import "core-js/modules/es.array.for-each.js";
|
|
25
|
+
import "core-js/modules/es.array.includes.js";
|
|
26
|
+
import "core-js/modules/es.array.is-array.js";
|
|
27
|
+
import "core-js/modules/es.array.iterator.js";
|
|
28
|
+
import "core-js/modules/es.array.join.js";
|
|
29
|
+
import "core-js/modules/es.array.push.js";
|
|
30
|
+
import "core-js/modules/es.date.to-primitive.js";
|
|
31
|
+
import "core-js/modules/es.function.bind.js";
|
|
32
|
+
import "core-js/modules/es.function.name.js";
|
|
33
|
+
import "core-js/modules/es.map.js";
|
|
34
|
+
import "core-js/modules/es.number.constructor.js";
|
|
35
|
+
import "core-js/modules/es.object.create.js";
|
|
36
|
+
import "core-js/modules/es.object.define-properties.js";
|
|
37
|
+
import "core-js/modules/es.object.define-property.js";
|
|
38
|
+
import "core-js/modules/es.object.get-own-property-descriptor.js";
|
|
39
|
+
import "core-js/modules/es.object.get-own-property-descriptors.js";
|
|
40
|
+
import "core-js/modules/es.object.keys.js";
|
|
41
|
+
import "core-js/modules/es.object.to-string.js";
|
|
42
|
+
import "core-js/modules/es.promise.js";
|
|
43
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
44
|
+
import "core-js/modules/es.regexp.test.js";
|
|
45
|
+
import "core-js/modules/es.string.includes.js";
|
|
46
|
+
import "core-js/modules/es.string.iterator.js";
|
|
47
|
+
import "core-js/modules/es.string.replace.js";
|
|
48
|
+
import "core-js/modules/esnext.function.metadata.js";
|
|
49
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
50
|
+
import "core-js/modules/esnext.iterator.filter.js";
|
|
51
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
52
|
+
import "core-js/modules/esnext.map.delete-all.js";
|
|
53
|
+
import "core-js/modules/esnext.map.emplace.js";
|
|
54
|
+
import "core-js/modules/esnext.map.every.js";
|
|
55
|
+
import "core-js/modules/esnext.map.filter.js";
|
|
56
|
+
import "core-js/modules/esnext.map.find.js";
|
|
57
|
+
import "core-js/modules/esnext.map.find-key.js";
|
|
58
|
+
import "core-js/modules/esnext.map.includes.js";
|
|
59
|
+
import "core-js/modules/esnext.map.key-of.js";
|
|
60
|
+
import "core-js/modules/esnext.map.map-keys.js";
|
|
61
|
+
import "core-js/modules/esnext.map.map-values.js";
|
|
62
|
+
import "core-js/modules/esnext.map.merge.js";
|
|
63
|
+
import "core-js/modules/esnext.map.reduce.js";
|
|
64
|
+
import "core-js/modules/esnext.map.some.js";
|
|
65
|
+
import "core-js/modules/esnext.map.update.js";
|
|
66
|
+
import "core-js/modules/esnext.symbol.metadata.js";
|
|
67
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
68
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
69
|
+
import { AgoraObservable, fetch, generateLogObserver, isElectron, isEmpty, jsonstring, trace } from '../../imports';
|
|
70
|
+
import { AgoraRteErrorCode, AgoraRteModuleErrorCode, generateRteClientErrorNew as generateRteClientError } from '../utilities/error';
|
|
71
|
+
import { createLogger } from '../utilities/logger';
|
|
72
|
+
var DEFAULT_FETCH_URL_TIMEOUT = 300; // milliseconds
|
|
73
|
+
|
|
74
|
+
// 用于判断是否是IP地址,简单的正则表达式判断示例,可根据实际完善
|
|
75
|
+
export var isIP = function isIP(ip) {
|
|
76
|
+
var ipRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
77
|
+
return ipRegex.test(ip);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// 判断是否为域名的函数
|
|
81
|
+
export var isDomainName = function isDomainName(str) {
|
|
82
|
+
var domainRegex = /^(?!:\/\/)(?=^.{1,253}$)([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
|
|
83
|
+
return domainRegex.test(str);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// 移除url的前缀 http/https
|
|
87
|
+
var removeHttpPrefix = function removeHttpPrefix(url) {
|
|
88
|
+
// 定义一个正则表达式,用于匹配以 http:// 或 https:// 开头的字符串
|
|
89
|
+
var regex = /^https?:\/\//;
|
|
90
|
+
// 使用 replace 方法替换匹配到的前缀为空字符串
|
|
91
|
+
return url.replace(regex, '');
|
|
92
|
+
};
|
|
93
|
+
export var transformUrlToRequestUrl = function transformUrlToRequestUrl(url, isElectron) {
|
|
94
|
+
var pureUrl = removeHttpPrefix(url);
|
|
95
|
+
if (isElectron) {
|
|
96
|
+
return "https://".concat(pureUrl);
|
|
97
|
+
} else {
|
|
98
|
+
if (isIP(pureUrl)) {
|
|
99
|
+
var modifiedIp = pureUrl.split('.').join('-') + '.rtctest.com';
|
|
100
|
+
var getUrl = "https://".concat(modifiedIp);
|
|
101
|
+
return getUrl;
|
|
102
|
+
} else if (isDomainName(pureUrl)) {
|
|
103
|
+
return "https://".concat(pureUrl);
|
|
104
|
+
}
|
|
105
|
+
return '';
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var generateApDetectorError = function generateApDetectorError(code, message) {
|
|
109
|
+
return generateRteClientError(AgoraRteModuleErrorCode.AP_DETECTOR, code, message);
|
|
110
|
+
};
|
|
111
|
+
export var AgoraRteApDetectorImpl = /*#__PURE__*/function () {
|
|
112
|
+
// ==================== 构造函数 ====================
|
|
113
|
+
/**
|
|
114
|
+
* @constructor
|
|
115
|
+
* @param internalRtcConfig 内网探测配置
|
|
116
|
+
* @param externalRtcConfig 外网探测配置
|
|
117
|
+
* @param detectTimeout 探测超时时间,单位ms, 如果传入 0 或者负数,则使用默认值300ms
|
|
118
|
+
* @param isRedetect 是否在 rtc channel client 断线重连时,重新进行探测, 默认值 true
|
|
119
|
+
*/
|
|
120
|
+
function AgoraRteApDetectorImpl(internalRtcConfig, externalRtcConfig, detectTimeout, isRedetect) {
|
|
121
|
+
_classCallCheck(this, AgoraRteApDetectorImpl);
|
|
122
|
+
_defineProperty(this, "logger", (_initProto(this), createLogger({
|
|
123
|
+
prefix: 'AgoraRteApDetectorImpl'
|
|
124
|
+
})));
|
|
125
|
+
// ==================== 私有属性 ====================
|
|
126
|
+
_defineProperty(this, "_isElectron", isElectron());
|
|
127
|
+
/** 最小的探测数 */
|
|
128
|
+
_defineProperty(this, "_minCount", 3);
|
|
129
|
+
_defineProperty(this, "_detectTimeout", DEFAULT_FETCH_URL_TIMEOUT);
|
|
130
|
+
_defineProperty(this, "_isRedetect", true);
|
|
131
|
+
_defineProperty(this, "_isFinished", false);
|
|
132
|
+
_defineProperty(this, "_isDetecting", false);
|
|
133
|
+
_defineProperty(this, "_abortController", null);
|
|
134
|
+
_defineProperty(this, "_availableRtcAccessPointConfig", {
|
|
135
|
+
serverList: []
|
|
136
|
+
});
|
|
137
|
+
_defineProperty(this, "_apDetectorObserver", new AgoraObservable());
|
|
138
|
+
this.logger.info("constructor, apDetectTimeout: ".concat(detectTimeout, ", isRedetect: ").concat(isRedetect, ", ") + "internalRtcConfig: ".concat(jsonstring(internalRtcConfig), ", externalRtcConfig: ").concat(jsonstring(externalRtcConfig)));
|
|
139
|
+
this._internalRtcConfig = this._resolveParamsRtcConfig('internalRtcConfig', internalRtcConfig);
|
|
140
|
+
this._externalRtcConfig = this._resolveParamsRtcConfig('externalRtcConfig', externalRtcConfig);
|
|
141
|
+
this._detectTimeout = this._resolveParamsDetecTimeout(detectTimeout);
|
|
142
|
+
this._isRedetect = this._resolveParamsIsRedetect(isRedetect);
|
|
143
|
+
this.addObserver(generateLogObserver(this.logger, ['onDetectionFailure', 'onDetectionSuccess', 'onRedetectionFailure', 'onRedetectionSuccess']));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ==================== 公有方法 ====================
|
|
147
|
+
return _createClass(AgoraRteApDetectorImpl, [{
|
|
148
|
+
key: "addObserver",
|
|
149
|
+
value: function addObserver(observer) {
|
|
150
|
+
this._apDetectorObserver.addObserver(observer);
|
|
151
|
+
}
|
|
152
|
+
}, {
|
|
153
|
+
key: "removeObserver",
|
|
154
|
+
value: function removeObserver(observer) {
|
|
155
|
+
this._apDetectorObserver.removeObserver(observer);
|
|
156
|
+
}
|
|
157
|
+
}, {
|
|
158
|
+
key: "isFinished",
|
|
159
|
+
value: function isFinished() {
|
|
160
|
+
this.logger.info("isFinished: ".concat(this._isFinished));
|
|
161
|
+
return this._isFinished;
|
|
162
|
+
}
|
|
163
|
+
}, {
|
|
164
|
+
key: "isDetecting",
|
|
165
|
+
value: function isDetecting() {
|
|
166
|
+
this.logger.info("isDetecting: ".concat(this._isDetecting));
|
|
167
|
+
return this._isDetecting;
|
|
168
|
+
}
|
|
169
|
+
}, {
|
|
170
|
+
key: "getAvailableRtcAccessPointConfig",
|
|
171
|
+
value: function getAvailableRtcAccessPointConfig() {
|
|
172
|
+
if (this._availableRtcAccessPointConfig.serverList.length === 0) {
|
|
173
|
+
this.logger.warn('getAvailableRtcAccessPointConfig: no available access point config');
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
this.logger.info("getAvailableRtcAccessPointConfig: ".concat(jsonstring(this._availableRtcAccessPointConfig)));
|
|
177
|
+
return this._availableRtcAccessPointConfig;
|
|
178
|
+
}
|
|
179
|
+
}, {
|
|
180
|
+
key: "isDetectRequired",
|
|
181
|
+
value: function isDetectRequired() {
|
|
182
|
+
var _this$_internalRtcCon, _this$_internalRtcCon2, _this$_externalRtcCon, _this$_externalRtcCon2;
|
|
183
|
+
var internalServerListLength = (_this$_internalRtcCon = (_this$_internalRtcCon2 = this._internalRtcConfig) === null || _this$_internalRtcCon2 === void 0 ? void 0 : _this$_internalRtcCon2.serverList.length) !== null && _this$_internalRtcCon !== void 0 ? _this$_internalRtcCon : 0;
|
|
184
|
+
var externalServerListLength = (_this$_externalRtcCon = (_this$_externalRtcCon2 = this._externalRtcConfig) === null || _this$_externalRtcCon2 === void 0 ? void 0 : _this$_externalRtcCon2.serverList.length) !== null && _this$_externalRtcCon !== void 0 ? _this$_externalRtcCon : 0;
|
|
185
|
+
if (internalServerListLength === 0 && externalServerListLength === 0) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
if (internalServerListLength !== 0 && externalServerListLength !== 0) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 只有一个不为 0 的情况
|
|
193
|
+
var nonEmptyRtcConfig;
|
|
194
|
+
var nonEmptyServerListLength;
|
|
195
|
+
if (internalServerListLength !== 0) {
|
|
196
|
+
nonEmptyRtcConfig = this._internalRtcConfig;
|
|
197
|
+
nonEmptyServerListLength = internalServerListLength;
|
|
198
|
+
} else {
|
|
199
|
+
nonEmptyRtcConfig = this._externalRtcConfig;
|
|
200
|
+
nonEmptyServerListLength = externalServerListLength;
|
|
201
|
+
}
|
|
202
|
+
if (nonEmptyServerListLength <= this._minCount) {
|
|
203
|
+
this._availableRtcAccessPointConfig = _objectSpread({}, nonEmptyRtcConfig);
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
}, {
|
|
209
|
+
key: "setConfig",
|
|
210
|
+
value: function setConfig(internalRtcConfig, externalRtcConfig, detectTimeout, isRedetect) {
|
|
211
|
+
var paras_log = "apDetectTimeout: ".concat(detectTimeout, ", isRedetect: ").concat(isRedetect, ", ") + "internalRtcConfig: ".concat(jsonstring(internalRtcConfig), ", externalRtcConfig: ").concat(jsonstring(externalRtcConfig));
|
|
212
|
+
if (!this._setConfigIsValid(internalRtcConfig, externalRtcConfig)) {
|
|
213
|
+
this.logger.warn("setConfig: invalid parameters, ".concat(paras_log));
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (this._isDetecting) {
|
|
217
|
+
this.stop();
|
|
218
|
+
}
|
|
219
|
+
this.logger.info("setConfig, ".concat(paras_log));
|
|
220
|
+
this._internalRtcConfig = this._resolveParamsRtcConfig('internalRtcConfig', internalRtcConfig);
|
|
221
|
+
this._externalRtcConfig = this._resolveParamsRtcConfig('externalRtcConfig', externalRtcConfig);
|
|
222
|
+
this._detectTimeout = this._resolveParamsDetecTimeout(detectTimeout);
|
|
223
|
+
this._isRedetect = this._resolveParamsIsRedetect(isRedetect);
|
|
224
|
+
this._availableRtcAccessPointConfig = {
|
|
225
|
+
serverList: []
|
|
226
|
+
};
|
|
227
|
+
this._isFinished = false;
|
|
228
|
+
}
|
|
229
|
+
}, {
|
|
230
|
+
key: "stop",
|
|
231
|
+
value: function stop() {
|
|
232
|
+
if (this._isDetecting && this._abortController) {
|
|
233
|
+
this._abortController.abort();
|
|
234
|
+
this._isDetecting = false;
|
|
235
|
+
this._abortController = null;
|
|
236
|
+
this.logger.info('stop: detection has been stopped');
|
|
237
|
+
} else {
|
|
238
|
+
this.logger.warn('stop: no detection in progress, nothing to stop');
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}, {
|
|
242
|
+
key: "restart",
|
|
243
|
+
value: function () {
|
|
244
|
+
var _restart = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(success, failure) {
|
|
245
|
+
var errorMsg, error;
|
|
246
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
247
|
+
while (1) switch (_context.prev = _context.next) {
|
|
248
|
+
case 0:
|
|
249
|
+
if (this._isRedetect) {
|
|
250
|
+
_context.next = 1;
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
errorMsg = 'restart: redetect is disabled, please check the isRedetect config';
|
|
254
|
+
error = generateApDetectorError(AgoraRteErrorCode.UNDEFINED_ERROR, errorMsg);
|
|
255
|
+
this.logger.error(errorMsg);
|
|
256
|
+
failure(error);
|
|
257
|
+
this._apDetectorObserver.notifyObservers('onRedetectionFailure');
|
|
258
|
+
return _context.abrupt("return", false);
|
|
259
|
+
case 1:
|
|
260
|
+
_context.next = 2;
|
|
261
|
+
return this._executeDetect(success, failure, 'restart', 'onRedetectionSuccess', 'onRedetectionFailure');
|
|
262
|
+
case 2:
|
|
263
|
+
return _context.abrupt("return", _context.sent);
|
|
264
|
+
case 3:
|
|
265
|
+
case "end":
|
|
266
|
+
return _context.stop();
|
|
267
|
+
}
|
|
268
|
+
}, _callee, this);
|
|
269
|
+
}));
|
|
270
|
+
function restart(_x, _x2) {
|
|
271
|
+
return _restart.apply(this, arguments);
|
|
272
|
+
}
|
|
273
|
+
return restart;
|
|
274
|
+
}()
|
|
275
|
+
}, {
|
|
276
|
+
key: "start",
|
|
277
|
+
value: function () {
|
|
278
|
+
var _start = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(success, failure) {
|
|
279
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
280
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
281
|
+
case 0:
|
|
282
|
+
_context2.next = 1;
|
|
283
|
+
return this._executeDetect(success, failure, 'start', 'onDetectionSuccess', 'onDetectionFailure');
|
|
284
|
+
case 1:
|
|
285
|
+
return _context2.abrupt("return", _context2.sent);
|
|
286
|
+
case 2:
|
|
287
|
+
case "end":
|
|
288
|
+
return _context2.stop();
|
|
289
|
+
}
|
|
290
|
+
}, _callee2, this);
|
|
291
|
+
}));
|
|
292
|
+
function start(_x3, _x4) {
|
|
293
|
+
return _start.apply(this, arguments);
|
|
294
|
+
}
|
|
295
|
+
return start;
|
|
296
|
+
}()
|
|
297
|
+
}, {
|
|
298
|
+
key: "_setConfigIsValid",
|
|
299
|
+
value: function _setConfigIsValid(internalRtcConfig, externalRtcConfig) {
|
|
300
|
+
if (internalRtcConfig === undefined && externalRtcConfig === undefined) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
if (isEmpty(internalRtcConfig === null || internalRtcConfig === void 0 ? void 0 : internalRtcConfig.serverList) && isEmpty(externalRtcConfig === null || externalRtcConfig === void 0 ? void 0 : externalRtcConfig.serverList)) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
}, {
|
|
309
|
+
key: "_executeDetect",
|
|
310
|
+
value: function () {
|
|
311
|
+
var _executeDetect2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(success, failure, type, successNotifyName, failureNotifyName) {
|
|
312
|
+
var errorMsg, error, signal, result, _errorMsg, _error;
|
|
313
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
314
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
315
|
+
case 0:
|
|
316
|
+
if (!this._isDetecting) {
|
|
317
|
+
_context3.next = 1;
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
errorMsg = "".concat(type, ": detection is already in progress, please do not call repeatedly");
|
|
321
|
+
error = generateApDetectorError(AgoraRteErrorCode.UNDEFINED_ERROR, errorMsg);
|
|
322
|
+
this.logger.error(errorMsg);
|
|
323
|
+
failure(error);
|
|
324
|
+
this._apDetectorObserver.notifyObservers(failureNotifyName);
|
|
325
|
+
return _context3.abrupt("return", false);
|
|
326
|
+
case 1:
|
|
327
|
+
this._isDetecting = true;
|
|
328
|
+
this._abortController = {
|
|
329
|
+
abort: function abort() {
|
|
330
|
+
this.signal.aborted = true;
|
|
331
|
+
},
|
|
332
|
+
signal: {
|
|
333
|
+
aborted: false
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
signal = this._abortController.signal;
|
|
337
|
+
_context3.next = 2;
|
|
338
|
+
return this._runAllDetectTask(signal);
|
|
339
|
+
case 2:
|
|
340
|
+
result = _context3.sent;
|
|
341
|
+
this._isFinished = true;
|
|
342
|
+
this._isDetecting = false;
|
|
343
|
+
this._abortController = null;
|
|
344
|
+
if (!result) {
|
|
345
|
+
_context3.next = 3;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
success();
|
|
349
|
+
this._apDetectorObserver.notifyObservers(successNotifyName);
|
|
350
|
+
return _context3.abrupt("return", true);
|
|
351
|
+
case 3:
|
|
352
|
+
_errorMsg = signal.aborted ? 'start: task is aborted' : 'start: no available access point detected';
|
|
353
|
+
_error = generateApDetectorError(AgoraRteErrorCode.AP_DETECT_FAILED, _errorMsg);
|
|
354
|
+
this.logger.error(_errorMsg);
|
|
355
|
+
failure(_error);
|
|
356
|
+
this._apDetectorObserver.notifyObservers(failureNotifyName);
|
|
357
|
+
return _context3.abrupt("return", false);
|
|
358
|
+
case 4:
|
|
359
|
+
case "end":
|
|
360
|
+
return _context3.stop();
|
|
361
|
+
}
|
|
362
|
+
}, _callee3, this);
|
|
363
|
+
}));
|
|
364
|
+
function _executeDetect(_x5, _x6, _x7, _x8, _x9) {
|
|
365
|
+
return _executeDetect2.apply(this, arguments);
|
|
366
|
+
}
|
|
367
|
+
return _executeDetect;
|
|
368
|
+
}()
|
|
369
|
+
}, {
|
|
370
|
+
key: "_runAllDetectTask",
|
|
371
|
+
value: function () {
|
|
372
|
+
var _runAllDetectTask2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(signal) {
|
|
373
|
+
var _this$_internalRtcCon3, _this$_externalRtcCon3;
|
|
374
|
+
var internalServerList, externalServerList, internalResult, externalResult;
|
|
375
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
376
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
377
|
+
case 0:
|
|
378
|
+
internalServerList = ((_this$_internalRtcCon3 = this._internalRtcConfig) === null || _this$_internalRtcCon3 === void 0 ? void 0 : _this$_internalRtcCon3.serverList) || [];
|
|
379
|
+
externalServerList = ((_this$_externalRtcCon3 = this._externalRtcConfig) === null || _this$_externalRtcCon3 === void 0 ? void 0 : _this$_externalRtcCon3.serverList) || []; // 先探测内网 IP
|
|
380
|
+
_context4.next = 1;
|
|
381
|
+
return this._runBatchDetectTask(internalServerList, signal);
|
|
382
|
+
case 1:
|
|
383
|
+
internalResult = _context4.sent;
|
|
384
|
+
if (!(internalResult.length > 0 && !signal.aborted)) {
|
|
385
|
+
_context4.next = 2;
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
this._availableRtcAccessPointConfig = _objectSpread(_objectSpread({}, this._internalRtcConfig), {}, {
|
|
389
|
+
serverList: internalResult
|
|
390
|
+
});
|
|
391
|
+
return _context4.abrupt("return", true);
|
|
392
|
+
case 2:
|
|
393
|
+
if (!(externalServerList.includes('public.agora') && !signal.aborted)) {
|
|
394
|
+
_context4.next = 3;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
this._availableRtcAccessPointConfig = _objectSpread(_objectSpread({}, this._externalRtcConfig), {}, {
|
|
398
|
+
serverList: ['public.agora']
|
|
399
|
+
});
|
|
400
|
+
return _context4.abrupt("return", true);
|
|
401
|
+
case 3:
|
|
402
|
+
_context4.next = 4;
|
|
403
|
+
return this._runBatchDetectTask(externalServerList, signal);
|
|
404
|
+
case 4:
|
|
405
|
+
externalResult = _context4.sent;
|
|
406
|
+
if (!(externalResult.length > 0 && !signal.aborted)) {
|
|
407
|
+
_context4.next = 5;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
this._availableRtcAccessPointConfig = _objectSpread(_objectSpread({}, this._externalRtcConfig), {}, {
|
|
411
|
+
serverList: externalResult
|
|
412
|
+
});
|
|
413
|
+
return _context4.abrupt("return", true);
|
|
414
|
+
case 5:
|
|
415
|
+
return _context4.abrupt("return", false);
|
|
416
|
+
case 6:
|
|
417
|
+
case "end":
|
|
418
|
+
return _context4.stop();
|
|
419
|
+
}
|
|
420
|
+
}, _callee4, this);
|
|
421
|
+
}));
|
|
422
|
+
function _runAllDetectTask(_x0) {
|
|
423
|
+
return _runAllDetectTask2.apply(this, arguments);
|
|
424
|
+
}
|
|
425
|
+
return _runAllDetectTask;
|
|
426
|
+
}()
|
|
427
|
+
}, {
|
|
428
|
+
key: "_runBatchDetectTask",
|
|
429
|
+
value: function () {
|
|
430
|
+
var _runBatchDetectTask2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(urlList, signal) {
|
|
431
|
+
var _this = this;
|
|
432
|
+
var concurrency,
|
|
433
|
+
promiseResult,
|
|
434
|
+
workers,
|
|
435
|
+
currentIndex,
|
|
436
|
+
createPromiseWorker,
|
|
437
|
+
i,
|
|
438
|
+
_args6 = arguments;
|
|
439
|
+
return _regeneratorRuntime.wrap(function (_context6) {
|
|
440
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
441
|
+
case 0:
|
|
442
|
+
concurrency = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : 5;
|
|
443
|
+
concurrency = Math.min(concurrency, urlList.length);
|
|
444
|
+
promiseResult = [];
|
|
445
|
+
workers = [];
|
|
446
|
+
currentIndex = 0;
|
|
447
|
+
createPromiseWorker = /*#__PURE__*/function () {
|
|
448
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
449
|
+
var url, result, _t;
|
|
450
|
+
return _regeneratorRuntime.wrap(function (_context5) {
|
|
451
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
452
|
+
case 0:
|
|
453
|
+
if (!(currentIndex < urlList.length && !signal.aborted)) {
|
|
454
|
+
_context5.next = 5;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
url = urlList[currentIndex];
|
|
458
|
+
currentIndex++;
|
|
459
|
+
_context5.prev = 1;
|
|
460
|
+
_context5.next = 2;
|
|
461
|
+
return _this._runOnceDetectTask(url);
|
|
462
|
+
case 2:
|
|
463
|
+
result = _context5.sent;
|
|
464
|
+
promiseResult.push(result);
|
|
465
|
+
_this.logger.info("_runBatchDetectTask: successfully detected ".concat(url));
|
|
466
|
+
_context5.next = 4;
|
|
467
|
+
break;
|
|
468
|
+
case 3:
|
|
469
|
+
_context5.prev = 3;
|
|
470
|
+
_t = _context5["catch"](1);
|
|
471
|
+
// 这里选择记录错误日志,但不阻止其他任务继续进行
|
|
472
|
+
_this.logger.error("_runBatchDetectTask: failed detected ".concat(url, ", ").concat(_t));
|
|
473
|
+
case 4:
|
|
474
|
+
_context5.next = 0;
|
|
475
|
+
break;
|
|
476
|
+
case 5:
|
|
477
|
+
case "end":
|
|
478
|
+
return _context5.stop();
|
|
479
|
+
}
|
|
480
|
+
}, _callee5, null, [[1, 3]]);
|
|
481
|
+
}));
|
|
482
|
+
return function createPromiseWorker() {
|
|
483
|
+
return _ref.apply(this, arguments);
|
|
484
|
+
};
|
|
485
|
+
}();
|
|
486
|
+
for (i = 0; i < concurrency; i++) {
|
|
487
|
+
workers.push(createPromiseWorker());
|
|
488
|
+
}
|
|
489
|
+
_context6.next = 1;
|
|
490
|
+
return Promise.all(workers);
|
|
491
|
+
case 1:
|
|
492
|
+
if (!signal.aborted) {
|
|
493
|
+
_context6.next = 2;
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
this.logger.info('_runBatchDetectTask: detection was aborted');
|
|
497
|
+
return _context6.abrupt("return", []);
|
|
498
|
+
case 2:
|
|
499
|
+
return _context6.abrupt("return", promiseResult);
|
|
500
|
+
case 3:
|
|
501
|
+
case "end":
|
|
502
|
+
return _context6.stop();
|
|
503
|
+
}
|
|
504
|
+
}, _callee6, this);
|
|
505
|
+
}));
|
|
506
|
+
function _runBatchDetectTask(_x1, _x10) {
|
|
507
|
+
return _runBatchDetectTask2.apply(this, arguments);
|
|
508
|
+
}
|
|
509
|
+
return _runBatchDetectTask;
|
|
510
|
+
}()
|
|
511
|
+
}, {
|
|
512
|
+
key: "_runOnceDetectTask",
|
|
513
|
+
value: function () {
|
|
514
|
+
var _runOnceDetectTask2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(url) {
|
|
515
|
+
var requestUrl, errorMsg;
|
|
516
|
+
return _regeneratorRuntime.wrap(function (_context7) {
|
|
517
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
518
|
+
case 0:
|
|
519
|
+
// 将 url 转换为请求 URL
|
|
520
|
+
requestUrl = transformUrlToRequestUrl(url, this._isElectron);
|
|
521
|
+
if (requestUrl) {
|
|
522
|
+
_context7.next = 1;
|
|
523
|
+
break;
|
|
524
|
+
}
|
|
525
|
+
errorMsg = "invalid server domain name or ip format";
|
|
526
|
+
return _context7.abrupt("return", Promise.reject(errorMsg));
|
|
527
|
+
case 1:
|
|
528
|
+
_context7.next = 2;
|
|
529
|
+
return this._fetchWithTimeoutAndCheck(requestUrl, this._detectTimeout);
|
|
530
|
+
case 2:
|
|
531
|
+
return _context7.abrupt("return", url);
|
|
532
|
+
case 3:
|
|
533
|
+
case "end":
|
|
534
|
+
return _context7.stop();
|
|
535
|
+
}
|
|
536
|
+
}, _callee7, this);
|
|
537
|
+
}));
|
|
538
|
+
function _runOnceDetectTask(_x11) {
|
|
539
|
+
return _runOnceDetectTask2.apply(this, arguments);
|
|
540
|
+
}
|
|
541
|
+
return _runOnceDetectTask;
|
|
542
|
+
}() // 请求 url,300ms 内返回 HTTP 状态 为 200 且包体为 hello 表示成功,其他情况均为失败
|
|
543
|
+
}, {
|
|
544
|
+
key: "_fetchWithTimeoutAndCheck",
|
|
545
|
+
value: function () {
|
|
546
|
+
var _fetchWithTimeoutAndCheck2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(url, customTimeout) {
|
|
547
|
+
var errorMsg, response, _error$message, _t2;
|
|
548
|
+
return _regeneratorRuntime.wrap(function (_context8) {
|
|
549
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
550
|
+
case 0:
|
|
551
|
+
errorMsg = '';
|
|
552
|
+
_context8.prev = 1;
|
|
553
|
+
_context8.next = 2;
|
|
554
|
+
return fetch(url, {
|
|
555
|
+
timeout: customTimeout,
|
|
556
|
+
method: 'GET'
|
|
557
|
+
});
|
|
558
|
+
case 2:
|
|
559
|
+
response = _context8.sent;
|
|
560
|
+
if (!(response.status !== 200)) {
|
|
561
|
+
_context8.next = 3;
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
errorMsg = "".concat(url, ", reason: response code is not 200, code: ").concat(response.status);
|
|
565
|
+
_context8.next = 5;
|
|
566
|
+
break;
|
|
567
|
+
case 3:
|
|
568
|
+
if (!(response.data !== 'hello')) {
|
|
569
|
+
_context8.next = 4;
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
errorMsg = "".concat(url, ", reason: response content is not 'hello'");
|
|
573
|
+
_context8.next = 5;
|
|
574
|
+
break;
|
|
575
|
+
case 4:
|
|
576
|
+
return _context8.abrupt("return", Promise.resolve(url));
|
|
577
|
+
case 5:
|
|
578
|
+
_context8.next = 7;
|
|
579
|
+
break;
|
|
580
|
+
case 6:
|
|
581
|
+
_context8.prev = 6;
|
|
582
|
+
_t2 = _context8["catch"](1);
|
|
583
|
+
if ((_t2 === null || _t2 === void 0 ? void 0 : _t2.name) === 'AbortError') {
|
|
584
|
+
errorMsg = "".concat(url, ", reason: request timeout: ").concat(customTimeout, ", aborted");
|
|
585
|
+
} else {
|
|
586
|
+
errorMsg = "".concat(url, ", reason: request unknown error : ").concat((_error$message = _t2 === null || _t2 === void 0 ? void 0 : _t2.message) !== null && _error$message !== void 0 ? _error$message : _t2);
|
|
587
|
+
}
|
|
588
|
+
case 7:
|
|
589
|
+
return _context8.abrupt("return", Promise.reject(errorMsg));
|
|
590
|
+
case 8:
|
|
591
|
+
case "end":
|
|
592
|
+
return _context8.stop();
|
|
593
|
+
}
|
|
594
|
+
}, _callee8, null, [[1, 6]]);
|
|
595
|
+
}));
|
|
596
|
+
function _fetchWithTimeoutAndCheck(_x12, _x13) {
|
|
597
|
+
return _fetchWithTimeoutAndCheck2.apply(this, arguments);
|
|
598
|
+
}
|
|
599
|
+
return _fetchWithTimeoutAndCheck;
|
|
600
|
+
}()
|
|
601
|
+
}, {
|
|
602
|
+
key: "_resolveParamsRtcConfig",
|
|
603
|
+
value: function _resolveParamsRtcConfig(name, rtcConfig) {
|
|
604
|
+
if (rtcConfig === undefined) {
|
|
605
|
+
return undefined;
|
|
606
|
+
}
|
|
607
|
+
if (_typeof(rtcConfig) !== 'object') {
|
|
608
|
+
this.logger.error("".concat(name, " type error, it is ").concat(_typeof(rtcConfig), ", expect type object"));
|
|
609
|
+
return undefined;
|
|
610
|
+
}
|
|
611
|
+
if (!Array.isArray(rtcConfig.serverList)) {
|
|
612
|
+
this.logger.error("".concat(name, ".serverList type is ").concat(_typeof(rtcConfig.serverList), ", expect type array"));
|
|
613
|
+
}
|
|
614
|
+
if (this._isElectron) {
|
|
615
|
+
var electronRtcConfig = rtcConfig;
|
|
616
|
+
if (typeof electronRtcConfig.verifyDomainName !== 'string') {
|
|
617
|
+
this.logger.error("".concat(name, ".verifyDomainName type is ").concat(_typeof(electronRtcConfig.verifyDomainName), ", expect type string"));
|
|
618
|
+
return undefined;
|
|
619
|
+
}
|
|
620
|
+
} else {
|
|
621
|
+
var webRtcConfig = rtcConfig;
|
|
622
|
+
if (typeof webRtcConfig.serverDomain !== 'string') {
|
|
623
|
+
this.logger.error("".concat(name, ".serverDomain type is ").concat(_typeof(webRtcConfig.serverDomain), ", expect type string"));
|
|
624
|
+
return undefined;
|
|
625
|
+
}
|
|
626
|
+
if (typeof webRtcConfig.serverPort !== 'number') {
|
|
627
|
+
this.logger.error("".concat(name, ".serverPort type is ").concat(_typeof(webRtcConfig.serverPort), ", expect type number"));
|
|
628
|
+
return undefined;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return rtcConfig;
|
|
632
|
+
}
|
|
633
|
+
}, {
|
|
634
|
+
key: "_resolveParamsDetecTimeout",
|
|
635
|
+
value: function _resolveParamsDetecTimeout() {
|
|
636
|
+
var detectTimeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_FETCH_URL_TIMEOUT;
|
|
637
|
+
if (typeof detectTimeout === 'number') {
|
|
638
|
+
if (detectTimeout > 0) {
|
|
639
|
+
return detectTimeout;
|
|
640
|
+
}
|
|
641
|
+
this.logger.warn("detectTimeout value is 0 or negative, use default value: ".concat(DEFAULT_FETCH_URL_TIMEOUT, "ms"));
|
|
642
|
+
return DEFAULT_FETCH_URL_TIMEOUT;
|
|
643
|
+
}
|
|
644
|
+
this.logger.error("detectTimeout type is ".concat(_typeof(detectTimeout), ", expect type is number, use default value: ").concat(DEFAULT_FETCH_URL_TIMEOUT, "ms"));
|
|
645
|
+
return DEFAULT_FETCH_URL_TIMEOUT;
|
|
646
|
+
}
|
|
647
|
+
}, {
|
|
648
|
+
key: "_resolveParamsIsRedetect",
|
|
649
|
+
value: function _resolveParamsIsRedetect() {
|
|
650
|
+
var isRedetect = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
651
|
+
if (typeof isRedetect === 'boolean') {
|
|
652
|
+
return isRedetect;
|
|
653
|
+
}
|
|
654
|
+
this.logger.error("isRedetect type is ".concat(_typeof(isRedetect), ", expect type is boolean, use default value: true"));
|
|
655
|
+
return true;
|
|
656
|
+
}
|
|
657
|
+
}]);
|
|
658
|
+
}();
|
|
659
|
+
_AgoraRteApDetectorImpl = AgoraRteApDetectorImpl;
|
|
660
|
+
var _applyDecs$e = _applyDecs(_AgoraRteApDetectorImpl, [[trace, 2, "isDetectRequired"], [trace, 2, "restart"], [trace, 2, "start"], [trace, 2, "_executeDetect"]], []).e;
|
|
661
|
+
var _applyDecs$e2 = _slicedToArray(_applyDecs$e, 1);
|
|
662
|
+
_initProto = _applyDecs$e2[0];
|
|
663
|
+
_applyDecs$e;
|