Immediately commit if we're currently terminating

This commit is contained in:
Jonathan Putney
2020-06-29 21:12:27 -04:00
parent 2a3f9b61af
commit 97070184b8
7 changed files with 47 additions and 23 deletions
+21 -9
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -3
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -15,7 +15,7 @@ module.exports = function(grunt) {
watch: { watch: {
scripts: { scripts: {
files: ['src/**/*.js'], files: ['src/**/*.js'],
tasks: ['browserify:development'], tasks: ['default'],
options: { options: {
spawn: false, spawn: false,
}, },
+19 -7
View File
@@ -145,10 +145,11 @@ export default class BaseAPI {
this.currentState = global_constants.STATE_TERMINATED; this.currentState = global_constants.STATE_TERMINATED;
const result = this.storeData(true); const result = this.storeData(true);
if (typeof result.errorCode !== 'undefined' && result.errorCode > 0) { if (!this.settings.sendBeaconCommit && !this.settings.asyncCommit &&
typeof result.errorCode !== 'undefined' && result.errorCode > 0) {
this.throwSCORMError(result.errorCode); this.throwSCORMError(result.errorCode);
} }
returnValue = result.result ? returnValue = (typeof result !== 'undefined' && result.result) ?
result.result : global_constants.SCORM_FALSE; result.result : global_constants.SCORM_FALSE;
if (checkTerminated) this.lastErrorCode = 0; if (checkTerminated) this.lastErrorCode = 0;
@@ -269,10 +270,11 @@ export default class BaseAPI {
if (this.checkState(checkTerminated, this.#error_codes.COMMIT_BEFORE_INIT, if (this.checkState(checkTerminated, this.#error_codes.COMMIT_BEFORE_INIT,
this.#error_codes.COMMIT_AFTER_TERM)) { this.#error_codes.COMMIT_AFTER_TERM)) {
const result = this.storeData(false); const result = this.storeData(false);
if (result.errorCode && result.errorCode > 0) { if (!this.settings.sendBeaconCommit && !this.settings.asyncCommit &&
result.errorCode && result.errorCode > 0) {
this.throwSCORMError(result.errorCode); this.throwSCORMError(result.errorCode);
} }
returnValue = result.result ? returnValue = (typeof result !== 'undefined' && result.result) ?
result.result : global_constants.SCORM_FALSE; result.result : global_constants.SCORM_FALSE;
this.apiLog(callbackName, 'HttpRequest', ' Result: ' + returnValue, this.apiLog(callbackName, 'HttpRequest', ' Result: ' + returnValue,
@@ -925,9 +927,10 @@ export default class BaseAPI {
* Send the request to the LMS * Send the request to the LMS
* @param {string} url * @param {string} url
* @param {object|Array} params * @param {object|Array} params
* @param {boolean} immediate
* @return {object} * @return {object}
*/ */
processHttpRequest(url: String, params) { processHttpRequest(url: String, params, immediate = false) {
const process = function(url, params, settings, error_codes) { const process = function(url, params, settings, error_codes) {
const genericError = { const genericError = {
'result': global_constants.SCORM_FALSE, 'result': global_constants.SCORM_FALSE,
@@ -992,9 +995,18 @@ export default class BaseAPI {
}; };
if (typeof debounce !== 'undefined') { if (typeof debounce !== 'undefined') {
const debounced = debounce(process, 5000); const debounced = debounce(process, 500);
debounced(url, params, this.settings, this.error_codes);
return debounced(url, params, this.settings, this.error_codes); // if we're terminating, go ahead and commit immediately
if (immediate) {
debounced.flush();
}
return {
result: global_constants.SCORM_TRUE,
errorCode: 0,
};
} else { } else {
return process(url, params, this.settings, this.error_codes); return process(url, params, this.settings, this.error_codes);
} }
+1 -1
View File
@@ -302,7 +302,7 @@ export default class Scorm12API extends BaseAPI {
(terminateCommit ? 'yes' : 'no') + '): '); (terminateCommit ? 'yes' : 'no') + '): ');
console.debug(commitObject); console.debug(commitObject);
} }
return this.processHttpRequest(this.settings.lmsCommitUrl, commitObject); return this.processHttpRequest(this.settings.lmsCommitUrl, commitObject, terminateCommit);
} else { } else {
console.log('Commit (terminated: ' + console.log('Commit (terminated: ' +
(terminateCommit ? 'yes' : 'no') + '): '); (terminateCommit ? 'yes' : 'no') + '): ');
+1 -1
View File
@@ -553,7 +553,7 @@ export default class Scorm2004API extends BaseAPI {
console.debug(commitObject); console.debug(commitObject);
} }
const result = this.processHttpRequest(this.settings.lmsCommitUrl, const result = this.processHttpRequest(this.settings.lmsCommitUrl,
commitObject); commitObject, terminateCommit);
// check if this is a sequencing call, and then call the necessary JS // check if this is a sequencing call, and then call the necessary JS
{ {