The audio/video input devices are identified by the device ID (deviceId). Each device has a unique device ID which you can get by getDevices. The device ID is randomly generated, and might change for the same device, so we recommend you call the getDevices method every time before switching the device.

  • For the Agora Web SDK v2.4.1 or earlier

    Set the microphoneId and cameraId parameters in the createStream method to switch the microphone and camera.

    1. Call the close method to close the local stream.
    2. Call the getDevices method to enumerate available devices and get the device IDs.
    3. Call the createStream method and fill the microphoneId or cameraId parameter with the device ID.
  • For the Agora Web SDK v2.5.0 or later
    Call the switchDevice method after getting the device ID. This method does not work on Safari 11 and Firefox.

If you do not need to select the input devices, set cameraId and microphoneId as "" in createStream to use the first input device by default.