diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index 4b7c6e26..f3b64343 100644 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -136,7 +136,7 @@ var curRoom; // dbo.collection("test", onCollectionNew); // }); -function onCollectionNew(err, collection) { +async function onCollectionNew(err, collection) { /* Prepei na elegxw kathe fora an to socket id tou user einai energo wste na mhn diathreitai zwntanh h callback kai lamvanw dublicate @@ -154,18 +154,28 @@ function onCollectionNew(err, collection) { var sid = this.id; console.log("Inside callback: " + room + " Id: " + sid); // LEFOS --- STORE USER IN REDIS - var rep = setUser(room, room); - - cursor.on("data", function (data) { - var obj = JSON.parse(JSON.stringify(data)); - // var getres = getkey(sid); - // if (getres == "1") { - // console.log("sending on event log"); - - // } else if (getres == "2") { - // cursor.close(); - // } - io.in(room).emit("logsend", obj); + var rep = setUser(sid, room); + + cursor.on("data", async function (data) { + cursor.pause(); + var res = await getkey(sid); + + if (res == "1") { + cursor.resume(); + var obj = JSON.parse(JSON.stringify(data)); + // var getres = getkey(sid); + // if (getres == "1") { + // console.log("sending on event log"); + + // } else if (getres == "2") { + // cursor.close(); + // } + io.in(room).emit("logsend", obj); + } else if (res == "2") { + cursor.resume(); + console.log("Cursor is closing..."); + cursor.close(); + } }); } @@ -218,7 +228,7 @@ io.on("connection", (s) => { }); s.on("onevent", function (data) { - console.log("I GOT THE DATA: ", data); + //console.log("I GOT THE DATA: ", data); var binddata = { user: data, id: s.id, @@ -227,7 +237,9 @@ io.on("connection", (s) => { }); s.on("disconnect", function () { - console.log("Socket: " + s.id + " Disconnected"); + //console.log("Socket: " + s.id + " Disconnected"); + console.log("Deleting " + s.id + "From redis"); + pubClient.del(s.id); }); setTimeout(function () { @@ -505,7 +517,7 @@ function onlogfile(path) { } async function checkstream(data) { - var res = await getkey(data.user); + var res = await getkey(data.id); if (res == "1") { console.log("Stream is on!"); } else { @@ -911,7 +923,7 @@ async function getkey(id) { resolve(null); } else { if (reply) { - console.log("---------fount----------"); + //console.log("---------fount----------"); resolve(1); } else { console.log("----------not fount------------");