Skip to content

Commit

Permalink
Multiple fix (#48)
Browse files Browse the repository at this point in the history
* Fix 'generic case of multiple copies of a key in an event'

* Spaces can mean something, dont remove them ( cf action Command in asterisk 14+ )

* using once we do not need to remove listener so we can remove the timer

* Use multiple variable instead of coma separated list

* fix issue: when use keepConnected prevent to explicitely disconnect

* updating version number and adding garronej to contributor

* adding missing contributor in licence
  • Loading branch information
garronej authored and pipobscure committed Jun 15, 2017
1 parent 0910740 commit fe609f2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 28 deletions.
14 changes: 11 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
MIT License
-----------

Copyright (C) 2012 by
Philipp Dunkel <https://github.com/phidelta>
Tekay <https://github.com/Tekay>
Copyright (C) 2012 - 2017 by
Philipp Dunkel <https://github.com/pipobscure>
abroweb <https://github.com/abroweb>
Igor Escobar <https://github.com/igorescobar>
Tekay <https://github.com/Tekay>
Kofi Hagan <https://github.com/kofibentum>
Hugo Chinchilla Carbonell <https://github.com/hugochinchilla>
Nick Mooney <https://github.com/Gnewt>
Asp3ctus <https://github.com/Asp3ctus>
Christian Gutierrez <https://github.com/chesstrian>
bchavet <https://github.com/bchavet>
Joserwan <https://github.com/joserwan>
Joseph Garrone <https://github.com/garronej>

Based on a work Copyright (C) 2010 Brian White <[email protected]>, but radically altered thereafter so as to constitute a new work.

Expand Down
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ ami.action({
```
## Contributors

* [Philipp Dunkel](https://github.com/phidelta)
* [Igor Escobar](<https://github.com/igorescobar)
* [Philipp Dunkel](https://github.com/pipobscure)
* [Igor Escobar](https://github.com/igorescobar)
* [Tekay](https://github.com/Tekay)
* [Kofi Hagan](https://github.com/kofibentum)
* [Hugo Chinchilla Carbonell](https://github.com/hugochinchilla)
Expand All @@ -62,19 +62,26 @@ ami.action({
* [Christian Gutierrez](https://github.com/chesstrian)
* [bchavet](https://github.com/bchavet)
* [Joserwan](https://github.com/joserwan)
* [Joseph Garrone](https://github.com/garronej)

## License

MIT License
-----------

Copyright (C) 2012 by
Copyright (C) 2012 - 2017 by
Philipp Dunkel <https://github.com/pipobscure>
Tekay <https://github.com/Tekay>
abroweb <https://github.com/abroweb>
Kofi Hagan <https://github.com/kofibentum>
Igor Escobar <https://github.com/igorescobar>
Joserwan https://github.com/joserwan
Tekay <https://github.com/Tekay>
Kofi Hagan <https://github.com/kofibentum>
Hugo Chinchilla Carbonell <https://github.com/hugochinchilla>
Nick Mooney <https://github.com/Gnewt>
Asp3ctus <https://github.com/Asp3ctus>
Christian Gutierrez <https://github.com/chesstrian>
bchavet <https://github.com/bchavet>
Joserwan <https://github.com/joserwan>
Joseph Garrone <https://github.com/garronej>

Based on a work Copyright (C) 2010 Brian White <[email protected]>, but radically altered thereafter so as to constitute a new work.

Expand Down
41 changes: 23 additions & 18 deletions lib/ami.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ function ManagerReader(context, data) {
item = {};
while (lines.length) {
line = lines.shift();
line = line.split(':');
line = line.split(': ');
var key = Utils.removeSpaces(line.shift()).toLowerCase();
line = Utils.removeSpaces(line.join(':'));
line = line.join(': ');

if (key === 'variable' || key === 'chanvariable') {

// Handle special case of one or more variables attached to an event and
// create a variables subobject in the event object
if (typeof(item[key]) !== 'object')
Expand All @@ -155,7 +157,7 @@ function ManagerReader(context, data) {
if (Array.isArray(item[key]))
item[key].push(line);
else
item[key] = [item[key]];
item[key] = [item[key], line];
} else
item[key] = line;
}
Expand Down Expand Up @@ -244,14 +246,17 @@ function ManagerKeepConnected(context) {
function MakeManagerAction(req, id) {
var msg = [];
msg.push('ActionID: ' + id);
msg = msg.concat(Object.keys(req).map(function(key) {

Object.keys(req).forEach(function (key) {

var nkey = Utils.removeSpaces(key).toLowerCase();
if (!nkey.length || ('actionid' == nkey))
return;

var nval = req[key];

nkey = nkey.substr(0, 1).toUpperCase() + nkey.substr(1);

switch (typeof nval) {
case 'undefined':
return;
Expand All @@ -262,21 +267,25 @@ function MakeManagerAction(req, id) {
return String(e);
}).join(',');
} else if (nval instanceof RegExp === false) {
nval = Object.keys(nval).map(function(name) {
return [name, nval[name]].join('=');
}).join(',');
Object.keys(nval).forEach( function(name) {
msg.push( nkey + ": " + name + "=" + nval[name].toString() );
});
return;
}
break;
default:
nval = String(nval);
break;
}
return [nkey, nval].join(': ');
}).filter(function(line) {
return line ? true : false;
}));

msg.push([nkey, nval].join(': '));

});

msg.sort();

return msg.join('\r\n') + '\r\n\r\n';

}

function ManagerAction(context, action, callback) {
Expand Down Expand Up @@ -322,20 +331,16 @@ function ManagerAction(context, action, callback) {
return id;
}

this.on(id, callback);

setTimeout(function(_, id, callback){
_.removeListener(id, callback);
}, 60000, this, id, callback);
this.once(id, callback);

return context.lastid = id;
}


function ManagerDisconnect(context, callback) {

if (context.reconnect)
this.removeListener('on', context.reconnect);
if (this.reconnect)
this.removeListener('close', this.reconnect);

if (context.connection && context.connection.readyState === 'open')
context.connection.end();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"web": "https://github.com/igorescobar"
}
],
"version":"0.1.15",
"version":"0.1.16",
"description":"A node.js module for interacting with the Asterisk Manager API.",
"keywords": ["asterisk", "voip", "ami", "asterisk-manager"],
"main": "index.js",
Expand Down

0 comments on commit fe609f2

Please sign in to comment.