UNPKG

agora-edu-core

Version:

Core APIs for building an online classroom

628 lines (627 loc) 18.4 kB
import { AGRtcDeviceInfo, AgoraRteMediaSourceState, AgoraMediaControl, AGScreenShareDevice, AGScreenShareType, AGRtcConnectionType, AGLowStreamParameter, AgoraRteScene, AGRenderMode, AGVideoEncoderConfigurations } from 'agora-rte-sdk'; import { IBaseProcessor } from 'agora-rte-extension'; import { EduStoreBase } from '../base'; import { FcrAudioRawDataConfig, FcrAudioRawDataObserver, FcrAudioRawDataPosition } from './type'; export declare const DEVICE_DISABLE = "DEVICE_DISABLE"; /** * `MediaStore` 类用于媒体数据处理。 */ /** @en * The `MediaStore` class is used for processing media streams. */ export declare class MediaStore extends EduStoreBase { private readonly _disposers; private _streamMediaTracks; /** * 视频采集设备 **/ /** @en * The video capturing devices */ videoCameraDevices: AGRtcDeviceInfo[]; /** * 音频采集设备 **/ /** @en * The audio sampling devices */ audioRecordingDevices: AGRtcDeviceInfo[]; /** * 音频播放设备 **/ /** @en * The audio playback devices */ audioPlaybackDevices: AGRtcDeviceInfo[]; /** * 当前视频采集设备 ID **/ /** @en * The ID of the current video capturing device */ cameraDeviceId?: string; /** * 当前音频采集设备 ID **/ /** @en * The ID of the current audio sampling device */ recordingDeviceId?: string; /** * 当前视频播放设备 ID **/ /** @en * The ID of the current video playback device */ playbackDeviceId?: string; /** * 本地视频采集设备状态 **/ /** @en * The state of the local video capturing device */ localCameraTrackState: AgoraRteMediaSourceState; /** * 本地预览视频采集设备状态 **/ /** @en * The state of the local preview video capturing device */ localPreviewCameraTrackState: AgoraRteMediaSourceState; /** * 本地音频采集设备状态 **/ /** @en * The state of the local audio sampling device */ localMicTrackState: AgoraRteMediaSourceState; /** * 本地预览音频采集设备状态 **/ /** @en * The state of the local preview audio sampling device */ localPreviewMicTrackState: AgoraRteMediaSourceState; /** * 本地屏幕采集设备状态 * **/ /** @en * The state of the local screen capturing device */ localScreenShareTrackState: AgoraRteMediaSourceState; /** * 屏幕共享声音采集设备状态 **/ /** @en * The state of screen sharing of sound capturing device */ localScreenShareAudioTrackState: AgoraRteMediaSourceState; /** * 本地声卡采集设备状态 * **/ /** @en * The state of the local loopback audio capturing device */ localLoopbackDeviceState: AgoraRteMediaSourceState; /** * 当前采集屏幕设备 */ /** @en * Currently capturing screen device */ currentScreenShareDevice?: AGScreenShareDevice; /** * 本地音频设备音量 * Range from [0,1] **/ /** @en * Local mic audio volume * range from [0,1] */ localMicAudioVolume: number; /** * 本地预览音频设备音量 * range from [0,1] **/ /** @en * local preview mic audio volume * range from [0,1] */ localPreviewMicAudioVolume: number; /** * 本地扬声器音量 * Range from [0,1] * **/ /** @en * Local playback test volume * Range from [0,1] */ localPlaybackTestVolume: number; /** * 视频是否镜像 * **/ /** @en * Whether the video is mirrored */ isMirror: boolean; private _audioPlaybackDeviceEnabled; private _previousCameraId?; private _previousRecordingId?; /** * @internal * * 获取多媒体控制器 **/ /** @en * @internal * * Get media control object */ get mediaControl(): AgoraMediaControl; /** * 镜像开关 * @param v 开启或关闭 * **/ /** @en * Set mirror * @param v Enable mirror for local video or not */ setMirror(v: boolean): void; /** * 设置音频裸数据回调参数 * 需要在加入教室前调用 * @param config 配置 **/ /** @en * Set the config for audio raw data callback * it needs called before join in the class * @param config config */ setAudioRawDataConfig(config: FcrAudioRawDataConfig, position: FcrAudioRawDataPosition): void; /** * 增加一个音频裸数据观察者 * @param cb 订阅者 * **/ /** @en * Add an audio raw data observer * @param cb 订阅者 */ addAudioRawDataObserver(observer: FcrAudioRawDataObserver, position: FcrAudioRawDataPosition): void; /** * 删除音频裸数据数据观察者 * @param cb * **/ /** @en * Remove an audio raw data observer * @param cb */ removeAudioRawDataObserver(observer: FcrAudioRawDataObserver, position: FcrAudioRawDataPosition): void; private _rawDataAdapterObservers; /** * @deprecated * 增加一个本地音频裸数据观察者,使用 addAudioRawDataObserver 替代此方法 * @param cb 订阅者 * **/ /** @en * @deprecated * Add an audio raw data observer * @param cb 订阅者 */ addRawDataListener(cb: (buffer: AudioBuffer) => void): void; /** * @deprecated * 删除一个本地音频裸数据数据观察者,使用 removeAudioRawDataObserver 替代此方法 * @param cb * **/ /** @en * @deprecated * Remove an audio raw data observer * @param cb */ removeRawDataListener(cb: (buffer: AudioBuffer) => void): void; /** * 设置本地摄像头视频编码器配置参数,影响本地采集视频的质量 * @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: AGVideoEncoderConfigurations): void; /** * 设置本地屏幕视频编码器配置参数,影响本地采集视频的质量 * @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: AGVideoEncoderConfigurations): void; /** * 为视频设置显示区域 * @param dom 渲染节点 * @param mirror 是否开启镜像 * **/ /** @en * Setup local video * @param dom render node * @param mirror enable mirror */ setupLocalVideo(dom: HTMLElement, mirror: boolean, renderMode?: AGRenderMode): void; /** * 为屏幕共享设置显示区域 * @param dom 渲染节点 * **/ /** @en * Sets a node for rendering the local screen-sharing stream * @param dom The rendering node */ setupLocalScreenShare(dom: HTMLElement): void; /** * 开启扬声器测试 * Electron 端不支持 Base64 格式的音频数据 * * @param url 资源地址 * **/ /** @en * Starts the playback device test * Base64 audio data not support on Electron platform * * @param url resouce url */ startPlaybackDeviceTest(url: string): void; /** * 停止扬声器测试 **/ /** @en * Stops the playback device test */ stopPlaybackDeviceTest(): void; /** * 开启音频设备测试 * @param indicateInterval 探测频率(毫秒) * **/ /** @en * Starts the audio device test * @param indicateInterval The indication interval (ms). */ startRecordingDeviceTest(indicateInterval: number): void; /** * 停止音频设备测试 **/ /** @en * Stops the audio device test */ stopRecordingDeviceTest(): void; /** * 开启或关闭本地视频 * @param value boolean **/ /** @en * Enables or disables the local video * @param value boolean * */ enableLocalVideo(value: boolean): void; /** * 开启或关闭本地所有音频播放 * @param value */ /** @en * * @param value */ enableLocalPlayback(value: boolean): void; /** * 开启或关闭本地音频 * @param value boolean **/ /** @en * Enables or disables the local audio * @param value boolean */ enableLocalAudio(value: boolean): void; /** * 设置当前正在屏幕共享的设备 * @param device */ /** @en * Set the device that is currently screen sharing * @param device */ setCurrentScreenShareDevice(device: AGScreenShareDevice): void; /** * 开始屏幕共享 * @param id 屏幕/窗口ID * @param type 屏幕分享数据源类型 * @param withAudio 是否分享声音/开启声卡采集 * @param audioDeviceName 声卡采集的设备名称,仅electron支持 * @param excludeWindowList 排除的窗口列表, 仅electron支持 */ startScreenShareCapture(params?: { id?: string; type?: AGScreenShareType; withAudio?: boolean; audioDeviceName?: string; excludeWindowList?: number[]; localPreview?: boolean; }): void; /** * 启动声卡采集 * @param params 可选参数对象,包括音频设备名称和连接类型 */ /** @en * Start loopback recording * @param params Optional parameter object, including audio device name and connection type */ startLoopbackRecording(params?: { audioDeviceName?: string; connType?: AGRtcConnectionType; }): void; /** * 停止声卡采集 * @param params 可选参数对象,包括连接类型 */ /** @en * Stop loopback recording * @param params Optional parameter object, including connection type */ stopLoopbackRecording(params?: { connType?: AGRtcConnectionType; }): void; /** * 停止屏幕共享 * withAudio: 是否同时关闭声卡采集,默认: True **/ /** @en * Stops sharing the screen * withAudio: whether to close loopback recording simultaneously, Default to: True */ stopScreenShareCapture(params?: { withAudio?: boolean; }): void; /** * 检测是否可以获取到屏幕采集设备列表 * @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(): boolean; /** * 检测是否有屏幕采集权限 * @returns 是否有屏幕采集的权限 **/ /** @en * Check whether the permission of screen capture is granted * @returns Whether the permission for screen capture is granted */ hasScreenSharePermission(): boolean; /** * 获取可采集应用窗口列表 * @returns 应用窗口列表 **/ /** @en * Gets a list of application windows that can be captured * @returns A list of application windows */ getWindowDevices(): Promise<AGScreenShareDevice[]>; /** * 获取可采集的屏幕列表 * @returns 屏幕列表 **/ /** @en * Gets a list of display devices that can be captured * @returns A list of application windows */ getDisplayDevices(): Promise<AGScreenShareDevice[]>; /** * 设置视频设备 ID * @param id 设备 ID **/ /** @en * Sets the local camera device ID * @param id Device ID */ setCameraDevice(id: string): void; /** * 设置音频设备 ID * @param id 设备 ID * **/ /** @en * Sets the local recording device ID * @param id Device ID */ setRecordingDevice(id: string): void; /** * 设置扬声器设备 ID * @param id 设备 ID **/ /** @en * set playback device ID * @param id Device ID */ setPlaybackDevice(id: string): void; /** * 更新本地媒体状态 * @param param0 视频状态和音频状态 **/ /** @en * Updates the local media state * @param param0 The video state and audio state */ updateLocalMediaState({ videoSourceState, audioSourceState, }: { videoSourceState?: AgoraRteMediaSourceState; audioSourceState?: AgoraRteMediaSourceState; }): Promise<void>; /** * 开启双流 * @param enable 是否开启 * @param connectionType RTC 连接 */ /** @en * Enables dual stream * @param enable Whether to enable * @param connectionType RTC connection */ enableDualStream(enable: boolean, connectionType?: AGRtcConnectionType, fromScene?: AgoraRteScene): Promise<void>; /** * 设置小流分辨率及码率 * @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: AGLowStreamParameter, connectionType?: AGRtcConnectionType, fromScene?: AgoraRteScene): void; /** * 播放流媒体 * @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: string, dom: HTMLElement, mirror: boolean, playVideo: boolean, playAudio: boolean): void; /** * 通过 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: string): import("agora-rte-sdk").StreamMediaPlayer | undefined; /** * 视频截图(此接口仅 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: string, streamUuid: number, filePath: string): Promise<void | import("agora-rte-sdk").AGSnapshotInfo>; /** * 视频截图(此接口仅 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: string, streamUuid: number): ImageData | undefined; /** * 增加摄像头视频流前处理器 * @param processors 视频采集前处理器 */ /** @en * @param processors preprocessor for the camera track * Adds the pre-processors to the local camera track */ addCameraProcessors(processors: IBaseProcessor[]): void; /** * 移除摄像头视频流处理器 */ /** @en * Removes all camera track processors */ removeCameraProcessors(): void; /** * 增加麦克风音频流前处理器 * @param processors 音频采集前处理器 */ /** @en * Adds the pre-processors to the local microphone track * @param processors preprocessor for the microphone track */ addMicrophoneProcessors(processors: IBaseProcessor[]): void; /** * 移除麦克风音频流处理器 */ /** @en * Removes all microphone track processors */ removeMicrophoneProcessors(): void; /** * 增加摄像头视频流前处理器(预览) * @param processors */ /** @en * @param processors * Adds the pre-processors to the local camera track(For preview) */ addPreviewCameraProcessors(processors: IBaseProcessor[]): void; /** * 移除摄像头视频流处理器(预览) */ /** @en * Removes all camera track processors(For preview) */ removePreviewCameraProcessors(): void; /** * 增加麦克风音频流前处理器(预览) * @param processors */ /** @en * Adds the pre-processors to the local microphone track(For preview) * @param processors */ addPreviewMicrophoneProcessors(processors: IBaseProcessor[]): void; /** * 移除麦克风音频流处理器(预览) */ /** @en * Removes all microphone track processors(For preview) */ removePreviewMicrophoneProcessors(): void; /** * @internal */ onInstall(): void; /** * @internal */ onDestroy(): void; }