Modify the server and webclient to allow for timestamps and the room that the message came from.

This commit is contained in:
Charles Descamps 2025-03-28 19:59:13 -07:00
parent 21820453bd
commit 66202e154b
2 changed files with 25 additions and 7 deletions

View file

@ -197,7 +197,9 @@
// Listen for messages from the server
socket.on('message', (data) => {
const messageElement = document.createElement('div');
messageElement.textContent = `${data.username || 'Server'}: ${data.message}`;
const timestamp = data.timestamp ? `[${data.timestamp}]` : '';
const chatRoomInfo = data.chat_room ? `(${data.chat_room})` : '';
messageElement.textContent = `${timestamp} ${data.username || 'Server'} ${chatRoomInfo}: ${data.message}`;
chatDiv.appendChild(messageElement);
chatDiv.scrollTop = chatDiv.scrollHeight; // Auto-scroll to the bottom
});