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