Using the scormdriver.js to check continuous connection.

449 views
Skip to first unread message

Luke ODonnell

unread,
May 25, 2016, 7:12:48 PM5/25/16
to eLearning Technology and Development
Hi all

Try as I might, I just cant get an accurate result when checking to see if the learning module is connected to the LMS.

I am using Javascript in Captivate 8 and I am trying to check the connection every 10 minutes.
Our LMS times out after 30 mins.

Here is the code:

///////////////////////////////////////////////////////////////

if (typeof window.GetStudentName==='undefined'){
sName='Name Not Found';
myAlert();
} else {
sName=GetStudentName();
myAlert_happy();
if(sName===''){

sName='Name Not Found';
} else {

/* Uncomment the below line to show the name in 'First Last' format */
/* sName=sName.split(', ')[1] + ' ' + sName.split(', ')[0]; */
}
}
/* Check for HTML5 vs. SWF output */
if (typeof window.cp==='undefined') {
/* We have SWF output, so Get the Captivate Object */
var objCp=document.getElementById('Captivate');

/* Set the studentName Captivate User variable with the JavaScript variabe, sName */
if(objCp && objCp.cpEISetValue){
objCp.cpEISetValue('m_VarHandle.studentName', sName);
sName = null;
}
} else {
/* We have HTML5 output */
if(cp.vm && cp.vm.setVariableValue){
cp.vm.setVariableValue('studentName', sName);
sName = null;
}
}
}

/////////////////////////////////////////////////////////////////

I am using the GetStudentName function to see if and when the LMS has lost connection to my module.
This works great if I check localhoast - I get my alert function activating.
If I put this server side on my LMS as a SCO. It shows up as being connected so I get myAlert_happy activation. so that part is working fine. 
Its just that if I loose connection and the LMS times out, I still get the myAlert_happy. I am assuming its because the browser cache keeps the GetStudentName(); results and doesn't unload this.
Is there a way that I can force the cache to loose all of its data and check the GetStudentName(); 'afresh'?
Or am I going about this completely wrong?

Cheers
Luke



 

Philip Hutchison

unread,
May 25, 2016, 7:43:55 PM5/25/16
to elearning-technolo...@googlegroups.com
Hi Luke

If you need to know whether the user is still connected to the internet, don't trust the LMS. You can use a JS utility like this one: https://www.gavick.com/blog/detect-offline-browser or try to load a remote file via xmlhttprequest, as described here: http://stackoverflow.com/questions/2384167/check-if-internet-connection-exists-with-javascript

Why not trust the LMS? Because most LMSs handle the SCORM data asynchronously. 

When you first launch the course, the LMS gets the data from the database, then puts it into a JavaScript layer so SCORM can interact with it (the SCORM API). When you fetch data, you are typically fetching data that is in this JS layer, which was preloaded at the time the course was launched. Since it's JavaScript, it's loaded in the client.

Subsequent attempts to save data (commit) will first be stored in the JS layer on the client side, then pushed to the server via AJAX (xmlhttprequest) later. When you do a 'get' after a 'set', you are typically getting data from the JS layer -- the client side -- without the LMS actually checking the database to see if the data is there. This is what trips people up.

The LMS has no reason to re-fetch the saved data from the database, it assumes the data in the JS layer has been synchronized with the LMS database, so why bother making those extra trips to the DB? Just grab what's in the JS layer, handle everything on the client side. 

The submission process (SetValue) is typically asynchronous. This means the LMS will often return a 'true' value indicating the SetValue call was successful, but in reality it's actually telling you the SetValue was successful in the JavaScript layer and not necessarily persisted to the DB. There is no guarantee the data was successfully persisted in the database, and no guarantee the connection to the LMS is still intact.

LMSs are kind of forced to handle it this way. xmlhttprequest has two modes: synchronous and asynchronous. Submitting data synchronously means all other JavaScript operations will halt until the result of the xmlhttprequest submission is received. This can take seconds (as opposed to milliseconds), which gives the impression that the course locked up and is broken, especially if the course makes multiple SetValue calls per page. LMS vendors want to avoid making the courses feel broken, so they use asynchronous submissions instead, which means they wind up faking the outcome of the submission -- they always say it was successful, and may return this 'success' value before the xmlhttprequest has even finished processing. 

Getting back to your use case, if you're checking to see whether the connection is active, a simple GetValue will not be reliable, because the data is being returned by the JavaScript layer, which is already loaded in the client, and thus remains available even if the internet connection dies. 

So to check if the internet connection is active, use methods outside the LMS (see links above for two approaches). There is no reliable way to check if the LMS is still available, except to try to load files stored on the LMS via xmlhttprequest, which is probably to slow and impractical.

Hope that helps
- philip






--
You received this message because you are subscribed to the Google Groups "eLearning Technology and Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elearning-technology-and...@googlegroups.com.
Visit this group at https://groups.google.com/group/elearning-technology-and-development.
To view this discussion on the web visit https://groups.google.com/d/msgid/elearning-technology-and-development/401975dc-4c6e-4403-8f85-ba28cd1af29f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luke ODonnell

unread,
May 25, 2016, 9:15:00 PM5/25/16
to eLearning Technology and Development
Phillip Thanks,

Just as I suspected.

I will try the load image approach, I am sure that a 1px by 1px black gif will not be too taxing.
I can drop it into Captivate as an html5 packet that loads and unloads every 5 mins or so. If it doesn't load (3 times) then suffice to say connection is lost.

I'll let you know how I get on.

Thanks again for the insight. 

Luke

Luke ODonnell

unread,
May 25, 2016, 9:58:06 PM5/25/16
to eLearning Technology and Development
So this is what I will try first:

<html>

<script>
     function ImgLoad(myobj){
       var randomNum = Math.round(Math.random() * 10000);
       var oImg=new Image;
       oImg.src="AA.gif"+"?rand="+randomNum;
       oImg.onload=function(){networkstatus_div.innerHTML="";}
       oImg.onerror=function(){networkstatus_div.innerHTML="Service is not available. Please check your Internet connection!";}
}

networkchecker = window.setInterval(function(){window.onload=ImgLoad()},1000);
</script>

<div id="networkstatus_div"></div>

</body>
</html>

Philip Hutchison

unread,
May 25, 2016, 10:09:39 PM5/25/16
to elearning-technolo...@googlegroups.com
I suggest trying the first link I provided, it uses the browser's official 'offline' property which is well supported from IE9+. Less hoops to jump through. I'd only use xhr if the other method proves unreliable for some reason. 

--
You received this message because you are subscribed to the Google Groups "eLearning Technology and Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elearning-technology-and...@googlegroups.com.
Visit this group at https://groups.google.com/group/elearning-technology-and-development.

Luke ODonnell

unread,
May 25, 2016, 11:16:00 PM5/25/16
to eLearning Technology and Development
I would do that but for the security requirements of the organisation I work for.
We can't download without months of paperwork and explaining.

Thanks anyway Philip.

Luke ODonnell

unread,
May 26, 2016, 7:40:46 AM5/26/16
to elearning-technolo...@googlegroups.com
OK, that last test cracked it. I have a way to confirm a timeout.
Thanks heaps Philip.

--
You received this message because you are subscribed to a topic in the Google Groups "eLearning Technology and Development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elearning-technology-and-development/-M14BwQYqns/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elearning-technology-and...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Regards from Luke


Reply all
Reply to author
Forward
0 new messages