Skip to content

Commit

Permalink
INTERVAL / TIMEOUT can now be set by Meteor.settings.public.presenceI…
Browse files Browse the repository at this point in the history
…nterval, and Meteor.settings.presenceTimeout respectively.
  • Loading branch information
nathan-muir committed Oct 10, 2013
1 parent b1a1e08 commit 97393b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 6 additions & 4 deletions presence_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
//
var computation = null;
var interval = null;
var INTERVAL = 1000;
if (typeof Meteor.settings !== "undefined" && typeof Meteor.settings.public !== "undefined"){
INTERVAL = Meteor.settings.public.presenceInterval || INTERVAL;
}
Meteor.Presence = {
// The presnce will contained in, which will be reset to null
// when they close the browser tab or log off
Expand All @@ -22,14 +26,12 @@ Meteor.Presence = {
Session.set('last-presence-set-at', new Date());
},

INTERVAL: 1000,

start: function(){
Meteor.Presence.stop();
// update presences every interval
interval = Meteor.setInterval(function() {
Meteor.Presence.update();
}, Meteor.Presence.INTERVAL);
}, INTERVAL);
// this is code that actually does it.
computation = Meteor.autorun(refreshPresence);
},
Expand Down Expand Up @@ -96,7 +98,7 @@ if (Meteor._reload) {
}
})();
}
// wait until startup so that client code can set their own INTERVAL & state function
// wait until startup so that client code can set their own state function
Meteor.startup(function(){
Meteor.Presence.start();
});
12 changes: 10 additions & 2 deletions presence_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ Meteor.methods({
});

var interval = null;
var INTERVAL = 1000;
var TIMEOUT = 10000;
if (typeof Meteor.settings !== "undefined"){
TIMEOUT = Meteor.settings.presenceTimeout || TIMEOUT;
if (typeof Meteor.settings.public !== "undefined"){
INTERVAL = Meteor.settings.public.presenceInterval || INTERVAL;
}
}
Meteor.Presence = {
INTERVAL: 1000,
TIMEOUT: 10000,
Expand All @@ -42,9 +50,9 @@ Meteor.Presence = {
Meteor.clearInterval(interval)
}
interval = Meteor.setInterval(function() {
var since = new Date(new Date().getTime() - Meteor.Presence.TIMEOUT);
var since = new Date(new Date().getTime() - TIMEOUT);
Meteor.presences.remove({lastSeen: {$lt: since}});
}, Meteor.Presence.INTERVAL);
}, INTERVAL);
}
};

Expand Down

0 comments on commit 97393b9

Please sign in to comment.