-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathclient.js
41 lines (36 loc) · 1.33 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// Client side activity detection for the session timeout
// - depends on jquery
//
// Meteor settings:
// - staleSessionHeartbeatInterval: interval (in ms) at which activity heartbeats are sent up to the server
// - staleSessionActivityEvents: the jquery events which are considered indicator of activity e.g. in an on() call.
//
var heartbeatInterval = Meteor.settings && Meteor.settings.public && Meteor.settings.public.staleSessionHeartbeatInterval || (3*60*1000); // 3mins
var activityEvents = Meteor.settings && Meteor.settings.public && Meteor.settings.public.staleSessionActivityEvents || 'mousemove click keydown';
var activityDetected = false;
Meteor.startup(function() {
//
// periodically send a heartbeat if activity has been detected within the interval
//
Meteor.setInterval(function() {
if (Meteor.userId() && activityDetected) {
Meteor.call('heartbeat');
activityDetected = false;
}
}, heartbeatInterval);
//
// detect activity and mark it as detected on any of the following events
//
$(document).on(activityEvents, function() {
activityDetected = true;
});
//
// ensure a heartbeat is sent when the user first logs in
//
Tracker.autorun(function(){
if(Meteor.userId()){
Meteor.call('heartbeat');
}
});
});