Giter Site home page Giter Site logo

asterisk-ami-events-stream's Introduction

Asterisk AMI Events Stream for NodeJS (ES2015)

Build Status Coverage Status Code Climate npm version

This is a transform stream for AMI socket. This stream has a three custom events:

This library is a part of Asterisk's AMI Client library.

  • amiEvent - fired when event was receive. Handler of this event receives AMI event object.
  • amiResponse - fired when response was receive. Handler of this event receives AMI response object.
  • amiAction - fired when action was receive. Handler of this event receives AMI action object.

If response from AMI not has structure like this:

<KEY>: <VALUE>CRLF
<KEY>: <VALUE>CRLF
...
<KEY>: <VALUE>CRLFx2

In above case, body of this response will be available in $content property of response object.

Install

$ npm i asterisk-ami-events-stream

NodeJS versions

support >=4.0.0

Usage

const net = require('net');
const amiUtils = require('asterisk-ami-event-utils');
const AmiEventsStream = require('asterisk-ami-events-stream');
const eventsStream = new AmiEventsStream();

const amiSocket = net.connect({port: 5038}, () => {
        console.log('connected to asterisk ami!');
        amiSocket.write(amiUtils.fromObject({
                Action: 'login',
                Username: 'login',
                Secret: 'password',
                Events: 'on'
            }));
        amiSocket.pipe(eventsStream);
    });
    
amiSocket
    .on('end', () => {
        amiSocket.unpipe(eventsStream);
        console.log('disconnected from asterisk ami');
    })
    .on('error', error => {
        console.log(error);
        amiSocket.unpipe(eventsStream);
    });

eventsStream
    .on('amiEvent', event => {
        console.log(event);
        amiSocket.end();
    })    
    .on('amiResponse', response => {
        console.log(response);
        amiSocket.end();
    })
    .on('amiAction', action => {
        console.log(action);
        amiSocket.end();
    });    

Examples

For examples, please, see tests ./test/*.

Tests

Tests require Mocha.

mocha ./tests

or with npm

npm test 

Test coverage with Istanbul

npm run coverage

License

Licensed under the MIT License

asterisk-ami-events-stream's People

Contributors

belirafon avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

rvleyden

asterisk-ami-events-stream's Issues

Session beeing Droped / Disconnected

I was wondering if this is by design or possibly a bug that if there is a certain amount of data coming thru the stream i get disconnected. If the System is idle or i only see phone registrations the system is happy. But as soon as i make a call to system and i get multiple messages like VarSet, Newexten, it closes on a VarSet. There is no error or anything so i am not sure how someone could troubleshot the disconnect.

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.