UNPKG

fcr-core

Version:

Core APIs for building online scenes

262 lines (259 loc) 17.5 kB
"use strict"; require("core-js/modules/es.symbol.description.js"); require("core-js/modules/es.error.cause.js"); require("core-js/modules/es.array.push.js"); require("core-js/modules/esnext.function.metadata.js"); require("core-js/modules/esnext.map.delete-all.js"); require("core-js/modules/esnext.map.emplace.js"); require("core-js/modules/esnext.map.every.js"); require("core-js/modules/esnext.map.filter.js"); require("core-js/modules/esnext.map.find.js"); require("core-js/modules/esnext.map.find-key.js"); require("core-js/modules/esnext.map.includes.js"); require("core-js/modules/esnext.map.key-of.js"); require("core-js/modules/esnext.map.map-keys.js"); require("core-js/modules/esnext.map.map-values.js"); require("core-js/modules/esnext.map.merge.js"); require("core-js/modules/esnext.map.reduce.js"); require("core-js/modules/esnext.map.some.js"); require("core-js/modules/esnext.map.update.js"); require("core-js/modules/esnext.symbol.metadata.js"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.FcrMainRoomControlImpl = void 0; require("core-js/modules/es.json.stringify.js"); require("core-js/modules/esnext.iterator.constructor.js"); require("core-js/modules/esnext.iterator.find.js"); require("core-js/modules/web.dom-collections.iterator.js"); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _imports = require("../../imports"); var _ = require(".."); var _groupControl = require("../group-control"); var _type = require("../../type"); var _type2 = require("../type"); var _error = require("../../utilities/error"); var _interpreterControl = require("../interpreter-control"); var _schema = require("../../schema"); var _logger = require("../../utilities/logger"); var _validateParams = _interopRequireDefault(require("../../utilities/validate-params")); var _sharedStorage = require("../../utilities/shared-storage"); var _utils = require("../whiteboard-control-v2/utils"); var _utils2 = require("../whiteboard-control/utils"); var _FcrMainRoomControlImpl; let _initProto, _enableWaitingRoomDecs, _moveToWaitingRoomByUserIdsDecs, _ref; 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)]; } }; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } 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); } 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; } 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; } const { shared: sharedScheduler, Duration } = _imports.AgoraScheduler; /** * @internal */ _ref = (_enableWaitingRoomDecs = [_imports.trace, (0, _validateParams.default)(_schema.booleanSchema)], _moveToWaitingRoomByUserIdsDecs = [_imports.trace, (0, _validateParams.default)(_schema.stringArraySchema)], "logger"); class FcrMainRoomControlImpl extends _.FcrBaseRoomControlImpl { constructor(engine, scene, api, config, sharedCache, chatConnection, chatRoomControl) { super(engine, scene, api, config, _type2.FcrRoomType.Mainroom, chatConnection, sharedCache, chatRoomControl); //@internal (0, _defineProperty2.default)(this, _ref, (_initProto(this), (0, _logger.createLogger)({ prefix: 'FcrMainRoomControlImpl' }))); (0, _defineProperty2.default)(this, "_privilegeObserver", { onLocalUserPermissionInfoAdded: this._onLocalUserPermissionInfoAdded, onLocalUserPermissionInfoDeleted: this._onLocalUserPermissionInfoDeleted }); this._groupControl = new _groupControl.FcrGroupControl(engine, scene, api, sharedCache); this._interpreterControl = new _interpreterControl.FcrInterpreterControlImpl(api, scene, config, engine, chatConnection, sharedCache); this._addLogObserver(); this._scene.addObserver({ onScenePropertiesUpdated: (sceneId, event) => { const annotationBoardAppId = (0, _imports.get)(event.changedProperties, 'widgets.annotation.extra.boardAppId'); if (annotationBoardAppId) { this.logger.info('widgets.annotation.extra.boardAppId updated, re-initializing annotation info'); this._initAnnotationInfo(); } const whiteboardBoardAppId = (0, _imports.get)(event.changedProperties, 'widgets.netlessBoard.extra.boardAppId'); if (whiteboardBoardAppId) { this.logger.info('widgets.netlessBoard.extra.boardAppId updated, re-initializing whiteboard info'); this._initBoardInfo(); } }, onJoinSceneSuccess: () => { this.logger.info('join scene success, re-initializing annotation and whiteboard info'); this._initAnnotationInfo(); this._initBoardInfo(); } }); this.logger.info("initialized, room id: ".concat(this._scene.sceneId)); } // @trace getInterpreterControl() { return this._interpreterControl; } // @trace getGroupControl() { return this._groupControl; } async join(options) { try { (0, _sharedStorage.clearAnnotationBoardOptions)(); (0, _sharedStorage.clearWhiteboardOptions)(); await super.join(options); const privilegeControl = this.getPrivilegeControl(); privilegeControl.addObserver(this._privilegeObserver); const task = sharedScheduler.addIntervalTask(() => { this._engine.getMonitor().uploadLog({ userUuid: this._config.userId, roomUuid: this._scene.sceneId }); }, Duration.minute(5), false); this._logUploadTask = task; } finally { this._engine.getMonitor().uploadLog({ userUuid: this._config.userId, roomUuid: this._scene.sceneId }); } } async leave() { try { const privilegeControl = this.getPrivilegeControl(); privilegeControl.removeObserver(this._privilegeObserver); return await super.leave(); } finally { var _this$_logUploadTask; (_this$_logUploadTask = this._logUploadTask) === null || _this$_logUploadTask === void 0 || _this$_logUploadTask.stop(); this._engine.getMonitor().uploadLog({ userUuid: this._config.userId, roomUuid: this._scene.sceneId }); } } addObserver(observer) { super.addObserver(observer); } removeObserver(observer) { super.removeObserver(observer); } async enableWaitingRoom(enable) { return (0, _error.handleRequestError)(() => this._api.enableWaitingRoom({ enable, roomId: this._scene.sceneId }), _error.FcrErrorModuleCode.ROOM, 'enable waiting room failed'); } async moveToWaitingRoomByUserIds(userIds) { const [error] = await (0, _imports.to)(this._api.moveToWaitingRoomByUserIds(userIds, this._scene.sceneId)); if (error) { this.logger.error("[RoomControl] move to waiting room failed, ".concat(error.message, "-").concat(JSON.stringify(error))); if (error instanceof _imports.AgoraRestfulClientError) { var _error$serviceCode; throw (0, _error.generateFcrCoreServerError)((_error$serviceCode = error.serviceCode) !== null && _error$serviceCode !== void 0 ? _error$serviceCode : -1, error.message, error); } throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'move to waiting room failed', error); } } async moveToWaitingRoomByUserRoles() { return this._api.moveToWaitingRoomByUserRoles([_type.FcrUserRoleToStringMap[_type.FcrUserRole.PARTICIPANT]], this._scene.sceneId); } async _initAnnotationInfo() { const roomId = this._scene.sceneId; const userId = this._scene.localUser.getLocalUserId(); const boardOptions = (await this._getToken(roomId, userId)).data; if (!boardOptions) { this.logger.error("get annotation board options failed, roomId: ".concat(roomId, ", userId: ").concat(userId, ", boardOptions: ").concat((0, _imports.jsonstring)(boardOptions))); } else { this.logger.info("get annotation board options success, roomId: ".concat(roomId, ", userId: ").concat(userId, ", boardOptions: ").concat((0, _imports.jsonstring)(boardOptions))); (0, _sharedStorage.setAnnotationBoardOptions)(boardOptions); } } async _initBoardInfo() { const roomId = this._scene.sceneId; const userId = this._scene.localUser.getLocalUserId(); const boardOptions = (await this._getBoardToken(roomId, userId)).data; if (!boardOptions) { this.logger.error("get whiteboard options failed, roomId: ".concat(roomId, ", userId: ").concat(userId, ", boardOptions: ").concat((0, _imports.jsonstring)(boardOptions))); } else { this.logger.info("get whiteboard options success, roomId: ".concat(roomId, ", userId: ").concat(userId, ", boardOptions: ").concat((0, _imports.jsonstring)(boardOptions))); (0, _sharedStorage.setWhiteboardOptions)(boardOptions); } } async _getToken(roomId, userId) { return await (0, _error.handleRequestError)(() => this._api.getAnnotationToken({ roomId, userId }), _error.FcrErrorModuleCode.ROOM_WHITEBOARD, 'get whiteboard token failed'); } async _getBoardToken(roomId, userId) { return await (0, _error.handleRequestError)(() => this._api.getWhiteboardToken({ roomId, userId }), _error.FcrErrorModuleCode.ROOM_WHITEBOARD, 'get whiteboard token failed'); } _onLocalUserPermissionInfoAdded(roomId, event) { if ((0, _utils2.hasBoardWritePermission)(event.permissionInfo)) { this.logger.info("add board write permission"); this.getSharingControl().getBoardControl().setOperationPrivilege(true); } if ((0, _utils2.hasAnnotationWritePermission)(event.permissionInfo)) { this.logger.info("add annotation write permission"); this.getSharingControl().getAnnotationControl().setOperationPrivilege(true); } } _onLocalUserPermissionInfoDeleted(roomId, event) { if ((0, _utils2.hasBoardWritePermission)(event.permissionInfo)) { this.logger.info("remove board write permission"); this.getSharingControl().getBoardControl().setOperationPrivilege(false); } if ((0, _utils2.hasAnnotationWritePermission)(event.permissionInfo)) { this.logger.info("remove annotation write permission"); this.getSharingControl().getAnnotationControl().setOperationPrivilege(false); } } _checkIfUpdateAnnotationMainWindow() { const streamControl = this.getStreamControl(); const userControl = this.getUserControl(); const mainWindow = this.getSharingControl().getAnnotationControl().getMainWindow(); const annotationConfig = (0, _utils.getAnnotationConfigFromRoomProperties)(this._scene.getSceneProperties(), this.logger); if (mainWindow) { const stream = streamControl.getStreamList().find(stream => stream.videoSourceType === _type.FcrVideoSourceType.SCREEN); const localUserId = userControl.getLocalUser().userId; if (stream) { var _userControl$getUser; const ownerId = stream.owner.userId; const isNotMeSharing = ownerId !== localUserId; const platform = (_userControl$getUser = userControl.getUser(ownerId)) === null || _userControl$getUser === void 0 ? void 0 : _userControl$getUser.platform; const isPcPlatform = platform && [_type.FcrPlatform.WEB_DESKTOP, _type.FcrPlatform.WINDOWS, _type.FcrPlatform.MACOS].includes(platform); const isAndroidPlatform = platform && platform === _type.FcrPlatform.ANDROID; this.logger.info("check if set auto cancel draw, isPcPlatform: ".concat(isPcPlatform, ", isAndroidPlatform: ").concat(isAndroidPlatform, ", isNotMeSharing: ").concat(isNotMeSharing, ", ownerId: ").concat(ownerId, ", localUserId: ").concat(localUserId, ", platform: ").concat(platform)); if (isPcPlatform) { mainWindow.setAutoCancelDraw(false); } if (isAndroidPlatform) { mainWindow.setAutoCancelDraw(isNotMeSharing); } if (!isNotMeSharing) { mainWindow.clean(); mainWindow.updateWindowSize({ width: annotationConfig.size.width, height: annotationConfig.size.height }); this._api.syncScreenShareOwnerAnnotationOpenDone(this._scene.sceneId); } } } } _addLogObserver() { this.addObserver((0, _logger.generateLogObserver)(this.logger, ['onCloudRecordingStateUpdated', 'onJoinRoomFailure', 'onJoinRoomSuccess', 'onLiveStreamingStateUpdated', // 'onNetworkQualityUpdated', // 'onNetworkStatsUpdated', 'onRoomMessageReceived', 'onRoomPropertiesDeleted', 'onRoomPropertiesUpdated', 'onRoomStateUpdated'])); } } exports.FcrMainRoomControlImpl = FcrMainRoomControlImpl; _FcrMainRoomControlImpl = FcrMainRoomControlImpl; [_initProto] = _applyDecs(_FcrMainRoomControlImpl, [[_imports.trace, 2, "join"], [_imports.trace, 2, "leave"], [_enableWaitingRoomDecs, 2, "enableWaitingRoom"], [_moveToWaitingRoomByUserIdsDecs, 2, "moveToWaitingRoomByUserIds"], [_imports.trace, 2, "moveToWaitingRoomByUserRoles"], [_imports.bound, 2, "_onLocalUserPermissionInfoAdded"], [_imports.bound, 2, "_onLocalUserPermissionInfoDeleted"]], [], 0, void 0, _.FcrBaseRoomControlImpl).e;