Reputation: 31
So, I'm new to SignalR and I want to make sort of a notification that will trigger once a user is connected, which he will have to clear (just click x). That notification should be shown to every new user that connects. The framework is Angular and asp.net. So far, I've only made a function where a message is broadcast to every connected user, but that will not help me much...
Upvotes: 0
Views: 618
Reputation: 3611
So you done the part of connecting your client side code to your hub. Now what you need to do is to send the message only to connected client overriding the OnConnected
method like:
[HubName("YourHubName")]
public class YourHub : Hub
{
public override async Task OnConnected()
{
await base.OnConnected();
await this.Clients.Caller("BroadcastMessage", "You are now connected!");
}
}
So basically when the user connects the hub, and since it is the caller of this method, it will receive the notification.
On the Angular side, I would recommend you to have two different modules, services and notifications.
Upvotes: 1