Last active
January 19, 2022 11:01
-
-
Save jasonheecs/5f7efd8a62719da344ae23f7a62cfa9c to your computer and use it in GitHub Desktop.
Revisions
-
jasonheecs revised this gist
Aug 30, 2021 . 1 changed file with 22 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,27 @@ let heartBeatActivated = false; class HeartBeat { constructor() { document.addEventListener('DOMContentLoaded', () => { this.initHeartBeat(); }); } initHeartBeat() { this.lastActive = new Date().valueOf(); if (!heartBeatActivated) { ['mousemove', 'scroll', 'click', 'keydown'].forEach((activity) => { document.addEventListener(activity, (ev) => { this.lastActive = ev.timeStamp + performance.timing.navigationStart; }, false); }); heartBeatActivated = true; } } } window.heartBeat = new HeartBeat(); const sessionTimeoutPollFrequency = 5; function pollForSessionTimeout() { if ((Date.now() - window.heartBeat.lastActive) < (sessionTimeoutPollFrequency * 1000)) { return; -
jasonheecs revised this gist
Mar 11, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ const sessionTimeoutPollFrequency = 5; window.lastActive = new Date().valueOf(); ['mousemove', 'scroll', 'click', 'keydown'].forEach((activity) => { -
jasonheecs renamed this gist
Mar 11, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jasonheecs created this gist
Mar 11, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ window.lastActive = new Date().valueOf(); ['mousemove', 'scroll', 'click', 'keydown'].forEach((activity) => { document.addEventListener(activity, (ev) => { window.lastActive = ev.timeStamp + performance.timing.navigationStart; }, false); }); function pollForSessionTimeout() { if ((Date.now() - window.heartBeat.lastActive) < (sessionTimeoutPollFrequency * 1000)) { return; } let request = new XMLHttpRequest(); request.onload = function (event) { var status = event.target.status; var response = event.target.response; // if the remaining valid time for the current user session is less than or equals to 0 seconds. if (status === 200 && (response <= 0)) { window.location.href = '/session_timeout'; } }; request.open('GET', '/check_session_timeout', true); request.responseType = 'json'; request.send(); setTimeout(pollForSessionTimeout, (sessionTimeoutPollFrequency * 1000)); }