Agora Test/Switch a Media Device
// 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.createMicrophoneVideoTrack({ microphoneId: selectedMicrophoneId }),
]);
})
.then([videoTrack, audioTrack] => {
videoTrack.play("<ELEMENT_ID_IN_DOM>");
setInterval(() => {
const level = audioTrack.getVolumeLevel();
console.log("local stream audio level", level);
}, 1000);
});
Copy