public static async Task SendServerMessage(IHubClients clients, MessageSenderArgs args) { await SendMessage("ServerMessage", clients, args); }
private static async Task SendMessage(string methodName, IHubClients clients, MessageSenderArgs args) { switch (args.Type) { case MessageType.Broadcast: await clients.All.SendAsync(methodName, args.Message); break; case MessageType.Direct: if (args.ConnectionId == null) { Console.WriteLine("ConnectionId doesn't exist for the given message, unable to deliver."); return; } await clients.Client(args.ConnectionId).SendAsync(methodName, args.Message); break; case MessageType.Group: if (args.GroupId == null) { Console.WriteLine("GroupId doesn't exist for the given message, unable to deliver."); return; } await clients.Groups(args.GroupId).SendAsync(methodName, args.Message); break; } }