lunes, 22 de febrero de 2010

Mod event socket en modo inbound

“inbound” modo significa que usando ESL la aplicación se conecta como cliente a FreeSWITCH (FS) para el envío y recepción de eventos y comandos. (http://wiki.freeswitch.org/wiki/Mod_event_socket)

Ejemplo usando managed ESL

El siguiente fragmento de código establece una conexión con FS, subscribe a todos los eventos en formato de texto plano, y entra en un bucle esperando por un evento e imprimiéndole en pantalla cuando llega.


//Initializes a new instance of ESLconnection, and connects to the host $host on the port $port, and supplies $password to freeswitch
ESLconnection eslConnection = new ESLconnection("localhost", "8021", "ClueCon");

if (eslConnection.Connected() != ESL_SUCCESS)
{
Console.WriteLine("Error connecting to FreeSwitch");
return;
}

//Set log level
//ESL.eslSetLogLevel((int)enLogLevel.DEBUG);

// Subscribe to all events
ESLevent eslEvent = eslConnection.SendRecv("event plain ALL");

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

//Turns an event into colon-separated 'name: value' pairs. The format parameter isn't used
Console.WriteLine(eslEvent.Serialize(String.Empty));

// Grab Events until process is killed
while (eslConnection.Connected() == ESL_SUCCESS)
{
eslEvent = eslConnection.RecvEvent();
Console.WriteLine(eslEvent.Serialize(String.Empty));
}

1 comentario:

  1. Hi Diego, thanks for your posts. I have used your code from the Freeswitch site and have managed to successfully connect via managed ESL.

    I am trying to build a simple .NET Windows Forms click-to-dial application.

    Is it possible, using ESL, to make outbound calls on behalf of a user?

    For example, my employees are using Xlite as their softphones, connected to FS. Can i create an application that will make calls on behalf of Xlite. In other words, employees will click a button on my application and Xlite begin to dial it?

    The closest I have got is:

    ESLConnection _eslconn = new ESLConnection

    string command = "api originate sofia/external/0313278213@10.40.0.1 &bridge(user/1002)";


    _eslconn.Send(command);

    which generates 2 calls.


    Alternatively, do you know of any .NET open source SIP softphones that I can play with? I had a look at FSCOMM, but I can't get my head around QT and C++

    Regards

    Roland

    ResponderEliminar