fcr-core 3.8.1 → 3.9.0-alpha
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/chat-connector/type.d.ts +40 -0
- package/lib/{chat-connection → chat-connector}/type.js +1 -1
- package/lib/engine/index.d.ts +10 -11
- package/lib/engine/index.js +63 -72
- package/lib/engine/type.d.ts +96 -0
- package/lib/engine/type.js +5 -0
- package/lib/imports.d.ts +7 -4
- package/lib/imports.js +30 -4
- package/lib/index.d.ts +3 -2
- package/lib/index.js +21 -2
- package/lib/media-control/desktop.js +12 -12
- package/lib/media-control/mobile.js +4 -0
- package/lib/media-control/type.d.ts +32 -33
- package/lib/monitor-control/index.js +3 -3
- package/lib/peer-session/index.js +14 -14
- package/lib/peer-session/type.d.ts +1 -1
- package/lib/plugins/chat/chatroom.js +417 -0
- package/lib/{chat-connection → plugins/chat}/config.d.ts +1 -0
- package/lib/{room-control/chatroom-control → plugins/chat}/config.js +2 -1
- package/lib/plugins/chat/connector.d.ts +38 -0
- package/lib/{chat-connection/index.js → plugins/chat/connector.js} +181 -61
- package/lib/room-control/ability-control/index.js +5 -4
- package/lib/room-control/ability-control/type.d.ts +5 -1
- package/lib/room-control/ability-control/type.js +4 -0
- package/lib/room-control/chatroom-control/type.d.ts +44 -35
- package/lib/room-control/group-control/index.js +9 -9
- package/lib/room-control/index.js +37 -22
- package/lib/room-control/interpreter-control/index.js +7 -4
- package/lib/room-control/interpreter-control/room.js +3 -3
- package/lib/room-control/interpreter-control/types.d.ts +2 -2
- package/lib/room-control/join-before-host-waitingroom-control/index.js +3 -3
- package/lib/room-control/mainroom-control/index.js +15 -13
- package/lib/room-control/privilege-control/index.js +39 -24
- package/lib/room-control/privilege-control/type.d.ts +15 -15
- package/lib/room-control/room-connector-control/index.js +7 -5
- package/lib/room-control/room-connector-control/type.d.ts +1 -1
- package/lib/room-control/room-control-factory.d.ts +3 -3
- package/lib/room-control/room-control-factory.js +7 -7
- package/lib/room-control/room-session/index.js +17 -15
- package/lib/room-control/room-session/type.d.ts +3 -3
- package/lib/room-control/sharing-control/index.js +13 -7
- package/lib/room-control/stream-control/index.js +18 -16
- package/lib/room-control/stream-control/type.d.ts +5 -5
- package/lib/room-control/stt-control/index.js +38 -31
- package/lib/room-control/type.d.ts +19 -19
- package/lib/room-control/user-control/index.js +20 -22
- package/lib/room-control/user-control/type.d.ts +1 -1
- package/lib/room-control/waitingroom-control/index.js +11 -11
- package/lib/room-control/whiteboard-control-v1/board-window.d.ts +21 -20
- package/lib/room-control/whiteboard-control-v1/board-window.js +27 -8
- package/lib/room-control/whiteboard-control-v1/factory.js +1 -1
- package/lib/room-control/whiteboard-control-v1/index.js +26 -18
- package/lib/room-control/whiteboard-control-v1/type.d.ts +26 -25
- package/lib/room-control/whiteboard-control-v1/type.js +1 -0
- package/lib/room-control/whiteboard-control-v2/annotation-control/control.d.ts +15 -6
- package/lib/room-control/whiteboard-control-v2/annotation-control/control.js +39 -5
- package/lib/room-control/whiteboard-control-v2/annotation-control/factory.d.ts +4 -5
- package/lib/room-control/whiteboard-control-v2/annotation-control/factory.js +6 -5
- package/lib/room-control/whiteboard-control-v2/annotation-control/type.d.ts +7 -1
- package/lib/room-control/whiteboard-control-v2/base/index.d.ts +9 -8
- package/lib/room-control/whiteboard-control-v2/base/index.js +84 -42
- package/lib/room-control/whiteboard-control-v2/base/main-window.d.ts +16 -15
- package/lib/room-control/whiteboard-control-v2/base/main-window.js +23 -4
- package/lib/room-control/whiteboard-control-v2/type.d.ts +17 -17
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/control.d.ts +12 -6
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/control.js +64 -18
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/factory.d.ts +2 -2
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/factory.js +10 -10
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/type.d.ts +1 -1
- package/lib/room-router/index.js +10 -7
- package/lib/room-router/type.d.ts +1 -1
- package/lib/schema.d.ts +24 -46
- package/lib/schema.js +1 -2
- package/lib/service/api.d.ts +5 -3
- package/lib/service/api.js +17 -12
- package/lib/type.d.ts +64 -45
- package/lib/type.js +76 -11
- package/lib/utilities/abortable-retry.d.ts +38 -0
- package/lib/utilities/abortable-retry.js +61 -0
- package/lib/utilities/dual-video-stream-config.d.ts +6 -0
- package/lib/utilities/dual-video-stream-config.js +25 -0
- package/lib/utilities/error-helpers.d.ts +10 -9
- package/lib/utilities/error-helpers.js +12 -11
- package/lib/utilities/error.d.ts +4 -40
- package/lib/utilities/error.js +20 -77
- package/lib/utilities/join-helper.js +2 -2
- package/lib/utilities/logger.d.ts +2 -2
- package/lib/utilities/logger.js +6 -25
- package/lib/utilities/package-info.d.ts +1 -2
- package/lib/utilities/package-info.js +4 -8
- package/lib/utilities/parameters.js +88 -15
- package/lib/utilities/validate-params.js +1 -1
- package/lib/utilities/video-encoder-config.d.ts +9 -0
- package/lib/utilities/video-encoder-config.js +109 -0
- package/lib-es/base-session.js +1 -0
- package/lib-es/chat-connector/type.js +6 -0
- package/lib-es/engine/index.js +412 -0
- package/lib-es/engine/type.js +1 -0
- package/lib-es/imports.js +59 -0
- package/lib-es/index.js +8 -0
- package/lib-es/media-control/desktop.js +172 -0
- package/lib-es/media-control/mobile.js +198 -0
- package/lib-es/media-control/type.js +6 -0
- package/lib-es/monitor-control/index.js +46 -0
- package/lib-es/monitor-control/type.js +1 -0
- package/lib-es/peer-session/index.js +279 -0
- package/lib-es/peer-session/type.js +1 -0
- package/lib-es/plugins/chat/chatroom.js +409 -0
- package/{lib/chat-connection → lib-es/plugins/chat}/config.js +5 -9
- package/lib-es/plugins/chat/connector.js +269 -0
- package/lib-es/plugins/electron-rtc-plugin.js +1 -0
- package/lib-es/plugins/rtm-plugin.js +1 -0
- package/lib-es/plugins/web-rtc-plugin.js +1 -0
- package/lib-es/room-control/ability-control/index.js +58 -0
- package/lib-es/room-control/ability-control/type.js +15 -0
- package/lib-es/room-control/chatroom-control/type.js +12 -0
- package/lib-es/room-control/group-control/index.js +256 -0
- package/lib-es/room-control/helpers/constants.js +92 -0
- package/lib-es/room-control/helpers/index.js +20 -0
- package/lib-es/room-control/helpers/validation-helper.js +46 -0
- package/lib-es/room-control/index.js +623 -0
- package/lib-es/room-control/interpreter-control/index.js +172 -0
- package/lib-es/room-control/interpreter-control/room.js +28 -0
- package/lib-es/room-control/interpreter-control/types.js +26 -0
- package/lib-es/room-control/join-before-host-waitingroom-control/index.js +29 -0
- package/lib-es/room-control/mainroom-control/index.js +248 -0
- package/lib-es/room-control/privilege-control/helper.js +97 -0
- package/lib-es/room-control/privilege-control/index.js +339 -0
- package/lib-es/room-control/privilege-control/type.js +159 -0
- package/lib-es/room-control/room-connector-control/index.js +182 -0
- package/lib-es/room-control/room-connector-control/type.js +28 -0
- package/lib-es/room-control/room-control-factory.js +77 -0
- package/lib-es/room-control/room-session/index.js +292 -0
- package/lib-es/room-control/room-session/type.js +1 -0
- package/lib-es/room-control/shared-cache.js +47 -0
- package/lib-es/room-control/sharing-control/index.js +307 -0
- package/lib-es/room-control/sharing-control/type.js +16 -0
- package/lib-es/room-control/stream-control/index.js +536 -0
- package/lib-es/room-control/stream-control/type.js +1 -0
- package/lib-es/room-control/stt-control/de-compress-gzip.js +33 -0
- package/lib-es/room-control/stt-control/index.js +350 -0
- package/lib-es/room-control/stt-control/type.js +10 -0
- package/lib-es/room-control/type.js +30 -0
- package/lib-es/room-control/user-control/index.js +344 -0
- package/lib-es/room-control/user-control/type.js +21 -0
- package/lib-es/room-control/waitingroom-control/index.js +68 -0
- package/lib-es/room-control/whiteboard-control/enum.js +18 -0
- package/lib-es/room-control/whiteboard-control/type.js +10 -0
- package/lib-es/room-control/whiteboard-control/utils.js +13 -0
- package/lib-es/room-control/whiteboard-control-v1/board-subwindow.js +18 -0
- package/lib-es/room-control/whiteboard-control-v1/board-window.js +573 -0
- package/lib-es/room-control/whiteboard-control-v1/enum.js +157 -0
- package/lib-es/room-control/whiteboard-control-v1/factory.js +12 -0
- package/lib-es/room-control/whiteboard-control-v1/index.js +427 -0
- package/lib-es/room-control/whiteboard-control-v1/mount-manager.js +6 -0
- package/lib-es/room-control/whiteboard-control-v1/type.js +8 -0
- package/lib-es/room-control/whiteboard-control-v1/utils.js +273 -0
- package/lib-es/room-control/whiteboard-control-v2/annotation-control/control.js +76 -0
- package/lib-es/room-control/whiteboard-control-v2/annotation-control/factory.js +37 -0
- package/lib-es/room-control/whiteboard-control-v2/annotation-control/type.js +1 -0
- package/lib-es/room-control/whiteboard-control-v2/base/index.js +347 -0
- package/lib-es/room-control/whiteboard-control-v2/base/main-window.js +269 -0
- package/lib-es/room-control/whiteboard-control-v2/constant.js +9 -0
- package/lib-es/room-control/whiteboard-control-v2/enum.js +28 -0
- package/lib-es/room-control/whiteboard-control-v2/type.js +1 -0
- package/lib-es/room-control/whiteboard-control-v2/utils.js +92 -0
- package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/control.js +204 -0
- package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/factory.js +61 -0
- package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/type.js +1 -0
- package/lib-es/room-router/index.js +263 -0
- package/lib-es/room-router/type.js +5 -0
- package/lib-es/schema.js +231 -0
- package/lib-es/service/api.js +1211 -0
- package/lib-es/service/type.js +1 -0
- package/lib-es/type.js +222 -0
- package/lib-es/utilities/abortable-retry.js +54 -0
- package/lib-es/utilities/cmd.js +1 -0
- package/lib-es/utilities/collection.js +64 -0
- package/lib-es/utilities/dual-video-stream-config.js +19 -0
- package/lib-es/utilities/error-helpers.js +224 -0
- package/lib-es/utilities/error.js +43 -0
- package/lib-es/utilities/join-helper.js +219 -0
- package/lib-es/utilities/logger.js +7 -0
- package/lib-es/utilities/package-info.js +5 -0
- package/lib-es/utilities/parameters.js +106 -0
- package/lib-es/utilities/retry-helpers.js +66 -0
- package/lib-es/utilities/shared-storage.js +31 -0
- package/lib-es/utilities/stream.js +18 -0
- package/lib-es/utilities/user.js +30 -0
- package/lib-es/utilities/validate-params.js +8 -0
- package/lib-es/utilities/video-encoder-config.js +103 -0
- package/package.json +11 -10
- package/lib/chat-connection/index.d.ts +0 -24
- package/lib/chat-connection/type.d.ts +0 -17
- package/lib/plugins/chatroom.js +0 -454
- package/lib/room-control/chatroom-control/config.d.ts +0 -51
- package/lib/utilities/storage.d.ts +0 -8
- package/lib/utilities/storage.js +0 -33
- /package/lib/plugins/{chatroom.d.ts → chat/chatroom.d.ts} +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { FcrBoardToolType } from './enum';
|
|
2
|
+
import { jsonstring, get } from '../../imports';
|
|
3
|
+
export function convertToForgeBoardTool(type) {
|
|
4
|
+
switch (type) {
|
|
5
|
+
case FcrBoardToolType.ARROW:
|
|
6
|
+
return 'arrow';
|
|
7
|
+
case FcrBoardToolType.CURVE:
|
|
8
|
+
return 'curve';
|
|
9
|
+
case FcrBoardToolType.ELLIPSE:
|
|
10
|
+
return 'ellipse';
|
|
11
|
+
case FcrBoardToolType.ERASER:
|
|
12
|
+
return 'eraser';
|
|
13
|
+
case FcrBoardToolType.LASER_POINTER:
|
|
14
|
+
return 'laser';
|
|
15
|
+
case FcrBoardToolType.TEXT:
|
|
16
|
+
return 'text';
|
|
17
|
+
case FcrBoardToolType.RECTANGLE:
|
|
18
|
+
return 'rectangle';
|
|
19
|
+
case FcrBoardToolType.TRIANGLE:
|
|
20
|
+
return 'triangle';
|
|
21
|
+
case FcrBoardToolType.SELECTOR:
|
|
22
|
+
return 'selector';
|
|
23
|
+
case FcrBoardToolType.STRAIGHT:
|
|
24
|
+
return 'line';
|
|
25
|
+
// case FcrBoardToolType.PENTAGRAM:
|
|
26
|
+
// return 'pentagram';
|
|
27
|
+
// case FcrBoardToolType.RHOMBUS:
|
|
28
|
+
// return 'rhombus';
|
|
29
|
+
case FcrBoardToolType.HAND:
|
|
30
|
+
return 'grab';
|
|
31
|
+
default:
|
|
32
|
+
return 'curve';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export const getAnnotationConfigFromRoomProperties = (properties, logger) => {
|
|
36
|
+
const boardAppId = get(properties, 'widgets.annotation.extra.boardAppId');
|
|
37
|
+
const boardId = get(properties, 'widgets.annotation.extra.boardId');
|
|
38
|
+
const boardToken = get(properties, 'widgets.annotation.extra.boardToken');
|
|
39
|
+
const boardRegion = get(properties, 'widgets.annotation.extra.boardRegion');
|
|
40
|
+
let width = get(properties, 'widgets.annotation.size.width');
|
|
41
|
+
let height = get(properties, 'widgets.annotation.size.height');
|
|
42
|
+
if (typeof width !== 'number') {
|
|
43
|
+
logger.warn(`got invalid width for annotation board, width: ${width}`);
|
|
44
|
+
width = 0;
|
|
45
|
+
}
|
|
46
|
+
if (typeof height !== 'number') {
|
|
47
|
+
logger.warn(`got invalid height for annotation board, height: ${height}`);
|
|
48
|
+
height = 0;
|
|
49
|
+
}
|
|
50
|
+
const boardWidthVal = width;
|
|
51
|
+
const boardHeightVal = height;
|
|
52
|
+
let boardWidth = 0;
|
|
53
|
+
let boardHeight = 0;
|
|
54
|
+
if (boardWidthVal !== 0 && boardHeightVal !== 0) {
|
|
55
|
+
({
|
|
56
|
+
width: boardWidth,
|
|
57
|
+
height: boardHeight
|
|
58
|
+
} = resizeToMax(boardWidthVal, boardHeightVal, FCR_ANNOTATION_SCALE_BASE));
|
|
59
|
+
} else {
|
|
60
|
+
logger.warn(`got invalid width or height for annotation board, skip resizing, width: ${boardWidthVal}, height: ${boardHeightVal}`);
|
|
61
|
+
}
|
|
62
|
+
logger.info(`got board config info, ${jsonstring({
|
|
63
|
+
boardAppId,
|
|
64
|
+
boardId,
|
|
65
|
+
boardToken,
|
|
66
|
+
boardRegion,
|
|
67
|
+
boardWidth,
|
|
68
|
+
boardHeight
|
|
69
|
+
})}`);
|
|
70
|
+
return {
|
|
71
|
+
size: {
|
|
72
|
+
width: boardWidth,
|
|
73
|
+
height: boardHeight
|
|
74
|
+
},
|
|
75
|
+
extra: {
|
|
76
|
+
boardAppId,
|
|
77
|
+
boardId,
|
|
78
|
+
boardToken,
|
|
79
|
+
region: boardRegion
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
export const resizeToMax = (w, h, scaleBase = FCR_ANNOTATION_SCALE_BASE) => {
|
|
84
|
+
const scale = scaleBase / Math.max(w, h);
|
|
85
|
+
return {
|
|
86
|
+
width: Math.round(w * scale),
|
|
87
|
+
height: Math.round(h * scale)
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const FCR_ANNOTATION_SCALE_BASE = 1920;
|
|
91
|
+
export const WHITEBOARD_WIDTH = 1920;
|
|
92
|
+
export const WHITEBOARD_HEIGHT = 1080;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import "core-js/modules/es.array.push.js";
|
|
2
|
+
import "core-js/modules/esnext.function.metadata.js";
|
|
3
|
+
import "core-js/modules/esnext.map.delete-all.js";
|
|
4
|
+
import "core-js/modules/esnext.map.emplace.js";
|
|
5
|
+
import "core-js/modules/esnext.map.every.js";
|
|
6
|
+
import "core-js/modules/esnext.map.filter.js";
|
|
7
|
+
import "core-js/modules/esnext.map.find.js";
|
|
8
|
+
import "core-js/modules/esnext.map.find-key.js";
|
|
9
|
+
import "core-js/modules/esnext.map.includes.js";
|
|
10
|
+
import "core-js/modules/esnext.map.key-of.js";
|
|
11
|
+
import "core-js/modules/esnext.map.map-keys.js";
|
|
12
|
+
import "core-js/modules/esnext.map.map-values.js";
|
|
13
|
+
import "core-js/modules/esnext.map.merge.js";
|
|
14
|
+
import "core-js/modules/esnext.map.reduce.js";
|
|
15
|
+
import "core-js/modules/esnext.map.some.js";
|
|
16
|
+
import "core-js/modules/esnext.map.update.js";
|
|
17
|
+
import "core-js/modules/esnext.symbol.metadata.js";
|
|
18
|
+
var _ref, _ref2;
|
|
19
|
+
let _initProto, _setBackgroundColorDecs, _initProto2;
|
|
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)]; } }; }
|
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
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); }
|
|
23
|
+
function _setFunctionName(e, t, n) { "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : ""); try { Object.defineProperty(e, "name", { configurable: !0, value: n ? n + " " + t : t }); } catch (e) {} return e; }
|
|
24
|
+
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); return e; }
|
|
25
|
+
import { ErrorModuleCode } from '../../../imports';
|
|
26
|
+
import { bound, get, trace } from '../../../imports';
|
|
27
|
+
import { stringSchema } from '../../../schema';
|
|
28
|
+
import { FcrReturnCode } from '../../../type';
|
|
29
|
+
import { handleRequestError } from '../../../utilities/error';
|
|
30
|
+
import { createLogger, generateLogObserver } from '../../../utilities/logger';
|
|
31
|
+
import { getDependenciesInfo } from '../../../utilities/package-info';
|
|
32
|
+
import { convertRteUserToFcrUser } from '../../../utilities/user';
|
|
33
|
+
import validateParams from '../../../utilities/validate-params';
|
|
34
|
+
import { FcrSharePermissionState } from '../../sharing-control/type';
|
|
35
|
+
import { FcrBoardPropertiesState } from '../../whiteboard-control/type';
|
|
36
|
+
import { FcrBaseWhiteboardControlImpl } from '../base';
|
|
37
|
+
import { WHITEBOARD_APP_ID } from '../constant';
|
|
38
|
+
import { WHITEBOARD_HEIGHT, WHITEBOARD_WIDTH } from '../utils';
|
|
39
|
+
export class FcrWhiteboardControlImpl extends (_ref = FcrBaseWhiteboardControlImpl) {
|
|
40
|
+
static {
|
|
41
|
+
[_initProto] = _applyDecs(this, [[trace, 2, "open"], [trace, 2, "close"], [trace, 2, "active"], [trace, 2, "inactive"], [_setBackgroundColorDecs, 2, "setBackgroundColor"], [trace, 2, "getBackgroundColor"], [trace, 2, "getActivity"], [trace, 2, "getOwnerId"], [bound, 2, "_onScenePropertiesUpdated"]], [], 0, void 0, _ref).e;
|
|
42
|
+
}
|
|
43
|
+
[(_setBackgroundColorDecs = [trace(['backgroundColor']), validateParams(stringSchema)], "logger")] = (_initProto(this), createLogger({
|
|
44
|
+
prefix: 'FcrWhiteboardControlImpl'
|
|
45
|
+
}));
|
|
46
|
+
_backgroundColor = '#ffffff';
|
|
47
|
+
_isActive = false;
|
|
48
|
+
_ownerId = null;
|
|
49
|
+
_preloadLock = false;
|
|
50
|
+
_notifyObservers = {
|
|
51
|
+
onScenePropertiesUpdated: this._onScenePropertiesUpdated
|
|
52
|
+
};
|
|
53
|
+
constructor(rtmClient, config, hasOperationPrivilege, sharedCache, forgeInitConfigFetcher, _scene, _api) {
|
|
54
|
+
super(rtmClient, config, hasOperationPrivilege, forgeInitConfigFetcher);
|
|
55
|
+
this._scene = _scene;
|
|
56
|
+
this._api = _api;
|
|
57
|
+
this._roomCache = sharedCache.getRoomCache(config.roomId);
|
|
58
|
+
this._scene.addObserver(this._notifyObservers);
|
|
59
|
+
this.logger.info(`Whitebaord Version: forge-whiteboard@${getDependenciesInfo('@netless/forge-whiteboard')}, forge-room@${getDependenciesInfo('@netless/forge-room')}, forge-room@${getDependenciesInfo('@netless/forge-rtm')}`);
|
|
60
|
+
this._isActive = this._scene.getScenePropertiesByKeyPath('widgets.netlessBoard').state === 1;
|
|
61
|
+
const backgroundColor = this._scene.getScenePropertiesByKeyPath('widgets.netlessBoard.extra.backgroundColor');
|
|
62
|
+
if (backgroundColor) {
|
|
63
|
+
this._backgroundColor = backgroundColor;
|
|
64
|
+
}
|
|
65
|
+
const ownerId = this._scene.getScenePropertiesByKeyPath('widgets.netlessBoard.ownerUserUuid');
|
|
66
|
+
if (ownerId) {
|
|
67
|
+
this._ownerId = ownerId;
|
|
68
|
+
}
|
|
69
|
+
this.logger.info(`initialized, hasOperationPrivilege: ${hasOperationPrivilege}`);
|
|
70
|
+
}
|
|
71
|
+
async open() {
|
|
72
|
+
const boardActiveInfo = this.getBoardActiveInfo();
|
|
73
|
+
if (!boardActiveInfo.isActive) {
|
|
74
|
+
await handleRequestError(() => this._api.toggleWhiteboardPreloadState(this.config.roomId, FcrSharePermissionState.ON), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'lock failed when open whiteboard');
|
|
75
|
+
|
|
76
|
+
// 标记白板锁状态, 关闭白板时判断是否需要解锁
|
|
77
|
+
this._preloadLock = true;
|
|
78
|
+
try {
|
|
79
|
+
this._isActive = true;
|
|
80
|
+
return await super.internalOpen(true);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
// 开启失败, 释放锁
|
|
83
|
+
this._preloadLock = false;
|
|
84
|
+
this._isActive = false;
|
|
85
|
+
await handleRequestError(() => this._api.toggleWhiteboardPreloadState(this.config.roomId, FcrSharePermissionState.OFF), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'unlock failed when open whiteboard');
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
return await super.internalOpen(false);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async close() {
|
|
93
|
+
const result = await super.close();
|
|
94
|
+
if (this._preloadLock) {
|
|
95
|
+
// 释放白板锁
|
|
96
|
+
await handleRequestError(() => this._api.toggleWhiteboardPreloadState(this.config.roomId, FcrSharePermissionState.OFF), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'unlock failed when close whiteboard');
|
|
97
|
+
this._preloadLock = false;
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
async active() {
|
|
102
|
+
return handleRequestError(() => this._api.toggleWhiteboardActivityState(this.config.roomId, FcrSharePermissionState.ON), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'active failed');
|
|
103
|
+
}
|
|
104
|
+
async inactive() {
|
|
105
|
+
return handleRequestError(() => this._api.toggleWhiteboardActivityState(this.config.roomId, FcrSharePermissionState.OFF), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'inactive failed');
|
|
106
|
+
}
|
|
107
|
+
getBoardActiveInfo() {
|
|
108
|
+
const {
|
|
109
|
+
state,
|
|
110
|
+
ownerUserUuid: ownerUserId
|
|
111
|
+
} = this._scene.getScenePropertiesByKeyPath('widgets.netlessBoard');
|
|
112
|
+
if (state === FcrBoardPropertiesState.ACTIVE) {
|
|
113
|
+
return {
|
|
114
|
+
isActive: true,
|
|
115
|
+
ownerUserId
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
return {
|
|
119
|
+
isActive: false,
|
|
120
|
+
ownerUserId: null
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async setBackgroundColor(backgroundColor) {
|
|
125
|
+
await this._api.setBackgroundColor({
|
|
126
|
+
roomId: this.config.roomId,
|
|
127
|
+
backgroundColor
|
|
128
|
+
});
|
|
129
|
+
this._backgroundColor = backgroundColor;
|
|
130
|
+
if (this.boardView) {
|
|
131
|
+
this.boardView.setBackgroundColor(backgroundColor);
|
|
132
|
+
}
|
|
133
|
+
return FcrReturnCode.SUCCESS;
|
|
134
|
+
}
|
|
135
|
+
getBackgroundColor() {
|
|
136
|
+
return this._backgroundColor;
|
|
137
|
+
}
|
|
138
|
+
getActivity() {
|
|
139
|
+
return this._isActive;
|
|
140
|
+
}
|
|
141
|
+
getOwnerId() {
|
|
142
|
+
return this._ownerId;
|
|
143
|
+
}
|
|
144
|
+
getApplicationId() {
|
|
145
|
+
return WHITEBOARD_APP_ID;
|
|
146
|
+
}
|
|
147
|
+
_onScenePropertiesUpdated(sceneId, event) {
|
|
148
|
+
const operatorUser = convertRteUserToFcrUser(event.operatorUser, this._roomCache);
|
|
149
|
+
const getByKeyPath = value => this._scene.getScenePropertiesByKeyPath(value);
|
|
150
|
+
if (event.cause && event.cause.cmd === 10) {
|
|
151
|
+
const state = getByKeyPath('widgets.netlessBoard.state') ?? FcrBoardPropertiesState.INACTIVE;
|
|
152
|
+
const backgroundColor = getByKeyPath('widgets.netlessBoard.extra.backgroundColor');
|
|
153
|
+
const widgetCauseReason = get(event.cause.data, 'widgetCause.data.reason');
|
|
154
|
+
const widgetCauseCmd = get(event.cause.data, 'widgetCause.cmd');
|
|
155
|
+
if (state === FcrBoardPropertiesState.ACTIVE) {
|
|
156
|
+
const ownerUserId = getByKeyPath('widgets.netlessBoard.ownerUserUuid');
|
|
157
|
+
this._ownerId = ownerUserId;
|
|
158
|
+
this._isActive = true;
|
|
159
|
+
this.observable.notifyObservers('onActive', ownerUserId, operatorUser);
|
|
160
|
+
}
|
|
161
|
+
if (state === FcrBoardPropertiesState.INACTIVE) {
|
|
162
|
+
this._ownerId = null;
|
|
163
|
+
this._isActive = false;
|
|
164
|
+
this.observable.notifyObservers('onInactive', widgetCauseReason, operatorUser);
|
|
165
|
+
}
|
|
166
|
+
if (widgetCauseCmd === FcrBoardPropertiesState.BACKGROUND_COLOR_UPDATED) {
|
|
167
|
+
this._backgroundColor = backgroundColor;
|
|
168
|
+
this.observable.notifyObservers('onBackgroundColorUpdated', backgroundColor, operatorUser);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
getWhiteboardOption() {
|
|
173
|
+
return {
|
|
174
|
+
...super.getWhiteboardOption(),
|
|
175
|
+
width: WHITEBOARD_WIDTH,
|
|
176
|
+
height: WHITEBOARD_HEIGHT
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
addLogObserver() {
|
|
180
|
+
this.addObserver(generateLogObserver(this.logger, [['onConnectionStateUpdated', ['state']], ['onActive', ['ownerId', 'operatorUser']], ['onInactive', ['reason', 'operatorUser']], ['onBackgroundColorUpdated', ['color', 'operatorUser']]]));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
export class FcrStandaloneWhiteboardControlImpl extends (_ref2 = FcrBaseWhiteboardControlImpl) {
|
|
184
|
+
static {
|
|
185
|
+
[_initProto2] = _applyDecs(this, [[trace, 2, "open"]], [], 0, void 0, _ref2).e;
|
|
186
|
+
}
|
|
187
|
+
constructor(...args) {
|
|
188
|
+
super(...args);
|
|
189
|
+
_initProto2(this);
|
|
190
|
+
}
|
|
191
|
+
async open() {
|
|
192
|
+
return await super.internalOpen(false);
|
|
193
|
+
}
|
|
194
|
+
getApplicationId() {
|
|
195
|
+
return WHITEBOARD_APP_ID;
|
|
196
|
+
}
|
|
197
|
+
getWhiteboardOption() {
|
|
198
|
+
return {
|
|
199
|
+
...super.getWhiteboardOption(),
|
|
200
|
+
width: WHITEBOARD_WIDTH,
|
|
201
|
+
height: WHITEBOARD_HEIGHT
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import "core-js/modules/es.array.push.js";
|
|
2
|
+
import "core-js/modules/esnext.function.metadata.js";
|
|
3
|
+
import "core-js/modules/esnext.map.delete-all.js";
|
|
4
|
+
import "core-js/modules/esnext.map.emplace.js";
|
|
5
|
+
import "core-js/modules/esnext.map.every.js";
|
|
6
|
+
import "core-js/modules/esnext.map.filter.js";
|
|
7
|
+
import "core-js/modules/esnext.map.find.js";
|
|
8
|
+
import "core-js/modules/esnext.map.find-key.js";
|
|
9
|
+
import "core-js/modules/esnext.map.includes.js";
|
|
10
|
+
import "core-js/modules/esnext.map.key-of.js";
|
|
11
|
+
import "core-js/modules/esnext.map.map-keys.js";
|
|
12
|
+
import "core-js/modules/esnext.map.map-values.js";
|
|
13
|
+
import "core-js/modules/esnext.map.merge.js";
|
|
14
|
+
import "core-js/modules/esnext.map.reduce.js";
|
|
15
|
+
import "core-js/modules/esnext.map.some.js";
|
|
16
|
+
import "core-js/modules/esnext.map.update.js";
|
|
17
|
+
import "core-js/modules/esnext.symbol.metadata.js";
|
|
18
|
+
let _initProto, _createForSubProcessDecs, _createForMainProcessDecs;
|
|
19
|
+
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)]; } }; }
|
|
20
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
21
|
+
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); }
|
|
22
|
+
function _setFunctionName(e, t, n) { "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : ""); try { Object.defineProperty(e, "name", { configurable: !0, value: n ? n + " " + t : t }); } catch (e) {} return e; }
|
|
23
|
+
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); return e; }
|
|
24
|
+
import { trace } from 'agora-foundation/lib/decorator/log';
|
|
25
|
+
import { DetailErrorCode, ErrorModuleCode } from 'agora-foundation/lib/utilities/error/error-code';
|
|
26
|
+
import { generateFcrCoreClientError, handleRequestError } from '../../../utilities/error';
|
|
27
|
+
import { createLogger } from '../../../utilities/logger';
|
|
28
|
+
import { getWhiteboardOptions } from '../../../utilities/shared-storage';
|
|
29
|
+
import { FcrStandaloneWhiteboardControlImpl, FcrWhiteboardControlImpl } from './control';
|
|
30
|
+
export class FcrWhiteboardControlFactoryImpl {
|
|
31
|
+
static {
|
|
32
|
+
[_initProto] = _applyDecs(this, [[_createForSubProcessDecs, 2, "createForSubProcess"], [_createForMainProcessDecs, 2, "createForMainProcess"]], []).e;
|
|
33
|
+
}
|
|
34
|
+
[(_createForSubProcessDecs = trace(['rtmClient', 'hasOperationPrivilege', 'boardConfig']), _createForMainProcessDecs = trace(['rtmClient', 'hasOperationPrivilege', 'boardConfig', 'scene', 'api', 'sharedCache']), "logger")] = (_initProto(this), createLogger({
|
|
35
|
+
prefix: 'FcrWhiteboardControlFactory'
|
|
36
|
+
}));
|
|
37
|
+
createForSubProcess(rtmClient, hasOperationPrivilege, boardConfig) {
|
|
38
|
+
return new FcrStandaloneWhiteboardControlImpl(rtmClient, boardConfig, hasOperationPrivilege, () => {
|
|
39
|
+
const forgeInitConfig = getWhiteboardOptions();
|
|
40
|
+
if (!forgeInitConfig) {
|
|
41
|
+
throw generateFcrCoreClientError(ErrorModuleCode.FCR_ROOM_WHITEBOARD, DetailErrorCode.UNDEFINED_ERROR, `whiteboard init config is not exist`, new Error(`whiteboard init config is not exist`));
|
|
42
|
+
}
|
|
43
|
+
return Promise.resolve(forgeInitConfig);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
createForMainProcess(rtmClient, hasOperationPrivilege, boardConfig, scene, api, sharedCache) {
|
|
47
|
+
return new FcrWhiteboardControlImpl(rtmClient, boardConfig, hasOperationPrivilege, sharedCache, this._createForgeInitConfigFetcher(api, boardConfig.roomId, boardConfig.userId), scene, api);
|
|
48
|
+
}
|
|
49
|
+
_createForgeInitConfigFetcher(api, roomId, userId) {
|
|
50
|
+
const getObjectInitConfig = async (roomId, userId) => {
|
|
51
|
+
return await handleRequestError(() => api.getWhiteboardToken({
|
|
52
|
+
roomId,
|
|
53
|
+
userId
|
|
54
|
+
}), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'get whiteboard token failed');
|
|
55
|
+
};
|
|
56
|
+
return async () => {
|
|
57
|
+
const response = await getObjectInitConfig(roomId, userId);
|
|
58
|
+
return response.data;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import "core-js/modules/es.array.push.js";
|
|
2
|
+
import "core-js/modules/esnext.function.metadata.js";
|
|
3
|
+
import "core-js/modules/esnext.map.delete-all.js";
|
|
4
|
+
import "core-js/modules/esnext.map.emplace.js";
|
|
5
|
+
import "core-js/modules/esnext.map.every.js";
|
|
6
|
+
import "core-js/modules/esnext.map.filter.js";
|
|
7
|
+
import "core-js/modules/esnext.map.find.js";
|
|
8
|
+
import "core-js/modules/esnext.map.find-key.js";
|
|
9
|
+
import "core-js/modules/esnext.map.includes.js";
|
|
10
|
+
import "core-js/modules/esnext.map.key-of.js";
|
|
11
|
+
import "core-js/modules/esnext.map.map-keys.js";
|
|
12
|
+
import "core-js/modules/esnext.map.map-values.js";
|
|
13
|
+
import "core-js/modules/esnext.map.merge.js";
|
|
14
|
+
import "core-js/modules/esnext.map.reduce.js";
|
|
15
|
+
import "core-js/modules/esnext.map.some.js";
|
|
16
|
+
import "core-js/modules/esnext.map.update.js";
|
|
17
|
+
import "core-js/modules/esnext.symbol.metadata.js";
|
|
18
|
+
let _initProto, _initDecs, _joinRoomDecs;
|
|
19
|
+
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)]; } }; }
|
|
20
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
21
|
+
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); }
|
|
22
|
+
function _setFunctionName(e, t, n) { "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : ""); try { Object.defineProperty(e, "name", { configurable: !0, value: n ? n + " " + t : t }); } catch (e) {} return e; }
|
|
23
|
+
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); return e; }
|
|
24
|
+
import { AgoraObservable, retryAttempt, to, trace } from '../imports';
|
|
25
|
+
import { RoomControlFactory } from '../room-control/room-control-factory';
|
|
26
|
+
import { FcrRoomType } from '../room-control/type';
|
|
27
|
+
import { fcrRoomJoinOptionsSchema, stringSchema } from '../schema';
|
|
28
|
+
import { FcrReturnCode } from '../type';
|
|
29
|
+
import { generateFcrCoreClientError, handleRequestError } from '../utilities/error';
|
|
30
|
+
import { FcrJoinHelper, handleJoinRetryFailure } from '../utilities/join-helper';
|
|
31
|
+
import { canRetryJoinError } from '../utilities/retry-helpers';
|
|
32
|
+
import { createLogger, generateLogObserver } from '../utilities/logger';
|
|
33
|
+
import validateParams from '../utilities/validate-params';
|
|
34
|
+
import { ROOM_ROUTER_CONSTANTS } from './type';
|
|
35
|
+
import { DetailErrorCode, ErrorModuleCode } from '../imports';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
export class FcrRoomRouterImpl {
|
|
42
|
+
static {
|
|
43
|
+
[_initProto] = _applyDecs(this, [[_initDecs, 2, "_init"], [_joinRoomDecs, 2, "joinRoom"], [trace, 2, "leaveRoom"]], []).e;
|
|
44
|
+
}
|
|
45
|
+
[(_initDecs = [trace(['roomId']), validateParams(stringSchema)], _joinRoomDecs = [trace(['options']), validateParams(fcrRoomJoinOptionsSchema)], "logger")] = (_initProto(this), createLogger({
|
|
46
|
+
prefix: 'FcrRoomRouterImpl'
|
|
47
|
+
}));
|
|
48
|
+
_abortController = null;
|
|
49
|
+
_observable = new AgoraObservable();
|
|
50
|
+
_roomControlObservable = {
|
|
51
|
+
onRoomRouteSwitched: async event => {
|
|
52
|
+
this._nextRoomRoute = event.targetRouting;
|
|
53
|
+
this._observable.notifyObservers('onRoomRouteSwitched', this._nextRoomRoute);
|
|
54
|
+
this.roomControl.removeObserver(this._roomControlObservable);
|
|
55
|
+
this._roomControl = null;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
_roomControl = null;
|
|
59
|
+
_nextRoomRoute = {
|
|
60
|
+
roomId: '',
|
|
61
|
+
roomType: FcrRoomType.Mainroom,
|
|
62
|
+
isJoined: false
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// 接口中新增一个bypass字段,在第一次调用joinRoom的时候不传,在后续收到房间切换后的joinRoom时传true
|
|
66
|
+
_bypass = undefined;
|
|
67
|
+
constructor(_rteEngine, _apiService, _config, _chatConnection, _sharedCache, roomId) {
|
|
68
|
+
this._rteEngine = _rteEngine;
|
|
69
|
+
this._apiService = _apiService;
|
|
70
|
+
this._config = _config;
|
|
71
|
+
this._chatConnection = _chatConnection;
|
|
72
|
+
this._sharedCache = _sharedCache;
|
|
73
|
+
this._init(roomId);
|
|
74
|
+
this._addLogObserver();
|
|
75
|
+
}
|
|
76
|
+
get roomControl() {
|
|
77
|
+
if (!this._roomControl) {
|
|
78
|
+
throw new Error('roomControl is not initialized');
|
|
79
|
+
}
|
|
80
|
+
return this._roomControl;
|
|
81
|
+
}
|
|
82
|
+
_init(roomId) {
|
|
83
|
+
this._nextRoomRoute = {
|
|
84
|
+
roomId,
|
|
85
|
+
roomType: FcrRoomType.Mainroom,
|
|
86
|
+
isJoined: false
|
|
87
|
+
};
|
|
88
|
+
this._bypass = undefined;
|
|
89
|
+
return FcrReturnCode.SUCCESS;
|
|
90
|
+
}
|
|
91
|
+
async joinRoom(options) {
|
|
92
|
+
this._abortController = new AbortController();
|
|
93
|
+
this._validateRoomJoinState();
|
|
94
|
+
const [error] = await to(this._executeJoinRoomWithRetry(options));
|
|
95
|
+
this._abortController = null;
|
|
96
|
+
if (error) {
|
|
97
|
+
this._handleJoinRoomError(error);
|
|
98
|
+
return Promise.reject(error);
|
|
99
|
+
}
|
|
100
|
+
if (!this._roomControl) {
|
|
101
|
+
return Promise.reject(new Error('Room control is not initialized'));
|
|
102
|
+
}
|
|
103
|
+
return Promise.resolve(this._roomControl);
|
|
104
|
+
}
|
|
105
|
+
async leaveRoom() {
|
|
106
|
+
this._abortController?.abort();
|
|
107
|
+
this._abortController = null;
|
|
108
|
+
this._roomControl?.leave();
|
|
109
|
+
this._roomControl = null;
|
|
110
|
+
return FcrReturnCode.SUCCESS;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 验证房间加入状态
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
_validateRoomJoinState() {
|
|
118
|
+
if (this._nextRoomRoute.isJoined) {
|
|
119
|
+
throw generateFcrCoreClientError(ErrorModuleCode.FCR_ROOM, DetailErrorCode.UNDEFINED_ERROR, 'Room join failed: The user has an active connection to the room.', new Error('Room join failed: The user has an active connection to the room.'));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 带重试机制的房间加入执行
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
127
|
+
async _executeJoinRoomWithRetry(options) {
|
|
128
|
+
const abortController = this._abortController;
|
|
129
|
+
return retryAttempt(() => this._performSingleJoinAttempt(options), [], {
|
|
130
|
+
retriesMax: ROOM_ROUTER_CONSTANTS.MAX_JOIN_ATTEMPTS
|
|
131
|
+
}).fail(async ({
|
|
132
|
+
error,
|
|
133
|
+
timeFn: waitBeforeRetry,
|
|
134
|
+
currentRetry: attemptCount
|
|
135
|
+
}) => {
|
|
136
|
+
return handleJoinRetryFailure(error, waitBeforeRetry, attemptCount, canRetryJoinError, () => {
|
|
137
|
+
this._throwIfAborted(abortController);
|
|
138
|
+
}, 'join room via router');
|
|
139
|
+
}).exec();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 执行单次房间加入尝试
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
async _performSingleJoinAttempt(options) {
|
|
147
|
+
const abortController = this._abortController;
|
|
148
|
+
const roomResponse = await this._performCheckIn(options);
|
|
149
|
+
this._throwIfAborted(abortController);
|
|
150
|
+
const roomControl = await this._joinRoomControl(options, roomResponse);
|
|
151
|
+
this._throwIfAborted(abortController);
|
|
152
|
+
this._updateRoomState(roomResponse, roomControl);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 执行CheckIn API调用
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
async _performCheckIn(options) {
|
|
160
|
+
const {
|
|
161
|
+
userId
|
|
162
|
+
} = this._rteEngine.getConfig();
|
|
163
|
+
const checkInParams = FcrJoinHelper.buildCheckInParams(options, userId, this._nextRoomRoute.roomId, {
|
|
164
|
+
bypass: this._bypass,
|
|
165
|
+
avatar: options.avatar
|
|
166
|
+
});
|
|
167
|
+
const {
|
|
168
|
+
data,
|
|
169
|
+
ts
|
|
170
|
+
} = await handleRequestError(() => this._apiService.checkIn(checkInParams), ErrorModuleCode.FCR_ENGINE);
|
|
171
|
+
return {
|
|
172
|
+
data,
|
|
173
|
+
ts
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 加入房间控制
|
|
179
|
+
* @private
|
|
180
|
+
*/
|
|
181
|
+
async _joinRoomControl(options, roomResponse) {
|
|
182
|
+
const {
|
|
183
|
+
data,
|
|
184
|
+
ts
|
|
185
|
+
} = roomResponse;
|
|
186
|
+
const abortController = this._abortController;
|
|
187
|
+
const roomControl = this._createRoomControl(data);
|
|
188
|
+
abortController?.signal.addEventListener('abort', () => {
|
|
189
|
+
roomControl.leave();
|
|
190
|
+
});
|
|
191
|
+
await roomControl.join({
|
|
192
|
+
...options,
|
|
193
|
+
snapshot: data,
|
|
194
|
+
timestamp: ts,
|
|
195
|
+
createStreamConfigs: options.createStreamConfigs
|
|
196
|
+
});
|
|
197
|
+
return roomControl;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 更新房间状态
|
|
202
|
+
* @private
|
|
203
|
+
*/
|
|
204
|
+
_updateRoomState(roomResponse, roomControl) {
|
|
205
|
+
const {
|
|
206
|
+
data
|
|
207
|
+
} = roomResponse;
|
|
208
|
+
this._nextRoomRoute = {
|
|
209
|
+
roomType: data.room.roomProperties.roomType,
|
|
210
|
+
roomId: data.room.roomInfo.roomUuid,
|
|
211
|
+
isJoined: true
|
|
212
|
+
};
|
|
213
|
+
this._bypass = 1;
|
|
214
|
+
this._observable.notifyObservers('onRoomJoined', roomControl);
|
|
215
|
+
this._roomControl = roomControl;
|
|
216
|
+
this._roomControl.addObserver(this._roomControlObservable);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 处理房间加入错误
|
|
221
|
+
* @private
|
|
222
|
+
*/
|
|
223
|
+
_handleJoinRoomError(error) {
|
|
224
|
+
this.logger.error(`Failed to join the room: ${error.message}`);
|
|
225
|
+
const fcrError = generateFcrCoreClientError(ErrorModuleCode.FCR_ROOM, DetailErrorCode.LOCAL_HTTP_REQUEST_FAILED, `join room failed: ${error.message}`);
|
|
226
|
+
this._observable.notifyObservers('onErrorOccurred', fcrError);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 创建房间控制实例
|
|
231
|
+
* @param roomResponse 房间响应数据
|
|
232
|
+
* @returns 房间控制实例
|
|
233
|
+
*/
|
|
234
|
+
_createRoomControl(roomResponse) {
|
|
235
|
+
const room = roomResponse.room;
|
|
236
|
+
const scene = this._rteEngine.createScene({
|
|
237
|
+
sceneId: room.roomInfo.roomUuid
|
|
238
|
+
});
|
|
239
|
+
return RoomControlFactory.create({
|
|
240
|
+
engine: this._rteEngine,
|
|
241
|
+
scene,
|
|
242
|
+
apiService: this._apiService,
|
|
243
|
+
config: this._config,
|
|
244
|
+
chatConnection: this._chatConnection,
|
|
245
|
+
sharedCache: this._sharedCache,
|
|
246
|
+
roomResponse
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
_throwIfAborted(abortController) {
|
|
250
|
+
if (abortController?.signal.aborted) {
|
|
251
|
+
throw new Error('Join room attempt aborted');
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
_addLogObserver() {
|
|
255
|
+
this.addObserver(generateLogObserver(this.logger, [['onErrorOccurred', ['error']], ['onRoomJoined', ['roomControl']], ['onRoomRouteSwitched', ['nextRoomRoute']]]));
|
|
256
|
+
}
|
|
257
|
+
addObserver(observer) {
|
|
258
|
+
this._observable.addObserver(observer);
|
|
259
|
+
}
|
|
260
|
+
removeObserver(observer) {
|
|
261
|
+
this._observable.removeObserver(observer);
|
|
262
|
+
}
|
|
263
|
+
}
|