Esempio n. 1
0
        /// <summary>
        /// Hub method. Called everytime when client trys to log into hub with a new (or expired) session.
        /// </summary>
        /// <param name="deviceUuid">A random id of client device, used for notification service</param>
        /// <param name="username">The username of client</param>
        /// <returns></returns>
        public async Task <string> EnterChatRoom(string deviceUuid, string username)
        {
            _logger.LogInformation("EnterChatRoom device: {0} username: {1}", deviceUuid, username);

            //  Try to store user login information (ConnectionId & deviceUuid)
            Session session = _userHandler.Login(username, Context.ConnectionId, deviceUuid);

            //  If login was successful, broadcast the system message
            if (session != null)
            {
                Message loginMessage = _messageFactory.CreateSystemMessage(username, "joined", DateTime.UtcNow);
                //  Do not store system messages. Directly send them out.
                await SendSystemMessage(loginMessage);

                return("success");
            }
            else
            {
                return("failure");
            }
        }