UNPKG

fcr-core

Version:

Core APIs for building online scenes

670 lines (669 loc) 22.7 kB
import { AgoraRteAudioRawDataConfig, AgoraRteBeautyOptions, AgoraRteCameraPosition, AgoraRteScreenCaptureParams, AgoraRteVirtualBackgroundOptions, AgoraRteCameraCaptureParams, AgoraRtcAudioOutputRouting } from '../imports'; import { FcrDeviceInfo, FcrDisplayInfo, FcrRenderView, FcrScreenCaptureType, FcrVideoOrientation, FcrWindowInfo } from '../type'; import { FcrMediaSourceState, FcrAiDenoiseLevel, FcrVideoSourceType, FcrAudioSourceType, FcrCapability } from '../type'; import { FcrRenderConfigSchema } from '../schema'; export type FcrAudioOutputRouting = AgoraRtcAudioOutputRouting; export type FcrDesktopMediaObserver = { /** * Callback to receive the auto play failed event. */ onAutoPlayFailed?(): void; /** * Callback when a camera is added. * @param device */ onCameraAdded?(device: FcrDeviceInfo): void; /** * Callback when a camera is removed. * @param device */ onCameraRemoved?(device: FcrDeviceInfo): void; /** * Callback when a microphone is added. * @param device */ onMicrophoneAdded?(device: FcrDeviceInfo): void; /** * Callback when a microphone is removed. * @param device */ onMicrophoneRemoved?(device: FcrDeviceInfo): void; /** * Callback when a speaker is added. * @param device */ onSpeakerAdded?(device: FcrDeviceInfo): void; /** * Callback when a speaker is removed. * @param device */ onSpeakerRemoved?(device: FcrDeviceInfo): void; /** * Callback to receive the volume indication of the speaker test. * @param volume */ onSpeakerTestVolumeIndicationUpdated?(volume: number): void; /** * Callback to receive the volume changes of the selected speaker. * @param volume * @param muted */ onSelectedSpeakerVolumeUpdated?(volume: number, muted: boolean): void; /** * Callback to receive the state changes of the system selected speaker. * @param speaker */ onSystemSelectedSpeakerChanged?(speaker: FcrDeviceInfo): void; /** * Callback to receive the state changes of the system selected microphone. * @param microphone */ onSystemSelectedMicrophoneChanged?(microphone: FcrDeviceInfo): void; }; export type FcrMobileMediaObserver = { /** * Callback to receive the auto play failed event. */ onAutoPlayFailed?(): void; onCameraStateUpdated?(state: FcrMediaSourceState): void; onMicrophoneStateUpdated?(state: FcrMediaSourceState): void; onMicrophoneVolumeIndicationUpdated?(volume: number): void; onOutputVolumeIndicationUpdated?(volume: number): void; onAudioOutputRoutingUpdated?(routing: FcrAudioOutputRouting): void; onScreenCaptureStateUpdated?(state: FcrMediaSourceState): void; }; export type FcrScreenTrackObserver = { /** * Callback to receive the state changes of the screen video track. * @param sourceId * @param state */ onScreenCaptureStateUpdated?(sourceId: string, state: FcrMediaSourceState): void; }; export type FcrMicrophoneTrackObserver = { /** * Callback to receive the state changes of the microphone audio track. * @param deviceId * @param state */ onMicrophoneStateUpdated?(deviceId: string, state: FcrMediaSourceState): void; /** * Callback to receive the volume indication of the microphone. * @param deviceId * @param volume */ onVolumeIndicationUpdated?(deviceId: string, volume: number): void; }; export type FcrCameraTrackObserver = { /** * Callback to receive the state changes of the camera video track. * @param deviceId * @param state */ onCameraStateUpdated?: (deviceId: string, state: FcrMediaSourceState) => void; }; export type FcrLoopbackObserver = { /** * Callback to receive the state changes of the loopback audio track. * @param deviceId * @param state */ onLoopbackRecordingStateUpdated?: (deviceId: string, state: FcrMediaSourceState) => void; }; export type FcrRenderConfig = FcrRenderConfigSchema; export type FcrBeautyOptions = AgoraRteBeautyOptions; export type FcrVirtualBackgroundOptions = AgoraRteVirtualBackgroundOptions; export type FcrCameraPosition = AgoraRteCameraPosition; export type FcrAudioRawDataConfig = AgoraRteAudioRawDataConfig; export type FcrScreenCaptureParams = AgoraRteScreenCaptureParams; export type FcrCameraCaptureParams = AgoraRteCameraCaptureParams; export interface FcrAudioEffectEnhancer { /** * Enables the AI denoiser for the audio track. */ enableAiDenoiser(): void; /** * Disables the AI denoiser for the audio track. */ disableAiDenoiser(): void; /** * Sets the AI denoiser level for the audio track. * @param level The AI denoiser level to set. */ setAiDenoiseLevel(level: FcrAiDenoiseLevel): void; /** * Enables HiFi mode for the audio track. */ enableHiFiMode(): void; /** * Disables HiFi mode for the audio track. */ disableHiFiMode(): void; /** * Enables echo cancellation for the audio track. */ enableEchoCancellation(): void; /** * Disables echo cancellation for the audio track. */ disableEchoCancellation(): void; /** * Enables stereo mode for the audio track. */ enableStereoMode(): void; /** * Disables stereo mode for the audio track. */ disableStereoMode(): void; /** * Enables original sound mode for the audio track. */ enableOriginalSoundMode(): void; /** * Disables original sound mode for the audio track. */ disableOriginalSoundMode(): void; /** * Enables AGC for the audio track. */ enableAGC(): void; /** * Disables AGC for the audio track. */ disableAGC(): void; } export interface FcrVideoEffectEnhancer { /** * Sets the beauty options for the video track. * @param options The beauty options. * @param view The HTML element to render the video on. */ setBeautyOptions(options: FcrBeautyOptions): void; /** * Enables the beauty effect for the video track. */ enableBeauty(): void; /** * Disables the beauty effect for the video track. */ disableBeauty(): void; /** * Sets the virtual background options for the video track. * @param options The virtual background options. */ setVirtualBackgroundOptions(options: FcrVirtualBackgroundOptions): void; /** * Enables the virtual background for the video track. */ enableVirtualBackground(): void; /** * Disables the virtual background for the video track. */ disableVirtualBackground(): void; /** * Enables lowlight enhancement for the video track. * * This method enhances the video quality in low-light conditions by adjusting * the brightness and contrast to improve visibility. */ enableLowlightEnhancement(): void; /** * Disables lowlight enhancement for the video track. * * This method turns off the lowlight enhancement feature, reverting any adjustments * made to the brightness and contrast for low-light conditions. */ disableLowlightEnhancement(): void; /** * Enables the video denoiser for the video track. * * This method reduces noise in the video stream, resulting in a clearer and more * visually appealing video output. */ enableVideoDenoiser(): void; /** * Disables the video denoiser for the video track. * * This method turns off the video denoiser feature, allowing the video stream * to be displayed without noise reduction. */ disableVideoDenoiser(): void; /** * Enables the hardware encoder for the video track. * * This method utilizes the hardware encoder of the device to encode the video stream, * which can improve performance and reduce CPU usage. */ enableHardwareEncoder(): void; /** * Disables the hardware encoder for the video track. * * This method stops using the hardware encoder of the device to encode the video stream, * potentially increasing CPU usage but providing more flexibility in software encoding. */ disableHardwareEncoder(): void; /** * Checks if the system satisfies the requirements for using virtual backgrounds. * * This method verifies if the current system meets the necessary conditions to enable * virtual backgrounds, such as hardware capabilities and software configurations. * * @returns {boolean} True if the system satisfies the requirements, false otherwise. */ checkSatisfyVirtualBackgroundRequirements(): boolean; /** * Checks if the system satisfies the requirements for using beauty effects. * * This method verifies if the current system meets the necessary conditions to enable * beauty effects, such as hardware capabilities and software configurations. * * @returns {boolean} True if the system satisfies the requirements, false otherwise. */ checkSatisfyBeautyRequirements(): boolean; } export interface FcrCameraTrack { /** * Gets the device ID of the camera. * @returns The device ID of the camera. */ getDeviceId(): string; /** * Gets the current state of the camera. * @returns The current state of the camera. */ getState(): FcrMediaSourceState; /** * Gets the video source type. * @returns The video source type. */ getVideoSourceType(): FcrVideoSourceType; /** * Starts the camera. */ start(): void; /** * Stops the camera. */ stop(): void; /** * Starts the camera test. */ startTest(): void; /** * Stops the camera test. */ stopTest(): void; /** * Starts the camera preview with the specified configuration and view. * @param config The configuration for the video render. * @param view The HTML element to render the video on. */ startPreview(config: FcrRenderConfig, view: FcrRenderView): void; /** * Stops the camera preview. * @param view The HTML element to render the video on. */ stopPreview(view: FcrRenderView): void; /** * Sets the capture parameters for the camera. * @param params The parameters for the video capture. */ setCaptureParams(params: FcrCameraCaptureParams): void; /** * Retrieves the video effect enhancer. * * This method returns an instance of the video effect enhancer, which is used to apply various effects to the video. * * @returns {VideoEffectEnhancer} An instance of the video effect enhancer. */ getVideoEffectEnhancer(): FcrVideoEffectEnhancer; /** * Sets the video orientation for the camera. * @param orientation orientation of the camera video. */ setVideoOrientation(orientation: FcrVideoOrientation): void; /** * * @param observer */ addObserver(observer: FcrCameraTrackObserver): void; /** * * @param observer */ removeObserver(observer: FcrCameraTrackObserver): void; } export interface FcrLoopbackTrack { /** * Gets the device ID of the loopback audio track. * @returns The device ID of the loopback audio track. */ getDeviceId(): string; /** * Gets the state of the loopback audio track. * @returns The state of the loopback audio track. */ getState(): FcrMediaSourceState; /** * Gets the audio source type of the loopback audio track. */ getAudioSourceType(): FcrAudioSourceType; /** * Starts the loopback audio track. */ start(): void; /** * Stops the loopback audio track. */ stop(): void; /** * Updates the signal volume for the loopback audio track. * @param volume Range from 0 to 400. 100 is the default volume. */ adjustVolume(volume: number): void; /** * * @param observer */ addObserver(observer: FcrLoopbackObserver): void; /** * * @param observer */ removeObserver(observer: FcrLoopbackObserver): void; } export interface FcrMicrophoneTrack { /** * Gets the device ID of the microphone. */ getDeviceId(): string; /** * Gets the state of the microphone audio track. */ getState(): FcrMediaSourceState; /** * Gets the audio source type of the microphone audio track. */ getAudioSourceType(): FcrAudioSourceType; /** * Sets the audio raw data configuration for the track. * @param config The audio raw data configuration. */ /** * Adds an observer for the audio raw data. * @param observer The observer for the audio raw data. */ /** * Removes an observer for the audio raw data. * @param observer The observer for the audio raw data. */ /** * Starts the microphone audio track for the specified device. * onLocalMicrophoneAudioStateUpdated callback will be triggered when the state of the microphone changes. * Note: * - {@link startTest} should be called after this method when you are not in a channel, * otherwise onLocalMicrophoneAudioStateUpdated may not be triggered in electron. */ start(): void; /** * Stops the microphone audio track for the specified device. */ stop(): void; /** * Starts the microphone test for the specified device. * @param interval The interval for the microphone test. */ startTest(interval: number): void; /** * Stops the microphone test for the specified device. */ stopTest(): void; /** * Updates the signal volume for the microphone audio track. * @param volume Range from 0 to 400. 100 is the default volume. */ adjustVolume(volume: number): void; /** * Retrieves the audio effect enhancer. * * This method returns an instance of the audio effect enhancer, which is used to apply various effects to the audio stream. * * @returns {AudioEffectEnhancer} An instance of the audio effect enhancer. */ getAudioEffectEnhancer(): FcrAudioEffectEnhancer; addObserver(observer: FcrMicrophoneTrackObserver): void; removeObserver(observer: FcrMicrophoneTrackObserver): void; } export interface FcrScreenTrack { /** * Gets the device ID of the screen. * @returns The device ID of the screen. */ getSourceId(): string; /** * Gets the current state of the screen. * @returns The current state of the screen. */ getState(): FcrMediaSourceState; /** * Gets the video source type. * @returns The video source type. */ getVideoSourceType(): FcrVideoSourceType; /** * Starts the screen preview with the specified configuration and view. * @param config The configuration for the video render. * @param view The HTML element to render the video on. */ startPreview(config: FcrRenderConfig, view: FcrRenderView): void; /** * Stops the screen preview. * @param view The HTML element to render the video on. */ stopPreview(view: FcrRenderView): void; /** * Sets the capture parameters for the screen. * @param params The parameters for the video capture. */ setCaptureParams(params: FcrScreenCaptureParams): void; /** * Starts the screen video track with the specified type and parameters. * @param type The type of screen capture. * @param excludeWindowList The list of window IDs to exclude from the screen capture. */ start(type: FcrScreenCaptureType, excludeWindowList: string[]): void; /** * Stops the screen video track for the specified source. */ stop(): void; /** * Adds an observer for the screen video track. * @param observer The observer for the screen video track. */ addObserver(observer: FcrScreenTrackObserver): void; /** * Removes an observer for the screen video track. * @param observer The observer for the screen video track. */ removeObserver(observer: FcrScreenTrackObserver): void; } export interface FcrDesktopMediaControl { /** * Get the list of loopback devices. * @returns An array of device information for each loopback device. */ getLoopbackList(): FcrDeviceInfo[]; /** * Get the list of cameras. * @returns An array of device information for each camera. */ getCameraList(): Promise<FcrDeviceInfo[]>; /** * Get the list of microphones. * @returns An array of device information for each microphone. */ getMicrophoneList(): Promise<FcrDeviceInfo[]>; /** * Get the list of speakers. * @returns An array of device information for each speaker. */ getSpeakerList(): Promise<FcrDeviceInfo[]>; /** * Get the system selected microphone. * @returns The system selected microphone, could be undefined if no microphone device. */ getSystemSelectedMicrophone(): Promise<FcrDeviceInfo | undefined>; /** * Get the system selected speaker. * @returns The system selected speaker, could be undefined if no speaker device. */ getSystemSelectedSpeaker(): Promise<FcrDeviceInfo | undefined>; /** * Get the list of windows. * @returns A promise that resolves with an array of window information. */ getWindowList(): Promise<FcrWindowInfo[]>; /** * Get the list of displays. * @returns A promise that resolves with an array of display information. */ getDisplayList(): Promise<FcrDisplayInfo[]>; /** * Get the video track of the specified camera. * @param deviceId The ID of the camera. * @returns The video track of the camera. */ getCameraTrack(deviceId: string): FcrCameraTrack; /** * Get the audio track of the specified microphone. * @param deviceId The ID of the microphone. * @returns The audio track of the microphone. */ getMicrophoneTrack(deviceId: string): FcrMicrophoneTrack; /** * Get the video track of the specified screen. * @param sourceId The ID of the screen. * @returns The video track of the screen. */ getScreenTrack(sourceId: string): FcrScreenTrack; /** * Get the audio track of the specified loopback source. * @param sourceId The ID of the loopback source. * @returns The audio track of the loopback source. */ getLoopbackTrack(sourceId: string): FcrLoopbackTrack; /** * Set the specified device as the speaker. * @param deviceId The ID of the device to set as the speaker. */ setSelectedSpeaker(deviceId: string): void; /** * Start a speaker test with the specified URL and interval. * @param url The URL to use for the test, which can be a base64 URL in browsers or absolute file path in Electron. * @param interval The interval between every time `onLocalMicrophoneAudioVolumeUpdated` is called. */ startSelectedSpeakerTest(url: string, interval: number): void; /** * Stop the speaker test. */ stopSelectedSpeakerTest(): void; /** * Adjust the output volume. * @param volume Range from 0 to 400. 100 is the default volume. */ adjustOutputVolume(volume: number): void; /** * Check if the media control supports the specified capability. * @param capability * @returns Whether the media control supports the specified capability. */ isCapabilitySupported(capability: FcrCapability): boolean; /** * Add an observer to the media control. * @param observer The observer to add. */ addObserver(observer: FcrDesktopMediaObserver): void; /** * Remove an observer from the media control. * @param observer The observer to remove. */ removeObserver(observer: FcrDesktopMediaObserver): void; /** * Set the volume of the speaker. * @param volume Range from 0 to 100. */ setSelectedSpeakerVolume(volume: number): void; /** * Get the volume of the speaker. * @returns The volume of the speaker. Range from 0 to 100. */ getSelectedSpeakerVolume(): number; /** * Follow the system speaker. * @param follow */ observeSystemSelectedSpeakerChanged(enable: boolean): void; /** * Follow the system microphone. * @param follow */ observeSystemSelectedMicrophoneChanged(enable: boolean): void; disableAGC(): number; enableAGC(): number; } export interface FcrMobileMediaControl { /** * Open the specified device. * @param deviceType The type of the device to open. */ openDevice(deviceType: FcrDeviceType): void; /** * Close the specified device. * @param deviceType The type of the device to close. */ closeDevice(deviceType: FcrDeviceType): void; getDeviceId(deviceType: FcrDeviceType): string; getDeviceState(deviceType: FcrDeviceType): FcrMediaSourceState; adjustOutputVolume(volume: number): void; /** * Switch the camera position. * @returns The new camera position. */ switchCamera(): FcrCameraPosition; /** * Get the current camera position. * @returns The current camera position. */ getCameraPosition(): FcrCameraPosition; startCameraTest(): void; stopCameraTest(): void; startCameraPreview(view: string | object, config: FcrRenderConfig): void; stopCameraPreview(view: string | object): void; stopCameraPreviewOnAllCanvas(): void; isCapabilitySupported(capability: FcrCapability): boolean; startScreenCapture(excludeWindowList: string[]): void; stopScreenCapture(): void; getScreenCaptureState(): FcrMediaSourceState; startLoopbackRecording(): void; stopLoopbackRecording(): void; getLoopbackRecordingState(): FcrMediaSourceState; enableSpeaker(enable: boolean): void; getAudioOutputRouting(): FcrAudioOutputRouting; getAudioEffectEnhancer(): FcrAudioEffectEnhancer; getVideoEffectEnhancer(): FcrVideoEffectEnhancer; /** * Add an observer to the media control. * @param observer The observer to add. */ addObserver(observer: FcrMobileMediaObserver): void; /** * Remove an observer from the media control. * @param observer The observer to remove. */ removeObserver(observer: FcrMobileMediaObserver): void; } export declare enum FcrDeviceType { Camera = "camera", Microphone = "microphone", Speaker = "speaker" }