Modify the server and webclient to allow for timestamps and the room that the message came from.
This commit is contained in:
parent
21820453bd
commit
66202e154b
2 changed files with 25 additions and 7 deletions
|
|
@ -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
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue