$ npm i asterisk-ami-test-server
support >=4.0.0
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));
});
.broadcast(data)
- sendsdata
package to all authontificated clients;.listen(port)
- start listening onport
;.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 require Mocha.
mocha ./tests
or with npm
npm test
Test coverage with Istanbul
npm run coverage
Licensed under the MIT License