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.

getLearnerPreferences

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

Example

import Cmi5, { LearnerPreferences } from "@xapi/cmi5";
const cmi5 = new Cmi5();
cmi5.initialize().then(() => {
const learnerPreferences: LearnerPreferences = cmi5.getLearnerPreferences();
});

Cmi5.isCmiAvailable

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

Example

import Cmi5 from "@xapi/cmi5";
const isCmiAvailable: boolean = Cmi5.isCmiAvailable();

Returns

This returns a Boolean.

isAuthenticated

This returns true if the instance constructed successfully.

Example

import Cmi5 from "@xapi/cmi5";
const cmi5 = new Cmi5();
cmi5.initialize().then(() => {
const isAuthenticated: boolean = cmi5.isAuthenticated();
});

Returns

This returns a Boolean.

Cmi5.instance

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

Example

import Cmi5 from "@xapi/cmi5";
const cmi5instance: Cmi5 = Cmi5.instance;

Returns

This returns a global Cmi5 singleton instance.

Cmi5.clearInstance

Clears the Cmi5 singleton instance.

Example

import Cmi5 from "@xapi/cmi5";
const cmi5instance: Cmi5 = Cmi5.instance;
Cmi5.clearInstance();

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

import Cmi5 from "@xapi/cmi5";
const cmi5 = new Cmi5();
// initialize etc
cmi5.moveOn();

Parameters

Parameter

Type

Required

Description

options

MoveOnOptions

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

import Cmi5 from "@xapi/cmi5";
import XAPI from "@xapi/xapi"; // For types as a developer dependency, not required but may be useful!
const cmi5: Cmi5 = new Cmi5();
await cmi5.initialize();
const xapi: XAPI = cmi5.xapi;
xapi.getStatement(...);

Returns

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