2014-03-06 14:28:36 +00:00
|
|
|
/* colibri.js -- a COLIBRI focus
|
2013-12-16 11:22:23 +00:00
|
|
|
* The colibri spec has been submitted to the XMPP Standards Foundation
|
|
|
|
* for publications as a XMPP extensions:
|
|
|
|
* http://xmpp.org/extensions/inbox/colibri.html
|
|
|
|
*
|
|
|
|
* colibri.js is a participating focus, i.e. the focus participates
|
|
|
|
* in the conference. The conference itself can be ad-hoc, through a
|
|
|
|
* MUC, through PubSub, etc.
|
|
|
|
*
|
2014-03-06 14:28:36 +00:00
|
|
|
* colibri.js relies heavily on the strophe.jingle library available
|
2013-12-16 11:22:23 +00:00
|
|
|
* from https://github.com/ESTOS/strophe.jingle
|
|
|
|
* and interoperates with the Jitsi videobridge available from
|
|
|
|
* https://jitsi.org/Projects/JitsiVideobridge
|
|
|
|
*/
|
|
|
|
/*
|
2014-03-06 14:28:36 +00:00
|
|
|
Copyright (c) 2013 ESTOS GmbH
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
*/
|
2013-12-16 11:22:23 +00:00
|
|
|
/* jshint -W117 */
|
2014-03-12 18:59:16 +00:00
|
|
|
|
|
|
|
ColibriFocus.prototype = Object.create(SessionBase.prototype);
|
2013-12-16 11:22:23 +00:00
|
|
|
function ColibriFocus(connection, bridgejid) {
|
2014-03-12 18:59:16 +00:00
|
|
|
|
2014-03-13 12:22:54 +00:00
|
|
|
SessionBase.call(this, connection, Math.random().toString(36).substr(2, 12));
|
2014-03-12 18:59:16 +00:00
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
this.bridgejid = bridgejid;
|
|
|
|
this.peers = [];
|
|
|
|
this.confid = null;
|
|
|
|
|
2014-05-13 14:51:08 +00:00
|
|
|
/**
|
|
|
|
* Local XMPP resource used to join the multi user chat.
|
|
|
|
* @type {*}
|
|
|
|
*/
|
|
|
|
this.myMucResource = Strophe.getResourceFromJid(connection.emuc.myroomjid);
|
|
|
|
|
2014-05-08 09:26:15 +00:00
|
|
|
/**
|
|
|
|
* Default channel expire value in seconds.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2014-07-15 22:36:51 +00:00
|
|
|
this.channelExpire
|
|
|
|
= ('number' === typeof(config.channelExpire))
|
|
|
|
? config.channelExpire
|
|
|
|
: 15;
|
2014-07-17 20:20:36 +00:00
|
|
|
/**
|
|
|
|
* Default channel last-n value.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
this.channelLastN
|
|
|
|
= ('number' === typeof(config.channelLastN)) ? config.channelLastN : -1;
|
2014-05-08 09:26:15 +00:00
|
|
|
|
2014-02-10 20:59:39 +00:00
|
|
|
// media types of the conference
|
2014-05-08 09:26:15 +00:00
|
|
|
if (config.openSctp)
|
|
|
|
this.media = ['audio', 'video', 'data'];
|
|
|
|
else
|
|
|
|
this.media = ['audio', 'video'];
|
2014-02-10 20:59:39 +00:00
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
this.connection.jingle.sessions[this.sid] = this;
|
|
|
|
this.mychannel = [];
|
|
|
|
this.channels = [];
|
|
|
|
this.remotessrc = {};
|
|
|
|
|
2014-02-03 18:40:10 +00:00
|
|
|
// container for candidates from the focus
|
|
|
|
// gathered before confid is known
|
|
|
|
this.drip_container = [];
|
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
// silly wait flag
|
|
|
|
this.wait = true;
|
2014-07-01 14:02:34 +00:00
|
|
|
|
|
|
|
this.recordingEnabled = false;
|
2014-07-23 07:12:36 +00:00
|
|
|
|
|
|
|
// stores information about the endpoints (i.e. display names) to
|
|
|
|
// be sent to the videobridge.
|
|
|
|
this.endpointsInfo = null;
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// creates a conferences with an initial set of peers
|
|
|
|
ColibriFocus.prototype.makeConference = function (peers) {
|
2014-01-03 16:41:50 +00:00
|
|
|
var self = this;
|
2013-12-16 11:22:23 +00:00
|
|
|
if (this.confid !== null) {
|
|
|
|
console.error('makeConference called twice? Ignoring...');
|
|
|
|
// FIXME: just invite peers?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.confid = 0; // !null
|
|
|
|
this.peers = [];
|
|
|
|
peers.forEach(function (peer) {
|
2014-01-03 16:41:50 +00:00
|
|
|
self.peers.push(peer);
|
|
|
|
self.channels.push([]);
|
2013-12-16 11:22:23 +00:00
|
|
|
});
|
|
|
|
|
2014-03-24 15:55:33 +00:00
|
|
|
this.peerconnection
|
|
|
|
= new TraceablePeerConnection(
|
|
|
|
this.connection.jingle.ice_config,
|
|
|
|
this.connection.jingle.pc_constraints );
|
|
|
|
|
|
|
|
if(this.connection.jingle.localAudio) {
|
|
|
|
this.peerconnection.addStream(this.connection.jingle.localAudio);
|
2014-03-12 15:08:24 +00:00
|
|
|
}
|
2014-03-24 15:55:33 +00:00
|
|
|
if(this.connection.jingle.localVideo) {
|
|
|
|
this.peerconnection.addStream(this.connection.jingle.localVideo);
|
2014-03-12 15:08:24 +00:00
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
this.peerconnection.oniceconnectionstatechange = function (event) {
|
2014-01-03 16:41:50 +00:00
|
|
|
console.warn('ice connection state changed to', self.peerconnection.iceConnectionState);
|
2013-12-16 11:22:23 +00:00
|
|
|
/*
|
2014-03-12 15:08:24 +00:00
|
|
|
if (self.peerconnection.signalingState == 'stable' && self.peerconnection.iceConnectionState == 'connected') {
|
|
|
|
console.log('adding new remote SSRCs from iceconnectionstatechange');
|
|
|
|
window.setTimeout(function() { self.modifySources(); }, 1000);
|
|
|
|
}
|
|
|
|
*/
|
2013-12-16 11:22:23 +00:00
|
|
|
};
|
|
|
|
this.peerconnection.onsignalingstatechange = function (event) {
|
2014-01-03 16:41:50 +00:00
|
|
|
console.warn(self.peerconnection.signalingState);
|
2013-12-16 11:22:23 +00:00
|
|
|
/*
|
2014-03-12 15:08:24 +00:00
|
|
|
if (self.peerconnection.signalingState == 'stable' && self.peerconnection.iceConnectionState == 'connected') {
|
|
|
|
console.log('adding new remote SSRCs from signalingstatechange');
|
|
|
|
window.setTimeout(function() { self.modifySources(); }, 1000);
|
|
|
|
}
|
|
|
|
*/
|
2013-12-16 11:22:23 +00:00
|
|
|
};
|
|
|
|
this.peerconnection.onaddstream = function (event) {
|
2013-12-29 20:14:19 +00:00
|
|
|
// search the jid associated with this stream
|
2014-01-03 16:41:50 +00:00
|
|
|
Object.keys(self.remotessrc).forEach(function (jid) {
|
|
|
|
if (self.remotessrc[jid].join('\r\n').indexOf('mslabel:' + event.stream.id) != -1) {
|
2013-12-29 20:14:19 +00:00
|
|
|
event.peerjid = jid;
|
|
|
|
}
|
|
|
|
});
|
2014-01-03 16:41:50 +00:00
|
|
|
$(document).trigger('remotestreamadded.jingle', [event, self.sid]);
|
2013-12-16 11:22:23 +00:00
|
|
|
};
|
2014-02-04 17:24:28 +00:00
|
|
|
this.peerconnection.onicecandidate = function (event) {
|
|
|
|
//console.log('focus onicecandidate', self.confid, new Date().getTime(), event.candidate);
|
|
|
|
if (!event.candidate) {
|
|
|
|
console.log('end of candidates');
|
|
|
|
return;
|
|
|
|
}
|
2014-02-24 20:13:04 +00:00
|
|
|
self.sendIceCandidate(event.candidate);
|
2014-02-04 17:24:28 +00:00
|
|
|
};
|
|
|
|
this._makeConference();
|
|
|
|
/*
|
2013-12-16 11:22:23 +00:00
|
|
|
this.peerconnection.createOffer(
|
|
|
|
function (offer) {
|
2014-01-03 16:41:50 +00:00
|
|
|
self.peerconnection.setLocalDescription(
|
2013-12-16 11:22:23 +00:00
|
|
|
offer,
|
|
|
|
function () {
|
|
|
|
// success
|
2014-01-03 16:41:50 +00:00
|
|
|
$(document).trigger('setLocalDescription.jingle', [self.sid]);
|
2013-12-16 11:22:23 +00:00
|
|
|
// FIXME: could call _makeConference here and trickle candidates later
|
2014-02-03 18:40:10 +00:00
|
|
|
self._makeConference();
|
2013-12-16 11:22:23 +00:00
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.log('setLocalDescription failed', error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.warn(error);
|
|
|
|
}
|
|
|
|
);
|
2014-02-04 17:24:28 +00:00
|
|
|
*/
|
2013-12-16 11:22:23 +00:00
|
|
|
};
|
|
|
|
|
2014-07-01 14:02:34 +00:00
|
|
|
// Sends a COLIBRI message which enables or disables (according to 'state') the
|
2014-07-18 15:36:03 +00:00
|
|
|
// recording on the bridge. Waits for the result IQ and calls 'callback' with
|
|
|
|
// the new recording state, according to the IQ.
|
2014-07-01 14:02:34 +00:00
|
|
|
ColibriFocus.prototype.setRecording = function(state, token, callback) {
|
|
|
|
var self = this;
|
2014-07-23 07:12:36 +00:00
|
|
|
var elem = $iq({to: this.bridgejid, type: 'set'});
|
2014-07-01 14:02:34 +00:00
|
|
|
elem.c('conference', {
|
|
|
|
xmlns: 'http://jitsi.org/protocol/colibri',
|
|
|
|
id: this.confid
|
|
|
|
});
|
|
|
|
elem.c('recording', {state: state, token: token});
|
|
|
|
elem.up();
|
|
|
|
|
|
|
|
this.connection.sendIQ(elem,
|
|
|
|
function (result) {
|
|
|
|
console.log('Set recording "', state, '". Result:', result);
|
|
|
|
var recordingElem = $(result).find('>conference>recording');
|
2014-07-18 15:36:03 +00:00
|
|
|
var newState = ('true' === recordingElem.attr('state'));
|
2014-07-01 14:02:34 +00:00
|
|
|
|
|
|
|
self.recordingEnabled = newState;
|
|
|
|
callback(newState);
|
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.warn(error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2014-07-23 07:12:36 +00:00
|
|
|
/*
|
|
|
|
* Updates the display name for an endpoint with a specific jid.
|
|
|
|
* jid: the jid associated with the endpoint.
|
|
|
|
* displayName: the new display name for the endpoint.
|
|
|
|
*/
|
|
|
|
ColibriFocus.prototype.setEndpointDisplayName = function(jid, displayName) {
|
|
|
|
var endpointId = jid.substr(1 + jid.lastIndexOf('/'));
|
|
|
|
var update = false;
|
|
|
|
|
|
|
|
if (this.endpointsInfo === null) {
|
|
|
|
this.endpointsInfo = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
var endpointInfo = this.endpointsInfo[endpointId];
|
|
|
|
if ('undefined' === typeof endpointInfo) {
|
|
|
|
endpointInfo = this.endpointsInfo[endpointId] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endpointInfo['displayname'] !== displayName) {
|
|
|
|
endpointInfo['displayname'] = displayName;
|
|
|
|
update = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update) {
|
|
|
|
this.updateEndpoints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sends a colibri message to the bridge that contains the
|
|
|
|
* current endpoints and their display names.
|
|
|
|
*/
|
|
|
|
ColibriFocus.prototype.updateEndpoints = function() {
|
|
|
|
if (this.confid === null
|
|
|
|
|| this.endpointsInfo === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.confid === 0) {
|
|
|
|
// the colibri conference is currently initiating
|
|
|
|
var self = this;
|
|
|
|
window.setTimeout(function() { self.updateEndpoints()}, 1000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var elem = $iq({to: this.bridgejid, type: 'set'});
|
|
|
|
elem.c('conference', {
|
|
|
|
xmlns: 'http://jitsi.org/protocol/colibri',
|
|
|
|
id: this.confid
|
|
|
|
});
|
|
|
|
|
|
|
|
for (var id in this.endpointsInfo) {
|
|
|
|
elem.c('endpoint');
|
|
|
|
elem.attrs({ id: id,
|
|
|
|
displayname: this.endpointsInfo[id]['displayname']
|
|
|
|
});
|
|
|
|
elem.up();
|
|
|
|
}
|
|
|
|
|
|
|
|
//elem.up(); //conference
|
|
|
|
|
|
|
|
this.connection.sendIQ(
|
|
|
|
elem,
|
|
|
|
function (result) {},
|
|
|
|
function (error) { console.warn(error); }
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
ColibriFocus.prototype._makeConference = function () {
|
2014-01-03 16:41:50 +00:00
|
|
|
var self = this;
|
2014-07-20 06:01:23 +00:00
|
|
|
var elem = $iq({ to: this.bridgejid, type: 'get' });
|
|
|
|
elem.c('conference', { xmlns: 'http://jitsi.org/protocol/colibri' });
|
2013-12-16 11:22:23 +00:00
|
|
|
|
2014-02-10 20:59:39 +00:00
|
|
|
this.media.forEach(function (name) {
|
2014-07-15 22:36:51 +00:00
|
|
|
var elemName;
|
|
|
|
var elemAttrs = { initiator: 'true', expire: self.channelExpire };
|
|
|
|
|
|
|
|
if ('data' === name)
|
|
|
|
{
|
|
|
|
elemName = 'sctpconnection';
|
|
|
|
elemAttrs['port'] = 5000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
elemName = 'channel';
|
2014-07-20 06:01:23 +00:00
|
|
|
if (('video' === name) && (self.channelLastN >= 0))
|
|
|
|
elemAttrs['last-n'] = self.channelLastN;
|
2014-07-15 22:36:51 +00:00
|
|
|
}
|
2014-05-08 09:26:15 +00:00
|
|
|
|
2014-07-20 06:01:23 +00:00
|
|
|
elem.c('content', { name: name });
|
2014-05-08 09:26:15 +00:00
|
|
|
|
2014-07-15 22:36:51 +00:00
|
|
|
elem.c(elemName, elemAttrs);
|
|
|
|
elem.attrs({ endpoint: self.myMucResource });
|
|
|
|
elem.up();// end of channel/sctpconnection
|
2014-05-08 09:26:15 +00:00
|
|
|
|
2014-02-04 17:24:28 +00:00
|
|
|
for (var j = 0; j < self.peers.length; j++) {
|
2014-07-15 22:36:51 +00:00
|
|
|
var peer = self.peers[j];
|
|
|
|
|
|
|
|
elem.c(elemName, elemAttrs);
|
|
|
|
elem.attrs({ endpoint: peer.substr(1 + peer.lastIndexOf('/')) });
|
2014-07-31 04:09:38 +00:00
|
|
|
if ('channel' === elemName && config.useRtcpMux) {
|
|
|
|
elem.c('rtcp-mux').up();
|
|
|
|
}
|
2014-07-15 22:36:51 +00:00
|
|
|
elem.up(); // end of channel/sctpconnection
|
2014-02-04 17:24:28 +00:00
|
|
|
}
|
|
|
|
elem.up(); // end of content
|
|
|
|
});
|
2014-07-23 07:12:36 +00:00
|
|
|
|
|
|
|
if (this.endpointsInfo !== null) {
|
|
|
|
for (var id in this.endpointsInfo) {
|
|
|
|
elem.c('endpoint');
|
|
|
|
elem.attrs({ id: id,
|
|
|
|
displayname: this.endpointsInfo[id]['displayname']
|
|
|
|
});
|
|
|
|
elem.up();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-04 17:24:28 +00:00
|
|
|
/*
|
2013-12-16 11:22:23 +00:00
|
|
|
var localSDP = new SDP(this.peerconnection.localDescription.sdp);
|
|
|
|
localSDP.media.forEach(function (media, channel) {
|
2014-03-06 14:28:36 +00:00
|
|
|
var name = SDPUtil.parse_mline(media.split('\r\n')[0]).media;
|
2013-12-16 11:22:23 +00:00
|
|
|
elem.c('content', {name: name});
|
2014-07-15 22:36:51 +00:00
|
|
|
elem.c('channel', {initiator: 'false', expire: self.channelExpire});
|
2013-12-16 11:22:23 +00:00
|
|
|
|
|
|
|
// FIXME: should reuse code from .toJingle
|
|
|
|
var mline = SDPUtil.parse_mline(media.split('\r\n')[0]);
|
|
|
|
for (var j = 0; j < mline.fmt.length; j++) {
|
|
|
|
var rtpmap = SDPUtil.find_line(media, 'a=rtpmap:' + mline.fmt[j]);
|
|
|
|
elem.c('payload-type', SDPUtil.parse_rtpmap(rtpmap));
|
|
|
|
elem.up();
|
|
|
|
}
|
|
|
|
|
2013-12-29 17:11:33 +00:00
|
|
|
localSDP.TransportToJingle(channel, elem);
|
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
elem.up(); // end of channel
|
2014-01-03 16:41:50 +00:00
|
|
|
for (j = 0; j < self.peers.length; j++) {
|
2014-07-15 22:36:51 +00:00
|
|
|
elem.c('channel', {initiator: 'true', expire: self.channelExpire }).up();
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
elem.up(); // end of content
|
|
|
|
});
|
2014-02-04 17:24:28 +00:00
|
|
|
*/
|
2013-12-16 11:22:23 +00:00
|
|
|
|
|
|
|
this.connection.sendIQ(elem,
|
|
|
|
function (result) {
|
2014-01-03 16:41:50 +00:00
|
|
|
self.createdConference(result);
|
2013-12-16 11:22:23 +00:00
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.warn(error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// callback when a conference was created
|
|
|
|
ColibriFocus.prototype.createdConference = function (result) {
|
|
|
|
console.log('created a conference on the bridge');
|
2014-02-03 18:40:10 +00:00
|
|
|
var self = this;
|
2013-12-16 11:22:23 +00:00
|
|
|
var tmp;
|
|
|
|
|
|
|
|
this.confid = $(result).find('>conference').attr('id');
|
|
|
|
var remotecontents = $(result).find('>conference>content').get();
|
2013-12-24 17:50:40 +00:00
|
|
|
var numparticipants = 0;
|
2014-05-08 09:26:15 +00:00
|
|
|
for (var i = 0; i < remotecontents.length; i++)
|
|
|
|
{
|
|
|
|
var contentName = $(remotecontents[i]).attr('name');
|
|
|
|
var channelName
|
|
|
|
= contentName !== 'data' ? '>channel' : '>sctpconnection';
|
|
|
|
|
|
|
|
tmp = $(remotecontents[i]).find(channelName).get();
|
2013-12-16 11:22:23 +00:00
|
|
|
this.mychannel.push($(tmp.shift()));
|
2013-12-24 17:50:40 +00:00
|
|
|
numparticipants = tmp.length;
|
2013-12-16 11:22:23 +00:00
|
|
|
for (j = 0; j < tmp.length; j++) {
|
|
|
|
if (this.channels[j] === undefined) {
|
|
|
|
this.channels[j] = [];
|
|
|
|
}
|
|
|
|
this.channels[j].push(tmp[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-04 17:24:28 +00:00
|
|
|
console.log('remote channels', this.channels);
|
2014-02-03 18:40:10 +00:00
|
|
|
|
2014-05-08 09:26:15 +00:00
|
|
|
// Notify that the focus has created the conference on the bridge
|
|
|
|
$(document).trigger('conferenceCreated.jingle', [self]);
|
|
|
|
|
|
|
|
var bridgeSDP = new SDP(
|
|
|
|
'v=0\r\n' +
|
|
|
|
'o=- 5151055458874951233 2 IN IP4 127.0.0.1\r\n' +
|
|
|
|
's=-\r\n' +
|
|
|
|
't=0 0\r\n' +
|
|
|
|
/* Audio */
|
|
|
|
'm=audio 1 RTP/SAVPF 111 103 104 0 8 106 105 13 126\r\n' +
|
|
|
|
'c=IN IP4 0.0.0.0\r\n' +
|
|
|
|
'a=rtcp:1 IN IP4 0.0.0.0\r\n' +
|
|
|
|
'a=mid:audio\r\n' +
|
|
|
|
'a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\n' +
|
|
|
|
'a=sendrecv\r\n' +
|
|
|
|
'a=rtpmap:111 opus/48000/2\r\n' +
|
|
|
|
'a=fmtp:111 minptime=10\r\n' +
|
|
|
|
'a=rtpmap:103 ISAC/16000\r\n' +
|
|
|
|
'a=rtpmap:104 ISAC/32000\r\n' +
|
|
|
|
'a=rtpmap:0 PCMU/8000\r\n' +
|
|
|
|
'a=rtpmap:8 PCMA/8000\r\n' +
|
|
|
|
'a=rtpmap:106 CN/32000\r\n' +
|
|
|
|
'a=rtpmap:105 CN/16000\r\n' +
|
|
|
|
'a=rtpmap:13 CN/8000\r\n' +
|
|
|
|
'a=rtpmap:126 telephone-event/8000\r\n' +
|
|
|
|
'a=maxptime:60\r\n' +
|
2014-07-31 04:09:38 +00:00
|
|
|
(config.useRtcpMux ? 'a=rtcp-mux\r\n' : '') +
|
2014-05-08 09:26:15 +00:00
|
|
|
/* Video */
|
|
|
|
'm=video 1 RTP/SAVPF 100 116 117\r\n' +
|
|
|
|
'c=IN IP4 0.0.0.0\r\n' +
|
|
|
|
'a=rtcp:1 IN IP4 0.0.0.0\r\n' +
|
|
|
|
'a=mid:video\r\n' +
|
|
|
|
'a=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\n' +
|
|
|
|
'a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n' +
|
|
|
|
'a=sendrecv\r\n' +
|
|
|
|
'a=rtpmap:100 VP8/90000\r\n' +
|
|
|
|
'a=rtcp-fb:100 ccm fir\r\n' +
|
|
|
|
'a=rtcp-fb:100 nack\r\n' +
|
|
|
|
'a=rtcp-fb:100 goog-remb\r\n' +
|
|
|
|
'a=rtpmap:116 red/90000\r\n' +
|
|
|
|
'a=rtpmap:117 ulpfec/90000\r\n' +
|
2014-07-31 04:09:38 +00:00
|
|
|
(config.useRtcpMux ? 'a=rtcp-mux\r\n' : '') +
|
2014-05-08 09:26:15 +00:00
|
|
|
/* Data SCTP */
|
|
|
|
(config.openSctp ?
|
|
|
|
'm=application 1 DTLS/SCTP 5000\r\n' +
|
|
|
|
'c=IN IP4 0.0.0.0\r\n' +
|
|
|
|
'a=sctpmap:5000 webrtc-datachannel\r\n' +
|
|
|
|
'a=mid:data\r\n'
|
|
|
|
: '')
|
|
|
|
);
|
|
|
|
|
2014-02-04 17:24:28 +00:00
|
|
|
bridgeSDP.media.length = this.mychannel.length;
|
2013-12-26 15:23:46 +00:00
|
|
|
var channel;
|
2014-02-04 17:24:28 +00:00
|
|
|
/*
|
2013-12-26 15:23:46 +00:00
|
|
|
for (channel = 0; channel < bridgeSDP.media.length; channel++) {
|
|
|
|
bridgeSDP.media[channel] = '';
|
|
|
|
// unchanged lines
|
|
|
|
bridgeSDP.media[channel] += SDPUtil.find_line(localSDP.media[channel], 'm=') + '\r\n';
|
|
|
|
bridgeSDP.media[channel] += SDPUtil.find_line(localSDP.media[channel], 'c=') + '\r\n';
|
|
|
|
if (SDPUtil.find_line(localSDP.media[channel], 'a=rtcp:')) {
|
|
|
|
bridgeSDP.media[channel] += SDPUtil.find_line(localSDP.media[channel], 'a=rtcp:') + '\r\n';
|
|
|
|
}
|
|
|
|
if (SDPUtil.find_line(localSDP.media[channel], 'a=mid:')) {
|
|
|
|
bridgeSDP.media[channel] += SDPUtil.find_line(localSDP.media[channel], 'a=mid:') + '\r\n';
|
|
|
|
}
|
|
|
|
if (SDPUtil.find_line(localSDP.media[channel], 'a=sendrecv')) {
|
|
|
|
bridgeSDP.media[channel] += 'a=sendrecv\r\n';
|
|
|
|
}
|
|
|
|
if (SDPUtil.find_line(localSDP.media[channel], 'a=extmap:')) {
|
|
|
|
bridgeSDP.media[channel] += SDPUtil.find_lines(localSDP.media[channel], 'a=extmap:').join('\r\n') + '\r\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: should look at m-line and group the ids together
|
|
|
|
if (SDPUtil.find_line(localSDP.media[channel], 'a=rtpmap:')) {
|
|
|
|
bridgeSDP.media[channel] += SDPUtil.find_lines(localSDP.media[channel], 'a=rtpmap:').join('\r\n') + '\r\n';
|
|
|
|
}
|
|
|
|
if (SDPUtil.find_line(localSDP.media[channel], 'a=fmtp:')) {
|
|
|
|
bridgeSDP.media[channel] += SDPUtil.find_lines(localSDP.media[channel], 'a=fmtp:').join('\r\n') + '\r\n';
|
|
|
|
}
|
|
|
|
if (SDPUtil.find_line(localSDP.media[channel], 'a=rtcp-fb:')) {
|
|
|
|
bridgeSDP.media[channel] += SDPUtil.find_lines(localSDP.media[channel], 'a=rtcp-fb:').join('\r\n') + '\r\n';
|
|
|
|
}
|
|
|
|
// FIXME: changed lines -- a=sendrecv direction, a=setup direction
|
|
|
|
}
|
2014-02-04 17:24:28 +00:00
|
|
|
*/
|
2013-12-26 15:23:46 +00:00
|
|
|
for (channel = 0; channel < bridgeSDP.media.length; channel++) {
|
2014-02-04 17:24:28 +00:00
|
|
|
// get the mixed ssrc
|
2013-12-16 11:22:23 +00:00
|
|
|
tmp = $(this.mychannel[channel]).find('>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
|
|
|
|
// FIXME: check rtp-level-relay-type
|
2014-05-08 09:26:15 +00:00
|
|
|
|
|
|
|
var isData = bridgeSDP.media[channel].indexOf('application') !== -1;
|
|
|
|
if (!isData && tmp.length)
|
|
|
|
{
|
2013-12-16 11:22:23 +00:00
|
|
|
bridgeSDP.media[channel] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'cname:mixed' + '\r\n';
|
|
|
|
bridgeSDP.media[channel] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'label:mixedlabela0' + '\r\n';
|
2013-12-31 08:40:22 +00:00
|
|
|
bridgeSDP.media[channel] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'msid:mixedmslabel mixedlabela0' + '\r\n';
|
|
|
|
bridgeSDP.media[channel] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'mslabel:mixedmslabel' + '\r\n';
|
2014-05-08 09:26:15 +00:00
|
|
|
}
|
|
|
|
else if (!isData)
|
|
|
|
{
|
2013-12-16 11:22:23 +00:00
|
|
|
// make chrome happy... '3735928559' == 0xDEADBEEF
|
2013-12-26 15:23:46 +00:00
|
|
|
// FIXME: this currently appears as two streams, should be one
|
2013-12-16 11:22:23 +00:00
|
|
|
bridgeSDP.media[channel] += 'a=ssrc:' + '3735928559' + ' ' + 'cname:mixed' + '\r\n';
|
|
|
|
bridgeSDP.media[channel] += 'a=ssrc:' + '3735928559' + ' ' + 'label:mixedlabelv0' + '\r\n';
|
2013-12-31 08:40:22 +00:00
|
|
|
bridgeSDP.media[channel] += 'a=ssrc:' + '3735928559' + ' ' + 'msid:mixedmslabel mixedlabelv0' + '\r\n';
|
|
|
|
bridgeSDP.media[channel] += 'a=ssrc:' + '3735928559' + ' ' + 'mslabel:mixedmslabel' + '\r\n';
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: should take code from .fromJingle
|
|
|
|
tmp = $(this.mychannel[channel]).find('>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]');
|
|
|
|
if (tmp.length) {
|
|
|
|
bridgeSDP.media[channel] += 'a=ice-ufrag:' + tmp.attr('ufrag') + '\r\n';
|
|
|
|
bridgeSDP.media[channel] += 'a=ice-pwd:' + tmp.attr('pwd') + '\r\n';
|
|
|
|
tmp.find('>candidate').each(function () {
|
|
|
|
bridgeSDP.media[channel] += SDPUtil.candidateFromJingle(this);
|
|
|
|
});
|
|
|
|
tmp = tmp.find('>fingerprint');
|
|
|
|
if (tmp.length) {
|
|
|
|
bridgeSDP.media[channel] += 'a=fingerprint:' + tmp.attr('hash') + ' ' + tmp.text() + '\r\n';
|
2014-02-04 17:24:28 +00:00
|
|
|
bridgeSDP.media[channel] += 'a=setup:actpass\r\n'; // offer so always actpass
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bridgeSDP.raw = bridgeSDP.session + bridgeSDP.media.join('');
|
|
|
|
|
|
|
|
this.peerconnection.setRemoteDescription(
|
2014-02-04 17:24:28 +00:00
|
|
|
new RTCSessionDescription({type: 'offer', sdp: bridgeSDP.raw}),
|
2013-12-16 11:22:23 +00:00
|
|
|
function () {
|
|
|
|
console.log('setRemoteDescription success');
|
2014-02-04 17:24:28 +00:00
|
|
|
self.peerconnection.createAnswer(
|
|
|
|
function (answer) {
|
|
|
|
self.peerconnection.setLocalDescription(answer,
|
|
|
|
function () {
|
|
|
|
console.log('setLocalDescription succeded.');
|
|
|
|
// make sure our presence is updated
|
|
|
|
$(document).trigger('setLocalDescription.jingle', [self.sid]);
|
|
|
|
var elem = $iq({to: self.bridgejid, type: 'get'});
|
|
|
|
elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: self.confid});
|
|
|
|
var localSDP = new SDP(self.peerconnection.localDescription.sdp);
|
|
|
|
localSDP.media.forEach(function (media, channel) {
|
2014-05-08 09:26:15 +00:00
|
|
|
var name = SDPUtil.parse_mid(SDPUtil.find_line(media, 'a=mid:'));
|
2014-02-04 17:24:28 +00:00
|
|
|
elem.c('content', {name: name});
|
|
|
|
var mline = SDPUtil.parse_mline(media.split('\r\n')[0]);
|
2014-05-08 09:26:15 +00:00
|
|
|
if (name !== 'data')
|
|
|
|
{
|
|
|
|
elem.c('channel', {
|
|
|
|
initiator: 'true',
|
|
|
|
expire: self.channelExpire,
|
|
|
|
id: self.mychannel[channel].attr('id'),
|
2014-05-13 14:51:08 +00:00
|
|
|
endpoint: self.myMucResource
|
2014-05-08 09:26:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// FIXME: should reuse code from .toJingle
|
|
|
|
for (var j = 0; j < mline.fmt.length; j++)
|
|
|
|
{
|
|
|
|
var rtpmap = SDPUtil.find_line(media, 'a=rtpmap:' + mline.fmt[j]);
|
|
|
|
if (rtpmap)
|
|
|
|
{
|
|
|
|
elem.c('payload-type', SDPUtil.parse_rtpmap(rtpmap));
|
|
|
|
elem.up();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var sctpmap = SDPUtil.find_line(media, 'a=sctpmap:' + mline.fmt[0]);
|
2014-05-26 12:54:17 +00:00
|
|
|
var sctpPort = SDPUtil.parse_sctpmap(sctpmap)[0];
|
2014-05-08 09:26:15 +00:00
|
|
|
elem.c("sctpconnection",
|
|
|
|
{
|
|
|
|
initiator: 'true',
|
|
|
|
expire: self.channelExpire,
|
2014-05-13 14:51:08 +00:00
|
|
|
endpoint: self.myMucResource,
|
2014-05-08 09:26:15 +00:00
|
|
|
port: sctpPort
|
|
|
|
}
|
|
|
|
);
|
2014-02-04 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
localSDP.TransportToJingle(channel, elem);
|
|
|
|
|
|
|
|
elem.up(); // end of channel
|
|
|
|
elem.up(); // end of content
|
|
|
|
});
|
|
|
|
|
|
|
|
self.connection.sendIQ(elem,
|
|
|
|
function (result) {
|
|
|
|
// ...
|
|
|
|
},
|
|
|
|
function (error) {
|
2014-05-08 09:26:15 +00:00
|
|
|
console.error(
|
|
|
|
"ERROR setLocalDescription succeded",
|
|
|
|
error, elem);
|
2014-02-04 17:24:28 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// now initiate sessions
|
|
|
|
for (var i = 0; i < numparticipants; i++) {
|
|
|
|
self.initiate(self.peers[i], true);
|
|
|
|
}
|
2014-06-05 11:09:31 +00:00
|
|
|
|
|
|
|
// Notify we've created the conference
|
|
|
|
$(document).trigger(
|
|
|
|
'conferenceCreated.jingle', self);
|
2014-02-04 17:24:28 +00:00
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.warn('setLocalDescription failed.', error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.warn('createAnswer failed.', error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
/*
|
2013-12-24 17:50:40 +00:00
|
|
|
for (var i = 0; i < numparticipants; i++) {
|
2014-01-03 16:41:50 +00:00
|
|
|
self.initiate(self.peers[i], true);
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
2014-02-04 17:24:28 +00:00
|
|
|
*/
|
2013-12-16 11:22:23 +00:00
|
|
|
},
|
|
|
|
function (error) {
|
2014-02-04 17:24:28 +00:00
|
|
|
console.log('setRemoteDescription failed.', error);
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// send a session-initiate to a new participant
|
|
|
|
ColibriFocus.prototype.initiate = function (peer, isInitiator) {
|
|
|
|
var participant = this.peers.indexOf(peer);
|
|
|
|
console.log('tell', peer, participant);
|
|
|
|
var sdp;
|
2013-12-26 15:23:46 +00:00
|
|
|
if (this.peerconnection !== null && this.peerconnection.signalingState == 'stable') {
|
2013-12-16 11:22:23 +00:00
|
|
|
sdp = new SDP(this.peerconnection.remoteDescription.sdp);
|
|
|
|
var localSDP = new SDP(this.peerconnection.localDescription.sdp);
|
|
|
|
// throw away stuff we don't want
|
|
|
|
// not needed with static offer
|
|
|
|
sdp.removeSessionLines('a=group:');
|
|
|
|
sdp.removeSessionLines('a=msid-semantic:'); // FIXME: not mapped over jingle anyway...
|
|
|
|
for (var i = 0; i < sdp.media.length; i++) {
|
2014-07-31 04:09:38 +00:00
|
|
|
if (!config.useRtcpMux){
|
|
|
|
sdp.removeMediaLines(i, 'a=rtcp-mux');
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
sdp.removeMediaLines(i, 'a=ssrc:');
|
|
|
|
sdp.removeMediaLines(i, 'a=crypto:');
|
|
|
|
sdp.removeMediaLines(i, 'a=candidate:');
|
|
|
|
sdp.removeMediaLines(i, 'a=ice-options:google-ice');
|
|
|
|
sdp.removeMediaLines(i, 'a=ice-ufrag:');
|
|
|
|
sdp.removeMediaLines(i, 'a=ice-pwd:');
|
|
|
|
sdp.removeMediaLines(i, 'a=fingerprint:');
|
|
|
|
sdp.removeMediaLines(i, 'a=setup:');
|
|
|
|
|
2014-01-03 22:08:05 +00:00
|
|
|
if (1) { //i > 0) { // not for audio FIXME: does not work as intended
|
2013-12-25 20:38:05 +00:00
|
|
|
// re-add all remote a=ssrcs
|
|
|
|
for (var jid in this.remotessrc) {
|
2014-07-14 07:28:22 +00:00
|
|
|
if (jid == peer || !this.remotessrc[jid][i])
|
|
|
|
continue;
|
2013-12-25 20:38:05 +00:00
|
|
|
sdp.media[i] += this.remotessrc[jid][i];
|
|
|
|
}
|
|
|
|
// and local a=ssrc lines
|
|
|
|
sdp.media[i] += SDPUtil.find_lines(localSDP.media[i], 'a=ssrc').join('\r\n') + '\r\n';
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sdp.raw = sdp.session + sdp.media.join('');
|
|
|
|
} else {
|
|
|
|
console.error('can not initiate a new session without a stable peerconnection');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add stuff we got from the bridge
|
|
|
|
for (var j = 0; j < sdp.media.length; j++) {
|
|
|
|
var chan = $(this.channels[participant][j]);
|
|
|
|
console.log('channel id', chan.attr('id'));
|
|
|
|
|
|
|
|
tmp = chan.find('>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
|
|
|
|
if (tmp.length) {
|
|
|
|
sdp.media[j] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'cname:mixed' + '\r\n';
|
|
|
|
sdp.media[j] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'label:mixedlabela0' + '\r\n';
|
2013-12-31 08:40:22 +00:00
|
|
|
sdp.media[j] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'msid:mixedmslabel mixedlabela0' + '\r\n';
|
|
|
|
sdp.media[j] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'mslabel:mixedmslabel' + '\r\n';
|
2014-05-08 09:26:15 +00:00
|
|
|
}
|
|
|
|
// No SSRCs for 'data', comes when j == 2
|
|
|
|
else if (j < 2)
|
|
|
|
{
|
2013-12-16 11:22:23 +00:00
|
|
|
// make chrome happy... '3735928559' == 0xDEADBEEF
|
|
|
|
sdp.media[j] += 'a=ssrc:' + '3735928559' + ' ' + 'cname:mixed' + '\r\n';
|
|
|
|
sdp.media[j] += 'a=ssrc:' + '3735928559' + ' ' + 'label:mixedlabelv0' + '\r\n';
|
2013-12-31 08:40:22 +00:00
|
|
|
sdp.media[j] += 'a=ssrc:' + '3735928559' + ' ' + 'msid:mixedmslabel mixedlabelv0' + '\r\n';
|
|
|
|
sdp.media[j] += 'a=ssrc:' + '3735928559' + ' ' + 'mslabel:mixedmslabel' + '\r\n';
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tmp = chan.find('>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]');
|
|
|
|
if (tmp.length) {
|
|
|
|
if (tmp.attr('ufrag'))
|
|
|
|
sdp.media[j] += 'a=ice-ufrag:' + tmp.attr('ufrag') + '\r\n';
|
|
|
|
if (tmp.attr('pwd'))
|
|
|
|
sdp.media[j] += 'a=ice-pwd:' + tmp.attr('pwd') + '\r\n';
|
|
|
|
// and the candidates...
|
|
|
|
tmp.find('>candidate').each(function () {
|
|
|
|
sdp.media[j] += SDPUtil.candidateFromJingle(this);
|
|
|
|
});
|
|
|
|
tmp = tmp.find('>fingerprint');
|
|
|
|
if (tmp.length) {
|
|
|
|
sdp.media[j] += 'a=fingerprint:' + tmp.attr('hash') + ' ' + tmp.text() + '\r\n';
|
|
|
|
/*
|
|
|
|
if (tmp.attr('direction')) {
|
|
|
|
sdp.media[j] += 'a=setup:' + tmp.attr('direction') + '\r\n';
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
sdp.media[j] += 'a=setup:actpass\r\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// make a new colibri session and configure it
|
|
|
|
// FIXME: is it correct to use this.connection.jid when used in a MUC?
|
|
|
|
var sess = new ColibriSession(this.connection.jid,
|
|
|
|
Math.random().toString(36).substr(2, 12), // random string
|
|
|
|
this.connection);
|
|
|
|
sess.initiate(peer);
|
|
|
|
sess.colibri = this;
|
2014-03-12 15:08:24 +00:00
|
|
|
// We do not announce our audio per conference peer, so only video is set here
|
|
|
|
sess.localVideo = this.connection.jingle.localVideo;
|
2013-12-16 11:22:23 +00:00
|
|
|
sess.media_constraints = this.connection.jingle.media_constraints;
|
|
|
|
sess.pc_constraints = this.connection.jingle.pc_constraints;
|
2013-12-30 09:28:48 +00:00
|
|
|
sess.ice_config = this.connection.jingle.ice_config;
|
2013-12-16 11:22:23 +00:00
|
|
|
|
|
|
|
this.connection.jingle.sessions[sess.sid] = sess;
|
|
|
|
this.connection.jingle.jid2session[sess.peerjid] = sess;
|
|
|
|
|
|
|
|
// send a session-initiate
|
|
|
|
var init = $iq({to: peer, type: 'set'})
|
|
|
|
.c('jingle',
|
|
|
|
{xmlns: 'urn:xmpp:jingle:1',
|
|
|
|
action: 'session-initiate',
|
|
|
|
initiator: sess.me,
|
|
|
|
sid: sess.sid
|
|
|
|
}
|
|
|
|
);
|
|
|
|
sdp.toJingle(init, 'initiator');
|
|
|
|
this.connection.sendIQ(init,
|
|
|
|
function (res) {
|
|
|
|
console.log('got result');
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
console.log('got error');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// pull in a new participant into the conference
|
|
|
|
ColibriFocus.prototype.addNewParticipant = function (peer) {
|
2014-01-03 16:41:50 +00:00
|
|
|
var self = this;
|
2014-05-08 09:26:15 +00:00
|
|
|
if (this.confid === 0 || !this.peerconnection.localDescription)
|
|
|
|
{
|
2013-12-16 11:22:23 +00:00
|
|
|
// bad state
|
2014-05-08 09:26:15 +00:00
|
|
|
if (this.confid === 0)
|
|
|
|
{
|
|
|
|
console.error('confid does not exist yet, postponing', peer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.error('local description not ready yet, postponing', peer);
|
|
|
|
}
|
2014-07-20 06:01:23 +00:00
|
|
|
window.setTimeout(function () { self.addNewParticipant(peer); }, 250);
|
2013-12-16 11:22:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var index = this.channels.length;
|
|
|
|
this.channels.push([]);
|
|
|
|
this.peers.push(peer);
|
|
|
|
|
|
|
|
var elem = $iq({to: this.bridgejid, type: 'get'});
|
2014-07-20 06:01:23 +00:00
|
|
|
elem.c(
|
|
|
|
'conference',
|
|
|
|
{ xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid });
|
2013-12-16 11:22:23 +00:00
|
|
|
var localSDP = new SDP(this.peerconnection.localDescription.sdp);
|
2013-12-24 13:41:10 +00:00
|
|
|
localSDP.media.forEach(function (media, channel) {
|
2014-05-08 09:26:15 +00:00
|
|
|
var name = SDPUtil.parse_mid(SDPUtil.find_line(media, 'a=mid:'));
|
2014-07-15 22:36:51 +00:00
|
|
|
var elemName;
|
|
|
|
var elemAttrs
|
|
|
|
= {
|
2014-03-17 11:20:42 +00:00
|
|
|
initiator: 'true',
|
2014-05-08 09:26:15 +00:00
|
|
|
expire: self.channelExpire,
|
2014-03-17 11:20:42 +00:00
|
|
|
endpoint: peer.substr(1 + peer.lastIndexOf('/'))
|
2014-07-15 22:36:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if ('data' == name)
|
|
|
|
{
|
|
|
|
elemName = 'sctpconnection';
|
|
|
|
elemAttrs['port'] = 5000;
|
2014-05-08 09:26:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-15 22:36:51 +00:00
|
|
|
elemName = 'channel';
|
2014-07-20 06:01:23 +00:00
|
|
|
if (('video' === name) && (self.channelLastN >= 0))
|
|
|
|
elemAttrs['last-n'] = self.channelLastN;
|
2014-05-08 09:26:15 +00:00
|
|
|
}
|
2014-07-15 22:36:51 +00:00
|
|
|
|
2014-07-20 06:01:23 +00:00
|
|
|
elem.c('content', { name: name });
|
2014-07-15 22:36:51 +00:00
|
|
|
elem.c(elemName, elemAttrs);
|
2014-07-31 04:09:38 +00:00
|
|
|
if ('channel' === elemName && config.useRtcpMux) {
|
|
|
|
elem.c('rtcp-mux').up();
|
|
|
|
}
|
2014-05-08 09:26:15 +00:00
|
|
|
elem.up(); // end of channel/sctpconnection
|
2013-12-16 11:22:23 +00:00
|
|
|
elem.up(); // end of content
|
|
|
|
});
|
|
|
|
|
|
|
|
this.connection.sendIQ(elem,
|
|
|
|
function (result) {
|
|
|
|
var contents = $(result).find('>conference>content').get();
|
|
|
|
for (var i = 0; i < contents.length; i++) {
|
2014-05-08 09:26:15 +00:00
|
|
|
var channelXml = $(contents[i]).find('>channel');
|
|
|
|
if (channelXml.length)
|
|
|
|
{
|
|
|
|
tmp = channelXml.get();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp = $(contents[i]).find('>sctpconnection').get();
|
|
|
|
}
|
2014-01-03 16:41:50 +00:00
|
|
|
self.channels[index][i] = tmp[0];
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
2014-01-03 16:41:50 +00:00
|
|
|
self.initiate(peer, true);
|
2013-12-16 11:22:23 +00:00
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
console.warn(error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// update the channel description (payload-types + dtls fp) for a participant
|
|
|
|
ColibriFocus.prototype.updateChannel = function (remoteSDP, participant) {
|
|
|
|
console.log('change allocation for', this.confid);
|
2014-05-08 09:26:15 +00:00
|
|
|
var self = this;
|
2013-12-16 11:22:23 +00:00
|
|
|
var change = $iq({to: this.bridgejid, type: 'set'});
|
|
|
|
change.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid});
|
2014-05-08 09:26:15 +00:00
|
|
|
for (channel = 0; channel < this.channels[participant].length; channel++)
|
|
|
|
{
|
2014-07-14 07:28:22 +00:00
|
|
|
if (!remoteSDP.media[channel])
|
|
|
|
continue;
|
|
|
|
|
2014-05-08 09:26:15 +00:00
|
|
|
var name = SDPUtil.parse_mid(SDPUtil.find_line(remoteSDP.media[channel], 'a=mid:'));
|
|
|
|
change.c('content', {name: name});
|
|
|
|
if (name !== 'data')
|
|
|
|
{
|
|
|
|
change.c('channel', {
|
|
|
|
id: $(this.channels[participant][channel]).attr('id'),
|
|
|
|
endpoint: $(this.channels[participant][channel]).attr('endpoint'),
|
|
|
|
expire: self.channelExpire
|
|
|
|
});
|
2014-07-31 04:09:38 +00:00
|
|
|
if (config.useRtcpMux) {
|
|
|
|
change.c('rtcp-mux').up();
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
|
2014-05-08 09:26:15 +00:00
|
|
|
var rtpmap = SDPUtil.find_lines(remoteSDP.media[channel], 'a=rtpmap:');
|
|
|
|
rtpmap.forEach(function (val) {
|
|
|
|
// TODO: too much copy-paste
|
|
|
|
var rtpmap = SDPUtil.parse_rtpmap(val);
|
|
|
|
change.c('payload-type', rtpmap);
|
|
|
|
//
|
|
|
|
// put any 'a=fmtp:' + mline.fmt[j] lines into <param name=foo value=bar/>
|
|
|
|
/*
|
|
|
|
if (SDPUtil.find_line(remoteSDP.media[channel], 'a=fmtp:' + rtpmap.id)) {
|
|
|
|
tmp = SDPUtil.parse_fmtp(SDPUtil.find_line(remoteSDP.media[channel], 'a=fmtp:' + rtpmap.id));
|
|
|
|
for (var k = 0; k < tmp.length; k++) {
|
|
|
|
change.c('parameter', tmp[k]).up();
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
2014-05-08 09:26:15 +00:00
|
|
|
*/
|
|
|
|
change.up();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var sctpmap = SDPUtil.find_line(remoteSDP.media[channel], 'a=sctpmap:');
|
|
|
|
change.c('sctpconnection', {
|
|
|
|
endpoint: $(this.channels[participant][channel]).attr('endpoint'),
|
|
|
|
expire: self.channelExpire,
|
2014-05-26 12:54:17 +00:00
|
|
|
port: SDPUtil.parse_sctpmap(sctpmap)[0]
|
2014-05-08 09:26:15 +00:00
|
|
|
});
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
// now add transport
|
2013-12-29 17:11:33 +00:00
|
|
|
remoteSDP.TransportToJingle(channel, change);
|
2013-12-16 11:22:23 +00:00
|
|
|
|
2014-05-08 09:26:15 +00:00
|
|
|
change.up(); // end of channel/sctpconnection
|
2013-12-16 11:22:23 +00:00
|
|
|
change.up(); // end of content
|
|
|
|
}
|
|
|
|
this.connection.sendIQ(change,
|
|
|
|
function (res) {
|
|
|
|
console.log('got result');
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
console.log('got error');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// tell everyone about a new participants a=ssrc lines (isadd is true)
|
|
|
|
// or a leaving participants a=ssrc lines
|
2014-03-13 12:22:54 +00:00
|
|
|
ColibriFocus.prototype.sendSSRCUpdate = function (sdpMediaSsrcs, fromJid, isadd) {
|
2014-01-03 16:41:50 +00:00
|
|
|
var self = this;
|
2013-12-16 11:22:23 +00:00
|
|
|
this.peers.forEach(function (peerjid) {
|
2014-03-13 12:22:54 +00:00
|
|
|
if (peerjid == fromJid) return;
|
|
|
|
console.log('tell', peerjid, 'about ' + (isadd ? 'new' : 'removed') + ' ssrcs from', fromJid);
|
2014-01-03 16:41:50 +00:00
|
|
|
if (!self.remotessrc[peerjid]) {
|
2013-12-16 11:22:23 +00:00
|
|
|
// FIXME: this should only send to participants that are stable, i.e. who have sent a session-accept
|
|
|
|
// possibly, this.remoteSSRC[session.peerjid] does not exist yet
|
|
|
|
console.warn('do we really want to bother', peerjid, 'with updates yet?');
|
|
|
|
}
|
2014-01-03 16:41:50 +00:00
|
|
|
var peersess = self.connection.jingle.jid2session[peerjid];
|
2014-03-13 12:22:54 +00:00
|
|
|
if(!peersess){
|
|
|
|
console.warn('no session with peer: '+peerjid+' yet...');
|
|
|
|
return;
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
2014-03-13 12:22:54 +00:00
|
|
|
|
|
|
|
self.sendSSRCUpdateIq(sdpMediaSsrcs, peersess.sid, peersess.initiator, peerjid, isadd);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overrides SessionBase.addSource.
|
|
|
|
*
|
|
|
|
* @param elem proprietary 'add source' Jingle request(XML node).
|
|
|
|
* @param fromJid JID of the participant to whom new ssrcs belong.
|
|
|
|
*/
|
|
|
|
ColibriFocus.prototype.addSource = function (elem, fromJid) {
|
|
|
|
|
|
|
|
var self = this;
|
2014-06-18 16:58:00 +00:00
|
|
|
// FIXME: dirty waiting
|
|
|
|
if (!this.peerconnection.localDescription)
|
|
|
|
{
|
|
|
|
console.warn("addSource - localDescription not ready yet")
|
2014-07-20 06:01:23 +00:00
|
|
|
setTimeout(function() { self.addSource(elem, fromJid); }, 200);
|
2014-06-18 16:58:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-13 12:22:54 +00:00
|
|
|
this.peerconnection.addSource(elem);
|
|
|
|
|
|
|
|
var peerSsrc = this.remotessrc[fromJid];
|
|
|
|
//console.log("On ADD", self.addssrc, peerSsrc);
|
|
|
|
this.peerconnection.addssrc.forEach(function(val, idx){
|
|
|
|
if(!peerSsrc[idx]){
|
|
|
|
// add ssrc
|
|
|
|
peerSsrc[idx] = val;
|
2013-12-25 20:38:05 +00:00
|
|
|
} else {
|
2014-03-13 12:22:54 +00:00
|
|
|
if(peerSsrc[idx].indexOf(val) == -1){
|
|
|
|
peerSsrc[idx] = peerSsrc[idx]+val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var oldRemoteSdp = new SDP(this.peerconnection.remoteDescription.sdp);
|
|
|
|
this.modifySources(function(){
|
|
|
|
// Notify other participants about added ssrc
|
|
|
|
var remoteSDP = new SDP(self.peerconnection.remoteDescription.sdp);
|
|
|
|
var newSSRCs = oldRemoteSdp.getNewMedia(remoteSDP);
|
|
|
|
self.sendSSRCUpdate(newSSRCs, fromJid, true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overrides SessionBase.removeSource.
|
|
|
|
*
|
|
|
|
* @param elem proprietary 'remove source' Jingle request(XML node).
|
|
|
|
* @param fromJid JID of the participant to whom removed ssrcs belong.
|
|
|
|
*/
|
|
|
|
ColibriFocus.prototype.removeSource = function (elem, fromJid) {
|
|
|
|
|
|
|
|
var self = this;
|
2014-06-18 16:58:00 +00:00
|
|
|
// FIXME: dirty waiting
|
|
|
|
if (!self.peerconnection.localDescription)
|
|
|
|
{
|
|
|
|
console.warn("removeSource - localDescription not ready yet");
|
2014-07-20 06:01:23 +00:00
|
|
|
setTimeout(function() { self.removeSource(elem, fromJid); }, 200);
|
2014-06-18 16:58:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-13 12:22:54 +00:00
|
|
|
this.peerconnection.removeSource(elem);
|
|
|
|
|
|
|
|
var peerSsrc = this.remotessrc[fromJid];
|
|
|
|
//console.log("On REMOVE", self.removessrc, peerSsrc);
|
|
|
|
this.peerconnection.removessrc.forEach(function(val, idx){
|
|
|
|
if(peerSsrc[idx]){
|
|
|
|
// Remove ssrc
|
|
|
|
peerSsrc[idx] = peerSsrc[idx].replace(val, '');
|
2013-12-25 20:38:05 +00:00
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
});
|
2014-03-13 12:22:54 +00:00
|
|
|
|
|
|
|
var oldSDP = new SDP(self.peerconnection.remoteDescription.sdp);
|
|
|
|
this.modifySources(function(){
|
|
|
|
// Notify other participants about removed ssrc
|
|
|
|
var remoteSDP = new SDP(self.peerconnection.remoteDescription.sdp);
|
|
|
|
var removedSSRCs = remoteSDP.getNewMedia(oldSDP);
|
|
|
|
self.sendSSRCUpdate(removedSSRCs, fromJid, false);
|
|
|
|
});
|
2013-12-16 11:22:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ColibriFocus.prototype.setRemoteDescription = function (session, elem, desctype) {
|
|
|
|
var participant = this.peers.indexOf(session.peerjid);
|
|
|
|
console.log('Colibri.setRemoteDescription from', session.peerjid, participant);
|
|
|
|
var remoteSDP = new SDP('');
|
|
|
|
var channel;
|
|
|
|
remoteSDP.fromJingle(elem);
|
|
|
|
|
|
|
|
// ACT 1: change allocation on bridge
|
|
|
|
this.updateChannel(remoteSDP, participant);
|
|
|
|
|
|
|
|
// ACT 2: tell anyone else about the new SSRCs
|
2014-03-13 12:22:54 +00:00
|
|
|
this.sendSSRCUpdate(remoteSDP.getMediaSsrcMap(), session.peerjid, true);
|
2013-12-16 11:22:23 +00:00
|
|
|
|
|
|
|
// ACT 3: note the SSRCs
|
|
|
|
this.remotessrc[session.peerjid] = [];
|
|
|
|
for (channel = 0; channel < this.channels[participant].length; channel++) {
|
2014-01-03 22:08:05 +00:00
|
|
|
//if (channel == 0) continue; FIXME: does not work as intended
|
2014-07-14 07:28:22 +00:00
|
|
|
if (!remoteSDP.media[channel])
|
|
|
|
continue;
|
|
|
|
|
2014-05-08 09:26:15 +00:00
|
|
|
if (SDPUtil.find_lines(remoteSDP.media[channel], 'a=ssrc:').length)
|
|
|
|
{
|
|
|
|
this.remotessrc[session.peerjid][channel] =
|
|
|
|
SDPUtil.find_lines(remoteSDP.media[channel], 'a=ssrc:')
|
|
|
|
.join('\r\n') + '\r\n';
|
2014-02-10 20:59:39 +00:00
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ACT 4: add new a=ssrc lines to local remotedescription
|
|
|
|
for (channel = 0; channel < this.channels[participant].length; channel++) {
|
2014-01-03 22:08:05 +00:00
|
|
|
//if (channel == 0) continue; FIXME: does not work as intended
|
2014-07-14 07:28:22 +00:00
|
|
|
if (!remoteSDP.media[channel])
|
|
|
|
continue;
|
|
|
|
|
2014-02-10 20:59:39 +00:00
|
|
|
if (SDPUtil.find_lines(remoteSDP.media[channel], 'a=ssrc:').length) {
|
2014-03-12 13:21:26 +00:00
|
|
|
this.peerconnection.enqueueAddSsrc(
|
|
|
|
channel,
|
|
|
|
SDPUtil.find_lines(remoteSDP.media[channel], 'a=ssrc:').join('\r\n') + '\r\n'
|
|
|
|
);
|
2014-02-10 20:59:39 +00:00
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
this.modifySources();
|
|
|
|
};
|
|
|
|
|
|
|
|
// relay ice candidates to bridge using trickle
|
|
|
|
ColibriFocus.prototype.addIceCandidate = function (session, elem) {
|
2014-01-03 16:41:50 +00:00
|
|
|
var self = this;
|
2013-12-16 11:22:23 +00:00
|
|
|
var participant = this.peers.indexOf(session.peerjid);
|
2014-01-03 16:41:50 +00:00
|
|
|
//console.log('change transport allocation for', this.confid, session.peerjid, participant);
|
2013-12-16 11:22:23 +00:00
|
|
|
var change = $iq({to: this.bridgejid, type: 'set'});
|
|
|
|
change.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid});
|
|
|
|
$(elem).each(function () {
|
|
|
|
var name = $(this).attr('name');
|
2014-05-08 09:26:15 +00:00
|
|
|
|
2013-12-16 11:22:23 +00:00
|
|
|
var channel = name == 'audio' ? 0 : 1; // FIXME: search mlineindex in localdesc
|
2014-05-08 09:26:15 +00:00
|
|
|
if (name != 'audio' && name != 'video')
|
|
|
|
channel = 2; // name == 'data'
|
2013-12-16 11:22:23 +00:00
|
|
|
|
|
|
|
change.c('content', {name: name});
|
2014-05-08 09:26:15 +00:00
|
|
|
if (name !== 'data')
|
|
|
|
{
|
|
|
|
change.c('channel', {
|
|
|
|
id: $(self.channels[participant][channel]).attr('id'),
|
|
|
|
endpoint: $(self.channels[participant][channel]).attr('endpoint'),
|
|
|
|
expire: self.channelExpire
|
|
|
|
});
|
2014-07-31 04:09:38 +00:00
|
|
|
|
|
|
|
if (config.useRtcpMux) {
|
|
|
|
change.c('rtcp-mux').up();
|
|
|
|
}
|
2014-05-08 09:26:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
change.c('sctpconnection', {
|
|
|
|
endpoint: $(self.channels[participant][channel]).attr('endpoint'),
|
|
|
|
expire: self.channelExpire
|
|
|
|
});
|
|
|
|
}
|
2013-12-16 11:22:23 +00:00
|
|
|
$(this).find('>transport').each(function () {
|
|
|
|
change.c('transport', {
|
|
|
|
ufrag: $(this).attr('ufrag'),
|
|
|
|
pwd: $(this).attr('pwd'),
|
|
|
|
xmlns: $(this).attr('xmlns')
|
|
|
|
});
|
|
|
|
|
|
|
|
$(this).find('>candidate').each(function () {
|
|
|
|
/* not yet
|
|
|
|
if (this.getAttribute('protocol') == 'tcp' && this.getAttribute('port') == 0) {
|
|
|
|
// chrome generates TCP candidates with port 0
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
var line = SDPUtil.candidateFromJingle(this);
|
|
|
|
change.c('candidate', SDPUtil.candidateToJingle(line)).up();
|
|
|
|
});
|
|
|
|
change.up(); // end of transport
|
|
|
|
});
|
2014-05-08 09:26:15 +00:00
|
|
|
change.up(); // end of channel/sctpconnection
|
2013-12-16 11:22:23 +00:00
|
|
|
change.up(); // end of content
|
|
|
|
});
|
|
|
|
// FIXME: need to check if there is at least one candidate when filtering TCP ones
|
|
|
|
this.connection.sendIQ(change,
|
|
|
|
function (res) {
|
|
|
|
console.log('got result');
|
|
|
|
},
|
|
|
|
function (err) {
|
2014-03-12 15:08:24 +00:00
|
|
|
console.error('got error', err);
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// send our own candidate to the bridge
|
|
|
|
ColibriFocus.prototype.sendIceCandidate = function (candidate) {
|
2014-02-24 20:13:04 +00:00
|
|
|
var self = this;
|
2013-12-16 11:22:23 +00:00
|
|
|
//console.log('candidate', candidate);
|
|
|
|
if (!candidate) {
|
|
|
|
console.log('end of candidates');
|
|
|
|
return;
|
|
|
|
}
|
2014-02-24 20:13:04 +00:00
|
|
|
if (this.drip_container.length === 0) {
|
|
|
|
// start 20ms callout
|
2014-07-20 06:01:23 +00:00
|
|
|
window.setTimeout(
|
|
|
|
function () {
|
|
|
|
if (self.drip_container.length === 0) return;
|
|
|
|
self.sendIceCandidates(self.drip_container);
|
|
|
|
self.drip_container = [];
|
|
|
|
},
|
|
|
|
20);
|
2014-02-24 20:13:04 +00:00
|
|
|
}
|
|
|
|
this.drip_container.push(candidate);
|
2014-02-03 18:40:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// sort and send multiple candidates
|
|
|
|
ColibriFocus.prototype.sendIceCandidates = function (candidates) {
|
|
|
|
var self = this;
|
2013-12-16 11:22:23 +00:00
|
|
|
var mycands = $iq({to: this.bridgejid, type: 'set'});
|
|
|
|
mycands.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid});
|
2014-02-03 18:40:10 +00:00
|
|
|
// FIXME: multi-candidate logic is taken from strophe.jingle, should be refactored there
|
|
|
|
var localSDP = new SDP(this.peerconnection.localDescription.sdp);
|
2014-05-08 09:26:15 +00:00
|
|
|
for (var mid = 0; mid < localSDP.media.length; mid++)
|
|
|
|
{
|
2014-02-03 18:40:10 +00:00
|
|
|
var cands = candidates.filter(function (el) { return el.sdpMLineIndex == mid; });
|
2014-05-08 09:26:15 +00:00
|
|
|
if (cands.length > 0)
|
|
|
|
{
|
|
|
|
var name = cands[0].sdpMid;
|
|
|
|
mycands.c('content', {name: name });
|
|
|
|
if (name !== 'data')
|
|
|
|
{
|
|
|
|
mycands.c('channel', {
|
|
|
|
id: $(this.mychannel[cands[0].sdpMLineIndex]).attr('id'),
|
|
|
|
endpoint: $(this.mychannel[cands[0].sdpMLineIndex]).attr('endpoint'),
|
|
|
|
expire: self.channelExpire
|
|
|
|
});
|
2014-07-31 04:09:38 +00:00
|
|
|
if (config.useRtcpMux) {
|
|
|
|
mycands.c('rtcp-mux').up();
|
|
|
|
}
|
|
|
|
|
2014-05-08 09:26:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mycands.c('sctpconnection', {
|
|
|
|
endpoint: $(this.mychannel[cands[0].sdpMLineIndex]).attr('endpoint'),
|
|
|
|
port: $(this.mychannel[cands[0].sdpMLineIndex]).attr('port'),
|
|
|
|
expire: self.channelExpire
|
|
|
|
});
|
|
|
|
}
|
2014-02-03 18:40:10 +00:00
|
|
|
mycands.c('transport', {xmlns: 'urn:xmpp:jingle:transports:ice-udp:1'});
|
|
|
|
for (var i = 0; i < cands.length; i++) {
|
|
|
|
mycands.c('candidate', SDPUtil.candidateToJingle(cands[i].candidate)).up();
|
|
|
|
}
|
|
|
|
mycands.up(); // transport
|
2014-05-08 09:26:15 +00:00
|
|
|
mycands.up(); // channel / sctpconnection
|
2014-02-03 18:40:10 +00:00
|
|
|
mycands.up(); // content
|
|
|
|
}
|
|
|
|
}
|
2014-02-04 17:24:28 +00:00
|
|
|
console.log('send cands', candidates);
|
2013-12-16 11:22:23 +00:00
|
|
|
this.connection.sendIQ(mycands,
|
|
|
|
function (res) {
|
|
|
|
console.log('got result');
|
|
|
|
},
|
|
|
|
function (err) {
|
2014-03-12 15:08:24 +00:00
|
|
|
console.error('got error', err);
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ColibriFocus.prototype.terminate = function (session, reason) {
|
|
|
|
console.log('remote session terminated from', session.peerjid);
|
|
|
|
var participant = this.peers.indexOf(session.peerjid);
|
|
|
|
if (!this.remotessrc[session.peerjid] || participant == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var ssrcs = this.remotessrc[session.peerjid];
|
|
|
|
for (var i = 0; i < ssrcs.length; i++) {
|
2014-03-12 13:21:26 +00:00
|
|
|
this.peerconnection.enqueueRemoveSsrc(i, ssrcs[i]);
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
// remove from this.peers
|
|
|
|
this.peers.splice(participant, 1);
|
|
|
|
// expire channel on bridge
|
|
|
|
var change = $iq({to: this.bridgejid, type: 'set'});
|
|
|
|
change.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid});
|
|
|
|
for (var channel = 0; channel < this.channels[participant].length; channel++) {
|
2014-05-08 09:26:15 +00:00
|
|
|
var name = channel === 0 ? 'audio' : 'video';
|
|
|
|
if (channel == 2)
|
|
|
|
name = 'data';
|
|
|
|
change.c('content', {name: name});
|
|
|
|
if (name !== 'data')
|
|
|
|
{
|
|
|
|
change.c('channel', {
|
|
|
|
id: $(this.channels[participant][channel]).attr('id'),
|
|
|
|
endpoint: $(this.channels[participant][channel]).attr('endpoint'),
|
|
|
|
expire: '0'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
change.c('sctpconnection', {
|
|
|
|
endpoint: $(this.channels[participant][channel]).attr('endpoint'),
|
|
|
|
expire: '0'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
change.up(); // end of channel/sctpconnection
|
2013-12-16 11:22:23 +00:00
|
|
|
change.up(); // end of content
|
|
|
|
}
|
|
|
|
this.connection.sendIQ(change,
|
|
|
|
function (res) {
|
|
|
|
console.log('got result');
|
|
|
|
},
|
|
|
|
function (err) {
|
2014-03-12 15:08:24 +00:00
|
|
|
console.error('got error', err);
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
// and remove from channels
|
|
|
|
this.channels.splice(participant, 1);
|
|
|
|
|
|
|
|
// tell everyone about the ssrcs to be removed
|
|
|
|
var sdp = new SDP('');
|
|
|
|
var localSDP = new SDP(this.peerconnection.localDescription.sdp);
|
|
|
|
var contents = SDPUtil.find_lines(localSDP.raw, 'a=mid:').map(SDPUtil.parse_mid);
|
|
|
|
for (var j = 0; j < ssrcs.length; j++) {
|
|
|
|
sdp.media[j] = 'a=mid:' + contents[j] + '\r\n';
|
|
|
|
sdp.media[j] += ssrcs[j];
|
2014-03-12 13:21:26 +00:00
|
|
|
this.peerconnection.enqueueRemoveSsrc(j, ssrcs[j]);
|
2013-12-16 11:22:23 +00:00
|
|
|
}
|
2014-03-13 12:22:54 +00:00
|
|
|
this.sendSSRCUpdate(sdp.getMediaSsrcMap(), session.peerjid, false);
|
2013-12-16 11:22:23 +00:00
|
|
|
|
|
|
|
delete this.remotessrc[session.peerjid];
|
|
|
|
this.modifySources();
|
|
|
|
};
|
2014-05-11 22:41:58 +00:00
|
|
|
|
|
|
|
ColibriFocus.prototype.sendTerminate = function (session, reason, text) {
|
|
|
|
var term = $iq({to: session.peerjid, type: 'set'})
|
|
|
|
.c('jingle',
|
|
|
|
{xmlns: 'urn:xmpp:jingle:1',
|
|
|
|
action: 'session-terminate',
|
|
|
|
initiator: session.me,
|
|
|
|
sid: session.sid})
|
|
|
|
.c('reason')
|
|
|
|
.c(reason || 'success');
|
|
|
|
|
|
|
|
if (text) {
|
|
|
|
term.up().c('text').t(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.connection.sendIQ(term,
|
|
|
|
function () {
|
|
|
|
if (!session)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (session.peerconnection) {
|
|
|
|
session.peerconnection.close();
|
|
|
|
session.peerconnection = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
session.terminate();
|
|
|
|
var ack = {};
|
|
|
|
ack.source = 'terminate';
|
|
|
|
$(document).trigger('ack.jingle', [session.sid, ack]);
|
|
|
|
},
|
|
|
|
function (stanza) {
|
|
|
|
var error = ($(stanza).find('error').length) ? {
|
|
|
|
code: $(stanza).find('error').attr('code'),
|
|
|
|
reason: $(stanza).find('error :first')[0].tagName,
|
|
|
|
}:{};
|
|
|
|
$(document).trigger('ack.jingle', [self.sid, error]);
|
|
|
|
},
|
|
|
|
10000);
|
|
|
|
if (this.statsinterval !== null) {
|
|
|
|
window.clearInterval(this.statsinterval);
|
|
|
|
this.statsinterval = null;
|
|
|
|
}
|
2014-07-01 14:02:34 +00:00
|
|
|
};
|
2014-07-03 14:35:47 +00:00
|
|
|
|
|
|
|
ColibriFocus.prototype.setRTCPTerminationStrategy = function (strategyFQN) {
|
|
|
|
var self = this;
|
|
|
|
var strategyIQ = $iq({to: this.bridgejid, type: 'set'});
|
|
|
|
strategyIQ.c('conference', {
|
|
|
|
xmlns: 'http://jitsi.org/protocol/colibri',
|
|
|
|
id: this.confid,
|
|
|
|
});
|
|
|
|
|
|
|
|
strategyIQ.c('rtcp-termination-strategy', {name: strategyFQN });
|
|
|
|
|
|
|
|
strategyIQ.c('content', {name: "video"});
|
|
|
|
strategyIQ.up(); // end of content
|
|
|
|
|
|
|
|
console.log('setting RTCP termination strategy', strategyFQN);
|
|
|
|
this.connection.sendIQ(strategyIQ,
|
|
|
|
function (res) {
|
|
|
|
console.log('got result');
|
|
|
|
},
|
|
|
|
function (err) {
|
|
|
|
console.error('got error', err);
|
|
|
|
}
|
|
|
|
);
|
2014-07-15 22:36:51 +00:00
|
|
|
};
|
2014-07-03 14:35:47 +00:00
|
|
|
|
2014-07-17 20:20:36 +00:00
|
|
|
/**
|
|
|
|
* Sets the default value of the channel last-n attribute in this conference and
|
|
|
|
* updates/patches the existing channels.
|
|
|
|
*/
|
|
|
|
ColibriFocus.prototype.setChannelLastN = function (channelLastN) {
|
|
|
|
if (('number' === typeof(channelLastN))
|
|
|
|
&& (this.channelLastN !== channelLastN))
|
|
|
|
{
|
|
|
|
this.channelLastN = channelLastN;
|
|
|
|
|
|
|
|
// Update/patch the existing channels.
|
2014-07-20 06:01:23 +00:00
|
|
|
var patch = $iq({ to: this.bridgejid, type: 'set' });
|
2014-07-17 20:20:36 +00:00
|
|
|
|
|
|
|
patch.c(
|
|
|
|
'conference',
|
2014-07-20 06:01:23 +00:00
|
|
|
{ xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid });
|
|
|
|
patch.c('content', { name: 'video' });
|
2014-07-17 20:20:36 +00:00
|
|
|
patch.c(
|
|
|
|
'channel',
|
|
|
|
{
|
2014-07-20 06:01:23 +00:00
|
|
|
id: $(this.mychannel[1 /* video */]).attr('id'),
|
|
|
|
'last-n': this.channelLastN
|
2014-07-17 20:20:36 +00:00
|
|
|
});
|
|
|
|
patch.up(); // end of channel
|
|
|
|
for (var p = 0; p < this.channels.length; p++)
|
|
|
|
{
|
|
|
|
patch.c(
|
|
|
|
'channel',
|
|
|
|
{
|
2014-07-20 06:01:23 +00:00
|
|
|
id: $(this.channels[p][1 /* video */]).attr('id'),
|
|
|
|
'last-n': this.channelLastN
|
2014-07-17 20:20:36 +00:00
|
|
|
});
|
|
|
|
patch.up(); // end of channel
|
|
|
|
}
|
|
|
|
this.connection.sendIQ(
|
|
|
|
patch,
|
|
|
|
function (res) {
|
2014-07-20 06:01:23 +00:00
|
|
|
console.info('Set channel last-n succeeded:', res);
|
2014-07-17 20:20:36 +00:00
|
|
|
},
|
|
|
|
function (err) {
|
2014-07-20 06:01:23 +00:00
|
|
|
console.error('Set channel last-n failed:', err);
|
2014-07-17 20:20:36 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|