[英]navigator.mediaDevices.getUserMedia with http server
How can I make navigator.mediaDevices.getUserMedia
work on a http server for all browsers.如何让
navigator.mediaDevices.getUserMedia
在 http 服务器上为所有浏览器工作。 Is it possible and how?有可能吗?怎么做?
This is my code that didn't work with http but worked with a https server这是我的代码,它不适用于 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);
It seems that Google Chrome and Mozilla Firefox only allow navigator.mediaDevices
over a secure https connections. Google Chrome 和 Mozilla Firefox 似乎只允许
navigator.mediaDevices
通过安全的 https 连接。 You can override this option on Chrome using the startup flag:您可以使用启动标志在 Chrome 上覆盖此选项:
--unsafely-treat-insecure-origin-as-secure="http://example.com"
You can find more information here:您可以在这里找到更多信息:
https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins
you can simply open this link on your chrome browser.您只需在 chrome 浏览器上打开此链接即可。 chrome://flags/#unsafely-treat-insecure-origin-as-secure.
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.
只需启用不安全来源,并将您的测试链接放在不安全来源选项旁边的框中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.