An asterisk manager interface client, uses EventEmitter to communicate events, will allow you to send actions, and receive responses (and associated events), and also receive async events from server
For API and docs, check out the homepage at http://marcelog.github.com/Nami
You can also download the distribution and doc from the CI server, at: http://ci.marcelog.name:8080/view/NodeJS/
Nami by itself is just a library that allows your nodejs code to communicate to an Asterisk Manager Interface (AMI). However, it includes a full application useful to monitor an asterisk installation.
You will be able to login, receive asynchronous events, and send actions (also, asynchronously receiving the according response with their optional related events).
This is supported by the Nami class (er.. function) which inherits from EventEmitter, so your application is able to subscribe to the interesting nami events.
namiConnected: Emitted when nami could successfully connect and logged in to an AMI server.
namiConnection: Emitted for all connection related events. Listen to this generic event for the status of the socket connection.
namiConnection(EventName): Emitted for the status of the connection. States include:
Errorevent will emit right before the
Closeevent and includes the error that was thrown. The
Closeevent includes a boolean value (
had_error) if an error was thrown.
namiEvent(EventName): These events are thrown based on the event name received. Let's say nami gets an event named "Dial", "VarSet", or "Hangup". This will emit the events: "namiEventDial", "namiEventVarSet", and "NamiEventHangup".
namiLoginIncorrect: Emitted when the login action fails (wrong password, etc).
namiInvalidPeer: Emitted if nami tried to connect to anything that did not salute like an AMI 1.1, 1.2, or 1.3.
namiRawMessage: Whenever a full message is received from the AMI (delimited by double crlf), this is emitted to invoke the decode routine. After namiRawMessage, the decodification routine runs to properly identify this message as a response, an event that belongs to a response, or an async event from server.
namiRawEvent: Emitted when the decodification routine classified the received message as an async event from server.
namiRawResponse: Emitted when the decodification routine classified the received message as a response to an action.
$ npm install log4js$ npm install nami
-or- Download it from this repo :)
Nami expects a configuration object, very much like this:
var namiConfig =host: "amihost"port: 5038username: "admin"secret: "secret";
$ mkdir testnami$ cd testnami$ npm install log4js$ npm install nami
var nami = new require"nami"NaminamiConfig;namion'namiEvent' ;namion'namiEventDial' ;namion'namiEventVarSet' ;namion'namiEventHangup' ;processon'SIGINT'namiclose;processexit;;namion'namiConnected'namisendCoreShowChannelsActionloggerdebug' ---- Response: ' + utilinspectresponse;;;namiopen;
Use the property 'variables' in the actions:
var action = Status;actionvariables ='var1': 'val1';namisendaction;
See src/index.js for a better example (including how to reconnect when the current connection closes).
That's about it.
See this gist for an example of how to connect to multiple asterisk boxes.