Skip to content

Instantly share code, notes, and snippets.

@marcelog
Created November 13, 2012 00:41
Show Gist options
  • Save marcelog/4063103 to your computer and use it in GitHub Desktop.
Save marcelog/4063103 to your computer and use it in GitHub Desktop.
Multiple ami connections with nami (nodejs asterisk manager interface)
// 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment