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