aherrick
aherrick

Reputation: 20169

Setup Stream capability in ASP.NET MVC

I'm taking a look at a Firebase library for .NET:

https://github.com/ziyasal/FireSharp

I have a simple ASP.NET MVC site that I'm using to read/write data to Firebase. It's working great, but I'd like to incorporate the streaming listener functionality so I can get notified when data has changed.

What do I need to do in order to engage that? I don't believe it can just hang off an action method and be notified, correct?

EventStreamResponse response = await _client.OnAsync("chat", (sender, args) => {
       System.Console.WriteLine(args.Data);
});

//Call dispose to stop listening for events
response.Dispose();

Upvotes: 2

Views: 357

Answers (2)

Cibercop
Cibercop

Reputation: 11

Try with https://www.nuget.org/packages/FirebaseSharp/ it's a good firebase .Net Client

Upvotes: 0

aherrick
aherrick

Reputation: 20169

I figured this out for the most part.

In the Global.asax I have a method like below that I just call on App Start. Strange thing I'm not currently sure why is on initial load it calls the "added" method for all elements in the list.

    private static async void EventStreaming()
    {
        EventStreamResponse response = await FirebaseHelper.Client.OnAsync("emails",

        added: (sender, args) =>
        {
            Debug.WriteLine("ADDED " + args.Data + " -> 2\n");
        },
        changed: (sender, args) =>
        {
            Debug.WriteLine("CHANGED " + args.Data);
        },
        removed: (sender, args) =>
        {
            Debug.WriteLine("REMOVED " + args.Path);
        });

        //Call dispose to stop listening for events
        //response.Dispose();
    }

Upvotes: 1

Related Questions