"cmi5 defined" Statement methods
The core "cmi5 defined" statement methods for communicating module status.

initialize

Initializes the session, must be called before performing other methods.

Example

1
import Cmi5 from "@xapi/cmi5";
2
3
const cmi5 = new Cmi5();
4
5
cmi5.initialize();
Copied!

Returns

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

complete

Completes the AU. Required for satisfaction if LaunchData.moveOn is equal to Completed, CompletedAndPassed or CompletedOrPassed.

Example

1
import Cmi5 from "@xapi/cmi5";
2
3
const cmi5 = new Cmi5();
4
5
// initialize etc
6
7
cmi5.complete();
Copied!

Parameters

Parameter
Type
Required
Description
options
false
The additional options object.
This returns a Promise containing an array with the resulting statementId if successful.

pass

Passes the AU. Required for satisfaction if LaunchData.moveOn is equal to Passed, CompletedAndPassed or CompletedOrPassed.

Examples

Example 1: Pass

1
import Cmi5 from "@xapi/cmi5";
2
3
const cmi5 = new Cmi5();
4
5
// initialize etc
6
7
cmi5.pass();
Copied!

Example 2: Pass with score

1
import Cmi5 from "@xapi/cmi5";
2
import { ResultScore } from "@xapi/xapi";
3
4
const cmi5 = new Cmi5();
5
6
// initialize etc
7
8
const score: ResultScore = {
9
scaled: 0.95,
10
raw: 95
11
min: 0
12
max: 100
13
}
14
15
cmi5.pass(score);
Copied!

Example 3: Pass with score and objective

1
import Cmi5 from "@xapi/cmi5";
2
import { ResultScore, ObjectiveActivity } from "@xapi/xapi";
3
4
const cmi5 = new Cmi5();
5
6
// initialize etc
7
8
const score: ResultScore = {
9
scaled: 0.95,
10
raw: 95
11
min: 0
12
max: 100
13
}
14
15
const objective: ObjectiveActivity = {
16
objectType: "Activity",
17
id: "https://github.com/xapijs/cmi5/objectives/test",
18
definition: {
19
type: "http://adlnet.gov/expapi/activities/objective",
20
name: {
21
"en-US": "Example Objective"
22
},
23
description: {
24
"en-US": "An example objective."
25
}
26
}
27
}
28
29
cmi5.pass(score, objective);
Copied!

Parameters

Parameter
Type
Required
Description
score
false
The score achieved by the learner.
objectiveOrOptions
false
The objective achieved by the learner or the additional options object.
Note: If using score and/or objective parameters, types for these are in @xapi/xapi and must be installed as a dev dependency npm i --save-dev @xapi/xapi.

Returns

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

fail

Fails the AU. Required to mark the AU as Failed if LaunchData.moveOn is equal to Passed, CompletedAndPassed or CompletedOrPassed.

Examples

Example 1: Fail

1
import Cmi5 from "@xapi/cmi5";
2
3
const cmi5 = new Cmi5();
4
5
// initialize etc
6
7
cmi5.fail();
Copied!

Example 2: Fail with score

1
import Cmi5 from "@xapi/cmi5";
2
import { ResultScore } from "@xapi/xapi";
3
4
const cmi5 = new Cmi5();
5
6
// initialize etc
7
8
const score: ResultScore = {
9
scaled: 0.25,
10
raw: 25
11
min: 0
12
max: 100
13
}
14
15
cmi5.fail(score);
Copied!

Parameters

Parameter
Type
Required
Description
score
false
The score achieved by the learner.
options
false
The additional options object.
Note: If using the score parameter, types for this are in @xapi/xapi and must be installed as a dev dependency npm i --save-dev @xapi/xapi.

Returns

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

terminate

Terminates the session, must be the last method called before closing the window.

Example

1
import Cmi5 from "@xapi/cmi5";
2
3
const cmi5 = new Cmi5();
4
5
// initialize etc
6
7
cmi5.terminate();
Copied!

Returns

This returns a Promise containing an array with the resulting statementId if successful.
Last modified 1yr ago