Tutorial: Switching Cameras/Mics

Switching Cameras/Mics

This document describes how to switch the camera and mic during an audio/video call.

Switching Camera

Getting camera list

let cameras = null;
TRTC.getCameras().then(devices => {
  cameras = devices;
  devices.forEach(dev => {
    console.log('camera label: ' + dev.label + ' deviceId: ' + dev.deviceId);
  });
});

Switching camera

// Assume that the local stream has been published.
// Switch to the second camera
let cameraId = cameras[1].deviceId;
localStream.switchDevice('video', cameraId).then(() => {
  console.log('switch camera success');
});

Switching Mic

Getting mic list

let microphones = null;
TRTC.getMicrophones().then(devices => {
  microphones = devices;
  devices.forEach(dev => {
    console.log('microphone label: ' + dev.label + ' deviceId: ' + dev.deviceId);
  });
});

Switching mic

// Assume that the local stream has been published.
// Switch to the second mic
let micId = microphones[1];
localStream.switchDevice('audio', micId).then(() => {
  console.log('switch microphone success');
});