Exemplo n.º 1
0
        /// <summary>
        /// Example using event socket in "Inbound" mode
        /// </summary>
        /// <param name="stateInfo">Object state info</param>
        static void InboundMode(Object stateInfo)
        {
            //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));
            }
        }
    /// <summary>
    /// Example using event socket in "Inbound" mode
    /// </summary>
    /// <param name="stateInfo">Object state info</param>
    static void InboundMode(Object stateInfo)
    {
      //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("127.0.0.1", "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));
      }
    }
Exemplo n.º 3
0
        /// <summary>
        /// Example using event socket in "Outbound" mode asynchronic
        /// </summary>
        /// <param name="stateInfo">Object state info</param>
        static void OutboundModeAsync(Object stateInfo)
        {
            /* add next line to a dialplan
             * <action application="socket" data="localhost:8022 async full" />
             */
            TcpListener tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8022);

            try
            {
                tcpListener.Start();

                Console.WriteLine("OutboundModeAsync, waiting for connections...");

                while (true)
                {
                    tcpListener.BeginAcceptSocket((asyncCallback) =>
                    {
                        TcpListener tcpListened = (TcpListener)asyncCallback.AsyncState;

                        Socket sckClient = tcpListened.EndAcceptSocket(asyncCallback);

                        //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(sckClient.Handle.ToInt32());

                        ESLevent eslEvent = eslConnection.GetInfo();
                        string strUuid    = eslEvent.GetHeader("UNIQUE-ID", -1);

                        eslConnection.SendRecv("myevents");
                        eslConnection.SendRecv("divert_events on");

                        eslConnection.Execute("answer", String.Empty, String.Empty);
                        eslConnection.Execute("playback", "music/8000/suite-espanola-op-47-leyenda.wav", String.Empty);

                        while (eslConnection.Connected() == ESL_SUCCESS)
                        {
                            eslEvent = eslConnection.RecvEvent();
                            Console.WriteLine(eslEvent.Serialize(String.Empty));
                        }

                        sckClient.Close();
                        Console.WriteLine("Connection closed uuid:{0}", strUuid);
                    }, tcpListener);

                    Thread.Sleep(50);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                tcpListener.Stop();
            }
        }
    /// <summary>
    /// Example using event socket in "Outbound" mode asynchronic
    /// </summary>
    /// <param name="stateInfo">Object state info</param>
    static void OutboundModeAsync(Object stateInfo)
    {
      /* add next line to a dialplan
       <action application="socket" data="localhost:8022 async full" />
      */
      TcpListener tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8022);

      try
      {
        tcpListener.Start();

        Console.WriteLine("OutboundModeAsync, waiting for connections...");

        while (true)
        {
          tcpListener.BeginAcceptSocket((asyncCallback) =>
         {
           TcpListener tcpListened = (TcpListener)asyncCallback.AsyncState;

           Socket sckClient = tcpListened.EndAcceptSocket(asyncCallback);

           //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(sckClient.Handle.ToInt32());

           ESLevent eslEvent = eslConnection.GetInfo();
           string strUuid = eslEvent.GetHeader("UNIQUE-ID", -1);

           eslConnection.SendRecv("myevents");
           eslConnection.SendRecv("divert_events on");

           eslConnection.Execute("answer", String.Empty, String.Empty);
           eslConnection.Execute("playback", "music/8000/suite-espanola-op-47-leyenda.wav", String.Empty);

           while (eslConnection.Connected() == ESL_SUCCESS)
           {
             eslEvent = eslConnection.RecvEvent();
             Console.WriteLine(eslEvent.Serialize(String.Empty));
           }

           sckClient.Close();
           Console.WriteLine("Connection closed uuid:{0}", strUuid);

         }, tcpListener);

          Thread.Sleep(50);
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex);
      }
      finally
      {
        tcpListener.Stop();
      }
    }