@@ -146,11 +146,13 @@ module.exports = function(Cam) {
146
146
147
147
/**
148
148
* Renew pull-point subscription
149
- * @param {options } callback
150
- * @param {function } callback
149
+ * @param {Object|Function } [options]
150
+ * @param {Function } callback
151
151
*/
152
-
153
152
Cam . prototype . renew = function ( options , callback ) {
153
+ if ( ! callback ) {
154
+ callback = options ;
155
+ }
154
156
let urlAddress = null ;
155
157
let subscriptionId = null ;
156
158
try {
@@ -335,9 +337,7 @@ module.exports = function(Cam) {
335
337
* @private
336
338
*/
337
339
function _terminationTime ( response ) {
338
- let result = new Date ( Date . now ( ) - response . currentTime . getTime ( ) + response . terminationTime . getTime ( ) ) ;
339
- // console.log("Events: Termination Time is " + result);
340
- return result ;
340
+ return new Date ( Date . now ( ) - response . currentTime . getTime ( ) + response . terminationTime . getTime ( ) ) ;
341
341
}
342
342
343
343
/**
@@ -351,12 +351,15 @@ module.exports = function(Cam) {
351
351
// if there is no pull-point subscription or it has expired, create new subscription
352
352
this . createPullPointSubscription ( function ( error ) {
353
353
if ( ! error ) {
354
+ delete this . _eventReconnectms ;
354
355
this . _eventPull ( ) ;
355
- } else if ( typeof error === 'object' && retryErrorCodes . includes ( error . code ) ) {
356
- // connection reset on creation - restart Event loop for pullMessages request
357
- this . _restartEventRequest ( ) ;
356
+ } else {
357
+ this . emit ( 'eventsError' , error ) ;
358
+ if ( typeof error === 'object' && retryErrorCodes . includes ( error . code ) ) {
359
+ // connection reset on creation - restart Event loop for pullMessages request
360
+ this . _restartEventRequest ( ) ;
361
+ }
358
362
}
359
- console . log ( "Error: " + error . code ) ;
360
363
} . bind ( this ) ) ;
361
364
} else {
362
365
this . _eventPull ( ) ;
@@ -376,10 +379,10 @@ module.exports = function(Cam) {
376
379
if ( this . listeners ( 'event' ) . length && this . events . subscription ) { // check for event listeners, if zero, or no subscription then stop pulling
377
380
this . pullMessages ( {
378
381
messageLimit : this . events . messageLimit
379
- } , function ( err , data , xml ) {
380
- if ( ! err ) {
382
+ } , function ( error , data , xml ) {
383
+ if ( ! error ) {
384
+ delete this . _eventReconnectms ;
381
385
if ( data . notificationMessage ) {
382
- this . _eventReconnectms = 0 ;
383
386
if ( ! Array . isArray ( data . notificationMessage ) ) {
384
387
data . notificationMessage = [ data . notificationMessage ] ;
385
388
}
@@ -395,14 +398,15 @@ module.exports = function(Cam) {
395
398
this . events . terminationTime = _terminationTime ( data ) ; // Axis does not increment the termination time. Use RENEW. Vista returns a termination time with the time now (ie we have expired) even if there was still time left over. Use RENEW
396
399
397
400
// Axis cameras require us to Rewew the Pull Point Subscription
398
- this . renew ( { } , function ( err , data ) {
399
- if ( ! err ) {
401
+ this . renew ( { } , function ( error , data ) {
402
+ if ( ! error ) {
400
403
this . events . terminationTime = _terminationTime ( data ) ;
401
404
}
402
405
this . _eventRequest ( ) ; // go around the loop again, once the RENEW has completed (and terminationTime updated)
403
406
} ) ;
404
407
} else {
405
- if ( typeof err === 'object' && err . code === 'ECONNRESET' ) {
408
+ this . emit ( 'eventsError' , error ) ;
409
+ if ( typeof error === 'object' && retryErrorCodes . includes ( error . code ) ) {
406
410
// connection reset - restart Event loop for pullMessages request
407
411
this . _restartEventRequest ( ) ;
408
412
} else {
0 commit comments