Javascript for session timeout

Javascript for session timeout

by Ronald Vyhmeister -
Number of replies: 11

Is there any way from JavaScript to read the time remaining in the session timeout? Alternatively, is there some way to reset the session timeout?

Thanks in advance!

Average of ratings: -
In reply to Ronald Vyhmeister

Re: Javascript for session timeout

by Andreas Grabs -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi Ronald,

maybe this could be interesting for you:
https://moodle.org/plugins/local_session_keepalive

Best regards
Andreas

In reply to Andreas Grabs

Re: Javascript for session timeout

by Ronald Vyhmeister -
Hi Andreas,

I looked at this... this plugin runs on PhP and just keeps the session going forever... I do want the session to timeout... and I don't want to modify the source code... Unfortunately the additional HTML (javascript) that we put in the system for the headers or body does not get pumped into the SCORM package which is launched in an iframe...
In reply to Ronald Vyhmeister

Re: Javascript for session timeout

by Andreas Grabs -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi Ronald,

the Plugin does not keep the session alive forever. It checks keystrokes on form inputs and if so it send a keep alive.

I thought you could use this as an example. You simply have to define in what condition the session should be stay. For example you could check whether or not a scorm iframe exists.

There would be no core code modification at all.

Best regards
Andreas

In reply to Andreas Grabs

Re: Javascript for session timeout

by Ronald Vyhmeister -
Hmmm... I installed the plugin (Moodle 3.9)... and have a funny thing happen... given I have a test site,

I set the systemwide session timeout to 2 minutes and the warning on the keepalive to 1 minute... When in a normal page, both the keepalive warning (at 1 minute) and the session timeout warning (from Moodle) just before 2 minutes work as expected.

The odd thing is that if I open a SCORM package, I can leave it idle for 5 minutes... or whatever duration, and my Moodle session does not timeout any more! Not exactly the desired behavior either...Any ideas?
In reply to Ronald Vyhmeister

Re: Javascript for session timeout

by Ken Task -
Picture of Particularly helpful Moodlers

SCORMS are different ... the client/student running the SCORM behind the scenes sends a 'checknet.txt' to the Moodle ... kinda like a ping ... to say am still using SCORM.   Check your access logs for a checknet.txt.   As long as the client/student doesn't click something in that SCORM that submits the SCORM tracking back and/or a button that basically says am finish to moodle, a SCORM session will last a long time.   Longer than normal time outs.

'SoS', Ken


In reply to Ken Task

Re: Javascript for session timeout

by Ronald Vyhmeister -

Thanks for the feedback... I don't find any checknet.txt in the access logs... and the weird thing we're having happen is that people leave the SCORM package open forever... and wind up with the learning not being recorded properly... 

If the SCORM package keeps the connection open, then why does the learning not get recorded? Weird!

In reply to Ronald Vyhmeister

Re: Javascript for session timeout

by Ronald Vyhmeister -
Think we've found the issue... we have a couple of LONG SCORM packages... and users put machines to sleep/hibernation... and come back hours later... so SCORM is still active... but the session has been lost due to timeout... oh, the joys of creative users!
Average of ratings: Useful (1)
In reply to Ronald Vyhmeister

Re: Javascript for session timeout

by Ronald Vyhmeister -
OK... So more (and hopefully final) data... The problem occurs ONLY when a machine goes to sleep... if the machine is hibernated, the SCORM player will detect the dropped network connection and terminate the playing upon restart...

So we've written a script that we've inserted in the additional HTML headers... This script will detect when there is a time gap (when can only be caused by sleeping)... and then prompt the user to close the SCORM window and restart it.

We realize that this approach may nail a user that put their machine to sleep to move from one room to another... but they're two clicks away from being back to where they left off... and it totally avoids the problem of the user who left the SCORM package running and returned many hours later... and then screams because their progress is lost...

So here's the script for those who may want it. Will only run in the SCORM player...

Hope this helps somebody in the future!
In reply to Ronald Vyhmeister

Re: Javascript for session timeout

by Richard Pochepan -

Hi Ronald,

How may I view the script which you referred to in your previous post?

Thanks!

In reply to Richard Pochepan

Re: Javascript for session timeout

by Ronald Vyhmeister -
Sorry... had not realized it hadn't pasted properly... here goes... This does not look at the timeout... it essentially says "you put your machine to sleep, so we don't know about timeouts, so restart the SCORM package".

Note that apparently Safari on mobile devices (iPads and iPhones) puts javascript to sleep whenever you go do something else... so you have this alert...


$(document).ready(function () {
//get current page's url
var url = window.location.href;
// detect if we are on the SCORM player page
if (url.includes('player.php')) {
// initialize the saved time
var saveDte = Date.now()
function checkTime() {
//get current time
var currentDte = Date.now();
// if the time elapsed is more than 11 seconds, then there was a time issue
var elapsedTime = ((currentDte - saveDte) / 1000);
if(elapsedTime > 11) {
console.log(elapsedTime + ' seconds' );
alert('Your computer appears to have gone to sleep. Please click ok to close this window and return to Moodle. You can resume your training by selecting the course link in Moodle.');
window.close();
} else {
console.log('date ok');
console.log(elapsedTime + ' seconds' );
//set new save date
saveDte = currentDte;
}
}
var timeoutId = setInterval(checkTime, 10000);
}
});
In reply to Ronald Vyhmeister

Re: Javascript for session timeout

by Colin Fraser -
There is no specific script to be able to read remaining time in a session AFAIK, but we used to be able to reset session times in the Admin > Session Handling page. Also, we used to be able to reset the session timeout in the >moodle>admin>server.php file, but... I'm not sure this is available any more - been a while since I looked at it,