|
@ -5,6 +5,11 @@ |
|
|
|
|
|
|
|
|
src: readmongo/swarmlab-app/src/run/ |
|
|
src: readmongo/swarmlab-app/src/run/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== stream2mongo |
|
|
=== stream2mongo |
|
|
|
|
|
|
|
|
[source,javascript] |
|
|
[source,javascript] |
|
@ -56,6 +61,51 @@ After clients insert new additional documents into a capped collection, the tail |
|
|
[source,javascript] |
|
|
[source,javascript] |
|
|
---- |
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
const pubClient = new Redis({ |
|
|
|
|
|
host: REDIS, |
|
|
|
|
|
port: REDIS_PORT, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// read from redis |
|
|
|
|
|
async function getkey(id) { |
|
|
|
|
|
return new Promise((resolve) => { |
|
|
|
|
|
pubClient.get(id, function (err, reply) { |
|
|
|
|
|
if (err) { |
|
|
|
|
|
resolve(null); |
|
|
|
|
|
} else { |
|
|
|
|
|
if (reply) { |
|
|
|
|
|
//console.log("---------fount----------"); |
|
|
|
|
|
resolve(1); |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log("----------not fount------------"); |
|
|
|
|
|
resolve(2); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// check if stream exists |
|
|
|
|
|
async function checkstream(data) { |
|
|
|
|
|
var res = await getkey(data.id); |
|
|
|
|
|
if (res == "1") { |
|
|
|
|
|
console.log("Stream is on!"); |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log("Creating Stream...."); |
|
|
|
|
|
|
|
|
|
|
|
var url = URL; |
|
|
|
|
|
MongoClient.connect( |
|
|
|
|
|
url, |
|
|
|
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
|
|
|
function (err, db) { |
|
|
|
|
|
if (err) throw err; |
|
|
|
|
|
var dbo = db.db(DATABASE); |
|
|
|
|
|
dbo.collection(COLLECTION, onCollectionNew.bind(data)); |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
io.on("connection", (s) => { |
|
|
io.on("connection", (s) => { |
|
|
console.error("socket connection"); |
|
|
console.error("socket connection"); |
|
|
var usersession = new Object(); |
|
|
var usersession = new Object(); |
|
@ -91,6 +141,10 @@ io.on("connection", (s) => { |
|
|
user: data, |
|
|
user: data, |
|
|
id: s.id, |
|
|
id: s.id, |
|
|
}; |
|
|
}; |
|
|
|
|
|
checkstream(binddata); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
---- |
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|