Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
Agora can not switch the camera getting : Cannot read properties of undefined (reading 'deviceId')

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));
  });
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

devices isn't defined in your code. You can get a list of devices using AgoraRTC.getDevices method.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!