Skip to content
Permalink
Browse files

Enhance in-dialog request management

  • Loading branch information
jmillan committed Jan 20, 2013
1 parent ce55b78 commit 69fbdbde8b537e087cc06690156d2364d2a71300
Showing with 44 additions and 27 deletions.
  1. +5 −6 src/InDialogRequestSender.js
  2. +39 −21 src/Session.js
@@ -22,20 +22,19 @@ JsSIP.InDialogRequestSender.prototype = {

onRequestTimeout: function() {
this.applicant.session.onRequestTimeout();
this.applicant.onRequestTimeout();
},

onTransportError: function() {
this.applicant.session.onTransportError();
this.applicant.onTransportError();
},

receiveResponse: function(response) {
var status_code = response.status_code;

// RFC3261 14.1. Terminate the dialog if a 408 or 481 is received from a re-Invite.
if (status_code === 408 || status_code === 481) {
this.applicant.ended('remote', response, JsSIP.c.causes.IN_DIALOG_408_OR_481);
} else {
this.applicant.receiveResponse(response);
if (response.status_code === 408 || response.status_code === 481) {
this.applicant.session.ended('remote', response, JsSIP.c.causes.IN_DIALOG_408_OR_481);
}
this.applicant.receiveResponse(response);
}
};
@@ -688,13 +688,19 @@ JsSIP.Session.prototype.sendBye = function(reason) {
};


JsSIP.Session.prototype.sendRequest = function(request, receiveResponse) {
var request_sender;

receiveResponse = receiveResponse || function(){};

request_sender = new JsSIP.Session.RequestSender(this, request, receiveResponse);

JsSIP.Session.prototype.sendRequest = function(request) {
var applicant, request_sender,
self = this;

applicant = {
session: self,
request: request,
receiveResponse: function(){},
onRequestTimeout: function(){},
onTransportError: function(){}
};

request_sender = new JsSIP.Session.RequestSender(this, applicant);
request_sender.send();
};

@@ -969,10 +975,10 @@ JsSIP.Session.prototype.sendInitialRequest = function(mediaType) {
/**
* @private
*/
JsSIP.Session.RequestSender = function(session, request, onReceiveResponse) {
JsSIP.Session.RequestSender = function(session, applicant) {
this.session = session;
this.request = request;
this.onReceiveResponse = onReceiveResponse;
this.request = applicant.request;
this.applicant = applicant;
this.reattempt = false;
this.reatemptTimer = null;
this.request_sender = new JsSIP.InDialogRequestSender(this);
@@ -985,26 +991,38 @@ JsSIP.Session.RequestSender.prototype = {
self = this,
status_code = response.status_code;

if (this.session.status !== JsSIP.c.SESSION_TERMINATED) {
if (response.method === JsSIP.c.INVITE && status_code === 491 && !this.reattempt) {
this.request.cseq.value = this.request.dialog.local_seqnum += 1;
this.reatemptTimer = window.setTimeout(
function() {
self.reattempt = true;
self.request_sender.send();
},
this.getReattemptTimeout()
);
if (response.method === JsSIP.c.INVITE && status_code === 491) {
if (!this.reattempt) {
this.request.cseq.value = this.request.dialog.local_seqnum += 1;
this.reatemptTimer = window.setTimeout(
function() {
if (self.session.status !== JsSIP.c.SESSION_TERMINATED) {
self.reattempt = true;
self.request_sender.send();
}
},
this.getReattemptTimeout()
);
} else {
this.onReceiveResponse.call(this.session, response);
this.applicant.receiveResponse(response);
}
} else {
this.applicant.receiveResponse(response);
}
},

send: function() {
this.request_sender.send();
},

onRequestTimeout: function() {
this.applicant.onRequestTimeout();
},

onTransportError: function() {
this.applicant.onTransportError();
},

// RFC3261 14.1
getReattemptTimeout: function() {
if(this.session.direction === 'outgoing') {

0 comments on commit 69fbdbd

Please sign in to comment.
You can’t perform that action at this time.