Skip to content

Instantly share code, notes, and snippets.

@yayitswei
Created March 22, 2016 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yayitswei/c1efdce6bfa2fc16b548 to your computer and use it in GitHub Desktop.
Save yayitswei/c1efdce6bfa2fc16b548 to your computer and use it in GitHub Desktop.
(defn start-autologout-monitoring []
(let [activity-ch (async/chan)]
(.ready
($ js/document)
(fn []
(this-as
this
(.mousemove ($ this) (fn [_] (go (>! activity-ch true))))
(.keypress ($ this) (fn [_] (go (>! activity-ch true))))
(go
(loop []
(let [[v p] (async/alts! [(async/timeout 5000) activity-ch])]
(if v (recur))))
(.open js/window "/logout")))))))
// source: http://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly
var idleTime = 0;
$(document).ready(function () {
//Increment the idle time counter every minute.
var idleInterval = setInterval(timerIncrement, 60000); // 1 minute
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
idleTime = 0;
});
});
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime > 19) { // 20 minutes
window.location.reload();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment