From 67bf7c751b14a75fa7e95adac6fd7c7d89f83662 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 6 Jan 2024 16:57:25 -0800 Subject: [PATCH 1/3] fix unsubscribe signature error --- lib/events.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/events.js b/lib/events.js index 148d631..9abc422 100644 --- a/lib/events.js +++ b/lib/events.js @@ -383,7 +383,7 @@ module.exports = function(Cam) { }); } else { // there was an error pulling the message - this.unsubscribe({}, function(_err,_data,_xml) { + this.unsubscribe(function(_err,_data,_xml) { // once the unsubsribe has completed (even if it failed), go around the loop again this._eventRequest(); }); From fbe9731c7c0246e25c39e90a81d91a231fbb5ab8 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sun, 7 Jan 2024 20:03:19 -0800 Subject: [PATCH 2/3] events not delivering unsubscribe error on callback --- lib/events.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/events.js b/lib/events.js index 9abc422..03a1310 100644 --- a/lib/events.js +++ b/lib/events.js @@ -154,7 +154,10 @@ module.exports = function(Cam) { try { urlAddress = this.events.subscription.subscriptionReference.address; } catch (e) { - throw new Error('You should create pull-point subscription first!'); + if (callback && callback.call) { + callback.call(this, new Error('You should create pull-point subscription first!')); + } + return; } try { @@ -225,7 +228,10 @@ module.exports = function(Cam) { try { urlAddress = this.events.subscription.subscriptionReference.address; } catch (e) { - throw new Error('You should create pull-point subscription first!'); + if (callback && callback.call) { + callback.call(this, new Error('You should create pull-point subscription first!')); + } + return; } try { @@ -273,7 +279,10 @@ module.exports = function(Cam) { try { urlAddress = this.events.subscription.subscriptionReference.address; } catch (e) { - throw new Error('You should create pull-point subscription first!'); + if (callback && callback.call) { + callback.call(this, new Error('You should create pull-point subscription first!')); + } + return; } try { From 5641b572c4ed0d993bb592ac118ea0c2a5a008f5 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Tue, 9 Jan 2024 14:30:02 -0800 Subject: [PATCH 3/3] preserve listeners during resubscribe --- lib/events.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/events.js b/lib/events.js index 03a1310..6466ac3 100644 --- a/lib/events.js +++ b/lib/events.js @@ -273,7 +273,7 @@ module.exports = function(Cam) { * @param {Cam~PullMessagesResponse} callback * @throws {Error} {@link Cam#events.subscription} must exists */ - Cam.prototype.unsubscribe = function(callback) { + Cam.prototype.unsubscribe = function(callback, preserveListeners) { let urlAddress = null; let subscriptionId = null; try { @@ -312,7 +312,9 @@ module.exports = function(Cam) { body: sendXml }, function(err, res, xml) { if (!err) { - this.removeAllListeners('event'); // We can subscribe again only if there is no 'event' listener + if (!preserveListeners) { + this.removeAllListeners('event'); // We can subscribe again only if there is no 'event' listener + } var data = linerase(res).unsubscribeResponse; } if (callback && callback.call) { @@ -395,7 +397,7 @@ module.exports = function(Cam) { this.unsubscribe(function(_err,_data,_xml) { // once the unsubsribe has completed (even if it failed), go around the loop again this._eventRequest(); - }); + }, true); } }.bind(this)); } else {