From 60739ee63fb7edd9f3398c963d58a7613718677f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Fri, 27 Sep 2013 09:56:55 +0200 Subject: [PATCH] Fix #164. Initialize 'registrator' in the 'UA' constructor. Thanks @nilsonfreitas - registrator is an internal UA element which must be initializated in the constructor --- src/UA.js | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/UA.js b/src/UA.js index 412ff5b54..14acc7a55 100644 --- a/src/UA.js +++ b/src/UA.js @@ -68,7 +68,6 @@ UA = function(configuration) { this.configuration = {}; this.dialogs = {}; - this.registrator = null; //User actions outside any session/dialog (MESSAGE) this.applicants = {}; @@ -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(); @@ -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; @@ -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) { @@ -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(); } }; @@ -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) {