DEVICE_ACCESS_DENIED switching camera

Hi,

I’m using OpenVidu browser. I found a strange behaviour on a Samsung Galaxy Tab A (2016) using Chrome (firstly tried with v74, but it didn’t solve updating to v80).

When I open the page, the camera permission correctly pops-up. I grant permission, and everything works fine. But switching to back camera (with Publisher.replaceTrack), OpenVidu throws a “DEVICE_ACCESS_DENIED” error. This doesn’t happen in other devices I tried (Samsung Galaxy A70, Samsung Galaxy A50, Google Nexus 5x, iPhone 8, Huawei P30 lite).

So, my question is: is there a way to force the browser to pop-up a new permission dialog for the other camera?

I don’t know. It seems a problem with the combination between browser and device operating system.

Maybe you can play with native WebRTC API to get access to the camera and then use OpenVidu methods.

I solved catching the error and using unpublish/publish instead of replaceTrack when the error occurs, and it now works with all browsers, IE6 Safari 12 included.

But I will give a try to the native WebRTC API too. I let you know if I’m lucky, thank you very much @micael.gallego .

Here is the pseudo-code:

var video_source = deviceId;

OV.getUserMedia({audioSource: false, videoSource: video_source})
.then(function (media)
{
    var new_camera = media.getVideoTracks()[0];
    publisher.replaceTrack(new_camera);
})
.catch(function (error)
{
    switch (error.name)
    {
        case 'DEVICE_ACCESS_DENIED':
            console.log('Access denied, trying republishing');

            session.unpublish(publisher);
            publisher = OV.initPublisher(undefined, {videoSource: video_source});
            publisher.addVideoElement(document.getElementById('video-element'));
            break;

        default:
            console.log(error);
            break;
    }
});