From 26ccf39f1afabc6d8f33f5c0951a86ee6d79c55d Mon Sep 17 00:00:00 2001 From: Mostafa Roshdy Date: Tue, 29 Apr 2025 13:51:19 +0300 Subject: [PATCH 1/4] feat: expose reconnection retries --- lib/client.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/client.js b/lib/client.js index b1eb7e4..4589749 100644 --- a/lib/client.js +++ b/lib/client.js @@ -40,7 +40,7 @@ var _utils = require('./utils.js'); * @prop {Object} _instanceListeners - array of instance objects for * instances that registered for scoped events keyed by event type */ -function Client(baseUrl, user, pass) { +function Client(baseUrl, user, pass, options) { var self = this; events.EventEmitter.call(self); @@ -55,6 +55,10 @@ function Client(baseUrl, user, pass) { * @prop {string} hostname * @prop {string} user - username for ARI instance * @prop {string} pass - password for ARI instance + * @prop {Object} options - options for ARI instance + * @prop {number} options.maxRetries - maximum number of retries + * @prop {number} options.retryDelay - delay between retries + * @prop {number} options.retryMaxDelay - maximum delay between retries */ self._connection = { protocol: parsedUrl.protocol, @@ -63,7 +67,8 @@ function Client(baseUrl, user, pass) { // support optional path prefix in asterisk http.conf prefix: parsedUrl.pathname === '/' ? '' : parsedUrl.pathname, user: user, - pass: pass + pass: pass, + options: options || {} }; // Keep track of instance event listeners. once true means that the callback @@ -349,7 +354,9 @@ Client.prototype.start = function (apps, subscribeAll, callback) { } var retry = backoff.create({ - delay: 100 + delay: self._connection.options.retryDelay || 100, + maxDelay: self._connection.options.maxDelay, + maxRetries: self._connection.options.maxRetries, }); connect(); From f51e3e86f8d18670c75e45441cdfc0b01934529c Mon Sep 17 00:00:00 2001 From: Mostafa Roshdy Date: Tue, 29 Apr 2025 17:27:14 +0300 Subject: [PATCH 2/4] fix:variable naming --- lib/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 4589749..6614016 100644 --- a/lib/client.js +++ b/lib/client.js @@ -355,7 +355,7 @@ Client.prototype.start = function (apps, subscribeAll, callback) { var retry = backoff.create({ delay: self._connection.options.retryDelay || 100, - maxDelay: self._connection.options.maxDelay, + maxDelay: self._connection.options.retryMaxDelay, maxRetries: self._connection.options.maxRetries, }); From b9a0f0185ca198723c9eda863d5251ce3548b7b5 Mon Sep 17 00:00:00 2001 From: Mostafa Roshdy Date: Tue, 29 Apr 2025 18:01:57 +0300 Subject: [PATCH 3/4] fix: pass options arugment to client fn --- lib/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index 6614016..1725147 100644 --- a/lib/client.js +++ b/lib/client.js @@ -601,7 +601,7 @@ Client.prototype.ping = function () { * The callback to be called upon connection * @returns {Q} promise - a promise that will resolve to a client */ -module.exports.connect = function (baseUrl, user, pass, +module.exports.connect = function (baseUrl, user, pass, options, /** * @callback connectCallback * @memberof module:ari-client @@ -610,7 +610,7 @@ module.exports.connect = function (baseUrl, user, pass, */ callback) { - var client = new Client(baseUrl, user, pass); + var client = new Client(baseUrl, user, pass, options); client.setMaxListeners(0); return client._attachApi().asCallback(callback); From 3e44f837936c017c304819840a4559cf84136b7a Mon Sep 17 00:00:00 2001 From: Mostafa Roshdy Date: Tue, 29 Apr 2025 18:11:42 +0300 Subject: [PATCH 4/4] reset retry function with the correct values --- lib/client.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 1725147..bcd92df 100644 --- a/lib/client.js +++ b/lib/client.js @@ -485,7 +485,9 @@ Client.prototype.start = function (apps, subscribeAll, callback) { processingError = false; // reset backoff handler when we successfully connect retry = backoff.create({ - delay: 100 + delay: self._connection.options.retryDelay || 100, + maxDelay: self._connection.options.retryMaxDelay, + maxRetries: self._connection.options.maxRetries, }); self.emit('WebSocketConnected'); // onced, will not be called when an automatic reconnect succeeds.