-
Notifications
You must be signed in to change notification settings - Fork 0
/
scormWrapper.js
48 lines (48 loc) · 1.86 KB
/
scormWrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const foundAPI = findAPI(window);
const isScorm2004 = !foundAPI.LMSInitialize;
const getNameInit = function () {
return (isScorm2004 ? 'Initialize' : 'LMSInitialize');
}
const getNameFinish = function () {
return (isScorm2004 ? 'Terminate' : 'LMSFinish');
}
const getNameSet = function () {
return (isScorm2004 ? 'SetValue' : 'LMSSetValue');
}
const initializeAttempt = function () {
const oldRetrieveDataValue = window.retrieveDataValue // from APIWrapper.js
window.retrieveDataValue = function (name) {
if (name === 'cmi.launch_data') {
const host = document.location.protocol + "//" + document.location.host + document.location.pathname;
// faking cmi launch_data when get LRS config from SCORMToXAPIFunctions.js
return JSON.stringify({
lrs:{
endpoint: "",
user: "",
password: ""
},
courseId: host + document.location.pathname,
lmsHomePage: host,
isScorm2004: isScorm2004,
activityId: host + document.location.pathname + "/activityXXyyZZ",
groupingContextActivity: {
definition: {
name: {
"en-US": "TECOM Workshop"
},
description: {
"en-US": "TECOM Workshop happening Nov 2016"
}
},
id: "http://example.com/event/xapiworkshop/tecom",
objectType: "Activity"
}
});
}
return oldRetrieveDataValue(name);
}
xapi.initializeAttempt();
}
foundAPI.on(getNameInit(), initializeAttempt);
foundAPI.on(getNameFinish(), xapi.terminateAttempt);
foundAPI.on(getNameSet(), xapi.saveDataValue);