Skip to main content

API Events Reference

This reference documents all events available in scorm-again APIs, their payloads, and usage patterns.

Event System Overview

Registering Listeners

Use the on() method to register event listeners:

// Basic event listener
api.on("Initialize", function() {
console.log("SCO initialized");
});

// With callback receiving data
api.on("SetValue", function(element, value) {
console.log(`${element} set to ${value}`);
});

Removing Listeners

Use the off() method to remove event listeners:

const myCallback = function(element, value) {
console.log(`${element} = ${value}`);
};

// Register
api.on("SetValue", myCallback);

// Later, remove
api.off("SetValue", myCallback);

Event Naming Conventions

Events follow the API method names:

  • SCORM 1.2: LMSInitialize, LMSFinish, LMSGetValue, LMSSetValue, LMSCommit
  • SCORM 2004: Initialize, Terminate, GetValue, SetValue, Commit

Listener Patterns

Standard Listeners

Listen to any API method call:

api.on("SetValue", function(element, value) {
// Fires on ANY SetValue call
});

Wildcard Listeners

Match multiple events using dot notation:

// Listen to all SetValue calls for score elements
api.on("SetValue.cmi.score.*", function(element, value) {
console.log(`Score updated: ${element} = ${value}`);
});

// Listen to all SetValue calls
api.on("SetValue.*", function(element, value) {
// Fires on every SetValue
});

Element-Specific Listeners

Listen to specific CMI elements:

// SCORM 1.2: Listen only to lesson_status changes
api.on("LMSSetValue.cmi.core.lesson_status", function(element, value) {
console.log(`Status changed to: ${value}`);
});

// SCORM 2004: Listen only to completion_status changes
api.on("SetValue.cmi.completion_status", function(element, value) {
updateProgressUI(value);
});

Core API Events

SCORM 1.2 Events

EventFires WhenCallback Signature
LMSInitializeSCO calls LMSInitialize()function()
LMSFinishSCO calls LMSFinish()function()
LMSGetValueSCO calls LMSGetValue()function(element)
LMSSetValueSCO calls LMSSetValue()function(element, value)
LMSCommitSCO calls LMSCommit()function()
LMSGetLastErrorSCO calls LMSGetLastError()function()
LMSGetErrorStringSCO calls LMSGetErrorString()function(errorCode)
LMSGetDiagnosticSCO calls LMSGetDiagnostic()function(errorCode)

SCORM 2004 Events

EventFires WhenCallback Signature
InitializeSCO calls Initialize()function()
TerminateSCO calls Terminate()function()
GetValueSCO calls GetValue()function(element)
SetValueSCO calls SetValue()function(element, value)
CommitSCO calls Commit()function()
GetLastErrorSCO calls GetLastError()function()
GetErrorStringSCO calls GetErrorString()function(errorCode)
GetDiagnosticSCO calls GetDiagnostic()function(errorCode)

Commit Events

BeforeTerminate

Fires immediately before termination processing begins. Use for cleanup or final data sync.

api.on("BeforeTerminate", function() {
// Perform cleanup before termination
saveAdditionalAnalytics();
});

CommitSuccess

Fires when a commit to the LMS succeeds (internal event, not typically used by LMS integrators).

CommitError

Fires when a commit to the LMS fails (internal event, not typically used by LMS integrators).


Offline Events

These events fire when offline support is enabled (enableOfflineSupport: true).

OfflineDataSynced

Fires when queued offline data successfully syncs to the server.

api.on("OfflineDataSynced", function() {
showNotification("Data synchronized successfully");
});

OfflineDataSyncFailed

Fires when offline data sync fails after all retry attempts.

api.on("OfflineDataSyncFailed", function() {
showNotification("Sync failed - data saved locally", "warning");
});

SequenceNext

Fires when SCORM 2004 content requests navigation to the next activity.

api.on("SequenceNext", function() {
// Handle navigation to next SCO
loadNextActivity();
});

SequencePrevious

Fires when SCORM 2004 content requests navigation to the previous activity.

api.on("SequencePrevious", function() {
// Handle navigation to previous SCO
loadPreviousActivity();
});

Sequencing Events (SCORM 2004 Only)

These events are configured via settings.sequencing.eventListeners and provide detailed insight into the sequencing engine.

Configuration

const api = new Scorm2004API({
sequencing: {
eventListeners: {
onActivityDelivery: function(activity) {
console.log("Deliver activity:", activity.id);
},
onSequencingError: function(error, context) {
console.error("Sequencing error:", error, context);
}
}
}
});

Sequencing Event Reference

EventFires WhenPayload
onSequencingStartSequencing session beginsactivity object
onSequencingEndSequencing session endsNone
onActivityDeliveryActivity ready for deliveryactivity object
onActivityUnloadActivity being unloadedactivity object
onNavigationRequestNavigation request receivedrequest: string, target?: string
onRollupCompleteRollup calculation finishedactivity object
onSequencingErrorSequencing error occurrederror: string, context?: string
onSequencingSessionEndSession ending{ reason, exception?, navigationRequest? }
onAutoCompletionAuto-completion triggered{ activity: string, completionStatus: string }
onAutoSatisfactionAuto-satisfaction triggered{ activity: string, satisfiedStatus: boolean }
onPostConditionExitParentExit parent post-condition{ activity: string }
onPostConditionExitAllExit all post-condition{ activity: string }
onTerminationRequestProcessingProcessing termination{ request, hasSequencingRequest, currentActivity }
onNavigationRequestProcessingProcessing navigation{ request, targetActivityId }
onPostConditionEvaluatedPost-condition evaluated{ activity, result, iteration }
onMultiLevelExitActionMulti-level exit{ activity: string }
onSuspendedActivityCleanupCleaning suspended activity{ activity: string }
onSuspendErrorSuspend operation failed{ activity, error }
onActivitySuspendedActivity suspended{ activity: string }
onDeliveryRequestProcessingProcessing delivery{ request, target }
onNavigationValidityUpdateNavigation validity changed{ currentActivity, validRequests[] }
onLimitConditionCheckLimit condition checked{ activity, limitType, exceeded }
onStateInconsistencyState inconsistency detected{ activity, issue }
onGlobalObjectiveMapInitializedGlobal objectives initialized{ count: number }
onGlobalObjectiveMapErrorGlobal objective error{ error: string }
onGlobalObjectiveUpdatedGlobal objective updated{ objectiveId, field, value }
onGlobalObjectiveUpdateErrorGlobal objective update failed{ objectiveId, error }
onSequencingDebugDebug information{ message, context? }

Detailed Sequencing Event Examples

onActivityDelivery

The most commonly used sequencing event. Fires when an activity should be delivered to the learner.

onActivityDelivery: function(activity) {
// activity contains:
// - id: Activity identifier from manifest
// - title: Activity title
// - resourceIdentifier: Resource to launch
// - parameters: Launch parameters

const launchUrl = buildLaunchUrl(activity.resourceIdentifier, activity.parameters);
loadContentFrame(launchUrl);
}

onNavigationValidityUpdate

Fires when available navigation options change. Use to update navigation UI.

onNavigationValidityUpdate: function(data) {
// data.currentActivity: Current activity ID or null
// data.validRequests: Array of valid navigation requests
// e.g., ["continue", "previous", "choice", "exit"]

updateNavButtons({
nextEnabled: data.validRequests.includes("continue"),
prevEnabled: data.validRequests.includes("previous"),
exitEnabled: data.validRequests.includes("exit")
});
}

onSequencingSessionEnd

Fires when the sequencing session is ending. Use for cleanup or final state persistence.

onSequencingSessionEnd: function(data) {
// data.reason: Why session ended ("complete", "suspend", "exit", "abandon")
// data.exception: Sequencing exception code if any
// data.navigationRequest: The navigation request that triggered end

if (data.reason === "complete") {
showCompletionScreen();
} else if (data.reason === "suspend") {
showResumePrompt();
}
}

Multiple Listener Registration

You can register the same callback for multiple events:

function logApiCall(element, value) {
analytics.track("scorm_api_call", { element, value });
}

// Register for multiple events
api.on("SetValue", logApiCall);
api.on("GetValue", logApiCall);
api.on("Commit", logApiCall);

Cleanup Patterns

Always clean up listeners when the content unloads to prevent memory leaks:

const listeners = {
onSetValue: function(element, value) { /* ... */ },
onTerminate: function() { /* ... */ }
};

// Register
api.on("SetValue", listeners.onSetValue);
api.on("Terminate", listeners.onTerminate);

// Cleanup on unload
window.addEventListener("unload", function() {
api.off("SetValue", listeners.onSetValue);
api.off("Terminate", listeners.onTerminate);
});