2

我正在使用 Freeswitch ESL 客户端,我致力于发起呼叫并在两个应用程序之间建立连接并使它们相互通信。我曾尝试在一端播放声音并在另一端录制,现在工作正常我的要求是在一端发送 dtmf 在另一端接收,我试过以下

private void sendDtmf(Channel channel) {
    SendMsg senDtmf = new SendMsg();
    senDtmf.addCallCommand("execute");
    senDtmf.addExecuteAppName("send_dtmf");
    senDtmf.addExecuteAppArg("2174");
    EslMessage response = sendSyncMultiLineCommand( channel,senDtmf.getMsgLines() );
    if (response.getHeaderValue(Name.REPLY_TEXT).startsWith("+OK")) {
        System.out.println(this.getClass().getName() + " >> DTMF Send");
        System.out.println("Resp: " + response.toString());
        log.info(this.getClass().getName() + " >> DTMF Send");
    } else {
        log.error(this.getClass().getName() + " >> DTMF failed :"
                + response.getHeaderValue(Name.REPLY_TEXT));
        System.out.println(this.getClass().getName() + " >> DTMF failed :"
                + response.getHeaderValue(Name.REPLY_TEXT));
    }
}

private void getdtmf( Channel channel, VoxtaMsg voxmsg) 
{ 
    SendMsg getDtmf= new SendMsg(); 
    getDtmf.addCallCommand( "execute" );
    getDtmf.addExecuteAppName( "play_and_get_digits" );
    getDtmf.addExecuteAppArg("4 4 3 7000 # /tmp/sounds/test.wav /tmp/sounds/test1.wav dtmf \\d+");
    EslMessage response = sendSyncMultiLineCommand( channel,getDtmf.getMsgLines() ); 
    if ( response.getHeaderValue( Name.REPLY_TEXT).startsWith( "+OK" ) )
    {
        System.out.println(this.getClass().getName()+" >> DTMF Received");
        log.info( this.getClass().getName()+" >> DTMF Received" ); 
    } 
    else
    {
        log.error( this.getClass().getName() + " >> DTMF failed: [{}}" +
        response.getHeaderValue( Name.REPLY_TEXT ));
        System.out.println(this.getClass().getName() + " >> DTMF failed: [{}}" +
                response.getHeaderValue( Name.REPLY_TEXT ) ); 
        log.debug("----------------------done-------------------------");
    }
 }

但无法得到任何结果,我是否需要在拨号计划中配置任何东西,或者我的总方法是错误的?

4

1 回答 1

3

您需要附加一个事件侦听器并等待“CHANNEL_EXECUTE_COMPLETE”命令。需要两件事。1)订阅连接上的事件 2)添加一个事件侦听器并取回您设置为的响应变量的值dtmf

假设client对象是连接。

client.connect(...);
client.setEventSubscriptions("plain", "CHANNEL_EXECUTE_COMPLETE");
client.addEventListener(new IEslEventListener() {
        @Override
        public void eventReceived(EslEvent event) {
            Map<String, String> vars = event.getEventHeaders();

            if (event.getEventName().equals("CHANNEL_EXECUTE_COMPLETE") && vars.get("Application").equals("play_and_get_digits")) {
                 PlayAndGetDigitsCallback(vars.get("dtmf"));
            }
        }

        @Override
        public void backgroundJobResultReceived(EslEvent event) {

        }
});

private void PlayAndGetDigitsCallback(String digits) {
    System.out.println("Digits received: " + digits);
}
于 2013-11-05T16:50:40.277 回答