using Microsoft.AspNetCore.SignalR; using System; using System.Collections.Generic; using System.Threading.Tasks; namespace SignalRChat { public class ChatHub : Hub { public Task SendMessageToAll(string message) { return Clients.All.SendAsync("ReceiveMessage", message); } public Task SendMessageToCaller(string message) { return Clients.Caller.SendAsync("ReceiveMessage", message); } public Task SendMessageToGroups(string user, string message) { List groups = new List() { "SignalR Users" }; return Clients.Groups(groups).SendAsync("ReceiveMessage", message); } public override Task OnConnectedAsync() { await Groups.AddAsync(Context.User.Identity.Name, "SignalR Users"); return base.OnConnectedAsync(); } } }