AgoraWebSDK NG API Docs

The Agora Web SDK NG provides a JavaScript and Typescript library. Powered by WebRTC, it enables you to establish and manage audio and video communications or live broadcast services from a web browser.

The Agora Web SDK NG is compatible with mainstream browsers. For details, see Compatibility.

Ensure that you use the HTTPS protocol or localhost, otherwise the error WEB_SECURITY_RESTRICT occurs.

Suggestions

  • Agora recommends reading Basic Features before going into the API details.
  • You can use the search bar at the top of the page to find the intended API.

Global module

AgoraRTC is the entry point for all the methods provided by the Agora Web SDK NG. AgoraRTC provides the following methods:

Core methods

Method Description
createClient Creates a local client object.

Local audio and video methods

Method Description
createMicrophoneAudioTrack Creates an audio track from the audio sampled by a microphone.
createCameraVideoTrack Creates a video track from the video captured by a camera.
createMicrophoneAndCameraTracks Creates an audio track and a video track.
createScreenVideoTrack Creates a video track for screen sharing.
createBufferSourceAudioTrack Creates an audio track from an audio file.
createCustomAudioTrack Creates a customized audio track.
createCustomVideoTrack Creates a customized video track.

Media device methods

Method Description
getDevices Enumerates the media input and output devices available.
getCameras Enumerates the video capture devices available, such as cameras.
getMicrophones Enumerates the audio sampling devices available, such as microphones.
getPlaybackDevices Enumerates the audio playback devices available, such as speakers.
getElectronScreenSources Gets the sources for screen-sharing with Electron.

Logger methods

Method Description
enableLogUpload Enables log upload
disableLogUpload Disables log upload
setLogLevel Sets the output log level of the SDK

Global callbacks

Callback Description
onCameraChanged Occurs when a video capture device is added or removed.
onMicrophoneChanged Occurs when an audio sampling device is added or removed.
onAudioAutoplayFailed Occurs when the autoplay of an audio track fails.

Other methods

Method Description
checkSystemRequirements Checks the compatibility of the current browser.
getSupportedCodec Gets the codecs that the browser supports.
createChannelMediaRelayConfiguration Creates a ChannelMediaRelayConfiguration object

AgoraRTCClient

Call createClient to create an AgoraRTCClient object, which represents a local user in a voice or video communication or live broadcast. The AgoraRTCClient interface provides the major functions for a voice or video communication or live broadcast.

Method Description
join Joins a channel.
leave Leaves a channel.
publish Publishes local audio and/or video tracks to a channel.
unpublish Unpublishes the local audio and/or video tracks.
subscribe Subscribes to the audio and/or video tracks of a remote user.
unsubscribe Unsubscribes from the audio and/or tracks of a remote user.

LocalTrack

localTrack is the abstract interface that defines local audio and video tracks and can be used for playing and publishing audio and video.

You can call different methods to create different local track objects based on the derived interfaces of localTrack:

Local audio tracks

The SDK provides the following three kinds of local audio tracks. LocalAudioTrack is derived from LocalTrack; MicrophoneAudioTrack and BufferSourceAudioTrack is derived from LocalAudioTrack.

Local Audio Track Description
LocalAudioTrack The basic interface for local audio tracks, providing the main methods of managing local audio, such as playing and setting volume.
Created by calling AgoraRTC.createCustomAudioTrack.
MicrophoneAudioTrack The interface for the audio sampled by a local microphone, adding functions such as switching devices.
Created by calling AgoraRTC.createMicrophoneAudioTrack.
BufferSourceAudioTrack The interface for the audio from a local audio file, adding functions for controlling the processing of the audio buffer.
Created by calling AgoraRTC.createBufferSourceAudioTrack.

Local video tracks

The SDK provides the following two kinds of local video tracks. LocalVideoTrack is derived from LocalTrack, and CameraVideoTrack is derived from LocalVideoTrack.

Local Video Track Description
LocalVideoTrack The basic interface for local video tracks, providing the main methods for managing local video, such as playing and applying image enhancement.
Created by calling AgoraRTC.createCustomVideoTrack or AgoraRTC.createScreenVideoTrack.
CameraVideoTrack The interface for the video captured by a local camera, adding functions such as switching devices and adjusting video encoder configurations.
Created by calling AgoraRTC.createCameraVideoTrack.

RemoteTrack

RemoteTrack is the abstract interface that defines remote audio and video tracks.

To get a remote track: Call subscribe to subscribe to a remote user, and then get the RemoteAudioTrack track and the RemoteVideoTrack track from AgoraRTCRemoteUser. Both RemoteAudioTrack and RemoteVideoTrack are derived from RemoteTrack.

Import the SDK

If you use <script> to import the Agora Web SDK NG, you can call AgoraRTC.createClient to get the exported modules.

If you use npm to import the SDK, see the following code:

import AgoraRTC from "agora-web-sdk-ng"
console.log(AgoraRTC.createClient);

Typed modules (for Typescript)

Agora provides a .d.ts file for Typescript developers to export all type definitions. See Global for all the modules and types that the Agora Web SDK NG exports.

import AgoraRTC, { IAgoraRTCClient } from "agora-rtc-sdk-ng";

const client: IAgoraRTCClient = AgoraRTC.createClient();