🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

nami

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nami - npm Package Compare versions

Comparing version
0.6.8
to
0.7.0
+2
-4
package.json

@@ -5,3 +5,3 @@ {

"description": "An asterisk manager interface client, uses EventEmitter to communicate events, will allow you to send actions, and receive responses (and associated events), and also receive async events from server",
"version": "0.6.8",
"version": "0.7.0",
"homepage": "https://github.com/marcelog/Nami",

@@ -27,6 +27,4 @@ "keywords": [

"engines" : { "node" : ">=0.6.5" },
"dependencies": {
"log4js": "0.3.9"
},
"dependencies": {},
"devDependencies": {}
}

@@ -30,3 +30,2 @@ [![Click here to lend your support to: Nami and make a donation at pledgie.com !](https://pledgie.com/campaigns/30946.png?skin_name=chrome)](https://pledgie.com/campaigns/30946)

* Nodejs (Tested with 0.6.5)
* log4js (For logging, tested with 0.3.9)

@@ -70,3 +69,2 @@ Events used in Nami

```sh
$ npm install log4js
$ npm install nami

@@ -94,3 +92,2 @@ ```

$ cd testnami
$ npm install log4js
$ npm install nami

@@ -110,3 +107,3 @@ ```

nami.send(new namiLib.Actions.CoreShowChannelsAction(), function(response){
logger.debug(' ---- Response: ' + util.inspect(response));
console.log(' ---- Response: ' + util.inspect(response));
});

@@ -138,2 +135,40 @@ });

Using logger other than console
------------------------------
Nami config may contain an optional attribute 'logger'.
If it exists, it will be used instead of console:
```js
namiConfig.logger = require('log4js').getLogger('Nami.Core');
var nami = new (require("nami").Nami)(namiConfig);
```
Viable options:
https://github.com/nomiddlename/log4js-node
https://github.com/trentm/node-bunyan
Logger may be anything that can be looks like:
```
logger = {
error: function(message) {},
warn : function(message) {},
info : function(message) {},
debug: function(message) {},
}
```
Controlling the loglevel
------------------------
If you are using your own logger (i.e: overriding the `logger` property of
the Nami client), you should check the documentation for it and apply the needed
changes or configuration accordingly.
If you are using the default Nami logger, you can set the property `logLevel`
of the Nami client to one of the following values:
* 0 to log only error messages.
* 1 to log error and warning messages.
* 2 to log error, warning, and info messages.
* 3 to log everything: error, warning, info, and debug messages.
Multiple server support

@@ -140,0 +175,0 @@ -----------------------

@@ -19,6 +19,5 @@ /*!

*/
var logger = require("log4js").getLogger('Nami.App');
var namiLib = require(__dirname + "/nami.js");
if (process.argv.length !== 6) {
logger.fatal("Use: <host> <port> <user> <secret>");
console.log("Use: <host> <port> <user> <secret>");
process.exit();

@@ -40,3 +39,3 @@ }

nami.on('namiConnectionClose', function (data) {
logger.debug('Reconnecting...');
console.log('Reconnecting...');
setTimeout(function () { nami.open(); }, 5000);

@@ -46,15 +45,15 @@ });

nami.on('namiInvalidPeer', function (data) {
logger.fatal("Invalid AMI Salute. Not an AMI?");
console.log("Invalid AMI Salute. Not an AMI?");
process.exit();
});
nami.on('namiLoginIncorrect', function () {
logger.fatal("Invalid Credentials");
console.log("Invalid Credentials");
process.exit();
});
nami.on('namiEvent', function (event) {
logger.debug('Got Event: ' + util.inspect(event));
console.log('Got Event: ' + util.inspect(event));
});
function standardSend(action) {
nami.send(action, function (response) {
logger.debug(' ---- Response: ' + util.inspect(response));
console.log(' ---- Response: ' + util.inspect(response));
});

@@ -61,0 +60,0 @@ }

@@ -38,8 +38,21 @@ /*!

* @constructor
* @param amiData The configuration for ami.
* @param {object} amiData The configuration for ami.
* @augments EventEmitter
*/
function Nami(amiData) {
var self = this;
Nami.super_.call(this);
this.logger = require('log4js').getLogger('Nami.Client');
this.logLevel = 3; // debug level by default.
var genericLog = function(minLevel, fun, msg) {
if(self.logLevel >= minLevel) {
fun(msg);
}
};
this.logger = amiData.logger || {
error: function(msg) { genericLog(0, console.error, msg)},
warn: function(msg) { genericLog(1, console.warn, msg)},
info: function(msg) { genericLog(2, console.info, msg)},
debug: function(msg) { genericLog(3, console.log, msg)}
};
this.connected = false;

@@ -66,3 +79,3 @@ this.amiData = amiData;

* is fired (i.e: on event Dial, namiEventDial will be fired).
*
*
* @see Nami#onRawMessage(String)

@@ -111,3 +124,3 @@ * @param {Event} response An Event message.

) {
this.responses[response.actionid] = response;
this.responses[response.actionid] = response;
} else if (typeof (this.callbacks[response.actionid]) !== 'undefined') {

@@ -262,3 +275,3 @@ this.callbacks[response.actionid](response);

});
// @param {Error} error Fires right before the `close` event

@@ -265,0 +278,0 @@ this.socket.on('error', function (error) {