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 Nov 13, 2013
1 parent e67b5a9 commit add769d
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 @@ -72,7 +72,6 @@ UA = function(configuration) {

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

//User actions outside any session/dialog (MESSAGE)
this.applicants = {};
Expand Down Expand Up @@ -165,6 +164,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 @@ -199,7 +201,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 @@ -275,10 +277,8 @@ UA.prototype.stop = function() {
}

// Close registrator
if(this.registrator) {
this.logger.log('closing registrator');
this.registrator.close();
}
this.logger.log('closing registrator');
this.registrator.close();

// Run _terminate_ on every Session
for(session in this.sessions) {
Expand Down Expand Up @@ -466,14 +466,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 @@ -712,9 +705,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 add769d

Please sign in to comment.