Thread: [Asterisk-java-users] help using PeerStatusEvent
Brought to you by:
srt
From: Aparna R. <apa...@ya...> - 2005-11-25 10:02:29
|
Hi all, I'm completely new to Java and need help n guidance in using asterisk-java. I would like to get the name of the Peer from asterisk , when it registers. how shouild i go abt implementing this? i know i shd luk into PeerStatusEvent. but being new to Java, i would like some sample code to help me with. kindly guide. thanks n regards aparna --------------------------------- Yahoo! Music Unlimited - Access over 1 million songs. Try it free. |
From: Stefan R. <sr...@re...> - 2005-11-25 10:36:07
Attachments:
signature.asc
|
Hi Aparna, > I would like to get the name of the Peer from asterisk , when it > registers. how shouild i go abt implementing this? > i know i shd luk into PeerStatusEvent. but being new to Java, i would > like some sample code to help me with. you are right about the PeerStatusEvent. Your application will have to listen for events that are received from Asterisk, for each event check if it is a PeerStatusEvent and then do something with it. To get started i suggest you to have a look at the tutorial available at http://www.asteriskjava.org/latest/tutorial.html There you will find the HelloEvents class that already does something similar. It listens for all events received within 10 seconds and prints them to the console. As you are only interested in the PeerStatusEvent you will want to change the handleEvent to check for it: public void handleEvent(ManagerEvent event) { if (event instanceof PeerStatusEvent) { String peerName = ((PeerStatusEvent) event).getPeer(); System.out.println("Got a PeerStatusEvent for " + peerName); } } Of course you probably want to do something more sophisticated that just printing out the name :) Hope that helps you get started. =Stefan Aparna Ramakrishnan schrieb: > Hi all, > > > kindly guide. > > thanks n regards > aparna > > Yahoo! Music Unlimited - Access over 1 million songs. Try it free. > <http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=36035/*http://music.yahoo.com/unlimited/> > |
From: Aparna R. <apa...@ya...> - 2005-11-25 15:32:50
|
Hi Stefan, Thnx for ur reply.The PeerStatusEvent now works. but before i get the name of the peer that just registered, i get a 'java.lang.InterruptedException : sleep interrupted'. But.. if i wait for long, the name of the peer that registered is displayed. Also the Connection doesn't logoff.! This is my Code: import java.io.IOException; import net.sf.asterisk.manager.AuthenticationFailedException; import net.sf.asterisk.manager.ManagerConnection; import net.sf.asterisk.manager.ManagerConnectionFactory; import net.sf.asterisk.manager.ManagerEventHandler; import net.sf.asterisk.manager.TimeoutException; import net.sf.asterisk.manager.action.StatusAction; import net.sf.asterisk.manager.event.ManagerEvent; public class HelloEvents implements ManagerEventHandler { private ManagerConnection managerConnection; public HelloEvents() throws IOException { ManagerConnectionFactory factory = new ManagerConnectionFactory(); this.managerConnection = factory.getManagerConnection("localhost", "manager", "pa55w0rd"); } public void run() throws IOException, AuthenticationFailedException, TimeoutException, InterruptedException { // register for events managerConnection.addEventHandler(this); // connect to Asterisk and log in managerConnection.login(); // request channel state managerConnection.sendAction(new StatusAction()); // wait 10 seconds for events to come in Thread.sleep(10000); // and finally log off and disconnect managerConnection.logoff(); } public void handleEvent(ManagerEvent event) { if (event instanceof PeerStatusEvent) { String peerName= ((PeerStatusEvent) event).getPeer(); System.out.println(peerName+ " has just now registered!"); } } public static void main(String[] args) throws Exception { HelloEvents helloEvents; helloEvents = new HelloEvents(); helloEvents.run(); } } kindly tel me if I'm going wrong somewhere. Thanks n regards Aparna -------------------------------------------- Hi all, I'm completely new to Java and need help n guidance in using asterisk-java. I would like to get the name of the Peer from asterisk , when it registers. how shouild i go abt implementing this? i know i shd luk into PeerStatusEvent. but being new to Java, i would like some sample code to help me with. kindly guide. thanks n regards aparna --------------------------------- Yahoo! DSL Something to write home about. Just $16.99/mo. or less |
From: Stefan R. <sr...@re...> - 2005-11-28 10:24:27
Attachments:
signature.asc
|
Hi, try to remove the sendAction(new StatusAction()) and increase the 10 seconds to a larger value. If that doesnt work, i need additional information regarding the exact version of Asterisk you are running. =Stefan |
From: Aparna R. <apa...@ya...> - 2005-11-28 10:36:30
|
hi Stefan, i removed the sendAction, as u suggested. it now works fine. thanks again. aparna Stefan Reuter <sr...@re...> wrote: Hi, try to remove the sendAction(new StatusAction()) and increase the 10 seconds to a larger value. If that doesnt work, i need additional information regarding the exact version of Asterisk you are running. =Stefan --------------------------------- Yahoo! Music Unlimited - Access over 1 million songs. Try it free. |
From: Ines <mou...@ya...> - 2005-12-09 11:22:31
|
hello, i need to do some call control in asterisk, using CCXML. i've been using Asterisk-Java, BaseAgiScript, but we can't do call control as there is only the method answer, i need to analyse a call when it gets threw asterisk. i found out that i can use JAsterisk but the probleme that there hardly no documentation on JAsterisk. has anyones used JAsterisk before ? or hoes somebody tried to do some call control in Asterisk ? if so, have u got any documentation? Thank's a lot Inés --------------------------------- Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger Téléchargez le ici ! |
From: Stefan R. <sr...@re...> - 2005-12-09 12:26:05
Attachments:
signature.asc
|
Hi, what functionality do you need for "call control"? you can use dial(), setExtension() and more with the AGI support of Asterisk-Java plus you can use the ManagerAPI with even more support like originate and redirect. =Stefan |
From: Ines <mou...@ya...> - 2005-12-09 13:05:02
|
Hello, Thanks for your reply, i want to be able to do call control, which means, when a call comes threw asterisk, i want to be able to detect it, without answering, and to be able to detect it's status (call alerting, connected... ) and then control it and decide to answer or not, to forward it ... I hope you understand what i mean inés --------------------------------- Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger Téléchargez le ici ! |
From: Stefan R. <sr...@re...> - 2005-12-09 13:21:36
Attachments:
signature.asc
|
Ines schrieb: > i want to be able to do call control, which means, when a call comes > threw asterisk, i want to be able to detect it, without answering, and > to be able to detect it's status (call alerting, connected... ) and then > control it and decide to answer or not, to forward it ... yes thanks for the clarification. Then you want to use the ManagerAPI. Have a look at the HelloManager and HelloEvents examples in the tutorial and at the javadocs for the classes in net.sf.asterisk.manager. Hope that helps. =Stefan |