Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ This javascript file is typically used in SCORM 2004 courses. If the ADL-provid
Note: The updated APIWrapper.js file does not stand-alone and MUST be used with the SCORMToXAPIFunctions.js file.

## SCORM1.2/APIWrapper.js
NOTE - THIS VERSION IS CURRENTLY OUT OF DATE. PLEASE SEE THE 2004 WRAPPER UNTIL THIS ISSUE IS ADDRESSED.

Javascript SCORM 1.2 API wrapper with new xAPI object (Implemented in SCORMToXAPIFunctions.js).
This javascript file is typically used in SCORM 1.2 courses. If the ADL-provided ADLWrapper.js file is used in your SCORM courses, it can be replaced with this file.

Expand Down Expand Up @@ -57,15 +55,18 @@ var activity = <manually configured URI goes here>;

Finally, several configuration values must be set in the updated APIWrapper.js file (init method). Instructions are also included in the header at the top of the JavaScript file. Near the top of the file, configure the following lines of code:
```JavaScript
var config = {
lrs:{
endpoint:"https://lrs.adlnet.gov/xapi/",
user:"<lrs user>",
password:"<lrs password>"
},
courseId:"<course identifier/uri>",
lmsHomePage:"<lms homepage>"
};
var config = {
lrs: {
endpoint: "https://lrs.adlnet.gov/xapi/",
user: "",
password: ""
},
courseId: "",
lmsHomePage: "",
isScorm2004: true,
activityId: "",
groupingContextActivity: {}
};
```

### Limitations
Expand Down
101 changes: 46 additions & 55 deletions SCORM1.2/APIWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ retrieveDataValue = doLMSGetValue;
** false if the initialization failed.
**
** Description:
** Initialize communication with LMS by calling the LMSInitialize
** Initialize communication with LMS by calling the doLMSInitialize
** function which will be implemented by the LMS.
**
*******************************************************************************/
Expand All @@ -136,33 +136,23 @@ function doLMSInitialize()
var api = getAPIHandle();
if (api == null)
{
message("Unable to locate the LMS's API Implementation.\nLMSInitialize was not successful.");
message("Unable to locate the LMS's API Implementation.\ndoLMSInitialize was not successful.");
return "false";
}

var result = api.LMSInitialize("");
var result = api.doLMSInitialize("");

if (result.toString() != "true")
{
var err = ErrorHandler();
message("LMSInitialize failed with error code: " + err.code);
message("doLMSInitialize failed with error code: " + err.code);
}
else
{
initialized = true;

// xAPI Extensions
var config = {
lrs:{
endpoint:"<LRS Endpoint>",
user:"<LRS User>",
password:"<LRS Password>"
},
courseId:"<Course IRI>",
lmsHomePage:"<LMS Home Page>",
isScorm2004:false
}; // isSCORM2004:true above - to convert SCORM 2004 courses
xapi.setConfig(config);
xapi.initializeAttempt();
initialized = true;

//xAPI Extension
xapi.initializeAttempt();

}

Expand All @@ -177,7 +167,7 @@ function doLMSInitialize()
** false if failed.
**
** Description:
** Close communication with LMS by calling the LMSFinish
** Close communication with LMS by calling the doLMSFinish
** function which will be implemented by the LMS
**
*******************************************************************************/
Expand All @@ -188,20 +178,20 @@ function doLMSFinish()
var api = getAPIHandle();
if (api == null)
{
message("Unable to locate the LMS's API Implementation.\nLMSFinish was not successful.");
message("Unable to locate the LMS's API Implementation.\ndoLMSFinish was not successful.");
return "false";
}
else
{
// xAPI Extension
xapi.terminateAttempt();

// call the LMSFinish function that should be implemented by the API
var result = api.LMSFinish("");
// call the doLMSFinish function that should be implemented by the API
var result = api.doLMSFinish("");
if (result.toString() != "true")
{
var err = ErrorHandler();
message("LMSFinish failed with error code: " + err.code);
message("doLMSFinish failed with error code: " + err.code);
}
}

Expand All @@ -220,31 +210,32 @@ function doLMSFinish()
** input value.
**
** Description:
** Wraps the call to the LMS LMSGetValue method
** Wraps the call to the LMS doLMSGetValue method
**
*******************************************************************************/
function doLMSGetValue(name)
{

var api = getAPIHandle();
var result = "";
if (api == null)
{
message("Unable to locate the LMS's API Implementation.\nLMSGetValue was not successful.");
message("Unable to locate the LMS's API Implementation.\ndoLMSGetValue was not successful.");
}
else if (! initialized && ! doLMSInitialize())
{
var err = ErrorHandler(); // get why doLMSInitialize() returned false
message("LMSGetValue failed - Could not initialize communication with the LMS - error code: " + err.code);
message("doLMSGetValue failed - Could not initialize communication with the LMS - error code: " + err.code);
}
else
{
result = api.LMSGetValue(name);
result = api.doLMSGetValue(name);

var error = ErrorHandler();
if (error.code != _NoError.code)
{
// an error was encountered so display the error description
message("LMSGetValue("+name+") failed. \n"+ error.code + ": " + error.string);
message("doLMSGetValue("+name+") failed. \n"+ error.code + ": " + error.string);
result = "";
}
}
Expand All @@ -260,7 +251,7 @@ function doLMSGetValue(name)
** false if failed.
**
** Description:
** Wraps the call to the LMS LMSSetValue function
** Wraps the call to the LMS doLMSSetValue function
**
*******************************************************************************/
function doLMSSetValue(name, value)
Expand All @@ -269,23 +260,23 @@ function doLMSSetValue(name, value)
var result = "false";
if (api == null)
{
message("Unable to locate the LMS's API Implementation.\nLMSSetValue was not successful.");
message("Unable to locate the LMS's API Implementation.\ndoLMSSetValue was not successful.");
}
else if (! initialized && ! doLMSInitialize())
else if (!initialized && !doLMSInitialize())
{
var err = ErrorHandler(); // get why doLMSInitialize() returned false
message("LMSSetValue failed - Could not initialize communication with the LMS - error code: " + err.code);
message("doLMSSetValue failed - Could not initialize communication with the LMS - error code: " + err.code);
}
else
{
// xAPI Extension
xapi.saveDataValue(name, value);

result = api.LMSSetValue(name, value);
result = api.doLMSSetValue(name, value);
if (result.toString() != "true")
{
var err = ErrorHandler();
message("LMSSetValue("+name+", "+value+") failed. \n"+ err.code + ": " + err.string);
message("doLMSSetValue("+name+", "+value+") failed. \n"+ err.code + ": " + err.string);
}
}

Expand All @@ -309,20 +300,20 @@ function doLMSCommit()
var result = "false";
if (api == null)
{
message("Unable to locate the LMS's API Implementation.\nLMSCommit was not successful.");
message("Unable to locate the LMS's API Implementation.\ndoLMSCommit was not successful.");
}
else if (! initialized && ! doLMSInitialize())
else if (!initialized && ! doLMSInitialize())
{
var err = ErrorHandler(); // get why doLMSInitialize() returned false
message("LMSCommit failed - Could not initialize communication with the LMS - error code: " + err.code);
message("doLMSCommit failed - Could not initialize communication with the LMS - error code: " + err.code);
}
else
{
result = api.LMSCommit("");
result = api.doLMSCommit("");
if (result != "true")
{
var err = ErrorHandler();
message("LMSCommit failed - error code: " + err.code);
message("doLMSCommit failed - error code: " + err.code);
}
}

Expand All @@ -336,20 +327,20 @@ function doLMSCommit()
** Return: The error code that was set by the last LMS function call
**
** Description:
** Call the LMSGetLastError function
** Call the doLMSGetLastError function
**
*******************************************************************************/
function doLMSGetLastError()
{
var api = getAPIHandle();
if (api == null)
{
message("Unable to locate the LMS's API Implementation.\nLMSGetLastError was not successful.");
message("Unable to locate the LMS's API Implementation.\ndoLMSGetLastError was not successful.");
//since we can't get the error code from the LMS, return a general error
return _GeneralException.code; //General Exception
}

return api.LMSGetLastError().toString();
return api.doLMSGetLastError().toString();
}

/*******************************************************************************
Expand All @@ -359,19 +350,19 @@ function doLMSGetLastError()
** Return: The textual description that corresponds to the input error code
**
** Description:
** Call the LMSGetErrorString function
** Call the doLMSGetErrorString function
**
********************************************************************************/
function doLMSGetErrorString(errorCode)
{
var api = getAPIHandle();
if (api == null)
{
message("Unable to locate the LMS's API Implementation.\nLMSGetErrorString was not successful.");
message("Unable to locate the LMS's API Implementation.\ndoLMSGetErrorString was not successful.");
return _GeneralException.string;
}

return api.LMSGetErrorString(errorCode).toString();
return api.doLMSGetErrorString(errorCode).toString();
}

/*******************************************************************************
Expand All @@ -382,19 +373,19 @@ function doLMSGetErrorString(errorCode)
** input error code
**
** Description:
** Call the LMSGetDiagnostic function
** Call the doLMSGetDiagnostic function
**
*******************************************************************************/
function doLMSGetDiagnostic(errorCode)
{
var api = getAPIHandle();
if (api == null)
{
message("Unable to locate the LMS's API Implementation.\nLMSGetDiagnostic was not successful.");
return "Unable to locate the LMS's API Implementation. LMSGetDiagnostic was not successful.";
message("Unable to locate the LMS's API Implementation.\ndoLMSGetDiagnostic was not successful.");
return "Unable to locate the LMS's API Implementation. doLMSGetDiagnostic was not successful.";
}

return api.LMSGetDiagnostic(errorCode).toString();
return api.doLMSGetDiagnostic(errorCode).toString();
}

/*******************************************************************************
Expand Down Expand Up @@ -430,12 +421,12 @@ function ErrorHandler()
}

// check for errors caused by or from the LMS
error.code = api.LMSGetLastError().toString();
error.code = api.doLMSGetLastError().toString();
if (error.code != _NoError.code)
{
// an error was encountered so display the error description
error.string = api.LMSGetErrorString(error.code);
error.diagnostic = api.LMSGetDiagnostic("");
error.string = api.doLMSGetErrorString(error.code);
error.diagnostic = api.doLMSGetDiagnostic("");
}

return error;
Expand Down Expand Up @@ -475,7 +466,7 @@ function getAPIHandle()
*******************************************************************************/
function findAPI(win)
{
var findAPITries = 0;
var findAPITries = 0;
while ((win.API == null) && (win.parent != null) && (win.parent != win))
{
findAPITries++;
Expand Down Expand Up @@ -537,4 +528,4 @@ function message(str)
{
output.log(str);
}
}
}
14 changes: 7 additions & 7 deletions SCORM2004/APIWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,17 @@ function doInitialize()
}
else
{
// todo remove
message("Initialize succeeded");

initialized = true;

// xAPI Extension
// xAPI Extension
xapi.initializeAttempt();
doSetValue("cmi.progress_measure", 0.0);

}

return result.toString();
}


/*******************************************************************************
**
** Function doTerminate()
Expand All @@ -189,7 +186,8 @@ function doTerminate()
{
// xAPI Extension
xapi.terminateAttempt();

doSetValue("cmi.progress_measure", 0.99);
xapi.measureProgress();
// call the Terminate function that should be implemented by the API
var result = api.Terminate("");
if (result.toString() != "true")
Expand All @@ -204,6 +202,9 @@ function doTerminate()
return result.toString();
}




/*******************************************************************************
**
** Function doGetValue(name)
Expand Down Expand Up @@ -232,7 +233,6 @@ function doGetValue(name)
}
else
{

result = api.GetValue(name);

var error = ErrorHandler();
Expand Down
Loading