Example #1
0
 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);
 }
Example #2
0
 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);
 }
Example #3
0
        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");
                }
            }
        }
Example #4
0
 private async void CreateGroup(string groupId, User creator)
 {
     ActiveGroups.CreateGroup(groupId, creator);
     await Groups.AddToGroupAsync(creator.ConnectionId, groupId);
 }