简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM