UNPKG

fcr-core

Version:

Core APIs for building online scenes

550 lines (543 loc) 28.5 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; require("core-js/modules/esnext.iterator.constructor.js"); require("core-js/modules/esnext.iterator.map.js"); var _imports = require("../imports"); var _type = require("../type"); var _error = require("../utilities/error"); 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 _collection = require("../utilities/collection"); var _ = require(".."); var _logger = require("../utilities/logger"); var _abilityControl = require("./ability-control"); var _sharingControl = require("./sharing-control"); let _initProto; 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 = 0; // 0: canceled, 1: joining constructor(_engine, _scene, _api, _config, _roomType, _chatConnection, _sharedCache, _chatRoomControl, _whiteboardControl) { this._engine = _engine; this._scene = _scene; this._api = _api; this._config = _config; this._roomType = _roomType; this._chatConnection = _chatConnection; this._sharedCache = _sharedCache; this._chatRoomControl = _chatRoomControl; this._whiteboardControl = _whiteboardControl; this._engineObserver = { onConnectionStateUpdated: state => { if (state === _.FcrConnectionState.ABORTED) { this._joinState = 0; 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._whiteboardControl && this._streamControl) { this.sharingControl = new _sharingControl.FcrSharingControlImpl(this._scene, this._api, this._engine, this._privilegeControl, this._whiteboardControl, this._streamControl, this._sharedCache, this._userControl); } 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 === 1100) { 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 === 1) { 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 === 4) { const schedule = event.changedProperties.schedule; if (schedule.state === 3) { this._joinState = 0; this._cleanup(); } this._observable.notifyObservers('onRoomStateUpdated', sceneId, schedule.state); } if (event.cause?.cmd === 8) { 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 === 700) { 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 === 1) { liveStreamingState = _type.FcrLiveStreamingState.STARTED; } if (state === 2) { liveStreamingState = _type.FcrLiveStreamingState.STOPPED; } this._observable.notifyObservers('onLiveStreamingStateUpdated', sceneId, liveStreamingState, pageUrl, reason); } }, onScenePropertiesDeleted: (sceneId, event) => { if (event.cause?.cmd === 8) { 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: (sceneId, event) => { if (event.cause?.cmd === 5 && event.modifiedUser.userId === this._scene.localUser.getLocalUserId()) { this._joinState = 0; this._cleanup(); } } }; } // @trace getSharingControl() { if (!this.sharingControl) { throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.NOT_JOINED_ROOM, 'sharing control not initialized, please join room first', new Error('sharing control not initialized, please join room first')); } return this.sharingControl; } // @trace getUserControl() { if (!this._userControl) { throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.NOT_JOINED_ROOM, 'user control not initialized, please join room first', new Error('user control not initialized, please join room first')); } return this._userControl; } // @trace getStreamControl() { if (!this._streamControl) { throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.NOT_JOINED_ROOM, 'stream control not initialized, please join room first', new Error('stream control not initialized, please join room first')); } return this._streamControl; } // @trace getRoomSessionControl() { if (!this._roomSessionControl) { throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.NOT_JOINED_ROOM, 'room session control not initialized, please join room first', new Error('room session control not initialized, please join room first')); } return this._roomSessionControl; } // @trace getChatRoomControl() { if (!this._chatRoomControl) { throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.NOT_JOINED_ROOM, 'chat room control not initialized, please join room first', new Error('chat room control not initialized, please join room first')); } return this._chatRoomControl; } // @trace getPrivilegeControl() { if (!this._privilegeControl) { throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.NOT_JOINED_ROOM, 'privilege control not initialized, please join room first', new Error('privilege control not initialized, please join room first')); } return this._privilegeControl; } // @trace getRoomConnectorControl() { if (!this._roomConnectorControl) { throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.NOT_JOINED_ROOM, 'room connector control not initialized, please join room first', new Error('room connector control not initialized, please join room first')); } return this._roomConnectorControl; } getAbilityControl() { if (!this._abilityControl) { throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.NOT_JOINED_ROOM, 'ability control not initialized, please join room first', new Error('ability control not initialized, please join room first')); } return this._abilityControl; } getSyncTimestamp() { return this._scene.getSyncTimestamp(); } 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; } getRoomSchedule() { if (!this._joinRoomSuccess) { throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.NOT_JOINED_ROOM, 'get schedule info failed, please join room first', new Error('get schedule info failed, please join room first')); } const schedule = this._scene.getScenePropertiesByKeyPath('schedule'); return { ...schedule, duration: schedule.duration ?? 0, startTime: Math.floor((schedule.startTime ?? 0) / 1000) }; } async join(options) { this._joinState = 1; if (this._joinRoomSuccess) { const fcrError = (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.JOIN_CONFLICT, 'join room failed, the room has been joined', new Error('join room failed, the room has been joined')); throw fcrError; } if (this._joining) { const fcrError = (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.JOIN_CONFLICT, 'join room failed, the previous join operation is not completed', new Error('join room failed, the previous join operation is not completed')); throw fcrError; } const isJoinStopped = () => { return this._joinState === 0; }; const handleJoinAborted = () => { if (this._joinState === 0) { this.logger.info('join is canceled'); this._cleanup(); const fcrError = (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.NOT_JOINED_ROOM, 'join is canceled', new Error('join is canceled')); this._observable.notifyObservers('onJoinRoomFailure', this._scene.sceneId, fcrError); throw fcrError; } }; try { this._joining = true; this._scene.addObserver(this._sceneObserver); this._engine.addObserver(this._engineObserver); let error = null; if ('snapshot' in options) { [error] = await (0, _imports.to)((async () => { await this._scene.join({ streamLatency: options.streamLatency, streamEncryptionConfig: options.streamEncryptionConfig, snapshot: options.snapshot, timestamp: options.timestamp }); handleJoinAborted(); })()); } else { const roomId = this._scene.sceneId; const { userId } = this._engine.getConfig(); [error] = await (0, _imports.to)((0, _imports.retryAttempt)(async () => { const res = await (0, _error.handleRequestError)(() => this._api.checkInInternal({ userName: options.userName, userId, userRole: _type.FcrUserRoleToStringMap[options.userRole], userProperties: options.userProperties, roomId, platform: options.platform ?? (0, _imports.getPlatform)(), streams: options.createStreamConfigs?.map(s => ({ videoSourceUuid: s.videoSourceId, audioSourceUuid: s.audioSourceId, streamName: s.streamName, ...(0, _imports.convertStreamTypeToPublishState)(s.streamType), videoSourceType: s.videoSourceType, audioSourceType: s.audioSourceType, audioSourceState: s.audioSourceState, videoSourceState: s.videoSourceState })), version: (0, _imports.getVersion)(), password: options.password }), _error.FcrErrorModuleCode.ROOM, 'check in internal failed'); handleJoinAborted(); const { data, ts } = res; const { streamLatency, streamEncryptionConfig } = options; await this._scene.join({ streamLatency, streamEncryptionConfig, snapshot: data, timestamp: ts }); handleJoinAborted(); }, [], { retriesMax: 10 }).fail(async _ref => { let { error, timeFn, currentRetry } = _ref; handleJoinAborted(); if (error instanceof _error.FcrError || error instanceof _imports.AgoraRteError) { this.logger.error(`join room failed, message: ${error.message}, code: ${error.code}`); if (_error.RTE_ERROR_CODES_NOT_RETRYABLE_WHEN_JOINING_ROOM.includes(error.code)) { this.logger.error(`cancel retry to join room, message: ${error.message}, code: ${error.code}`); throw error; } } this.logger.warn(`retry to join room, error message: ${error.message}, retry ${currentRetry} times`); await timeFn(); return true; }).exec()); } if (error) { this.logger.error(`join room failed, ${error.message}-${JSON.stringify(error)}`); this._observable.notifyObservers('onJoinRoomFailure', this._scene.sceneId, error); throw error; } 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)}`); } } finally { this._joining = false; } } async leave() { this._joinState = 0; 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 === 1) { return _type.FcrLiveStreamingState.STARTED; } if (liveStreamingState === 2) { 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 (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'send scene message failed', 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._whiteboardControl?.close(), this._scene.leave()]); } finally { this._joinRoomSuccess = false; } } _formatRecordingState(state, ready, onhold) { let recordState = _type.FcrRecordingState.Stopped; if (state === 1) { if (!ready) { recordState = _type.FcrRecordingState.Starting; } else { if (!onhold) { recordState = _type.FcrRecordingState.Started; } else { recordState = _type.FcrRecordingState.Paused; } } } return recordState; } _liveStreamingGenerateError = message => (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_LIVE_STREAMING, _error.FcrErrorCode.LOCAL_HTTP_REQUEST_FAILED, message, new Error(message)); async _liveStreamingAction(action, errorMessage) { try { const { code } = await action(); if (code !== 0) { throw this._liveStreamingGenerateError(errorMessage); } } catch (error) { throw this._liveStreamingGenerateError(errorMessage); } } } /** * @internal */ exports.FcrBaseRoomControlImpl = FcrBaseRoomControlImpl; class FcrSubRoomControlImpl extends FcrBaseRoomControlImpl {} exports.FcrSubRoomControlImpl = FcrSubRoomControlImpl;