Salesforse LWC not working navigator.mediaDevices.enumerateDevices()

237 Views Asked by At

`

navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
  devices.forEach(function(device) {
    console.log(device.kind + ": " + device.label +
                " id = " + device.deviceId);
  });
})
.catch(function(err) {
  console.log(err.name + ": " + err.message);
});

Unable to receive audio devices and microphone in LWC. Maybe someone faced this problem?`

1

There are 1 best solutions below

0
On

With Lightning Locker Service a lot of the browsers native javascript objects (like window, document, etc.) are completely rewritten. This includes the navigator.mediaDevices object. Luckily Salesforce is making the switch to Lightning Web Security which opens some of these objects back up. It looks like you do have access to the navigator.mediaDevices object when Lightning Web Security is enabled. You can take a look at this article to see how to enable Lightning Web Security and use that object.