Manage student interactions in elearning applications using the xAPI specification
$ npm install @elearntics/xapi-events
import * as xapiEvents from '@elearntics/xapi-events';
<script src="node_modules/@elearntics/xapi-events/dist/xapi-events.js" type="text/javascript"></script>
const defaultStatement = xapiEvents.getDefaultStatement();
const events = [{
id: 'select-text',
callback: xapiEvents.LRS.send,
name: 'mouseup',
elementSelectors: ['.text'],
isValid: false,
status: 'OFF',
statement: [...defaultStatement, {
verb: 'selected',
actor: '[email protected]'
}]
}];
xapiEvents.LRS.setConfig({
USERNAME: 'username',
PASSWORD: 'password',
URL: 'http://example.com'
});
xapiEvents.addEvents(events);
xapiEvents.enableAllEvents();
xapiEvents.listenEnabledEvents();
xapiEvents.init('[email protected]', 'xapiEvents-Example');
A unique identifier.
The function to be executed when the event is triggered.
The name of the event listener. (i.e: click, mouseup, mousedown...)
The query selector for the HTML elements that will listen to the event.
The array elements that are listening to the event.
The statement structure that will be used when the event is triggers.
The event status. There are three possible states:
- ON
- OFF
- DISABLED (the initial state)
The event will only be available if its state is ON
.
Initializes xapiEvents
by default.
Resets xapiEvents
by default.
Sets the default statement that is used to build the rest of the statements.
It subscribes to all the events for all the xAPI events that are enabled.
It remove the subscription to all the events for all the xAPI events that are enabled.
Add a single xAPI Event.
Add multiple xAPI Events.
Remove the first event it founds a given xAPI Event id;
Set all the xAPI events status to ON.
Set an xAPI event status to ON.
Set ALL the xAPI events status to OFF.
Set an xAPI event status to OFF.
Gets the default xAPI event structure.
Gets the default statment structure.
Gets all the elements that are listening to the event.
Returns if the event is well-formed.
You can set the credentials to connect to your LRS.
- username: your username.
- password: your password.
- url: the url where your LRS is hosted.
xapiEvents.LRS.setConfig({
USERNAME: 'username',
PASSWORD: 'password',
URL: 'http://example.com'
});
Post an statement to your LRS. Can be used as a callback for an xapi-event.
MIT © elearntics