Skip to content

Simple Test & Development Server for Asterisk AMI (NodeJS & ES2015)

License

Notifications You must be signed in to change notification settings

BelirafoN/asterisk-ami-test-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asterisk AMI Test Server

Build Status Coverage Status Code Climate npm version

Install

$ npm i asterisk-ami-test-server

NodeJS versions

support >=4.0.0

Usage

Server

const AmiTestServer = require('asterisk-ami-test-server');
const server = new AmiTestServer({
    maxConnections: 50,
    authTimeout: 30000,
    credentials: {
        username: 'test',
        secret: 'test'
    }
});

server
    .on('listening', () => console.log('listening'))
    .on('connection', authClientsCount => console.log(`authClientsCount: ${authClientsCount}`))
    .on('error', error => console.log(error))
    .on('close', () => console.log('close'))
    .listen(5038);
    
// Asterisk AMI Test Server listening on 5038 port

Client

const CRLF = '\r\n';
const net = required('net');
const client = net.connect({port: 5038}, () => {
    client
        .once('data', chunk => {
            console.log(chunk.toString());
            client.destroy();
        })
        .write([
            'Action: Login',
            'Username: test',
            'Secret: test'
        ].join(CRLF) + CRLF.repeat(2));
});

Methods

  • .broadcast(data) - sends data package to all authontificated clients;
  • .listen(port) - start listening on port;
  • .close() - close all client's connections;
  • .getAuthClients() - get array of all authontificated clients;
  • .getUnAuthClients() - get array of all unauthontificated clients;
  • .getClients() - get array of all clients;

Tests

Tests require Mocha.

mocha ./tests

or with npm

npm test 

Test coverage with Istanbul

npm run coverage

License

Licensed under the MIT License

About

Simple Test & Development Server for Asterisk AMI (NodeJS & ES2015)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published