-
Notifications
You must be signed in to change notification settings - Fork 12
/
example.js
65 lines (56 loc) · 1.38 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
var AMI = require('./ami');
var util = require('util');
var ami = new AMI({
port: 5038,
host: 'localhost',
login: 'login',
password: 'secret',
events: 'on'
});
function printRes (err, res) {
if (err) {
console.log('action failed', err);
return;
}
console.log('response to action: ' + util.inspect(res));
}
ami.connect(function () {
ami.send({ Action: 'Command', Command: 'core show uptime' }, printRes);
console.log('connected to AMI version ' + ami.version);
});
ami.on('error', function (e) {
console.log('Fatal error: ', e);
process.exit(255);
});
ami.on('FullyBooted', function () {
ami.send({
Action: 'Command',
Command: 'database show'
}, printRes);
ami.send({ Action: 'SIPpeers' }, printRes);
ami.on('event', function (ev) {
console.log('got event ' + ev.Event);
});
});
process.on('SIGINT', function () {
console.log('SIGINT received, stopping');
ami.disconnect();
process.exit(0);
});
setTimeout(function () {
ami.send({
Action: 'Command',
Command: 'sip show registry'
}, printRes);
ami.send({ Action: 'ShowDialPlan' }, printRes);
setTimeout(function () {
ami.send({ Action: 'SIPpeers' }, printRes);
}, 5000);
setInterval(function () {
ami.send({ Action: 'Ping' }, printRes);
}, 3000);
}, 3000);
ami.on('PeerStatus', function (msg) {
console.log('peer status: ' + util.inspect(msg));
});