@agora-js/media
Version:
media module across @agora-js packages
1,249 lines (1,122 loc) • 152 kB
TypeScript
import { AgoraRTCError } from '@agora-js/shared';
import { CheckVisibleResult } from '@agora-js/shared';
import { ElectronDesktopCapturerSource } from '@agora-js/shared';
import { EventEmitter } from '@agora-js/shared';
import { IAudioProcessor } from 'agora-rte-extension';
import type { IAudioProcessorContext } from 'agora-rte-extension';
import { IBaseProcessor } from 'agora-rte-extension';
import type { IProcessorContext } from 'agora-rte-extension';
import { isElectron } from '@agora-js/shared';
import type { Kind } from 'agora-rte-extension';
import type { NetworkQuality } from '@agora-js/shared';
import type { ProcessorStats } from 'agora-rte-extension';
import { PromiseMutex } from '@agora-js/shared';
import { RequiredOnlyOneOf } from '@agora-js/shared';
import { SDKStore } from '@agora-js/shared';
import { UID } from '@agora-js/shared';
import { Usage } from 'agora-rte-extension';
import type { UsageWithDirection } from 'agora-rte-extension';
export declare const __TRACK_LIST__: Track[];
export declare function addTrack(track: Track): void;
export declare interface AgoraRTCCompatibility {
getDisplayMedia: boolean;
getStreamFromExtension: boolean;
supportUnifiedPlan: boolean;
supportMinBitrate: boolean;
supportSetRtpSenderParameters: boolean;
supportDualStream: boolean;
webAudioMediaStreamDest: boolean;
supportReplaceTrack: boolean;
supportWebGL: boolean;
webAudioWithAEC: boolean;
supportRequestFrame: boolean;
supportShareAudio: boolean;
supportDualStreamEncoding: boolean;
supportDataChannel: boolean;
supportPCSetConfiguration: boolean;
supportWebRTCEncodedTransform: boolean;
supportWebRTCInsertableStream: boolean;
supportRequestVideoFrameCallback: boolean;
supportWebCrypto: boolean;
supportSuppressLocalAudioPlayback: boolean;
supportRestrictOwnAudio: boolean;
}
export declare class AgoraRTCPlayer extends VideoPlayer {
private container?;
private slot?;
constructor(config: PlayerConfig, internal?: boolean);
updateConfig(config: PlayerConfig): void;
updateVideoTrack(track?: MediaStreamTrack): void;
play(sessionId?: string): void;
getCurrentFrame(): ImageData;
getCurrentFrameToUint8Array(type: string, quality?: number): Promise<ImageTypedData>;
destroy(): void;
private createElements;
private mountedVideoElement;
private unmountedVideoElement;
protected resetVideoElement(): void;
getContainerElement(): HTMLDivElement | undefined;
}
/**
* Statistics of the call, which can be retrieved by calling [AgoraRTCClient.getRTCStats]{@link IAgoraRTCClient.getRTCStats}.
*/
export declare interface AgoraRTCStats {
/**
* Call duration in seconds.
*/
Duration: number;
/**
* The total bitrate (bps) of the received audio and video, represented by an instantaneous value.
*/
RecvBitrate: number;
/**
* The total number of bytes received, represented by an aggregate value.
*/
RecvBytes: number;
/**
* The total bitrate (bps) of the sent audio and video, represented by an instantaneous value.
*/
SendBitrate: number;
/**
* The total number of bytes sent, represented by an aggregate value.
*/
SendBytes: number;
/**
* The number of users in the channel.
*
* - Communication profile: The number of users in the channel.
* - Live Broadcast profile:
* - If the local user is an audience: The number of users in the channel = The number of hosts in the channel + 1.
* - If the local user is a host: The number of users in the channel = The number of hosts in the channel.
*/
UserCount: number;
/**
* RTT (Round-Trip Time) between the SDK and Agora's edge server, in ms.
*/
RTT: number;
/**
* The estimated bandwidth (Kbps) of the uplink network.
*/
OutgoingAvailableBandwidth: number;
}
export declare enum AUDIO_CONTEXT_EVENT {
IOS_15_16_INTERRUPTION_START = "ios15_16-interruption-start",
IOS_15_16_INTERRUPTION_END = "ios15_16-interruption-end",
IOS_INTERRUPTION_START = "ios-interruption-start",
IOS_INTERRUPTION_END = "ios-interruption-end",
STATE_CHANGE = "state-change"
}
/**
* @ignore
*/
export declare const AUDIO_ENCODER_CONFIG_SETTINGS: {
speech_low_quality: AudioEncoderConfiguration;
speech_standard: AudioEncoderConfiguration;
music_standard: AudioEncoderConfiguration;
standard_stereo: AudioEncoderConfiguration;
high_quality: AudioEncoderConfiguration;
high_quality_stereo: AudioEncoderConfiguration;
};
export declare enum AUDIO_TRACK_EVENT {
UPDATE_TRACK_SOURCE = "update-track-source"
}
declare class AudioBufferSource extends AudioSource {
private audioBuffer;
protected sourceNode?: AudioBufferSourceNode;
private startPlayTime;
private startPlayOffset;
private pausePlayTime;
private options;
private currentLoopCount;
private currentPlaybackSpeed;
set currentState(state: AudioSourceState);
get currentState(): AudioSourceState;
private _currentState;
constructor(buffer: AudioBuffer, options?: AudioSourceOptions);
createWebAudioDiagram(): GainNode;
get duration(): number;
get playbackSpeed(): number;
get currentTime(): number;
updateOptions(options: AudioSourceOptions): void;
startProcessAudioBuffer(): void;
pauseProcessAudioBuffer(): void;
seekAudioBuffer(time: number): void;
resumeProcessAudioBuffer(): void;
stopProcessAudioBuffer(): void;
destroy(): void;
setAudioBufferPlaybackSpeed(speed: number): void;
private startSourceNode;
private createSourceNode;
private handleSourceNodeEnded;
private reset;
}
export declare const audioContextState: AudioState;
declare class AudioElementPlayCenter {
onAutoplayFailed?: () => void;
private elementMap;
private elementStateMap;
private elementsNeedToResume;
private sinkIdMap;
constructor();
setSinkID(trackId: string, deviceID: string): Promise<void>;
play(track: MediaStreamTrack, trackId: string, volume: number, sessionId?: string): void;
updateTrack(trackId: string, track: MediaStreamTrack): void;
isPlaying(trackId: string): boolean;
setVolume(trackId: string, volume: number): void;
getVolume(trackId: string): number;
stop(trackId: string): void;
private bindAudioElementEvents;
getPlayerState(trackId: string): string;
private autoResumeAudioElement;
autoResumeAfterInterruption: (force?: boolean) => Promise<void[]>;
private autoResumeAfterInterruptionOnIOS15_16;
}
export declare const audioElementPlayCenter: AudioElementPlayCenter;
/**
*
* `AudioEncoderConfiguration` is the interface that defines the audio encoder configurations.
*
* You can customize the audio encoder configurations when calling [AgoraRTC.createCustomAudioTrack]{@link IAgoraRTC.createCustomAudioTrack}, [AgoraRTC.createMicrophoneAudioTrack]{@link IAgoraRTC.createMicrophoneAudioTrack} or [AgoraRTC.createBufferSourceAudioTrack]{@link IAgoraRTC.createBufferSourceAudioTrack}.
*/
export declare interface AudioEncoderConfiguration {
/**
* Sample rate of the audio (Hz).
*/
sampleRate?: number;
/**
* Sample size of the audio.
*/
sampleSize?: number;
/**
* Whether to enable stereo.
*/
stereo?: boolean;
/**
* Bitrate of the audio (Kbps).
*/
bitrate?: number;
}
/**
* The preset audio encoder configurations.
*
* You can pass the preset video encoder configurations when calling the following methods:
* - [AgoraRTC.createCustomAudioTrack]{@link IAgoraRTC.createCustomAudioTrack}
* - [AgoraRTC.createMicrophoneAudioTrack]{@link IAgoraRTC.createMicrophoneAudioTrack}
* - [AgoraRTC.createBufferSourceAudioTrack]{@link IAgoraRTC.createBufferSourceAudioTrack}
*
* The following table lists all the preset audio profiles. The SDK uses `"music_standard"` by default.
*
* | Audio Profile | Configurations |
* | -------- | --------------- |
* |`"speech_low_quality"`|Sample rate 16 kHz, mono, encoding bitrate 24 Kbps|
* |`"speech_standard"`|Sample rate 32 kHz, mono, encoding bitrate 24 Kbps|
* |`"music_standard"`|Sample rate 48 kHz, mono, encoding bitrate 32 Kbps|
* |`"standard_stereo"`|Sample rate 48 kHz, stereo, encoding bitrate 64 Kbps|
* |`"high_quality"`|Sample rate 48 kHz, mono, encoding bitrate 128 Kbps|
* |`"high_quality_stereo"`|Sample rate 48 kHz, stereo, encoding bitrate 192 Kbps| Kbps.
* @public
*/
export declare type AudioEncoderConfigurationPreset = keyof typeof AUDIO_ENCODER_CONFIG_SETTINGS;
export declare interface AudioMetadata {
value: Uint8Array;
}
export declare interface AudioPlaybackOptions {
origin?: boolean;
mixing?: boolean;
effect?: boolean;
}
export declare class AudioProcessorContext extends EventEmitter implements IAudioProcessorContext {
private constraintsMap;
private statsRegistry;
private readonly audioContext;
private readonly trackId;
private readonly direction;
private usageRegistry;
private _chained;
set chained(chained: boolean);
get chained(): boolean;
constructor(audioContext: AudioContext, trackId: string, direction: "local" | "remote");
getConstraints(): Promise<MediaTrackConstraints>;
getAudioContext(): AudioContext;
requestApplyConstraints(constraints: MediaTrackConstraints, processor: IBaseProcessor): Promise<void>;
requestRevertConstraints(processor: IBaseProcessor): Promise<void>;
registerStats(processor: IBaseProcessor, type: string, cb: () => any): void;
unregisterStats(processor: IBaseProcessor, type: string): void;
gatherStats(): ProcessorStats[];
registerUsage(processor: IBaseProcessor, cb: () => Usage): void;
unregisterUsage(processor: IBaseProcessor): void;
gatherUsage(): Promise<UsageWithDirection[]>;
getDirection(): "local" | "remote";
}
export declare class AudioProcessorDestination extends EventEmitter implements IAudioProcessor {
name: string;
ID: string;
private inputTrack?;
private inputNode?;
private readonly audioProcessorContext;
_source?: IAudioProcessor;
constructor(audioProcessorContext: AudioProcessorContext);
get kind(): Kind;
get enabled(): boolean;
pipe(): IAudioProcessor;
unpipe(): void;
enable(): void;
disable(): void;
reset(): void;
updateInput(inputOptions: {
track?: MediaStreamTrack;
node?: AudioNode;
context: IAudioProcessorContext;
}): void;
}
export declare interface AudioPts {
value: BigInt;
}
declare abstract class AudioSource extends EventEmitter {
outputNode: GainNode;
outputTrack?: MediaStreamTrack;
isPlayed: boolean;
protected abstract sourceNode?: AudioNode;
context: AudioContext;
private audioBufferNode?;
private destNode?;
private audioOutputLevel;
protected volumeLevelAnalyser: VolumeLevelAnalyser;
private _processedNode;
get processSourceNode(): AudioNode | undefined;
set processedNode(node: AudioNode | undefined);
get processedNode(): AudioNode | undefined;
protected playNode: AudioNode;
protected isDestroyed: boolean;
protected onNoAudioInput?: () => void;
protected isNoAudioInput: boolean;
private _noAudioInputCount;
constructor();
startGetAudioBuffer(bufferSize: number): void;
stopGetAudioBuffer(): void;
createOutputTrack(): MediaStreamTrack;
play(dest?: AudioNode): void;
stop(): void;
getAccurateVolumeLevel(): number;
checkHasAudioInput(times?: number): Promise<boolean>;
getAudioVolume(): number;
setVolume(level: number): void;
destroy(): void;
protected disconnect(): void;
protected connect(): void;
}
export declare enum AudioSourceEvents {
AUDIO_SOURCE_STATE_CHANGE = "audio_source_state_change",
RECEIVE_TRACK_BUFFER = "receive_track_buffer",
ON_AUDIO_BUFFER = "on_audio_buffer",
UPDATE_SOURCE = "update_source"
}
/**
* Options for processing the audio buffer. You need to set the options for processing the audio buffer when calling [startProcessAudioBuffer]{@link IBufferSourceAudioTrack.startProcessAudioBuffer}.
*/
export declare interface AudioSourceOptions {
/**
* How many times the audio loops.
*/
cycle?: number;
/**
* Whether to loop the audio infinitely.
*/
loop?: boolean;
/**
* The playback position (seconds).
*/
startPlayTime?: number;
}
/**
* Processing state of the audio buffer:
* - `"stopped"`: The SDK stops processing the audio buffer. Reasons may include:
* - The SDK finishes processing the audio buffer.
* - The user manually stops the processing of the audio buffer.
* - `"playing"`: The SDK is processing the audio buffer.
* - `"paused"`: The SDK pauses processing the audio buffer.
*
* You can get the state with [BufferSourceAudioTrack.on("source-state-change")]{@link IBufferSourceAudioTrack.event_source_state_change}.
*/
export declare type AudioSourceState = "stopped" | "playing" | "paused";
declare class AudioState extends EventEmitter {
prevState: AudioContextState | "interrupted" | undefined;
curState: AudioContextState | "interrupted" | undefined;
currentTime?: number;
currentTimeStuckAt?: number;
private interruptDetectorTrack?;
get duringInterruption(): boolean;
private onLocalAudioTrackMute;
private onLocalAudioTrackUnmute;
bindInterruptDetectorTrack(track: MicrophoneAudioTrack): void;
unbindInterruptDetectorTrack(track: MicrophoneAudioTrack): void;
}
export declare function audioTimerLoop(callback: (time: number) => any, frequency: number): () => void;
/**
* Configurations for the audio track of screen sharing.
*/
export declare interface AudioTrackInitConfig {
/**
* Whether to enable acoustic echo cancellation:
* - `true`: Enable acoustic echo cancellation.
* - `false`: Do not enable acoustic echo cancellation.
*/
AEC?: boolean;
/**
* Whether to enable audio gain control:
* - `true`: Enable audio gain control.
* - `false`: Do not enable audio gain control.
*/
AGC?: boolean;
/**
* Whether to enable automatic noise suppression:
* - `true`: Enable automatic noise suppression.
* - `false`: Do not automatic noise suppression.
*/
ANS?: boolean;
}
declare class AudioTrackSource extends AudioSource {
protected sourceNode: MediaStreamAudioSourceNode;
track: MediaStreamTrack;
clonedTrack?: MediaStreamTrack;
private audioElement;
private isCurrentTrackCloned;
private isRemoteTrack;
private originVolumeLevelAnalyser?;
get isFreeze(): boolean;
constructor(track: MediaStreamTrack, isRemoteTrack?: boolean, originTrack?: MediaStreamTrack);
private rebuildWebAudio;
updateTrack(track: MediaStreamTrack): void;
destroy(): void;
createMediaStreamSourceNode(track: MediaStreamTrack): MediaStreamAudioSourceNode;
updateOriginTrack(originTrack: MediaStreamTrack): void;
getOriginVolumeLevel(): number;
}
declare class AutoPlayGestureEventEmitter extends EventEmitter {
onAutoplayFailed?: () => void;
onAudioAutoplayFailed?: () => void;
}
export declare const autoPlayGestureEventEmitter: AutoPlayGestureEventEmitter;
/**
* @ignore
*
* Image enhancement options. You need to set the image enhancement options when calling [setBeautyEffect]{@link ILocalVideoTrack.setBeautyEffect}.
*/
export declare interface BeautyEffectOptions {
/**
*
* The smoothness level.
*
* The value range is [0.0, 1.0]. The original smoothness level is 0.0. The default value is 0.5. This parameter is usually used to remove blemishes.
*/
smoothnessLevel?: number;
/**
* The brightness level.
*
* The value range is [0.0, 1.0]. The original brightness level is 0.0. The default value is 0.7.
*/
lighteningLevel?: number;
/**
* The redness level.
*
* The value range is [0.0, 1.0]. The original redness level is 0.0. The default value is 0.1. This parameter adjusts the red saturation level.
*/
rednessLevel?: number;
/**
* The contrast level. Use this together with {@link lighteningLevel}.
* - 0: Low contrast level.
* - 1: (Default) The original contrast level.
* - 2: High contrast level.
*/
lighteningContrastLevel?: 0 | 1 | 2;
}
export declare interface BeautyWebGLParameters {
denoiseLevel?: number;
lightLevel?: number;
rednessLevel?: number;
lighteningContrastLevel?: number;
}
export declare const blob2Uint8Array: (blob: Blob) => Promise<Uint8Array>;
export declare class BufferSourceAudioTrack extends LocalAudioTrack implements IBufferSourceAudioTrack {
source: string | File | AudioBuffer | null;
private _bufferSource;
get __className__(): string;
constructor(source: string | File | AudioBuffer, bufferSource: AudioBufferSource, encodingConfig?: AudioEncoderConfiguration, trackId?: string);
get currentState(): AudioSourceState;
get duration(): number;
get playbackSpeed(): number;
getCurrentTime(): number;
startProcessAudioBuffer(options?: AudioSourceOptions): void;
pauseProcessAudioBuffer(): void;
seekAudioBuffer(time: number): void;
resumeProcessAudioBuffer(): void;
stopProcessAudioBuffer(): void;
close(): void;
setAudioBufferPlaybackSpeed(speed: number): void;
}
/**
* Configurations for the audio track from an audio file or `AudioBuffer` object. Set these configurations when calling [AgoraRTC.createBufferSourceAudioTrack]{@link IAgoraRTC.createBufferSourceAudioTrack}.
*/
export declare interface BufferSourceAudioTrackInitConfig {
/**
* The type of the audio source:
* - `File`: An [File](https://developer.mozilla.org/en-US/docs/Web/API/File) object, representing a local audio file.
* - `string`: The online audio file retrieved from an HTTPS address. Ensure the address supports HTTPS and CORS.
* - `AudioBuffer`: An [AudioBuffer](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer) object, representing the raw data in PCM format.
*/
source: File | string | AudioBuffer;
/**
* Whether to cache the online file:
* - `true`: Cache the online file.
* - `false`: (default) Do not cache the online file.
*/
cacheOnlineFile?: boolean;
/**
* The audio encoder configurations.
*
* You can set the audio encoder configurations in either of the following ways:
* - Pass the preset audio encoder configurations by using [[AudioEncoderConfigurationPreset]].
* - Pass your customized audio encoder configurations by using [[AudioEncoderConfiguration]].
*
* > Firefox does not support setting the audio encoding rate.
*/
encoderConfig?: AudioEncoderConfiguration | AudioEncoderConfigurationPreset;
}
export declare class CameraVideoTrack extends LocalVideoTrack implements ICameraVideoTrack {
private _config;
private _originalConstraints;
private _constraints;
_enabled: boolean;
_deviceName: string;
get __className__(): string;
constructor(track: MediaStreamTrack, config: CameraVideoTrackInitConfig, constraints: MediaTrackConstraints, scalabilityConfig?: SVCConfiguration, optimizationMode?: OptimizationMode, trackId?: string);
setDevice(deviceId: string | RequiredOnlyOneOf<{
facingMode: VideoFacingModeEnum;
deviceId: string;
}>): Promise<void>;
private _setDeviceById;
private _setDeviceByFacingModel;
setEnabled(enabled: boolean, skipChangeState?: boolean): Promise<void>;
setEncoderConfiguration(config: VideoEncoderConfiguration | VideoEncoderConfigurationPreset, doNotRenegoation?: boolean): Promise<void>;
protected _getDefaultPlayerConfig(): Partial<PlayerConfig>;
protected onTrackEnded(): void;
renewMediaStreamTrack(newConstraints?: MediaTrackConstraints): Promise<void>;
tryResumeVideoForIOS15_16WeChat: () => Promise<void>;
close(): void;
clone(config?: VideoEncoderConfiguration | VideoEncoderConfigurationPreset, cloneTrack?: boolean): CameraVideoTrack;
bindProcessorContextEvents(): void;
}
/**
* Configurations for the video track from the video captured by a camera. Set these configurations when calling [AgoraRTC.createCameraVideoTrack]{@link IAgoraRTC.createCameraVideoTrack}.
*/
export declare interface CameraVideoTrackInitConfig {
/**
* The video encoder configurations.
*
* You can set the video encoder configurations in either of the following ways:
* - Pass the preset video encoder configurations by using [[VideoEncoderConfigurationPreset]].
* - Pass your customized video encoder configurations by using [[VideoEncoderConfiguration]].
* - Leave this property empty to use the SDK's default value, `"480p_1"` (resolution: 640 × 480, frame rate: 15 fps, bitrate: 500 Kbps).
*/
encoderConfig?: VideoEncoderConfiguration | VideoEncoderConfigurationPreset;
/**
* Whether to user the front camera or the rear camera.
*
* You can use this parameter to choose between the front camera and the rear camera on a mobile device:
* - `"user"`: The front camera.
* - `"environment"`: The rear camera.
*/
facingMode?: VideoFacingModeEnum;
/**
* Specifies the camera ID.
*
* You can get a list of the available cameras by calling [AgoraRTC.getCameras]{@link IAgoraRTC.getCameras}.
*/
cameraId?: string;
/**
* @since
* <br>   *4.2.0*
*
* Sets the video transmission optimization mode.
*
* You can call this method during a video call, a live streaming or screen sharing to dynamically change the optimization mode. For example, during the screen sharing, before you change the shared content from text to video, you can change the optimization mode from `"detail"` to `"motion"` to ensure smoothness in poor network conditions.
*
* > Note: This method supports Chrome only.
*
* @param mode The video transmission optimization mode:
* - `"detail"`: Prioritizes video quality.
* - The browser ensures high-quality images by automatically calculating a minimum bitrate based on the capturing resolution and frame rate. No matter how poor the network condition is, the sending bitrate will never be lower than the minimum value.
* - In most cases, the browser does not reduce the sending resolution, but may reduce the frame rate.
* - `"motion"`: Since v4.21.0, the browser prioritizes video smoothness.
* - In poor network conditions, the browser reduces the sending bitrate to minimize video freezes.
* - In most cases, the browser does not reduce the frame rate, but may reduce the sending resolution.
* - `"balanced"`: The default optimization mode.
* - For screen sharing video streams, the SDK default optimization strategy is quality-first.
* - For other video streams, the SDK default optimization strategy is balanced between quality and smoothness. Under poor network conditions, both the frame rate and resolution will be adjusted.
*/
optimizationMode?: OptimizationMode;
/**
* @ignore
*
* @since
* <br>   *4.18.0*
*
* Configurations for Scalable Video Coding (SVC).
*
* You can set the configurations using one of the following options:
* - Use the preset SVC configurations provided by the SDK through {@link SVCConfigurationPreset}.
* - Use your custom SVC configurations through {@link SVCConfiguration}.
*/
scalabiltyMode?: SVCConfiguration | SVCConfigurationPreset;
}
export declare function checkMediaStreamTrackResolution(track: MediaStreamTrack): Promise<[number, number]>;
export declare function checkTrackState(): (target: any, propertyKey: any, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<any> | undefined;
/**
* The visibility of the `<video>` tag.
*
* Get the visibility of the `<video>` tag through the following methods and events:
* - [localVideoTrack.on("video-element-visible-status")]{@link ILocalVideoTrack.event_video_element_visible_status}
* - [localVideoTrack.getVideoElementVisibleStatus]{@link ILocalVideoTrack.getVideoElementVisibleStatus}
* - [remoteVideoTrack.on("video-element-visible-status")]{@link IRemoteVideoTrack.event_video_element_visible_status_2}
* - [remoteVideoTrack.getVideoElementVisibleStatus]{@link IRemoteVideoTrack.getVideoElementVisibleStatus}
*
* This object contains the following parameters:
* - `visible`: Boolean, whether the `<video>` tag is visible or not.
* - `reason`: This parameter is only valid when `visible` is `false`, which indicates the reason:
* - `"SIZE"`: The size of `<video>` is too small to see.
* - `"STYLE"`: The CSS styles of `<video>` or its ancestor element cause `<video>` to be invisible.
* - `"POSITION"`: The `<video>` tag or its ancestor element are positioned outside the viewport.
* - `"COVERED"`: The `<video>` tag is covered by other elements.
*/
export declare type CheckVideoVisibleResult = CheckVisibleResult;
/**
* Specifies a constraint for a property, such as the resolution or bitrate for video capture in [[VideoEncoderConfiguration]].
*/
export declare interface ConstrainLong {
/**
* The lower limit of the property.
*/
min?: number;
/**
* The upper limit of the property.
*/
max?: number;
/**
* An ideal value of a property. If the video capture device cannot output this value, it outputs the closest value instead.
*/
ideal?: number;
/**
* A required value of a property. If the video capture device cannot output this value, the video capture fails.
*/
exact?: number;
}
export declare function createBufferSourceAudioTrack(config: BufferSourceAudioTrackInitConfig): Promise<BufferSourceAudioTrack>;
export declare function createCameraVideoTrack(config?: CameraVideoTrackInitConfig): Promise<CameraVideoTrack>;
export declare function createCustomAudioTrack(config: CustomAudioTrackInitConfig): LocalAudioTrack;
export declare function createCustomVideoTrack(config: CustomVideoTrackInitConfig): LocalVideoTrack;
export declare function createMicrophoneAndCameraTracks(audioConfig?: MicrophoneAudioTrackInitConfig, videoConfig?: CameraVideoTrackInitConfig): Promise<[MicrophoneAudioTrack, CameraVideoTrack]>;
export declare function createMicrophoneAudioTrack(config?: MicrophoneAudioTrackInitConfig): Promise<MicrophoneAudioTrack>;
export declare function createMixingAudioTrack(trackList: LocalAudioTrack[]): MixingAudioTrack;
export declare function createScreenVideoTrack(config: ScreenVideoTrackInitConfig, withAudio: "enable"): Promise<[LocalVideoTrack, LocalAudioTrack]>;
export declare function createScreenVideoTrack(config?: ScreenVideoTrackInitConfig, withAudio?: "disable"): Promise<LocalVideoTrack>;
export declare function createScreenVideoTrack(config: ScreenVideoTrackInitConfig, withAudio: "auto" | ScreenAudioTrackInitConfig): Promise<[LocalVideoTrack, LocalAudioTrack] | LocalVideoTrack>;
/**
* Configurations for the custom audio track. Set these configurations when calling [AgoraRTC.createCustomAudioTrack]{@link IAgoraRTC.createCustomAudioTrack}.
*/
export declare interface CustomAudioTrackInitConfig {
/**
* Your [MediaStreamTrack](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack) object.
*/
mediaStreamTrack: MediaStreamTrack;
/**
* The audio encoder configurations.
*
* You can set the audio encoder configurations in either of the following ways:
* - Pass the preset audio encoder configurations by using [[AudioEncoderConfigurationPreset]].
* - Pass your customized audio encoder configurations by using [[AudioEncoderConfiguration]].
*
* > Firefox does not support setting the audio encoding rate.
*/
encoderConfig?: AudioEncoderConfiguration | AudioEncoderConfigurationPreset;
}
/**
* Configurations for the custom video track. Set these configurations when calling [AgoraRTC.createCustomVideoTrack]{@link IAgoraRTC.createCustomVideoTrack}.
*/
export declare interface CustomVideoTrackInitConfig {
/**
* Your [MediaStreamTrack](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack) object.
*/
mediaStreamTrack: MediaStreamTrack;
/**
* @since
* <br>   *4.17.1*
*
* Width of the video.
*
* You can pass a `number`, or a constraint such as `{ max: 1280, min: 720 }`.
*
* For more details about the constraint, see [ConstrainLong]{@link ConstrainLong}.
*/
width?: number | ConstrainLong;
/**
* @since
* <br>   *4.17.1*
*
* Height of the video.
*
* You can pass a `number`, or a constraint such as `{ max: 1280, min: 720 }`.
*
* For more details about the constraint, see [ConstrainLong]{@link ConstrainLong}.
*/
height?: number | ConstrainLong;
/**
* @since
* <br>   *4.17.1*
*
* Frame rate of the video (fps).
*
* You can pass a `number`, or a constraint such as `{ max: 30, min: 5 }`.
*
* For details about the constraint, see [ConstrainLong]{@link ConstrainLong}.
*/
frameRate?: number | ConstrainLong;
/**
* The minimum bitrate of sending the video track (Kbps).
*/
bitrateMin?: number;
/**
* The maximum bitrate of sending the video track (Kbps).
*/
bitrateMax?: number;
/**
* @since
* <br>   *4.2.0*
*
* Sets the video transmission optimization mode.
*
* You can call this method during a video call, a live streaming or screen sharing to dynamically change the optimization mode. For example, during the screen sharing, before you change the shared content from text to video, you can change the optimization mode from `"detail"` to `"motion"` to ensure smoothness in poor network conditions.
*
* > Note: This method supports Chrome only.
*
* @param mode The video transmission optimization mode:
* - `"balanced"`: Uses the default optimization mode.
* - For a screen-sharing video track, the default transmission optimization strategy is to prioritizes clarity.
* - For the other types of video tracks, the SDK may reduce the frame rate or the sending resolution in poor network conditions.
* - `"detail"`: Prioritizes video quality.
* - The SDK ensures high-quality images by automatically calculating a minimum bitrate based on the capturing resolution and frame rate. No matter how poor the network condition is, the sending bitrate will never be lower than the minimum value.
* - In most cases, the SDK does not reduce the sending resolution, but may reduce the frame rate.
* - `"motion"`: Since 4.21.0, the SDK prioritizes video smoothness.
* - In poor network conditions, the SDK reduces the sending bitrate to minimize video freezes.
* - In most cases, the SDK does not reduce the frame rate, but may reduce the sending resolution.
*/
optimizationMode?: OptimizationMode;
/**
* @ignore
*
* @since
* <br>   *4.18.0*
*
* Configurations for Scalable Video Coding (SVC).
*
* You can set `scalabiltyMode` using one of the following options:
* - Use the preset SVC configurations provided by the SDK through {@link SVCConfigurationPreset}.
* - Use your custom SVC configurations through {@link SVCConfiguration}.
*/
scalabiltyMode?: SVCConfiguration | SVCConfigurationPreset;
}
export declare abstract class DataChannel extends EventEmitter implements IDataChannel {
readonly trackMediaType: TrackMediaType.DATA;
private _version;
private _type;
_config: IDataChannelConfig;
_originDataChannel?: RTCDataChannel;
protected _dataStreamPacketHeader: ArrayBuffer;
protected _dataStreamPacketHandler: IDataStream;
private _datachannelEventMap;
constructor(config: IDataChannelConfig, datachannel?: RTCDataChannel);
useDataStream(dataStream: IDataStream): void;
get id(): number;
get ordered(): boolean;
get maxRetransmits(): number;
get metadata(): string;
get readyState(): RTCDataChannelState;
get _originDataChannelId(): number | null;
getChannelId(): number;
getConfig(): IDataChannelConfig;
_close(): void;
_waitTillOpen(): Promise<void>;
_updateOriginDataChannel(datachannel: RTCDataChannel): void;
private _initPacketHeader;
private _bandDataChannelEvents;
private _unbindDataChannelEvents;
}
export declare enum DataChannelEvents {
OPEN = "open",
MESSAGE = "message",
CLOSE = "close",
CLOSING = "closing",
ERROR = "error"
}
export declare function decodeAudioData(buffer: ArrayBuffer): Promise<AudioBuffer>;
export declare const DEFAULT_LOCAL_AUDIO_TRACK_STATS: LocalAudioTrackStats;
export declare const DEFAULT_LOCAL_VIDEO_TRACK_STATS: LocalVideoTrackStats;
export declare const DEFAULT_NETWORK_QUALITY_STATS: NetworkQuality;
export declare const DEFAULT_REMOTE_AUDIO_TRACK_STATS: RemoteAudioTrackStats;
export declare const DEFAULT_REMOTE_VIDEO_TRACK_STATS: RemoteVideoTrackStats;
export declare interface DenoiserStats {
ns: number;
ebn: number;
ean: number;
vl: number;
}
export declare function detectSupportAudioElementSetSinkId(): boolean;
export declare function detectSupportAutCC(): boolean | undefined;
export declare function detectSupportAutCCFeedback(): boolean | undefined;
export declare function detectSupportInstantVideo(store?: SDKStore): boolean;
export declare function detectSupportPrePc(store?: SDKStore): boolean;
export declare function detectSupportPreSub(store?: SDKStore): boolean;
export declare function detectSupportRestrictOwnAudio(): boolean;
export declare function detectSupportSDPEndpoint(): boolean;
export declare function detectSupportSuppressLocalAudioPlayback(): boolean;
/**
* Information of the media input device.
*
* - You can get the audio sampling device information through [onMicrophoneChanged]{@link onMicrophoneChanged}.
* - You can get the video capture device information through [onCameraChanged]{@link onCameraChanged}.
* - You can get the audio playback device information through [onPlaybackDeviceChanged]{@link onPlaybackDeviceChanged}.
*/
export declare interface DeviceInfo {
/**
* The latest time when the state of the media input device was updated.
*
* A Unix timestamp in milliseconds.
*/
updateAt: number;
/**
* The time when the SDK first detects the media input device.
*
* A Unix timestamp in milliseconds.
*/
initAt: number;
/**
* The state of the capture device.
*/
state: DeviceState;
/**
* Device information of the media input device. See [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo) for details.
*/
device: MediaDeviceInfo;
}
export declare class DeviceManager extends EventEmitter {
private _state;
get state(): DeviceManagerState;
set state(state: DeviceManagerState);
private isAccessMicrophonePermission;
private isAccessCameraPermission;
private lastAccessMicrophonePermission;
private lastAccessCameraPermission;
private checkdeviceMatched;
private deviceInfoMap;
constructor();
enumerateDevices(audio: boolean, video: boolean, skipPermissionCheck?: boolean): Promise<MediaDeviceInfo[]>;
getRecordingDevices(skipPermissionCheck?: boolean): Promise<MediaDeviceInfo[]>;
getCamerasDevices(skipPermissionCheck?: boolean): Promise<MediaDeviceInfo[]>;
getSpeakers(skipPermissionCheck?: boolean): Promise<MediaDeviceInfo[]>;
searchDeviceIdByName(deviceName: string): string | null;
getDeviceById(deviceId: string): Promise<MediaDeviceInfo>;
private init;
private updateDevicesInfo;
private checkMediaDeviceInfoIsOk;
}
export declare const deviceManager: DeviceManager;
export declare enum DeviceManagerEvent {
STATE_CHANGE = "state_change",
RECORDING_DEVICE_CHANGED = "recordingDeviceChanged",
PLAYOUT_DEVICE_CHANGED = "playoutDeviceChanged",
CAMERA_DEVICE_CHANGED = "cameraDeviceChanged"
}
export declare enum DeviceManagerState {
IDLE = "IDLE",
INITING = "INITING",
INITEND = "INITEND"
}
/**
* The state of the media input device.
* - `"ACTIVE"`: The device is plugged in.
* - `"INACTIVE"`: The device is unplugged.
*/
export declare type DeviceState = "ACTIVE" | "INACTIVE";
export declare const emptyImage2TypedArray: (type: string) => Promise<ImageTypedData>;
/**
* @ignore
*
* Occurs when the device is overloaded after you call [setBeautyEffect]{@link ILocalVideoTrack.setBeautyEffect} to enable image enhancement.
*
* You can listen for this event to notify users of the device overload and disable image enhancement.
*
* ```javascript
* localVideoTrack.on("beauty-effect-overload", () => {
* console.log("beauty effect overload, disable beauty effect");
* localVideoTrack.setBeautyEffect(false);
* });
* ```
* @event
* @asMemberOf ILocalVideoTrack
*/
declare function event_beauty_effect_overload(): void;
/**
* Occurs when the first remote audio or video frame is decoded.
*
* > Note:
* > To trigger this callback, the local client needs to call [IRemoteTrack.play]{@link play}.
*
* @event
* @asMemberOf IRemoteTrack
*/
declare function event_first_frame_decoded(): void;
/**
* @since
* <br>   *4.20.1*
*
* Parsing SEI data from the H.264 or H.265 video stream triggers this event, which returns the SEI data.
*
* @param sei SEI data in Uint8Array
* @asMemberOf ILocalVideoTrack
* @event
*/
declare function event_sei_received(sei: Uint8Array): void;
/**
* Occurs when the state of processing the audio buffer in [BufferSourceAudioTrack]{@link IBufferSourceAudioTrack} changes.
*
* @param currentState The state of processing the audio buffer:
* - `"stopped"`: The SDK stops processing the audio buffer. Reasons may include:
* - The SDK finishes processing the audio buffer.
* - The user manually stops the processing of the audio buffer.
* - `"paused"`: The SDK pauses the processing of the audio buffer.
* - `"playing"`: The SDK is processing the audio buffer.
*
* @event
* @asMemberOf IBufferSourceAudioTrack
*/
declare function event_source_state_change(currentState: AudioSourceState): void;
/**
* Occurs when a audio or video track ends.
*
* Reasons may include:
* - Camera is unplugged.
* - Microphone is unplugged.
* - The local user stops screen sharing.
* - The local user closes the underlying `MediaStreamTrack`.
* - A local media device malfunctions.
* - The device permission is revoked.
*
* @event
* @asMemberOf ILocalTrack
*/
declare function event_track_ended(): void;
/**
* Triggers when a media track is updated.
* @param track The media stream track. See [MediaStreamTrack](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack).
* @event
*/
export declare function event_track_updated(track: MediaStreamTrack): void;
/**
* Occurs when the `RTCRtpTransceiver` instance of the current track is updated.
*
* @param transceiver The new `RTCRtpTransceiver` instance.
* @param type The type of the video stream to which the current track belongs. See {@link StreamType}.
*
* @event
* @asMemberOf ILocalTrack
*/
declare function event_transceiver_updated(transceiver: RTCRtpTransceiver, type?: StreamType): void;
/**
* Occurs when the `RTCRtpTransceiver` instance of the current track is updated.
*
* @param transceiver The new `RTCRtpTransceiver` instance.
* @event
* @asMemberOf IRemoteTrack
*/
declare function event_transceiver_updated_2(transceiver: RTCRtpTransceiver): void;
/**
* @ignore
*/
declare function event_user_datachannel_close(): void;
/**
* @ignore
*/
declare function event_user_datachannel_error(ev: Event): void;
/**
* @ignore
*/
declare function event_user_datachannel_message(data: ArrayBuffer): void;
/**
* @ignore
*/
declare function event_user_datachannel_open(): void;
/**
* @since
* <br>   *4.8.0*
*
* Indicates the visibility of the `<video>` HTML tag.
*
* The SDK triggers this event every 30 seconds.
*
* After you call `localVideoTrack.play`, the SDK creates an [`<video>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video) tag for playing video tracks. When `localVideoTrack.isPlaying` is `true` but you cannot see any video, this event helps you check whether the `<video>` tag is visible or not and learn the reason when the `<video>` tag is invisible.
*
* @param data The visibility of the `<video>` tag.
* @asMemberOf ILocalVideoTrack
* @event
*/
declare function event_video_element_visible_status(data?: CheckVideoVisibleResult): void;
/**
* @since
* <br>   *4.8.0*
*
* Indicates the visibility of the `<video>` HTML tag.
*
* The SDK triggers this event every 30 seconds.
*
* After you call `remoteVideoTrack.play`, the SDK creates an [`<video>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video) tag for playing video tracks. When `remoteVideoTrack.isPlaying` is `true` but you cannot see any video, this event helps you check whether the `<video>` tag is visible or not and learn the reason when the `<video>` tag is invisible.
*
* @param data The visibility of the `<video>` tag.
* @asMemberOf IRemoteVideoTrack
* @event
*/
declare function event_video_element_visible_status_2(data?: CheckVideoVisibleResult): void;
/**
* Occurs when the video state changes.
*
* @event
* @asMemberOf IRemoteTrack
*/
declare function event_video_state_changed(videoState: VideoState): void;
export declare interface ExtendedVideoFrameCallbackMetadata extends VideoFrameCallbackMetadata {
timestamp: DOMHighResTimeStamp;
}
export declare interface ExternalMethods {
getDenoiserStats?: () => DenoiserStats | undefined;
}
declare class FakeAudioNode {
disconnect(): void;
connect(): void;
}
declare class FakeTrackSource extends EventEmitter {
context: any;
processSourceNode: undefined;
outputTrack: undefined;
processedNode: undefined;
clonedTrack: undefined;
outputNode: FakeAudioNode;
get isPlayed(): boolean;
get isFreeze(): boolean;
constructor();
setVolume(): void;
createOutputTrack(): MediaStreamTrack;
getOriginVolumeLevel(): number;
getAccurateVolumeLevel(): number;
stopGetAudioBuffer(): void;
startGetAudioBuffer(): void;
play(): void;
stop(): void;
destroy(): void;
updateTrack(): void;
updateOriginTrack(): void;
createMediaStreamSourceNode(): undefined;
}
export declare const frameData2CryptoBuffer: (imageData: ImageTypedData, appid: string, channelName: string) => Promise<Uint8Array>;
export declare function getAudioContext(): AudioContext;
export declare function getAudioEncoderConfiguration(profile: AudioEncoderConfigurationPreset | AudioEncoderConfiguration): AudioEncoderConfiguration;
export declare function getBitrateConstrainRange(width: number, height: number, frameRate: number, bitrateMin?: number, bitrateMax?: number): DoubleRange;
export declare function getBitrateFromResAndFps(width: number, height: number, fps: number): Required<DoubleRange>;
export declare function getCompatibility(): AgoraRTCCompatibility;
export declare function getConstraintsFromAudioConfig(config: AudioTrackInitConfig): MediaTrackConstraints;
export declare function getConstraintsFromCameraConfig(config: CameraVideoTrackInitConfig): MediaTrackConstraints;
export declare function getConstraintsFromMicrophoneConfig(config: MicrophoneAudioTrackInitConfig): MediaTrackConstraints;
export declare function getConstraintsFromScreenAudioConfig(config: ScreenAudioTrackInitConfig): MediaTrackConstraints & {
suppressLocalAudioPlayback?: boolean;
restrictOwnAudio?: boolean;
};
export declare function getConstraintsFromScreenConfig(config: ScreenVideoTrackInitConfig): ScreenConstraintsWithElectron;
export declare function getElectronScreenSources(type?: ScreenSourceType): Promise<ElectronDesktopCapturerSource[]>;
export declare function getElectronScreenStream(sourceId: string, config: ScreenConstraintsWithElectron, captureAudio?: boolean): Promise<MediaStream>;
export declare function getElectronScreenStreamByUserSelect(config: ScreenConstraintsWithElectron, captureAudio?: boolean): Promise<MediaStream>;
export declare function getLocalStream(config: GetUserMediaConfig, id: string): Promise<MediaStream>;
export declare function getNewNearestVideoProfile(width: number, height: number, frameRate: number): any;
export declare function getNewVideoBitrate(width: number, height: number, fps: number): [number, number];
export declare const getOriginSenderConfig: (track: LocalVideoTrack) => {
frameRate: number;
bitrateMax: number;
bitrateMin: number;
scaleResolutionDownBy: number;
scale: number;
};
export declare function getScalabilityConfiguration(profile: SVCConfiguration | SVCConfigurationPreset): SVCConfiguration;
export declare function getScreenEncoderConfiguration(profile: VideoEncoderConfiguration | ScreenEncoderConfigurationPreset | string): VideoEncoderConfiguration;
export declare function getSilenceAudioTrack(): MediaStreamTrack;
export declare function getSilenceSamplesDuration(buffer: AudioBuffer): number;
export declare function getStaticTrackStream(track: MediaStreamTrack, interval?: number): MediaStreamTrack | void;
export declare interface GetUserMediaConfig {
video?: MediaTrackConstraints;
audio?: MediaTrackConstraints;
screen?: ScreenConstraintsWithElectron;
videoSource?: MediaStreamTrack;
audioSource?: MediaStreamTrack;
screenAudio?: boolean | MediaTrackConstraints;
}
export declare function getVideoEncoderConfiguration(profile: VideoEncoderConfigurationPreset | VideoEncoderConfiguration | undefined): VideoEncoderConfiguration;
export declare function handleGetUserMediaError(errorName: string, message?: string): AgoraRTCError;
export declare let HAS_GUM_AUDIO: boolean;
export declare let HAS_GUM_VIDEO: boolean;
export declare function hasAudioContext(): boolean;
export declare function hasMicrophoneTrack(): boolean;
/**
* Inherited from [LocalAudioTrack]{@link ILocalAudioTrack}, `BufferSourceAudioTrack` is an interface for the audio from a local audio file and adds several functions for controlling the processing of the audio buffer, such as starting processing, stopping processing, and seeking a specified time location.
*
* You can create an audio track from an audio file by calling [AgoraRTC.createBufferSourceAudioTrack]{@link IAgoraRTC.createBufferSourceAudioTrack}.
*/
export declare interface IBufferSourceAudioTrack extends ILocalAudioTrack {
/**
* The [source]{@link BufferSourceAudioTrackInitConfig.source} specified when creating an audio track.
*/
source: string | File | AudioBuffer | null;
/**
* The current state of audio processing, such as start, pause, or stop.
*/
currentState: AudioSourceState;
/**
* The total duration of the audio (seconds).
*/
duration: number;
/**
* @since
* <br>   *4.18.0*
*
* The playback speed of the current audio file. Valid range is [50, 400], where:
* - `50`: Half the original speed.
* - `100`: (Default) The original speed.
* - `400`: Four times the original speed.
*/
playbackSpeed: number;
/**
* @param event The event name.
* @param listener See [source-state-change]{@link event_source_state_change}.
*/
on(event: "source-state-change", listener: typeof event_source_state_change): void;
/**
* When the specified event happens, the SDK triggers the callback that you pass.
*
* @param event The event name.
* @param listener The callback function.
*/
on(event: string, listener: Function): void;
/**
* Gets the progress (seconds) of the audio buffer processing.
*
* @returns The progress (seconds) of the audio buffer processing.
*/
getCurrentTime(): number;
/**
* Starts processing the audio buffer.
*
* > Starting processing the audio buffer means that the processing unit in the SDK has received the audio data. If the audio track has been published, the remote user can hear