On node.js I get an error:
TypeError: Cannot read property 'talk_duration' of undefined
From: setTimeout(this.hangup, this.data.talk_duration * 1000);
in the setInterval
.
However, outside of setInterval
I have console.log(this.data.talk_duration);
which work fine.
this.outcomeAnswer = function () {
console.log(this.data.talk_duration); //this work
num = 0;
db.run("INSERT INTO in_queue (action_id, state) VALUES ('" + this.data.action_id + "', 'InQueue')", function (error) {
queueCheckLoop = setInterval(function () {
num++;
if (num == 5) {
clearInterval(queueCheckLoop);
}
db.each("SELECT count(*) as total FROM agent_queue WHERE state = 'Ready'", function (err, row) {
if (row.total > 0) {
clearInterval(queueCheckLoop);
setTimeout(this.hangup, this.data.talk_duration * 1000);
}
});
}, 1000);
});
}