Advertisement
Guest User

java fs outbound

a guest
Jun 9th, 2011
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.27 KB | None | 0 0
  1. //SocketClientTest.java
  2.  
  3. //Setup a socket listener to handle FS calls
  4. //When a call is connected, an instance of ManagerPipelineFactory is executed
  5.  
  6.     public void run_client() throws InterruptedException
  7.     {
  8.         SocketClient client = new SocketClient( 8040, new ManagerPipelineFactory() );
  9.         client.start();
  10.         Thread.sleep( 45000 );
  11.         client.stop();
  12.     }
  13.  
  14.  
  15.  
  16. //
  17. //Handler code.
  18. //ManagerOutboundHandler.java
  19. //
  20.  
  21.     protected void handleConnectResponse( ChannelHandlerContext ctx, EslEvent event )
  22.     {
  23.         log.info( "Received connect response [{}]", event );
  24.         if ( event.getEventName().equalsIgnoreCase( "CHANNEL_DATA" ) )
  25.         {
  26.             // this is the response to the initial connect
  27.             log.info( "Event-Date-Local: [{}]", event.getEventDateLocal() );
  28.             log.info( "Unique-ID: [{}]", event.getEventHeaders().get( "Unique-ID" ) );
  29.             log.info( "Channel-ANI: [{}]", event.getEventHeaders().get( "Channel-ANI" ) );
  30.             log.info( "Answer-State: [{}]", event.getEventHeaders().get( "Answer-State" ) );
  31.  
  32.             //Answers the call
  33.             answerCall(ctx.getChannel());
  34.  
  35.             //Receive events
  36.             enableEvents(ctx.getChannel());
  37.  
  38.             //play a message
  39.             playMessage(ctx.getChannel());
  40.  
  41.             //dial an extension
  42.             dialExtension(ctx.getChannel());
  43.  
  44.             //transfer the call
  45.             bridgeCall(ctx.getChannel());
  46.         }
  47.         else
  48.         {
  49.             throw new IllegalStateException( "Unexpected event after connect" );
  50.         }
  51.     }
  52.  
  53.     private void answerCall(Channel channel){
  54.  
  55.     SendMsg answerMsg = new SendMsg();
  56.     answerMsg.addCallCommand("execute");
  57.     answerMsg.addExecuteAppName("answer");
  58.     answerMsg.addEventLock();
  59.  
  60.     EslMessage response = sendSyncMultiLineCommand(channel, answerMsg.getMsgLines());
  61.  
  62.         //The call is answered (I can see the talk time on my cisco phone)
  63.         //FS log:
  64.  
  65.     /*
  66.     2011-06-09 16:00:54.483903 [DEBUG] switch_core_session.c:954 Send signal sofia/internal/5655@192.168.8.11 [BREAK]
  67.     2011-06-09 16:00:54.490938 [DEBUG] switch_ivr.c:563 sofia/internal/5655@192.168.8.11 Command Execute answer()
  68.     EXECUTE sofia/internal/5655@192.168.8.11 answer()
  69.     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
  70.     2011-06-09 16:00:54.490938 [DEBUG] switch_rtp.c:1623 Starting timer [soft] 160 bytes per 20ms
  71.     2011-06-09 16:00:54.492245 [DEBUG] sofia_glue.c:3277 Set 2833 dtmf send payload to 101
  72.     2011-06-09 16:00:54.492245 [DEBUG] sofia_glue.c:3282 Set 2833 dtmf receive payload to 101
  73.     2011-06-09 16:00:54.492245 [DEBUG] mod_sofia.c:681 Local SDP sofia/internal/5655@192.168.8.11:
  74.     v=0
  75.     o=FreeSWITCH 1307619234 1307619235 IN IP4 192.168.5.72
  76.     s=FreeSWITCH
  77.     c=IN IP4 192.168.5.72
  78.     t=0 0
  79.     m=audio 30420 RTP/AVP 0 101
  80.     a=rtpmap:0 PCMU/8000
  81.     a=rtpmap:101 telephone-event/8000
  82.     a=fmtp:101 0-16
  83.     a=silenceSupp:off - - - -
  84.     a=ptime:20
  85.     a=sendrecv
  86.  
  87.     2011-06-09 16:00:54.492245 [DEBUG] switch_core_session.c:709 Send signal sofia/internal/5655@192.168.8.11 [BREAK]
  88.     2011-06-09 16:00:54.492245 [DEBUG] switch_channel.c:2830 (sofia/internal/5655@192.168.8.11) Callstate Change RINGING -> ACTIVE
  89.     2011-06-09 16:00:54.492245 [NOTICE] mod_dptools.c:930 Channel [sofia/internal/5655@192.168.8.11] has been answered
  90.     2011-06-09 16:00:54.493685 [DEBUG] sofia.c:4761 Channel sofia/internal/5655@192.168.8.11 entering state [completed][200]
  91.     2011-06-09 16:00:54.501868 [DEBUG] sofia.c:4761 Channel sofia/internal/5655@192.168.8.11 entering state [ready][200]
  92.     2011-06-09 16:00:54.618836 [DEBUG] switch_rtp.c:3083 Correct ip/port confirmed.
  93.     */
  94.     }
  95.  
  96.     private void enableEvents(Channel channel){
  97.         EslMessage response = sendSyncSingleLineCommand(channel, "myevents");
  98.  
  99.         //Register to receive events. From this point on all notifications for events can be logged/managed on the application
  100.     }
  101.    
  102.     private void playMessage(Channel channel) {
  103.         SendMsg playMsg = new SendMsg();
  104.         playMsg.addCallCommand("execute");
  105.         playMsg.addExecuteAppName("playback");
  106.         playMsg.addExecuteAppArg("/apps/messages/hello-msg.wav");
  107.         answerMsg.addEventLock();
  108.    
  109.         EslMessage response = sendSyncMultiLineCommand(channel, playMsg.getMsgLines());
  110.  
  111.         //Works perfect
  112.     }
  113.  
  114.     private void dialExtension(Channel channel){
  115.         SendMsg dialMsg = new SendMsg();
  116.         dialMsg.addCallCommand("api");
  117.         dialMsg.addExecuteAppName("originate");
  118.         dialMsg.addExecuteAppArg("{originate_timeout=10}sofia/external/5562@192.168.23.104");
  119.  
  120.         EslMessage response = sendSyncMultiLineCommand(channel, dialMsg.getMsgLines());
  121.  
  122.         //FS Log
  123.         /*
  124.         2011-06-09 16:10:59.626385 [DEBUG] switch_core_session.c:954 Send signal sofia/internal/5655@192.168.8.11 [BREAK]
  125.         */
  126.     }
  127.  
  128.         private void bridgeCall(Channel channel){
  129.         SendMsg bridgeMsg = new SendMsg();
  130.         bridgeMsg.addCallCommand("api");
  131.         bridgeMsg.addExecuteAppName("bridge");
  132.          bridgeMsg.addExecuteAppArg("sofia/external/5562@192.168.23.104");
  133.  
  134.         EslMessage response = sendSyncMultiLineCommand(channel, bridgeMsg.getMsgLines());
  135.        
  136.         //FS log:
  137.         /*
  138.         2011-06-09 16:14:08.431101 [DEBUG] switch_core_session.c:954 Send signal sofia/internal/5655@192.168.8.11 [BREAK]
  139.         */
  140.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement