3

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
Omar Wagih
  • 8,504
  • 7
  • 59
  • 75

2 Answers2

2

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'));
});
Harsh Gupta
  • 444
  • 3
  • 9
0

I had this issue because of the mobile hotspot. I was trying to connect with the device that had hotspot enabled once i switched to another wifi and connected both my server and devices with same wifi(none of these devices should have hotspot enabled) it started working.