Permalink
Browse files

feat(xmpp): make P2P Stun servers configurable

STUN servers used in the P2P connection can be configured through
"p2pStunServers" option.
  • Loading branch information...
paweldomas committed Feb 23, 2017
1 parent c53a6d6 commit 3c395037e48915d4bbb95f2092ba2c1c4c4df032
Showing with 29 additions and 15 deletions.
  1. +21 −14 modules/xmpp/strophe.jingle.js
  2. +8 −1 modules/xmpp/xmpp.js
@@ -11,19 +11,25 @@ import Statistics from "../statistics/statistics";
import ConnectionPlugin from "./ConnectionPlugin";
class JingleConnectionPlugin extends ConnectionPlugin {
constructor(xmpp, eventEmitter) {
/**
* Creates new <tt>JingleConnectionPlugin</tt>
* @param {XMPP} xmpp
* @param {EventEmitter} eventEmitter
* @param {Array<Object>} p2pStunServers an array which is part of the ice
* config passed to the <tt>PeerConnection</tt> with the structure defined
* by the WebRTC standard.
*/
constructor(xmpp, eventEmitter, p2pStunServers) {
super();
this.xmpp = xmpp;
this.eventEmitter = eventEmitter;
this.sessions = {};
// FIXME make configurable and use STUN only in P2P
this.ice_config = {
iceServers: [
{ urls: "stun:stun.l.google.com:19302" },
{ urls: "stun:stun1.l.google.com:19302" },
{ urls: "stun:stun2.l.google.com:19302" }
]
};
this.jvb_ice_config = { iceServers: [ ] };
this.p2p_ice_config = { iceServers: [ ] };
if (Array.isArray(p2pStunServers)) {
logger.info("Configured STUN servers: ", p2pStunServers);
this.p2p_ice_config.iceServers = p2pStunServers;
}
this.media_constraints = {
mandatory: {
'OfferToReceiveAudio': true,
@@ -106,7 +112,8 @@ class JingleConnectionPlugin extends ConnectionPlugin {
fromJid,
this.connection,
this.media_constraints,
this.ice_config,
// Only P2P makes use of the ICE config
isP2P ? this.p2p_ice_config : this.jvb_ice_config,
isP2P /* P2P */, false /* initiator */,
this.xmpp.options);
@@ -196,7 +203,7 @@ class JingleConnectionPlugin extends ConnectionPlugin {
peer,
this.connection,
this.media_constraints,
this.ice_config,
this.p2p_ice_config,
true /* P2P */, true /* initiator */,
this.xmpp.options);
@@ -278,7 +285,7 @@ class JingleConnectionPlugin extends ConnectionPlugin {
}
}
});
this.ice_config.iceServers = iceservers;
this.jvb_ice_config.iceServers = iceservers;
}, err => {
logger.warn('getting turn credentials failed', err);
logger.warn('is mod_turncredentials or similar installed?');
@@ -309,7 +316,7 @@ class JingleConnectionPlugin extends ConnectionPlugin {
module.exports = function(XMPP, eventEmitter) {
module.exports = function(XMPP, eventEmitter, p2pStunServers) {
Strophe.addConnectionPlugin('jingle',
new JingleConnectionPlugin(XMPP, eventEmitter));
new JingleConnectionPlugin(XMPP, eventEmitter, p2pStunServers));
};
View
@@ -25,6 +25,13 @@ function createConnection(token, bosh = '/http-bind') {
}
export default class XMPP extends Listenable {
/**
* FIXME describe all options
* @param {Object} options
* @param {Array<Object>} options.p2pStunServers see
* {@link JingleConnectionPlugin} for more details.
* @param token
*/
constructor(options, token) {
super();
this.connection = null;
@@ -370,7 +377,7 @@ export default class XMPP extends Listenable {
_initStrophePlugins() {
initEmuc(this);
initJingle(this, this.eventEmitter);
initJingle(this, this.eventEmitter, this.options.p2pStunServers);
initStropheUtil();
initPing(this);
initRayo();

0 comments on commit 3c39503

Please sign in to comment.