Starts to abstract JingleSession.

This commit is contained in:
Boris Grozev 2015-08-03 13:32:29 -05:00
parent deaff6af5b
commit baf720c553
3 changed files with 28 additions and 7 deletions

View File

@ -0,0 +1,11 @@
/*
* JingleSession provides an API to manage a single Jingle session. We will
* have different implementations depending on the underlying interface used
* (i.e. WebRTC and ORTC) and here we hold the code common to all of them.
*/
function JingleSession() {
// dripping is sending trickle candidates not one-by-one
this.usedrip = true;
}
module.exports = JingleSession;

View File

@ -1,4 +1,5 @@
/* jshint -W117 */ /* jshint -W117 */
var JingleSession = require("./JingleSession");
var TraceablePeerConnection = require("./TraceablePeerConnection"); var TraceablePeerConnection = require("./TraceablePeerConnection");
var SDPDiffer = require("./SDPDiffer"); var SDPDiffer = require("./SDPDiffer");
var SDPUtil = require("./SDPUtil"); var SDPUtil = require("./SDPUtil");
@ -11,6 +12,7 @@ var SSRCReplacement = require("./LocalSSRCReplacement");
// Jingle stuff // Jingle stuff
function JingleSessionPC(me, sid, connection, service, eventEmitter) { function JingleSessionPC(me, sid, connection, service, eventEmitter) {
JingleSession.call(this, me, sid, connection, service, eventEmitter);
this.me = me; this.me = me;
this.sid = sid; this.sid = sid;
this.connection = connection; this.connection = connection;
@ -33,7 +35,6 @@ function JingleSessionPC(me, sid, connection, service, eventEmitter) {
this.usetrickle = true; this.usetrickle = true;
this.usepranswer = false; // early transport warmup -- mind you, this might fail. depends on webrtc issue 1718 this.usepranswer = false; // early transport warmup -- mind you, this might fail. depends on webrtc issue 1718
this.usedrip = false; // dripping is sending trickle candidates not one-by-one
this.hadstuncandidate = false; this.hadstuncandidate = false;
this.hadturncandidate = false; this.hadturncandidate = false;
@ -65,6 +66,17 @@ function JingleSessionPC(me, sid, connection, service, eventEmitter) {
// stable and the ice connection state is connected. // stable and the ice connection state is connected.
this.modifySourcesQueue.pause(); this.modifySourcesQueue.pause();
} }
JingleSessionPC.prototype = JingleSession.prototype;
JingleSessionPC.prototype.constructor = JingleSessionPC;
JingleSessionPC.prototype.setOffer = function(offer) {
this.setRemoteDescription(offer, 'offer');
};
JingleSessionPC.prototype.setAnswer = function(answer) {
this.setRemoteDescription(answer, 'answer');
};
JingleSessionPC.prototype.updateModifySourcesQueue = function() { JingleSessionPC.prototype.updateModifySourcesQueue = function() {
var signalingState = this.peerconnection.signalingState; var signalingState = this.peerconnection.signalingState;
@ -339,7 +351,6 @@ JingleSessionPC.prototype.sendIceCandidate = function (candidate) {
initiator: this.initiator, initiator: this.initiator,
sid: this.sid}); sid: this.sid});
this.localSDP = new SDP(this.peerconnection.localDescription.sdp); this.localSDP = new SDP(this.peerconnection.localDescription.sdp);
var self = this;
var sendJingle = function (ssrc) { var sendJingle = function (ssrc) {
if(!ssrc) if(!ssrc)
ssrc = {}; ssrc = {};
@ -368,7 +379,7 @@ JingleSessionPC.prototype.sendIceCandidate = function (candidate) {
JingleSessionPC.onJingleError(self.sid, error); JingleSessionPC.onJingleError(self.sid, error);
}, },
10000); 10000);
} };
sendJingle(); sendJingle();
} }
this.lasticecandidate = true; this.lasticecandidate = true;

View File

@ -112,14 +112,14 @@ module.exports = function(XMPP, eventEmitter) {
sess.initiate(fromJid, false); sess.initiate(fromJid, false);
// FIXME: setRemoteDescription should only be done when this call is to be accepted // FIXME: setRemoteDescription should only be done when this call is to be accepted
sess.setRemoteDescription($(iq).find('>jingle'), 'offer'); sess.setOffer($(iq).find('>jingle'));
this.sessions[sess.sid] = sess; this.sessions[sess.sid] = sess;
this.jid2session[sess.peerjid] = sess; this.jid2session[sess.peerjid] = sess;
// the callback should either // the callback should either
// .sendAnswer and .accept // .sendAnswer and .accept
// or .sendTerminate -- not necessarily synchronus // or .sendTerminate -- not necessarily synchronous
// TODO: do we check activecall == null? // TODO: do we check activecall == null?
this.connection.jingle.activecall = sess; this.connection.jingle.activecall = sess;
@ -129,12 +129,11 @@ module.exports = function(XMPP, eventEmitter) {
// TODO: check affiliation and/or role // TODO: check affiliation and/or role
console.log('emuc data for', sess.peerjid, console.log('emuc data for', sess.peerjid,
this.connection.emuc.members[sess.peerjid]); this.connection.emuc.members[sess.peerjid]);
sess.usedrip = true; // not-so-naive trickle ice
sess.sendAnswer(); sess.sendAnswer();
sess.accept(); sess.accept();
break; break;
case 'session-accept': case 'session-accept':
sess.setRemoteDescription($(iq).find('>jingle'), 'answer'); sess.setAnswer($(iq).find('>jingle'));
sess.accept(); sess.accept();
$(document).trigger('callaccepted.jingle', [sess.sid]); $(document).trigger('callaccepted.jingle', [sess.sid]);
break; break;