コード例 #1
0
        private async Task GeneralRoomAdd(SmallAppUser currentUser)
        {
            if (UserInGeneralDiscussRoom.All(x => x.Id != currentUser.Id))
            {
                var msg =
                    $"Welcome, \"{currentUser.DisplayName}\" has joined the discussion - {DateTime.Now.ToString("HH:mm")}";
                await Clients
                .AllExcept(UserConnecteds.Where(x => x.Id == CurrentUser.Id.Value).Select(x => x.ConnectionId)
                           .Append(Context.ConnectionId)).SendAsync("ReceiveWelcome", msg);

                await Clients.Client(Context.ConnectionId).SendAsync("ReceiveWelcome", "You has join the discussion");
            }

            UserInGeneralDiscussRoom.Add(currentUser);
            await UpdateOnlineCounter();
        }
コード例 #2
0
        private async Task GeneralRoomRemove(SmallAppUser currentUser)
        {
            var msg = $"\"{currentUser.DisplayName}\" has left the discussion - {DateTime.Now.ToString("HH:mm")}";

            if (UserInGeneralDiscussRoom.Any(x => x.ConnectionId == Context.ConnectionId))
            {
                await Clients
                .AllExcept(UserConnecteds.Where(x => CurrentUser.Id != null && x.Id == CurrentUser.Id.Value)
                           .Select(x => x.ConnectionId))
                .SendAsync("ReceiveBye", msg);

                UserInGeneralDiscussRoom =
                    UserInGeneralDiscussRoom.Where(x => x.ConnectionId != Context.ConnectionId).ToList();
                await UpdateOnlineCounter();
            }
        }
コード例 #3
0
        public override async Task OnConnectedAsync()
        {
            if (CurrentUser.Id != null)
            {
                var currentUser = await AppUserRepository.GetAsync(CurrentUser.Id.Value);

                var mapped = new SmallAppUser
                {
                    Id           = currentUser.Id,
                    DisplayName  = currentUser.DisplayName,
                    Picture      = currentUser.Picture,
                    ConnectionId = Context.ConnectionId
                };

                await GeneralRoomAdd(mapped);

                UserConnecteds.Add(mapped);
            }

            await base.OnConnectedAsync();
        }