peerjs/webrtc iceConnectionState failed

梦想与她 提交于 2019-12-01 06:25:25

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