WebRTC over HTTPs 问题 [英] WebRTC over HTTPs Issue

查看:50
本文介绍了WebRTC over HTTPs 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的 WebRTC 应用程序,它可以很好地测试本地主机;但是,除非您有安全连接,否则 WEBRTC 没有多大用处,因为浏览器现在不会运行 GetUserMedia 除非您有 HTTP,所以我正在尝试"将其升级为 SSL-TLS.下面是我的两个应用程序并排的屏幕截图,一个安全(不工作)另一个不安全(工作)

I have created a simple WebRTC application that works fine in testing overlocal host; However, WEBRTC isn't much use unless you have a secure connection, as browsers now will not run GetUserMedia unless you have HTTPs, so I am 'trying' to upgrade it for SSL-TLS. Below is a screen shot of my two applications side by side, one secure (not working) the other non secure (works)

正如您在上面看到的,本地主机连接"而 HTTPs无法建立连接".我是 SSL 的新手,所以这可能很简单.只是希望多一些关注这一点.

As you can see above, localhost 'connects' while HTTPs 'can't establish connection'. I am new to SSL, so this may be a simple one. Just would appreciate some more eyes on this.

我知道用于 Javascript 的 HTTPS 服务器正在安全连接,请参见下图

I do know my HTTPS server for the the Javascript is connecting securely, see image below

以下是我的代码片段.任何帮助将不胜感激:

Below are my code snippets. Any help would be greatly appreciated:

SSL 客户端 - Client.JS

var connection = new WebSocket('wss://localhost:8443'),

name = "";

非安全客户端 - Client.JS

var connection = new WebSocket('ws://localhost:8888'),

    name = "";

非安全 JS 服务器 - index.JS

var WebSocketServer = require('ws').Server,

wss = new WebSocketServer({ port: 8888 }),

users = {};
wss.on('connection', function (connection) {
connection.on('message', function (message) .....

安全的 JS 服务器 - SSLindex.JS

 Var https = require('https'),

fs = require('fs'),

 express = require('express'),

  app = express();


var wss = https.createServer({
key: fs.readFileSync('server.key'),

cert: fs.readFileSync('server.crt'),

ca: fs.readFileSync('ca.crt'),

requestCert: true,

rejectUnauthorized: false
 }, app).listen('8443', function() {
console.log("Secure Express server listening on port 8443");
});

 app.use("/", function(req, res, next) 
{
 res.send("index.js is working!");

  });

推荐答案

为了方便开发者,chrome 会将 localhost 视为安全源.
如果您使用的是 http://localhost 或 ws://localhost,则不涉及 SSL,因此它在右侧工作得很好屏幕截图.
但是对于 httpswss,浏览器会验证 SSL 证书颁发机构.

For developers convenience chrome will treat localhost as a secure origin.
If you are using http://localhost or ws://localhost there is no SSL involved, so its working just fine in right side screenshot.
But for https or wss, browser will verify the SSL certificate authority.

使用 wss://localhost:8443/解决 websocket 连接问题

To resolve websocket connection issue with wss://localhost:8443/

临时解决方法:打开 https://localhost:8443/ url 并通过单击 Adavced = 允许浏览器异常> 继续
实际解决方案:为您的节点服务器(node.kali2016.com)分配一个域名,并使用授权的 SSL 证书配置节点.然后替换
var connection = new WebSocket('wss://localhost:8443')

var connection = new WebSocket('wss://yourdomainname:8443')

Temporary work around: Open https://localhost:8443/ url and allow the browser exception by clicking Adavced => proceed
Actual Solution: Assign a domain name to your node server (node.kali2016.com) and configure node with Authorised SSL certificates. Then replace
var connection = new WebSocket('wss://localhost:8443')
with
var connection = new WebSocket('wss://yourdomainname:8443')

这篇关于WebRTC over HTTPs 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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