]> git.cworth.org Git - zombocom-ai/commitdiff
Send along the user's name with each comment made
authorCarl Worth <cworth@cworth.org>
Thu, 8 Dec 2022 07:32:15 +0000 (23:32 -0800)
committerCarl Worth <cworth@cworth.org>
Thu, 8 Dec 2022 07:32:15 +0000 (23:32 -0800)
So we can actually tell who said what in the chat.

index.html
index.js

index 9989e40608f5946a60353e6f85b6df2bde206410..6173a6879b0ef229b24268845b3dfaba08c33bde 100644 (file)
@@ -78,8 +78,8 @@
     <div id="images">
     </div>
 
-    <ul id="comments">
-    </ul>
+    <dl id="comments">
+    </dl>
 
     <p>
       <form action="" id="comment-form">
@@ -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) => {
index 0b854a66bcd9643590393b418a8f3125c61241f1..1239ea2fab43360d621942d40ecd95cacced79f3 100644 (file)
--- 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);
     });