Skip to content

Commit

Permalink
Enhance in-dialog request management
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillan committed Jan 20, 2013
1 parent ce55b78 commit 69fbdbd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
11 changes: 5 additions & 6 deletions src/InDialogRequestSender.js
Expand Up @@ -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);
}
};
60 changes: 39 additions & 21 deletions src/Session.js
Expand Up @@ -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();
};

Expand Down Expand Up @@ -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);
Expand All @@ -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') {
Expand Down

0 comments on commit 69fbdbd

Please sign in to comment.