我正在尝试运行Angular 4项目。这是一个视频聊天应用程序。当我尝试使用localhost
运行时,它不起作用,当我使用时
ng s --host 192.16.10.xxx:4200
它导致使用网络摄像头出现问题并显示此错误:
[Deprecation] getUserMedia()不再适用于不安全的起源。要使用此功能,您应该考虑将应用程序切换到安全的来源,例如HTTPS。有关详细信息,请参阅goo.gl/rStTGz。
我不知道该怎么做。
谁能帮我这个?
编辑 -
我已生成ssl文件localhost.key
和localhost.csr
和文件夹结构
当我试图跑
ng serve --ssl --ssl-key localhost.key --ssl-cert localhost.csr --host 0.0.0.0
它给出了一个错误
error:0906D06C:PEM routines:PEM_read_bio:no start line
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
您需要使用(自签名)ssl证书为您的项目提供服务。您可以在命令行上执行此操作或在配置文件中指定。您可以找到生成证书的过程,然后是CLI。主机部分是可选的
# angular generates a self-signed certificate for localhost automatically
ng serve --ssl
-or-
# tries to use to the provided certificate, it it cannot find generate one
ng serve --ssl --ssl-key <ssl_key_file> --ssl-cert <ssl_cert_file>
不要忘记将证书作为受信任的根证书导入到您的PC /浏览器中。您可以查看如何为每个浏览器执行此操作。
因此,尝试使用证书在本地运行Angular应用程序。您可以使用open ssl生成证书
openssl req -new -x509 -newkey rsa:2048 -sha256 -nodes -keyout localhost.key -days 3560 -out localhost.crt -config certificate.cnf
然后跑
"start": "ng serve --ssl --ssl-key d:\\certificates\\localhost.key --ssl-cert d:\\certificates\localhost.crt"
我在https://medium.com/@richardr39/using-angular-cli-to-serve-over-https-locally-70dab07417c8网站上找到了这个信息