agora-edu-core
Version:
Core APIs for building an online classroom
830 lines (800 loc) • 33.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.RoomStore = void 0;
require("core-js/modules/esnext.set.add-all.js");
require("core-js/modules/esnext.set.delete-all.js");
require("core-js/modules/esnext.set.difference.js");
require("core-js/modules/esnext.set.every.js");
require("core-js/modules/esnext.set.filter.js");
require("core-js/modules/esnext.set.find.js");
require("core-js/modules/esnext.set.intersection.js");
require("core-js/modules/esnext.set.is-disjoint-from.js");
require("core-js/modules/esnext.set.is-subset-of.js");
require("core-js/modules/esnext.set.is-superset-of.js");
require("core-js/modules/esnext.set.join.js");
require("core-js/modules/esnext.set.map.js");
require("core-js/modules/esnext.set.reduce.js");
require("core-js/modules/esnext.set.some.js");
require("core-js/modules/esnext.set.symmetric-difference.js");
require("core-js/modules/esnext.set.union.js");
var _agoraRteSdk = require("agora-rte-sdk");
var _get = _interopRequireDefault(require("lodash/get"));
var _mobx = require("mobx");
var _configs = require("../../../../configs");
var _eventCenter = require("../../../../event-center");
var _type = require("../../../../type");
var _error = require("../../../../utils/error");
var _base = require("../base");
var _commandHandler = _interopRequireDefault(require("./command-handler"));
var _type2 = require("./type");
var _error2 = require("../../../../services/error");
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _dec6, _class3, _descriptor4, _SceneEventHandler;
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = 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 _initializerDefineProperty(e, i, r, l) { r && Object.defineProperty(e, i, { enumerable: r.enumerable, configurable: r.configurable, writable: r.writable, value: r.initializer ? r.initializer.call(l) : void 0 }); }
function _applyDecoratedDescriptor(i, e, r, n, l) { var a = {}; return Object.keys(n).forEach(function (i) { a[i] = n[i]; }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function (r, n) { return n(i, e, r) || r; }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a; }
function _initializerWarningHelper(r, e) { throw Error("Decorating class property failed. Please ensure that transform-class-properties is enabled and runs after the decorators transform."); }
/**
* `RoomStore` 类用于初始化教室和监听教室数据。
*/
/** @en
* The `RoomStore` class is used for initializing rooms and listening for the room data.
*/
let RoomStore = exports.RoomStore = (_dec = _agoraRteSdk.Log.attach({
proxyMethods: false
}), _dec2 = _agoraRteSdk.Log.trace, _dec3 = _agoraRteSdk.Log.trace, _dec4 = _mobx.action.bound, _dec5 = _mobx.action.bound, _dec(_class = (_class2 = class RoomStore extends _base.EduStoreBase {
constructor() {
super(...arguments);
this._cmdHandler = new _commandHandler.default({
getUserById: userUuid => {
return this.classroomStore.userStore.users.get(userUuid);
},
getCurrentSceneId: () => {
return this.classroomStore.connectionStore.sceneId;
}
});
this._clientServerTimeShift = 0;
this._clockRefreshTask = void 0;
this._disposers = [];
this._customMessageObservers = new Set();
/**
* @internal
* 房间时钟
*/
/** @en
* @internal
* Clock time of the room
*/
_initializerDefineProperty(this, "_clockTime", _descriptor, this);
/**
* 教室日程信息
*/
/** @en
* Classroom schedule info
*/
_initializerDefineProperty(this, "classroomSchedule", _descriptor2, this);
_initializerDefineProperty(this, "_dataStore", _descriptor3, this);
}
/**
* @internal
*
* 主房间数据信息
**/
/** @en
* @internal
*
* main store datastore
*/
get mainRoomDataStore() {
const scene = this.classroomStore.connectionStore.mainRoomScene;
const handler = SceneEventHandler.getEventHandler(scene);
return handler.dataStore;
}
/**
* @internal
*
* 分组房间数据信息
**/
/** @en
* @internal
*
* sub store datastore
*/
get subRoomDataStore() {
const scene = this.classroomStore.connectionStore.subRoomScene;
const handler = SceneEventHandler.getEventHandler(scene);
return handler.dataStore;
}
/**
* 轮播设置
**/
/** @en
* Carousel setting
*/
get carousel() {
return this._dataStore.carousel;
}
/**
* 视频墙状态
*/
/** @en
* Expanded scope state
*/
get expandedScope() {
return this._dataStore.expandedScope;
}
/**
* 挥手的用户列表
**/
/** @en
* List of users which are waving arm
*/
get waveArmList() {
return this._dataStore.waveArmList;
}
/**
* 台上用户列表
**/
/** @en
* List of users which are on the stage
*/
get acceptedList() {
return this._dataStore.acceptedList;
}
/**
* 被邀请上台中的用户列表
*/
/** @en
* List of users which are being invited to the stage
*/
get inviteList() {
return this._dataStore.inviteList;
}
/**
* 自定义房间属性
**/
/** @en
* Custom room properties
*/
get flexProps() {
return this._dataStore.flexProps;
}
/**
* @internal
* @deprecated
*
* 伪直播属性
**/
/** @en
* @internal
* @deprecated
*
* hosting scene properties
*/
get hostingScene() {
var _this$_dataStore, _this$_dataStore$flex;
return (_this$_dataStore = this._dataStore) === null || _this$_dataStore === void 0 ? void 0 : (_this$_dataStore$flex = _this$_dataStore.flexProps) === null || _this$_dataStore$flex === void 0 ? void 0 : _this$_dataStore$flex.hostingScene;
}
/**
* 录制状态
**/
/** @en
* Record status
*/
get recordStatus() {
return this._dataStore.recordStatus;
}
/**
* 录制是否已经准备好
**/
/** @en
* Whether the recording has been ready
*/
get recordReady() {
return this._dataStore.recordReady;
}
/**
* 录制是否在暂停
**/
/** @en
* Whether the recording has been ready
*/
get recordOnHold() {
return this._dataStore.recordOnHold;
}
/**
* 录制生成的视频流地址
**/
/** @en
* Generated video stream addresses of the record
*/
get recordStreamingUrl() {
return this._dataStore.recordStreamingUrl;
}
/**
* 当前教室内正在进行的屏幕共享的流 UUID
* @en
* The stream UUID for screen sharing currently taking place in the classroom
*/
get screenShareStreamUuid() {
return this._dataStore.screenShareStreamUuid;
}
/**
* 当前教室内正在进行的屏幕共享的流所属的用户 UUID
* @en
* The user UUID to which the stream of the screen sharing currently taking place in the classroom belongs
*/
get screenShareUserUuid() {
return this._dataStore.screenShareUserUuid;
}
/**
* 当前用户是否在台上
*/
/** @en
* Whether the local user is on stage
*/
get isOnPodium() {
return this._dataStore.isOnPodium;
}
/**
* 房间时钟
*/
/** @en
* Clock time of the room
*/
get clockTime() {
return this._clockTime;
}
/**
* 当前是否在分享屏幕
*/
/** @en
* Whether the local user is currently sharing the screen
*/
get isScreenSharing() {
return this._dataStore.screenState === 1;
}
/** Methods */
startClockRefreshTask() {
if (!this._clockRefreshTask || this._clockRefreshTask.isStopped) {
this._clockRefreshTask = _agoraRteSdk.Scheduler.shared.addIntervalTask(this.tickClock, _agoraRteSdk.Scheduler.Duration.second(0.5));
}
}
_hanldeTimestampGapChange(timestamp) {
this._clientServerTimeShift = timestamp;
}
/** Actions */
/**
* 开始视频轮播
* @param params 轮播设置
**/
/** @en
* Starts the video gallery rotation
* @param params Carousel setting
*
*/
async startCarousel(params) {
try {
await this.api.startCarousel(_objectSpread({
roomUuid: this.classroomStore.connectionStore.sceneId,
count: 6
}, params));
} catch (err) {
_error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_CAROUSEL_START_FAIL, err);
}
}
/**
* 停止视频轮播
**/
/** @en
*
* Stops the video carousel rotation
*/
async stopCarousel() {
try {
await this.api.stopCarousel({
roomUuid: this.classroomStore.connectionStore.sceneId
});
} catch (err) {
_error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_CAROUSEL_STOP_FAIL, err);
}
}
/**
* 授予学生奖励
* @param rewards userUuid: 被奖励用户 UUID, changeRecord: 奖励数量
* @param isBatch 是否批量发奖励
**/
/** @en
* Sends rewards to users
* @param rewards userUuid: user being rewarded, changeRecord: reward quantity
* @param isBatch Whether sends records in a batch
*/
async sendRewards(rewards, isBatch) {
try {
await this.api.sendRewards({
roomUuid: this.classroomStore.connectionStore.sceneId,
rewards: rewards
}, isBatch);
} catch (err) {
_error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_SEND_STAR_FAIL, err);
}
}
/**
* 更新课堂状态
*
* @param state 课堂状态
**/
/** @en
* Updates the class state
*
* @param state The class state
*/
async updateClassState(state) {
try {
await this.api.updateClassState({
roomUuid: _configs.EduClassroomConfig.shared.sessionInfo.roomUuid,
state: state
});
} catch (err) {
_error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_UPDATE_CLASS_STATE_FAIL, err);
}
}
/**
* 更新房间自定义属性
* @param properties
* @param cause
*/
/** @en
* Updates room flex properties
* @param properties
* @param cause
*/
async updateFlexProperties(properties, cause) {
try {
await this.api.updateFlexProperties(_configs.EduClassroomConfig.shared.sessionInfo.roomUuid, {
properties,
cause
});
} catch (err) {
_error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_ROOM_FLEXPROPERTEIS_FAIL, err);
}
}
/**
* @internal
*
* 增量更新自定义属性
* @param increments
* @param cause
* @param throttleTime
*/
/** @en
* @internal
*
* Updates Increment properties
* @param increments
* @param cause
* @param throttleTime
*/
async updateIncrementProperties(increments, cause, throttleTime) {
try {
await this.api.updateFlexProperties(_configs.EduClassroomConfig.shared.sessionInfo.roomUuid, {
increments,
cause,
throttleTime
});
} catch (err) {
_error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_ROOM_FLEXPROPERTEIS_FAIL, err);
}
}
/**
* @internal
* @deprecated
*
* 更新伪直播属性
*
* @param properties 伪直播属性
**/
/** @en
* @deprecated
* @internal
*
* Updates the hosting scene live properties
*
* @param properties Hosting scene properties
*/
async updateHostingSceneProperties(properties, cause) {
try {
await this.api.updateFlexProperties(_configs.EduClassroomConfig.shared.sessionInfo.roomUuid, {
properties: {
hostingScene: properties
},
cause
});
} catch (err) {
_error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_ROOM_FLEXPROPERTEIS_FAIL, err);
}
}
/**
* 发送自定义频道消息
* @param cmd
* @param data
* @param sync
*/
/** @en
*
* @param cmd
* @param data
* @param sync
*/
async sendCustomChannelMessage(data) {
let needSync = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
try {
var _this$classroomStore$, _this$classroomStore$2;
await ((_this$classroomStore$ = this.classroomStore.connectionStore.scene) === null || _this$classroomStore$ === void 0 ? void 0 : (_this$classroomStore$2 = _this$classroomStore$.localUser) === null || _this$classroomStore$2 === void 0 ? void 0 : _this$classroomStore$2.sendCustomChannelMessage(_type2.FcrCustomMessageCommandType.flexMsg, data, needSync));
} catch (err) {
_error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_SEND_CUSTOM_CHANNEL_MESSAGE_FAIL, err);
}
}
/**
* 发送自定义点对点消息
* @param cmd
* @param data
* @param toUserUuid
* @param ack
*/
/** @en
*
* @param cmd
* @param data
* @param toUserUuid
* @param ack
*/
async sendCustomPeerMessage(data, toUserUuid) {
let needAck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
try {
var _this$classroomStore$3, _this$classroomStore$4;
await ((_this$classroomStore$3 = this.classroomStore.connectionStore.scene) === null || _this$classroomStore$3 === void 0 ? void 0 : (_this$classroomStore$4 = _this$classroomStore$3.localUser) === null || _this$classroomStore$4 === void 0 ? void 0 : _this$classroomStore$4.sendCustomPeerMessage(_type2.FcrCustomMessageCommandType.flexMsg, data, toUserUuid, needAck));
} catch (err) {
if (err.servCode === _error2.AGServiceErrorCode.SERV_USER_NOT_ONLINE) {
_error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_SEND_CUSTOM_PEER_MESSAGE_USER_NOT_ONLINE, err);
}
_error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_SEND_CUSTOM_PEER_MESSAGE_FAIL, err);
}
}
/**
* 增加一个自定义消息观察者
* @param observer
*/
/**
*
* @param observer
*/
addCustomMessageObserver(observer) {
this._customMessageObservers.add(observer);
}
/**
* 移除一个自定义消息观察者
* @param observer
*/
/**
*
* @param observer
*/
removeCustomMessageObserver(observer) {
this._customMessageObservers.delete(observer);
}
tickClock() {
this._clockTime = Date.now();
}
/**
* 服务器和本地时间的差(非可观察属性),单位:毫秒
**/
/** @en
* Difference between server and local time(non-observable), unit: milliseconds
*/
get clientServerTimeShift() {
return this._clientServerTimeShift;
}
_handleRoomPropertiesChange(changedRoomProperties, roomProperties, operator, cause) {
changedRoomProperties.forEach(key => {
if (key === 'compatibleVersion') {
const compatibleVersion = (0, _get.default)(roomProperties, 'compatibleVersion', []);
_configs.EduClassroomConfig.shared.setCompatibleVersions(compatibleVersion);
}
if (key === 'schedule') {
const startTime = (0, _get.default)(roomProperties, 'schedule.startTime');
startTime !== undefined && (this.classroomSchedule.startTime = startTime);
const duration = (0, _get.default)(roomProperties, 'schedule.duration');
duration !== undefined && (this.classroomSchedule.duration = duration);
const closeDelay = (0, _get.default)(roomProperties, 'schedule.closeDelay');
closeDelay !== undefined && (this.classroomSchedule.closeDelay = closeDelay);
const state = (0, _get.default)(roomProperties, 'schedule.state');
state !== undefined && (this.classroomSchedule.state = state);
}
});
}
//others
_addEventHandlers(scene) {
scene.on(_agoraRteSdk.AgoraRteEventType.RoomPropertyUpdated, this._handleRoomPropertiesChange);
scene.on(_agoraRteSdk.AgoraRteEventType.TimeStampGapUpdate, this._hanldeTimestampGapChange);
}
_removeEventHandlers(scene) {
scene.off(_agoraRteSdk.AgoraRteEventType.RoomPropertyUpdated, this._handleRoomPropertiesChange);
scene.off(_agoraRteSdk.AgoraRteEventType.TimeStampGapUpdate, this._hanldeTimestampGapChange);
}
_setEventHandler(scene) {
if (this.classroomStore.connectionStore.mainRoomScene === scene) {
let handler = SceneEventHandler.getEventHandler(scene);
if (!handler) {
handler = SceneEventHandler.createEventHandler(scene, this._cmdHandler);
}
this._dataStore = handler.dataStore;
} else {
const handler = SceneEventHandler.createEventHandler(scene, this._cmdHandler);
this._dataStore = handler.dataStore;
}
}
/**
* @internal
*/
/** @en
* @internal
*/
onInstall() {
this._disposers.push((0, _mobx.reaction)(() => {
return this.classroomStore.connectionStore.scene;
}, scene => {
if (scene) {
const eduObserver = {
onReceivePeerMessage: message => {
if (message.payload.cmd === _type2.FcrCustomMessageCommandType.flexMsg) {
this._customMessageObservers.forEach(observer => {
observer.onReceivePeerMessage({
fromUser: message.fromUser,
payload: message.payload.data
});
});
}
},
onReceiveChannelMessage: message => {
if (message.payload.cmd === _type2.FcrCustomMessageCommandType.flexMsg) {
this._customMessageObservers.forEach(observer => {
observer.onReceiveChannelMessage({
fromUser: message.fromUser,
payload: message.payload.data
});
});
}
}
};
scene.addCustomMessageObserver(eduObserver);
}
}));
this._disposers.push((0, _mobx.computed)(() => this.classroomStore.connectionStore.mainRoomScene).observe(_ref => {
let {
newValue,
oldValue
} = _ref;
if (oldValue) {
this._removeEventHandlers(oldValue);
}
if (newValue) {
// bind events
this._addEventHandlers(newValue);
}
}));
this._disposers.push((0, _mobx.computed)(() => this.classroomStore.connectionStore.scene).observe(_ref2 => {
let {
newValue,
oldValue
} = _ref2;
if (newValue) {
this._setEventHandler(newValue);
}
}));
// set schedule when checked in
this._disposers.push((0, _mobx.reaction)(() => this.classroomStore.connectionStore.mainRoomCheckInData, checkInData => {
if (checkInData) {
(0, _mobx.runInAction)(() => {
this._clientServerTimeShift = checkInData.clientServerTime - Date.now();
this.classroomSchedule = checkInData.classRoomSchedule;
});
}
}));
// stop task when class stopped
this._disposers.push((0, _mobx.reaction)(() => this.classroomSchedule.state, () => {
if (this.classroomSchedule.state === _type2.ClassState.close) {
var _this$_clockRefreshTa;
(_this$_clockRefreshTa = this._clockRefreshTask) === null || _this$_clockRefreshTa === void 0 ? void 0 : _this$_clockRefreshTa.stop();
}
_eventCenter.EduEventCenter.shared.emitClasroomEvents(_type.AgoraEduClassroomEvent.ClassStateChanged, this.classroomSchedule.state);
}));
// remove below when server can update class state to close automatically
this._disposers.push((0, _mobx.reaction)(() => this._clockTime, () => {
if (this.classroomSchedule.state === _type2.ClassState.afterClass) {
const {
duration = 0,
startTime = 0,
closeDelay
} = this.classroomSchedule;
const calibratedTime = Date.now() + this._clientServerTimeShift;
const isClosed = calibratedTime - startTime > (duration + closeDelay) * 1000;
if (isClosed) {
(0, _mobx.runInAction)(() => {
this.classroomSchedule.state = _type2.ClassState.close;
});
}
}
}));
// start room clock
this.startClockRefreshTask();
}
/**
* @internal
*/
/** @en
* @internal
*/
onDestroy() {
var _this$_clockRefreshTa2;
this._customMessageObservers.clear();
SceneEventHandler.cleanup();
(_this$_clockRefreshTa2 = this._clockRefreshTask) === null || _this$_clockRefreshTa2 === void 0 ? void 0 : _this$_clockRefreshTa2.stop();
this._disposers.forEach(d => d());
this._disposers = [];
}
}, _descriptor = _applyDecoratedDescriptor(_class2.prototype, "_clockTime", [_mobx.observable], {
configurable: true,
enumerable: true,
writable: true,
initializer: function () {
return 0;
}
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "classroomSchedule", [_mobx.observable], {
configurable: true,
enumerable: true,
writable: true,
initializer: function () {
return {
closeDelay: 0
};
}
}), _applyDecoratedDescriptor(_class2.prototype, "mainRoomDataStore", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "mainRoomDataStore"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "subRoomDataStore", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "subRoomDataStore"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "carousel", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "carousel"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "expandedScope", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "expandedScope"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "waveArmList", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "waveArmList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "acceptedList", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "acceptedList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "inviteList", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "inviteList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "flexProps", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "flexProps"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "hostingScene", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "hostingScene"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "recordStatus", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "recordStatus"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "recordReady", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "recordReady"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "recordOnHold", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "recordOnHold"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "recordStreamingUrl", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "recordStreamingUrl"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "screenShareStreamUuid", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "screenShareStreamUuid"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "screenShareUserUuid", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "screenShareUserUuid"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "isOnPodium", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "isOnPodium"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "clockTime", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "clockTime"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "isScreenSharing", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "isScreenSharing"), _class2.prototype), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "_dataStore", [_mobx.observable], {
configurable: true,
enumerable: true,
writable: true,
initializer: function () {
return {
carousel: {
state: 0,
type: 1,
range: 1,
interval: 10
},
waveArmList: [],
acceptedList: [],
inviteList: [],
flexProps: {},
recordStatus: _type2.RecordStatus.stopped,
recordReady: false,
recordOnHold: false,
isOnPodium: false,
recordStreamingUrl: undefined,
screenState: 0
};
}
}), _applyDecoratedDescriptor(_class2.prototype, "startCarousel", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "startCarousel"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "stopCarousel", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "stopCarousel"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "sendRewards", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "sendRewards"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "updateClassState", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "updateClassState"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "updateFlexProperties", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "updateFlexProperties"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "updateIncrementProperties", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "updateIncrementProperties"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "updateHostingSceneProperties", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "updateHostingSceneProperties"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "sendCustomChannelMessage", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "sendCustomChannelMessage"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "sendCustomPeerMessage", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "sendCustomPeerMessage"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "addCustomMessageObserver", [_agoraRteSdk.bound, _dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "addCustomMessageObserver"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "removeCustomMessageObserver", [_agoraRteSdk.bound, _dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "removeCustomMessageObserver"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "tickClock", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "tickClock"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "_handleRoomPropertiesChange", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "_handleRoomPropertiesChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "_setEventHandler", [_mobx.action], Object.getOwnPropertyDescriptor(_class2.prototype, "_setEventHandler"), _class2.prototype), _class2)) || _class);
let SceneEventHandler = (_dec6 = _mobx.action.bound, _class3 = (_SceneEventHandler = class SceneEventHandler {
static createEventHandler(scene, cmdHandler) {
if (SceneEventHandler._handlers[scene.sceneId]) {
SceneEventHandler._handlers[scene.sceneId].removeEventHandlers();
}
const handler = new SceneEventHandler(scene, cmdHandler);
handler.addEventHandlers();
SceneEventHandler._handlers[scene.sceneId] = handler;
return SceneEventHandler._handlers[scene.sceneId];
}
static getEventHandler(scene) {
return SceneEventHandler._handlers[scene.sceneId];
}
static cleanup() {
Object.keys(SceneEventHandler._handlers).forEach(k => {
SceneEventHandler._handlers[k].removeEventHandlers();
});
SceneEventHandler._handlers = {};
}
constructor(_scene, _cmdHandler) {
this._scene = _scene;
this._cmdHandler = _cmdHandler;
_initializerDefineProperty(this, "dataStore", _descriptor4, this);
}
addEventHandlers() {
this._scene.on(_agoraRteSdk.AgoraRteEventType.RoomPropertyUpdated, this._handleRoomPropertiesChange);
}
removeEventHandlers() {
this._scene.off(_agoraRteSdk.AgoraRteEventType.RoomPropertyUpdated, this._handleRoomPropertiesChange);
}
_handleRoomPropertiesChange(changedRoomProperties, roomProperties, operator, cause) {
changedRoomProperties.forEach(key => {
if (key === 'record') {
this.dataStore.recordStatus = (0, _get.default)(roomProperties, 'record.state', _type2.RecordStatus.stopped);
this.dataStore.recordReady = (0, _get.default)(roomProperties, 'record.ready', false);
this.dataStore.recordOnHold = (0, _get.default)(roomProperties, 'record.onhold', false);
this.dataStore.recordStreamingUrl = (0, _get.default)(roomProperties, 'record.streamingUrl', undefined);
}
if (key === 'processes') {
const handsUpList = (0, _get.default)(roomProperties, 'processes.handsUp.progress', []);
this.dataStore.inviteList = handsUpList;
const waveArmList = (0, _get.default)(roomProperties, 'processes.waveArm.progress', []);
this.dataStore.waveArmList = waveArmList;
const handsUpAcceptList = (0, _get.default)(roomProperties, 'processes.handsUp.accepted', []);
const waveArmAcceptList = (0, _get.default)(roomProperties, 'processes.waveArm.accepted', []);
this.dataStore.acceptedList = [].concat(handsUpAcceptList).concat(waveArmAcceptList);
this.dataStore.isOnPodium = this.getIsOnPodium(this.dataStore.acceptedList);
}
if (key === 'carousel') {
this.dataStore.carousel = {
interval: (0, _get.default)(roomProperties, 'carousel.interval', 10),
range: (0, _get.default)(roomProperties, 'carousel.range', 1),
type: (0, _get.default)(roomProperties, 'carousel.type', 1),
state: (0, _get.default)(roomProperties, 'carousel.state', 0)
};
}
if (key === 'expandedScope') {
this.dataStore.expandedScope = {
state: (0, _get.default)(roomProperties, 'expandedScope.state', 0),
userUuids: (0, _get.default)(roomProperties, 'expandedScope.userUuids', [])
};
}
if (key === 'screen') {
const screenData = (0, _get.default)(roomProperties, 'screen');
if (screenData.state === 1) {
this.dataStore.screenShareStreamUuid = screenData.streamUuid;
this.dataStore.screenShareUserUuid = screenData.userUuid;
}
this.dataStore.screenState = screenData.state;
}
if (key === 'flexProps') {
this.dataStore.flexProps = (0, _get.default)(roomProperties, 'flexProps', {});
}
});
// // execute commands
this._cmdHandler.exec(operator, cause, roomProperties, this._scene.sceneId);
}
getIsOnPodium() {
let acceptedList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
const sessionInfo = _configs.EduClassroomConfig.shared.sessionInfo;
return !!acceptedList.find(item => {
return item.userUuid === sessionInfo.userUuid;
});
}
}, _SceneEventHandler._handlers = {}, _SceneEventHandler), _descriptor4 = _applyDecoratedDescriptor(_class3.prototype, "dataStore", [_mobx.observable], {
configurable: true,
enumerable: true,
writable: true,
initializer: function () {
return {
carousel: {
state: 0,
type: 1,
range: 1,
interval: 10
},
waveArmList: [],
acceptedList: [],
inviteList: [],
flexProps: {},
recordStatus: _type2.RecordStatus.stopped,
recordReady: false,
recordOnHold: false,
isOnPodium: this.getIsOnPodium(),
recordStreamingUrl: undefined
};
}
}), _applyDecoratedDescriptor(_class3.prototype, "_handleRoomPropertiesChange", [_dec6], Object.getOwnPropertyDescriptor(_class3.prototype, "_handleRoomPropertiesChange"), _class3.prototype), _class3);