marcelog / Nami

Asterisk manager interface (ami) client for nodejs
http://marcelog.github.com/Nami
Apache License 2.0
99 stars 59 forks source link

Allow masking events on Login when opening the connection #52

Open adaxi opened 6 years ago

adaxi commented 6 years ago

I have an Asterisk instance that generates a great amount of events. The manager is configured to authorize all events:

read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
write = system,call,agent,user,config,command,reporting,originate,message

My application connects using the Asterisk Management Interface (AMI) but at startup I don't want to be flooded by all events generated by Asterisk. I want to be able to select which events should be transmitted.

Using the Events command I can decide which events should be transmitted. Unfortunately from the moment I login until the moment I submit this command my application is flooded by events.

A non-documented feature of the login action allows us to set the event mask that we are interested in at Login.

This pull request allows you to pass an array of events:

var namiConfig = {
    host: process.argv[2],
    port: process.argv[3],
    username: process.argv[4],
    secret: process.argv[5],
    events: ['system', 'call']
};

var nami = new namiLib.Nami(namiConfig);

When the events option is omitted Nami does not set the event mask on the login action.

Similar to #13 but less intrusive.

adaxi commented 5 years ago

Looks like the same was implemented in the PHP version.