Skip to content

Commit

Permalink
Fix #164. Initialize 'registrator' in the 'UA' constructor. Thanks @n…
Browse files Browse the repository at this point in the history
…ilsonfreitas

- registrator is an internal UA element which must be initializated in the constructor
  • Loading branch information
jmillan committed Sep 27, 2013
1 parent bb935c4 commit 60739ee
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ UA = function(configuration) {

this.configuration = {};
this.dialogs = {};
this.registrator = null;

//User actions outside any session/dialog (MESSAGE)
this.applicants = {};
Expand Down Expand Up @@ -106,6 +105,9 @@ UA = function(configuration) {
this.error = C.CONFIGURATION_ERROR;
throw e;
}

// Initialize registrator
this.registrator = new JsSIP.Registrator(this);
};
UA.prototype = new JsSIP.EventEmitter();

Expand Down Expand Up @@ -139,7 +141,7 @@ UA.prototype.unregister = function(options) {
* @param {Boolean}
*/
UA.prototype.isRegistered = function() {
if(this.registrator && this.registrator.registered) {
if(this.registrator.registered) {
return true;
} else {
return false;
Expand Down Expand Up @@ -208,10 +210,8 @@ UA.prototype.stop = function() {
}

// Close registrator
if(this.registrator) {
console.log(LOG_PREFIX +'closing registrator');
this.registrator.close();
}
console.log(LOG_PREFIX +'closing registrator');
this.registrator.close();

// Run _terminate_ on every Session
for(session in this.sessions) {
Expand Down Expand Up @@ -374,14 +374,7 @@ UA.prototype.onTransportConnected = function(transport) {
});

if(this.configuration.register) {
if(this.registrator) {
this.registrator.onTransportConnected();
} else {
this.registrator = new JsSIP.Registrator(this, transport);
this.register();
}
} else if (!this.registrator) {
this.registrator = new JsSIP.Registrator(this, transport);
this.registrator.onTransportConnected();
}
};

Expand Down Expand Up @@ -599,9 +592,7 @@ UA.prototype.closeSessionsOnTransportError = function() {
this.sessions[idx].onTransportError();
}
// Call registrator _onTransportClosed_
if(this.registrator){
this.registrator.onTransportClosed();
}
this.registrator.onTransportClosed();
};

UA.prototype.recoverTransport = function(ua) {
Expand Down

0 comments on commit 60739ee

Please sign in to comment.