UNPKG

fcr-core

Version:

Core APIs for building online scenes

608 lines (589 loc) 27.9 kB
"use strict"; 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"); Object.defineProperty(exports, "__esModule", { value: true }); exports.FcrSubRoomControlImpl = exports.FcrBaseRoomControlImpl = void 0; var _imports = require("../imports"); var _type = require("../type"); var _type2 = require("./type"); var _roomConnectorControl = require("./room-connector-control"); var _roomSession = require("./room-session"); var _privilegeControl = require("./privilege-control"); var _userControl = require("./user-control"); var _streamControl = require("./stream-control"); var _abilityControl = require("./ability-control"); var _sharingControl = require("./sharing-control"); var _error = require("../utilities/error"); var _collection = require("../utilities/collection"); var _logger = require("../utilities/logger"); var _2 = require(".."); var _helpers = require("./helpers"); var _errorHelpers = require("../utilities/error-helpers"); var _sttControl = require("./stt-control"); let _initProto; // Core SDK imports // Service and API imports // Type definitions // Room control types and interfaces // Control implementations // Error handling and utilities // Core state // Helpers and utilities 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; } /** * 房间控制基础实现类 * * 负责管理房间的生命周期,包括加入、离开、状态管理等核心功能。 * 提供统一的房间控制接口,管理各个子控制器的初始化和销毁。 * * @internal */ class FcrBaseRoomControlImpl { static { [_initProto] = _applyDecs(this, [[_imports.trace, 2, "getSyncTimestamp"], [_imports.trace, 2, "getRoomInfo"], [_imports.trace, 2, "getRoomSchedule"], [_imports.trace, 2, "join"], [_imports.trace, 2, "leave"], [_imports.trace, 2, "start"], [_imports.trace, 2, "end"], [_imports.trace, 2, "close"], [_imports.trace, 2, "getRoomState"], [_imports.trace, 2, "getRoomProperties"], [_imports.trace, 2, "getRoomPropertiesByKeyPath"], [_imports.trace, 2, "updateRoomProperties"], [_imports.trace, 2, "updateIncrementRoomProperties"], [_imports.trace, 2, "deleteRoomProperties"], [_imports.trace, 2, "startCloudRecording"], [_imports.trace, 2, "pauseCloudRecording"], [_imports.trace, 2, "resumeCloudRecording"], [_imports.trace, 2, "stopCloudRecording"], [_imports.trace, 2, "getLiveStreamingState"], [_imports.trace, 2, "getLiveStreamingConfig"], [_imports.trace, 2, "startLiveStreaming"], [_imports.trace, 2, "updateLiveStreamingLayout"], [_imports.trace, 2, "stopLiveStreaming"], [_imports.trace, 2, "getCloudRecordingState"], [_imports.trace, 2, "sendRoomMessage"]], []).e; } //@internal logger = (_initProto(this), (0, _logger.createLogger)({ prefix: 'FcrBaseRoomControlImpl' })); _observable = new _imports.AgoraObservable(); _joinRoomSuccess = false; _joining = false; _joinState = _helpers.ROOM_CONTROL_CONSTANTS.JOIN_STATE.CANCELED; constructor(_engine, _scene, _api, _config, _roomType, _chatConnection, _sharedCache, _chatRoomControl) { this._engine = _engine; this._scene = _scene; this._api = _api; this._config = _config; this._roomType = _roomType; this._chatConnection = _chatConnection; this._sharedCache = _sharedCache; this._chatRoomControl = _chatRoomControl; // 初始化 FcrJoinHelper const { userId } = this._engine.getConfig(); this._joinHelper = new _helpers.FcrJoinHelper(userId, this._scene, this._api); this._engineObserver = { onConnectionStateUpdated: state => { if (state === _2.FcrConnectionState.ABORTED) { this._joinState = _helpers.ROOM_CONTROL_CONSTANTS.JOIN_STATE.CANCELED; this._cleanup(); } } }; this._sceneObserver = { onJoinSceneSuccess: (sceneId, localUser) => { this._joinRoomSuccess = true; this._chatRoomControl?.join(); this._userControl = new _userControl.FcrUserControlImpl(this._scene, this._api, this._sharedCache); this._streamControl = new _streamControl.FcrStreamControlImpl(this._engine, this._scene, this._api, this._sharedCache); this._roomSessionControl = new _roomSession.FcrRoomSessionControlImpl(this, this._api, localUser.getLocalUserId()); this._privilegeControl = new _privilegeControl.FcrPrivilegeControlImpl(this._engine, this._scene, this._api, this._sharedCache); this._roomConnectorControl = new _roomConnectorControl.FcrRoomConnectorControlImpl(this._scene, this._engine, this._api); this._abilityControl = new _abilityControl.FcrAbilityControlImpl(this._scene); if (this._streamControl && !this.sharingControl && // TODO: 确认是否需要限制在主房间 this._roomType === _type2.FcrRoomType.Mainroom) { this.logger.info('[whiteboard]: join scene success, start create sharing control'); this.sharingControl = new _sharingControl.FcrSharingControlImpl(this._scene, this._api, this._engine, this._privilegeControl, this._streamControl, this._sharedCache, this._userControl); } this._sttControl = new _sttControl.FcrSttControlImpl(this._scene, this._api, this._sharedCache); this._observable.notifyObservers('onJoinRoomSuccess', sceneId); }, // onJoinSceneFailure: (sceneId, error) => { // this._observable.notifyObservers( // 'onJoinRoomFailure', // sceneId, // generateFcrCoreClientError( // FcrErrorModuleCode.ROOM, // FcrErrorCode.NOT_JOINED_ROOM, // 'join room failed', // error, // ), // ); // }, onSceneMessageReceived: (sceneId, message) => { this._observable.notifyObservers('onRoomMessageReceived', sceneId, message); const payload = message.payload; if (message.cmd === _helpers.ROOM_MESSAGE_COMMANDS.ROOM_ROUTE_SWITCH) { const localUserRole = this._userControl?.getLocalUser().userRole; if (localUserRole && payload.targetRoles.includes(_type.FcrUserRoleToStringMap[localUserRole])) { this._observable.notifyObservers('onRoomRouteSwitched', { targetRouting: { roomId: payload.toRoom.roomUuid, roomType: payload.toRoom.roomType, isJoined: false }, operatorUser: this._userControl?.getUser(message.senderId) }); this.leave(); } } }, onScenePropertiesUpdated: async (sceneId, event) => { if (event.cause?.cmd === _helpers.ROOM_MESSAGE_COMMANDS.CLOUD_RECORDING) { const { state, ready, onhold } = this._scene.getSceneProperties().record; const recordState = this._formatRecordingState(state, ready, onhold); this._observable.notifyObservers('onCloudRecordingStateUpdated', sceneId, recordState); } if (event.cause?.cmd === _helpers.ROOM_MESSAGE_COMMANDS.ROOM_STATE_UPDATE) { const schedule = event.changedProperties.schedule; if (schedule.state === _helpers.ROOM_STATE_VALUES.ENDED) { this._joinState = _helpers.ROOM_CONTROL_CONSTANTS.JOIN_STATE.CANCELED; this._cleanup(); } this._observable.notifyObservers('onRoomStateUpdated', sceneId, schedule.state); } if (event.cause?.cmd === _helpers.ROOM_MESSAGE_COMMANDS.ROOM_PROPERTIES_UPDATE) { const changedProperties = {}; for (const key in event.changedProperties) { if (key.startsWith('flexProps')) { changedProperties[key] = event.changedProperties[key]; } } if (Object.keys(changedProperties).length > 0) { const structure = (0, _collection.convertToStructure)(changedProperties); this._observable.notifyObservers('onRoomPropertiesUpdated', sceneId, { ...event, changedProperties: structure['flexProps'] }); } } if (event.cause?.cmd === _helpers.ROOM_MESSAGE_COMMANDS.LIVE_STREAMING_UPDATE) { let liveStreamingState = _type.FcrLiveStreamingState.STOPPED; let state = this._scene.getScenePropertiesByKeyPath('live.state'); let pageUrl = this._scene.getScenePropertiesByKeyPath('live.pageUrl'); const reason = event.cause?.data?.reason; if (state === _helpers.LIVE_STREAMING_STATE_VALUES.STARTED) { liveStreamingState = _type.FcrLiveStreamingState.STARTED; } if (state === _helpers.LIVE_STREAMING_STATE_VALUES.STOPPED_ALT) { liveStreamingState = _type.FcrLiveStreamingState.STOPPED; } this._observable.notifyObservers('onLiveStreamingStateUpdated', sceneId, liveStreamingState, pageUrl, reason); } }, onScenePropertiesDeleted: (sceneId, event) => { if (event.cause?.cmd === _helpers.ROOM_MESSAGE_COMMANDS.ROOM_PROPERTIES_UPDATE) { this._observable.notifyObservers('onRoomPropertiesDeleted', sceneId, event); } }, onNetworkQualityUpdated: (sceneId, event) => { this._observable.notifyObservers('onNetworkQualityUpdated', sceneId, event); }, onNetworkStatsUpdated: (sceneId, stats) => { this._observable.notifyObservers('onNetworkStatsUpdated', sceneId, stats); }, onUserPropertiesUpdated: (_, event) => { if (event.cause?.cmd === _helpers.ROOM_MESSAGE_COMMANDS.USER_KICK_OUT && event.modifiedUser.userId === this._scene.localUser.getLocalUserId()) { this._joinState = _helpers.ROOM_CONTROL_CONSTANTS.JOIN_STATE.CANCELED; this._cleanup(); } } }; } /** * 获取字幕控制器 * @returns 字幕控制器实例 * @throws {FcrError} 如果控制器未初始化 */ // @trace getSttControl() { (0, _helpers.validateControllerInitialized)(this._sttControl, _errorHelpers.ControllerType.STT); return this._sttControl; } /** * 获取屏幕共享控制器 * @returns 屏幕共享控制器实例 * @throws {FcrError} 如果控制器未初始化 */ // @trace getSharingControl() { (0, _helpers.validateControllerInitialized)(this.sharingControl, _errorHelpers.ControllerType.SHARING); return this.sharingControl; } /** * 获取用户控制器 * @returns 用户控制器实例 * @throws {FcrError} 如果控制器未初始化 */ // @trace getUserControl() { (0, _helpers.validateControllerInitialized)(this._userControl, _errorHelpers.ControllerType.USER); return this._userControl; } /** * 获取流控制器 * @returns 流控制器实例 * @throws {FcrError} 如果控制器未初始化 */ // @trace getStreamControl() { (0, _helpers.validateControllerInitialized)(this._streamControl, _errorHelpers.ControllerType.STREAM); return this._streamControl; } /** * 获取房间会话控制器 * @returns 房间会话控制器实例 * @throws {FcrError} 如果控制器未初始化 */ // @trace getRoomSessionControl() { (0, _helpers.validateControllerInitialized)(this._roomSessionControl, _errorHelpers.ControllerType.ROOM_SESSION); return this._roomSessionControl; } /** * 获取聊天室控制器 * @returns 聊天室控制器实例 * @throws {FcrError} 如果控制器未初始化 */ // @trace getChatRoomControl() { (0, _helpers.validateControllerInitialized)(this._chatRoomControl, _errorHelpers.ControllerType.CHAT_ROOM); return this._chatRoomControl; } /** * 获取权限控制器 * @returns 权限控制器实例 * @throws {FcrError} 如果控制器未初始化 */ // @trace getPrivilegeControl() { (0, _helpers.validateControllerInitialized)(this._privilegeControl, _errorHelpers.ControllerType.PRIVILEGE); return this._privilegeControl; } // @trace getRoomConnectorControl() { (0, _helpers.validateControllerInitialized)(this._roomConnectorControl, _errorHelpers.ControllerType.ROOM_CONNECTOR); return this._roomConnectorControl; } getAbilityControl() { (0, _helpers.validateControllerInitialized)(this._abilityControl, _errorHelpers.ControllerType.ABILITY); return this._abilityControl; } getSyncTimestamp() { return this._scene.getSyncTimestamp(); } /** * 获取房间信息 * * @returns 房间信息,如果未加入房间则返回 undefined */ getRoomInfo() { const sceneInfo = this._scene.getSceneInfo(); const passwordInfo = this._scene.getScenePropertiesByKeyPath('security.password'); const userProperties = this._scene.getUserPropertiesByUserId(this._scene.localUser.getLocalUserId()); const shareLink = userProperties?.info?.shareLink; const label = this._scene.getScenePropertiesByKeyPath('label'); return sceneInfo ? { roomId: sceneInfo.sceneId, roomName: sceneInfo.sceneName, roomType: this._roomType, password: passwordInfo?.payload?.text, inviteLink: shareLink, label } : void 0; } /** * 获取房间计划信息 * * @returns 房间计划信息,包括开始时间、时长等 * @throws {FcrError} 如果未加入房间 */ getRoomSchedule() { (0, _helpers.validateRoomJoined)(this._joinRoomSuccess, 'get schedule info'); const schedule = this._scene.getScenePropertiesByKeyPath('schedule'); return { ...schedule, duration: schedule.duration ?? 0, startTime: Math.floor((schedule.startTime ?? 0) / 1000) }; } /** * 加入房间 * * 支持两种加入方式: * 1. 通过快照加入(适用于已有房间快照的场景) * 2. 通过选项加入(需要进行CheckIn流程) * * @param options 加入房间的选项或快照 * @throws {FcrError} 加入失败时抛出错误 */ async join(options) { // 前置验证和状态设置 this._validateAndSetupJoinState(); try { this._initializeJoinObservers(); await this._executeJoinProcess(options); // 处理机器人用户的特殊逻辑 await this._handleRobotUserSetup(options); } catch (error) { // 处理加入失败 this._handleJoinFailure(error); throw error; } finally { // 清理状态 this._joining = false; } } /** * 验证前置条件并设置加入状态 * @private */ _validateAndSetupJoinState() { this._joinState = _helpers.ROOM_CONTROL_CONSTANTS.JOIN_STATE.JOINING; (0, _helpers.validateJoinRoomPreconditions)(this._joinRoomSuccess, this._joining); } /** * 初始化加入过程的观察者和状态 * @private */ _initializeJoinObservers() { this._joining = true; this._scene.addObserver(this._sceneObserver); this._engine.addObserver(this._engineObserver); } /** * 执行房间加入过程 * @private */ async _executeJoinProcess(options) { const handleJoinAborted = this._createJoinAbortedHandler(); const [error] = await (0, _imports.to)(this._joinHelper.join(options, handleJoinAborted)); if (error) { throw error; } } /** * 创建加入中止处理器 * @private */ _createJoinAbortedHandler() { return () => { if (this._joinState === _helpers.ROOM_CONTROL_CONSTANTS.JOIN_STATE.CANCELED) { this.logger.info('join is canceled'); this._cleanup(); const fcrError = _helpers.roomControlErrorHelper.createOperationCanceledError('Joining'); this._observable.notifyObservers('onJoinRoomFailure', this._scene.sceneId, fcrError); throw fcrError; } }; } /** * 处理机器人用户的特殊设置 * @private */ async _handleRobotUserSetup(options) { if (options.userRole === _type.FcrUserRole.ROBOT) { const res = (0, _error.handleRequestError)(() => this._api.setCloudRecordingReady(this._scene.sceneId), _error.FcrErrorModuleCode.ROOM, 'set cloud recording ready failed'); this.logger.info(`set cloud recording ready, response: ${(0, _imports.jsonstring)(res)}`); } } /** * 处理加入失败的情况 * @private */ _handleJoinFailure(error) { this.logger.error(`failed to join room: ${error.message}`); this._observable.notifyObservers('onJoinRoomFailure', this._scene.sceneId, error); } /** * 离开房间 * * 清理所有资源,包括观察者、控制器实例等 */ async leave() { this._joinState = _helpers.ROOM_CONTROL_CONSTANTS.JOIN_STATE.CANCELED; await this._cleanup(); } /** * 开始房间 * * 只有房间创建者或管理员才能调用此方法 */ async start() { await this._api.startRoom(this._scene.sceneId); } /** * 结束房间 * * 只有房间创建者或管理员才能调用此方法 */ async end() { await this._api.endRoom(this._scene.sceneId); } async close() { await this._api.closeRoom(this._scene.sceneId); } getRoomState() { return this._scene.getScenePropertiesByKeyPath('schedule.state'); } getRoomProperties() { return this._scene.getScenePropertiesByKeyPath('flexProps'); } getRoomPropertiesByKeyPath(keyPath) { return this._scene.getScenePropertiesByKeyPath('flexProps.' + keyPath); } async updateRoomProperties(properties, cause) { await (0, _error.handleRequestError)(() => this._api.updateRoomProperties({ roomId: this._scene.sceneId, properties, cause }), _error.FcrErrorModuleCode.ROOM, 'update room properties failed'); } async updateIncrementRoomProperties(increments, cause) { await (0, _error.handleRequestError)(() => this._api.updateRoomProperties({ roomId: this._scene.sceneId, increments, cause }), _error.FcrErrorModuleCode.ROOM, 'update room properties failed'); } async deleteRoomProperties(properties, cause) { await (0, _error.handleRequestError)(() => this._api.deleteRoomProperties({ roomId: this._scene.sceneId, properties, cause }), _error.FcrErrorModuleCode.ROOM, 'delete room rroperties failed'); } async startCloudRecording(config) { await (0, _error.handleRequestError)(() => this._api.startCloudRecording(config, this._scene.sceneId), _error.FcrErrorModuleCode.ROOM, 'start cloud recording failed'); } async pauseCloudRecording() { await (0, _error.handleRequestError)(() => this._api.pauseCloudRecording(this._scene.sceneId), _error.FcrErrorModuleCode.ROOM, 'pause cloud recording failed'); } async resumeCloudRecording() { await (0, _error.handleRequestError)(() => this._api.resumeCloudRecording(this._scene.sceneId), _error.FcrErrorModuleCode.ROOM, 'resume cloud recording failed'); } async stopCloudRecording() { await (0, _error.handleRequestError)(() => this._api.stopCloudRecording(this._scene.sceneId), _error.FcrErrorModuleCode.ROOM, 'stop cloud recording failed'); } getLiveStreamingState() { let liveStreamingState = this._scene.getScenePropertiesByKeyPath('live.state'); if (liveStreamingState === _helpers.LIVE_STREAMING_STATE_VALUES.STARTED) { return _type.FcrLiveStreamingState.STARTED; } if (liveStreamingState === _helpers.LIVE_STREAMING_STATE_VALUES.STOPPED_ALT) { return _type.FcrLiveStreamingState.STOPPED; } return _type.FcrLiveStreamingState.STOPPED; } getLiveStreamingConfig() { const res = this._scene.getScenePropertiesByKeyPath('live'); if (res) { return { pushStreamingUrl: res.streamUrl, pullStreamingUrl: res.pageUrl, pushStreamingKey: res.streamKey, layoutType: res.layoutType }; } return { pushStreamingUrl: '', pullStreamingUrl: '', pushStreamingKey: '', layoutType: _type.FcrLiveStreamingLayoutType.SPEAKER }; } async startLiveStreaming(data) { await this._liveStreamingAction(() => this._api.startLiveStreaming(this._scene.sceneId, data), 'start live streaming failed'); } async updateLiveStreamingLayout(layoutType) { await this._liveStreamingAction(() => this._api.updateLiveStreamingLayout(this._scene.sceneId, layoutType), 'update live streaming layout failed'); } async stopLiveStreaming() { await this._liveStreamingAction(() => this._api.stopLiveStreaming(this._scene.sceneId), 'stop live streaming failed'); } getCloudRecordingState() { const { state, ready, onhold } = this._scene.getScenePropertiesByKeyPath('record'); return this._formatRecordingState(state, ready, onhold); } async sendRoomMessage(payload, guaranteedDelivery) { try { await this._scene.localUser.sendSceneMessage(payload, '101', guaranteedDelivery); } catch (e) { throw _helpers.roomControlErrorHelper.createSendMessageError(e); } } isHostKeyEnabled() { return this._scene.getScenePropertiesByKeyPath('info.hasHostKey'); } addObserver(observer) { this._observable.addObserver(observer); } removeObserver(observer) { this._observable.removeObserver(observer); } async _cleanup() { this._scene.removeObserver(this._sceneObserver); this._engine.removeObserver(this._engineObserver); try { return await Promise.all([ // @ts-ignore this._chatRoomControl?.leave(), this.sharingControl?.getBoardControl().close(), this.sharingControl?.getAnnotationControl().close(), this._scene.leave()]); } finally { this._joinRoomSuccess = false; } } _formatRecordingState(state, ready, onhold) { let recordState = _type.FcrRecordingState.Stopped; if (state === _helpers.RECORDING_STATE_VALUES.RECORDING) { if (!ready) { recordState = _type.FcrRecordingState.Starting; } else { if (!onhold) { recordState = _type.FcrRecordingState.Started; } else { recordState = _type.FcrRecordingState.Paused; } } } return recordState; } async _liveStreamingAction(action, errorMessage) { try { const { code } = await action(); if (code !== _helpers.RESPONSE_CODES.SUCCESS) { throw _helpers.liveStreamingErrorHelper.createNetworkError(errorMessage); } } catch (error) { throw _helpers.liveStreamingErrorHelper.createNetworkError(errorMessage); } } } /** * @internal */ exports.FcrBaseRoomControlImpl = FcrBaseRoomControlImpl; class FcrSubRoomControlImpl extends FcrBaseRoomControlImpl {} exports.FcrSubRoomControlImpl = FcrSubRoomControlImpl;