Asterisk-java Ami3 Property Change monitoring

Source: Internet
Author: User

Asteriskserver.addasteriskserverlistener (New Asterisklistenerinit ());//service property listener automatically connects services

Implement Asteriskserverlistener,propertychangelistener, change all attributes on the service channel, user, queue, voice room

public class Asterisklistenerinit implements asteriskserverlistener,propertychangelistener{

@Override
public void PropertyChange (Propertychangeevent evt) {
Mapcacheutil mapcache=mapcacheutil.getinstance ();
String number= "";//Call or incoming number
Object evtobj = Evt.getsource ();
if (evtobj instanceof Asteriskchannel) {
Asteriskchannel channel = (asteriskchannel) evtobj;
Channelstate channelstatus=channel.getstate ();
if (channelstate.ringing==channelstatus) {//channel status is in the ring
Asteriskchannel Dialichannel=channel.getdialingchannel ();//Call the previous channel of this channel
if (dialichannel==null) {//This is an outgoing call, callback in the ring
Number=channel.getcallerid (). GetNumber ();
}else{
Number=dialichannel.getcallerid (). GetNumber (). Replace ("+baseutil.getnumber" (Channel.getname ()), "" ");//Decoding protocol
}
if (!mapcache.getextensions (). Contains (number)) {
New WebSocket (). Broadcast ("WebSocket" +baseutil.getnumber (Channel.getname ()), "Call Bounce Screen" +number);
}
}else if (channelstate.up==channelstatus) {//channel status is up
Asteriskchannel Dialichannel=channel.getdialingchannel ();//Call the previous channel of this channel
if (dialichannel!=null) {
if (Mapcache.getextensions (). Contains (Channel.getcallerid (). GetNumber ())) {//Inbound channel retention scheme
Mapcache.put (Channel.getname (), Dialichannel.getname ()), or//when the called channel is passed in the cache
}else{//Outbound Call Retention scheme
Mapcache.put (Dialichannel.getname (), Channel.getname ());
}
}
}else if (channelstate.hungup==channelstatus) {///channel status is hanging
Mapcache.remove (Channel.getcallerid (). GetNumber () +baseutil.channel_centent);//Remove the hook-up channel cache
Mapcache.remove (Channel.getname ());//Remove the pop-screen channel cache
}
}else if (evtobj instanceof Asteriskagentimpl) {
Asteriskagentimpl Agent = (Asteriskagentimpl) evtobj;
SYSTEM.OUT.PRINTLN ("New Agent" +agent.getname ());
}
}

@Override
public void Onnewasteriskchannel (Asteriskchannel channel) {
TODO auto-generated Method Stub
Mapcacheutil instance=mapcacheutil.getinstance ();//Get Cached objects
CallerID Cid=channel.getcallerid ();
if (cid!=null) {
Instance.put (Cid.getnumber () +baseutil.channel_centent, Channel.getname ());//new channel information is added to the cache and used for hanging machines
}
Channel.addpropertychangelistener ("state", this);//trigger action only when the channel status is changed
System.out.println (Cid.getnumber () +baseutil.channel_centent+ "establishing a new channel" +channel);
}

@Override
public void Onnewmeetmeuser (Meetmeuser user) {
TODO auto-generated Method Stub
User.addpropertychangelistener (this);
SYSTEM.OUT.PRINTLN ("Establishment of a new conference room");
}

@Override
public void Onnewagent (Asteriskagentimpl agent) {
TODO auto-generated Method Stub
Agent.addpropertychangelistener (this);
SYSTEM.OUT.PRINTLN ("Establishment of new agents");
}

@Override
public void Onnewqueueentry (Asteriskqueueentry entry) {
TODO auto-generated Method Stub
Entry.addpropertychangelistener (this);
System.out.println ("Create a new queue");
}

}

Asterisk-java Ami3 Property Change monitoring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.