From: Carl Worth Date: Thu, 8 Dec 2022 07:32:15 +0000 (-0800) Subject: Send along the user's name with each comment made X-Git-Url: https://git.cworth.org/git?p=zombocom-ai;a=commitdiff_plain;h=81dfb9bbf5b112d139b355334e6d844580aa30e4 Send along the user's name with each comment made So we can actually tell who said what in the chat. --- 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); });