public async Task SendMessageToGroupAsync(string message, string groupName) { groupName = groupName.Trim(); var senderClient = InMemoryDB.GetClientByConnectionId(Context.ConnectionId); await Clients.Groups(groupName).ReceiveMessageAsync(senderClient.NickName, message); }
/// <summary> /// Clientlar arasinda mesajlasma /// </summary> /// <param name="message"></param> /// <returns></returns> public async Task SendMessageAsync(string message, string nickName) { nickName = nickName.Trim(); var senderClient = InMemoryDB.GetClientByConnectionId(Context.ConnectionId); if (nickName == All) { await Clients.Others.ReceiveMessageAsync(senderClient.NickName, message); } else { var receiverClient = InMemoryDB.GetClientByNickName(nickName); await Clients.Client(receiverClient.ConnectionId).ReceiveMessageAsync(senderClient.NickName, message); } }
public async Task AddClientToGroupsAsync(IEnumerable <string> groupNames) { Client client = InMemoryDB.GetClientByConnectionId(Context.ConnectionId); foreach (var groupName in groupNames) { Group group = InMemoryDB.GetGroup(groupName); var result = group.Clients.Any(i => i.ConnectionId == Context.ConnectionId); if (result) { continue; } @group.Clients.Add(client); await Groups.AddToGroupAsync(Context.ConnectionId, groupName); } }