public async ValueTask BroadcastMessage(ChatSession session, string message) { foreach (var u in _users) { await u.SendAsync($"{session.Name}: {message}"); } }
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."); }
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); }; }