예제 #1
0
        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);
        }
예제 #2
0
        /// <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);
            }
        }
예제 #3
0
        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);
            }
        }