http://wiki.freeswitch.org/wiki/Java_ESL_Client, how I can make a connection before starting to handle Outbound connection ?
Greeting, bellow is an example to handle outbound connection and make hung up: but it never show How to make the connection in first place is their an example in main of how this function work ? /* * Copyright 2010 david varnes. * * Licensed under the Apache License, version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.freeswitch.esl.client.outbound.example; import org.freeswitch.esl.client.outbound.AbstractOutboundClientHandler; import org.freeswitch.esl.client.transport.SendMsg; import org.freeswitch.esl.client.transport.event.EslEvent; import org.freeswitch.esl.client.transport.message.EslMessage; import org.freeswitch.esl.client.transport.message.EslHeaders.Name; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; /** * Simple example of a handler for outbound connection from FreeSWITCH server. * This class will log some of the FreeSWTICH call channel variables and * then hangup the call. * * @author david varnes */ public class SimpleHangupOutboundHandler extends AbstractOutboundClientHandler { @Override protected void handleConnectResponse( ChannelHandlerContext ctx, EslEvent event ) { log.info( "Received connect response [{}]", event ); if ( event.getEventName().equalsIgnoreCase( "CHANNEL_DATA" ) ) { // this is the response to the initial connect log.info( "======================= incoming channel data =============================" ); log.info( "Event-Date-Local: [{}]", event.getEventDateLocal() ); log.info( "Unique-ID: [{}]", event.getEventHeaders().get( "Unique-ID" ) ); log.info( "Channel-ANI: [{}]", event.getEventHeaders().get( "Channel-ANI" ) ); log.info( "Answer-State: [{}]", event.getEventHeaders().get( "Answer-State" ) ); log.info( "Caller-Destination-Number: [{}]", event.getEventHeaders().get( "Caller-Destination-Number" ) ); log.info( "======================= = = = = = = = = = = = =============================" ); // now hangup the call hangupCall( ctx.getChannel() ); } else { throw new IllegalStateException( "Unexpected event after connect: [" + event.getEventName() + ']' ); } } @Override protected void handleEslEvent( ChannelHandlerContext ctx, EslEvent event ) { log.info( "Received event [{}]", event ); } private void hangupCall( Channel channel ) { SendMsg hangupMsg = new SendMsg(); hangupMsg.addCallCommand( "execute" ); hangupMsg.addExecuteAppName( "hangup" ); EslMessage response = sendSyncMultiLineCommand( channel, hangupMsg.getMsgLines() ); if ( response.getHeaderValue( Name.REPLY_TEXT ).startsWith( "+OK" ) ) { log.info( "Call hangup successful" ); } else { log.error( "Call hangup failed: [{}}", response.getHeaderValue( Name.REPLY_TEXT ) ); } } }
This example you mention handles an outbound connection coming FROM FreeSWITCH server. What this means is that your application is *NOT* the one that connects to FreeSWITCH, but acts as a server waiting for connections coming from FreeSWITCH. When a call is received on FreeSWITCH, it will open a socket connection to your application and you'll have total control of the call. Please take a couple of minutes and read the wiki page where this is explained: http://wiki.freeswitch.org/wiki/Java_ESL_Client#Outbound_socket_client_usage In outbound mode, your code will be executed for every incoming call. If you want to use FreeSWITCH out of the context of an incoming call (like to originate new calls) then you must use it in inbound mode (see http://wiki.freeswitch.org/wiki/Java_ESL_Client#Inbound_client_usage). The library contains a very good set of unit tests (ClientTest.java) showing how to use it in inbound mode. From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Marwan Idriss Sent: Wednesday, April 10, 2013 3:08 AM To: freeswitch-users@lists.freeswitch.org Subject: [Freeswitch-users] http://wiki.freeswitch.org/wiki/Java_ESL_Client, how I can make a connection before starting to handle Outbound connection ? Greeting, bellow is an example to handle outbound connection and make hung up: but it never show How to make the connection in first place is their an example in main of how this function work ? /* * Copyright 2010 david varnes. * * Licensed under the Apache License, version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.freeswitch.esl.client.outbound.example; import org.freeswitch.esl.client.outbound.AbstractOutboundClientHandler; import org.freeswitch.esl.client.transport.SendMsg; import org.freeswitch.esl.client.transport.event.EslEvent; import org.freeswitch.esl.client.transport.message.EslMessage; import org.freeswitch.esl.client.transport.message.EslHeaders.Name<http://org.freeswitch.esl.client.transport.message.EslHeaders.Name>; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; /** * Simple example of a handler for outbound connection from FreeSWITCH server. * This class will log some of the FreeSWTICH call channel variables and * then hangup the call. * * @author david varnes */ public class SimpleHangupOutboundHandler extends AbstractOutboundClientHandler { @Override protected void handleConnectResponse( ChannelHandlerContext ctx, EslEvent event ) { log.info<http://log.info>( "Received connect response [{}]", event ); if ( event.getEventName().equalsIgnoreCase( "CHANNEL_DATA" ) ) { // this is the response to the initial connect log.info<http://log.info>( "======================= incoming channel data =============================" ); log.info<http://log.info>( "Event-Date-Local: [{}]", event.getEventDateLocal() ); log.info<http://log.info>( "Unique-ID: [{}]", event.getEventHeaders().get( "Unique-ID" ) ); log.info<http://log.info>( "Channel-ANI: [{}]", event.getEventHeaders().get( "Channel-ANI" ) ); log.info<http://log.info>( "Answer-State: [{}]", event.getEventHeaders().get( "Answer-State" ) ); log.info<http://log.info>( "Caller-Destination-Number: [{}]", event.getEventHeaders().get( "Caller-Destination-Number" ) ); log.info<http://log.info>( "======================= = = = = = = = = = = = =============================" ); // now hangup the call hangupCall( ctx.getChannel() ); } else { throw new IllegalStateException( "Unexpected event after connect: [" + event.getEventName() + ']' ); } } @Override protected void handleEslEvent( ChannelHandlerContext ctx, EslEvent event ) { log.info<http://log.info>( "Received event [{}]", event ); } private void hangupCall( Channel channel ) { SendMsg hangupMsg = new SendMsg(); hangupMsg.addCallCommand( "execute" ); hangupMsg.addExecuteAppName( "hangup" ); EslMessage response = sendSyncMultiLineCommand( channel, hangupMsg.getMsgLines() ); if ( response.getHeaderValue( Name.REPLY_TEXT ).startsWith( "+OK" ) ) { log.info<http://log.info>( "Call hangup successful" ); } else { log.error( "Call hangup failed: [{}}", response.getHeaderValue( Name.REPLY_TEXT ) ); } } }
Hi, Please take a look. I'm using node.js and esl (https://github.com/shimaore/esl) Programming ESL Client and Server using node.js (http://nodejs.org/), it's also cross-platform. For example, -------------------------------------------------- // // esl-test1.js // var esl = require('esl'); var util = require('util'); var audio_file = []; // // play and get digits // <min> <max> <tries> <timeout> <terminators> <file> <invalid_file> <var_name> <regexp> <digit_timeout> // audio_file[0]='1 1 3 5000 # sounds/mywav/0.wav'; audio_file[1]='1 1 3 5000 # sounds/mywav/1.wav'; audio_file[2]='1 1 3 5000 # sounds/mywav/2.wav'; audio_file[3]='1 1 3 5000 # sounds/mywav/3.wav'; audio_file[4]='1 1 3 5000 # sounds/mywav/4.wav'; audio_file[5]='1 1 3 5000 # sounds/mywav/5.wav'; audio_file[6]='1 1 3 5000 # sounds/mywav/6.wav'; audio_file[7]='1 1 3 5000 # sounds/mywav/7.wav'; audio_file[8]='1 1 3 5000 # sounds/mywav/8.wav'; audio_file[9]='1 1 3 5000 # sounds/mywav/9.wav'; audio_file[10]='1 1 3 5000 # sounds/mywav/10.wav'; audio_file[11]='1 1 3 5000 # sounds/mywav/11.wav'; audio_file[12]='1 1 3 5000 # sounds/mywav/12.wav'; audio_file[13]='1 1 3 5000 # sounds/mywav/13.wav'; var error3 = '1 1 3 5000 # sounds/mywav/error3.wav'; var welcome = '1 1 3 5000 # sounds/mywav/hello.wav'; var server = esl.createCallServer(); //var server = esl.createClient(); server.on('CONNECT', function(req, res) { var uri, channel_data, unique_id; channel_data = req.body; unique_id = channel_data['Unique-ID']; req.execute('answer'); //req.execute('playback', 'sounds/mywav/hello.wav'); //req.execute('play_and_get_digits', '2 5 3 7000 # sounds/mywav/hello.wav sounds/mywav/error3.wav myFoo \d+'); req.execute('play_and_get_digits', welcome); req.on('DTMF', function(req) { //util.log('DTMF:'+util.inspect(req, null, null)); var digit; var channel_data; channel_data = req.body; unique_id = channel_data['Unique-ID']; util.log('DTMF: unique_id='+unique_id); digit = channel_data['DTMF-Digit']; console.log('DTMF Received=' + digit); util.log('DTMF Received'); if(digit==='#' || digit==='*'){ req.execute('play_and_get_digits', error3); } else { var n = parseInt(digit); req.execute('play_and_get_digits', audio_file[n]); } return; }); req.on('CHANNEL_ANSWER', function(req) { //util.log('CHANNEL_ANSWER:'+util.inspect(req, null, null)); var channel_data; channel_data = req.body; unique_id = channel_data['Unique-ID']; util.log('CHANNEL_ANSWER: unique_id='+unique_id); return util.log('Call was answered'); }); req.on('CHANNEL_HANGUP', function(req) { //util.log('CHANNEL_HANGUP:'+util.inspect(req, null, null)); var channel_data; channel_data = req.body; unique_id = channel_data['Unique-ID']; util.log('CHANNEL_HANGUP: unique_id='+unique_id); console.log('CHANNEL_HANGUP'); return util.log('CHANNEL_HANGUP'); }); req.on('CHANNEL_HANGUP_COMPLETE', function(req) { ///util.log('CHANNEL_HANGUP_COMPLETE:'+util.inspect(req, null, null)); var channel_data; channel_data = req.body; unique_id = channel_data['Unique-ID']; util.log('CHANNEL_HANGUP_COMPLETE: unique_id='+unique_id); console.log('CHANNEL_HANGUP_COMPLETE'); return util.log('CHANNEL_HANGUP_COMPLETE'); }); req.on('DISCONNECT', function(req) { //util.log('DISCONNECT:'+util.inspect(req, null, null)); var channel_data; channel_data = req.body; unique_id = channel_data['Unique-ID']; util.log('DISCONNECT: unique_id='+unique_id); console.log('DISCONNECT'); return util.log('DISCONNECT'); }) //util.log('CONNECT: req '+util.inspect(req, null, null)); util.log('CONNECT: unique_id='+unique_id); return util.log('CONNECT received'); }); server.listen(9173); ----------------------------------------------- Thanks Regards, Thomas Lee -- View this message in context: http://freeswitch-users.2379917.n2.nabble.com/http-wiki-freeswitch-org-wiki-... Sent from the freeswitch-users mailing list archive at Nabble.com.
participants (3)
-
Hector Geraldino
-
Marwan Idriss
-
Thomas Lee