MediaDevices selection

Update: 20220203 14:00

Selection of video input, audio input, and audio output is not easy because navigator.mediaDevices.enumerateDevices() does not work as expected. This is a simplified example code for learning how-to. For mobile device videoConstraints.facingMode = 'environment' may be required instead of deviceId. See: https://github.com/philnash/mediadevices-camera-selection/blob/master/app.js

  1. enumerateDevices() works only with https connection. (file:/// is OK with Firefox)
  2. getUserMedia() then enumerateDevices() without closing the stream got from getUserMedia()
  3. Close each track of the stream when device selection has been changed.
Reference implementation: https://github.com/webrtc/samples/tree/gh-pages/src/content/devices/input-output
Audio source:
Audio destination:
Video source:

Debug messages: