Adding new selfReportSessionTime setting

This commit is contained in:
Jonathan Putney
2020-06-26 14:50:33 -04:00
parent aa03f6affb
commit ca94ee9fb5
12 changed files with 643 additions and 500 deletions

View File

@@ -62,6 +62,7 @@ export function checkValidRange(
export class BaseCMI {
jsonString = false;
#initialized = false;
#start_time;
/**
* Constructor for BaseCMI, just marks the class as abstract
@@ -80,12 +81,28 @@ export class BaseCMI {
return this.#initialized;
}
/**
* Getter for #start_time
* @return {Number}
*/
get start_time() {
return this.#start_time;
}
/**
* Called when the API has been initialized after the CMI has been created
*/
initialize() {
this.#initialized = true;
}
/**
* Called when the player should override the 'session_time' provided by
* the module
*/
setStartTime() {
this.#start_time = new Date().getTime();
}
}
/**

View File

@@ -11,6 +11,7 @@ import ErrorCodes from '../constants/error_codes';
import Regex from '../constants/regex';
import {ValidationError} from '../exceptions';
import * as Utilities from '../utilities';
import * as Util from '../utilities';
const scorm12_constants = APIConstants.scorm12;
const scorm12_regex = Regex.scorm12;
@@ -254,7 +255,7 @@ export class CMI extends BaseCMI {
* @return {string}
*/
getCurrentTotalTime() {
return this.core.getCurrentTotalTime();
return this.core.getCurrentTotalTime(this.start_time);
}
}
@@ -508,13 +509,21 @@ class CMICore extends BaseCMI {
/**
* Adds the current session time to the existing total time.
*
* @param {Number} start_time
* @return {string}
*/
getCurrentTotalTime() {
getCurrentTotalTime(start_time: Number) {
let sessionTime = this.#session_time;
const startTime = start_time;
if (typeof startTime !== 'undefined' || startTime === null) {
const seconds = new Date().getTime() - startTime;
sessionTime = Util.getSecondsAsHHMMSS(seconds / 1000);
}
return Utilities.addHHMMSSTimeStrings(
this.#total_time,
this.#session_time,
sessionTime,
new RegExp(scorm12_regex.CMITimespan),
);
}

View File

@@ -431,7 +431,8 @@ export class CMI extends BaseCMI {
* @param {string} suspend_data
*/
set suspend_data(suspend_data) {
if (check2004ValidFormat(suspend_data, scorm2004_regex.CMIString64000, true)) {
if (check2004ValidFormat(suspend_data, scorm2004_regex.CMIString64000,
true)) {
this.#suspend_data = suspend_data;
}
}
@@ -476,9 +477,17 @@ export class CMI extends BaseCMI {
* @return {string} ISO8601 Duration
*/
getCurrentTotalTime() {
let sessionTime = this.#session_time;
const startTime = this.start_time;
if (typeof startTime !== 'undefined' || startTime === null) {
const seconds = new Date().getTime() - startTime;
sessionTime = Util.getSecondsAsISODuration(seconds / 1000);
}
return Util.addTwoDurations(
this.#total_time,
this.#session_time,
sessionTime,
scorm2004_regex.CMITimespan,
);
}
@@ -966,7 +975,8 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} description
*/
set description(description) {
if (check2004ValidFormat(description, scorm2004_regex.CMILangString250, true)) {
if (check2004ValidFormat(description, scorm2004_regex.CMILangString250,
true)) {
this.#description = description;
}
}
@@ -1121,7 +1131,8 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} description
*/
set description(description) {
if (check2004ValidFormat(description, scorm2004_regex.CMILangString250, true)) {
if (check2004ValidFormat(description, scorm2004_regex.CMILangString250,
true)) {
this.#description = description;
}
}
@@ -1257,7 +1268,8 @@ export class CMICommentsObject extends BaseCMI {
if (this.initialized && this.#readOnlyAfterInit) {
throwReadOnlyError();
} else {
if (check2004ValidFormat(comment, scorm2004_regex.CMILangString4000, true)) {
if (check2004ValidFormat(comment, scorm2004_regex.CMILangString4000,
true)) {
this.#comment = comment;
}
}