Thread: [Asterisk-java-users] Interrupting StreamFile with DTMF digits.
Brought to you by:
srt
From: John M. <jo...@sy...> - 2005-12-15 16:24:46
|
Hi, I have an application where I need to interrupt the StreamFile command with a DTMF "*" - I cannot seem to get it to work and I just wanted to check that it does work in the following configuration. I am using asterisk-java-0.1 and Asterisk 1.0.9 and the following is the line of Java. streamFile(i_channel, "prompt/a.wav","*"); The file just plays like as if it was a Playback command as opposed to a Background command. best regards, John. John Melody SyberNet Ltd. Galway Business Park, Dangan, Galway. Tel. No. +353 91 514400 Fax. NO. +353 91 514409 Mobile - 087-2345847 |
From: Jonathan A. <jau...@st...> - 2005-12-15 16:57:34
|
Have you verified that you are receiving DTMF tones. I ran into a similar problem and discovered that my Asterisk/VoIP configuration was not detecting the tones. My situation turned out to be the firewall blocking and a wrong SIP configuration. On Thu, 2005-12-15 at 16:09 +0000, John Melody wrote: > Hi, > > I have an application where I need to interrupt the StreamFile command with > a DTMF "*" - I cannot seem to get it to work and I just wanted to check that > it does work in the following configuration. > > I am using asterisk-java-0.1 and Asterisk 1.0.9 and the following is the > line of Java. > > streamFile(i_channel, "prompt/a.wav","*"); > > The file just plays like as if it was a Playback command as opposed to a > Background command. > > best regards, > John. > > John Melody > SyberNet Ltd. > Galway Business Park, > Dangan, > Galway. > Tel. No. +353 91 514400 > Fax. NO. +353 91 514409 > Mobile - 087-2345847 > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > |
From: John M. <jo...@sy...> - 2005-12-16 11:12:22
|
Yes, Jonathan, I am receiving DTMF happily in the rest of the application. However, all the rest of the DTMF input takes place in extension.conf. It appears to be only when the application is in the FastAGI script that it does not recognise the DTMF tones. Is there anything that has to be enabled to pass DTMF digits to AGI? -----Original Message----- From: ast...@li... [mailto:ast...@li...]On Behalf Of Jonathan Augenstine Sent: 15 December 2005 16:57 To: ast...@li... Subject: Re: [Asterisk-java-users] Interrupting StreamFile with DTMF digits. Have you verified that you are receiving DTMF tones. I ran into a similar problem and discovered that my Asterisk/VoIP configuration was not detecting the tones. My situation turned out to be the firewall blocking and a wrong SIP configuration. On Thu, 2005-12-15 at 16:09 +0000, John Melody wrote: > Hi, > > I have an application where I need to interrupt the StreamFile command with > a DTMF "*" - I cannot seem to get it to work and I just wanted to check that > it does work in the following configuration. > > I am using asterisk-java-0.1 and Asterisk 1.0.9 and the following is the > line of Java. > > streamFile(i_channel, "prompt/a.wav","*"); > > The file just plays like as if it was a Playback command as opposed to a > Background command. > > best regards, > John. > > John Melody > SyberNet Ltd. > Galway Business Park, > Dangan, > Galway. > Tel. No. +353 91 514400 > Fax. NO. +353 91 514409 > Mobile - 087-2345847 > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ Asterisk-java-users mailing list Ast...@li... https://lists.sourceforge.net/lists/listinfo/asterisk-java-users |
From: Stefan R. <sr...@re...> - 2005-12-16 12:02:53
Attachments:
signature.asc
|
John Melody schrieb: > Yes, Jonathan, I am receiving DTMF happily in the rest of the application. > However, all the rest of the DTMF input takes place in extension.conf. It > appears to be only when the application is in the FastAGI script that it > does not recognise the DTMF tones. > > Is there anything that has to be enabled to pass DTMF digits to AGI? no it usually "just works" :) I would suggest you to use the latest release of Asterisk-Java (i.e. 0.2) and try to reproduce the problem with that version. And you could try to allow other dtmf digits to be pressed like streamFile("myprompt", "1234"); =Stefan |
From: Brett S. <bs...@no...> - 2005-12-16 23:55:52
|
I'm trying to write an application that can monitor specific channels and when a call comes in answer the call and call an application (rx_fax). I think I've worked out how to detect that a channel is ringing but I'm don' now how to answer it and call an application. I've looked at the OriginateEvent but that seems to be for makeing outbound calls. Any help would be appreciated. Regards, Bret. |
From: Stefan R. <sr...@re...> - 2005-12-17 00:01:06
|
Have a look at RedirectAction it allows you to redirect a channel to an extension. That extension should then call the application. The other option is to not use the ManagerAPI at all for this stuff but implement an AGI script and map the fax extensions to that AGI script. =3DStefan On Sat, 2005-12-17 at 10:54 +1100, Brett Sutton wrote: > I'm trying to write an application that can monitor specific channels=20 > and when a call comes in answer the call and call an application (rx_fax)= . >=20 > I think I've worked out how to detect that a channel is ringing but I'm=20 > don' now how to answer it and call an application. > I've looked at the OriginateEvent but that seems to be for makeing=20 > outbound calls. >=20 > Any help would be appreciated. >=20 > Regards, > Bret. >=20 >=20 > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi= les > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users |
From: John M. <jo...@sy...> - 2006-01-11 18:03:13
|
Hi Stefan, I have upgraded to 0.2 on Asterisk 1.0.9 and I have the same problems. I also tried other escape characters such as 1, 2, etc. Using the AGI debugging I notice the AGI command used has the following syntax. >>> STREAM FILE "myprompt" "1" where the digit "1" is the valid escape digit. I found the following example in the AGI Help ... STREAM FILE welcome # Plays the file 'welcome'. If the user presses the '#' key the playing stops and the command returns 200 result=35 Note Don't give an extension with the filename. Asterisk looks for the file to play in /var/lib/asterisk/sounds Use double quotes if the message should play completely. For example to play audio file 'welcome' without allowing interruption by digits use: STREAM FILE welcome "" The last comment might suggest that the quotes around the escape digits might lead the interpreter to play the file fully as the previous example does not have any quotes on the escape digit. Does anyone have an example of a working AGI STREAM FILE command with escape digits provided. thanks for any help, regards, John. -----Original Message----- From: ast...@li... [mailto:ast...@li...]On Behalf Of Stefan Reuter Sent: 16 December 2005 12:01 To: ast...@li... Subject: Re: [Asterisk-java-users] Interrupting StreamFile with DTMF digits. John Melody schrieb: > Yes, Jonathan, I am receiving DTMF happily in the rest of the application. > However, all the rest of the DTMF input takes place in extension.conf. It > appears to be only when the application is in the FastAGI script that it > does not recognise the DTMF tones. > > Is there anything that has to be enabled to pass DTMF digits to AGI? no it usually "just works" :) I would suggest you to use the latest release of Asterisk-Java (i.e. 0.2) and try to reproduce the problem with that version. And you could try to allow other dtmf digits to be pressed like streamFile("myprompt", "1234"); =Stefan |
From: Stefan R. <sr...@re...> - 2006-01-12 00:03:46
|
> The last comment might suggest that the quotes around the escape digits > might lead the interpreter to play the file fully as the previous example > does not have any quotes on the escape digit. nope escaping just works fine. I suggest you to have a look if your general DTMF setup is ok as this problem does not seem to directly relate to the AGI stuff. > Does anyone have an example of a working AGI STREAM FILE command with esc= ape > digits provided. I tried it in my test environment with Asterisk 1.2.1 and Asterisk-Java 0.2. Here is my code: TestAGI.java public class TestAGI extends BaseAGIScript { public void service(AGIRequest request, AGIChannel channel) throws AGIException { // answer the call answer(); =20 char c =3D streamFile("vm-instructions", "1"); =20 System.out.println("got char: '" + c + "'"); // end the call hangup(); } public static void main(String[] args) throws IOException { new DefaultAGIServer().startup(); } } fastagi-mapping.properties: test.agi =3D TestAGI Output on Asterisk CLI with agi debug: AGI Rx << ANSWER AGI Tx >> 200 result=3D0 AGI Rx << STREAM FILE "vm-instructions" "1" AGI Tx >> 200 result=3D49 endpos=3D45760 AGI Rx << HANGUP Output of the program after pressing DTMF 1: got char: '1' =3DStefan |
From: Brett S. <bs...@no...> - 2005-12-18 11:38:11
|
Here's a technique I use to get arround the problem of trying to send an Action when you are in an event handler. If you don't know; its simply not possible. The call to 'new RecieveFax(event)' creates its own connection to the API Manager. I do wonder whether it would be better if the MangerEventHandler method was called in a seperate thread from that which the ManagerReader runs in however that may have other undesirable side affects. Alternatively the call to SendAction should probably throw an IllegalStateException rather than just timing out. As it stand its hard to diagnose why the call to SendAction fails. Basically It's necessary to send the subsequent action in a different thread from the the eventHandler otherwise the ManagerReader locks up and nothing works. The subsequent actionn should also be sent using a separate instance of the ManagerConnection. You could potentionally send the subsequent action in the event handler thread (using a separate ManagerConnection) but you will block the ManagerReader from notifying your application of other events and I'm not certain, but I suspect that there is little to be gained from holding the ManagerReader up whilst you do other work as I doubt that Asterisk is waiting on the ManagerReader and as such you really arn't doing the operation synchronously (with respect to Asterisk). So here is a sample class demonstating one possible solution. I hope this of some use. Regards, Brett. import java.io.IOException; import java.util.TreeSet; import java.util.Vector; import java.util.concurrent.LinkedBlockingQueue; 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; import net.sf.asterisk.manager.event.NewChannelEvent; import net.sf.asterisk.manager.event.NewStateEvent; import org.apache.commons.configuration.ConfigurationException; import org.apache.log4j.Logger; <http://sourceforge.net/mailarchive/message.php?msg_id=13870642>public class FaxManagerInbound extends Thread implements ManagerEventHandler { static Logger logger = Logger.getLogger(FaxManagerInbound.class.getName()); private static FaxManagerInbound self; private boolean running; private ManagerConnection managerConnection; private Vector<Channel> channels; private static final LinkedBlockingQueue<NewChannelEvent> queue = new LinkedBlockingQueue<NewChannelEvent>(); static public FaxManagerInbound getInstance() throws ConfigurationException, IOException, AuthenticationFailedException, TimeoutException { if (self == null) { self = new FaxManagerInbound(Configuration.getInstance() .getChannels()); self.start(); } return self; } private FaxManagerInbound(TreeSet<Channel> channels) throws IOException, AuthenticationFailedException, TimeoutException { super("FaxManager Inbound"); managerConnection = connect(); // Get the list of channels we are interested in for (Channel channel : channels) { if (channel.type == ChannelManager.ChannelType.Inbound || channel.type == ChannelManager.ChannelType.Both) { this.channels.add(channel); } } } public void run() { running = true; logger.info("Inbound FaxManager started"); while (running) { try { if (!managerConnection.isConnected()) { logger .info("Inbound Manager API Connection lost; reconnecting."); managerConnection = connect(); logger.info("Inbound Manager API: reconnected"); } NewChannelEvent event = queue.take(); new RecieveFax(event); } catch (Throwable e) { // We don't like the manager shuting down just becuase of a // problem with a single fax. logger.error(e.getMessage(), e); } } logger.info("Inbound FaxManager Stopping"); } public void shutdown() { running = false; queue.notify(); notify(); } ManagerConnection connect() throws IOException, AuthenticationFailedException, TimeoutException { ManagerConnection connection = null; ManagerConnectionFactory factory = new ManagerConnectionFactory(); connection = factory.getManagerConnection(Configuration .getAsteriskHost(), Configuration.getAsteriskUsername(), Configuration.getAsteriskPassword()); // register for events connection.addEventHandler(this); // connect to Asterisk and log in managerConnection.login(); // request channel state managerConnection.sendAction(new StatusAction()); return connection; } public void handleEvent(ManagerEvent managerEvent) { if (managerEvent instanceof NewChannelEvent) { NewChannelEvent event = (NewChannelEvent) managerEvent; System.out.println(event.getState()); if (event.getState().compareToIgnoreCase("Ringing") == 0 || (event.getState().compareToIgnoreCase("Ring") == 0)) { queue.add(event); } } else if (managerEvent instanceof NewStateEvent) { NewStateEvent event = (NewStateEvent) managerEvent; System.out.println("State:" + event.getState()); System.out.println(event); } else // just print received events System.out.println("Event: " + managerEvent); } } |
From: Stefan R. <sr...@re...> - 2005-12-19 14:16:00
|
Brett, thanks for publishing your solution, i am sure it will be of help for others with similar requirements. I am currently thinking about the options to fix this for Asterisk-Java 0.3. What I thought about is: a) using one connection only for event receiving and using a pool of connections for sending actions b) separating the reader and the event handling, i.e. there would be one reader threat that places asterisks output into a buffer and a threadpool that dispatches the events to the listeners. There are some issues with both option that I would like to discuss. Option a) has the problem that multiple connections are needed. Thats probably fine if you run one central instance to control asterisk but calls for trouble when using Asterisk-Java on the desktop. Option b) is better in this regard but no longer guarantees that events are delivered in the order they are received. This could be adressed by adding a sequence to the events but places additional burdon on the developer. What do you think? Are there other options? What would you prefer? =3DStefan On Sun, 2005-12-18 at 22:37 +1100, Brett Sutton wrote: > Here's a technique I use to get arround the problem of trying to send > an Action when you are in an event handler. > If you don't know; its simply not possible. >=20 > The call to 'new RecieveFax(event)' creates its own connection to the > API Manager. >=20 > I do wonder whether it would be better if the MangerEventHandler > method was called in a seperate thread from that which the > ManagerReader runs in however that may have other undesirable side > affects.=20 > Alternatively the call to SendAction should probably throw an > IllegalStateException rather than just timing out. As it stand its > hard to diagnose why the call to SendAction fails. >=20 > Basically It's necessary to send the subsequent action in a different > thread from the the eventHandler otherwise the ManagerReader locks up > and nothing works. The subsequent actionn should also be sent using a > separate instance of the ManagerConnection. >=20 > You could potentionally send the subsequent action in the event > handler thread (using a separate ManagerConnection) but you will block > the ManagerReader from notifying your application of other events and > I'm not certain, but I suspect that there is little to be gained from > holding the ManagerReader up whilst you do other work as I doubt that > Asterisk is waiting on the ManagerReader and as such you really arn't > doing the operation synchronously (with respect to Asterisk). >=20 > So here is a sample class demonstating one possible solution. >=20 > I hope this of some use. >=20 > Regards, > Brett. >=20 > import java.io.IOException; > import java.util.TreeSet; > import java.util.Vector; > import java.util.concurrent.LinkedBlockingQueue; >=20 > 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; > import net.sf.asterisk.manager.event.NewChannelEvent; > import net.sf.asterisk.manager.event.NewStateEvent; >=20 > import org.apache.commons.configuration.ConfigurationException; > import org.apache.log4j.Logger; >=20 >=20 > public class FaxManagerInbound extends Thread implements > ManagerEventHandler > { > static Logger logger =3D > Logger.getLogger(FaxManagerInbound.class.getName()); >=20 > private static FaxManagerInbound self; >=20 > private boolean running; >=20 > private ManagerConnection managerConnection; >=20 > private Vector<Channel> channels; >=20 > private static final LinkedBlockingQueue<NewChannelEvent> queue =3D > new LinkedBlockingQueue<NewChannelEvent>(); >=20 > static public FaxManagerInbound getInstance() > throws ConfigurationException, > IOException, > AuthenticationFailedException, > TimeoutException > { > if (self =3D=3D null) > { > self =3D new FaxManagerInbound(Configuration.getInstance() > .getChannels()); > self.start(); > } > return self; > } >=20 > private FaxManagerInbound(TreeSet<Channel> channels) > throws IOException, > AuthenticationFailedException, > TimeoutException > { > super("FaxManager Inbound"); > managerConnection =3D connect(); >=20 > // Get the list of channels we are interested in > for (Channel channel : channels) > { > if (channel.type =3D=3D ChannelManager.ChannelType.Inbound > || channel.type =3D=3D > ChannelManager.ChannelType.Both) > { > this.channels.add(channel); > } > } > } >=20 > public void run() > { > running =3D true; > logger.info("Inbound FaxManager started"); > while (running) > { > try > { > if (!managerConnection.isConnected()) > { > logger > .info("Inbound Manager API Connection > lost; reconnecting."); > managerConnection =3D connect(); > logger.info("Inbound Manager API: reconnected"); > } >=20 > NewChannelEvent event =3D queue.take(); > new RecieveFax(event); >=20 > } > catch (Throwable e) > { > // We don't like the manager shuting down just becuase > of a > // problem with a single fax. > logger.error(e.getMessage(), e); > } > } > logger.info("Inbound FaxManager Stopping"); > } >=20 > public void shutdown() > { > running =3D false; > queue.notify(); > notify(); > } >=20 > ManagerConnection connect() > throws IOException, > AuthenticationFailedException, > TimeoutException > { > ManagerConnection connection =3D null; > ManagerConnectionFactory factory =3D new > ManagerConnectionFactory(); >=20 > connection =3D factory.getManagerConnection(Configuration > .getAsteriskHost(), > Configuration.getAsteriskUsername(), > Configuration.getAsteriskPassword()); >=20 > // register for events > connection.addEventHandler(this); >=20 > // connect to Asterisk and log in > managerConnection.login(); >=20 > // request channel state > managerConnection.sendAction(new StatusAction()); >=20 > return connection; > } >=20 > public void handleEvent(ManagerEvent managerEvent) > { > if (managerEvent instanceof NewChannelEvent) > { > NewChannelEvent event =3D (NewChannelEvent) managerEvent; > System.out.println(event.getState()); > if (event.getState().compareToIgnoreCase("Ringing") =3D=3D 0 > || (event.getState().compareToIgnoreCase("Ring") > =3D=3D 0)) > { > queue.add(event); > } >=20 > } > else if (managerEvent instanceof NewStateEvent) > { > NewStateEvent event =3D (NewStateEvent) managerEvent; > System.out.println("State:" + event.getState()); > System.out.println(event); >=20 > } > else >=20 > // just print received events > System.out.println("Event: " + managerEvent); > } >=20 > } >=20 |
From: Jonathan A. <jau...@st...> - 2005-12-15 20:14:01
|
This is really just an annoyance and not creating any road blocks. But, I am currently using the Eclipse IDE. One of the things that it reports is that the AbstractAGIScript and it incumbent methods are deprecated. It is not creating any problems but does anyone know why it is doing this and what I can do to correct this problem? Jonathan |
From: Stefan R. <sr...@re...> - 2005-12-15 20:20:32
|
On Thu, 2005-12-15 at 12:13 -0800, Jonathan Augenstine wrote: > This is really just an annoyance and not creating any road blocks. But, > I am currently using the Eclipse IDE. One of the things that it reports > is that the AbstractAGIScript and it incumbent methods are deprecated. > It is not creating any problems but does anyone know why it is doing > this and what I can do to correct this problem? yes you should use BaseAGIScript with Asterisk-Java 0.2 :) |