asterisk-java ami2 事件监听

 asteriskServer文章1提到啦怎么获取,就不解释

asteriskServer.addChainListener(new AsteriskeventListenerInit());//整个服务的事件监听,给这个服务加监听

通过实现ManagerEventListener类,

public class AsteriskeventListenerInit implements ManagerEventListener {

@Override
 public void onManagerEvent(ManagerEvent event) {

这里可以获得事件返回的参数,获取类型可以惨开api文档

domo:

//返回sip分机结束事件
 }else if(event instanceof PeerlistCompleteEvent){
  PeerlistCompleteEvent perrs=(PeerlistCompleteEvent)event;
  MapCacheUtil Instance=MapCacheUtil.getInstance();
  if(perrs.getActionId()!=null){
   Instance.putPerrsList(perrs.getActionId(), Instance.getPerrs(perrs.getActionId()));//获取整个事件结束
  }
 //返回的是sip分机信息事件  
 }else if(event instanceof PeerEntryEvent){
  PeerEntryEvent pentry=(PeerEntryEvent)event;
  mapcache.putExtensions(pentry.getObjectName());//存放所有分机的容器,用于判断是分机就不需要弹屏
  if(pentry!=null && pentry.getStatus()!=null){
  if(pentry.getStatus().contains("OK") && !String.valueOf(pentry.getPort()).equals("0")){
   List actionidoldList=mapcache.getActionId();
   if(actionidoldList!=null){
    for(int i=0;i<actionidoldList.size();i++){
     String actionid=pentry.getActionId();
     if(!ToolUtils.checkNull(actionid) && actionid.equals(actionidoldList.get(i))){
      if(ToolUtils.isInteger(pentry.getObjectName())){//分机号是数字类型就放入
      mapcache.putPerrs(actionid, pentry.getObjectName());
      }
     }
    }
   }
   perrlist.add(pentry.getObjectName());
  }  
  }

 //返回的是挂机信息事件
 }else if(event instanceof HangupEvent){
  HangupEvent hangup=(HangupEvent)event;
  new WebSocket().broadcast("websocket"+BaseUtil.getnumber(hangup.getChannel()), "挂机原因:"+BaseUtil.getHangup(Integer.valueOf(hangup.getCause()).intValue()));  
    //分机状态改变事件
 }else if(event instanceof ExtensionStatusEvent){
  ExtensionStatusEvent extensionstatus=(ExtensionStatusEvent)event;
  JSONObject jsono=new JSONObject();
  jsono.put("id", extensionstatus.getExten());
  jsono.put("statusname", BaseUtil.getExtensionState(extensionstatus.getStatus())); 
  new WebSocket().broadcastAll(jsono); 
 //暂时是呼叫保留事件
 }else if(event instanceof ParkedCallEvent){
  ParkedCallEvent parkcall=(ParkedCallEvent)event;  
   String key=BaseUtil.getnumber(parkcall.getFrom());
   key+=BaseUtil.CHANNELPARK_CENTENT;
   mapcache.put(key, parkcall.getExten());  
 //获取数据库数据事件
 }else if(event instanceof DbGetResponseEvent){
  DbGetResponseEvent dbget=(DbGetResponseEvent)event;
 }else if(event instanceof DisconnectEvent){
  DisconnectEvent disconn=(DisconnectEvent)event;
  System.out.println("连接asterisk服务失败事件触发:"+disconn);
 //所有结果返回事件,写在最后
 }else if(event instanceof ResponseEvent){
  ResponseEvent response=(ResponseEvent)event;
 }

}

}

posted on 2016-05-16 09:57  sui008  阅读(1517)  评论(0编辑  收藏  举报

导航