示例#1
0
 public async ValueTask BroadcastMessage(ChatSession session, string message)
 {
     foreach (var u in _users)
     {
         await u.SendAsync($"{session.Name}: {message}");
     }
 }
示例#2
0
        public async ValueTask LeaveRoom(ChatSession session)
        {
            lock (_users)
            {
                _users.Remove(session);
            }

            foreach (var u in _users)
            {
                await u.SendAsync($"{session.Name} left.");
            }

            _logger.LogInformation($"{session.Name} left.");
        }
示例#3
0
        public async ValueTask EnterRoom(ChatSession session)
        {
            lock (_users)
            {
                _users.Add(session);
            }

            foreach (var u in _users)
            {
                await u.SendAsync($"{session.Name} entered just now.");
            }

            _logger.LogInformation($"{session.Name} entered.");

            session.Closed += async(s, e) =>
            {
                await LeaveRoom(s as ChatSession);
            };
        }