peerjs / webrtc iceConnectionState失败

时间:2015-12-21 23:00:35

标签: javascript websocket webrtc p2p peerjs

我一直试图解决这个问题。我试图使用peerjs建立一个简单的连接。我可以成功连接到身份USER_ID的对等方。但是,他们无法连接到我。我们在尝试连接时收到以下日志。

iceConnectionState最终更改为failed,无法接收任何数据。

  • 该应用程序正在使用peerjs云服务器
  • 我使用的是最新版本的Chrome。他们尝试使用最新版本的Chrome和Firefox
  • 他们关闭了所有防火墙
  • 甚至尝试了peerjs chat example,但失败并出现同样的错误。

知道为什么会发生这种情况/正在进行吗?

任何帮助表示赞赏!

peer.min.js:1 PeerJS:  Socket open
peer.min.js:1 PeerJS:  Creating RTCPeerConnection.
peer.min.js:1 PeerJS:  Listening for ICE candidates.
peer.min.js:1 PeerJS:  Listening for `negotiationneeded`
peer.min.js:1 PeerJS:  Listening for data channel
peer.min.js:1 PeerJS:  Listening for remote stream
peer.min.js:1 PeerJS:  Setting remote description RTCSessionDescription
peer.min.js:1 PeerJS:  Added ICE candidate for: USER_ID
peer.min.js:1 PeerJS:  Set remoteDescription: OFFER for: USER_ID
peer.min.js:1 PeerJS:  Created answer.
peer.min.js:1 PeerJS:  Set localDescription: answer for: USER_ID
peer.min.js:1 PeerJS:  Received ICE candidates for: USER_ID
peer.min.js:1 PeerJS:  Added ICE candidate for: USER_ID
peer.min.js:1 PeerJS:  Received ICE candidates for: USER_ID
peer.min.js:1 PeerJS:  Added ICE candidate for: USER_ID
peer.min.js:1 PeerJS:  Received ICE candidates for: USER_ID
peer.min.js:1 PeerJS:  iceConnectionState is disconnected, closing connections to USER_ID

1 个答案:

答案 0 :(得分:1)

我遇到了完全相同的问题。添加STUN TURN服务器应该可以解决该问题。

客户端代码

peer = new Peer(this.api.currentUserValue().id+'-'+this.api.currentUserValue().first_name,{
                                                    host: 'localhost',
                                                    port: 8080,
                                                    path: '/api',
                                                    debug: 3,
                                                    config: { 'iceServers': [
                                                      { 'url': 'stun:stun.l.google.com:19302' },
                                                      { 'url': 'turn:numb.viagenie.ca',credential: 'xxxx', username:'xxxx@gmail.com'  } ] } // this is must for keeping the connection open
                                                      });

服务器端代码

var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var expressPeerServer = require('peer').ExpressPeerServer;
var path = require('path');



app.set('port', (process.env.OPENSHIFT_NODEJS_PORT || "8080"));
app.set('host', (process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1"));

app.use(express.static(path.join(__dirname, '/client')));
app.use('/api', expressPeerServer(server, {debug:true}));




server.listen(app.get('port'),app.get('host'),function(){
  console.log('Server running at %s:%s',app.get('host'),app.get('port'));
});