Immediately commit if we're currently terminating
This commit is contained in:
30
dist/scorm-again.js
vendored
30
dist/scorm-again.js
vendored
File diff suppressed because one or more lines are too long
2
dist/scorm-again.js.map
vendored
2
dist/scorm-again.js.map
vendored
File diff suppressed because one or more lines are too long
6
dist/scorm-again.min.js
vendored
6
dist/scorm-again.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -15,7 +15,7 @@ module.exports = function(grunt) {
|
||||
watch: {
|
||||
scripts: {
|
||||
files: ['src/**/*.js'],
|
||||
tasks: ['browserify:development'],
|
||||
tasks: ['default'],
|
||||
options: {
|
||||
spawn: false,
|
||||
},
|
||||
|
||||
@@ -145,10 +145,11 @@ export default class BaseAPI {
|
||||
this.currentState = global_constants.STATE_TERMINATED;
|
||||
|
||||
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);
|
||||
}
|
||||
returnValue = result.result ?
|
||||
returnValue = (typeof result !== 'undefined' && result.result) ?
|
||||
result.result : global_constants.SCORM_FALSE;
|
||||
|
||||
if (checkTerminated) this.lastErrorCode = 0;
|
||||
@@ -269,10 +270,11 @@ export default class BaseAPI {
|
||||
if (this.checkState(checkTerminated, this.#error_codes.COMMIT_BEFORE_INIT,
|
||||
this.#error_codes.COMMIT_AFTER_TERM)) {
|
||||
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);
|
||||
}
|
||||
returnValue = result.result ?
|
||||
returnValue = (typeof result !== 'undefined' && result.result) ?
|
||||
result.result : global_constants.SCORM_FALSE;
|
||||
|
||||
this.apiLog(callbackName, 'HttpRequest', ' Result: ' + returnValue,
|
||||
@@ -925,9 +927,10 @@ export default class BaseAPI {
|
||||
* Send the request to the LMS
|
||||
* @param {string} url
|
||||
* @param {object|Array} params
|
||||
* @param {boolean} immediate
|
||||
* @return {object}
|
||||
*/
|
||||
processHttpRequest(url: String, params) {
|
||||
processHttpRequest(url: String, params, immediate = false) {
|
||||
const process = function(url, params, settings, error_codes) {
|
||||
const genericError = {
|
||||
'result': global_constants.SCORM_FALSE,
|
||||
@@ -992,9 +995,18 @@ export default class BaseAPI {
|
||||
};
|
||||
|
||||
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 {
|
||||
return process(url, params, this.settings, this.error_codes);
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ export default class Scorm12API extends BaseAPI {
|
||||
(terminateCommit ? 'yes' : 'no') + '): ');
|
||||
console.debug(commitObject);
|
||||
}
|
||||
return this.processHttpRequest(this.settings.lmsCommitUrl, commitObject);
|
||||
return this.processHttpRequest(this.settings.lmsCommitUrl, commitObject, terminateCommit);
|
||||
} else {
|
||||
console.log('Commit (terminated: ' +
|
||||
(terminateCommit ? 'yes' : 'no') + '): ');
|
||||
|
||||
@@ -553,7 +553,7 @@ export default class Scorm2004API extends BaseAPI {
|
||||
console.debug(commitObject);
|
||||
}
|
||||
const result = this.processHttpRequest(this.settings.lmsCommitUrl,
|
||||
commitObject);
|
||||
commitObject, terminateCommit);
|
||||
|
||||
// check if this is a sequencing call, and then call the necessary JS
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user