Skip to content

Commit

Permalink
Fix: set exit state on initialisation to negate SCORM 2004 runtime da…
Browse files Browse the repository at this point in the history
…ta being reset on relaunch if disconnected whilst course widow is closed (fixes #320).
  • Loading branch information
danielghost committed Dec 9, 2024
1 parent 9dbfaff commit 3fe73d1
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions js/scorm/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class ScormWrapper {

this.startTime = new Date();
this.initTimedCommit();
this.setExitState();
return this.lmsConnected;
}

Expand Down Expand Up @@ -289,6 +290,8 @@ class ScormWrapper {
return;
}

this.setSessionTime();

if (this.scorm.save()) {
this.commitRetries = 0;
this.lastCommitSuccessTime = new Date();
Expand Down Expand Up @@ -335,15 +338,8 @@ class ScormWrapper {
this.logOutputWin.close();
}

this.endTime = new Date();

if (this.isSCORM2004()) {
this.scorm.set('cmi.session_time', this.convertToSCORM2004Time(this.endTime.getTime() - this.startTime.getTime()));
this.scorm.set('cmi.exit', this.getExitState());
} else {
this.scorm.set('cmi.core.session_time', this.convertToSCORM12Time(this.endTime.getTime() - this.startTime.getTime()));
this.scorm.set('cmi.core.exit', this.getExitState());
}
this.setSessionTime();
this.setExitState();

if (this._connection) {
this._connection.stop();
Expand Down Expand Up @@ -940,6 +936,15 @@ class ScormWrapper {
return response.join(',');
}

setSessionTime() {
const endTime = new Date();
if (this.isSCORM2004()) {
this.setValue('cmi.session_time', this.convertToSCORM2004Time(endTime.getTime() - this.startTime.getTime()));
} else {
this.setValue('cmi.core.session_time', this.convertToSCORM12Time(endTime.getTime() - this.startTime.getTime()));
}
}

getExitState() {
const completionStatus = this.scorm.data.completionStatus;
const isIncomplete = completionStatus === COMPLETION_STATE.INCOMPLETE.asLowerCase || completionStatus === COMPLETION_STATE.UNKNOWN.asLowerCase;
Expand All @@ -949,6 +954,11 @@ class ScormWrapper {
return '';
}

setExitState() {
const dataModel = this.isSCORM2004() ? 'cmi.exit' : 'cmi.core.exit';
this.setValue(dataModel, this.getExitState());
}

}

// static
Expand Down

0 comments on commit 3fe73d1

Please sign in to comment.