我无法从客户端脚本连接:
this.Peer = new Peer({host: PEER_SERVER_ADDR,
port: PEER_PORT_ADDR, //at this context: 30028
path: PEER_PATH_ADDR,
debug: true,
config:{'iceServers'[{urls:'stun:stun.l.google.com:19302'} ]}
});
对等信号服务器:
var express = require("express");
var ExpressPeerServer = require("peer").ExpressPeerServer;
var bodyParser = require("body-parser");
var urlencodedParser = bodyParser.urlencoded({extended: false});
var jsonParser = bodyParser.json();
//var BodyParser = require("body-parser");
var const_and_funcs = require("./vk_space_chat_constants_and_general_functions.js");
var app = express();
var heroku_port = process.env.PORT || const_and_funcs.PEER_PORT_ADDR; //:30028
var server = app.listen(heroku_port);
console.log(heroku_port);
console.log(const_and_funcs.PEER_PATH_ADDR + " ");
var options = {
debug: true
};
var peerServer = ExpressPeerServer(server, options);
app.use(const_and_funcs.PEER_PATH_ADDR, peerServer);
app.use(jsonParser);
app.use(urlencodedParser);
但是当我尝试连接到服务器时,我遇到了这个问题:
h t t p s :// My_App.herokuapp.com:30028/vk_space_chat/peerjs/id?ts=14850577089420.5386418990500108
Failed to load resource: net::ERR_CONNECTION_REFUSED
peer.min.js:1 PeerJS: ERROR Error retrieving ID undefined
peer.min.js:1 PeerJS: ERROR Aborting!
peer.min.js:1 PeerJS: ERROR Error: Could not get an ID from the server.
peer.min.js:1 PeerJS: ERROR Error retrieving ID ProgressEvent
peer.min.js:1 PeerJS: ERROR Aborting!
peer.min.js:1 PeerJS: ERROR Error: Could not get an ID from the server.
但是相同的代码在我的本地 Node.js 服务器上工作!!!没有什么问题!谁能帮助我?..也许WebSockets有问题?..或者使用普通VPS可能会更好?