Adds the Audio or Video Track
This method adds the audio or video tracks into the stream.
When the track is added, the Client.on("stream-updated")
is triggered on the remote client.
The track can be retrieved from the mediaStream
method.
Adjusts Audio Mixing Volume
The volume of the mixing audio. The value ranges between 0 and 100 (default).
Closes the Stream
This method closes the stream.
After calling this method, the camera and microphone authorizations are reset.
Disables the Audio
DEPRECATED from v 2.5.1, use muteAudio instead.
This method disables the audio track in the stream.
It works only when the audio flag is true
in the stream.
Disables the Video
DEPRECATED from v 2.5.1, use muteVideo instead.
This method disables the video track in the stream.
It works only when the video flag is true
in the stream.
Enables the Audio
DEPRECATED from v 2.5.1, use unmuteAudio instead.
This method enables the audio track in the stream.
It works only when the audio flag is true
in the stream.
By default the audio track is enabled. If you call disableAudio, call this method to enable audio.
Enables the Video
DEPRECATED from v 2.5.1, use unmuteVideo instead.
This method enables the video track in the stream.
It works only when the video flag is true
in the stream.
By default the video track is enabled. If you call disableVideo, call this method to enable video.
Retrieves the Current Audio Level
This method retrieves the current audio level.
Call setTimeout
or setInterval
to retrieve the local or remote audio change.
The audio level. The value range is [0,1].
Retrieves the Current Position of the Audio Mixing
Retrieves the playback position (ms) of the audio.
Returns the current position of the audio mixing if successful.
Retrieves Audio Mixing Duration
Returns the audio mixing duration (ms) if successful.
Retrieves the Audio Track
This method retrieves the audio track in the stream and can be used together with replaceTrack.
If the stream contains an audio track, it will be returned in a MediaStreamTrack
object.
Gets the volume of the audio effects.
Returns an array that contains soundId
and volume
. Each soundId
has a correspondingvolume
.
soundId
: The ID of the audio effect. Each audio effect has a unique ID. The value range is [1,10000].volume
: Volume of the audio effect. The value range is [0,100].Retrieves the Stream ID
This method retrieves the stream ID.
Gets Connection Statistics
This method gets the connection statistics of the stream.
Note
It may take some time to get some of the statistics.
The callback contains the connection statistics of the stream.
Retrieves the Video Track
This method retrieves the video track in the stream and can be used together with replaceTrack.
If the stream contains a video track, it will be returned in a MediaStreamTrack
object.
Retrieves the Audio Flag
This method retrieves the audio flag and only works for local streams.
Retrieves the Video Flag
This method retrieves the video flag and only works for local streams.
Initializes the Stream Object
This method initializes the local stream object.
If this method fails, see getUserMedia Exceptions for error information.
Some errors might be returned in the callback, for example: {type: "error", msg: "NotAllowedError", info: "Permission denied"}
.
The possible error information in the msg
field includes:
The info
field shows the extra information for the error. If no more extra information, its value will be null
.
The callback when the method succeeds.
The callback when the method fails.
Returns Whether the Stream is Playing
true
: The stream is being rendered or playing on the page.false
: The stream is neither being rendered nor playing on the page.Disables the Audio
This method disables the audio track in the stream.
Client.on("mute-audio")
callback on the remote client.Note For local streams, it works only when the audio flag is true
in the stream.
true
: Success.false
: Failure. Possible reasons include no audio, stream not initialized, and audio track already disabled.Disables the Video
This method disables the video track in the stream.
Client.on("mute-video")
callback on the remote client.Note For local streams, it works only when the video flag is true
in the stream.
true
: Success.false
: Failure. Possible reasons include no video, stream not initialized, and video track already disabled.Occurs when the user gives access to the camera and microphone.
Occurs when the user denies access to the camera and microphone.
Occurs when screen-sharing stops.
Occurs when the video track no longer provides data to the stream.
Possible reasons include device removal and deauthorization. See MediaStreamTrack.onended.
Occurs when the audio track no longer provides data to the stream.
Possible reasons include device removal and deauthorization. See MediaStreamTrack.onended.
Occurs when the audio mixing stream playback starts/resumes.
Note This callback is triggered when the audio mixing stream is loaded and starts playing, or when the paused audio mixing stream resumes playing.
Occurs when the last audio mixing stream playback finishes.
Occurs when the stream playback status changes.
On Windows, frequent DOM manipulations might cause the browser to pause the Chrome player. To avoid this, you can listen for this event and call the Stream.resume method to resume the playback.
This callback has the following properties.
Pauses all audio effects.
Pauses Audio Mixing
Pauses a specified audio effect.
The ID of the audio effect. Each audio effect has a unique ID. The value range is [1,10000].
Plays the Audio/Video Stream
This method plays the video or audio stream.
Note
Due to browser policy changes, this method must be triggered by the user's gesture on the Chrome 70+ and Safari browsers. See Autoplay Policy Changes for details.
Represents the HTML element ID. Digits and letters in the ASCII character set, “_”, “-", and ".". The string length must be greater than 0 and less than 256 bytes.
Options for playing the stream.
Video display mode:
"cover"
: Uniformly scale the video until it fills the visible boundaries (cropped).
One dimension of the video may have clipped contents. Refer to the cover
option of object-fit
in CSS.
"contain"
: Uniformly scale the video until one of its dimension fits the boundary (zoomed to fit).
Areas that are not filled due to the disparity in the aspect ratio will be filled with black. Refer to the contain
option of object-fit
in CSS.
For local streams, by default the cover mode is used for video playing and the contain mode is used for screen sharing; for remote streams, by default the cover mode is used.
Sets whether to mute the playing stream.
The muted
flag can be used as a workaround for the browser's autoplay policy.
On Chrome 70+ and Safari, a video stream with sound does not play until triggered by a user gesture.
If you want to play the video anyway without a user gesture, you can set the muted
flag to true, so that the video is automatically played without sound.
For more information, see Autoplay Policy Changes.
Whether or not the playback succeeds.
null
if the playback succeeds.Plays a specified audio effect.
This method supports playing multiple audio effect files at the same time, and is different from startAudioMixing.
You can use this method to add specific audio effects for specific scenarios. For example, gaming.
Note
Audio effect options.
The number of playback loops (only supported on Chrome 65 and later).
A positive integer. The value range is [1,10000]. The default value is 1.
The URL of the online audio effect file.
The URL must contain ASCII characters only, and the string length must be greater than 0 and less than 256 bytes.
Supported audio formats: MP3, AAC, and other audio formats depending on the browser.
The ID of the specified audio effect.
A positive integer. The value range is [1,10000]. Each audio effect has a unique ID.
If the audio effect is preloaded into the memory through the preloadEffect method, ensure that the soundId value is set to the same value as in preloadEffect.
The callback of this method:
Note
The callbacks of the audio effect methods all use the Node.js callback pattern.
Preloads a specified audio effect file into the memory.
To ensure smooth communication, limit the size of the audio effect file.
The ID of the audio effect. Each audio effect has a unique ID. The value range is [1,10000].
The URL of the online audio effect file. Supports MP3, AAC, and other audio formats depending on the browser.
Removes the Audio or Video Track
This method removes the audio or video tracks from the stream.
When the track is removed, the Client.on("stream-updated")
callback is triggered on the remote client.
Note
The track can be retrieved from the mediaStream
method.
Replaces the Audio/Video Track
This method replaces the audio or video MediaStreamTrack
in the local stream.
After the local stream is published, you can use this method to switch the cameras, or switch between the microphone and the music player.
The new track can be retrieved by getUserMedia
, MediaElement.captureStream
or other methods.
The replaced track will be stopped.
Note
The new track.
The callback when the method succeeds.
The callback when the method fails. The following are common errors:
"INVALID_TRACK"
and "INVALID_TRACK_TYPE"
: The MediaStreamTrack object cannot be recognized."MEDIASTREAM_TRACK_NOT_FOUND"
: The track to be replaced is not found, for example, replacing a video track in an audio-only stream."NO_STREAM_FOUND"
: The local stream object is not found.Resumes the Audio/Video Stream Playback
This method can be used when the playback fails after calling the Stream.play method. In most cases, the playback is stopped due to the browser policy.
This method needs to be triggered by a user gesture. See Autoplay Policy Changes for more information.
Resumes playing all audio effects.
Resumes Audio Mixing
When the audio mixing file playback resumes, the SDK triggers the Stream.on("audioMixingPlayed")
callback on the local client.
Resumes playing a specified audio effect.
The ID of the audio effect. Each audio effect has a unique ID. The value range is [1,10000].
Sets the Audio Mixing Position
Sets the playback position of the audio mixing file to a different start position (by default plays from the beginning).
The time (ms) to start playing the audio mixing file, an integer. The value range is [0,100000000].
Sets the Audio Output
This method sets the audio output device for the remote stream. You can use it to switch between the speakerphones. It can be called either before or after the remote stream is played.
Note
Only Chrome 49 or later supports this function.
The device ID can be retrieved from getDevices, whose kind should be "audiooutput". The retrieved ID is ASCII characters, and the string length is greater than 0 and less than 256 bytes.
The callback when the method succeeds.
The callback when the method fails.
Sets the Audio Profile
This method sets the audio profile of the local stream.
It is optional and works only when called before Stream.init. The default value is "music_standard"
.
Note
Due to the limitations of browsers, some browsers may not be fully compatible with the audio profile you set.
AEC
, AGC
, and ANS
options in audioProcessing are automatically disabled.The audio profile has the following options:
"speech_low_quality"
: Sample rate 16 kHz, mono, encoding rate 24 Kbps."speech_standard"
: Sample rate 32 kHz, mono, encoding rate 24 Kbps."music_standard"
: Sample rate 48 kHz, mono, encoding rate 40 Kbps."standard_stereo"
: Sample rate 48 kHz, stereo, encoding rate 64 Kbps."high_quality"
: Sample rate 48 kHz, mono, encoding rate 128 Kbps."high_quality_stereo"
: Sample rate 48 kHz, stereo, encoding rate 192 Kbps.Sets the Volume
This method set the volume for the remote stream.
It can be called either before or after the remote stream is played.
Ranges from 0 (muted) to 100 (loudest). The default value is 100.
Enables/Disables image enhancement and sets the options.
Since
3.0.0
This method is asynchronous, and must be called with Promise
or async
/await
keywords.
The image enhancement function involves real-time compute-intensive processing. Though it is based on hardware acceleration, the processing has high GPU and CPU overheads. For low-end devices, enabling image enhancement affects the system performance. When the video resolution is set as 360p, 720p or higher, and the frame rate is set as 30 fps or 15 fps, do not enable image enhancement.
This method supports the following browsers:
Note
setBeautyEffectOptions
after the method call of replaceTrack
or addTrack
succeeds.Client.on("stream-published")
callback.Whether to enable image enhancement:
true
: Enable image enhancement.false
: (Default) Disable image enhancement.The image enhancement options.
The contrast level, used with the lighteningLevel
parameter.
The brightness level.
The value ranges from 0.0 (original) to 1.0. The default value is 0.7.
The redness level.
The value ranges from 0.0 (original) to 1.0. The default value is 0.1. This parameter adjusts the red saturation level.
The sharpness level.
The value ranges from 0.0 (original) to 1.0. The default value is 0.5. This parameter is usually used to remove blemishes.
A promise object, which is resolved after the method call succeeds.
Sets the volume of the audio effects.
Volume of the audio effect. The value range is [0,100].The default value is 100 (the original volume).
Sets the Screen Profile
This method sets the profile of the screen in screen-sharing. Ensure that you call this method before Stream.init.
Note
This method works for local streams only.
The screen profile. See the following table for details.
Screen Profile Definition
Screen Profile | Resolution | Frame Rate |
---|---|---|
480p_1 | 640 × 480 | 5 |
480p_2 | 640 × 480 | 30 |
720p_1 | 1280 × 720 | 5 |
720p_2 | 1280 × 720 | 30 |
1080p_1 | 1920 × 1080 | 5 |
1080p_2 | 1920 × 1080 | 30 |
Note:
Due to limitations of some devices and browsers, the resolution you set may fail to take effect and get adjusted by the browser. In this case, billings will be calculated based on the actual resolution.
Customizes the Video Encoder Configuration
You can use this method to customize the video resolution, frame rate, and bitrate of the local stream. This method can be called before or after Stream.init.
Note
audioSource
and videoSource
properties), the resolution and frame rate setting does not take effect.Sets the Video Profile
This method sets the video encoding profile for the local stream. Each video encoding profile includes a set of parameters, such as the resolution, frame rate, and bitrate. The default value is "480p_1"
.
This method is optional and is usually called before Stream.init. From v2.7, you can also call this method after Stream.init to change the video encoding profile.
Note
audioSource
and videoSource
properties), the resolution and frame rate setting does not take effect.The video profile. See the following table for its definition and supported profiles in different scenarios.
Video Profile Definition
Video profile | Resolution | Frame rate (fps) | Bitrate (Kbps) | Chrome | Firefox | Safari |
---|---|---|---|---|---|---|
120p_1 | 160 × 120 | 15 | 65 | ✓ | ||
120p_3 | 120 × 120 | 15 | 50 | ✓ | ||
180p_1 | 320 × 180 | 15 | 140 | ✓ | ||
180p_3 | 180 × 180 | 15 | 100 | ✓ | ||
180p_4 | 240 × 180 | 15 | 120 | ✓ | ||
240p_1 | 320 × 240 | 15 | 200 | ✓ | ||
240p_3 | 240 × 240 | 15 | 140 | ✓ | ||
240p_4 | 424 × 240 | 15 | 220 | ✓ | ||
360p_1 | 640 × 360 | 15 | 400 | ✓ | ||
360p_3 | 360 × 360 | 15 | 260 | ✓ | ||
360p_4 | 640 × 360 | 30 | 600 | ✓ | ||
360p_6 | 360 × 360 | 30 | 400 | ✓ | ||
360p_7 | 480 × 360 | 15 | 320 | ✓ | ||
360p_8 | 480 × 360 | 30 | 490 | ✓ | ||
360p_9 | 640 × 360 | 15 | 800 | ✓ | ||
360p_10 | 640 × 360 | 24 | 800 | ✓ | ||
360p_11 | 640 × 360 | 24 | 1000 | ✓ | ||
480p_1 | 640 × 480 | 15 | 500 | ✓ | ✓ | ✓ |
480p_2 | 640 × 480 | 30 | 1000 | ✓ | ✓ | ✓ |
480p_3 | 480 × 480 | 15 | 400 | ✓ | ✓ | ✓ |
480p_4 | 640 × 480 | 30 | 750 | ✓ | ✓ | ✓ |
480p_6 | 480 × 480 | 30 | 600 | ✓ | ✓ | ✓ |
480p_8 | 848 × 480 | 15 | 610 | ✓ | ✓ | ✓ |
480p_9 | 848 × 480 | 30 | 930 | ✓ | ✓ | ✓ |
480p_10 | 640 × 480 | 10 | 400 | ✓ | ✓ | ✓ |
720p_1 | 1280 × 720 | 15 | 1130 | ✓ | ✓ | ✓ |
720p_2 | 1280 × 720 | 30 | 2000 | ✓ | ✓ | ✓ |
720p_3 | 1280 × 720 | 30 | 1710 | ✓ | ✓ | ✓ |
720p_5 | 960 × 720 | 15 | 910 | ✓ | ✓ | ✓ |
720p_6 | 960 × 720 | 30 | 1380 | ✓ | ✓ | ✓ |
1080p_1 | 1920 × 1080 | 15 | 2080 | ✓ | ✓ | |
1080p_2 | 1920 × 1080 | 30 | 3000 | ✓ | ✓ | |
1080p_3 | 1920 × 1080 | 30 | 3150 | ✓ | ✓ | |
1080p_5 | 1920 × 1080 | 60 | 4780 | ✓ | ✓ | |
1440p | 2560 × 1440 | 30 | 4850 | ✓ | ✓ | |
1440p_1 | 2560 × 1440 | 30 | 4850 | ✓ | ✓ | |
1440p_2 | 2560 × 1440 | 60 | 7350 | ✓ | ✓ | |
4K_1 | 3840 × 2160 | 30 | 8910 | ✓ | ✓ | |
4K_3 | 3840 × 2160 | 60 | 13500 | ✓ | ✓ |
Note:
Whether 1080 resolution or above can be supported depends on the device. If the device cannot support 1080p, the actual frame rate is lower than the one listed in the table. Agora optimizes the video on low-end devices.
With the update of web browsers, this table might not reflect all the supported profiles for each browser. The actual support is subject to the device and web browser version.
Some versions of some web browsers might not support all the video profiles listed in the table. In this case, we recommend you use the mainstream video profiles (the ones with the _1
suffix in the above table).
The Safari browser does not support modifying the video frame rate (30 fps by default). If you set a frame rate other than 30 fps on Safari, the browser may change or reject your setting.
Due to limitations of some devices and browsers, the resolution you set may fail to take effect and get adjusted by the browser. In this case, billings are calculated based on the actual resolution.
Sets the volume of a specified audio effect.
The ID of the audio effect. Each audio effect has a unique ID. The value range is [1,10000].
Volume of the audio effect. The value range is [0,100].The default value is 100 (the original volume).
Starts Audio Mixing
This method mixes the specified online audio file with the audio stream from the microphone; or, it replaces the microphone’s audio stream with the specified online audio file.
You can specify the number of playback loops and play time duration.
When the audio mixing file playback starts, the SDK triggers the Stream.on("audioMixingPlayed")
callback on the local client.
When the audio mixing file playback finishes, the SDK triggers the Stream.on("audioMixingFinished")
callback on the local client.
Note
Audio mixing settings.
Whether or not to store the audio mixing file in the cache.
true
: (default) store the audio mixing file in the cache to speed up mixing this file the next time.false
: do not store the audio mixing file in the cache to save RAM.Number of playback loops (only supports Chrome 65+)
A positive integer. The value range is [1,10000]. The default value is 1.
Path of the online audio file to mix. ASCII characters only, and the string length must be greater than 0 and less than 256 bytes.
Supported audio formats: mp3, aac, and other audio formats depending on the browser.
Whether the audio mixing file loops infinitely.
true
: The audio mixing file loops infinitely. Do not use this option if cycle
is specified.false
: (Default) Disables the infinite loops.Sets the playback position (ms) of the audio mixing file. An integer, and the value range is [0,100000000].
If you need to play the file from the beginning, set this paramter to 0.
Whether the online audio file replaces the local audio stream.
true
: The content of the online audio file replaces the audio stream from the microphone.false
: (Default) The online audio file is mixed with the audio stream from the microphone.Note
Safari does not support this parameter.
The callback of this method:
null: The method succeeds.
err: The method fails. Possible errors:
Note The callbacks of the other audio mixing methods are the same as this one, using the Node.js callback pattern.
Stops the Stream Playback
Call this method to stop playing the stream set by Stream.play.
Stops playing all audio effects.
Stops Audio Mixing
Stops playing a specified audio effect.
The ID of the audio effect. Each audio effect has a unique ID. The value range is [1,10000].
Switches the Media Input Device
This method switches between the media input devices:
If you call this method after publish, there is no need to re-publish the stream after switching the device.
This method does not support the following scenarios:
Note
This method might not take effect on some mobile devices.
Type of the device: "audio" or "video".
Device ID, which can be retrieved from getDevices. The retrieved ID is ASCII characters, and the string length is greater than 0 and less than 256 bytes.
The callback when the method succeeds.
The callback when the method fails.
Releases a specified preloaded audio effect from the memory.
The ID of the audio effect. Each audio effect has a unique ID. The value range is [1,10000].
Enables the Audio
This method enables the audio track in the stream.
If you call this method to enable the audio track for local streams, the Client.on("unmute-audio")
callback is triggered on the remote client.
Note For local streams, it works only when the audio flag is true
in the stream.
By default the audio track is enabled. If you call muteAudio, call this method to enable audio.
true
: Success.false
: Failure. Possible reasons include no audio, stream not initialized, and audio track already enabled.Enables the Video
This method enables the video track in the stream.
If you call this method to enable the audio track for local streams, the Client.on("unmute-video")
callback is triggered on the remote client.
Note For local streams, it works only when the video flag is true
in the stream.
By default the video track is enabled. If you call muteVideo, call this method to enable video.
true
: Success.false
: Failure. Possible reasons include no video, stream not initialized, and video track already enabled.
The Stream interface provides methods that define the behaviors of a Stream object, such as the playback control and video encoder configurations.
The Stream object is created by the createStream method. A stream represents a published local or subscribed remote media stream object in a call session.
All Stream methods can be called for both local and remote streams if not specified.