Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new actions / new banners / extra type check #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/message/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,22 @@ function GetConfigJson() {
GetConfigJson.super_.call(this, 'GetConfigJson');
}

/*
* UpdateConfig Action.
* @constructor
* @see Action(String)
* @see See <a href="https://wiki.asterisk.org/wiki/display/AST/ManagerAction_UpdateConfig">https://wiki.asterisk.org/wiki/display/AST/ManagerAction_UpdateConfig</a>.
* @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
Expand Down Expand Up @@ -919,6 +935,18 @@ function QueueLog() {
QueueLog.super_.call(this, 'QueueLog');
}

/**
* Events Action.
* @constructor
* @see Action(String)
* @see See <a href="https://wiki.asterisk.org/wiki/display/AST/ManagerAction_Events">https://wiki.asterisk.org/wiki/display/AST/ManagerAction_Events</a>.
* @property {String} EventMask EventMask
* @augments Action
*/
function Events() {
Events.super_.call(this, 'Events');
}

/**
* MeetmeList Action.
* @constructor
Expand Down Expand Up @@ -1066,6 +1094,7 @@ util.inherits(Action, message.Message);
(function() {
var i;
var actions = [
Events,
Login,
Logoff,
Ping,
Expand Down Expand Up @@ -1099,6 +1128,7 @@ util.inherits(Action, message.Message);
ExtensionState,
GetConfig,
GetConfigJson,
UpdateConfig,
GetVar,
SetVar,
JabberSend,
Expand Down
5 changes: 3 additions & 2 deletions src/nami.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { };
Expand Down Expand Up @@ -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'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm curious about why would this be necessary, since events should be by default an empty array according to: https://github.com/marcelog/Nami/blob/master/src/message/response.js#L42

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was to avoid this exception, in our production logs. I agree it seems unneccesary but here is the trace

/var/www/rte/node_modules/nami/src/nami.js:77
        this.responses[event.actionid].events.push(event);
                                              ^
TypeError: Cannot call method 'push' of undefined
    at Nami.onRawEvent (/var/www/rte/node_modules/nami/src/nami.js:77:47)
    at Nami.EventEmitter.emit (events.js:95:17)
    at Nami.onRawMessage (/var/www/rte/node_modules/nami/src/nami.js:130:14)
    at Nami.EventEmitter.emit (events.js:95:17)
    at Nami.onData (/var/www/rte/node_modules/nami/src/nami.js:153:14)
    at Socket.<anonymous> (/var/www/rte/node_modules/nami/src/nami.js:197:18)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:736:14)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. I think we should dig a bit more in this.. if we got an event associated to a response, we should include it, and not skip it, like the patch does. Makes sense? Could you check what event is exactly that makes this fail? For example, checking if this.responses[event.actionid].events is undefined, and logging the event if so. Perhaps there's another thing going on here

) {
this.responses[event.actionid].events.push(event);
if (
Expand Down Expand Up @@ -242,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();
Expand Down