In real-time scenarios requiring high quality, conducting tests before joining a channel helps troubleshoot in advance and improve the overall user experience. You can perform the following pre-call tests:
This article describes how to implement these tests.
Agora provides an open-source sample project that implements pre-call tests on GitHub. You can refer to the source code in recordingDeviceControl.js
.
Follow these steps to test the microphone and camera:
AgoraRTC.getDevices
to get available devices.AgoraRTC.createCameraVideoTrack
to create a local video track, set cameraId
to test the camera. When calling AgoraRTC.createMicrophoneAudioTrack
to create a local audio track, set microphoneId
to test the microphone.CameraVideoTrack.play
to play the local video track.MicrophoneAudioTrack.getVolumeLevel
to get the current volume. A greater-than-zero volume means that the microphone is working.// Get all audio and video devices.
AgoraRTC.getDevices()
.then(devices => {
const audioDevices = devices.filter(function(device){
return device.kind === "audioinput";
});
const videoDevices = devices.filter(function(device){
return device.kind === "videoinput";
});
var selectedMicrophoneId = audioDevices[0].deviceId;
var selectedCameraId = videoDevices[0].deviceId;
return Promise.all([
AgoraRTC.createCameraVideoTrack({ cameraId: selectedCameraId }),
AgoraRTC.createMicrophoneAudioTrack({ microphoneId: selectedMicrophoneId }),
]);
})
.then([videoTrack, audioTrack] => {
videoTrack.play("<ELEMENT_ID_IN_DOM>");
setInterval(() => {
const level = audioTrack.getVolumeLevel();
console.log("local stream audio level", level);
}, 1000);
});
Agora recommends that you draw the UI for displaying the volume change and video, enabling users to check directly whether the devices are working.
The device ID is generated randomly and might change for the same device, so Agora recommends you call getDevices
before testing the devices.
Due to browser security limitations, the Agora Web SDK does not provide any API method for testing the audio playback device. You can test the audio playback device in either of the following ways:
<audio>
element to create an audio player on the web page for users to play an online audio file and confirm whether they can hear the sound.MicrophoneAudioTrack.play
to play the audio and check whether they can hear the audio.Perform a pre-call network quality test as follows:
Call createClient
twice to create two client objects:
Call createMicrophoneAndCameraTracks
to create a local audio track and a local video track.
The two client objects both call join
to join the same testing channel.
Call uplinkClient.publish
to publish the audio and video tracks, and then call downlinkClient.subscribe
to subscribe to the published audio and video tracks.
Listen for the uplinkClient.on("network-quality")
event to get the uplink network condition between the local device and Agora edge server.
Listen for the downlinkClient.on("network-quality")
event to get the downlink network condition between the local device and Agora edge server.
client.on("network-quality")
event once every two second.If you want to get more statistics of the audio and video tracks, such as the sending or receiving bitrate and the end-to-end delay, you can call uplinkClient.getLocalAudioStats
or uplinkClient.getLocalVideoStats
to get the uplink statistics, and call downlinkClient.getRemoteAudioStats
or downlinkClient.getRemoteVideoStats
to get the downlink statistics.
// Get the uplink network condition
uplinkClient.on("network-quality", (quality) => {
console.log("uplink network quality", quality.uplinkNetworkQuality);
});
// Get the downlink network condition
downlinkClient.on("network-quality", (quality) => {
console.log("downlink network quality", quality.downlinkNetworkQuality);
});
// Get the uplink statistics
uplinkVideoStats = uplinkClient.getLocalVideoStats();
// Get the downlink statistics
downlinkVideoStats = downlinkClient.getRemoteVideoStats()[<UPLINKCLIENT_UID>];
console.log("uplink video stats", uplinkVideoStats);
console.log("downlink video stats", downlinkVideoStats);