]> git.cworth.org Git - zombocom-ai/blobdiff - index.js
Add code to submit image generation instructions to the server
[zombocom-ai] / index.js
index 9279c877250c9e6055d142f9839dddd22dae775d..249537fd3414cd2541b16513901ab6eaeb68359a 100644 (file)
--- a/index.js
+++ b/index.js
@@ -8,7 +8,17 @@ const { Server } = require("socket.io");
 const io = new Server(server);
 const port = 2122;
 
-comments = [];
+const state_file = 'zombocom-state.json'
+
+var comments;
+
+// Load comments at server startup
+fs.readFile(state_file, (err, data) => {
+    if (err)
+        comments = [];
+    else
+        comments = JSON.parse(data);
+});
 
 // Save comments when server is shutting down
 function cleanup() {
@@ -32,15 +42,22 @@ app.get('/index.html', (req, res) => {
 });
 
 io.on('connection', (socket) => {
+
     // Replay old comments to a newly-joining client
     comments.forEach((comment) => {
         socket.emit('comment', comment)
     });
+
     // When any client comments, send that to all clients (including sender)
     socket.on('comment', (comment) => {
         io.emit('comment', comment);
         comments.push(comment);
     });
+
+    // Generate an image when requested
+    socket.on('generate', (request) => {
+        console.log(`Generating image with code=${request['code']} and prompt=${request['prompt']}`);
+    });
 });
 
 server.listen(port, () => {