Signal R notify client

i am completely newbie to Signal R Core. I would like to know the best practice how to notify client about event which has happened in my system. i have a real task which is following

I am subscribed to events call_begin and call_end when my eventHandler handles that events i would like to notify about them clients via signal r. So far i have done this via this code.

 private void  CallStartedEventHandler(CallData callData) 
    {
        _callNotifierHub.NotifyAboutCallStartedOrEnded("call_started", callData.CallID);
    }

    private void  CallEndedEventHandler(CallMetadata callMetadata) 
    {
         _callNotifierHub.NotifyAboutCallStartedOrEnded("call_ended", callData.CallID);
    }

And this is my hub code

 public class CallNotifierHub : Hub, ICallNotifierHub
{
    public async Task NotifyAboutCallStartedOrEnded(string message, long callId)
    {
        await Clients.All.SendAsync("NotifyAboutCallEvent", message, callId);
    }
}

And i am interested is this ok? Any suggestions?Would this eve n work???

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If you’d like to send message/notification to clients from outside a hub, to achieve it you can use the SignalR IHubContext. For more information, you can refer to the following article.

https://docs.microsoft.com/en-us/aspnet/core/signalr/hubcontext?view=aspnetcore-3.1


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x