예제 #1
0
        public void Joined()
        {
            ChatUser user = new ChatUser()
            {
                Id       = Context.User.Identity.GetUserId(),
                Username = Context.User.Identity.GetUserName()
            };

            _context.AddUser(user);
            _context.AddMapping(Context.ConnectionId, user.Id);
            Clients.All.Joins(user.Id, Context.User.Identity.GetUserName(), DateTime.Now);
        }
예제 #2
0
        public void Joined()
        {
            ApplicationUser user = new ApplicationUser()
            {
                Id       = ObjectId.GenerateNewId().ToString(),
                UserName = Clients.Caller.userName
            };

            _repository.Users.Add(user);
            _repository.AddMapping(Context.ConnectionId, user.Id);
            Clients.All.joins(user.Id, Clients.Caller.userName, DateTime.Now);
        }
예제 #3
0
        /// <summary>
        /// Fired when a client joins the chat. Here round trip state is available and we can register the user in the list
        /// </summary>
        public void Joined()
        {
            ChatUser user = new ChatUser()
            {
                //Id = Context.ConnectionId,
                Id       = Guid.NewGuid().ToString(),
                Username = Clients.Caller.username
            };

            _repository.Add(user);
            _repository.AddMapping(Context.ConnectionId, user.Id);
            Clients.All.joins(user.Id, Clients.Caller.username, DateTime.Now);
        }
예제 #4
0
        public async Task Join(string userName)
        {
            var connId = this.Context.ConnectionId;

            if (!_repository.Users.Where(u => u.UserName == userName).Any() && !string.IsNullOrEmpty(userName))
            {
                UserModel user = new UserModel()
                {
                    Id       = Guid.NewGuid().ToString(),
                    UserName = userName
                };
                _repository.Add(user);
                _repository.AddMapping(Context.ConnectionId, user.Id);
            }
            await Clients.All.SendAsync("RefrishUsers", GetUserList());

            await Clients.Client(connId).SendAsync("ShowAllMessages", _chatService.GetAllMessage());
        }