How to get device IDs of camera/microphone currently being used by publisher?

Hi there, is there a way to quickly get the device ID of the camera/microphone that is currently being used by a publisher? I initialize the publisher videoSource/audioSource with undefined which just uses the default webcam/microphone from my understanding.

Later in the session though, I would like to display some info about the webcam/microphone being used but I don’t know how to retrieve that info and I can’t really find anything about this from the documentation.

I see how to get a list of all possible media devices but that doesn’t really inform me of the device IDs that are currently being used. Is there a way to do this?

Hope that makes sense.

Thanks!

Hi,

as far as I see it, there is no “simple” OpenVidu method for doing this.
But you can use the stream property of your Publisher object to get the underlying MediaStream object. According to the MDN documentation (MediaStream) this object provides both a getVideoTracks() as well as a getAudioTracks() methods which returns an array of MediaStreamTrack objects (in most cases their should only be one video and one audio track, but you should check docs for more informations and should consider a case where their is more than one track of each kind). This object has id and label properties, which are the same as deviceId and label of the corresponding Device (see in OV docs) object in OpenVidu methods.

So you could do something like this to get the id of the currently used camera:
OpenVidu.initPublisher(...).stream.getMediaStream().getVideoTracks()[0].id

Hope this helps, although you may have already figured this out yourself by now :slight_smile:

Regards
Sven

1 Like

Thanks for the response :slight_smile: I finally got around to fixing this issue in my app.

You pointed me in the right direction, but there was one little tweak I needed to make. Just wanted to make note of it in case anyone else runs into the same issue I did. The id of the MediaStreamTrack object is actually not the same as the deviceId. In order to get the deviceId associated with the MediaStreamTrack, you need to call MediaStreamTrack.getSettings().deviceId.

1 Like