Adding SCORM 2004 Support to the SCORM CMI5 Wrapper
The SCORM CMI5 Wrapper was developed to demonstrate how to support legacy SCORM content in an LMS enabled with the extensible data model, CMI5. This wrapper was specifically designed to run in the prototype CMI5 Learning Record Store (LRS) that ADL demonstrated at iFest 2011, illustrating the tracking of learning content from non-traditional e-learning sources. Since it was developed for the demo, the only SCORM API support in the wrapper is for SCORM 1.2. However, with minimal changes, this wrapper can be updated to work with SCORM 2004-conformant SCOs.
The wrapper dynamically builds the data model, converting the dot notation of the SCORM CMI data model into a JSON binding. Since this is done dynamically, the wrapper can accept any dot notation sent from the SCO. This means that no modifications are needed to support the changes in the SCORM 2004 data model from the SCORM 1.2 data model, such as cmi.core.lesson_status to cmi.success_status.
Although the wrapper can handle any dot notation data model, the API it provides is only the SCORM 1.2 version. Since there are differences between the SCORM 1.2 and SCORM 2004 APIs, it is not possible to run a SCORM 2004-conformant SCO using the wrapper as it is. But by creating a new API that conforms to SCORM 2004, you can use this wrapper with SCORM 2004-conformant content. The rest of this article will explain what changes to make.
Adding 2004 API Support
The API is created in the JavaScript file called scorm.js, which is included in the download of the SCORM CMI5 Wrapper. This API object is what SCORM 1.2 SCOs look for when they want to communicate with the LMS. But in SCORM 2004, the API specification changed, and with it changed the names of the functions and the name of the API object. This change in the name of the object is helpful, though, because it means we can add both the SCORM 1.2 and SCORM 2004 API objects without conflicts.
So if you look at the scorm.js file you will see that the API object is created at the beginning, right after the documentation and the license.
function API() { } API.prototype.LMSInitialize = function(param){return true;}; API.prototype.LMSFinish = function(param){ // call commit this.LMSCommit(param);
function API()
{
}
API.prototype.LMSInitialize = function(param){return true;};
API.prototype.LMSFinish = function(param){
// call commit
this.LMSCommit(param);After defining all of the functions that are part of the SCORM 1.2 API, like LMSInitialize and so on, a new API object is initialized and attached to the window object.
window.API = new API();
window.API = new API();
To add the SCORM 2004 API, create a new object and add the function defined in the SCORM RTE book. First create the constructor of the object.
function API_1484_11() { }
function API_1484_11()
{
}Then add the functions to the object. Notice that the function names are different from SCORM 1.2. Most notable is that “LMS” is missing from the function names and the name change of LMSFinish to Terminate.
API_1484_11.prototype.Initialize API_1484_11.prototype.Terminate API_1484_11.prototype.GetValue API_1484_11.prototype.SetValue API_1484_11.prototype.Commit API_1484_11.prototype.GetLastError API_1484_11.prototype.GetErrorString API_1484_11.prototype.GetDiagnostic
API_1484_11.prototype.Initialize API_1484_11.prototype.Terminate API_1484_11.prototype.GetValue API_1484_11.prototype.SetValue API_1484_11.prototype.Commit API_1484_11.prototype.GetLastError API_1484_11.prototype.GetErrorString API_1484_11.prototype.GetDiagnostic
Now for convenience and to prevent duplication of code, you can assign these functions the functions from the SCORM 1.2 API.
API_1484_11.prototype.Initialize = window.API.LMSInitialize; API_1484_11.prototype.Terminate = window.API.LMSFinish; API_1484_11.prototype.GetValue = window.API.LMSGetValue; API_1484_11.prototype.SetValue = window.API.LMSSetValue; API_1484_11.prototype.Commit = window.API.LMSCommit; API_1484_11.prototype.GetLastError = window.API.LMSGetLastError; API_1484_11.prototype.GetErrorString = window.API.LMSGetErrorString; API_1484_11.prototype.GetDiagnostic = window.API.LMSGetDiagnostic;
API_1484_11.prototype.Initialize = window.API.LMSInitialize; API_1484_11.prototype.Terminate = window.API.LMSFinish; API_1484_11.prototype.GetValue = window.API.LMSGetValue; API_1484_11.prototype.SetValue = window.API.LMSSetValue; API_1484_11.prototype.Commit = window.API.LMSCommit; API_1484_11.prototype.GetLastError = window.API.LMSGetLastError; API_1484_11.prototype.GetErrorString = window.API.LMSGetErrorString; API_1484_11.prototype.GetDiagnostic = window.API.LMSGetDiagnostic;
There is one exception. LMSFinish, in the SCORM 1.2 API, contains the line this.LMSCommit(param) to bundle up the CMI5 data and send it to the LRS. This will cause an error when you try to call Terminate because this will be referencing the SCORM 2004 API object we are making, which doesn’t define a LMSCommit function. There are two options for fixing this. First you can add a LMSCommit function to the SCORM 2004 API object. Or you can define a new function for Terminate instead of using the same function as LMSFinish. I recommend the second option, since it will keep the SCORM 2004 API object aligned with the SCORM 2004 specification and it gives you the ability to change the implementation later without impacting the SCORM 1.2 API.
API_1484_11.prototype.Terminate = function(param){ this.Commit(param); return true; };
API_1484_11.prototype.Terminate = function(param){
this.Commit(param);
return true;
};After building the SCORM 2004 constructor and functions, you need to create an instance of the API and attach it to the window object so that SCOs can find the API. To do this, create a new attribute on the window object and assign it a newly created SCORM API object. Make sure to name the window attribute API_1484_11 so that the SCOs can find it.
window.API_1484_11 = new API_1484_11();
window.API_1484_11 = new API_1484_11();
That’s it. Your SCORM 2004 SCOs should find this new API and report its data to the SCORM CMI5 Wrapper now.
The scorm.js file: SCORM CMI5 Wrapper SCORM JavaScript File