peerjs/webrtc iceConnectionState failed

旧时模样 提交于 2019-12-01 04:35:27

问题


I've been trying to figure this out for a while. I'm trying to establish a simple connection using peerjs. I can connect successfully to the peer with id USER_ID. However, they are unable unable to connect to me. I receive the following log when they try to connect.

iceConnectionState is changed to failed eventually and no data can be recieved.

  • The application is using the peerjs cloud server
  • I'm using the latest version of Chrome. They have tried using latest versions of Chrome and Firefox
  • They have switched off any firewalls
  • Have even tried the peerjs chat example and it fails with the same error.

Any idea why this might happen / going on here?

Any help appreciated!

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:


I had the exact same issue. Adding the STUN TURN servers should resolve the issue.

Client Side Code

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

Server Side code

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


来源:https://stackoverflow.com/questions/34405816/peerjs-webrtc-iceconnectionstate-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!