navigator.mediaDevices.getUserMedia with http server

Viewed 4443

How can I make navigator.mediaDevices.getUserMedia work on a http server for all browsers. Is it possible and how?

This is my code that didn't work with http but worked with a https server

navigator.mediaDevices.getUserMedia({ video: true, audio: false })
         .then(function(stream) {
             video.srcObject = stream;
             video.play();
            })
         .catch(function(err) {
            console.log("An error occurred! " + err);
            });

  video = document.getElementById('video');
  video.addEventListener('canplay', function(ev){
  if (!streaming) {
    
    height = video.videoHeight / (video.videoWidth/width);
  
    video.setAttribute('width', width);
    video.setAttribute('height', height);
    canvas.setAttribute('width', width);
    canvas.setAttribute('height', height);
    streaming = true;
  }
}, false);
2 Answers

you can simply open this link on your chrome browser. chrome://flags/#unsafely-treat-insecure-origin-as-secure . And just enable the insecure origin and also put your testing link in the box given next to the insecure origin option.

Related