-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
71 lines (62 loc) · 2.33 KB
/
index.html
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html>
<head>
<title>xAPI Package Example</title>
<!-- Loading Tincan Javascript Library to communicate with LRS -->
<script src="tincan-min.js"></script>
</head>
<body>
<!-- Replace URL below with URL to your "custom learning content" -->
<iframe src="https://www.jskl.fr/" width="100%" height="100%" border="0"
frameborder="0"></iframe>
<!-- This can be included in another JS file. Kept here for this sample -->
<script>
// xAPI configuration is sent in the URL query string parameters
var urlParams = new URLSearchParams(window.location.search);
var endpoint = urlParams.get('endpoint');
var auth = urlParams.get('auth');
// actor represents the current user using LMS
var actor = JSON.parse(urlParams.get('actor')); // this needs to be JSON decoded
// extracting data from LMS in URL
var activity_id = urlParams.get('activity_id');
var registration = urlParams.get('registration');
// Configure & Connect to the LRS using endpoint & auth provided by LMS in URL
var lrs = new TinCan.LRS({
endpoint: endpoint,
auth: auth
});
// Creating "completed" statement to be sent when "custom learning content" is done
var completionStatement = new TinCan.Statement({
actor: actor, // the actor data sent by LMS
object: {
id: activity_id, // the activity_id sent by LMS
objectType: "Activity"
},
context: {
registration: registration // the registration sent by LMS
},
verb: {
id: "http://adlnet.gov/expapi/verbs/completed",
display: {
"en-US": "completed"
},
},
result: {
completion: true,
// score: { "raw": 42, "min": 0, "max": 100, "scaled": 0.4 } Here you can set a score for completion
}
});
// Add a listener to enable communication between "custom learning content" (inside iframe) and this page ( hosted on the LMS using xAPI Package)
window.addEventListener('message', function (event) {
if (event.origin == 'https://www.jskl.fr' && event.data.message == 'end_course') { // Use your origin and set a message ID
// Course inside "custom learning content" is finished, send "completed" statement created before to the LRS
lrs.saveStatement(completionStatement, {
callback: function (error, xhr) {
// error will be null if this succeeded
// You can handle error here
}
})
}
}, false);
</script>
</body>
</html>