-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a presence collection so we can track non-logged in users.
- Loading branch information
Showing
7 changed files
with
34 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.0 -- moved over to a presence collection so we could track more than one presence per user and presences of non-logged in users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Meteor.presences = new Meteor.Collection('presences'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
PRESENCE_TIMEOUT_MS = 10000; | ||
PRESENCE_INTERVAL = 1000; | ||
|
||
|
||
|
||
// a method to indicate that the user is still online | ||
Meteor.methods({ | ||
setPresence: function(state) { | ||
if (Meteor.userId()) { | ||
Meteor.users.update(Meteor.userId(), {$set: {presence: { | ||
state: state, | ||
lastSeen: new Date() | ||
}}}); | ||
} | ||
setPresence: function(sessionId, state) { | ||
Meteor.presences.update({ | ||
sessionId: sessionId | ||
}, {$set: { | ||
userId: Meteor.userId(), | ||
state: state, | ||
lastSeen: new Date() | ||
}}, { | ||
upsert: true | ||
}); | ||
} | ||
}); | ||
|
||
Meteor.setInterval(function() { | ||
|
||
// set all users who we haven't seen for a while to not be present | ||
var match = { | ||
'presence.lastSeen': {$lt: new Date(new Date().getTime() - PRESENCE_TIMEOUT_MS)}, | ||
'presence.state': {$exists: true} | ||
}; | ||
|
||
Meteor.users.update(match, {$unset: {'presence.state': true}}); | ||
var since = new Date(new Date().getTime() - PRESENCE_TIMEOUT_MS); | ||
Meteor.presences.remove({lastSeen: {$lt: since}}); | ||
}, PRESENCE_INTERVAL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters