|
@ -42,6 +42,57 @@ async function onCollectionNew(err, collection) { |
|
|
|
|
|
|
|
|
---- |
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
var cursor = collection.find({}, options).stream(); |
|
|
|
|
|
|
|
|
|
|
|
A Tailable Cursor *remains open* after the client exhausts the results in the initial cursor. |
|
|
|
|
|
|
|
|
|
|
|
Tailable cursors are conceptually equivalent to the *tail* Unix command with the *-f* option (i.e. with "follow" mode). |
|
|
|
|
|
|
|
|
|
|
|
After clients insert new additional documents into a capped collection, the tailable cursor will continue to retrieve documents. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== socket (open,event) |
|
|
|
|
|
|
|
|
|
|
|
[source,javascript] |
|
|
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
io.on("connection", (s) => { |
|
|
|
|
|
console.error("socket connection"); |
|
|
|
|
|
var usersession = new Object(); |
|
|
|
|
|
usersession.SOCKET = {}; |
|
|
|
|
|
usersession.SOCKET.error = {}; |
|
|
|
|
|
console.error("socket ..."); |
|
|
|
|
|
s.auth = false; |
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------ |
|
|
|
|
|
// --- authenticate |
|
|
|
|
|
// ------------------------------ |
|
|
|
|
|
s.on("authenticate", function (data) { |
|
|
|
|
|
const token = data; |
|
|
|
|
|
(async () => { |
|
|
|
|
|
var isvalid = await checkToken(token); |
|
|
|
|
|
if (isvalid.action == "ok") { |
|
|
|
|
|
usersession.SOCKET.user = isvalid.user; |
|
|
|
|
|
usersession.SOCKET.scope = isvalid.scope; // space delimeter |
|
|
|
|
|
usersession.SOCKET.token = isvalid.token; |
|
|
|
|
|
usersession.SOCKET.id = s.id; |
|
|
|
|
|
s.auth = true; |
|
|
|
|
|
} else { |
|
|
|
|
|
s.auth = false; |
|
|
|
|
|
} |
|
|
|
|
|
})(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------ |
|
|
|
|
|
// --- event |
|
|
|
|
|
// ------------------------------ |
|
|
|
|
|
s.on("onevent", function (data) { |
|
|
|
|
|
var binddata = { |
|
|
|
|
|
user: data, |
|
|
|
|
|
id: s.id, |
|
|
|
|
|
}; |
|
|
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== restart |
|
|
=== restart |
|
|
|
|
|
|
|
|