Commit 545380d3 authored by Moritz Langenstein's avatar Moritz Langenstein
Browse files

(ml5717) Receive temporary turnservers from signalling server

parent fda5000a
......@@ -116,13 +116,15 @@ var LioWebRTC = function (_WildEmitter) {
return;
}
if (!peer) {
console.log('Received offer from', message.from);
peer = self.webrtc.createPeer({
id: message.from,
sid: message.sid,
type: message.roomType,
enableDataChannels: self.config.enableDataChannels,
sharemyscreen: message.roomType === 'screen' && !message.broadcaster,
broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null
broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null,
iceServers: self.webrtc.config.peerConnectionConfig.iceServers.concat(message.turnservers)
});
if (_this.config.dataOnly && _this.config.constraints.maxPeers > 0) {
_this.sendPing(peer, peer.id, true);
......@@ -130,10 +132,10 @@ var LioWebRTC = function (_WildEmitter) {
peer.start();
_this.emit('createdPeer', peer);
}
peer.handleMessage(message);
} else {
return;
}
peer.handleMessage(message);
} else if (peers.length) {
peers.forEach(function (p) {
p.handleMessage(message);
......@@ -188,19 +190,17 @@ var LioWebRTC = function (_WildEmitter) {
self.webrtc.config.peerConnectionConfig.iceServers = args;
self.emit('stunservers', args);
});
connection.on('turnservers', function (args) {
/*connection.on('turnservers', (args) => {
// appends to the config
self.webrtc.config.peerConnectionConfig.iceServers = self.webrtc.config.peerConnectionConfig.iceServers.concat(args);
self.emit('turnservers', args);
});
/*
this.webrtc.on('iceFailed', (peer) => {
});*/
/*this.webrtc.on('iceFailed', (peer) => {
// local ice failure
});
this.webrtc.on('connectivityError', (peer) => {
// remote ice failure
});
*/
});*/
// sending mute/unmute to all peers
_this.webrtc.on('audioOn', function () {
......@@ -506,10 +506,11 @@ var LioWebRTC = function (_WildEmitter) {
client = roomDescription.clients[id];
for (type in client) {
if (client[type]) {
if (type !== 'turnservers' && client[type]) {
console.log('Received peer info about', id, 'on room join');
var peerCount = _this5.webrtc.getPeers().length;
if (_this5.config.dataOnly && _this5.config.constraints.maxPeers > 0 && (peerCount >= _this5.config.constraints.minPeers || peerCount >= _this5.config.constraints.maxPeers)) {
break;
return;
}
peer = self.webrtc.createPeer({
id: id,
......@@ -518,7 +519,8 @@ var LioWebRTC = function (_WildEmitter) {
receiveMedia: {
offerToReceiveAudio: type !== 'screen' && !_this5.config.dataOnly && _this5.config.receiveMedia.offerToReceiveAudio ? 1 : 0,
offerToReceiveVideo: !_this5.config.dataOnly && self.config.receiveMedia.offerToReceiveVideo ? 1 : 0
}
},
iceServers: self.webrtc.config.peerConnectionConfig.iceServers.concat(client.turnservers)
});
if (_this5.config.dataOnly && _this5.config.constraints.maxPeers > 0) {
_this5.sendPing(peer, peer.id, true);
......@@ -608,10 +610,11 @@ var LioWebRTC = function (_WildEmitter) {
var type = void 0;
var peer = void 0;
for (type in client) {
if (client[type]) {
if (type !== 'turnservers' && client[type]) {
console.log('Connecting to random peer', peerId);
var peerCount = this.webrtc.getPeers().length;
if (this.config.constraints.maxPeers > 0 && peerCount >= this.config.constraints.maxPeers) {
break;
return;
}
peer = this.webrtc.createPeer({
id: peerId,
......@@ -620,7 +623,8 @@ var LioWebRTC = function (_WildEmitter) {
receiveMedia: {
offerToReceiveAudio: type !== 'screen' && !this.config.dataOnly && this.config.receiveMedia.offerToReceiveAudio ? 1 : 0,
offerToReceiveVideo: !this.config.dataOnly && this.config.receiveMedia.offerToReceiveVideo ? 1 : 0
}
},
iceServers: self.webrtc.config.peerConnectionConfig.iceServers.concat(client.turnservers)
});
if (this.config.dataOnly && this.config.constraints.maxPeers > 0) {
this.sendPing(peer, peerId, true);
......
......@@ -59,7 +59,7 @@ var Peer = function (_WildEmitter) {
_this.channels = {};
_this.sid = options.sid || Date.now().toString();
// Create an RTCPeerConnection via the polyfill
_this.pc = new _rtcpeerconnection2.default(_this.parent.config.peerConnectionConfig, _this.parent.config.peerConnectionConstraints);
_this.pc = new _rtcpeerconnection2.default(Object.assign({}, _this.parent.config.peerConnectionConfig, { iceServers: options.iceServers || _this.parent.config.peerConnectionConfig.iceServers }), _this.parent.config.peerConnectionConstraints);
_this.pc.on('ice', _this.onIceCandidate.bind(_this));
_this.pc.on('endOfCandidates', function (event) {
self.send('endOfCandidates', event);
......
......@@ -47,7 +47,7 @@ var WebRTC = function (_LocalMedia) {
var config = _this.config = {
debug: false,
peerConnectionConfig: {
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
iceServers: []
},
peerConnectionConstraints: {
optional: []
......
......@@ -74,6 +74,7 @@ class LioWebRTC extends WildEmitter {
return;
}
if (!peer) {
console.log('Received offer from', message.from)
peer = self.webrtc.createPeer({
id: message.from,
sid: message.sid,
......@@ -81,6 +82,7 @@ class LioWebRTC extends WildEmitter {
enableDataChannels: self.config.enableDataChannels,
sharemyscreen: message.roomType === 'screen' && !message.broadcaster,
broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null,
iceServers: self.webrtc.config.peerConnectionConfig.iceServers.concat(message.turnservers),
});
if (this.config.dataOnly && this.config.constraints.maxPeers > 0) {
this.sendPing(peer, peer.id, true);
......@@ -88,10 +90,10 @@ class LioWebRTC extends WildEmitter {
peer.start();
this.emit('createdPeer', peer);
}
peer.handleMessage(message);
} else {
return;
}
peer.handleMessage(message);
} else if (peers.length) {
peers.forEach((p) => {
p.handleMessage(message);
......@@ -145,19 +147,17 @@ class LioWebRTC extends WildEmitter {
self.webrtc.config.peerConnectionConfig.iceServers = args;
self.emit('stunservers', args);
});
connection.on('turnservers', (args) => {
/*connection.on('turnservers', (args) => {
// appends to the config
self.webrtc.config.peerConnectionConfig.iceServers = self.webrtc.config.peerConnectionConfig.iceServers.concat(args);
self.emit('turnservers', args);
});
/*
this.webrtc.on('iceFailed', (peer) => {
});*/
/*this.webrtc.on('iceFailed', (peer) => {
// local ice failure
});
this.webrtc.on('connectivityError', (peer) => {
// remote ice failure
});
*/
});*/
// sending mute/unmute to all peers
this.webrtc.on('audioOn', () => {
......@@ -411,10 +411,11 @@ class LioWebRTC extends WildEmitter {
for (id of Object.keys(roomDescription.clients).reverse().filter(item => item !== this.id)) {
client = roomDescription.clients[id];
for (type in client) {
if (client[type]) {
if (type !== 'turnservers' && client[type]) {
console.log('Received peer info about', id, 'on room join')
const peerCount = this.webrtc.getPeers().length;
if (this.config.dataOnly && this.config.constraints.maxPeers > 0 && (peerCount >= this.config.constraints.minPeers || peerCount >= this.config.constraints.maxPeers)) {
break;
return;
}
peer = self.webrtc.createPeer({
id,
......@@ -424,6 +425,7 @@ class LioWebRTC extends WildEmitter {
offerToReceiveAudio: type !== 'screen' && !this.config.dataOnly && this.config.receiveMedia.offerToReceiveAudio ? 1 : 0,
offerToReceiveVideo: !this.config.dataOnly && self.config.receiveMedia.offerToReceiveVideo ? 1 : 0,
},
iceServers: self.webrtc.config.peerConnectionConfig.iceServers.concat(client.turnservers),
});
if (this.config.dataOnly && this.config.constraints.maxPeers > 0) {
this.sendPing(peer, peer.id, true);
......@@ -489,10 +491,11 @@ class LioWebRTC extends WildEmitter {
let type;
let peer;
for (type in client) {
if (client[type]) {
if (type !== 'turnservers' && client[type]) {
console.log('Connecting to random peer', peerId)
const peerCount = this.webrtc.getPeers().length;
if (this.config.constraints.maxPeers > 0 && peerCount >= this.config.constraints.maxPeers) {
break;
return;
}
peer = this.webrtc.createPeer({
id: peerId,
......@@ -502,6 +505,7 @@ class LioWebRTC extends WildEmitter {
offerToReceiveAudio: type !== 'screen' && !this.config.dataOnly && this.config.receiveMedia.offerToReceiveAudio ? 1 : 0,
offerToReceiveVideo: !this.config.dataOnly && this.config.receiveMedia.offerToReceiveVideo ? 1 : 0,
},
iceServers: self.webrtc.config.peerConnectionConfig.iceServers.concat(client.turnservers),
});
if (this.config.dataOnly && this.config.constraints.maxPeers > 0) {
this.sendPing(peer, peerId, true);
......
......@@ -27,7 +27,9 @@ class Peer extends WildEmitter {
this.channels = {};
this.sid = options.sid || Date.now().toString();
// Create an RTCPeerConnection via the polyfill
this.pc = new PeerConnection(this.parent.config.peerConnectionConfig, this.parent.config.peerConnectionConstraints);
this.pc = new PeerConnection(Object.assign({}, this.parent.config.peerConnectionConfig,
{ iceServers: options.iceServers || this.parent.config.peerConnectionConfig.iceServers }),
this.parent.config.peerConnectionConstraints);
this.pc.on('ice', this.onIceCandidate.bind(this));
this.pc.on('endOfCandidates', (event) => {
self.send('endOfCandidates', event);
......
......@@ -12,7 +12,7 @@ class WebRTC extends LocalMedia {
const config = this.config = {
debug: false,
peerConnectionConfig: {
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }],
iceServers: [],
},
peerConnectionConstraints: {
optional: [],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment