Пример #1
0
        private async Task LeftRoom()
        {
            User user = ConnectedUsers.GetUser(Context.ConnectionId);

            if (user != default)
            {
                await Clients.GroupExcept(user.GroupId, user.ConnectionId).UserLeft(this.UserToTransport(user));
            }
        }
Пример #2
0
        public async Task CreateNewRoom()
        {
            string groupId;

            do
            {
                groupId = new string(Guid.NewGuid().ToString().Take(5).ToArray());
            } while (ActiveGroups.Groups.Select(x => x.Id).Contains(groupId)); //Ensure that group id does not exist
            CreateGroup(groupId, ConnectedUsers.GetUser(Context.ConnectionId));
            await Clients.Caller.GoToRoom(groupId);                            //Redirects user to room
        }
Пример #3
0
        public async Task JoinedRoom()
        {
            User user = ConnectedUsers.GetUser(Context.ConnectionId);

            if (user != default)
            {
                object[] users           = this.UsersToTransport(ConnectedUsers.Users.Where(x => x.GroupId == user.GroupId).ToArray());
                var      syncUsersTask   = Clients.Caller.SyncUsers(users);                                                             //Sync caller users
                var      notifyUsersTask = Clients.GroupExcept(user.GroupId, user.ConnectionId).UserJoined(this.UserToTransport(user)); //Notify others that caller joined
                Task.WaitAll(new Task[] { syncUsersTask, notifyUsersTask });
            }
        }