Fixing issue with commit callback not being called for scheduled commits
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
19969
package-lock.json
generated
19969
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "scorm-again",
|
||||
"version": "1.5.0",
|
||||
"version": "1.5.1",
|
||||
"description": "A modern SCORM JavaScript run-time library for AICC, SCORM 1.2, and SCORM 2004",
|
||||
"main": "dist/scorm-again.min.js",
|
||||
"directories": {
|
||||
|
||||
@@ -200,6 +200,7 @@ export default class BaseAPI {
|
||||
* Sets the value of the CMIElement.
|
||||
*
|
||||
* @param {string} callbackName
|
||||
* @param {string} commitCallback
|
||||
* @param {boolean} checkTerminated
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
@@ -207,6 +208,7 @@ export default class BaseAPI {
|
||||
*/
|
||||
setValue(
|
||||
callbackName: String,
|
||||
commitCallback: String,
|
||||
checkTerminated: boolean,
|
||||
CMIElement,
|
||||
value) {
|
||||
@@ -244,7 +246,7 @@ export default class BaseAPI {
|
||||
// schedule a commit, if autocommit is turned on
|
||||
if (String(this.lastErrorCode) === '0') {
|
||||
if (this.settings.autocommit && !this.#timeout) {
|
||||
this.scheduleCommit(this.settings.autocommitSeconds * 1000);
|
||||
this.scheduleCommit(this.settings.autocommitSeconds * 1000, commitCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1178,9 +1180,10 @@ export default class BaseAPI {
|
||||
* Throws a SCORM error
|
||||
*
|
||||
* @param {number} when - the number of milliseconds to wait before committing
|
||||
* @param {string} callback - the name of the commit event callback
|
||||
*/
|
||||
scheduleCommit(when: number) {
|
||||
this.#timeout = new ScheduledCommit(this, when);
|
||||
scheduleCommit(when: number, callback: string) {
|
||||
this.#timeout = new ScheduledCommit(this, when, callback);
|
||||
this.apiLog('scheduleCommit', '', 'scheduled',
|
||||
global_constants.LOG_LEVEL_DEBUG);
|
||||
}
|
||||
@@ -1205,15 +1208,18 @@ class ScheduledCommit {
|
||||
#API;
|
||||
#cancelled = false;
|
||||
#timeout;
|
||||
#callback;
|
||||
|
||||
/**
|
||||
* Constructor for ScheduledCommit
|
||||
* @param {BaseAPI} API
|
||||
* @param {number} when
|
||||
* @param {string} callback
|
||||
*/
|
||||
constructor(API: any, when: number) {
|
||||
constructor(API: any, when: number, callback: string) {
|
||||
this.#API = API;
|
||||
this.#timeout = setTimeout(this.wrapper.bind(this), when);
|
||||
this.#callback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1231,7 +1237,7 @@ class ScheduledCommit {
|
||||
*/
|
||||
wrapper() {
|
||||
if (!this.#cancelled) {
|
||||
this.#API.commit();
|
||||
this.#API.commit(this.#callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ export default class Scorm12API extends BaseAPI {
|
||||
* @return {string}
|
||||
*/
|
||||
lmsSetValue(CMIElement, value) {
|
||||
return this.setValue('LMSSetValue', false, CMIElement, value);
|
||||
return this.setValue('LMSSetValue', 'LMSCommit', false, CMIElement, value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -124,7 +124,7 @@ export default class Scorm2004API extends BaseAPI {
|
||||
* @return {string}
|
||||
*/
|
||||
lmsSetValue(CMIElement, value) {
|
||||
return this.setValue('SetValue', true, CMIElement, value);
|
||||
return this.setValue('SetValue', 'Commit', true, CMIElement, value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -486,15 +486,18 @@ describe('SCORM 1.2 API Tests', () => {
|
||||
const callback = sinon.spy(() => 1);
|
||||
const callback2 = sinon.spy(() => 2);
|
||||
const callback3 = sinon.spy(() => 3);
|
||||
const callback4 = sinon.spy(() => 4);
|
||||
scorm12API.on('CommitSuccess', callback);
|
||||
scorm12API.on('CommitSuccess', callback2);
|
||||
scorm12API.on('LMSSetValue', callback3);
|
||||
scorm12API.on('LMSCommit', callback3);
|
||||
scorm12API.on('LMSSetValue', callback4);
|
||||
|
||||
scorm12API.lmsSetValue('cmi.core.session_time', '00:01:00');
|
||||
clock.tick(2000);
|
||||
expect(callback.calledOnce).to.be.true;
|
||||
expect(callback2.calledOnce).to.be.true;
|
||||
expect(callback3.calledOnce).to.be.true;
|
||||
expect(callback4.calledOnce).to.be.true;
|
||||
|
||||
scorm12API.off('CommitSuccess', callback);
|
||||
|
||||
@@ -503,6 +506,7 @@ describe('SCORM 1.2 API Tests', () => {
|
||||
expect(callback.calledTwice).to.be.false; // removed callback should not be called a second time
|
||||
expect(callback2.calledTwice).to.be.true;
|
||||
expect(callback3.calledTwice).to.be.true;
|
||||
expect(callback4.calledTwice).to.be.true;
|
||||
});
|
||||
it('Should handle CommitError event',
|
||||
() => {
|
||||
|
||||
@@ -687,15 +687,18 @@ describe('SCORM 2004 API Tests', () => {
|
||||
const callback = sinon.spy(() => 1);
|
||||
const callback2 = sinon.spy(() => 2);
|
||||
const callback3 = sinon.spy(() => 3);
|
||||
const callback4 = sinon.spy(() => 4);
|
||||
scorm2004API.on('CommitSuccess', callback);
|
||||
scorm2004API.on('CommitSuccess', callback2);
|
||||
scorm2004API.on('SetValue', callback3);
|
||||
scorm2004API.on('Commit', callback3);
|
||||
scorm2004API.on('SetValue', callback4);
|
||||
|
||||
scorm2004API.lmsSetValue('cmi.session_time', 'PT1M0S');
|
||||
clock.tick(2000);
|
||||
expect(callback.calledOnce).to.be.true;
|
||||
expect(callback2.calledOnce).to.be.true;
|
||||
expect(callback3.calledOnce).to.be.true;
|
||||
expect(callback4.calledOnce).to.be.true;
|
||||
|
||||
scorm2004API.off('CommitSuccess', callback);
|
||||
|
||||
@@ -704,6 +707,7 @@ describe('SCORM 2004 API Tests', () => {
|
||||
expect(callback.calledTwice).to.be.false; // removed callback should not be called a second time
|
||||
expect(callback2.calledTwice).to.be.true;
|
||||
expect(callback3.calledTwice).to.be.true;
|
||||
expect(callback4.calledTwice).to.be.true;
|
||||
});
|
||||
it('Should handle CommitError event',
|
||||
() => {
|
||||
|
||||
Reference in New Issue
Block a user