]> git.cworth.org Git - zombocom-ai/blobdiff - index.js
Add a reuse button
[zombocom-ai] / index.js
index 2c980dc796d3d1992db34646ed09d46e8de64c08..55e17982786b27ad39ce47568dfe13cf18a39e02 100644 (file)
--- a/index.js
+++ b/index.js
@@ -77,19 +77,22 @@ io.on('connection', (socket) => {
 
     // Replay old comments and images to a newly-joining client
     socket.emit('reset');
-    state.comments.forEach((comment) => {
-        socket.emit('comment', comment)
-    });
     state.images.forEach((image) => {
         socket.emit('image', image)
     });
+    state.comments.forEach((comment) => {
+        socket.emit('comment', comment)
+    });
 
     socket.on('set-name', (name) => {
+        console.log("Received set-name event: " + name);
         socket.request.session.name = name;
+        socket.request.session.save();
     });
 
     // When any client comments, send that to all clients (including sender)
     socket.on('comment', (comment) => {
+        comment.name = socket.request.session.name;
         io.emit('comment', comment);
         state.comments.push(comment);
     });
@@ -108,7 +111,7 @@ io.on('connection', (socket) => {
             child.stdout.on('data', (data) => {
                 const images = JSON.parse(data);
                 images.forEach((image) => {
-                    console.log(`Emitting image to clients: ${image}`);
+                    image.index = state.images.length;
                     io.emit('image', image);
                     state.images.push(image);
                 });