diff --git a/src/RTCSession.js b/src/RTCSession.js index ea3603b62..61169f053 100644 --- a/src/RTCSession.js +++ b/src/RTCSession.js @@ -197,6 +197,8 @@ RTCSession.prototype.answer = function(options) { var // run for reply success callback replySucceeded = function() { + var timeout = JsSIP.Timers.T1; + self.status = C.STATUS_WAITING_FOR_ACK; /** @@ -204,27 +206,24 @@ RTCSession.prototype.answer = function(options) { * Response retransmissions cannot be accomplished by transaction layer * since it is destroyed when receiving the first 2xx answer */ - self.timers.invite2xxTimer = window.setTimeout(function invite2xxRetransmission(retransmissions) { - retransmissions = retransmissions || 1; - - var timeout = JsSIP.Timers.T1 * (Math.pow(2, retransmissions)); - - if((retransmissions * JsSIP.Timers.T1) <= JsSIP.Timers.T2) { - retransmissions += 1; + self.timers.invite2xxTimer = window.setTimeout(function invite2xxRetransmission() { + if (self.status !== C.STATUS_WAITING_FOR_ACK) { + return; + } - request.reply(200, null, ['Contact: '+ self.contact], body); + request.reply(200, null, ['Contact: '+ self.contact], body); - self.timers.invite2xxTimer = window.setTimeout( - function() { - invite2xxRetransmission(retransmissions); - }, - timeout - ); - } else { - window.clearTimeout(self.timers.invite2xxTimer); + if (timeout < JsSIP.Timers.T2) { + timeout = timeout * 2; + if (timeout > JsSIP.Timers.T2) { + timeout = JsSIP.Timers.T2; + } } + self.timers.invite2xxTimer = window.setTimeout( + invite2xxRetransmission, timeout + ); }, - JsSIP.Timers.T1 + timeout ); /**