This assignment contains my submission for the chat assignment of the Web Based Systems course I am taking. One of the requirements for this assignment is that it's hosted on GitHub, so that's the main reason it's here.
As suggested by the professor, a starting point for this code was the chat tutorial by Socket.IO, which can be found at https://socket.io/get-started/chat/ (or at https://web.archive.org, depending on when you read this and what the future holds). However, the assignment requires many more features, and so the resulting code should look quite different from the results of the tutorial.
Sure. Unless you're also submitting a chat assignment for a Web Based Systems course, in which case maybe it's better you just use this as a reference if you get stuck.
I currently have assigned an MIT license to this project. I may assign an even more free license later, when I have the time to (a) breath and (b) read through the different options. Regardless of what the license is, though, I really do not care at all whether this gets reused, how it gets reused, whether I'm credited...
If you have the chance, though, it may be nice to credit the socket.io tutorial as the inspiration for this code. Or, at least, keep any comments I have that link back to them.
As required by the assignment, I have implemented the following features:
- Basic responsive design.
- Timestamps (calculated by the server)
- Unique nicknames upon connection
- Bottom-aligning of text (this is supposed to be challenging!) and a scroll bar
- History
- Memory of at least the last 200 messages. This is probably better to do in memory than on disk, given that this is just a school assignment...
- The entire remembered chat log is displayed to the user upon connection
- List of all online users. Instantly updated for all users whenever someone joins/disconnects.
- Changing of nicknames using the
/nick <new nickname>
command- Command is refused if the nickname is not unique
- Nickname change produces instant refresh for all users, making the change visible to all of them
- Change of nickname colour via
/nickcolor RRGGBB
command- Again, change is instantly shown to all users...
- User-posted messages are bolded (not so much a feature as an assignment requirement...)
- Persistence via Cookies.
- If a user disconnects, then reconnects, they keep their nickname.
- Supports 5+ concurrent users at a time.
- Tested to work in both Chrome and Firefox. [I'll try to test Edge wherever possible. Safari and Internet Explorer are probably on their own...]
Finally, the following is a note to myself to make sure it works on the lab's Linux computers.
[Update on this: it seems that use of padStart()
was an issue, but that should be all. If you have trouble running this with an older version of node, replace padStart()
with a quick custom replacement.]
Running:
- Make sure you have NodeJS on your machine, since that's what's used for the server-side logic.
- Copy the files from the "chatapp" directory somewhere, or else just navigate there via command prompt/terminal/etc.
- Install the socket.io and express node nodules:
npm install --save express
for Expressnpm install --save socket.io
for Socket IO- OR
npm install
to just install everything mentioned in the package.json at once.
- Run
npm start
- Visit http://localhost:3000 via your browser of choice. Tested to work with Firefox, Chrome, and Edge. Probably works on others too, because the UI is really simple.