Browse Source

room with .bind()

master
lefteris 4 years ago
parent
commit
32216bb350
  1. 3
      swarmlab-app/src/package.json
  2. 46
      swarmlab-app/src/run/app.js

3
swarmlab-app/src/package.json

@ -7,7 +7,6 @@
"start": "node ./run/app.js"
},
"dependencies": {
"mongoose": "5.12.1",
"async": "^3.2.0",
"axios": "^0.20.0",
"bestikk-log": "^1.0.0-alpha.2",
@ -20,6 +19,8 @@
"ioredis": "^4.24.2",
"luxon": "^1.25.0",
"mongodb": "^3.6.3",
"mongoose": "5.12.1",
"node-global-storage": "^1.2.3",
"socket.io": "^4.0.0",
"socket.io-redis": "^6.1.0",
"url-exist-sync": "^1.0.2"

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

@ -128,12 +128,12 @@ console.log("reading from db....");
// Lefos-- variable poy krata to trexon room tou xrhsth kathe fora
var curRoom;
var url = "mongodb://mongo:27017/";
MongoClient.connect(url, function (err, db) {
if (err) throw err;
var dbo = db.db("fluentdb");
dbo.collection("test", onCollectionNew);
});
// var url = "mongodb://mongo:27017/";
// MongoClient.connect(url, function (err, db) {
// if (err) throw err;
// var dbo = db.db("fluentdb");
// dbo.collection("test", onCollectionNew);
// });
function onCollectionNew(err, collection) {
let options = {
@ -144,20 +144,13 @@ function onCollectionNew(err, collection) {
};
var cursor = collection.find({}, options).stream();
var itemsProcessed = 0;
var room = this;
console.log("Inside callback: " + room);
cursor.on("data", function (data) {
var obj = JSON.parse(JSON.stringify(data));
// obj.log = JSON.parse(obj.log);
// var jsonfinal = [];
// obj.forEach((value) => {
// if (value.log.includes("app_name")) {
// jsonfinal.push(JSON.parse(value.log));
// }
// });
// Pernaw karfota to room pros to paron
io.in(curRoom).emit("logsend", obj);
io.in(room).emit("logsend", obj);
});
}
@ -206,6 +199,26 @@ io.on("connection", (s) => {
})();
});
s.on("onevent", function (data) {
console.log("I GOT THE DATA: ", data);
var user = data;
console.log("reading from db....");
// var url = "mongodb://mongo:27017/";
// MongoClient.connect(url, function (err, db) {
// if (err) throw err;
// var dbo = db.db("fluentdb");
// dbo.collection("test", onCollectionNew);
// });
var url = "mongodb://mongo:27017/";
MongoClient.connect(url, function (err, db) {
if (err) throw err;
var dbo = db.db("fluentdb");
dbo.collection("test", onCollectionNew.bind(user));
});
});
setTimeout(function () {
if (!s.auth) {
console.log("Disconnecting timeout socket ", s.id);
@ -216,7 +229,6 @@ io.on("connection", (s) => {
s.join(room);
console.log("joining rooom", s.rooms);
console.log(room + " created ");
//LEFOS == Krataw to room gia na douleuei on event dunamika se kathe xrhsth
curRoom = room;
// });
}

Loading…
Cancel
Save