Node.js 使用节点js释放开关esl

Node.js 使用节点js释放开关esl,node.js,freeswitch,Node.js,Freeswitch,我正在使用nodejs实现freeswitch ESL,我正在使用module,它工作正常,我可以使用execute函数调用dialplan工具 然而,execute函数是nodejs的modesl模块中的异步实现 我需要的是一个同步调用,这样当我调用execute函数时,执行应该等到freeswitch完成该应用程序的执行 在下面的代码示例中,我在回放完成之前获得了输出“ivr finished” exports.process_ivr = function (conn, id) {

我正在使用nodejs实现freeswitch ESL,我正在使用module,它工作正常,我可以使用execute函数调用dialplan工具

然而,execute函数是nodejs的modesl模块中的异步实现

我需要的是一个同步调用,这样当我调用execute函数时,执行应该等到freeswitch完成该应用程序的执行

在下面的代码示例中,我在回放完成之前获得了输出“ivr finished”

exports.process_ivr = function (conn, id)
{
    conn.execute('answer');
    conn.execute('playback','/root/before.wav');
    console.log('ivr finished');
}; 
由于没有调用freeswitch命令的异步方法,所以有没有其他方法可以使用nodejs实现这一点?

试试这个

 conn.execute('answer',function(){
    conn.execute('playback','/root/before.wav',function(){
      console.log('ivr finished');
    });
 });

node.js使用一个线程,所以同步功能将使
modesl
一次服务一个客户端?我认为您可以通过回调
conn.execute('playback','/root/before.wav',函数(){console.log('ivr finished')})
检测execute是否完成;这没有帮助,它只是在通话结束时记录。假设我一个接一个地发送4个播放命令,那么所有这些命令都将排队到ESL。理想的情况是使用play_和get_数字并处理dtmf值的不同响应。但您可以检查dtmf,然后在回调中调用next
execute
,然后在回调中调用回调。很难阅读:)但它是异步的。我认为主题初学者需要阅读一本关于节点如何工作、事件循环、异步IO和回调的好书。