private async void AddToGroup(string groupId, User user) { if (user.GroupId != default && groupId != user.GroupId) { ActiveGroups.RemoveUserFromGroup(user.GroupId, user); } if (groupId != user.GroupId) { ActiveGroups.AddUserToGroup(groupId, user); } await Groups.AddToGroupAsync(user.ConnectionId, groupId); }
public void PurgeUsers() { this.purgeUsersTimer = new Timer((e) => { User[] users = ConnectedUsers.Users.Where(x => x.Disconnected && x.ExpirationTime < DateTime.Now).ToArray(); foreach (User user in users) { ActiveGroups.RemoveUserFromGroup(user.GroupId, user); } ConnectedUsers.Users.Where(x => x.Disconnected && x.ExpirationTime < DateTime.Now).ToArray(); }, null, 0, 60000); }
public async Task JoinRoom(string groupId) { var user = ConnectedUsers.Users.FirstOrDefault(x => x.UID == Context.UserIdentifier); if (user != default) //user exist { if (ActiveGroups.GetGroup(groupId) != default) //Group exist { AddToGroup(groupId, user); await Clients.Caller.GoToRoom(groupId); } else { await Clients.Caller.ReceiveMessage("InvalidGroup"); } } }
private async void CreateGroup(string groupId, User creator) { ActiveGroups.CreateGroup(groupId, creator); await Groups.AddToGroupAsync(creator.ConnectionId, groupId); }