A basic Scorm Driver for launching and tracking SCORM 1.2 & 2004 content, build with Typescript.
npm install
npx webpack
The ES5 output will be compiled to /dist/Barnacle.js.
The library uses Webpack to bundle, the default configuration is to target a Barnacle global variable. The script can be included using a script tag.
<script src="Barnacle.js"></script>Webpack configuration can be changed to support UMD or CommonJS library targets.
To init a new API construct a new ScormDriver
let driver = new Barnacle.ScormDriver(
{
onCommit: ( data, value ) => {}
},
/* [SCORM 1.2 Factory function] */,
/* [SCORM 2004 Factory function] */ );options parameter accepts a object with a callback function onCommit ( state, version ). This function will be called when new data is available via the API. See SCORM runtime reference for details of the values set in the data model.
SCORM 1.2 factory function and SCORM 2004 factory function parameters accepts a function to construct the implementation of the SCORM API. ( options: BarnacleOptions ) => UnifiedScormSignature
When the content commits changes to the data model, the onCommit handler will be called with the state and the version supplied as paramenters.
function onCommit ( state, version ) {
console.log( state );
// Will display an object containing the SCORM data model
/*
{
"cmi.suspend_data" : "[124,252,358,469,121,254,322]",
"cmi.completion_status" : "incomplete",
"cmi.success_status" : "unknown"
}
*/
console.log( version );
// Will display the string value of the SCORM API version
// "SCORM 1.2" or "SCORM 2004 4th Edition"
}When you need to resume the session, call load before you launch the content.
let driver = new Barnacle.ScormDriver();
driver.attach( window );
driver.load( {
"cmi.suspend_data" : "[124,252,358,469,121,254,322]",
"cmi.completion_status" : "incomplete",
"cmi.success_status" : "unknown"
}, "SCORM 2004 4th Edition" );
driver.launch( "/index_lms.html" ); // Resume where you left off.A ScormDriver has three methods available:
attach ( window )
The ScormDriver will create the required API and API_1484_11 variable for communication with the content.
window - the window object you want to attach to. Required.
load ( state, version )
The ScormDriver will pre-populate the specified version with the state.
state - an object to load into the SCORM API, each property will be used to perform an LMSSetValue or SetValue. Required.
version - "SCORM 1.2" or "SCORM 2004 4th Edition". Required.
launch ( url, newWindowName, openerWindow )
The ScormDriver will open the content in a new Window.
url - the url of the resource to open in the new browser window. Required.
newWindowName - the name for the new window. Default: "course".
openerWindow - the window object that will open the new window. Default: window
A ManifestLoader has a single method load to async get a SCORM manifest.
let loader = new Barnacle.ManifestLoader();
let manifest = await loader.load( "my_scorm_package/imsmanifest.xml" );
Barnacle.ScormDriver.launch( "my_scorm_package/${manifest.webContent.href}" );