Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Requests. #13

Open
countrdd opened this issue Oct 14, 2020 · 2 comments
Open

Feature Requests. #13

countrdd opened this issue Oct 14, 2020 · 2 comments

Comments

@countrdd
Copy link

First off thanks for this project, very nice.

Is there a way that is could be modified to allow connnecting to multiple AMI's? and adding connection option like time that can be used to define the AMIHOST that the event is coming from?

@countrdd
Copy link
Author

Patch for hostName added to each event/Response.
hostnamepatch.txt

@countrdd
Copy link
Author

Example Connect to Multiple AMI Servers
const AmiClient = require('asterisk-ami-client');
var servers = [];
var boxes = [
{username: 'username', password: 'password', host: 'hostipname', port: 5038, pbxname: 'YHC'},
{username: 'username', password: 'password', host: 'hostipname', port: 5038, pbxname: 'LEI'}
]

let client = new AmiClient({
reconnect: true,
maxAttemptsCount: 60,
attemptsDelay: 3000,
keepAlive: false,
keepAliveDelay: 1000,
addTime: true,

});
for (var j = 0; j < boxes.length; j++) {
(function (i) {
servers[i] = new AmiClient({
reconnect: true,
maxAttemptsCount: 60,
attemptsDelay: 3000,
keepAlive: false,
keepAliveDelay: 1000,
addTime: true,
hostName: boxes[i].pbxname

    });
    servers[i].connect(boxes[i].username, boxes[i].password, {host: boxes[i].host, port: boxes[i].port})
        .then(amiConnection => {

            servers[i]
                .on('connect', () => console.log('connect'))
                .on('event', event => console.log(event))
                // .on('data', chunk => console.log(chunk))
                .on('response', response => console.log(response))
                .on('disconnect', () => console.log('disconnect'))
                .on('reconnection', () => console.log('reconnection'))
                .on('internalError', error => console.log(error))
                .action({
                    Action: 'Ping'
                });

            //setTimeout(() => {
            //    client.disconnect();
            //}, 5000);

        })
        .catch(error => console.log(error));

})(j);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant