From 81dfb9bbf5b112d139b355334e6d844580aa30e4 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 7 Dec 2022 23:32:15 -0800 Subject: [PATCH] Send along the user's name with each comment made So we can actually tell who said what in the chat. --- index.html | 15 +++++++++------ index.js | 4 +++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 9989e40..6173a68 100644 --- a/index.html +++ b/index.html @@ -78,8 +78,8 @@
- +
+

@@ -159,10 +159,13 @@ mute.addEventListener("click", () => { } }); - socket.on('comment', function(msg) { - var item = document.createElement('li'); - item.textContent = msg; - comments.appendChild(item); + socket.on('comment', function(comment) { + const dt = document.createElement('dt'); + const dd = document.createElement('dd'); + dt.textContent = comment.name; + dd.textContent = comment.text; + comments.appendChild(dt); + comments.appendChild(dd); }); socket.on('inform-name', (name) => { diff --git a/index.js b/index.js index 0b854a6..1239ea2 100644 --- a/index.js +++ b/index.js @@ -91,7 +91,9 @@ io.on('connection', (socket) => { }); // When any client comments, send that to all clients (including sender) - socket.on('comment', (comment) => { + socket.on('comment', (comment_text) => { + comment = { name: socket.request.session.name, + text: comment_text } io.emit('comment', comment); state.comments.push(comment); }); -- 2.43.0