I'm currently exploring webRTC and what I want to do is to get all the mediadevices info along with deviceId
using navigator.mediaDevices.enumerateDevices();
and then separate it out according to its kind attribute and allow user to choose which media device to use for specific kind. Like Show a dropdown of cameras found and allow user to choose which camera to use which is why i need deviceId of each device.
This is code I'm currently using to get mediadevices:
const getConnectedDevices = async (type, callback) => {
const mediaDevices = await navigator.mediaDevices.enumerateDevices();
console.log(mediaDevices);
callback(mediaDevices.filter((device) => device.kind === type));
};
And this is what I got back as output:
[
{
deviceId: ""
groupId: "51081772b5c5df2dbcb2ca2b8ae36c5d693d816f8d4bf4039cdb15802b7ffc54"
kind: "audioinput"
label: ""
},
{
deviceId: ""
groupId: "2e7a46f912e66fea3b6af4822e427c02a7725c39d86194dccdf5b7993293d7da"
kind: "videoinput"
label: ""
},
{
deviceId: ""
groupId: "51081772b5c5df2dbcb2ca2b8ae36c5d693d816f8d4bf4039cdb15802b7ffc54"
kind: "audiooutput"
label: ""
}
]
getting a empty deviceId all the time.
I also tried calling await navigator.mediaDevices.getUserMedia( {video: true,audio: true,})
before await navigator.mediaDevices.enumerateDevices()
but still got same result.