diff --git a/Queue.js b/Queue.js new file mode 100644 index 000000000..b1d6bfdcf --- /dev/null +++ b/Queue.js @@ -0,0 +1,11 @@ +var Queue = function(limit) { + this.limit = limit; + this.elements = []; +} +Queue.prototype.push = function(elem) { + this.elements.push(elem); + while (this.elements.length > this.limit) { + this.elements.shift(); + } +} +module.exports = Queue; \ No newline at end of file diff --git a/README.md b/README.md index c18a098c0..b454ec3b7 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,23 @@ the [Getting Started](http://socket.io/get-started/chat/) guide of the Socket.IO website. Please refer to it to learn how to run this application. + +# Homework + +Here are some ideas to improve the application: + + - Broadcast a message to connected users when someone connects or disconnects + - Add support for nicknames + - Don’t send the same message to the user that sent it himself. Instead, append the message directly as soon as he presses enter. + - Add “{user} is typing” functionality + - Show who’s online + - Add private messaging + - Share your improvements! + + - __(DONE)__ Joining users see up to a 100 of latest messages in their personal message boards + - __(DONE)__ The message board clearly indicates the authorship of messages by the same user + - __(DONE)__ The anonymous user identity is assigned automatically, and it survives browser restarts + +# Issues + + - Client: handle server disconnect, do not loose outgoing messages diff --git a/index.html b/index.html index 5f2767e98..9d3b4485b 100644 --- a/index.html +++ b/index.html @@ -7,8 +7,8 @@ body { font: 13px Helvetica, Arial; } form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; } form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; } - form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; } - #messages { list-style-type: none; margin: 0; padding: 0; } + form button, form label { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; } + #messages { list-style-type: none; margin: 0; padding: 0; padding-bottom: 100px; } #messages li { padding: 5px 10px; } #messages li:nth-child(odd) { background: #eee; } @@ -16,19 +16,54 @@