navigator.mediaDevices.getUserMedia不起作用,webkitGetUserMedia也不起作用

编程入门 行业动态 更新时间:2024-10-10 01:27:25
本文介绍了navigator.mediaDevices.getUserMedia不起作用,webkitGetUserMedia也不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直使用webkitGetUserMedia方法(getUserMedia通过adapter.js)在我的web应用程序中为webRTC获取相机和微件。我的服务器不安全(没有SSL证书)。它一切正常,直到我开始出现错误:getUserMedia()不再适用于不安全的起源。要使用此功能,您应该考虑将您的应用程序切换到安全来源,例如HTTPS。请参阅 goo.gl/rStTGz 了解更多详情。

我使用Google搜索,现在我看到了在Chrome中,我需要使用navigator.mediaDevices.getUserMedia()。我正在使用Chrome 47.0.2526.80 m,并且在此页面上 https:// developer。 mozilla/en-US/docs/Web/API/MediaDevices/getUserMedia 它说这个方法应该支持这个版本。但是,当我调用navigator.mediaDevices.getUserMedia时,我得到未定义。所以现在我无法在Chrome中使用这两种方法。

任何人都可以帮助我解决这个问题。 Thanks

解决方案

根据新的Chrome更新(来自Google Chrome 47),getUserMedia() chrome浏览器通过http://(Unsecure Origin),它可以在https://(Secure Origin)上运行。

为了开发目的, 1.localhost被视为HTTP上的安全源,因此如果您能够从本地主机运行服务器,则应该能够在该服务器上测试该功能。

2.您可以使用运行chrome - unsafely-treat-insecure-origin-as-secure =example标记(将example替换为您实际想要测试的来源),这会将该来源视为此会话的安全。请注意,您还需要包含 - user-data-dir = / test / only / profile / dir 以创建标志起作用的新测试配置文件。

参考: sites.google/a/chromium/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins

I've been using webkitGetUserMedia method (getUserMedia through adapter.js) to get the camera nad microhpone for webRTC on my web app. My server is not secure (no SSL certificate). It all worked fine until I started getting an error saying : "getUserMedia() no longer works on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See goo.gl/rStTGz for more details."

I googled and I saw that now in Chrome I need to use navigator.mediaDevices.getUserMedia(). I'm using Chrome 47.0.2526.80 m, and on this page developer.mozilla/en-US/docs/Web/API/MediaDevices/getUserMedia it says that this method should be supported for this version. However when I call navigator.mediaDevices.getUserMedia I get undefined. So now I cannot use either method in Chrome.

Can anyone please help me with this issue. Thanks

解决方案

As per new chrome update (From Google Chrome 47), getUserMedia() is no longer supported in chrome browser over (Unsecure Origin) , It will work on (Secure Origin)

For development purpose,

1.localhost is treated as a secure origin over HTTP, so if you're able to run your server from localhost, you should be able to test the feature on that server.

2.You can run chrome with the --unsafely-treat-insecure-origin-as-secure="example" flag (replacing "example" with the origin you actually want to test), which will treat that origin as secure for this session. Note that you also need to include the --user-data-dir=/test/only/profile/dir to create a fresh testing profile for the flag to work.

reference: sites.google/a/chromium/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins

更多推荐

navigator.mediaDevices.getUserMedia不起作用,webkitGetUserMedia也不起作用

本文发布于:2023-10-26 06:54:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529403.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:也不   不起作用   mediaDevices   navigator   webkitGetUserMedia

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!