asteriskServer文章1提到啦怎麼獲取,就不解釋web
asteriskServer.addChainListener(new AsteriskeventListenerInit());//整個服務的事件監聽,給這個服務加監聽數據庫
經過實現ManagerEventListener類,json
public class AsteriskeventListenerInit implements ManagerEventListener {api
@Override
public void onManagerEvent(ManagerEvent event) {websocket
這裏能夠得到事件返回的參數,獲取類型能夠慘開api文檔dom
domo:socket
//返回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());
}
}ide
//返回的是掛機信息事件
}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;
}事件
}ip
}