The Real-time Communication (RTC) SDK provides methods to test audio and video devices. Before a call, you can check whether your camera, microphone, and speakers are working correctly to ensure good call quality. This topic describes how to test these devices.
Implementation
Collection device test
Follow these steps to verify that your local microphone and camera are working correctly:
Retrieve the active devices and their IDs using the device management API.
Select a device ID from the previous step. Specify this ID when you call createMicrophoneAudioTrack() and createCameraVideoTrack() to create local audio and video track objects.
After the resource is created, you can start testing:
Call the play() method of the camera track. If the video is displayed correctly, the camera is working correctly.
Call the getVolumeLevel() method of the microphone track. If the return value is greater than 0, the microphone is working correctly.
Sample code:
import DingRTC from 'dingrtc';
DingRTC.getCameras().then(async (cameraList) => {
const cameraId = cameraList[0].deviceId;
const cameraTrack = await DingRTC.createCameraVideoTrack({ deviceId: cameraId });
cameraTrack.play('#videoWrapper');
})
DingRTC.getMicrophones().then(async (microphoneList) => {
const microphoneId = microphoneList[0].deviceId;
const microphoneTrack = await DingRTC.createMicrophoneAudioTrack({ deviceId: microphoneId });
setInterval(() => {
console.log(`audioLevel: ${microphoneTrack.getVolumeLevel()}`)
}, 600);
})
Test the speaker
The RTC SDK does not provide a dedicated API for testing the speaker. However, you can use one of the following methods to perform the test:
Use the HTML audio tag to play an audio file and check if you can hear the sound.
After capturing audio from the microphone, call the play() method of the microphone track object and check if you can hear the sound.