dfi-asterisk-ami-test-server
v0.1.6
Published
Asterisk Ami Test Server for NodeJS (ES2015)
Downloads
1
Readme
Asterisk AMI Test Server
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)
- 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
Tests require Mocha.
mocha ./tests
or with npm
npm test
Test coverage with Istanbul
npm run coverage
License
Licensed under the MIT License