UNPKG

agora-edu-core

Version:

Core APIs for building an online classroom

160 lines (158 loc) 6.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReportStore = void 0; var _agoraRteSdk = require("agora-rte-sdk"); var _mobx = require("mobx"); var _configs = require("../../../../configs"); var _reportV = require("../../../../services/report-v2"); var _type = require("../../../../type"); var _error = require("../../../../utils/error"); var _base = require("../base"); var _class; 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; } /** * `ReportStore` 监听教室状态,上报教室数据。 */ /** @en * `ReportStore` monitors classroom status and report classroom data. */ let ReportStore = exports.ReportStore = (_class = class ReportStore extends _base.EduStoreBase { constructor() { super(...arguments); this._disposers = []; } get currentTime() { return new Date().getTime(); } get screenShareStreamAccessor() { return { rtcState: this.classroomStore.connectionStore.rtcSubState, localShareStreamUuid: this.classroomStore.streamStore.localShareStreamUuid }; } _handleError(code) { if (code === _error.AGEduErrorCode.EDU_ERR_MEDIA_START_SCREENSHARE_FAIL) { _reportV.ReportServiceV2.shared.reportScreenShareStart(this.currentTime, +code); } else if (code === _error.AGEduErrorCode.EDU_ERR_MEDIA_STOP_SCREENSHARE_FAIL) { _reportV.ReportServiceV2.shared.reportScreenShareEnd(this.currentTime, +code); } } onInstall() { _error.EduErrorCenter.shared.on('error', this._handleError); this._disposers.push((0, _mobx.computed)(() => this.screenShareStreamAccessor).observe(_ref => { let { oldValue, newValue } = _ref; const { localShareStreamUuid, rtcState } = newValue; if (localShareStreamUuid && rtcState === _agoraRteSdk.AGRtcState.Connected) { _reportV.ReportServiceV2.shared.reportScreenShareStart(this.currentTime, 0); } else if ((oldValue === null || oldValue === void 0 ? void 0 : oldValue.rtcState) === _agoraRteSdk.AGRtcState.Connected && rtcState === _agoraRteSdk.AGRtcState.Idle) { _reportV.ReportServiceV2.shared.reportScreenShareEnd(this.currentTime, 0); } })); this._disposers.push((0, _mobx.computed)(() => this.classroomStore.connectionStore.classroomState).observe(_ref2 => { let { oldValue, newValue } = _ref2; if (oldValue === _type.ClassroomState.Reconnecting && newValue === _type.ClassroomState.Connected) { _reportV.ReportServiceV2.shared.reportApaasUserReconnect(this.currentTime, 0); } })); this._disposers.push((0, _mobx.reaction)(() => { return this.classroomStore.connectionStore.classroomState; }, classroomState => { if (classroomState === _type.ClassroomState.Connected) { var _scene$localUser; const { vid } = this.classroomStore.connectionStore.mainRoomCheckInData; const { scene } = this.classroomStore.connectionStore; if (isNaN(vid) || vid === null || !scene) { return _agoraRteSdk.Logger.warn(`no vid/scene when initializing report params, report data may be inaccurate`); } const createdTs = scene.createTs; if (!createdTs) { return _agoraRteSdk.Logger.warn(`no scene created ts, report data may be inaccurate`); } const streamUuid = ((_scene$localUser = scene.localUser) === null || _scene$localUser === void 0 ? void 0 : _scene$localUser.streamUuid) || '0'; //initialize rtc connection const { sessionInfo } = _configs.EduClassroomConfig.shared; const userRoleMap = { '-1': 'none', '0': 'invisible', '1': 'teacher', '2': 'student', '3': 'assistant' }; const reportUserParams = { vid, ver: _configs.EduClassroomConfig.getVersion(), scenario: 'education', uid: sessionInfo.userUuid, userName: sessionInfo.userName, /** * rtc流id */ streamUid: +streamUuid, streamSuid: streamUuid, /** * apaas角色 */ role: userRoleMap[sessionInfo.role], /** * rtc sid */ streamSid: scene.rtcSid, /** * rtm sid */ rtmSid: scene.rtmSid, /** * apaas房间id,与rtc/rtm channelName相同 */ roomId: sessionInfo.roomUuid, /** * 房间创建的时间戳 */ roomCreateTs: createdTs }; _reportV.ReportServiceV2.shared.initReportUserParams(reportUserParams); } })); this._disposers.push((0, _mobx.computed)(() => this.classroomStore.connectionStore.rtcState).observe(_ref3 => { let { oldValue, newValue } = _ref3; if (oldValue === _agoraRteSdk.AGRtcState.Connecting && newValue === _agoraRteSdk.AGRtcState.Connected) { const { scene } = this.classroomStore.connectionStore; if (scene === null || scene === void 0 ? void 0 : scene.rtcSid) { _reportV.ReportServiceV2.shared.updateRtcSessionId(scene === null || scene === void 0 ? void 0 : scene.rtcSid); } //connected _reportV.ReportServiceV2.shared.reportApaasUserJoin(this.currentTime, 0); } else if (oldValue === _agoraRteSdk.AGRtcState.Connected && newValue === _agoraRteSdk.AGRtcState.Idle) { //disconnected _reportV.ReportServiceV2.shared.reportApaasUserQuit(this.currentTime, 0); } })); } onDestroy() { _error.EduErrorCenter.shared.off('error', this._handleError); this._disposers.forEach(d => d()); this._disposers = []; } }, _applyDecoratedDescriptor(_class.prototype, "screenShareStreamAccessor", [_mobx.computed], Object.getOwnPropertyDescriptor(_class.prototype, "screenShareStreamAccessor"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "_handleError", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class.prototype, "_handleError"), _class.prototype), _class);