【问题标题】:How to troubleshoot problem with setting WebRTC server on vps?如何解决在 vps 上设置 WebRTC 服务器的问题?
【发布时间】:2018-12-05 14:57:38
【问题描述】:

我使用peerjs-server 为webRTC 编写了一个简单的节点快速服务器,并使用peerjs 编写了一个简单的客户端。在本地主机上一切正常,但是当我在 vps 上尝试时,出现错误:

Firefox can't connect with server ws://my.vps/peerjs/peerjs?key=peerjs&id=hj3hpekwaa38fr00&token=ymtfvhagiw
PeerJS:  Socket closed.
PeerJS:  ERROR Error: Lost connection to server.
Error: "Lost connection to server."
emitError                   https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.16/peer.min.js:1:16426
_initializeServerConnection https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.16/peer.min.js:1:12260
emit                        https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.16/peer.min.js:1:25516
onclose                     https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.16/peer.min.js:1:19350

服务器:

const express = require('express');
enter code here`const app = express();
const ExpressPeerServer = require('peer').ExpressPeerServer;

app.use(express.static('./public'));

const server = app.listen(80, () => { // 3000 on localhost
    console.log('Express server listen on port ' + 80);
});

const options = { debug: true };
const peerserver = ExpressPeerServer(server, options);

app.use('/peerjs', peerserver);
app.use('/*', express.static('./public/index.html'));

客户:

var peer = new Peer('', {
    host: location.hostname,
    port: location.port || (location.protocol === 'https:' ? 443 : 80),
    path: '/peerjs',
    debug: 3
});

peer.on('open', function (id) {
    console.log(id);
});

任何帮助表示感谢。

【问题讨论】:

  • 你终于能解决问题了吗?

标签: node.js webrtc peer peerjs


【解决方案1】:

您似乎正在连接服务器ws://my.vps/,这是一个连接到http://my.vps/ 的服务器的网络套接字,但似乎并不存在。

它可能也应该使用 https(或 wss)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-16
    • 2015-03-31
    • 1970-01-01
    • 2013-12-12
    • 1970-01-01
    • 2014-07-01
    • 2011-02-10
    • 2022-06-16
    相关资源
    最近更新 更多