码迷,mamicode.com
首页 > 编程语言 > 详细

asterisk-java ami3 属性改变监听

时间:2016-05-16 11:06:28      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:

asteriskServer.addAsteriskServerListener(new AsteriskListenerInit());//服务属性监听会自动连接服务

实现AsteriskServerListener,PropertyChangeListener,对服务的通道,用户,队列,语音室所有属性改变

public class AsteriskListenerInit implements AsteriskServerListener,PropertyChangeListener{

@Override
 public void propertyChange(PropertyChangeEvent evt) { 
  MapCacheUtil mapcache=MapCacheUtil.getInstance();
  String number="";//呼叫或者呼入的号码
  Object evtObj = evt.getSource();
  if (evtObj instanceof AsteriskChannel) {
   AsteriskChannel channel = (AsteriskChannel) evtObj;
   ChannelState channelstatus=channel.getState();
   if(ChannelState.RINGING==channelstatus){//通道状态是响铃中
    AsteriskChannel dialichannel=channel.getDialingChannel();//呼叫此通道的上一个通道
    if(dialichannel==null){//此次是呼出通话,回拨响铃中
        number=channel.getCallerId().getNumber();
    }else{
     number=dialichannel.getCallerId().getNumber().replace("99"+BaseUtil.getnumber(channel.getName()), "");//解码协议    
    }
    if(!mapcache.getExtensions().contains(number)){
     new WebSocket().broadcast("websocket"+BaseUtil.getnumber(channel.getName()), "来电弹屏"+number);        
      }
   }else if(ChannelState.UP==channelstatus){//通道状态是接起中
    AsteriskChannel dialichannel=channel.getDialingChannel();//呼叫此通道的上一个通道
    if(dialichannel!=null){
     if(mapcache.getExtensions().contains(channel.getCallerId().getNumber())){//呼入通道保留方案
     mapcache.put(channel.getName(), dialichannel.getName());//接起时将呼叫的通道传入缓存中
     }else{//呼出通话保留方案
     mapcache.put(dialichannel.getName(), channel.getName());
     }
    }   
   }else if(ChannelState.HUNGUP==channelstatus){//通道状态是挂断时
        mapcache.remove(channel.getCallerId().getNumber()+BaseUtil.CHANNEL_CENTENT);//移除挂机通道缓存
        mapcache.remove(channel.getName());//移除弹屏通道缓存
   }         
  }else if (evtObj instanceof AsteriskAgentImpl) {
   AsteriskAgentImpl agent = (AsteriskAgentImpl) evtObj;
   System.out.println("新增代理"+agent.getName());
  }
 }

 @Override
 public void onNewAsteriskChannel(AsteriskChannel channel) {
  // TODO Auto-generated method stub
  MapCacheUtil instance=MapCacheUtil.getInstance();//获得缓存对象
  CallerId cid=channel.getCallerId();
  if(cid!=null){
  instance.put(cid.getNumber()+BaseUtil.CHANNEL_CENTENT, channel.getName());//新的通道信息加入缓存中,为啦挂机使用
  }
  channel.addPropertyChangeListener("state",this);//只监听通道状态改变时触发操作
  System.out.println(cid.getNumber()+BaseUtil.CHANNEL_CENTENT+"建立新的通道"+channel);
 }

 @Override
 public void onNewMeetMeUser(MeetMeUser user) {
  // TODO Auto-generated method stub
  user.addPropertyChangeListener(this);
  System.out.println("建立新的会议室");
 }

 @Override
 public void onNewAgent(AsteriskAgentImpl agent) {
  // TODO Auto-generated method stub
  agent.addPropertyChangeListener(this);
  System.out.println("建立新的代理");
 }

 @Override
 public void onNewQueueEntry(AsteriskQueueEntry entry) {
  // TODO Auto-generated method stub
  entry.addPropertyChangeListener(this);
  System.out.println("建立新的队列");
 }

}

asterisk-java ami3 属性改变监听

标签:

原文地址:http://www.cnblogs.com/cbdd/p/5497115.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!