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,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/es.symbol.description.js");
|
|
4
|
-
require("core-js/modules/es.error.cause.js");
|
|
5
3
|
require("core-js/modules/es.array.push.js");
|
|
6
4
|
require("core-js/modules/esnext.function.metadata.js");
|
|
7
|
-
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
-
require("core-js/modules/esnext.iterator.filter.js");
|
|
9
|
-
require("core-js/modules/esnext.iterator.for-each.js");
|
|
10
5
|
require("core-js/modules/esnext.symbol.metadata.js");
|
|
11
6
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
12
7
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -28,18 +23,12 @@ require("core-js/modules/esnext.map.merge.js");
|
|
|
28
23
|
require("core-js/modules/esnext.map.reduce.js");
|
|
29
24
|
require("core-js/modules/esnext.map.some.js");
|
|
30
25
|
require("core-js/modules/esnext.map.update.js");
|
|
31
|
-
require("core-js/modules/web.dom-collections.iterator.js");
|
|
32
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
33
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
34
26
|
var _imports = require("../imports");
|
|
35
27
|
var _error = require("../utilities/error");
|
|
36
28
|
var _logger = require("../utilities/logger");
|
|
37
29
|
var _schema = require("../schema");
|
|
38
30
|
var _validateParams = _interopRequireDefault(require("../utilities/validate-params"));
|
|
39
|
-
|
|
40
|
-
let _initProto, _startPeerSessionDecs, _stopPeerSessionDecs, _endPeerSessionDecs, _acceptPeerSessionDecs, _rejectPeerSessionDecs, _ref;
|
|
41
|
-
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; }
|
|
42
|
-
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) { (0, _defineProperty2.default)(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; }
|
|
31
|
+
let _initProto, _startPeerSessionDecs, _stopPeerSessionDecs, _endPeerSessionDecs, _acceptPeerSessionDecs, _rejectPeerSessionDecs;
|
|
43
32
|
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)]; } }; }
|
|
44
33
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
45
34
|
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); }
|
|
@@ -53,25 +42,29 @@ const KEEPALIVE_TIMEOUT_MULTIPLIER = exports.KEEPALIVE_TIMEOUT_MULTIPLIER = 2;
|
|
|
53
42
|
/**
|
|
54
43
|
* @internal
|
|
55
44
|
*/
|
|
56
|
-
_ref = (_startPeerSessionDecs = [(0, _imports.trace)(['params']), (0, _validateParams.default)(_schema.fcrPeerSessionParamsSchema)], _stopPeerSessionDecs = [(0, _imports.trace)(['sessionId']), (0, _validateParams.default)(_schema.stringSchema)], _endPeerSessionDecs = [(0, _imports.trace)(['sessionId', 'cause']), (0, _validateParams.default)(_schema.stringSchema, _schema.stringKeyUnknownValueSchema.optional())], _acceptPeerSessionDecs = [(0, _imports.trace)(['session', 'cause']), (0, _validateParams.default)(_schema.fcrSessionBaseSchema, _schema.stringKeyUnknownValueSchema.optional())], _rejectPeerSessionDecs = [(0, _imports.trace)(['session', 'cause']), (0, _validateParams.default)(_schema.fcrSessionBaseSchema, _schema.stringKeyUnknownValueSchema.optional())], "logger");
|
|
57
45
|
class FcrPeerSessionControlImpl {
|
|
46
|
+
static {
|
|
47
|
+
[_initProto] = _applyDecs(this, [[_startPeerSessionDecs, 2, "startPeerSession"], [_stopPeerSessionDecs, 2, "stopPeerSession"], [_endPeerSessionDecs, 2, "endPeerSession"], [_acceptPeerSessionDecs, 2, "acceptPeerSession"], [_rejectPeerSessionDecs, 2, "rejectPeerSession"], [_imports.trace, 2, "release"]], []).e;
|
|
48
|
+
}
|
|
49
|
+
//@internal
|
|
50
|
+
[(_startPeerSessionDecs = [(0, _imports.trace)(['params']), (0, _validateParams.default)(_schema.fcrPeerSessionParamsSchema)], _stopPeerSessionDecs = [(0, _imports.trace)(['sessionId']), (0, _validateParams.default)(_schema.stringSchema)], _endPeerSessionDecs = [(0, _imports.trace)(['sessionId', 'cause']), (0, _validateParams.default)(_schema.stringSchema, _schema.stringKeyUnknownValueSchema.optional())], _acceptPeerSessionDecs = [(0, _imports.trace)(['session', 'cause']), (0, _validateParams.default)(_schema.fcrSessionBaseSchema, _schema.stringKeyUnknownValueSchema.optional())], _rejectPeerSessionDecs = [(0, _imports.trace)(['session', 'cause']), (0, _validateParams.default)(_schema.fcrSessionBaseSchema, _schema.stringKeyUnknownValueSchema.optional())], "logger")] = (_initProto(this), (0, _logger.createLogger)({
|
|
51
|
+
prefix: 'FcrPeerSessionControlImpl'
|
|
52
|
+
}));
|
|
53
|
+
//@internal
|
|
54
|
+
_observable = new _imports.AgoraObservable();
|
|
55
|
+
//@internal
|
|
56
|
+
_taskInterval = _imports.Duration.second(1);
|
|
57
|
+
//@internal
|
|
58
|
+
|
|
59
|
+
//@internal
|
|
60
|
+
_scheduleMap = new Map();
|
|
61
|
+
//@internal
|
|
62
|
+
_receivedMap = new Map();
|
|
63
|
+
//@internal
|
|
64
|
+
_engineObserver = {
|
|
65
|
+
onPeerMessageReceived: this._handlePeerMessage.bind(this)
|
|
66
|
+
};
|
|
58
67
|
constructor(_rteEngine, _api, _userId) {
|
|
59
|
-
//@internal
|
|
60
|
-
(0, _defineProperty2.default)(this, _ref, (_initProto(this), (0, _logger.createLogger)({
|
|
61
|
-
prefix: 'FcrPeerSessionControlImpl'
|
|
62
|
-
})));
|
|
63
|
-
//@internal
|
|
64
|
-
(0, _defineProperty2.default)(this, "_observable", new _imports.AgoraObservable());
|
|
65
|
-
//@internal
|
|
66
|
-
(0, _defineProperty2.default)(this, "_taskInterval", _imports.Duration.second(1));
|
|
67
|
-
//@internal
|
|
68
|
-
(0, _defineProperty2.default)(this, "_scheduleMap", new Map());
|
|
69
|
-
//@internal
|
|
70
|
-
(0, _defineProperty2.default)(this, "_receivedMap", new Map());
|
|
71
|
-
//@internal
|
|
72
|
-
(0, _defineProperty2.default)(this, "_engineObserver", {
|
|
73
|
-
onPeerMessageReceived: this._handlePeerMessage.bind(this)
|
|
74
|
-
});
|
|
75
68
|
this._rteEngine = _rteEngine;
|
|
76
69
|
this._api = _api;
|
|
77
70
|
this._userId = _userId;
|
|
@@ -83,7 +76,7 @@ class FcrPeerSessionControlImpl {
|
|
|
83
76
|
async startPeerSession(params) {
|
|
84
77
|
try {
|
|
85
78
|
const session = {
|
|
86
|
-
sessionId: (0, _imports.md5)(
|
|
79
|
+
sessionId: (0, _imports.md5)(`${Date.now()}`),
|
|
87
80
|
sessionKey: params.sessionKey,
|
|
88
81
|
payload: params.payload,
|
|
89
82
|
duration: params.duration,
|
|
@@ -94,24 +87,28 @@ class FcrPeerSessionControlImpl {
|
|
|
94
87
|
if (this._scheduleMap.has(session.sessionId)) {
|
|
95
88
|
throw (0, _error.generateFcrCoreClientError)(_imports.ErrorModuleCode.FCR_PEER_SESSION, _imports.DetailErrorCode.PEER_SESSION_ALREADY_EXISTS, 'peer session already exists');
|
|
96
89
|
}
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
90
|
+
const {
|
|
91
|
+
data: {
|
|
92
|
+
interval
|
|
93
|
+
}
|
|
94
|
+
} = await this._api.updatePeerSession({
|
|
95
|
+
userId: this._userId,
|
|
96
|
+
sessionId: session.sessionId,
|
|
97
|
+
sessionKey: session.sessionKey,
|
|
98
|
+
duration: session.duration,
|
|
99
|
+
payload: session.payload,
|
|
100
|
+
targetId: params.receiverId,
|
|
101
|
+
keepAlive: params.keepAlive,
|
|
102
|
+
action: 0
|
|
103
|
+
});
|
|
108
104
|
const nextTs = Date.now() + interval;
|
|
109
|
-
this._scheduleMap.set(session.sessionId,
|
|
105
|
+
this._scheduleMap.set(session.sessionId, {
|
|
106
|
+
...params,
|
|
110
107
|
nextTs,
|
|
111
108
|
startTs: Date.now(),
|
|
112
109
|
action: 0
|
|
113
|
-
})
|
|
114
|
-
this.logger.info(
|
|
110
|
+
});
|
|
111
|
+
this.logger.info(`[PeerSession] put into session schedule: ${session.sessionId}, next ts: ${nextTs}, remain: ${nextTs - Date.now()}ms`);
|
|
115
112
|
return session.sessionId;
|
|
116
113
|
} catch (e) {
|
|
117
114
|
throw (0, _error.generateFcrCoreServerError)(_imports.DetailErrorCode.LOCAL_HTTP_REQUEST_FAILED, 'start peer session failed');
|
|
@@ -154,23 +151,27 @@ class FcrPeerSessionControlImpl {
|
|
|
154
151
|
if (session.keepAlive) {
|
|
155
152
|
const params = this._receivedMap.get(session.sessionId);
|
|
156
153
|
if (params) {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
154
|
+
const {
|
|
155
|
+
data: {
|
|
156
|
+
interval
|
|
157
|
+
}
|
|
158
|
+
} = await this._api.updatePeerSession({
|
|
159
|
+
userId: this._userId,
|
|
160
|
+
sessionId: session.sessionId,
|
|
161
|
+
sessionKey: session.sessionKey,
|
|
162
|
+
duration: session.duration,
|
|
163
|
+
payload: session.payload,
|
|
164
|
+
targetId: session.senderId,
|
|
165
|
+
keepAlive: session.keepAlive,
|
|
166
|
+
action: 1
|
|
167
|
+
});
|
|
168
168
|
const _now = Date.now();
|
|
169
|
-
this._receivedMap.set(session.sessionId,
|
|
169
|
+
this._receivedMap.set(session.sessionId, {
|
|
170
|
+
...params,
|
|
170
171
|
nextTs: _now + interval,
|
|
171
172
|
startTs: _now,
|
|
172
173
|
action: 1
|
|
173
|
-
})
|
|
174
|
+
});
|
|
174
175
|
return;
|
|
175
176
|
}
|
|
176
177
|
}
|
|
@@ -253,7 +254,7 @@ class FcrPeerSessionControlImpl {
|
|
|
253
254
|
action: params.action
|
|
254
255
|
};
|
|
255
256
|
if (this._isSessionExpired(session)) {
|
|
256
|
-
this.logger.info(
|
|
257
|
+
this.logger.info(`peer session expired, removed: ${session.sessionId}`);
|
|
257
258
|
if (session.keepAlive) {
|
|
258
259
|
await this.endPeerSession(session.sessionId);
|
|
259
260
|
}
|
|
@@ -265,28 +266,32 @@ class FcrPeerSessionControlImpl {
|
|
|
265
266
|
|
|
266
267
|
// check timeout
|
|
267
268
|
if (params.nextTs < Date.now()) {
|
|
268
|
-
this.logger.info(
|
|
269
|
+
this.logger.info(`ping session: ${session.sessionId}`);
|
|
269
270
|
try {
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
271
|
+
const {
|
|
272
|
+
data: {
|
|
273
|
+
interval
|
|
274
|
+
}
|
|
275
|
+
} = await this._api.updatePeerSession({
|
|
276
|
+
userId: this._userId,
|
|
277
|
+
sessionId: session.sessionId,
|
|
278
|
+
sessionKey: session.sessionKey,
|
|
279
|
+
duration: params.duration,
|
|
280
|
+
payload: session.payload,
|
|
281
|
+
targetId: params.receiverId,
|
|
282
|
+
keepAlive: params.keepAlive,
|
|
283
|
+
action: params.action
|
|
284
|
+
});
|
|
281
285
|
const nextTs = Date.now() + interval;
|
|
282
286
|
if (this._scheduleMap.has(session.sessionId)) {
|
|
283
|
-
this._scheduleMap.set(session.sessionId,
|
|
287
|
+
this._scheduleMap.set(session.sessionId, {
|
|
288
|
+
...params,
|
|
284
289
|
nextTs
|
|
285
|
-
})
|
|
286
|
-
this.logger.info(
|
|
290
|
+
});
|
|
291
|
+
this.logger.info(`[PeerSession] refresh session schedule: ${session.sessionId}, next ts: ${nextTs}`);
|
|
287
292
|
}
|
|
288
293
|
} catch (e) {
|
|
289
|
-
this.logger.error(
|
|
294
|
+
this.logger.error(`ping session failed: ${e}`);
|
|
290
295
|
}
|
|
291
296
|
}
|
|
292
297
|
}
|
|
@@ -294,7 +299,7 @@ class FcrPeerSessionControlImpl {
|
|
|
294
299
|
for (const key of this._receivedMap.keys()) {
|
|
295
300
|
const session = this._receivedMap.get(key);
|
|
296
301
|
if (this._isSessionExpired(session)) {
|
|
297
|
-
this.logger.info(
|
|
302
|
+
this.logger.info(`peer session expired, removed: ${key}`);
|
|
298
303
|
if (session.keepAlive) {
|
|
299
304
|
await this.endPeerSession(key);
|
|
300
305
|
}
|
|
@@ -306,21 +311,23 @@ class FcrPeerSessionControlImpl {
|
|
|
306
311
|
// 如果会话是keepAlive的,并且距离上次ping的时间超过2倍interval,则认为会话已过期(可能因为对方或己方已经掉线),需要结束会话
|
|
307
312
|
if (session.keepAlive && session.nextTs + session.interval * KEEPALIVE_TIMEOUT_MULTIPLIER < Date.now()) {
|
|
308
313
|
await this.endPeerSession(key);
|
|
309
|
-
this.logger.info(
|
|
314
|
+
this.logger.info(`peer session has not been pinged, removed: ${key}`);
|
|
310
315
|
}
|
|
311
316
|
}
|
|
312
317
|
}
|
|
313
318
|
|
|
314
319
|
//@internal
|
|
315
320
|
async _handlePeerMessage(message) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
payload
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
const {
|
|
322
|
+
senderId,
|
|
323
|
+
payload
|
|
324
|
+
} = message;
|
|
325
|
+
const {
|
|
326
|
+
data,
|
|
327
|
+
cmd
|
|
328
|
+
} = payload;
|
|
329
|
+
const logContext = `cmd=${cmd}, sessionKey=${data.sessionKey}, sessionId=${data.sessionUuid}, ` + `action=${String(data.action)}, senderId=${senderId}, keepAlive=${!!data.keepAlive}`;
|
|
330
|
+
this.logger.info(`[PeerSession] received peer message: ${logContext}, payload=${JSON.stringify(data.payload ?? {})}`);
|
|
324
331
|
if (cmd === '1001') {
|
|
325
332
|
const session = {
|
|
326
333
|
sessionId: data.sessionUuid,
|
|
@@ -340,52 +347,53 @@ class FcrPeerSessionControlImpl {
|
|
|
340
347
|
if (!this._isSessionExpired(session)) {
|
|
341
348
|
if (data.action === 1) {
|
|
342
349
|
if (this._scheduleMap.has(session.sessionId)) {
|
|
343
|
-
var _session$payload, _ref3, _data$payload2;
|
|
344
350
|
const sessionResponse = {
|
|
345
351
|
sessionId: session.sessionId,
|
|
346
352
|
sessionKey: session.sessionKey,
|
|
347
353
|
responderId: senderId,
|
|
348
|
-
payload:
|
|
349
|
-
cause:
|
|
354
|
+
payload: session.payload ?? {},
|
|
355
|
+
cause: data.payload?.cause ?? {},
|
|
350
356
|
keepAlive: !!session.keepAlive
|
|
351
357
|
};
|
|
352
358
|
const params = this._scheduleMap.get(session.sessionId);
|
|
353
|
-
this._scheduleMap.set(session.sessionId,
|
|
359
|
+
this._scheduleMap.set(session.sessionId, {
|
|
360
|
+
...params,
|
|
354
361
|
action: 1
|
|
355
|
-
})
|
|
356
|
-
this.logger.info(
|
|
362
|
+
});
|
|
363
|
+
this.logger.info(`[PeerSession] forward peer session accepted to observers: ${logContext}`);
|
|
357
364
|
this._observable.notifyObservers('onPeerSessionAccepted', sessionResponse);
|
|
358
365
|
} else {
|
|
359
|
-
this.logger.info(
|
|
366
|
+
this.logger.info(`[PeerSession] ignore peer session accepted without local schedule: ${logContext}`);
|
|
360
367
|
}
|
|
361
368
|
if (this._receivedMap.has(session.sessionId)) {
|
|
362
|
-
this._receivedMap.set(session.sessionId,
|
|
369
|
+
this._receivedMap.set(session.sessionId, {
|
|
370
|
+
...session,
|
|
363
371
|
nextTs: Date.now() + data.interval,
|
|
364
372
|
startTs: Date.now(),
|
|
365
373
|
action: 1
|
|
366
|
-
})
|
|
374
|
+
});
|
|
367
375
|
}
|
|
368
376
|
return;
|
|
369
377
|
} else {
|
|
370
378
|
if (!this._receivedMap.has(session.sessionId)) {
|
|
371
|
-
this.logger.info(
|
|
379
|
+
this.logger.info(`[PeerSession] forward peer session request to observers: ${logContext}`);
|
|
372
380
|
this._observable.notifyObservers('onPeerSessionReceived', session);
|
|
373
381
|
} else {
|
|
374
|
-
this.logger.info(
|
|
382
|
+
this.logger.info(`[PeerSession] peer session request already cached, update cache only: ${logContext}`);
|
|
375
383
|
}
|
|
376
|
-
this._receivedMap.set(session.sessionId,
|
|
384
|
+
this._receivedMap.set(session.sessionId, {
|
|
385
|
+
...session,
|
|
377
386
|
nextTs: Date.now() + data.interval,
|
|
378
387
|
startTs: Date.now(),
|
|
379
388
|
action: 0
|
|
380
|
-
})
|
|
389
|
+
});
|
|
381
390
|
}
|
|
382
391
|
} else {
|
|
383
|
-
this.logger.info(
|
|
392
|
+
this.logger.info(`[PeerSession] ignore expired peer session message: ${logContext}, ` + `timestamp=${session.timestamp}, duration=${session.duration}`);
|
|
384
393
|
}
|
|
385
394
|
} else if (cmd === '1002') {
|
|
386
395
|
if (data.action === 1) {
|
|
387
396
|
if (this._scheduleMap.has(data.sessionUuid)) {
|
|
388
|
-
var _session$payload2, _ref4, _data$payload3;
|
|
389
397
|
const session = this._scheduleMap.get(data.sessionUuid);
|
|
390
398
|
const sessionResponse = {
|
|
391
399
|
sessionId: data.sessionUuid,
|
|
@@ -393,19 +401,18 @@ class FcrPeerSessionControlImpl {
|
|
|
393
401
|
responderId: senderId,
|
|
394
402
|
// FIXME: session may be lost when the client refreshes
|
|
395
403
|
// get payload from original session
|
|
396
|
-
payload:
|
|
397
|
-
cause:
|
|
404
|
+
payload: session.payload ?? {},
|
|
405
|
+
cause: data.payload?.cause ?? {},
|
|
398
406
|
keepAlive: !!data.keepAlive
|
|
399
407
|
};
|
|
400
408
|
this._scheduleMap.delete(data.sessionUuid);
|
|
401
|
-
this.logger.info(
|
|
409
|
+
this.logger.info(`[PeerSession] forward peer session accepted to observers: ${logContext}`);
|
|
402
410
|
this._observable.notifyObservers('onPeerSessionAccepted', sessionResponse);
|
|
403
411
|
} else {
|
|
404
|
-
this.logger.info(
|
|
412
|
+
this.logger.info(`[PeerSession] ignore peer session accepted without local schedule: ${logContext}`);
|
|
405
413
|
}
|
|
406
414
|
} else if (data.action === 2) {
|
|
407
415
|
if (this._scheduleMap.has(data.sessionUuid)) {
|
|
408
|
-
var _session$payload3, _ref5, _data$payload4;
|
|
409
416
|
const session = this._scheduleMap.get(data.sessionUuid);
|
|
410
417
|
const sessionResponse = {
|
|
411
418
|
sessionId: data.sessionUuid,
|
|
@@ -413,28 +420,27 @@ class FcrPeerSessionControlImpl {
|
|
|
413
420
|
responderId: senderId,
|
|
414
421
|
// FIXME: session may be lost when the client refreshes
|
|
415
422
|
// get payload from original session
|
|
416
|
-
payload:
|
|
417
|
-
cause:
|
|
423
|
+
payload: session.payload ?? {},
|
|
424
|
+
cause: data.payload?.cause ?? {},
|
|
418
425
|
keepAlive: !!data.keepAlive
|
|
419
426
|
};
|
|
420
427
|
if (this._scheduleMap.has(data.sessionUuid)) {
|
|
421
428
|
this._scheduleMap.delete(data.sessionUuid);
|
|
422
|
-
this.logger.info(
|
|
429
|
+
this.logger.info(`[PeerSession] forward peer session rejected to observers: ${logContext}`);
|
|
423
430
|
this._observable.notifyObservers('onPeerSessionRejected', sessionResponse);
|
|
424
431
|
}
|
|
425
432
|
} else {
|
|
426
|
-
this.logger.info(
|
|
433
|
+
this.logger.info(`[PeerSession] ignore peer session rejected without local schedule: ${logContext}`);
|
|
427
434
|
}
|
|
428
435
|
} else if (data.action === 3) {
|
|
429
436
|
const scheduleSession = this._scheduleMap.get(data.sessionUuid);
|
|
430
437
|
const receivedSession = this._receivedMap.get(data.sessionUuid);
|
|
431
438
|
const session = scheduleSession || receivedSession;
|
|
432
439
|
if (session) {
|
|
433
|
-
var _ref6, _data$payload5;
|
|
434
440
|
const params = {
|
|
435
441
|
sessionId: data.sessionUuid,
|
|
436
442
|
fromUserId: senderId,
|
|
437
|
-
cause:
|
|
443
|
+
cause: data.payload?.cause ?? {}
|
|
438
444
|
};
|
|
439
445
|
if (scheduleSession) {
|
|
440
446
|
this._scheduleMap.delete(data.sessionUuid);
|
|
@@ -443,15 +449,15 @@ class FcrPeerSessionControlImpl {
|
|
|
443
449
|
this._receivedMap.delete(data.sessionUuid);
|
|
444
450
|
}
|
|
445
451
|
this._observable.notifyObservers('onPeerSessionEnded', params.sessionId, params.fromUserId, params.cause);
|
|
446
|
-
this.logger.info(
|
|
452
|
+
this.logger.info(`[PeerSession] forward peer session ended to observers: ${logContext}`);
|
|
447
453
|
} else {
|
|
448
|
-
this.logger.info(
|
|
454
|
+
this.logger.info(`[PeerSession] ignore peer session ended without cached session: ${logContext}`);
|
|
449
455
|
}
|
|
450
456
|
} else {
|
|
451
|
-
this.logger.info(
|
|
457
|
+
this.logger.info(`[PeerSession] ignore peer session response with unknown action: ${logContext}`);
|
|
452
458
|
}
|
|
453
459
|
} else {
|
|
454
|
-
this.logger.info(
|
|
460
|
+
this.logger.info(`[PeerSession] ignore unsupported peer session cmd: ${logContext}`);
|
|
455
461
|
}
|
|
456
462
|
}
|
|
457
463
|
|
|
@@ -463,9 +469,4 @@ class FcrPeerSessionControlImpl {
|
|
|
463
469
|
this.addObserver((0, _logger.generateLogObserver)(this.logger, [['onPeerSessionAccepted', ['session']], ['onPeerSessionReceived', ['session']], ['onPeerSessionRejected', ['session']], ['onPeerSessionEnded', ['sessionId', 'fromUserId', 'reason']]]));
|
|
464
470
|
}
|
|
465
471
|
}
|
|
466
|
-
exports.FcrPeerSessionControlImpl = FcrPeerSessionControlImpl;
|
|
467
|
-
_FcrPeerSessionControlImpl = FcrPeerSessionControlImpl;
|
|
468
|
-
var _applyDecs$e = _applyDecs(_FcrPeerSessionControlImpl, [[_startPeerSessionDecs, 2, "startPeerSession"], [_stopPeerSessionDecs, 2, "stopPeerSession"], [_endPeerSessionDecs, 2, "endPeerSession"], [_acceptPeerSessionDecs, 2, "acceptPeerSession"], [_rejectPeerSessionDecs, 2, "rejectPeerSession"], [_imports.trace, 2, "release"]], []).e;
|
|
469
|
-
var _applyDecs$e2 = (0, _slicedToArray2.default)(_applyDecs$e, 1);
|
|
470
|
-
_initProto = _applyDecs$e2[0];
|
|
471
|
-
_applyDecs$e;
|
|
472
|
+
exports.FcrPeerSessionControlImpl = FcrPeerSessionControlImpl;
|