0.1.4 • Published 10 years ago

asterisk-ami-test-server v0.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

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

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago