Skip to content
Permalink
Browse files

Fix #163. Stop transport revocery on UA.stop().

- 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 caf20f94fe270110cf69590a85502b5c05e6f9e5
Showing with 23 additions and 20 deletions.
  1. +18 −19 src/EventEmitter.js
  2. +5 −1 src/UA.js
@@ -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;
@@ -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);
},

/**
@@ -85,6 +85,7 @@ UA = function(configuration) {
};

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

/**
* Load configuration
@@ -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');
@@ -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);

0 comments on commit caf20f9

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