Asterisk-java ami2 event listening, asterisk-javaami2

Source: Internet
Author: User

Asterisk-java ami2 event listening, asterisk-javaami2

AsteriskServer article 1 does not explain how to obtain it.

AsteriskServer. addChainListener (new AsteriskeventListenerInit (); // monitors the events of the entire service and adds a listener to this service.

By implementing the ManagerEventListener class,

Public class AsteriskeventListenerInit implements ManagerEventListener {

@ Override
Public void onManagerEvent (ManagerEvent event ){

Here we can get the parameters returned by the event. The Retrieval type can be used to open the api documentation.

Domo:

// Return the sip Extension termination event
} 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 (); // get the end of the entire event
}
// The sip Extension Information event is returned.
} Else if (event instanceof PeerEntryEvent ){
PeerEntryEvent pentry = (PeerEntryEvent) event;
Mapcache. putExtensions (pentry. getObjectName (); // the container that stores all extensions. This container is used to determine whether an extension is needed.
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 () {// if the extension number is numeric
Mapcache. putPerrs (actionid, pentry. getObjectName ());
}
}
}
}
Perrlist. add (pentry. getObjectName ());
}
}

// The host information event is returned.
} Else if (event instanceof HangupEvent ){
HangupEvent hangup = (HangupEvent) event;
New WebSocket (). broadcast ("websocket" + BaseUtil. getnumber (hangup. getChannel (), "reason for hanging up:" + BaseUtil. getHangup (Integer. valueOf (hangup. getCause ()). intValue ()));
// Extension status change event
} 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 );
// Temporary call reservation event
} Else if (event instanceof ParkedCallEvent ){
ParkedCallEvent parkcall = (ParkedCallEvent) event;
String key = BaseUtil. getnumber (parkcall. getFrom ());
Key + = BaseUtil. CHANNELPARK_CENTENT;
Mapcache. put (key, parkcall. getExten ());
// Obtain Database Data Events
} Else if (event instanceof DbGetResponseEvent ){
DbGetResponseEvent dbget = (DbGetResponseEvent) event;
} Else if (event instanceof DisconnectEvent ){
DisconnectEvent disconn = (DisconnectEvent) event;
System. out. println ("triggered when an asterisk connection failure event occurs:" + disconn );
// All returned events are written at the end.
} Else if (event instanceof ResponseEvent ){
ResponseEvent response = (ResponseEvent) event;
}

}

}

Related Article

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.