0.1.6 • Published 1 year ago

@dodancs/asterisk-ami-test-server v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year 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