Search code examples
webrtc

How to get id of active camera with javascript?


I have successfully used webrtc to bind a local camera to a html element. I have more than one camera connected to my pc.

How can I use javascript to find out the DeviceID of the camera, that is now in use?


Solution

  • Get the tracks from the MediaStream you get from getUserMedia, look at the label property. See https://github.com/webrtc/samples/blob/master/src/content/getusermedia/gum/js/main.js#L23 for a sample.