javascriptwebrtchardware

getUserMedia - Cannot access camera from two browsers at the same time


I've been experimenting with webRTC for my next project to create a video chat and testing has been difficult. I have this simple code to access the camera:

        navigator.getUserMedia = navigator.getUserMedia ||
                                 navigator.webkitGetUserMedia ||
                                 navigator.mozGetUserMedia ||
                                 navigator.msGetUserMedia;

        var video = document.querySelector('#av-chat video');

        if (navigator.getUserMedia) {
          navigator.getUserMedia({audio: true, video: true}, function(stream) {
            video.src = window.URL.createObjectURL(stream);
          }, errorCallback);
        }

which works fine on chrome and mozilla but when I try to do it together, it doesn't work. What I mean by together is like opening the same file with this code in two browsers. It seems that when one browser has access to the camera, it blocks it for anyone else.

I have not seen this issue discussed on the internet so I was wondering, is it just me? If not, is there a solution?


Solution

  • This is a limitation on Windows. On Mac OS you can use the same camera in multiple applications at the same time but not in Windows unfortunately. You have a few options here:

    1. Buy a Mac 😛
    2. Get a second USB camera to use in your second application while testing.
    3. Install some software for splitting your camera or creating a virtual camera.
    4. Use fake devices in either Chrome or Firefox (or both) for testing (like Philipp suggested). It's actually quite easy to turn on fake devices in Firefox and it's free so that's probably the best option if you don't already have another USB camera sitting around.
      1. Just go to about:config in your URL bar
      2. Accept the warning message
      3. Add a new Boolean value. You do this by right clicking and choosing New->Boolean.
      4. Then enter media.navigator.streams.fake
      5. Choose true as the value. enter image description here Now when you use your camera you will get a fake video and audio sound.