Coder Social home page Coder Social logo

node-asterisk-ami's Introduction

asterisk-ami

An extremely lightweight Asterisk AMI connector

Build Status

Install

npm install asterisk-ami

Usage

var AsteriskAmi = require('asterisk-ami');
var ami = new AsteriskAmi( { host: 'hostname', username: 'username', password: 'secret' } );

ami.on('ami_data', function(data){
	console.log('AMI DATA', data);
	//decide between Events and non events here and what to do with them, maybe run an event emitter for the ones you care about
});

ami.connect(function(){
	ami.send({action: 'Ping'});//run a callback event when we have connected to the socket
});//connect creates a socket connection and sends the login action

ami.send({action: 'Ping'});

##Events

(AMI Data) These give you AMI specific information

  • ami_login Called when logging into the ami, no data passed back
  • ami_data Called for each event we get back from the AMI, with an object being returned

(net socket events) Use these events to determine the status of the socket connection, as if the socket is disconnected, you would need to add your .on('close') events again, this was a bug in the previous version of asterisk-ami, use these new events instead which will always be called, even if the connection has died and been reconnected.

  • ami_socket_drain
  • ami_socket_error
  • ami_socket_timeout
  • ami_socket_end
  • ami_socket_close
  • ami_socket_unwritable

##methods

.connect(function(){
  console.log('connection to AMI socket successful');
}, function(raw_data){
  console.log('every time data comes back in the socket, this callback is called, useful for recording stats on data', raw_data);
})

.disconnect() //logs out of the AMI and then closes the connection, sets reconnect to false so that it wont try and reconnect

.send({action: 'Ping'}) //send an ami call, pass in a javascript object with the params you want to send the ami

.destroy() //terminates the connection to the ami socket if say disconnect fails, or you've lost connection to the ami and you're not using reconnect: true as a param

Configuration options

AsteriskAmi has preset/configurable options, you can set these via an object passed in to AsteriskAmi

  • port: Port number for Asterisk AMI, default 5038
  • host: Host of Asterisk, default localhost
  • username: Username of Asterisk AMI user, default: username
  • password: Password of Asterisk AMI user, default: password
  • debug: Do you want debugging output to the screen, default: false
  • reconnect: Do you want the ami to reconnect if the connection is dropped, default: false
  • reconnect_after How long to wait to reconnect, in miliseconds, default: 3000
  • events Do we want to recieve AMI events, default: true

NPM Maintainers

The npm module for this library is maintained by:

License

asterisk-ami is licensed under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.