public
Created

Multiple ami connections with nami (nodejs asterisk manager interface)

  • Download Gist
gistfile1.js
JavaScript
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
// Used to store different nami objects (dont worry about it)
var namis = [];
 
// Create your event emitter object, you will call "on()"
// on this one instead of "the namis".
var mainEventEmitter = ....;
 
// Assuming you have an array called "boxes" with the ami
// login info for each "ami box", and a "name" field.
for(var j = 0; j < boxes.length; j++) {
(function(i) {
var pbx = boxes[i];
var name = pbx.name;
namis[i] = new namiLib.Nami(pbx);
namis[i].on('namiInvalidPeer', function (data) {
mainEventEmitter.emit('invalidPeer', { name: name, id: i });
});
namis[i].on('namiLoginIncorrect', function () {
mainEventEmitter.emit('loginIncorrect', { name: name, id: i });
});
namis[i].on('namiConnected', function (event) {
mainEventEmitter.emit('connected', { name: name, id: i });
});
namis[i].on('namiEvent', function (event) {
mainEventEmitter.emit('event', { name: name, id: i , event: event});
});
namis[i].open();
})(j);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.