如何解决在VPS上设置WebRTC服务器的问题?

时间:2018-12-05 14:57:39

标签: node.js webrtc peer peerjs

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

Map<String, List<Student>> collect = students.stream() // stream capabilities
        .sorted(Comparator.comparingInt(Student::getAge).reversed()) // sort by age, descending
        .collect(Collectors.groupingBy(Student::getName)); // group by name.

服务器:

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'));

任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

您似乎正在与服务器ws://my.vps/连接,该服务器是到http://my.vps/上似乎不存在的服务器的Web套接字。

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