cmi.core.suspend_data vs. cmi.suspend_data

It seems to be a common issue that some SCORM 1.2 modules are trying to store "suspend_data" in cmi.core.suspend_data instead of cmi.suspend_data, which is actually the correct field according to the spec. We're still only storing it once, but will allow getting and setting from cmi.core.suspend_data. Exported JSON will continue to only output spec compliant data.
This commit is contained in:
Jonathan Putney
2020-02-06 12:35:49 -05:00
parent de91be85e2
commit 3103707aec
6 changed files with 87 additions and 34 deletions

60
dist/scorm-again.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
{
"name": "scorm-again",
"version": "1.0.2",
"version": "1.0.3",
"description": "A modern SCORM JavaScript run-time library for AICC, SCORM 1.2, and SCORM 2004",
"main": "dist/scorm-again.min.js",
"directories": {

View File

@@ -73,7 +73,6 @@ export function check12ValidRange(
export class CMI extends BaseCMI {
#_children = '';
#_version = '3.4';
#suspend_data = '';
#launch_data = '';
#comments = '';
#comments_from_lms = '';
@@ -91,7 +90,9 @@ export class CMI extends BaseCMI {
if (initialized) this.initialize();
this.#_children = cmi_children ? cmi_children : scorm12_constants.cmi_children;
this.#_children = cmi_children ?
cmi_children :
scorm12_constants.cmi_children;
this.core = new CMICore();
this.objectives = new CMIObjectives();
this.student_data = student_data ? student_data : new CMIStudentData();
@@ -182,7 +183,7 @@ export class CMI extends BaseCMI {
* @return {string}
*/
get suspend_data() {
return this.#suspend_data;
return this.core?.suspend_data;
}
/**
@@ -190,8 +191,8 @@ export class CMI extends BaseCMI {
* @param {string} suspend_data
*/
set suspend_data(suspend_data) {
if (check12ValidFormat(suspend_data, scorm12_regex.CMIString4096, true)) {
this.#suspend_data = suspend_data;
if (this.core) {
this.core.suspend_data = suspend_data;
}
}
@@ -297,6 +298,7 @@ class CMICore extends BaseCMI {
#lesson_mode = 'normal';
#exit = '';
#session_time = '00:00:00';
#suspend_data = '';
/**
* Getter for #_children
@@ -486,6 +488,24 @@ class CMICore extends BaseCMI {
}
}
/**
* Getter for #suspend_data
* @return {string}
*/
get suspend_data() {
return this.#suspend_data;
}
/**
* Setter for #suspend_data
* @param {string} suspend_data
*/
set suspend_data(suspend_data) {
if (check12ValidFormat(suspend_data, scorm12_regex.CMIString4096, true)) {
this.#suspend_data = suspend_data;
}
}
/**
* Adds the current session time to the existing total time.
*

View File

@@ -374,6 +374,17 @@ describe('SCORM 1.2 CMI Tests', () => {
fieldName: 'cmi.suspend_data',
valueToTest: '',
});
h.checkFieldConstraintSize({
cmi: cmiInitialized(),
fieldName: 'cmi.core.suspend_data',
limit: 4096,
expectedError: type_mismatch,
});
h.checkWrite({
cmi: cmiInitialized(),
fieldName: 'cmi.core.suspend_data',
valueToTest: '',
});
h.checkReadOnly({
cmi: cmiInitialized(),
fieldName: 'cmi.launch_data',