UNPKG

agora-edu-core

Version:

Core APIs for building an online classroom

1,261 lines (1,223 loc) 50 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MediaStore = exports.DEVICE_DISABLE = 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"); require("core-js/modules/esnext.map.delete-all.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"); var _agoraRteSdk = require("agora-rte-sdk"); var _mobx = require("mobx"); var _type = require("../../../../type"); var _ = require("../../../.."); var _error = require("../../../../utils/error"); var _base = require("../base"); var _type2 = require("./type"); var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor0, _descriptor1, _descriptor10, _descriptor11, _descriptor12, _descriptor13, _descriptor14, _descriptor15, _descriptor16, _descriptor17; 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."); } const DEVICE_DISABLE = exports.DEVICE_DISABLE = 'DEVICE_DISABLE'; /** * `MediaStore` 类用于媒体数据处理。 */ /** @en * The `MediaStore` class is used for processing media streams. */ let MediaStore = exports.MediaStore = (_dec = _agoraRteSdk.Log.attach({ proxyMethods: false }), _dec2 = _mobx.action.bound, _dec3 = _mobx.action.bound, _dec4 = _mobx.action.bound, _dec5 = _mobx.action.bound, _dec6 = _mobx.action.bound, _dec7 = _mobx.action.bound, _dec8 = _mobx.action.bound, _dec(_class = (_class2 = class MediaStore extends _base.EduStoreBase { constructor() { super(...arguments); this._disposers = new Set(); this._streamMediaTracks = new Map(); /** * 视频采集设备 **/ /** @en * The video capturing devices */ _initializerDefineProperty(this, "videoCameraDevices", _descriptor, this); /** * 音频采集设备 **/ /** @en * The audio sampling devices */ _initializerDefineProperty(this, "audioRecordingDevices", _descriptor2, this); /** * 音频播放设备 **/ /** @en * The audio playback devices */ _initializerDefineProperty(this, "audioPlaybackDevices", _descriptor3, this); /** * 当前视频采集设备 ID **/ /** @en * The ID of the current video capturing device */ _initializerDefineProperty(this, "cameraDeviceId", _descriptor4, this); /** * 当前音频采集设备 ID **/ /** @en * The ID of the current audio sampling device */ _initializerDefineProperty(this, "recordingDeviceId", _descriptor5, this); /** * 当前视频播放设备 ID **/ /** @en * The ID of the current video playback device */ _initializerDefineProperty(this, "playbackDeviceId", _descriptor6, this); /** * 本地视频采集设备状态 **/ /** @en * The state of the local video capturing device */ _initializerDefineProperty(this, "localCameraTrackState", _descriptor7, this); /** * 本地预览视频采集设备状态 **/ /** @en * The state of the local preview video capturing device */ _initializerDefineProperty(this, "localPreviewCameraTrackState", _descriptor8, this); /** * 本地音频采集设备状态 **/ /** @en * The state of the local audio sampling device */ _initializerDefineProperty(this, "localMicTrackState", _descriptor9, this); /** * 本地预览音频采集设备状态 **/ /** @en * The state of the local preview audio sampling device */ _initializerDefineProperty(this, "localPreviewMicTrackState", _descriptor0, this); /** * 本地屏幕采集设备状态 * **/ /** @en * The state of the local screen capturing device */ _initializerDefineProperty(this, "localScreenShareTrackState", _descriptor1, this); /** * 屏幕共享声音采集设备状态 **/ /** @en * The state of screen sharing of sound capturing device */ _initializerDefineProperty(this, "localScreenShareAudioTrackState", _descriptor10, this); /** * 本地声卡采集设备状态 * **/ /** @en * The state of the local loopback audio capturing device */ _initializerDefineProperty(this, "localLoopbackDeviceState", _descriptor11, this); /** * 当前采集屏幕设备 */ /** @en * Currently capturing screen device */ _initializerDefineProperty(this, "currentScreenShareDevice", _descriptor12, this); /** * 本地音频设备音量 * Range from [0,1] **/ /** @en * Local mic audio volume * range from [0,1] */ _initializerDefineProperty(this, "localMicAudioVolume", _descriptor13, this); /** * 本地预览音频设备音量 * range from [0,1] **/ /** @en * local preview mic audio volume * range from [0,1] */ _initializerDefineProperty(this, "localPreviewMicAudioVolume", _descriptor14, this); /** * 本地扬声器音量 * Range from [0,1] * **/ /** @en * Local playback test volume * Range from [0,1] */ _initializerDefineProperty(this, "localPlaybackTestVolume", _descriptor15, this); /** * 视频是否镜像 * **/ /** @en * Whether the video is mirrored */ _initializerDefineProperty(this, "isMirror", _descriptor16, this); _initializerDefineProperty(this, "_audioPlaybackDeviceEnabled", _descriptor17, this); this._previousCameraId = void 0; this._previousRecordingId = void 0; this._rawDataAdapterObservers = new Map(); } /** * @internal * * 获取多媒体控制器 **/ /** @en * @internal * * Get media control object */ get mediaControl() { var _this$classroomStore$; const agoraMediaControl = (_this$classroomStore$ = this.classroomStore.connectionStore.engine) === null || _this$classroomStore$ === void 0 ? void 0 : _this$classroomStore$.getAgoraMediaControl(); if (!agoraMediaControl) { return _error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_MEDIA_CONTROL_NOT_READY, new Error(`mediaControl undefined, not initialize?`)); } // handleThrowableError will throw an error so it's not possible to return undefined here return agoraMediaControl; } /** * 镜像开关 * @param v 开启或关闭 * **/ /** @en * Set mirror * @param v Enable mirror for local video or not */ setMirror(v) { this.isMirror = v; } /** * 设置音频裸数据回调参数 * 需要在加入教室前调用 * @param config 配置 **/ /** @en * Set the config for audio raw data callback * it needs called before join in the class * @param config config */ setAudioRawDataConfig(config, position) { if (typeof position === 'undefined') { position = _type2.FcrAudioRawDataPosition.record; } if (position === _type2.FcrAudioRawDataPosition.record) { this.mediaControl.createMicrophoneAudioTrack().setAudioRawDataConfig(config); } if (position === _type2.FcrAudioRawDataPosition.beforeMixed) { this.mediaControl.createStreamPlayer().setAudioRawDataConfig(config); } } /** * 增加一个音频裸数据观察者 * @param cb 订阅者 * **/ /** @en * Add an audio raw data observer * @param cb 订阅者 */ addAudioRawDataObserver(observer, position) { if (position === _type2.FcrAudioRawDataPosition.record) { this.mediaControl.createMicrophoneAudioTrack().addAudioRawDataObserver(observer); } if (position === _type2.FcrAudioRawDataPosition.beforeMixed) { this.mediaControl.createStreamPlayer().addAudioRawDataObserver(observer); } } /** * 删除音频裸数据数据观察者 * @param cb * **/ /** @en * Remove an audio raw data observer * @param cb */ removeAudioRawDataObserver(observer, position) { if (position === _type2.FcrAudioRawDataPosition.record) { this.mediaControl.createMicrophoneAudioTrack().removeAudioRawDataObserver(observer); } if (position === _type2.FcrAudioRawDataPosition.beforeMixed) { this.mediaControl.createStreamPlayer().removeAudioRawDataObserver(observer); } } /** * @deprecated * 增加一个本地音频裸数据观察者,使用 addAudioRawDataObserver 替代此方法 * @param cb 订阅者 * **/ /** @en * @deprecated * Add an audio raw data observer * @param cb 订阅者 */ addRawDataListener(cb) { let observer = this._rawDataAdapterObservers.get(cb); if (!observer) { observer = { onAudioRawDataRecored: data => { cb(data.buffer); }, onAudioRawDataBeforeMixed: () => {} }; this._rawDataAdapterObservers.set(cb, observer); } this.addAudioRawDataObserver(observer, _type2.FcrAudioRawDataPosition.record); } /** * @deprecated * 删除一个本地音频裸数据数据观察者,使用 removeAudioRawDataObserver 替代此方法 * @param cb * **/ /** @en * @deprecated * Remove an audio raw data observer * @param cb */ removeRawDataListener(cb) { const observer = this._rawDataAdapterObservers.get(cb); if (!observer) { return; } this.removeAudioRawDataObserver(observer, _type2.FcrAudioRawDataPosition.record); } /** * 设置本地摄像头视频编码器配置参数,影响本地采集视频的质量 * @param encoderConfig */ /** @en * Sets the video encoder configuration for the local camera device, which affects the quality of the local user video * @param encoderConfig */ setCameraVideoEncoderConfig(encoderConfig) { const { localCameraStreamUuid } = this.classroomStore.streamStore; if (localCameraStreamUuid) { var _this$classroomStore$2, _this$classroomStore$3; (_this$classroomStore$2 = this.classroomStore.connectionStore.scene) === null || _this$classroomStore$2 === void 0 ? void 0 : (_this$classroomStore$3 = _this$classroomStore$2.localUser) === null || _this$classroomStore$3 === void 0 ? void 0 : _this$classroomStore$3.setVideoEncoderConfig(encoderConfig, localCameraStreamUuid); } } /** * 设置本地屏幕视频编码器配置参数,影响本地采集视频的质量 * @param encoderConfig */ /** @en * Sets the video encoder configuration for the local screen device, which affects the quality of the local user video * @param encoderConfig */ setScreenVideoEncoderConfig(encoderConfig) { const { localShareStreamUuid } = this.classroomStore.streamStore; if (localShareStreamUuid) { var _this$classroomStore$4, _this$classroomStore$5; (_this$classroomStore$4 = this.classroomStore.connectionStore.scene) === null || _this$classroomStore$4 === void 0 ? void 0 : (_this$classroomStore$5 = _this$classroomStore$4.localUser) === null || _this$classroomStore$5 === void 0 ? void 0 : _this$classroomStore$5.setVideoEncoderConfig(encoderConfig, localShareStreamUuid); } } /** * 为视频设置显示区域 * @param dom 渲染节点 * @param mirror 是否开启镜像 * **/ /** @en * Setup local video * @param dom render node * @param mirror enable mirror */ setupLocalVideo(dom, mirror, renderMode) { const track = this.mediaControl.createCameraVideoTrack(); if (track) { track.setView(new _agoraRteSdk.AgoraRtcLocalVideoCanvas(dom, mirror, renderMode)); } } /** * 为屏幕共享设置显示区域 * @param dom 渲染节点 * **/ /** @en * Sets a node for rendering the local screen-sharing stream * @param dom The rendering node */ setupLocalScreenShare(dom) { const track = this.mediaControl.createScreenShareTrack(); if (track) { track.setView(new _agoraRteSdk.AgoraRtcLocalVideoCanvas(dom)); } } /** * 开启扬声器测试 * Electron 端不支持 Base64 格式的音频数据 * * @param url 资源地址 * **/ /** @en * Starts the playback device test * Base64 audio data not support on Electron platform * * @param url resouce url */ startPlaybackDeviceTest(url) { this.mediaControl.startAudioPlaybackDeviceTest(url); } /** * 停止扬声器测试 **/ /** @en * Stops the playback device test */ stopPlaybackDeviceTest() { this.mediaControl.stopAudioPlaybackDeviceTest(); } /** * 开启音频设备测试 * @param indicateInterval 探测频率(毫秒) * **/ /** @en * Starts the audio device test * @param indicateInterval The indication interval (ms). */ startRecordingDeviceTest(indicateInterval) { this.mediaControl.startAudioRecordingDeviceTest(indicateInterval); } /** * 停止音频设备测试 **/ /** @en * Stops the audio device test */ stopRecordingDeviceTest() { this.mediaControl.stopAudioRecordingDeviceTest(); } /** * 开启或关闭本地视频 * @param value boolean **/ /** @en * Enables or disables the local video * @param value boolean * */ enableLocalVideo(value) { if (value) { // open device if (this._previousCameraId) { this.setCameraDevice(this._previousCameraId); } else { this.setCameraDevice(this.videoCameraDevices[0].deviceid); } } else { // close device if (this.cameraDeviceId !== DEVICE_DISABLE) { this._previousCameraId = this.cameraDeviceId; this.setCameraDevice(DEVICE_DISABLE); } } } /** * 开启或关闭本地所有音频播放 * @param value */ /** @en * * @param value */ enableLocalPlayback(value) { this._audioPlaybackDeviceEnabled = value; } /** * 开启或关闭本地音频 * @param value boolean **/ /** @en * Enables or disables the local audio * @param value boolean */ enableLocalAudio(value) { if (value) { // open device if (this._previousRecordingId) { this.setRecordingDevice(this._previousRecordingId); } else { this.setRecordingDevice(this.audioRecordingDevices[0].deviceid); } } else { // close device if (this.recordingDeviceId !== DEVICE_DISABLE) { this._previousRecordingId = this.recordingDeviceId; this.setRecordingDevice(DEVICE_DISABLE); } } } /** * 设置当前正在屏幕共享的设备 * @param device */ /** @en * Set the device that is currently screen sharing * @param device */ setCurrentScreenShareDevice(device) { this.currentScreenShareDevice = device; } /** * 开始屏幕共享 * @param id 屏幕/窗口ID * @param type 屏幕分享数据源类型 * @param withAudio 是否分享声音/开启声卡采集 * @param audioDeviceName 声卡采集的设备名称,仅electron支持 * @param excludeWindowList 排除的窗口列表, 仅electron支持 */ startScreenShareCapture(params) { const track = this.mediaControl.createScreenShareTrack(); track.startWithParams(params); if (_agoraRteSdk.AgoraRteEngineConfig.platform === _agoraRteSdk.AgoraRteRuntimePlatform.Electron) { if ((params === null || params === void 0 ? void 0 : params.withAudio) && (params === null || params === void 0 ? void 0 : params.audioDeviceName)) { this.mediaControl.createLoopbackDevice().setDevice(params.audioDeviceName); } if (params === null || params === void 0 ? void 0 : params.withAudio) { this.mediaControl.createLoopbackDevice().startRecording(_agoraRteSdk.AGRtcConnectionType.main); } } } /** * 启动声卡采集 * @param params 可选参数对象,包括音频设备名称和连接类型 */ /** @en * Start loopback recording * @param params Optional parameter object, including audio device name and connection type */ startLoopbackRecording(params) { const device = this.mediaControl.createLoopbackDevice(); if (params === null || params === void 0 ? void 0 : params.audioDeviceName) { device.setDevice(params.audioDeviceName); } device.startRecording(params === null || params === void 0 ? void 0 : params.connType); } /** * 停止声卡采集 * @param params 可选参数对象,包括连接类型 */ /** @en * Stop loopback recording * @param params Optional parameter object, including connection type */ stopLoopbackRecording(params) { this.mediaControl.createLoopbackDevice().stopRecording(params === null || params === void 0 ? void 0 : params.connType); } /** * 停止屏幕共享 * withAudio: 是否同时关闭声卡采集,默认: True **/ /** @en * Stops sharing the screen * withAudio: whether to close loopback recording simultaneously, Default to: True */ stopScreenShareCapture(params) { var _params$withAudio; const withAudio = (_params$withAudio = params === null || params === void 0 ? void 0 : params.withAudio) !== null && _params$withAudio !== void 0 ? _params$withAudio : true; const track = this.mediaControl.createScreenShareTrack(); track.stop(); if (withAudio) { this.mediaControl.createLoopbackDevice().stopRecording(_agoraRteSdk.AGRtcConnectionType.main); } } /** * 检测是否可以获取到屏幕采集设备列表 * @returns 是否可获取到屏幕采集设备列表 **/ /** @en * Checks whether a list of screen capture devices can be obtained * @returns Whether a list of screen capture devices can be obtained */ isScreenDeviceEnumerateSupported() { return this.mediaControl.isScreenDeviceEnumerateSupported(); } /** * 检测是否有屏幕采集权限 * @returns 是否有屏幕采集的权限 **/ /** @en * Check whether the permission of screen capture is granted * @returns Whether the permission for screen capture is granted */ hasScreenSharePermission() { return this.mediaControl.hasScreenSharePermission(); } /** * 获取可采集应用窗口列表 * @returns 应用窗口列表 **/ /** @en * Gets a list of application windows that can be captured * @returns A list of application windows */ getWindowDevices() { return this.mediaControl.getWindowDevices(); } /** * 获取可采集的屏幕列表 * @returns 屏幕列表 **/ /** @en * Gets a list of display devices that can be captured * @returns A list of application windows */ getDisplayDevices() { return this.mediaControl.getDisplayDevices(); } /** * 设置视频设备 ID * @param id 设备 ID **/ /** @en * Sets the local camera device ID * @param id Device ID */ setCameraDevice(id) { this.cameraDeviceId = id; } /** * 设置音频设备 ID * @param id 设备 ID * **/ /** @en * Sets the local recording device ID * @param id Device ID */ setRecordingDevice(id) { this.recordingDeviceId = id; } /** * 设置扬声器设备 ID * @param id 设备 ID **/ /** @en * set playback device ID * @param id Device ID */ setPlaybackDevice(id) { this.playbackDeviceId = id; } /** * 更新本地媒体状态 * @param param0 视频状态和音频状态 **/ /** @en * Updates the local media state * @param param0 The video state and audio state */ async updateLocalMediaState(_ref) { let { videoSourceState, audioSourceState } = _ref; try { const scene = this.classroomStore.connectionStore.scene; if (scene) { var _scene$localUser; await ((_scene$localUser = scene.localUser) === null || _scene$localUser === void 0 ? void 0 : _scene$localUser.updateLocalMediaState({ videoSourceState, audioSourceState })); } } catch (e) { _error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_MEDIA_UPDATE_DEVICE_STATE_FAIL, e); } } /** * 开启双流 * @param enable 是否开启 * @param connectionType RTC 连接 */ /** @en * Enables dual stream * @param enable Whether to enable * @param connectionType RTC connection */ async enableDualStream(enable, connectionType, fromScene) { try { const scene = fromScene || this.classroomStore.connectionStore.scene; if (scene) { await scene.enableDualStream(enable, connectionType); } } catch (e) { _error.EduErrorCenter.shared.handleNonThrowableError(_error.AGEduErrorCode.EDU_ERR_ENABLE_DUAL_STREAM_FAIL, e); } } /** * 设置小流分辨率及码率 * @param setLowStreamParameter 要设置的小流参数 * @param connectionType RTC 连接 */ /** @en * Sets resolution and frame rate of the low-quality stream * @param setLowStreamParameter Parameter used to set the low-quality stream * @param connectionType RTC connection */ setLowStreamParameter(setLowStreamParameter, connectionType, fromScene) { try { const scene = fromScene || this.classroomStore.connectionStore.scene; if (scene) { scene.setLowStreamParameter(setLowStreamParameter, connectionType); } } catch (e) { _error.EduErrorCenter.shared.handleThrowableError(_error.AGEduErrorCode.EDU_ERR_SET_LOW_STREAM_PARAMETER_FAIL, new Error(`failed to set low stream parameter`)); } } /** * 播放流媒体 * @param streamUrl hls url * @param dom * @param mirror * @param playVideo * @param playAudio */ /** @en * Play a media stream * @param streamUrl hls url * @param dom * @param mirror * @param playVideo * @param playAudio * */ setupMediaStream(streamUrl, dom, mirror, playVideo, playAudio) { let track = this._streamMediaTracks.get(streamUrl); if (!track) { track = this.mediaControl.createStreamMediaTrack(); this._streamMediaTracks.set(streamUrl, track); } const canvas = new _agoraRteSdk.AgoraMediaPlayerCanvas(streamUrl, dom, { mirror, playVideo, playAudio }); if (!playVideo && !playAudio) { track.stop(); } else { track.setView(canvas); track.setPlayVideo(playVideo); track.setPlayAudio(playAudio); track.start(); } } /** * 通过 URL 获取流媒体播放器 * @param streamUrl 要播放的视频流地址 * @returns 视频播放器对象,用于控制音视频播放 */ /** @en * Get a stream media track by stream URL * @param streamUrl Video URL to play * @returns Video player object that controls audio and video playback */ getMediaTrackPlayer(streamUrl) { const mediaTrack = this._streamMediaTracks.get(streamUrl); return mediaTrack === null || mediaTrack === void 0 ? void 0 : mediaTrack.player; } /** * 视频截图(此接口仅 Electron 支持)。 * 截取指定房间内的指定视频流,生成 JPG 图片保存到本地。 * @param channel RTC 频道名称,使用 roomUuid。 * @param streamUuid 流 ID。 * @param filePath 保存图片的本地绝对路径。 * @returns 截图信息 */ /** @en * Takes a snapshot from a video stream (Only for Electron). * The snapshot is saved to the local folder that you specify in the JPG format. * @param channel The ID of the RTC channel. You can set this parameter as roomUuid. * @param streamUuid The stream ID. * @param filePath The absolute path for saving the snapshot. * @returns Snapshot info */ getSnapshot(channel, streamUuid, filePath) { const stream = this.classroomStore.streamStore.streamByStreamUuid.get(streamUuid.toString()); if (stream) { return this.mediaControl.takeSnapshot(channel, stream.isLocal ? 0 : streamUuid, filePath); } else { this.logger.info('getSnapshot => failed. Stream not exist'); return Promise.reject(); } } /** * 视频截图(此接口仅 Web 支持)。 * 截取指定房间内的指定视频流。此方法返回携带 RGBA 信息的 [ImageData](https://developer.mozilla.org/zh-CN/docs/Web/API/ImageData) 数据。 * @param channel RTC 频道名称,可使用 roomUuid。 * @param streamUuid 流 ID。 * @returns 截图信息 */ /** @en * Takes a snapshot from a video stream (Only for Web). * This method returns an [ImageData](https://developer.mozilla.org/en-US/docs/Web/API/ImageData) object, which contains the data in the RGBA order. * @param channel The ID of the RTC channel. You can set this parameter as roomUuid. * @param streamUuid The stream ID. * @returns Snapshot info */ getSnapshotRgba(channel, streamUuid) { const stream = this.classroomStore.streamStore.streamByStreamUuid.get(streamUuid.toString()); if (stream) { return this.mediaControl.getCurrentFrameData(channel, streamUuid.toString(), stream.isLocal); } else { this.logger.info('getSnapshotRgba => failed. Stream not exist'); } } /** * 增加摄像头视频流前处理器 * @param processors 视频采集前处理器 */ /** @en * @param processors preprocessor for the camera track * Adds the pre-processors to the local camera track */ addCameraProcessors(processors) { this.mediaControl.createCameraVideoTrack().addProcessors(processors); } /** * 移除摄像头视频流处理器 */ /** @en * Removes all camera track processors */ removeCameraProcessors() { this.mediaControl.createCameraVideoTrack().removeProcessors(); } /** * 增加麦克风音频流前处理器 * @param processors 音频采集前处理器 */ /** @en * Adds the pre-processors to the local microphone track * @param processors preprocessor for the microphone track */ addMicrophoneProcessors(processors) { this.mediaControl.createMicrophoneAudioTrack().addProcessors(processors); } /** * 移除麦克风音频流处理器 */ /** @en * Removes all microphone track processors */ removeMicrophoneProcessors() { this.mediaControl.createMicrophoneAudioTrack().removeProcessors(); } /** * 增加摄像头视频流前处理器(预览) * @param processors */ /** @en * @param processors * Adds the pre-processors to the local camera track(For preview) */ addPreviewCameraProcessors(processors) { this.mediaControl.createCameraVideoTrack().addPreviewProcessors(processors); } /** * 移除摄像头视频流处理器(预览) */ /** @en * Removes all camera track processors(For preview) */ removePreviewCameraProcessors() { this.mediaControl.createCameraVideoTrack().removePreviewProcessors(); } /** * 增加麦克风音频流前处理器(预览) * @param processors */ /** @en * Adds the pre-processors to the local microphone track(For preview) * @param processors */ addPreviewMicrophoneProcessors(processors) { this.mediaControl.createMicrophoneAudioTrack().addPreviewProcessors(processors); } /** * 移除麦克风音频流处理器(预览) */ /** @en * Removes all microphone track processors(For preview) */ removePreviewMicrophoneProcessors() { this.mediaControl.createMicrophoneAudioTrack().removePreviewProcessors(); } /** * @internal */ onInstall() { const store = this.classroomStore; this._disposers.add((0, _mobx.reaction)(() => store.connectionStore.engine, engine => { if (engine) { const mediaControl = this.mediaControl; mediaControl.on(_agoraRteSdk.AgoraMediaControlEventType.cameraListChanged, (_added, _newDevices, allDevices) => { (0, _mobx.runInAction)(() => { this.videoCameraDevices = allDevices.concat([{ deviceid: DEVICE_DISABLE, devicename: '' }]); }); }); mediaControl.on(_agoraRteSdk.AgoraMediaControlEventType.playbackDeviceListChanged, (_added, _newDevices, allDevices) => { (0, _mobx.runInAction)(() => { this.audioPlaybackDevices = allDevices; }); }); mediaControl.on(_agoraRteSdk.AgoraMediaControlEventType.recordingDeviceListChanged, (_added, _newDevices, allDevices) => { (0, _mobx.runInAction)(() => { this.audioRecordingDevices = allDevices.concat([{ deviceid: DEVICE_DISABLE, devicename: '' }]); }); }); mediaControl.on(_agoraRteSdk.AgoraMediaControlEventType.localAudioVolume, volume => { (0, _mobx.runInAction)(() => { this.localMicAudioVolume = volume; }); }); mediaControl.on(_agoraRteSdk.AgoraMediaControlEventType.localPreviewAudioVolume, volume => { (0, _mobx.runInAction)(() => { this.localPreviewMicAudioVolume = volume; }); }); mediaControl.on(_agoraRteSdk.AgoraMediaControlEventType.localVideoTrackChanged, (state, type, reason, withAudio) => { (0, _mobx.runInAction)(() => { if (type === _agoraRteSdk.AgoraRteVideoSourceType.Camera) { this.localCameraTrackState = state; // this.localCameraErrorReason = reason; } else if (type === _agoraRteSdk.AgoraRteVideoSourceType.ScreenShare) { this.localScreenShareTrackState = state; if (reason === _agoraRteSdk.AGRteTrackErrorReason.PermissionDenied) { _.EduEventCenter.shared.emitClasroomEvents(_type.AgoraEduClassroomEvent.CaptureScreenPermissionDenied); } if (withAudio) { this.localScreenShareAudioTrackState = state; } } }); }); mediaControl.on(_agoraRteSdk.AgoraMediaControlEventType.localPreviewVideoTrackChanged, state => { (0, _mobx.runInAction)(() => { this.localPreviewCameraTrackState = state; }); }); mediaControl.on(_agoraRteSdk.AgoraMediaControlEventType.localAudioTrackChanged, (state, type) => { (0, _mobx.runInAction)(() => { if (type === _agoraRteSdk.AgoraRteAudioSourceType.Mic) { this.localMicTrackState = state; } if (type === _agoraRteSdk.AgoraRteAudioSourceType.Loopback) { this.localLoopbackDeviceState = state; } }); }); mediaControl.on(_agoraRteSdk.AgoraMediaControlEventType.localPreviewAudioTrackChanged, state => { (0, _mobx.runInAction)(() => { this.localPreviewMicTrackState = state; }); }); mediaControl.on(_agoraRteSdk.AgoraMediaControlEventType.localAudioPlaybackVolumeIndicator, volume => { (0, _mobx.runInAction)(() => { this.localPlaybackTestVolume = volume; }); }); // this must come last after event listener is registered (0, _mobx.runInAction)(() => { this.videoCameraDevices = mediaControl.getVideoCameraList().concat([{ deviceid: DEVICE_DISABLE, devicename: '' }]); this.audioRecordingDevices = mediaControl.getAudioRecordingList().concat([{ deviceid: DEVICE_DISABLE, devicename: '' }]); this.audioPlaybackDevices = mediaControl.getAudioPlaybackList(); }); } else { //clean up } })); const deviceStateConvertionMap = { [_agoraRteSdk.AgoraRteMediaSourceState.started]: 1, [_agoraRteSdk.AgoraRteMediaSourceState.starting]: 1, [_agoraRteSdk.AgoraRteMediaSourceState.stopped]: 2, [_agoraRteSdk.AgoraRteMediaSourceState.error]: 0 }; this._disposers.add((0, _mobx.reaction)(() => this.localCameraTrackState, () => { const { userUuid } = _.EduClassroomConfig.shared.sessionInfo; const roomUuid = _.EduClassroomConfig.shared.sessionInfo.roomUuid; _.EduClassroomConfig.shared.isLowAPIVersionCompatibleRequired && this.classroomStore.connectionStore.classroomState === _type.ClassroomState.Connected && this.classroomStore.api.reportMicCameraStateLeagcy({ userUuid, roomUuid, data: { camera: deviceStateConvertionMap[this.localCameraTrackState] } }); })); this._disposers.add((0, _mobx.reaction)(() => this.localMicTrackState, () => { const { userUuid } = _.EduClassroomConfig.shared.sessionInfo; const roomUuid = _.EduClassroomConfig.shared.sessionInfo.roomUuid; _.EduClassroomConfig.shared.isLowAPIVersionCompatibleRequired && this.classroomStore.connectionStore.classroomState === _type.ClassroomState.Connected && this.classroomStore.api.reportMicCameraStateLeagcy({ userUuid, roomUuid, data: { mic: deviceStateConvertionMap[this.localMicTrackState] } }); })); this._disposers.add((0, _mobx.reaction)(() => this.localScreenShareTrackState, localScreenShareTrackState => { if (localScreenShareTrackState === _agoraRteSdk.AgoraRteMediaSourceState.stopped) { (0, _mobx.runInAction)(() => { this.currentScreenShareDevice = undefined; }); } })); // 处理视频设备变动 this._disposers.add((0, _mobx.computed)(() => this.classroomStore.mediaStore.videoCameraDevices).observe(_ref2 => { let { newValue, oldValue } = _ref2; const { cameraDeviceId } = this.classroomStore.mediaStore; // 避免初始化阶段触发新设备的弹窗通知 if (oldValue && oldValue.length > 1) { const inOldList = oldValue.find(v => v.deviceid === cameraDeviceId); const inNewList = newValue.find(v => v.deviceid === cameraDeviceId); if (inOldList && !inNewList) { _.EduEventCenter.shared.emitClasroomEvents(_type.AgoraEduClassroomEvent.CurrentCamUnplugged); } } })); // 处理录音设备变动 this._disposers.add((0, _mobx.computed)(() => this.classroomStore.mediaStore.audioRecordingDevices).observe(_ref3 => { let { newValue, oldValue } = _ref3; const { recordingDeviceId } = this.classroomStore.mediaStore; // 避免初始化阶段触发新设备的弹窗通知 if (oldValue && oldValue.length > 1) { const inOldList = oldValue.find(v => v.deviceid === recordingDeviceId); const inNewList = newValue.find(v => v.deviceid === recordingDeviceId); if (inOldList && !inNewList) { _.EduEventCenter.shared.emitClasroomEvents(_type.AgoraEduClassroomEvent.CurrentMicUnplugged); } } })); // 处理扬声器设备变动 this._disposers.add((0, _mobx.computed)(() => this.classroomStore.mediaStore.audioPlaybackDevices).observe(_ref4 => { let { newValue, oldValue } = _ref4; const { playbackDeviceId } = this.classroomStore.mediaStore; // 避免初始化阶段触发新设备的弹窗通知 if (oldValue && oldValue.length > 0) { const inOldList = oldValue.find(v => v.deviceid === playbackDeviceId); const inNewList = newValue.find(v => v.deviceid === playbackDeviceId); if (inOldList && !inNewList) { _.EduEventCenter.shared.emitClasroomEvents(_type.AgoraEduClassroomEvent.CurrentSpeakerUnplugged); } } })); } /** * @internal */ onDestroy() { this.setCameraDevice(DEVICE_DISABLE); this.setRecordingDevice(DEVICE_DISABLE); for (const disposer of this._disposers) { disposer(); } this._disposers.clear(); } }, _descriptor = _applyDecoratedDescriptor(_class2.prototype, "videoCameraDevices", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return []; } }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "audioRecordingDevices", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return []; } }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "audioPlaybackDevices", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return []; } }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "cameraDeviceId", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: null }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "recordingDeviceId", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: null }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "playbackDeviceId", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: null }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "localCameraTrackState", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return _agoraRteSdk.AgoraRteMediaSourceState.stopped; } }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "localPreviewCameraTrackState", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return _agoraRteSdk.AgoraRteMediaSourceState.stopped; } }), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "localMicTrackState", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return _agoraRteSdk.AgoraRteMediaSourceState.stopped; } }), _descriptor0 = _applyDecoratedDescriptor(_class2.prototype, "localPreviewMicTrackState", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return _agoraRteSdk.AgoraRteMediaSourceState.stopped; } }), _descriptor1 = _applyDecoratedDescriptor(_class2.prototype, "localScreenShareTrackState", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return _agoraRteSdk.AgoraRteMediaSourceState.stopped; } }), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "localScreenShareAudioTrackState", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return _agoraRteSdk.AgoraRteMediaSourceState.stopped; } }), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "localLoopbackDeviceState", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return _agoraRteSdk.AgoraRteMediaSourceState.stopped; } }), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "currentScreenShareDevice", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: null }), _descriptor13 = _applyDecoratedDescriptor(_class2.prototype, "localMicAudioVolume", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return 0; } }), _descriptor14 = _applyDecoratedDescriptor(_class2.prototype, "localPreviewMicAudioVolume", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return 0; } }), _descriptor15 = _applyDecoratedDescriptor(_class2.prototype, "localPlaybackTestVolume", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return 0; } }), _descriptor16 = _applyDecoratedDescriptor(_class2.prototype, "isMirror", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return false; } }), _descriptor17 = _applyDecoratedDescriptor(_class2.prototype, "_audioPlaybackDeviceEnabled", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return true; } }), _applyDecoratedDescriptor(_class2.prototype, "setMirror", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "setMirror"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setAudioRawDataConfig", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "setAudioRawDataConfig"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "addAudioRawDataObserver", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "addAudioRawDataObserver"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "removeAudioRawDataObserver", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "removeAudioRawDataObserver"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "addRawDataListener", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "addRawDataListener"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "removeRawDataListener", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "removeRawDataListener"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setupLocalVideo", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "setupLocalVideo"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setupLocalScreenShare", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "setupLocalScreenShare"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "startPlaybackDeviceTest", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "startPlaybackDeviceTest"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "stopPlaybackDeviceTest", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "stopPlaybackDeviceTest"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "startRecordingDeviceTest", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "startRecordingDeviceTest"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "stopRecordingDeviceTest", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "stopRecordingDeviceTest"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "enableLocalVideo", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "enableLocalVideo"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "enableLocalPlayback", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "enableLocalPlayback"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "enableLocalAudio", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "enableLocalAudio"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setCurrentScreenShareDevice", [_mobx.action], Object.getOwnPropertyDescriptor(_class2.prototype, "setCurrentScreenShareDevice"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "startScreenShareCapture", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "startScreenShareCapture"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "startLoopbackRecording", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "startLoopbackRecording"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "stopScreenShareCapture", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "stopScreenShareCapture"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "isScreenDeviceEnumerateSupported", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "isScreenDeviceEnumerateSupported"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "hasScreenSharePermission", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "hasScreenSharePermission"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getWindowDevices", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "getWindowDevices"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getDisplayDevices", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "getDisplayDevices"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setCameraDevice", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "setCameraDevice"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setRecordingDevice", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "setRecordingDevice"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setPlaybackDevice", [_dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "setPlaybackDevice"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "updateLocalMediaState", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "updateLocalMediaState"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "enableDualStream", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "enableDualStream"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setLowStreamParameter", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "setLowStreamParameter"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setupMediaStream", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "setupMediaStream"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getMediaTrackPlayer", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "getMediaTrackPlayer"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getSnapshot", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "getSnapshot"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getSnapshotRgba", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "getSnapshotRgba"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "addCameraProcessors", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "addCameraProcessors"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "removeCameraProcessors", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "removeCameraProcessors"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "addMicrophoneProcessors", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "addMicrophoneProcessors"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "removeMicrophoneProcessors", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "removeMicrophoneProcessors"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "addPreviewCameraProcessors", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "addPreviewCameraProcessors"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "removePreviewCameraProcessors", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "removePreviewCameraProcessors"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "addPreviewMicrophoneProcessors", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "addPreviewMicrophoneProcessors"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "removePreviewMicrophoneProcessors", [_agoraRteSdk.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "removePreviewMicrophoneProcessors"), _class2.prototype), _class2)) || _class);