fcr-core 3.10.1 → 3.10.5
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/engine/index.js +102 -108
- package/lib/imports.js +1 -0
- package/lib/media-control/desktop.js +22 -13
- package/lib/media-control/mobile.js +27 -19
- package/lib/media-control/type.d.ts +3 -3
- package/lib/monitor-control/index.js +17 -7
- package/lib/peer-session/index.js +120 -121
- package/lib/plugins/chat/chatroom.js +119 -96
- package/lib/plugins/chat/connector.js +69 -48
- package/lib/remote-control/index.js +194 -216
- package/lib/room-control/ability-control/index.js +20 -10
- package/lib/room-control/application-control/index.js +82 -75
- package/lib/room-control/group-control/index.js +31 -30
- package/lib/room-control/helpers/board-init-info-helper.js +16 -10
- package/lib/room-control/helpers/validation-helper.js +1 -1
- package/lib/room-control/index.js +70 -51
- package/lib/room-control/infinity-room-control/index.js +27 -19
- package/lib/room-control/interpreter-control/index.js +77 -65
- package/lib/room-control/interpreter-control/room.js +6 -4
- package/lib/room-control/join-before-host-waitingroom-control/index.js +6 -4
- package/lib/room-control/mainroom-control/index.js +37 -25
- package/lib/room-control/privilege-control/helper.js +28 -13
- package/lib/room-control/privilege-control/index.js +36 -28
- package/lib/room-control/room-connector-control/index.js +52 -49
- package/lib/room-control/room-connector-control/type.d.ts +1 -1
- package/lib/room-control/room-control-factory.js +10 -12
- package/lib/room-control/room-session/index.js +77 -74
- package/lib/room-control/shared-cache.js +63 -56
- package/lib/room-control/sharing-control/index.js +65 -57
- package/lib/room-control/stream-control/index.js +197 -193
- package/lib/room-control/stt-control/de-compress-gzip.js +10 -0
- package/lib/room-control/stt-control/index.js +93 -86
- package/lib/room-control/user-control/index.js +162 -155
- package/lib/room-control/waitingroom-control/index.js +18 -9
- package/lib/room-control/whiteboard-control/utils.js +4 -2
- package/lib/room-control/whiteboard-control-v1/board-subwindow.js +2 -1
- package/lib/room-control/whiteboard-control-v1/board-window.js +120 -103
- package/lib/room-control/whiteboard-control-v1/factory.js +7 -4
- package/lib/room-control/whiteboard-control-v1/index.js +80 -67
- package/lib/room-control/whiteboard-control-v1/mount-manager.js +4 -2
- package/lib/room-control/whiteboard-control-v1/utils.js +17 -14
- package/lib/room-control/whiteboard-control-v2/annotation-control/control.js +14 -10
- package/lib/room-control/whiteboard-control-v2/annotation-control/factory.js +17 -8
- package/lib/room-control/whiteboard-control-v2/base/index.js +61 -53
- package/lib/room-control/whiteboard-control-v2/base/main-window.js +39 -30
- package/lib/room-control/whiteboard-control-v2/utils.js +10 -10
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/control.js +45 -33
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/factory.js +27 -11
- package/lib/room-control/widget-control/index.js +43 -33
- package/lib/room-router/index.js +66 -58
- package/lib/schema.d.ts +15 -15
- package/lib/service/api.js +446 -548
- package/lib/struct.js +5 -2
- package/lib/utilities/abortable-retry.js +3 -0
- package/lib/utilities/collection.js +15 -11
- package/lib/utilities/error-helpers.js +34 -27
- package/lib/utilities/error.js +4 -3
- package/lib/utilities/join-helper.js +37 -31
- package/lib/utilities/logger.js +8 -5
- package/lib/utilities/parameters.js +21 -10
- package/lib/utilities/retry-helpers.js +1 -0
- package/lib/utilities/stream.js +16 -11
- package/lib/utilities/user.js +4 -3
- package/lib/utilities/validate-params.js +1 -1
- package/lib/utilities/video-encoder-config.js +10 -5
- package/lib-es/engine/index.js +102 -108
- package/lib-es/media-control/desktop.js +22 -13
- package/lib-es/media-control/mobile.js +27 -19
- package/lib-es/monitor-control/index.js +16 -7
- package/lib-es/peer-session/index.js +120 -121
- package/lib-es/plugins/chat/chatroom.js +118 -95
- package/lib-es/plugins/chat/connector.js +67 -47
- package/lib-es/remote-control/index.js +194 -216
- package/lib-es/room-control/ability-control/index.js +19 -10
- package/lib-es/room-control/application-control/index.js +81 -75
- package/lib-es/room-control/group-control/index.js +31 -30
- package/lib-es/room-control/helpers/board-init-info-helper.js +15 -10
- package/lib-es/room-control/helpers/validation-helper.js +1 -1
- package/lib-es/room-control/index.js +69 -51
- package/lib-es/room-control/infinity-room-control/index.js +26 -19
- package/lib-es/room-control/interpreter-control/index.js +77 -65
- package/lib-es/room-control/interpreter-control/room.js +5 -4
- package/lib-es/room-control/join-before-host-waitingroom-control/index.js +5 -4
- package/lib-es/room-control/mainroom-control/index.js +37 -25
- package/lib-es/room-control/privilege-control/helper.js +27 -13
- package/lib-es/room-control/privilege-control/index.js +36 -28
- package/lib-es/room-control/room-connector-control/index.js +52 -49
- package/lib-es/room-control/room-control-factory.js +10 -12
- package/lib-es/room-control/room-session/index.js +77 -74
- package/lib-es/room-control/shared-cache.js +62 -56
- package/lib-es/room-control/sharing-control/index.js +64 -57
- package/lib-es/room-control/stream-control/index.js +197 -193
- package/lib-es/room-control/stt-control/de-compress-gzip.js +10 -0
- package/lib-es/room-control/stt-control/index.js +93 -86
- package/lib-es/room-control/user-control/index.js +162 -155
- package/lib-es/room-control/waitingroom-control/index.js +18 -9
- package/lib-es/room-control/whiteboard-control/utils.js +4 -2
- package/lib-es/room-control/whiteboard-control-v1/board-subwindow.js +2 -1
- package/lib-es/room-control/whiteboard-control-v1/board-window.js +120 -103
- package/lib-es/room-control/whiteboard-control-v1/factory.js +6 -4
- package/lib-es/room-control/whiteboard-control-v1/index.js +80 -67
- package/lib-es/room-control/whiteboard-control-v1/mount-manager.js +3 -2
- package/lib-es/room-control/whiteboard-control-v1/utils.js +17 -14
- package/lib-es/room-control/whiteboard-control-v2/annotation-control/control.js +13 -10
- package/lib-es/room-control/whiteboard-control-v2/annotation-control/factory.js +16 -8
- package/lib-es/room-control/whiteboard-control-v2/base/index.js +60 -53
- package/lib-es/room-control/whiteboard-control-v2/base/main-window.js +39 -30
- package/lib-es/room-control/whiteboard-control-v2/utils.js +10 -10
- package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/control.js +45 -33
- package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/factory.js +26 -11
- package/lib-es/room-control/widget-control/index.js +42 -33
- package/lib-es/room-router/index.js +66 -58
- package/lib-es/service/api.js +445 -548
- package/lib-es/struct.js +4 -2
- package/lib-es/utilities/abortable-retry.js +3 -0
- package/lib-es/utilities/collection.js +14 -11
- package/lib-es/utilities/error-helpers.js +33 -26
- package/lib-es/utilities/error.js +4 -3
- package/lib-es/utilities/join-helper.js +36 -29
- package/lib-es/utilities/logger.js +7 -5
- package/lib-es/utilities/parameters.js +21 -10
- package/lib-es/utilities/retry-helpers.js +1 -0
- package/lib-es/utilities/stream.js +15 -11
- package/lib-es/utilities/user.js +4 -3
- package/lib-es/utilities/validate-params.js +1 -1
- package/lib-es/utilities/video-encoder-config.js +10 -5
- package/package.json +4 -4
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import "core-js/modules/es.symbol.description.js";
|
|
2
|
+
import "core-js/modules/es.error.cause.js";
|
|
1
3
|
import "core-js/modules/es.array.push.js";
|
|
2
4
|
import "core-js/modules/esnext.function.metadata.js";
|
|
5
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
6
|
+
import "core-js/modules/esnext.iterator.filter.js";
|
|
7
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
8
|
import "core-js/modules/esnext.symbol.metadata.js";
|
|
4
|
-
|
|
9
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
10
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
11
|
+
var _FcrPeerSessionControlImpl;
|
|
12
|
+
let _initProto, _startPeerSessionDecs, _stopPeerSessionDecs, _endPeerSessionDecs, _acceptPeerSessionDecs, _rejectPeerSessionDecs, _ref;
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
5
15
|
import "core-js/modules/es.json.stringify.js";
|
|
6
16
|
import "core-js/modules/esnext.map.delete-all.js";
|
|
7
17
|
import "core-js/modules/esnext.map.emplace.js";
|
|
@@ -17,6 +27,7 @@ import "core-js/modules/esnext.map.merge.js";
|
|
|
17
27
|
import "core-js/modules/esnext.map.reduce.js";
|
|
18
28
|
import "core-js/modules/esnext.map.some.js";
|
|
19
29
|
import "core-js/modules/esnext.map.update.js";
|
|
30
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
20
31
|
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 (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 (e) { return m(e), w.value; } : (o < 4 && (k = i(w, "get", m)), 3 !== o && (F = i(w, "set", m))) : (k = function (e) { return e[n]; }, (o < 2 || 4 === o) && (F = function (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 (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)]; } }; }
|
|
21
32
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
22
33
|
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); }
|
|
@@ -36,29 +47,25 @@ export const KEEPALIVE_TIMEOUT_MULTIPLIER = 2;
|
|
|
36
47
|
/**
|
|
37
48
|
* @internal
|
|
38
49
|
*/
|
|
50
|
+
_ref = (_startPeerSessionDecs = [trace(['params']), validateParams(fcrPeerSessionParamsSchema)], _stopPeerSessionDecs = [trace(['sessionId']), validateParams(stringSchema)], _endPeerSessionDecs = [trace(['sessionId', 'cause']), validateParams(stringSchema, stringKeyUnknownValueSchema.optional())], _acceptPeerSessionDecs = [trace(['session', 'cause']), validateParams(fcrSessionBaseSchema, stringKeyUnknownValueSchema.optional())], _rejectPeerSessionDecs = [trace(['session', 'cause']), validateParams(fcrSessionBaseSchema, stringKeyUnknownValueSchema.optional())], "logger");
|
|
39
51
|
export class FcrPeerSessionControlImpl {
|
|
40
|
-
static {
|
|
41
|
-
[_initProto] = _applyDecs(this, [[_startPeerSessionDecs, 2, "startPeerSession"], [_stopPeerSessionDecs, 2, "stopPeerSession"], [_endPeerSessionDecs, 2, "endPeerSession"], [_acceptPeerSessionDecs, 2, "acceptPeerSession"], [_rejectPeerSessionDecs, 2, "rejectPeerSession"], [trace, 2, "release"]], []).e;
|
|
42
|
-
}
|
|
43
|
-
//@internal
|
|
44
|
-
[(_startPeerSessionDecs = [trace(['params']), validateParams(fcrPeerSessionParamsSchema)], _stopPeerSessionDecs = [trace(['sessionId']), validateParams(stringSchema)], _endPeerSessionDecs = [trace(['sessionId', 'cause']), validateParams(stringSchema, stringKeyUnknownValueSchema.optional())], _acceptPeerSessionDecs = [trace(['session', 'cause']), validateParams(fcrSessionBaseSchema, stringKeyUnknownValueSchema.optional())], _rejectPeerSessionDecs = [trace(['session', 'cause']), validateParams(fcrSessionBaseSchema, stringKeyUnknownValueSchema.optional())], "logger")] = (_initProto(this), createLogger({
|
|
45
|
-
prefix: 'FcrPeerSessionControlImpl'
|
|
46
|
-
}));
|
|
47
|
-
//@internal
|
|
48
|
-
_observable = new AgoraObservable();
|
|
49
|
-
//@internal
|
|
50
|
-
_taskInterval = Duration.second(1);
|
|
51
|
-
//@internal
|
|
52
|
-
|
|
53
|
-
//@internal
|
|
54
|
-
_scheduleMap = new Map();
|
|
55
|
-
//@internal
|
|
56
|
-
_receivedMap = new Map();
|
|
57
|
-
//@internal
|
|
58
|
-
_engineObserver = {
|
|
59
|
-
onPeerMessageReceived: this._handlePeerMessage.bind(this)
|
|
60
|
-
};
|
|
61
52
|
constructor(_rteEngine, _api, _userId) {
|
|
53
|
+
//@internal
|
|
54
|
+
_defineProperty(this, _ref, (_initProto(this), createLogger({
|
|
55
|
+
prefix: 'FcrPeerSessionControlImpl'
|
|
56
|
+
})));
|
|
57
|
+
//@internal
|
|
58
|
+
_defineProperty(this, "_observable", new AgoraObservable());
|
|
59
|
+
//@internal
|
|
60
|
+
_defineProperty(this, "_taskInterval", Duration.second(1));
|
|
61
|
+
//@internal
|
|
62
|
+
_defineProperty(this, "_scheduleMap", new Map());
|
|
63
|
+
//@internal
|
|
64
|
+
_defineProperty(this, "_receivedMap", new Map());
|
|
65
|
+
//@internal
|
|
66
|
+
_defineProperty(this, "_engineObserver", {
|
|
67
|
+
onPeerMessageReceived: this._handlePeerMessage.bind(this)
|
|
68
|
+
});
|
|
62
69
|
this._rteEngine = _rteEngine;
|
|
63
70
|
this._api = _api;
|
|
64
71
|
this._userId = _userId;
|
|
@@ -70,7 +77,7 @@ export class FcrPeerSessionControlImpl {
|
|
|
70
77
|
async startPeerSession(params) {
|
|
71
78
|
try {
|
|
72
79
|
const session = {
|
|
73
|
-
sessionId: md5(
|
|
80
|
+
sessionId: md5("".concat(Date.now())),
|
|
74
81
|
sessionKey: params.sessionKey,
|
|
75
82
|
payload: params.payload,
|
|
76
83
|
duration: params.duration,
|
|
@@ -81,28 +88,24 @@ export class FcrPeerSessionControlImpl {
|
|
|
81
88
|
if (this._scheduleMap.has(session.sessionId)) {
|
|
82
89
|
throw generateFcrCoreClientError(ErrorModuleCode.FCR_PEER_SESSION, DetailErrorCode.PEER_SESSION_ALREADY_EXISTS, 'peer session already exists');
|
|
83
90
|
}
|
|
84
|
-
const {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
keepAlive: params.keepAlive,
|
|
96
|
-
action: 0
|
|
97
|
-
});
|
|
91
|
+
const _await$this$_api$upda = await this._api.updatePeerSession({
|
|
92
|
+
userId: this._userId,
|
|
93
|
+
sessionId: session.sessionId,
|
|
94
|
+
sessionKey: session.sessionKey,
|
|
95
|
+
duration: session.duration,
|
|
96
|
+
payload: session.payload,
|
|
97
|
+
targetId: params.receiverId,
|
|
98
|
+
keepAlive: params.keepAlive,
|
|
99
|
+
action: 0
|
|
100
|
+
}),
|
|
101
|
+
interval = _await$this$_api$upda.data.interval;
|
|
98
102
|
const nextTs = Date.now() + interval;
|
|
99
|
-
this._scheduleMap.set(session.sessionId, {
|
|
100
|
-
...params,
|
|
103
|
+
this._scheduleMap.set(session.sessionId, _objectSpread(_objectSpread({}, params), {}, {
|
|
101
104
|
nextTs,
|
|
102
105
|
startTs: Date.now(),
|
|
103
106
|
action: 0
|
|
104
|
-
});
|
|
105
|
-
this.logger.info(
|
|
107
|
+
}));
|
|
108
|
+
this.logger.info("[PeerSession] put into session schedule: ".concat(session.sessionId, ", next ts: ").concat(nextTs, ", remain: ").concat(nextTs - Date.now(), "ms"));
|
|
106
109
|
return session.sessionId;
|
|
107
110
|
} catch (e) {
|
|
108
111
|
throw generateFcrCoreServerError(DetailErrorCode.LOCAL_HTTP_REQUEST_FAILED, 'start peer session failed');
|
|
@@ -145,27 +148,23 @@ export class FcrPeerSessionControlImpl {
|
|
|
145
148
|
if (session.keepAlive) {
|
|
146
149
|
const params = this._receivedMap.get(session.sessionId);
|
|
147
150
|
if (params) {
|
|
148
|
-
const {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
keepAlive: session.keepAlive,
|
|
160
|
-
action: 1
|
|
161
|
-
});
|
|
151
|
+
const _await$this$_api$upda2 = await this._api.updatePeerSession({
|
|
152
|
+
userId: this._userId,
|
|
153
|
+
sessionId: session.sessionId,
|
|
154
|
+
sessionKey: session.sessionKey,
|
|
155
|
+
duration: session.duration,
|
|
156
|
+
payload: session.payload,
|
|
157
|
+
targetId: session.senderId,
|
|
158
|
+
keepAlive: session.keepAlive,
|
|
159
|
+
action: 1
|
|
160
|
+
}),
|
|
161
|
+
interval = _await$this$_api$upda2.data.interval;
|
|
162
162
|
const _now = Date.now();
|
|
163
|
-
this._receivedMap.set(session.sessionId, {
|
|
164
|
-
...params,
|
|
163
|
+
this._receivedMap.set(session.sessionId, _objectSpread(_objectSpread({}, params), {}, {
|
|
165
164
|
nextTs: _now + interval,
|
|
166
165
|
startTs: _now,
|
|
167
166
|
action: 1
|
|
168
|
-
});
|
|
167
|
+
}));
|
|
169
168
|
return;
|
|
170
169
|
}
|
|
171
170
|
}
|
|
@@ -248,7 +247,7 @@ export class FcrPeerSessionControlImpl {
|
|
|
248
247
|
action: params.action
|
|
249
248
|
};
|
|
250
249
|
if (this._isSessionExpired(session)) {
|
|
251
|
-
this.logger.info(
|
|
250
|
+
this.logger.info("peer session expired, removed: ".concat(session.sessionId));
|
|
252
251
|
if (session.keepAlive) {
|
|
253
252
|
await this.endPeerSession(session.sessionId);
|
|
254
253
|
}
|
|
@@ -260,32 +259,28 @@ export class FcrPeerSessionControlImpl {
|
|
|
260
259
|
|
|
261
260
|
// check timeout
|
|
262
261
|
if (params.nextTs < Date.now()) {
|
|
263
|
-
this.logger.info(
|
|
262
|
+
this.logger.info("ping session: ".concat(session.sessionId));
|
|
264
263
|
try {
|
|
265
|
-
const {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
keepAlive: params.keepAlive,
|
|
277
|
-
action: params.action
|
|
278
|
-
});
|
|
264
|
+
const _await$this$_api$upda3 = await this._api.updatePeerSession({
|
|
265
|
+
userId: this._userId,
|
|
266
|
+
sessionId: session.sessionId,
|
|
267
|
+
sessionKey: session.sessionKey,
|
|
268
|
+
duration: params.duration,
|
|
269
|
+
payload: session.payload,
|
|
270
|
+
targetId: params.receiverId,
|
|
271
|
+
keepAlive: params.keepAlive,
|
|
272
|
+
action: params.action
|
|
273
|
+
}),
|
|
274
|
+
interval = _await$this$_api$upda3.data.interval;
|
|
279
275
|
const nextTs = Date.now() + interval;
|
|
280
276
|
if (this._scheduleMap.has(session.sessionId)) {
|
|
281
|
-
this._scheduleMap.set(session.sessionId, {
|
|
282
|
-
...params,
|
|
277
|
+
this._scheduleMap.set(session.sessionId, _objectSpread(_objectSpread({}, params), {}, {
|
|
283
278
|
nextTs
|
|
284
|
-
});
|
|
285
|
-
this.logger.info(
|
|
279
|
+
}));
|
|
280
|
+
this.logger.info("[PeerSession] refresh session schedule: ".concat(session.sessionId, ", next ts: ").concat(nextTs));
|
|
286
281
|
}
|
|
287
282
|
} catch (e) {
|
|
288
|
-
this.logger.error(
|
|
283
|
+
this.logger.error("ping session failed: ".concat(e));
|
|
289
284
|
}
|
|
290
285
|
}
|
|
291
286
|
}
|
|
@@ -293,7 +288,7 @@ export class FcrPeerSessionControlImpl {
|
|
|
293
288
|
for (const key of this._receivedMap.keys()) {
|
|
294
289
|
const session = this._receivedMap.get(key);
|
|
295
290
|
if (this._isSessionExpired(session)) {
|
|
296
|
-
this.logger.info(
|
|
291
|
+
this.logger.info("peer session expired, removed: ".concat(key));
|
|
297
292
|
if (session.keepAlive) {
|
|
298
293
|
await this.endPeerSession(key);
|
|
299
294
|
}
|
|
@@ -305,23 +300,21 @@ export class FcrPeerSessionControlImpl {
|
|
|
305
300
|
// 如果会话是keepAlive的,并且距离上次ping的时间超过2倍interval,则认为会话已过期(可能因为对方或己方已经掉线),需要结束会话
|
|
306
301
|
if (session.keepAlive && session.nextTs + session.interval * KEEPALIVE_TIMEOUT_MULTIPLIER < Date.now()) {
|
|
307
302
|
await this.endPeerSession(key);
|
|
308
|
-
this.logger.info(
|
|
303
|
+
this.logger.info("peer session has not been pinged, removed: ".concat(key));
|
|
309
304
|
}
|
|
310
305
|
}
|
|
311
306
|
}
|
|
312
307
|
|
|
313
308
|
//@internal
|
|
314
309
|
async _handlePeerMessage(message) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
payload
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const logContext = `cmd=${cmd}, sessionKey=${data.sessionKey}, sessionId=${data.sessionUuid}, ` + `action=${String(data.action)}, senderId=${senderId}, keepAlive=${!!data.keepAlive}`;
|
|
324
|
-
this.logger.info(`[PeerSession] received peer message: ${logContext}, payload=${JSON.stringify(data.payload ?? {})}`);
|
|
310
|
+
var _data$payload;
|
|
311
|
+
const senderId = message.senderId,
|
|
312
|
+
payload = message.payload;
|
|
313
|
+
const _ref2 = payload,
|
|
314
|
+
data = _ref2.data,
|
|
315
|
+
cmd = _ref2.cmd;
|
|
316
|
+
const logContext = "cmd=".concat(cmd, ", sessionKey=").concat(data.sessionKey, ", sessionId=").concat(data.sessionUuid, ", ") + "action=".concat(String(data.action), ", senderId=").concat(senderId, ", keepAlive=").concat(!!data.keepAlive);
|
|
317
|
+
this.logger.info("[PeerSession] received peer message: ".concat(logContext, ", payload=").concat(JSON.stringify((_data$payload = data.payload) !== null && _data$payload !== void 0 ? _data$payload : {})));
|
|
325
318
|
if (cmd === '1001') {
|
|
326
319
|
const session = {
|
|
327
320
|
sessionId: data.sessionUuid,
|
|
@@ -341,53 +334,52 @@ export class FcrPeerSessionControlImpl {
|
|
|
341
334
|
if (!this._isSessionExpired(session)) {
|
|
342
335
|
if (data.action === 1) {
|
|
343
336
|
if (this._scheduleMap.has(session.sessionId)) {
|
|
337
|
+
var _session$payload, _ref3, _data$payload2;
|
|
344
338
|
const sessionResponse = {
|
|
345
339
|
sessionId: session.sessionId,
|
|
346
340
|
sessionKey: session.sessionKey,
|
|
347
341
|
responderId: senderId,
|
|
348
|
-
payload: session.payload
|
|
349
|
-
cause: data.payload
|
|
342
|
+
payload: (_session$payload = session.payload) !== null && _session$payload !== void 0 ? _session$payload : {},
|
|
343
|
+
cause: (_ref3 = (_data$payload2 = data.payload) === null || _data$payload2 === void 0 ? void 0 : _data$payload2.cause) !== null && _ref3 !== void 0 ? _ref3 : {},
|
|
350
344
|
keepAlive: !!session.keepAlive
|
|
351
345
|
};
|
|
352
346
|
const params = this._scheduleMap.get(session.sessionId);
|
|
353
|
-
this._scheduleMap.set(session.sessionId, {
|
|
354
|
-
...params,
|
|
347
|
+
this._scheduleMap.set(session.sessionId, _objectSpread(_objectSpread({}, params), {}, {
|
|
355
348
|
action: 1
|
|
356
|
-
});
|
|
357
|
-
this.logger.info(
|
|
349
|
+
}));
|
|
350
|
+
this.logger.info("[PeerSession] forward peer session accepted to observers: ".concat(logContext));
|
|
358
351
|
this._observable.notifyObservers('onPeerSessionAccepted', sessionResponse);
|
|
359
352
|
} else {
|
|
360
|
-
this.logger.info(
|
|
353
|
+
this.logger.info("[PeerSession] ignore peer session accepted without local schedule: ".concat(logContext));
|
|
361
354
|
}
|
|
362
355
|
if (this._receivedMap.has(session.sessionId)) {
|
|
363
|
-
this._receivedMap.set(session.sessionId, {
|
|
364
|
-
...session,
|
|
356
|
+
this._receivedMap.set(session.sessionId, _objectSpread(_objectSpread({}, session), {}, {
|
|
365
357
|
nextTs: Date.now() + data.interval,
|
|
366
358
|
startTs: Date.now(),
|
|
367
359
|
action: 1
|
|
368
|
-
});
|
|
360
|
+
}));
|
|
369
361
|
}
|
|
370
362
|
return;
|
|
371
363
|
} else {
|
|
372
364
|
if (!this._receivedMap.has(session.sessionId)) {
|
|
373
|
-
this.logger.info(
|
|
365
|
+
this.logger.info("[PeerSession] forward peer session request to observers: ".concat(logContext));
|
|
374
366
|
this._observable.notifyObservers('onPeerSessionReceived', session);
|
|
375
367
|
} else {
|
|
376
|
-
this.logger.info(
|
|
368
|
+
this.logger.info("[PeerSession] peer session request already cached, update cache only: ".concat(logContext));
|
|
377
369
|
}
|
|
378
|
-
this._receivedMap.set(session.sessionId, {
|
|
379
|
-
...session,
|
|
370
|
+
this._receivedMap.set(session.sessionId, _objectSpread(_objectSpread({}, session), {}, {
|
|
380
371
|
nextTs: Date.now() + data.interval,
|
|
381
372
|
startTs: Date.now(),
|
|
382
373
|
action: 0
|
|
383
|
-
});
|
|
374
|
+
}));
|
|
384
375
|
}
|
|
385
376
|
} else {
|
|
386
|
-
this.logger.info(
|
|
377
|
+
this.logger.info("[PeerSession] ignore expired peer session message: ".concat(logContext, ", ") + "timestamp=".concat(session.timestamp, ", duration=").concat(session.duration));
|
|
387
378
|
}
|
|
388
379
|
} else if (cmd === '1002') {
|
|
389
380
|
if (data.action === 1) {
|
|
390
381
|
if (this._scheduleMap.has(data.sessionUuid)) {
|
|
382
|
+
var _session$payload2, _ref4, _data$payload3;
|
|
391
383
|
const session = this._scheduleMap.get(data.sessionUuid);
|
|
392
384
|
const sessionResponse = {
|
|
393
385
|
sessionId: data.sessionUuid,
|
|
@@ -395,18 +387,19 @@ export class FcrPeerSessionControlImpl {
|
|
|
395
387
|
responderId: senderId,
|
|
396
388
|
// FIXME: session may be lost when the client refreshes
|
|
397
389
|
// get payload from original session
|
|
398
|
-
payload: session.payload
|
|
399
|
-
cause: data.payload
|
|
390
|
+
payload: (_session$payload2 = session.payload) !== null && _session$payload2 !== void 0 ? _session$payload2 : {},
|
|
391
|
+
cause: (_ref4 = (_data$payload3 = data.payload) === null || _data$payload3 === void 0 ? void 0 : _data$payload3.cause) !== null && _ref4 !== void 0 ? _ref4 : {},
|
|
400
392
|
keepAlive: !!data.keepAlive
|
|
401
393
|
};
|
|
402
394
|
this._scheduleMap.delete(data.sessionUuid);
|
|
403
|
-
this.logger.info(
|
|
395
|
+
this.logger.info("[PeerSession] forward peer session accepted to observers: ".concat(logContext));
|
|
404
396
|
this._observable.notifyObservers('onPeerSessionAccepted', sessionResponse);
|
|
405
397
|
} else {
|
|
406
|
-
this.logger.info(
|
|
398
|
+
this.logger.info("[PeerSession] ignore peer session accepted without local schedule: ".concat(logContext));
|
|
407
399
|
}
|
|
408
400
|
} else if (data.action === 2) {
|
|
409
401
|
if (this._scheduleMap.has(data.sessionUuid)) {
|
|
402
|
+
var _session$payload3, _ref5, _data$payload4;
|
|
410
403
|
const session = this._scheduleMap.get(data.sessionUuid);
|
|
411
404
|
const sessionResponse = {
|
|
412
405
|
sessionId: data.sessionUuid,
|
|
@@ -414,27 +407,28 @@ export class FcrPeerSessionControlImpl {
|
|
|
414
407
|
responderId: senderId,
|
|
415
408
|
// FIXME: session may be lost when the client refreshes
|
|
416
409
|
// get payload from original session
|
|
417
|
-
payload: session.payload
|
|
418
|
-
cause: data.payload
|
|
410
|
+
payload: (_session$payload3 = session.payload) !== null && _session$payload3 !== void 0 ? _session$payload3 : {},
|
|
411
|
+
cause: (_ref5 = (_data$payload4 = data.payload) === null || _data$payload4 === void 0 ? void 0 : _data$payload4.cause) !== null && _ref5 !== void 0 ? _ref5 : {},
|
|
419
412
|
keepAlive: !!data.keepAlive
|
|
420
413
|
};
|
|
421
414
|
if (this._scheduleMap.has(data.sessionUuid)) {
|
|
422
415
|
this._scheduleMap.delete(data.sessionUuid);
|
|
423
|
-
this.logger.info(
|
|
416
|
+
this.logger.info("[PeerSession] forward peer session rejected to observers: ".concat(logContext));
|
|
424
417
|
this._observable.notifyObservers('onPeerSessionRejected', sessionResponse);
|
|
425
418
|
}
|
|
426
419
|
} else {
|
|
427
|
-
this.logger.info(
|
|
420
|
+
this.logger.info("[PeerSession] ignore peer session rejected without local schedule: ".concat(logContext));
|
|
428
421
|
}
|
|
429
422
|
} else if (data.action === 3) {
|
|
430
423
|
const scheduleSession = this._scheduleMap.get(data.sessionUuid);
|
|
431
424
|
const receivedSession = this._receivedMap.get(data.sessionUuid);
|
|
432
425
|
const session = scheduleSession || receivedSession;
|
|
433
426
|
if (session) {
|
|
427
|
+
var _ref6, _data$payload5;
|
|
434
428
|
const params = {
|
|
435
429
|
sessionId: data.sessionUuid,
|
|
436
430
|
fromUserId: senderId,
|
|
437
|
-
cause: data.payload
|
|
431
|
+
cause: (_ref6 = (_data$payload5 = data.payload) === null || _data$payload5 === void 0 ? void 0 : _data$payload5.cause) !== null && _ref6 !== void 0 ? _ref6 : {}
|
|
438
432
|
};
|
|
439
433
|
if (scheduleSession) {
|
|
440
434
|
this._scheduleMap.delete(data.sessionUuid);
|
|
@@ -443,15 +437,15 @@ export class FcrPeerSessionControlImpl {
|
|
|
443
437
|
this._receivedMap.delete(data.sessionUuid);
|
|
444
438
|
}
|
|
445
439
|
this._observable.notifyObservers('onPeerSessionEnded', params.sessionId, params.fromUserId, params.cause);
|
|
446
|
-
this.logger.info(
|
|
440
|
+
this.logger.info("[PeerSession] forward peer session ended to observers: ".concat(logContext));
|
|
447
441
|
} else {
|
|
448
|
-
this.logger.info(
|
|
442
|
+
this.logger.info("[PeerSession] ignore peer session ended without cached session: ".concat(logContext));
|
|
449
443
|
}
|
|
450
444
|
} else {
|
|
451
|
-
this.logger.info(
|
|
445
|
+
this.logger.info("[PeerSession] ignore peer session response with unknown action: ".concat(logContext));
|
|
452
446
|
}
|
|
453
447
|
} else {
|
|
454
|
-
this.logger.info(
|
|
448
|
+
this.logger.info("[PeerSession] ignore unsupported peer session cmd: ".concat(logContext));
|
|
455
449
|
}
|
|
456
450
|
}
|
|
457
451
|
|
|
@@ -462,4 +456,9 @@ export class FcrPeerSessionControlImpl {
|
|
|
462
456
|
_addLogObserver() {
|
|
463
457
|
this.addObserver(generateLogObserver(this.logger, [['onPeerSessionAccepted', ['session']], ['onPeerSessionReceived', ['session']], ['onPeerSessionRejected', ['session']], ['onPeerSessionEnded', ['sessionId', 'fromUserId', 'reason']]]));
|
|
464
458
|
}
|
|
465
|
-
}
|
|
459
|
+
}
|
|
460
|
+
_FcrPeerSessionControlImpl = FcrPeerSessionControlImpl;
|
|
461
|
+
var _applyDecs$e = _applyDecs(_FcrPeerSessionControlImpl, [[_startPeerSessionDecs, 2, "startPeerSession"], [_stopPeerSessionDecs, 2, "stopPeerSession"], [_endPeerSessionDecs, 2, "endPeerSession"], [_acceptPeerSessionDecs, 2, "acceptPeerSession"], [_rejectPeerSessionDecs, 2, "rejectPeerSession"], [trace, 2, "release"]], []).e;
|
|
462
|
+
var _applyDecs$e2 = _slicedToArray(_applyDecs$e, 1);
|
|
463
|
+
_initProto = _applyDecs$e2[0];
|
|
464
|
+
_applyDecs$e;
|