I'm using Node to run this code
but when I run this code get the undefined return from leadid variable in get function :
call = {};
call.hangup = {
get: function(isOpen, ami, elastic, validator, growly, mysql, request){
var self = call.hangup;
this.isOpen = isOpen;
this.ami = ami;
this.elastic = elastic;
this.validator = validator;
this.growly = growly;
this.mysql = mysql;
this.request = request;
if(isOpen)
{
ami.on('hangup', function(evt){
var cause_status = parseInt(evt.cause);
var message = self.causeStatus(cause_status);
var channel = evt.channel;
var isDAHDI = validator.contains(channel,"DAHDI");
if((isDAHDI)&&(cause_status == 16))
{
var mobile = evt.calleridnum;
if(validator.isLength(mobile,11))
{
if(validator.matches(mobile,/^09/i))
{
var txtMessage = "";
var sending = "";
var leadid = self.searching(mobile, mysql, validator);
retrun leadid; /// get the undefined !!!!
}
}
}
});
}else {
console.log("Hangup's Event is OFF !");
}
},
searching: function(number, mysql, validator){
this.number = number;
this.mysql = mysql;
this.validator = validator;
var query = "{sql ...}";
mysql.query(query, function(err, rows, fields) {
if (err) throw err;
if(!validator.isNull(rows))
{
return rows[0].leadid;
}else {
return false;
}
});
},
};
module.exports = call;
this is how I call it in main file:
var call = require('./call');
call.hangup.get(true, ami, client, validator, growly, connection, request);
in other hands when I call this function (searching) in the main file
new call.hangup.searching(number, connection, validator);
it's work correctly
how can I fix it ?
new self.searchingifsearchingis a method of thecall.hangup? You are missed something in your studying...undefined?