I am trying to use Agora.io. Everything was working as it should. Until I add switching between cameras. I'm trying to switch between cameras thanks to the code below. But the problem is that I get this error: Uncaught TypeError: Cannot read properties of undefined (reading 'deviceId')
The error line is in the changeStreamSource() :
deviceId = devices.cameras[deviceIndex].deviceId;
Can you guide me on this?
function changeStreamSource (deviceIndex, deviceType) {
console.log('Switching stream sources for: ' + deviceType);
var deviceId;
var existingStream = false;
if (deviceType === "video") {
deviceId = devices.cameras[deviceIndex].deviceId;
}
localStreams.camera.stream.switchDevice(deviceType, deviceId, function(){
console.log('successfully switched to new device with id: ' + JSON.stringify(deviceId));
// set the active device ids
if(deviceType === "audio") {
localStreams.camera.micId = deviceId;
} else if (deviceType === "video") {
localStreams.camera.camId = deviceId;
} else {
console.log("unable to determine deviceType: " + deviceType);
}
}, function(){
console.log('failed to switch to new device with id: ' + JSON.stringify(deviceId));
});
}
devices isn't defined in your code. You can get a list of devices using AgoraRTC.getDevices method.