科尔多瓦:getUserMedia()不再适用于不安全的来源 [英] Cordova: getUserMedia() no longer works on insecure origins

查看:73
本文介绍了科尔多瓦:getUserMedia()不再适用于不安全的来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况

在我的Cordova混合应用程序(使用 Quasar 框架构建)中,我需要添加一个视频-通话功能.

In my Cordova hybrid app (built with Quasar framework), I need to a add a video-call feature.

我需要使用函数 getUserMedia().

在localhost上进行测试时,一切正常,但是在设备上进行测试时,一切正常.

Everything works fine while testing on localhost, but when testing on the device it doesn't work.

错误:

[不推荐使用] getUserMedia()不再适用于不安全的来源.要使用此功能,您应该考虑将应用程序切换到安全来源,例如HTTPS.

此错误很可能是由于Cordova不在https上运行这一事实引起的.

Most probably this error is caused by the fact that Cordova doesn't run on https.

尝试:

我已尽我所能在Google上找到的所有内容,但无济于事.

I have tried everything I could find on Google but nothing worked..

人行横道:

我看到有人建议安装 crosswalk 插件.我已经尝试过,但没有任何改变.

I have seen somebody suggesting to install the crosswalk plugin. I have tried but nothing changed.

权限:

我尝试使用 android-permissions 插件请求权限.

I have tried asking for permission using the android-permissions plugin.

但是当它提示请求时,尽管单击了 ALLOW 按钮,但权限仍设置为 DENIED_ALWAYS ...

But when it prompt the request, despite clicking on the ALLOW button, the permission was set to DENIED_ALWAYS...

我尝试使用 diagnostic cordova插件,但结果是相同的

I have tried using the diagnostic cordova plugin, but the result was the same

问题:

如何在cordova应用程序中使用 getUserMedia()?

How can I use getUserMedia() in a cordova app?

编辑-解决方案:

@Andre解决方案是解决该问题的正确方法.

@Andre solution is the correct solution to the question.

我在设备的开发环境中运行应用程序时遇到了该错误.Quasar在192.168.0.18上运行我的devServer,该主机与localhost不同,因此未被识别为安全.

I was getting that error while running the app in a dev environment in my device. Quasar run my devServer on 192.168.0.18, that is not same as localhost, and thus not recognized as secure.

通过在配置中设置 https:true ,该问题已解决.

By setting https: true in the config, that issue was resolved.

构建应用程序后,Cordova在file://上运行,并且在file://协议上没有不安全的来源问题,如@jcesarmobile在评论中指出的那样.

After building the app, Cordova run on file://, and on the file:// protocol there is no insecure origin issue, as pointed out by @jcesarmobile in the comments.

我在构建时仍然有问题,但与该问题本身无关,但是涉及权限,我设法使用 cordova-plugin-android-permissions 插件解决了这些问题.

I had still problems on build, but not related with this problem itself, but involving permissions, and I managed to resolve them using the cordova-plugin-android-permissions plugin.

推荐答案

您不能.

http://(不安全来源)不再支持使用getUserMedia(),仅在https://(安全来源)上可以使用

Using getUserMedia() is no longer supported over http:// (Unsecure Origin), It will work only over https:// (Secure Origin)

  • 出于开发目的,localhost被视为基于HTTP的安全来源,因此,如果能够从localhost运行服务器,则应该可以在该服务器上工作.这就是为什么使用locahost在您的案例中可以使用它的原因.
  • 出于生产目的,请考虑使用HTTPS.您可以使用让我们加密" 获得免费的SSL证书.
  • For development purpose, 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 work on that server. That's why it works on your case using locahost.
  • For production purpose, consider using HTTPS. You can get a free SSL certificate using Let's encrypt.

使用Quasar框架,您可以通过编辑quasar.conf.js 文件.此处允许使用参数.

With Quasar framework, you can use Webpack over HTTPS by editing your quasar.conf.js file. Here are allowed parameters.

// quasar.conf.js
devServer: {
    https: true
}

它将使用自签名证书.

如果要使用自己的证书,请按以下说明使用:

If you want to use your own certificate, use as following :

// quasar.conf.js
devServer: {
  https: {
      key: fs.readFileSync('/path/to/server.key'),
      cert: fs.readFileSync('/path/to/server.crt'),
      ca: fs.readFileSync('/path/to/ca.pem'),
  }
}

这篇关于科尔多瓦:getUserMedia()不再适用于不安全的来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆