danbarua / NEventSocket

A reactive FreeSwitch eventsocket library for Modern .Net
Mozilla Public License 2.0
74 stars 37 forks source link

Inbound #20

Closed gregoriusus closed 8 years ago

gregoriusus commented 9 years ago

Hi! Tried NEventSocket and I am amazed. It is just that on Inbound connection I get no subscribe events. Tried with simple example on read me, but I cannot get any event. Otherwise sending commands works ok.

Can you please tell me how should I found out what is wrong?

danbarua commented 9 years ago

If NEventSocket detects a logging library in your program, such as NLog, Log4Net etc then it will route log messages to that. Could you log trace-level messages to a file and paste the logs here and we can see what is going on?

gregoriusus commented 9 years ago

I installed Nlog and tried example.

This is last debug trace that I get 2015-08-12 03:59:47 TID[13] DEBUG CommandReply re ceived [+OK event listener enabled plain] for [event plain CHANNEL_EXECUTE_COMPL ETE BACKGROUND_JOB CHANNEL_HANGUP CHANNEL_ANSWER CHANNEL_PROGRESS CHANNEL_PROGRESS_MEDIA CHANNEL_BRIDGE CHANNEL_UNBRIDGE CUSTOM conference::maintenance]

This is code snippet that I use: await client.SubscribeEvents();

        client.Events.Where(x => x.EventName == EventName.ChannelAnswer)
              .Subscribe(x =>
                  {
                      uuid = x.UUID;
                      ColorConsole.WriteLine("Channel Answer Event ".Blue(), x.UUID);
                  });

Is there a way I can send you private my ESL settings (ip,user, pass), so you can try to subscribe for example to HEARTBEAT event?

danbarua commented 9 years ago

Sure, it's my GitHub user name at gmail.com

danbarua commented 8 years ago

It looks like calling Console.ReadLine() blocks subscription callbacks. As a workaround, adding await Task.Delay(200); before Console.ReadLine(); seems to do the trick.

danbarua commented 8 years ago

If you're calling Console.ReadLine() in production, you have bigger issues. :) you would normally be running as a Windows Service where blocking the UI thread is not an issue. On Thu, 15 Oct 2015 at 18:58, gregoriusus notifications@github.com wrote:

That's great news. Just one question. Is this workaround ok for production?

Best regards, Gregor

On Thu, Oct 15, 2015, 19:09 Dan Barua notifications@github.com wrote:

It looks like calling Console.ReadLine() blocks subscription callbacks. As a workaround, adding await Task.Delay(200); before Console.ReadLine(); seems to do the trick.

— Reply to this email directly or view it on GitHub < https://github.com/danbarua/NEventSocket/issues/20#issuecomment-148460186> .

Gregor Nanger

CTO t./f.: 00386 (0) 7 6000 308/309 • m:. 00386 (0)41 756485 • Infomedia d.o.o. • Jerebova 3, Novo mesto, Slovenia • www.infomedia.si

— Reply to this email directly or view it on GitHub https://github.com/danbarua/NEventSocket/issues/20#issuecomment-148473025 .

danbarua commented 8 years ago

alternatively, instead of calling Console.ReadLine(); we can do this to avoid blocking the main thread:

Console.WriteLine("Press CTRL+C to exit");
await Observable.FromEventPattern<ConsoleCancelEventHandler, ConsoleCancelEventArgs>(
                    h => Console.CancelKeyPress += h,
                    h => Console.CancelKeyPress -= h).ToTask();
danbarua commented 8 years ago

Seems to be working now.

Eternal21 commented 8 years ago

This seems like a great library, but I'm also having the same problem. Using latest release from nuget (1.0.2). I am not using Console.ReadLine(). I'm using the sample code from the readme (below). The only change is that I write to Debug window instead of Console window. The "status" response works fine and I get status output in Debug window, but after that no events are being displayed from FreeSWITCH. I also tried subscribing to EventName.All, with no luck either. How do I go about debugging this? Thanks.

public async Task Test()
{
    using (var socket = await InboundSocket.Connect("10.10.10.77", 8021, "ClueCon"))
    {
        var apiResponse = await socket.SendApi("status");
        Debug.WriteLine(apiResponse.BodyText);

        await socket.SubscribeEvents(EventName.ChannelAnswer);

        socket.Events
            .Where(x => x.EventName == EventName.ChannelAnswer)
            .Subscribe(x =>
            {
                Debug.WriteLine("Channel Answer Event " + x.UUID);
            });
    }
}
gregoriusus commented 8 years ago

Well, you have to use Readline otherwise your program finish.

Eternal21 commented 8 years ago

Never mind. My fault. The local socket variable was going out of scope, so it clearly could no longer react to events. Fixed by making it an instance variable instead of a local one. Kudos on the library again.

EDIT: I posted before seeing your response. Thanks.