Browse Source

One stream per User

master
lefteris 4 years ago
parent
commit
8b4ee9260a
  1. 46
      swarmlab-app/src/run/app.js

46
swarmlab-app/src/run/app.js

@ -136,7 +136,7 @@ var curRoom;
// dbo.collection("test", onCollectionNew); // 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 Prepei na elegxw kathe fora an to socket id tou user einai energo
wste na mhn diathreitai zwntanh h callback kai lamvanw dublicate wste na mhn diathreitai zwntanh h callback kai lamvanw dublicate
@ -154,18 +154,28 @@ function onCollectionNew(err, collection) {
var sid = this.id; var sid = this.id;
console.log("Inside callback: " + room + " Id: " + sid); console.log("Inside callback: " + room + " Id: " + sid);
// LEFOS --- STORE USER IN REDIS // LEFOS --- STORE USER IN REDIS
var rep = setUser(room, room); var rep = setUser(sid, room);
cursor.on("data", function (data) { cursor.on("data", async function (data) {
var obj = JSON.parse(JSON.stringify(data)); cursor.pause();
// var getres = getkey(sid); var res = await getkey(sid);
// if (getres == "1") {
// console.log("sending on event log"); if (res == "1") {
cursor.resume();
// } else if (getres == "2") { var obj = JSON.parse(JSON.stringify(data));
// cursor.close(); // var getres = getkey(sid);
// } // if (getres == "1") {
io.in(room).emit("logsend", obj); // 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) { s.on("onevent", function (data) {
console.log("I GOT THE DATA: ", data); //console.log("I GOT THE DATA: ", data);
var binddata = { var binddata = {
user: data, user: data,
id: s.id, id: s.id,
@ -227,7 +237,9 @@ io.on("connection", (s) => {
}); });
s.on("disconnect", function () { 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 () { setTimeout(function () {
@ -505,7 +517,7 @@ function onlogfile(path) {
} }
async function checkstream(data) { async function checkstream(data) {
var res = await getkey(data.user); var res = await getkey(data.id);
if (res == "1") { if (res == "1") {
console.log("Stream is on!"); console.log("Stream is on!");
} else { } else {
@ -911,7 +923,7 @@ async function getkey(id) {
resolve(null); resolve(null);
} else { } else {
if (reply) { if (reply) {
console.log("---------fount----------"); //console.log("---------fount----------");
resolve(1); resolve(1);
} else { } else {
console.log("----------not fount------------"); console.log("----------not fount------------");

Loading…
Cancel
Save