diff --git a/SignalRChat/ChatHub.cs b/SignalRChat/ChatHub.cs index b3fa059..09e6520 100644 --- a/SignalRChat/ChatHub.cs +++ b/SignalRChat/ChatHub.cs @@ -10,72 +10,78 @@ namespace SignalRChat public class ChatHub : Hub { #region Data Members - + //Lista de Usuarios Conectados static List ConnectedUsers = new List(); + //Lista de Mensajes Enviados static List CurrentMessage = new List(); #endregion #region Methods + //Conexión de Usuarios public void Connect(string userName) { var id = Context.ConnectionId; - + //Un contador que me asigna los ID's al usuario nuevo sin que se repitan if (ConnectedUsers.Count(x => x.ConnectionId == id) == 0) { + //Añade al usuario al ID generado en la lista de Usuarios ConnectedUsers.Add(new UserDetail { ConnectionId = id, UserName = userName }); - // send to caller + //Conecta ese nuevo usuario al Chat Clients.Caller.onConnected(id, userName, ConnectedUsers, CurrentMessage); - // send to all except caller client + //Envio a todos, excepto al usuario nuevo Clients.AllExcept(id).onNewUserConnected(id, userName); } } - + //Envio de Mensajes public void SendMessageToAll(string userName, string message) { - // store last 100 messages in cache + //Llama a la funcion que me almacena los mensajes en el Cache AddMessageinCache(userName, message); - // Broad cast message + //Envia el mensaje a todos los usuarios del chat Clients.All.messageReceived(userName, message); } - + //Desconexión de Usuarios public override System.Threading.Tasks.Task OnDisconnected() { + //Me recorre los Usuarios y verifica la conexión de ellos var item = ConnectedUsers.FirstOrDefault(x => x.ConnectionId == Context.ConnectionId); + //Si la conexión es null, quiere decir que cerró la ventana if (item != null) { + //Me remueve el usuario ConnectedUsers.Remove(item); var id = Context.ConnectionId; Clients.All.onUserDisconnected(id, item.UserName); } - + //Retorno de la función return base.OnDisconnected(); } - + #endregion #region - + //Funcion para almacenar mensajes en el cache private void AddMessageinCache(string userName, string message) { + //A la lista añadimos el mensaje que envió el usuario CurrentMessage.Add(new MessageDetail { UserName = userName, Message = message }); - - if (CurrentMessage.Count > 100) + //Al cargar la pagina el historial va a contener los ultimos mensajes, ese valor se declara acá + if (CurrentMessage.Count > 5) CurrentMessage.RemoveAt(0); } - #endregion } diff --git a/SignalRChat/Common/MessageDetail.cs b/SignalRChat/Common/MessageDetail.cs index 874bd1f..25447b6 100644 --- a/SignalRChat/Common/MessageDetail.cs +++ b/SignalRChat/Common/MessageDetail.cs @@ -5,11 +5,12 @@ namespace SignalRChat.Common { + //Lista de Mensajes public class MessageDetail { - + //Usuario public string UserName { get; set; } - + //Mensaje del Usuario public string Message { get; set; } } diff --git a/SignalRChat/Common/UserDetail.cs b/SignalRChat/Common/UserDetail.cs index 1e940bb..0ddb201 100644 --- a/SignalRChat/Common/UserDetail.cs +++ b/SignalRChat/Common/UserDetail.cs @@ -5,9 +5,12 @@ namespace SignalRChat.Common { + //Lista de Usuarios public class UserDetail { + //ID Usuario public string ConnectionId { get; set; } + //Nombre Usuario public string UserName { get; set; } } } \ No newline at end of file diff --git a/SignalRChat/Css/ChatStyle.css b/SignalRChat/Css/ChatStyle.css deleted file mode 100644 index a76deb5..0000000 --- a/SignalRChat/Css/ChatStyle.css +++ /dev/null @@ -1,84 +0,0 @@ -body { - margin-top: 0px; - margin-left: 0px; -} - -.chatRoom { - width: 650px; - margin-left: auto; - margin-right: auto; - border: solid 1px gray; -} - - .chatRoom .content { - height: 300px; - clear: both; - } - - .chatRoom .content .chatWindow { - float: left; - width: 100%; - height: 100%; - overflow-y: scroll; - } - - .chatRoom .content .chatWindow .message { - padding: 10px; - } - - .chatRoom .content .chatWindow .message .userName { - font-weight: bold; - } - - - .chatRoom .messageBar { - border-top: solid 1px gray; - padding: 4px; - } - - .chatRoom .messageBar .textbox { - width: 550px; - } - -.draggable { - position: absolute; - border: #5f9482 solid 1px !important; - width: 250px; -} - - .draggable .header { - cursor: move; - background-color: #d7e5e4; - border-bottom: #5f9482 solid 1px; - color: #1e4638; - } - - .draggable .selText { - color: black; - padding: 4px; - } - - .draggable .messageArea { - width: 250px; - overflow-y: scroll; - height: 200px; - border-bottom: #5f9482 solid 1px; - } - - .draggable .messageArea .message { - padding: 4px; - } - - .draggable .buttonBar { - width: 250px; - padding: 4px; - } - - .draggable .buttonBar .msgText { - width: 172px; - } - - .draggable .buttonBar .button { - margin-left: 4px; - width: 55px; - } diff --git a/SignalRChat/Css/Site.css b/SignalRChat/Css/Site.css index fbffdaf..71bbd90 100644 --- a/SignalRChat/Css/Site.css +++ b/SignalRChat/Css/Site.css @@ -142,6 +142,7 @@ margin-top: 5%; color: #fff; font-family: "open_sanslight"; + font-weight: bold; } .middleR { @@ -225,9 +226,22 @@ height: 96%; left: 2%; position: absolute; - overflow: auto; + overflow-y: auto; + overflow-x: hidden; } + .chat::-webkit-scrollbar { + -webkit-appearance: none; + } + + .chat::-webkit-scrollbar:vertical { + width: 5px; + height: auto; + background-color: #ccc; + border: 2px solid #f1f2f3; + border-radius: 10px; + } + #icono { width: 1em; height: 1em; diff --git a/SignalRChat/SignalRChat.csproj b/SignalRChat/SignalRChat.csproj index 70535aa..54c6f56 100644 --- a/SignalRChat/SignalRChat.csproj +++ b/SignalRChat/SignalRChat.csproj @@ -80,7 +80,6 @@ - diff --git a/SignalRChat/index.html b/SignalRChat/index.html index 7bdd1e5..ecb838f 100644 --- a/SignalRChat/index.html +++ b/SignalRChat/index.html @@ -2,14 +2,15 @@ - - - + + + + - -