Scorm to xAPI wrapper
Main git repository with source code and working example: https://gitlab.com/eduplex-api/scorm-to-xapi-wrapper
Scope of this repository
The purpose of this project is to provide a quick, easy way to implement both SCORM 1.2 Run-Time API and SCORM 2004 Run-Time API while it handles automated conversion of SCORM Data Model elements to associated xAPI statements to allow xAPI tracking in your SCORM packages. Those xAPI statements can be stored in a xAPI compatible LRS like, for example, Learning Locker.
Required files
All required files are located in the src directory.
xapiwrapper.min.js - Manages complexities of the xAPI and includes the ADL core verbs (This file must be loaded as a script in the page).
The following files should be imported to use their functions:
APIWrapper.util.js - This is the generic wrapper that calls functions from both scormApi12 and scormApi2004 wrapper objects.
baseAPI.util.js - This file contains code that is reused by scormApi12 and scormApi2004, and some constants used in APIWrapper. A manual import it is not needed, files which use it will automatically import it.
scormApi12.util.js - The SCORM 1.2 wrapper object.
scormApi2004.util.js - The SCORM 2004 wrapper object.
SCORMToXAPIFunctions.js - Contains all the code required to map SCORM data model elements to xAPI statements.
Configuration
You will need to set several configuration values in order for the wrappers to communicate with the LRS:
The most important properties are:
lrs.endpoint
Should define the URL where the LRS is located (it could be just the domain or it could include also a path prefix ending with/
).lrs.user
Username or access key from the LRS client.lrs.password
Password or secret from the LRS client.isScorm2004
Should define if the SCORM 2004 or SCORM 1.2.activityId
Unique identifier of this SCORM package in the LRS.courseId
The IRI of the entire course activity. This will be used as context to group statements.groupingContextActivity.id
It can be the same asactivityId
.
Try it yourself
You can clone the repository to test yourself the functionality. Keep in mind you will need a web server serving all files, otherwise the browser will block requests due to CORS. You need the whole repository as it is in order to make the example files work correctly.
You would need to add your LRS configuration and credentials in the function called getXapiConfig from the file demo/index.js
. After that you are ready to try it. Access index.html which will load a simple SCORM package (already part of this project) where you can do some clicks and answer a test.
With each interaction you will be sending data to the LRS as xAPI statements that you can check in your LRS dashboard. The state of the progress will also be stored in the LRS. You can replace the ExampleScorm package with any other package of your choice, just remember to unzip the original package and use the same directory name.
Other considerations
It is important the iframe with the SCORM is loaded after all the javascript code is executed, all window objects are created and event listeners are set.
This project implementation results in a lot of HTTP requests each time there is an interaction from the user. To reduce this amount we added a delay (implemented with
setTimeout
indemo/index.js
) in the event that triggers the request to update the attempt state in the LRS. But this is not strictly necessary in order to work.The versions of SCORM supported are 1.2 and 2004. Make sure to provide the right version through isScorm2004 field in the xAPI configuration object and also in the init method.
This test repository was tested with Learning Locker
How does it work
In order to start tracking SCORM courses with xAPI statements first we need to store the LRS configuration, create some window objects which are required in the wrapper files and set some event listenners to convert SCORM actions to xAPI. Most of this objects and functions are provided by the files mentioned in the first section of this project. You will only need to provide some small configuration or make changes in the behaviour of the events if you want to add extra functionality.
You will just need to call this init method before loading your SCORM package on an iframe.
You can check an example of the implementation on the file demo/index.js
. In this file would be important to change the following variables:
isScorm2004
Depending on the version used: SCORM 2004 or SCORM 1.2actorId
Unique identifier for the learner/student
The idea of this file is to overwrite some needed values and implement some event handlers. This is just a proof of concept, but adapting this code into any platform or application should be easy. It has been proven to work on an SPA (single page application)
License
The source code for the site is licensed under the MIT license, which you can find in the LICENSE file.
The ExampleScorm files are downloaded from the SCORM - Golf Examples site (SCORM 1.2 complete example from "Basic Run-Time Calls" section) by Rustici Software LLC. It is licensed under Creative Commons Attribution 3.0 United States License. All credits to the creator of the original demo content, no changes were made on this content.
Files are based on another open source repository (https://github.com/adlnet/SCORM-to-xAPI-Wrapper) which has both Apache License and Creative Commons. You can find more information about licenses inside each file.
Last updated