我怎样才能navigator.mediaDevices.getUserMedia在http服务器上为所有浏览器工作。这可能吗?如何实现?
这是我的代码,不适用于 http,但适用于 https 服务器
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);
Run Code Online (Sandbox Code Playgroud)
Google Chrome 和 Mozilla Firefox 似乎只允许navigator.mediaDevices安全的 https 连接。您可以使用启动标志在 Chrome 上覆盖此选项:
--unsafely-treat-insecure-origin-as-secure="http://example.com"
您可以在这里找到更多信息: