Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: SCORM 2004 runtime data reset if disconnected on exit #323

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
return;
}
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 property = this.isSCORM2004() ? 'cmi.exit' : 'cmi.core.exit';
this.setValue(property, this.getExitState());
}

}

// static
Expand Down