[Freeswitch-users] event socket

Nuwan Wijerathne NuwanW at unifybusiness.co.uk
Thu Oct 27 00:14:23 MSD 2011


Thanks a lot. This helps and solve my issues. Thank you again.

--- original message ---
From: "Hector Geraldino" <Hector.Geraldino at ip-soft.net>
Subject: Re: [Freeswitch-users] event socket
Date: 26th October 2011
Time: 8:55:00 pm


Hi,

The best source is the Mod_event_socket page on the wiki.

        http://wiki.freeswitch.org/wiki/Event_Socket
        http://wiki.freeswitch.org/wiki/Event_Socket_Outbound


You can answer a call by using a socket inbound connection to freeswitch, and you don't need to write any special instructions on the dialplan to do so, just listen for events and send api commands. But in my particular experience, if you want to control an incoming call (a call that hits an extension managed by freeswitch) you'll be better served by using a socket outbound connection. Off course this is from a design perspective, not because there are limitations when using an inbound connection.

Think about a socket outbound connection as a substitution of part of your dialplan. You take complete control over the incoming call, and you can answer it, play messages, capture dtmf tones, bridge it to another extension, etc. in a more cleaner way.

The socket inbound connection in my experience is better suited for situations where you need to create (and control) a new call from freeswitch to another extension, either controlled by freeswitch or another platform through a gateway. A simple use case scenario: an IVR app that bridges an incoming call to another leg:

1) PSTN -> FS -> Outbound socket app (C#)
2) C# app answers the call, plays a message and wait for DTMF tones
3) User presses 1 on the dialpad, an event is sent to the C# app
4) The C# app creates a new inbound connection to FS, and using this new connection:
        a) Originates a call to another extension (leg B)
        b) bridge the two calls, using uuid_bridge


In resume what I'm trying to say is: use outbound mode to control incoming calls as a way to replace/enhance the actions you can execute in a diaplan, and use inbound mode when you want freeswitch to make new calls, check status, etc.

Again, you can use the inbound mode to perform the same tasks as with outbound, this is just a guideline based on my experience.


From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Nuwan Wijerathne
Sent: Wednesday, October 26, 2011 10:51 AM
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] event socket

Thank you for the reply. Could you please answer couple of questions,

1. Can an external application in inbound mode can answer inbound calls. For example extension 200 dials 9. Is it possible to answer this call by an external application (inbound mode) ? If it is possible what is the dial plan entry for this ? I read event socket inbound and outbound mode and I'm under the impression that I can't use an external application in inbound mode to answer calls.
2. Could you please direct me to a source where I can find all supported features/functionality in event socket inbound and outbound mode.

Thank you,

From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Hector Geraldino
Sent: 25 October 2011 20:19
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] event socket

I just figured out something when reading your code.

By looking at your dialplan it looks like you're willing to take control over the incoming calls in your application by using the 'socket outbound' connection mode. In this case your application MUST act as a server and listen for socket connections on the designated port (you need a Server Socket class or its equivalent in .NET).

However according to your dialplan it looks like you're trying to bind the incoming call back to freeswitch, using the default port that FS uses for inbound connections (8021) - please correct me if I'm wrong. If you actually want to give the control of the incoming call to your application, you should use a different port, or change the FS default port on the configuration.  I don't know if the eslConnection class in .NET allows you to listen for incoming socket connection, but it looks to me more like a socket client.

Probably you should double check the Mod_event_socket documentation on the wiki to get more info about the .NET client library, and have a better understanding of the inbound/outbound connection modes. In the outbound mode you need to listen for new connections from your application, and you configure this mode by modifying the dialplan in the way you've done. In the inbound mode you can have a regular dialplan, and receive events for the calls that are handled by freeswitch dialplans.


From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Nuwan Wijerathne
Sent: Tuesday, October 25, 2011 11:57 AM
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] event socket

I'm receiving "+OK" from .Execute(). I'm not receiving a "CHANNEL_DATA" event.

Nuwan Wijerathne

Software Engineering Department

Unify Business Solutions Ltd
Ambassador House, 5 Midland Way, Barlborough, Chesterfield, S43 4XA
Mobile: 07834 001304  | Tel: 08458717788 | Fax: 08458717799
Website: www.unifybusiness.co.uk

From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Hector Geraldino
Sent: 25 October 2011 16:13
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] event socket

What Type is returned by the .Execute() method call?

Maybe you should create a new variable and assign the returned value to it, so you can inspect the result of the method call, something like:
                EslMessage response = eslConnection.Execute("answer", null, CallID);
       String isOk = response.getHeaderValue("Reply-Text");
so you can inspect the response returned by FreeSwitch.

BTW, this is mostly Java code so I'm not sure that these Types/properties are available on the C# assemblies.

And finally, try to perform this operation after receiving the CHANNEL_DATA event instead of CHANNEL_STATE.


From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Nuwan Wijerathne
Sent: Tuesday, October 25, 2011 10:54 AM
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] event socket

Hi,

CallID is a variable I defined. I'm assigning the call Unique-ID to this variable as follows,

                string CallID = eventHandle.GetHeader("Unique-ID");
My full code is at the bottom of this email,

Thank you,

Nuwan Wijerathne

Software Engineering Department

Unify Business Solutions Ltd
Ambassador House, 5 Midland Way, Barlborough, Chesterfield, S43 4XA
Mobile: 07834 001304  | Tel: 08458717788 | Fax: 08458717799
Website: www.unifybusiness.co.uk

From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Hynek Cihlar
Sent: 25 October 2011 15:43
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] event socket

You want the Unique-ID variable of the incoming message, not CallID.

Hynek
On Tue, Oct 25, 2011 at 4:36 PM, Nuwan Wijerathne <NuwanW at unifybusiness.co.uk> wrote:
            Sorry still no progress, code as follows

               if (eventHandle.getType() == "CHANNEL_STATE" && eventHandle.GetHeader("Answer-State") == "ringing")
                {
                    eslConnection.Execute("answer", null, CallID);
                }
Thank you,

From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Hynek Cihlar
Sent: 25 October 2011 15:23

To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] event socket

You also have to provide the UUID of the channel, so freeswitch knows which one to answer.

Sent from my mobile device

On Oct 25, 2011, at 16:19, Nuwan Wijerathne <NuwanW at unifybusiness.co.uk> wrote:
I made the changes below, still no progress,

                 if (eventHandle.getType() == "CHANNEL_STATE" && eventHandle.GetHeader("Answer-State") == "ringing")
                {
                    eslConnection.Execute("answer", null, null);
                }

Thank you,

Nuwan Wijerathne

Software Engineering Department

Unify Business Solutions Ltd
Ambassador House, 5 Midland Way, Barlborough, Chesterfield, S43 4XA
Mobile: 07834 001304  | Tel: 08458717788 | Fax: 08458717799
Website: www.unifybusiness.co.uk

From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Hynek Cihlar
Sent: 25 October 2011 14:54
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] event socket

Answer on event CHANNEL_CALLSTATE and channel call state RINGING.

Hynek
On Tue, Oct 25, 2011 at 3:49 PM, Nuwan Wijerathne <NuwanW at unifybusiness.co.uk> wrote:
Hi,

Thanks for the reply. Yes my application is listening on the port and I'm receiving events. However when I try to execute "answer" application it's not working. I'm trying to execute "answer" application when I receive "CHANNEL_CREATE" event on inbound calls. Please see code below. Could you Please advise

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;

namespace ESLTest
{
    public class Test
    {
        private Dictionary<string, Call> CallsTable;

        private Thread ThreadReader;

        private ESLconnection eslConnection;

        private const int CONNECTED = 1;

        private const string server = "localhost";
        private const string port = "8021";
        private const string password = "ClueCon";


        public Test()
        {
            CallsTable = new Dictionary<string, Call>();
            Connect();
        }


        private void Connect()
        {
            eslConnection = new ESLconnection(server, port, password);

            if (eslConnection.Connected().Equals( CONNECTED))
            {
                Console.WriteLine("Conneected to FreeSwitch");

                ThreadReader = new Thread(new ThreadStart(Read));
                ThreadReader.Start();
            }
            else
            {
                Console.WriteLine("Conneection Failure");
            }
        }



        private void Read()
        {
            ESLevent eventHandle = eslConnection.SendRecv("event plain ALL");

            if (eventHandle == null)
            {
                Console.WriteLine("Error subscribing to all events");
                return;
            }
            else
           {
                Console.WriteLine("Subscribed to all events");
            }

            while (true)
            {
                eventHandle = eslConnection.RecvEvent();

                string CallID = eventHandle.GetHeader("Unique-ID");

                if (eventHandle.getType() == "CHANNEL_CREATE")
                {
                    //Inbound call
                    if (eventHandle.GetHeader("Call-Direction") == "inbound")
                    {
                        CallsTable.Add(CallID, new Call(CallID));
                        eslConnection.Execute("answer", null, null);
                        Console.WriteLine(string.Format("{0} : Inbound CallID : {1}", eventHandle.getType(), CallID));
                    }
                }
           }
    }
}

Dialplan entry as follows,

                <extension name="intercept">
                     <condition field="destination_number" expression="^9$">
                           <action application="socket" data="127.0.0.1:8021 async full"/>
                    </condition>
                </extension>

Thank you,

From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Michael Collins
Sent: 24 October 2011 18:14
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] event socket

Please confirm: are you sending the call to the "socket" application in your dialplan? If so, then your ESL app needs to be listening on the TCP port specified. See the examples here: http://wiki.freeswitch.org/wiki/Event_Socket_Outbound#Examples

-MC
On Mon, Oct 24, 2011 at 8:50 AM, Nuwan Wijerathne <NuwanW at unifybusiness.co.uk> wrote:
Hi,

I'm trying to build an IVR application around freeswtich. I'm using freeswitch event socket in C#. I'm intercepting inbound calls in the dial plan and sending them to my application via outbound socket. Could someone please explain how to execute "answer" application through event socket.

Eg - I'm sending the command as below and it's not working.

ESLConnection eslConnection = new ESLConnection(server, port, password)
ESLEvent eventHandle = eslConnection.SendRecv("event plain ALL");

eventHandle = eslConnection.RecvEvent();
string uniqueCallID = evenHandle.GetHeader("Unique-ID");

eslConnection.Execute("answer", string.Empty, UniqueCallID);


I believe I'm doing something wrong as I can't find required information. Could someone please let me know where to find more information about freeswitch event socket in .Net. (Google not giving me required information)

Thank you,



FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org



FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org


FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org


FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org



FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org



Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list