Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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.retryMaxDelay,
maxRetries: self._connection.options.maxRetries,
});

connect();
Expand Down Expand Up @@ -478,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.
Expand Down Expand Up @@ -594,7 +603,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
Expand All @@ -603,7 +612,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);
Expand Down