From d625716f213c5b97951426c46a97f6a2d5caf84c Mon Sep 17 00:00:00 2001 From: Paul Ashfield Date: Fri, 7 Nov 2014 13:22:00 +0000 Subject: [PATCH 1/3] Add two new Actions - Events and UpdateConfig Allow for any sequence of numerics and periods in the version number that Asterisk returns (2.5 for Asterisk 13) in the welcome banner Some extra type checking to prevent exceptions that we have seen in production message flows. --- src/message/action.js | 30 ++++++++++++++++++++++++++++++ src/nami.js | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) mode change 100644 => 100755 src/message/action.js mode change 100644 => 100755 src/nami.js diff --git a/src/message/action.js b/src/message/action.js old mode 100644 new mode 100755 index 0f4533a..d980108 --- a/src/message/action.js +++ b/src/message/action.js @@ -449,6 +449,22 @@ function GetConfigJson() { GetConfigJson.super_.call(this, 'GetConfigJson'); } +/* + * UpdateConfig Action. + * @constructor + * @see Action(String) + * @see See https://wiki.asterisk.org/wiki/display/AST/ManagerAction_UpdateConfig. + * @property {String} ActionID - ActionID for this transaction. Will be returned. + * @property {String} SrcFilename - Configuration filename to read (e.g. foo.conf). + * @property {String} DstFilename - Configuration filename to write (e.g. foo.conf) + * @property {String} Reload - Whether or not a reload should take place (or name of specific module). + * @property {String} Action-XXXXXX - Action to take. + * @augments Action + */ +function UpdateConfig() { + UpdateConfig.super_.call(this, 'UpdateConfig'); +} + /** * GetVar Action. * @constructor @@ -919,6 +935,18 @@ function QueueLog() { QueueLog.super_.call(this, 'QueueLog'); } +/** + * Events Action. + * @constructor + * @see Action(String) + * @see See https://wiki.asterisk.org/wiki/display/AST/ManagerAction_Events. + * @property {String} EventMask EventMask + * @augments Action + */ +function Events() { + Events.super_.call(this, 'Events'); +} + /** * MeetmeList Action. * @constructor @@ -1066,6 +1094,7 @@ util.inherits(Action, message.Message); (function() { var i; var actions = [ + Events, Login, Logoff, Ping, @@ -1099,6 +1128,7 @@ util.inherits(Action, message.Message); ExtensionState, GetConfig, GetConfigJson, + UpdateConfig, GetVar, SetVar, JabberSend, diff --git a/src/nami.js b/src/nami.js old mode 100644 new mode 100755 index f4de760..b20d76e --- a/src/nami.js +++ b/src/nami.js @@ -45,7 +45,7 @@ function Nami(amiData) { this.amiData = amiData; this.EOL = "\r\n"; this.EOM = this.EOL + this.EOL; - this.welcomeMessage = "Asterisk Call Manager/.*" + this.EOL; + this.welcomeMessage = "Asterisk Call Manager/[0-9,.]*" + this.EOL; this.received = false; this.responses = { }; this.callbacks = { }; @@ -73,6 +73,7 @@ Nami.prototype.onRawEvent = function (event) { typeof (event.actionid) !== 'undefined' && typeof (this.responses[event.actionid]) !== 'undefined' && typeof (this.callbacks[event.actionid]) !== 'undefined' + && typeof (this.responses[event.actionid].events) !== 'undefined' ) { this.responses[event.actionid].events.push(event); if ( From 312c07ceeea9bdb8711704a2ed654085c72cbd4c Mon Sep 17 00:00:00 2001 From: Paul Ashfield Date: Fri, 7 Nov 2014 13:37:36 +0000 Subject: [PATCH 2/3] Files back to 0644 --- src/message/action.js | 0 src/nami.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/message/action.js mode change 100755 => 100644 src/nami.js diff --git a/src/message/action.js b/src/message/action.js old mode 100755 new mode 100644 diff --git a/src/nami.js b/src/nami.js old mode 100755 new mode 100644 From b84a31aa66cd7de2100f222bba3d53ef1ef5fc96 Mon Sep 17 00:00:00 2001 From: Paul Ashfield Date: Thu, 13 Nov 2014 20:02:57 +0000 Subject: [PATCH 3/3] .destroy() any existing connections instead of .end(). This avoids an observed production problem on WANs where sockets being held open following aa ECONNRESET --- src/nami.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nami.js b/src/nami.js index b20d76e..9f0c57b 100644 --- a/src/nami.js +++ b/src/nami.js @@ -243,7 +243,7 @@ Nami.prototype.initializeSocket = function () { if (this.socket && !this.socket.destroyed) { this.socket.removeAllListeners(); - this.socket.end(); + this.socket.destroy(); } this.socket = new net.Socket();