Helpers

A selection of useful helpers.

getLaunchParameters

This gets the launch parameters supplied in the URL. Can be used before initializing.

Example

import Cmi5, { LaunchParameters } from "@xapi/cmi5";

const cmi5 = new Cmi5();

const launchParameters: LaunchParameters = cmi5.getLaunchParameters();

Returns

This returns a LaunchParameters object.

getLaunchData

This gets the launch data from the LMS. Can not be used before initializing the AU.

Example

import Cmi5, { LaunchData } from "@xapi/cmi5";

const cmi5 = new Cmi5();

cmi5.initialize().then(() => {
  const launchData: LaunchData = cmi5.getLaunchData();
});

Returns

This returns a LaunchData object.

getAuthToken

This gets the session's authToken. Useful for storing in non-volatile storage local to the user (e.g. SessionStorage) to preserve the state between page refreshes. Pass this value and initializedDate to initialize to restore the previous session.

Example

Returns

This returns a string or null if the Cmi5 instance has not been initialized.

getInitializedDate

This gets the session's initializedDate. Useful for storing in non-volatile storage local to the user (e.g. SessionStorage) to preserve the state between page refreshes. Pass this value and authToken to initialize to restore the previous session.

Example

Returns

This returns a Date or null if the Cmi5 instance has not been initialized.

getLearnerPreferences

This gets the learner preferences from the LMS. Can not be used before initializing the AU.

Example

Cmi5.isCmiAvailable

This returns true if the environment has all the necessary parameters for initialisation.

Example

Returns

This returns a Boolean.

isAuthenticated

This returns true if the instance constructed successfully.

Example

Returns

This returns a Boolean.

Cmi5.instance

Creates a new Cmi5 singleton instance, or if already called returns the same singleton Cmi5 instance.

Example

Returns

This returns a global Cmi5 singleton instance.

Cmi5.clearInstance

Clears the Cmi5 singleton instance.

Example

moveOn

Automatically satisfies the AU based upon the Launch Data from the LMS. It will send the "cmi5 defined" statements for:

  • Pass or fail if a score is provided and the mastery score is configured

  • complete statement

  • terminate statement (unless disabled in the options parameter)

Example

Parameters

Parameter

Type

Required

Description

options

false

The additional options object.

This returns a Promise containing an array with the resulting statementIds if successful.

Cmi5.xapi

Returns the internal xAPI.js Wrapper library instance. Useful for accessing any xAPI Resources using the Cmi5 authentication. Can only be accessed after successfully calling the initialize method.

Example

Returns

This returns the internal XAPI instance, authenticated with the LRS endpoint and authentication token.

Last updated

Was this helpful?