• Freeswitch(四):使用java esl写一个FreeSwitchEventListener 服务


    使用java esl写一个FreeSwitchEventListener 服务

    package com.sip;
    
    import com.google.common.base.Throwables;
    import org.freeswitch.esl.client.IEslEventListener;
    import org.freeswitch.esl.client.inbound.Client;
    import org.freeswitch.esl.client.outbound.AbstractOutboundClientHandler;
    import org.freeswitch.esl.client.outbound.AbstractOutboundPipelineFactory;
    import org.freeswitch.esl.client.outbound.SocketClient;
    import org.freeswitch.esl.client.outbound.example.SimpleHangupOutboundHandler;
    import org.freeswitch.esl.client.transport.event.EslEvent;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import java.util.Map; public class FreeSwitchEventListener { private static Logger logger = LoggerFactory.getLogger(FreeSwitchEventListener.class); public static void main(String[] args) { try { final Client inboudClient = new Client(); inboudClient.connect("192.168.1.196", 8021, "ClueCon", 10); inboudClient.addEventListener(new IEslEventListener() { @Override public void eventReceived(EslEvent eslEvent) { System.out.println(eslEvent.getEventName()); String eventname = eslEvent.getEventName(); if ("CHANNEL_HANGUP_COMPLETE".equals(eventname)) { System.out.println("进入挂机完成事件"); Map<String, String> dd = eslEvent.getEventHeaders(); System.out.println("variable_effective_caller_id_number is::::::" + dd.get("variable_effective_caller_id_number")); } } @Override public void backgroundJobResultReceived(EslEvent eslEvent) { System.out.println("事件名称++++"+eslEvent.getEventName()); } }); inboudClient.setEventSubscriptions("plain", "all");        //发送命令 String re= inboudClient.sendAsyncApiCommand("originate", "user/1000 1001"); System.out.println("呼叫结果:" + re); final SocketClient outboundServer = new SocketClient( 8084, new AbstractOutboundPipelineFactory() { @Override protected AbstractOutboundClientHandler makeHandler() {
                      //这个类可以自己重写一个
    return new SimpleHangupOutboundHandler(); } } ); outboundServer.start(); } catch (Throwable t) { Throwables.propagate(t); } } }

    pom文件添加以下依赖

     <dependencies>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.7.25</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.7.25</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>org.freeswitch.esl.client</groupId>
                <artifactId>org.freeswitch.esl.client</artifactId>
                <version>0.9.2</version>
            </dependency>
            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>25.1-jre</version>
            </dependency>
            <dependency>
                <groupId>io.netty</groupId>
                <artifactId>netty-all</artifactId>
                <version>4.1.17.Final</version>
                <type>bundle</type>
            </dependency>
        </dependencies>
    小人才疏学浅,看官不喜勿喷,谢谢
  • 相关阅读:
    Git centos 6.5 搭建(gitosis)
    error at ::0 can't find referenced pointcut xxx
    MySql 主从配置
    svn 搭建
    Flatbuffers学习
    python3 获取函数变量
    pyqt5 重启相同线程错误:QThread: Destroyed while thread is still running
    WIN10 使用注册表设置单应用KIOSK模式(不限win10版本)
    WIN10 使用POWERSHELL 设置单应用KIOSK模式(win10家庭版或企业版)
    py文件加密打包成exe文件
  • 原文地址:https://www.cnblogs.com/feiqilai/p/15464303.html
Copyright © 2020-2023  润新知