SCORM = true;
SCORM_INITED = false;
-SCORM_START_TIME = null;
+SCORM_START_TIME = 0;
SCORM_INTERACTION_TIMESTAMPS = [];
SCORM_CORRECT_ANSWERS = [];
SCORM_ID_TO_N = {};
SCORM_INTERACTIONS_INITED = false;
SCORM_LOCATION_INITED = false;
SCORM_OK = false;
+SCORM_TIME_ELAPSED = 0;
+SCORM_LAST_ACTIVITY = (new Date()).getTime();
var _CMI12 = {
'location': 'cmi.core.lesson_location',
finishScorm();
});
+ $(document).on('mousemove touchmove', function () {
+ resetInactivityTimer();
+ startScormTimer();
+ });
+
+ setInterval(function () {
+ let inactivity = Math.round(((new Date()).getTime() - SCORM_LAST_ACTIVITY) / 1000);
+ if (inactivity > 15) {
+ pauseScormTimer();
+ }
+ if (inactivity > 300) {
+ finishScorm();
+ scormClose();
+ }
+ }, 10000);
+
+ $(window).on('blur', function () {
+ pauseScormTimer();
+ });
+
+ $(window).on('focus', function () {
+ startScormTimer();
+ });
+
if (SCORM_LOCATION_INITED) {
return;
}
}
function startScormTimer() {
- SCORM_START_TIME = new Date();
+ if (SCORM_START_TIME === 0) {
+ console.log('start timer');
+ SCORM_START_TIME = new Date().getTime();
+ }
+}
+
+function pauseScormTimer() {
+ if (SCORM_START_TIME === 0) {
+
+ return;
+ }
+ console.log('pause timer');
+ var currentTime = new Date().getTime();
+ SCORM_TIME_ELAPSED += (currentTime - SCORM_START_TIME);
+ SCORM_START_TIME = 0;
+}
+
+function resetInactivityTimer() {
+ SCORM_LAST_ACTIVITY = new Date().getTime();
}
function scormComplete() {
if (!SCORM_OK) {
return;
}
- var currentTime = new Date();
+
var sessionTime;
- var endTime = currentTime.getTime()
- var calculatedTime = endTime - SCORM_START_TIME;
+ pauseScormTimer();
+ let calculatedTime = SCORM_TIME_ELAPSED;
if (pipwerks.SCORM.version == '1.2') {
var totalHours = Math.floor(calculatedTime / 1000 / 60 / 60);