@@ -186,7 +186,6 @@ JsSIP.Registrator.prototype = {
186186 extraHeaders = extraHeaders || [ ] ;
187187
188188 this . registered = false ;
189- this . ua . emit ( 'unregistered' , this . ua ) ;
190189
191190 // Clear the registration timer.
192191 window . clearTimeout ( this . registrationTimer ) ;
@@ -216,21 +215,39 @@ JsSIP.Registrator.prototype = {
216215 * @private
217216 */
218217 this . receiveResponse = function ( response ) {
219- console . log ( JsSIP . C . LOG_REGISTRATOR + response . status_code + ' ' + response . reason_phrase + ' received to unregister request' ) ;
218+ var cause ;
219+
220+ switch ( true ) {
221+ case / ^ 1 [ 0 - 9 ] { 2 } $ / . test ( response . status_code ) :
222+ // Ignore provisional responses.
223+ break ;
224+ case / ^ 2 [ 0 - 9 ] { 2 } $ / . test ( response . status_code ) :
225+ this . unregistered ( response ) ;
226+ break ;
227+ default :
228+ cause = JsSIP . Utils . sipErrorCause ( response . status_code ) ;
229+
230+ if ( cause ) {
231+ cause = JsSIP . C . causes [ cause ] ;
232+ } else {
233+ cause = JsSIP . C . causes . SIP_FAILURE_CODE ;
234+ }
235+ this . unregistered ( response , cause ) ;
236+ }
220237 } ;
221238
222239 /**
223240 * @private
224241 */
225242 this . onRequestTimeout = function ( ) {
226- console . log ( JsSIP . C . LOG_REGISTRATOR + 'Request Timeout received for unregister request' ) ;
243+ this . unregistered ( null , JsSIP . C . causes . REQUEST_TIMEOUT ) ;
227244 } ;
228245
229246 /**
230247 * @private
231248 */
232249 this . onTransportError = function ( ) {
233- console . log ( JsSIP . C . LOG_REGISTRATOR + 'Transport Error received for unregister request' ) ;
250+ this . unregistered ( null , JsSIP . C . causes . CONNECTION_ERROR ) ;
234251 } ;
235252
236253 request_sender . send ( ) ;
@@ -242,14 +259,28 @@ JsSIP.Registrator.prototype = {
242259 registrationFailure : function ( response , cause ) {
243260 if ( this . registered ) {
244261 this . registered = false ;
245- this . ua . emit ( 'unregistered' , this . ua ) ;
262+ this . ua . emit ( 'unregistered' , this . ua , {
263+ response : response || null ,
264+ cause : cause
265+ } ) ;
246266 }
247267 this . ua . emit ( 'registrationFailed' , this . ua , {
248268 response : response || null ,
249269 cause : cause
250270 } ) ;
251271 } ,
252272
273+ /**
274+ * @private
275+ */
276+ unregistered : function ( response , cause ) {
277+ this . registered = false ;
278+ this . ua . emit ( 'unregistered' , this . ua , {
279+ response : response || null ,
280+ cause : cause || null
281+ } ) ;
282+ } ,
283+
253284 /**
254285 * @private
255286 */
0 commit comments