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???
Solution 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