Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SocketClientTest.java
- //Setup a socket listener to handle FS calls
- //When a call is connected, an instance of ManagerPipelineFactory is executed
- public void run_client() throws InterruptedException
- {
- SocketClient client = new SocketClient( 8040, new ManagerPipelineFactory() );
- client.start();
- Thread.sleep( 45000 );
- client.stop();
- }
- //
- //Handler code.
- //ManagerOutboundHandler.java
- //
- 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( "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" ) );
- //Answers the call
- answerCall(ctx.getChannel());
- //Receive events
- enableEvents(ctx.getChannel());
- //play a message
- playMessage(ctx.getChannel());
- //dial an extension
- dialExtension(ctx.getChannel());
- //transfer the call
- bridgeCall(ctx.getChannel());
- }
- else
- {
- throw new IllegalStateException( "Unexpected event after connect" );
- }
- }
- private void answerCall(Channel channel){
- SendMsg answerMsg = new SendMsg();
- answerMsg.addCallCommand("execute");
- answerMsg.addExecuteAppName("answer");
- answerMsg.addEventLock();
- EslMessage response = sendSyncMultiLineCommand(channel, answerMsg.getMsgLines());
- //The call is answered (I can see the talk time on my cisco phone)
- //FS log:
- /*
- 2011-06-09 16:00:54.483903 [DEBUG] switch_core_session.c:954 Send signal sofia/internal/5655@192.168.8.11 [BREAK]
- 2011-06-09 16:00:54.490938 [DEBUG] switch_ivr.c:563 sofia/internal/5655@192.168.8.11 Command Execute answer()
- EXECUTE sofia/internal/5655@192.168.8.11 answer()
- 2011-06-09 16:00:54.490938 [DEBUG] sofia_glue.c:3015 AUDIO RTP [sofia/internal/5655@192.168.8.11] 192.168.5.72 port 30420 -> 10.150.25.10 port 19568 codec: 0 ms: 20
- 2011-06-09 16:00:54.490938 [DEBUG] switch_rtp.c:1623 Starting timer [soft] 160 bytes per 20ms
- 2011-06-09 16:00:54.492245 [DEBUG] sofia_glue.c:3277 Set 2833 dtmf send payload to 101
- 2011-06-09 16:00:54.492245 [DEBUG] sofia_glue.c:3282 Set 2833 dtmf receive payload to 101
- 2011-06-09 16:00:54.492245 [DEBUG] mod_sofia.c:681 Local SDP sofia/internal/5655@192.168.8.11:
- v=0
- o=FreeSWITCH 1307619234 1307619235 IN IP4 192.168.5.72
- s=FreeSWITCH
- c=IN IP4 192.168.5.72
- t=0 0
- m=audio 30420 RTP/AVP 0 101
- a=rtpmap:0 PCMU/8000
- a=rtpmap:101 telephone-event/8000
- a=fmtp:101 0-16
- a=silenceSupp:off - - - -
- a=ptime:20
- a=sendrecv
- 2011-06-09 16:00:54.492245 [DEBUG] switch_core_session.c:709 Send signal sofia/internal/5655@192.168.8.11 [BREAK]
- 2011-06-09 16:00:54.492245 [DEBUG] switch_channel.c:2830 (sofia/internal/5655@192.168.8.11) Callstate Change RINGING -> ACTIVE
- 2011-06-09 16:00:54.492245 [NOTICE] mod_dptools.c:930 Channel [sofia/internal/5655@192.168.8.11] has been answered
- 2011-06-09 16:00:54.493685 [DEBUG] sofia.c:4761 Channel sofia/internal/5655@192.168.8.11 entering state [completed][200]
- 2011-06-09 16:00:54.501868 [DEBUG] sofia.c:4761 Channel sofia/internal/5655@192.168.8.11 entering state [ready][200]
- 2011-06-09 16:00:54.618836 [DEBUG] switch_rtp.c:3083 Correct ip/port confirmed.
- */
- }
- private void enableEvents(Channel channel){
- EslMessage response = sendSyncSingleLineCommand(channel, "myevents");
- //Register to receive events. From this point on all notifications for events can be logged/managed on the application
- }
- private void playMessage(Channel channel) {
- SendMsg playMsg = new SendMsg();
- playMsg.addCallCommand("execute");
- playMsg.addExecuteAppName("playback");
- playMsg.addExecuteAppArg("/apps/messages/hello-msg.wav");
- answerMsg.addEventLock();
- EslMessage response = sendSyncMultiLineCommand(channel, playMsg.getMsgLines());
- //Works perfect
- }
- private void dialExtension(Channel channel){
- SendMsg dialMsg = new SendMsg();
- dialMsg.addCallCommand("api");
- dialMsg.addExecuteAppName("originate");
- dialMsg.addExecuteAppArg("{originate_timeout=10}sofia/external/5562@192.168.23.104");
- EslMessage response = sendSyncMultiLineCommand(channel, dialMsg.getMsgLines());
- //FS Log
- /*
- 2011-06-09 16:10:59.626385 [DEBUG] switch_core_session.c:954 Send signal sofia/internal/5655@192.168.8.11 [BREAK]
- */
- }
- private void bridgeCall(Channel channel){
- SendMsg bridgeMsg = new SendMsg();
- bridgeMsg.addCallCommand("api");
- bridgeMsg.addExecuteAppName("bridge");
- bridgeMsg.addExecuteAppArg("sofia/external/5562@192.168.23.104");
- EslMessage response = sendSyncMultiLineCommand(channel, bridgeMsg.getMsgLines());
- //FS log:
- /*
- 2011-06-09 16:14:08.431101 [DEBUG] switch_core_session.c:954 Send signal sofia/internal/5655@192.168.8.11 [BREAK]
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement