Skip to content

Commit

Permalink
Fix #163. Stop transport revocery on UA.stop().
Browse files Browse the repository at this point in the history
- EventEmitter does not emit in the same execution iteration to avoid inestability. Thanks @ibc
  • Loading branch information
jmillan committed Sep 27, 2013
1 parent 60739ee commit caf20f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
37 changes: 18 additions & 19 deletions src/EventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ EventEmitter.prototype = {
* @param {Array} args
*/
emit: function(event, sender, data) {
var listeners, length,
idx=0;
var listeners, length,
emitter = this;

if (!this.checkEvent(event)) {
return;
Expand All @@ -156,23 +156,22 @@ EventEmitter.prototype = {

var e = new JsSIP.Event(event, sender, data);

if (e) {
for (idx; idx<length; idx++) {
listeners[idx].apply(null, [e]);
}
} else {
for (idx; idx<length; idx++) {
listeners[idx].call();
}
}

// Check whether _once_ was defined for the event
idx = this.onceNotFired.indexOf(event);

if (idx !== -1) {
this.onceNotFired.splice(idx,1);
this.events[event].shift();
}
window.setTimeout(
function(){
var idx=0;

for (idx; idx<length; idx++) {
listeners[idx].call(null, e);
}

// Check whether _once_ was defined for the event
idx = emitter.onceNotFired.indexOf(event);

if (idx !== -1) {
emitter.onceNotFired.splice(idx,1);
emitter.events[event].shift();
}
}, 0);
},

/**
Expand Down
6 changes: 5 additions & 1 deletion src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ UA = function(configuration) {
};

this.transportRecoverAttempts = 0;
this.transportRecoveryTimer = null;

/**
* Load configuration
Expand Down Expand Up @@ -208,6 +209,9 @@ UA.prototype.stop = function() {
console.warn('UA already closed');
return;
}

// Clear transportRecoveryTimer
window.clearTimeout(this.transportRecoveryTimer);

// Close registrator
console.log(LOG_PREFIX +'closing registrator');
Expand Down Expand Up @@ -619,7 +623,7 @@ UA.prototype.recoverTransport = function(ua) {

console.log(LOG_PREFIX + 'next connection attempt in '+ nextRetry +' seconds');

window.setTimeout(
this.transportRecoveryTimer = window.setTimeout(
function(){
ua.transportRecoverAttempts = count + 1;
new JsSIP.Transport(ua, server);
Expand Down

0 comments on commit caf20f9

Please sign in to comment.