Skip to content

Commit 26ccf39

Browse files
feat: expose reconnection retries
1 parent c2e516a commit 26ccf39

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/client.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var _utils = require('./utils.js');
4040
* @prop {Object} _instanceListeners - array of instance objects for
4141
* instances that registered for scoped events keyed by event type
4242
*/
43-
function Client(baseUrl, user, pass) {
43+
function Client(baseUrl, user, pass, options) {
4444
var self = this;
4545
events.EventEmitter.call(self);
4646

@@ -55,6 +55,10 @@ function Client(baseUrl, user, pass) {
5555
* @prop {string} hostname
5656
* @prop {string} user - username for ARI instance
5757
* @prop {string} pass - password for ARI instance
58+
* @prop {Object} options - options for ARI instance
59+
* @prop {number} options.maxRetries - maximum number of retries
60+
* @prop {number} options.retryDelay - delay between retries
61+
* @prop {number} options.retryMaxDelay - maximum delay between retries
5862
*/
5963
self._connection = {
6064
protocol: parsedUrl.protocol,
@@ -63,7 +67,8 @@ function Client(baseUrl, user, pass) {
6367
// support optional path prefix in asterisk http.conf
6468
prefix: parsedUrl.pathname === '/' ? '' : parsedUrl.pathname,
6569
user: user,
66-
pass: pass
70+
pass: pass,
71+
options: options || {}
6772
};
6873

6974
// Keep track of instance event listeners. once true means that the callback
@@ -349,7 +354,9 @@ Client.prototype.start = function (apps, subscribeAll, callback) {
349354
}
350355

351356
var retry = backoff.create({
352-
delay: 100
357+
delay: self._connection.options.retryDelay || 100,
358+
maxDelay: self._connection.options.maxDelay,
359+
maxRetries: self._connection.options.maxRetries,
353360
});
354361

355362
connect();

0 commit comments

Comments
 (0)