java esl实现通话记录record

1.pom依赖

<dependency>
      <groupId>org.freeswitch.esl.client</groupId>
      <artifactId>org.freeswitch.esl.client</artifactId>
      <version>0.9.2</version>
</dependency>

2.java esl

autoload_configs/event_socket.conf.xml

<configuration name="event_socket.conf" description="Socket Client">
  <settings>
    <param name="nat-map" value="false"/>
    <param name="listen-ip" value="0.0.0.0"/>
    <param name="listen-port" value="8021"/>
    <param name="password" value="ClueCon"/>
    <param name="apply-inbound-acl" value="lan"/>
    <!--<param name="stop-on-bind-error" value="true"/>-->
  </settings>
</configuration>

 

/**
 * Java esl调用FreeSWITCH发起呼叫等
 *
 * @author SimonHua
 */
@Controller
public class ESL {
    @Autowired
    CallRecordServiceImpl callRecordService;
    @Autowired
    CallSoundServiceImpl callSoundService;

    private static final Logger log = LoggerFactory.getLogger(ESL.class);
    /**
     * autoload_configs目录event_socket.conf.xml文件中
     */
    private static String host = "192.168.6.31";
    private static int port = 8021;
    private static String password = "ClueCon";

    @PostConstruct
    public Client inBand() {

        final Client client = new Client();
        try {
            client.connect(host, port, password, 20);
        } catch (InboundConnectionFailure e) {
            log.error("Connect failed", e);
            return null;
        }

        // 注册事件处理程序
        client.addEventListener(new IEslEventListener() {
            public void eventReceived(EslEvent event) {
                String type = event.getEventName();
                Map<String,String> map = event.getEventHeaders();
                String call_uuid = map.get("Unique-ID");
                String caller_id_name = map.get("Caller-Caller-ID-Number");
                String caller_id_number = map.get("Caller-Caller-ID-Name");
                String destination_number = map.get("Caller-Destination-Number");

                JSONObject json = JSONObject.parseObject(JSON.toJSONString(map));
                switch (type){
                    case EventConstant.RECORD_START:
                        String filepath = map.get("Record-File-Path");
                        CallSound callSound = new CallSound();
                        callSound.setCallUuid(call_uuid);
                        callSound.setFilePath(filepath);
                        callSoundService.insert(callSound);
                        break;
                    case EventConstant.RECORD_STOP:
                        break;
//                    case EventConstant.CHANNEL_ANSWER:
//                        break;
                    case EventConstant.CHANNEL_BRIDGE:
                        long startTime = Long.parseLong(map.get("Caller-Channel-Created-Time"));
                        long answerTime = Long.parseLong(map.get("Caller-Channel-Answered-Time"));
                        CallRecord record = new CallRecord();
                        record.setCallUuid(call_uuid);
                        record.setCallerIdName(caller_id_name);
                        record.setCallerIdNumber(caller_id_number);
                        record.setDestinationNumber(destination_number);
                        record.setStartStamp(startTime);
                        record.setAnswerStamp(answerTime);
                        callRecordService.insert(record);
                        break;
//                    case EventConstant.CHANNEL_DESTROY:
//                        break;
                    case EventConstant.CHANNEL_HANGUP_COMPLETE:
                        String hangupCause = map.get("variable_hangup_cause");
                        long endTime = Long.parseLong(map.get("Caller-Channel-Hangup-Time"));
                        CallRecord callRecord = callRecordService.findByuuid(call_uuid);
                        if(callRecord==null)break;
                        callRecord.setEndStamp(endTime);
                        callRecord.setUduration(endTime-callRecord.getStartStamp());
                        int billsec = Integer.parseInt((endTime-callRecord.getAnswerStamp())/(1000*1000)+"");
                        callRecord.setBillsec(billsec);
                        callRecord.setHangupCause(hangupCause);
                        callRecordService.update(callRecord);
                        break;
                    default:
                        break;
                }
            }

            public void backgroundJobResultReceived(EslEvent event) {
                // String uuid = event.getEventHeaders().get("Job-UUID");
                log.info("Background job result received+:" + event.getEventName() + "/" + event.getEventHeaders());// +"/"+JoinString(event.getEventHeaders())+"/"+JoinString(event.getEventBodyLines()));
            }
        });
        client.setEventSubscriptions("plain", "all");
        return client;
    }


}

3.git代码下载

https://github.com/15190250058/esl.git

4.event事件对照表

http://www.freeswitch.net.cn/82.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值