-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadl_launch.html
107 lines (87 loc) · 2.43 KB
/
adl_launch.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript">
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
onConnectionSuccess(xhr.response);
} else {
onConnectionError();
}
}
};
xhr.open("POST", getLauncherURL());
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", getLauncherAuth());
xhr.send(getData());
function onConnectionSuccess(response) {
var data = JSON.parse(response);
window.location = "index.html?xAPILaunchService=" + getLauncherEndpoint() + "&xAPILaunchKey=" + encodeURIComponent(data.key) + "&activity_id=" + getActivityId() + "®istration=" + getRegistration();
}
function onConnectionError() {
}
function generateUUID() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == "x" ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
function getLauncherURL() {
var url = "https://launcher.learninglocker.net/session/" + generateUUID() + "/launch";
return url;
}
function getLauncherAuth() {
// "Basic " + toBase64('username:password');
var auth = "";
return auth;
}
function getLauncherEndpoint() {
var endpoint = "https://launcher.learninglocker.net/content/";
return encodeURIComponent(endpoint);
}
function getActivityId() {
var activityId = "https://example.com/unique_identifier";
return encodeURIComponent(activityId);
}
function getRegistration() {
var uuid = "";
return uuid;
}
function getData() {
var data = {
statement: {
actor: {
mbox: "mailto:[email protected]",
name: "Test User"
},
context: {
contextActivities: {
grouping: [
{
objectType: "Activity",
id: "https://example.com/course_identifier",
definition: {
name: {
en: "Test Course"
}
}
}
]
}
}
},
ttl: 10
};
return JSON.stringify(data);
}
</script>
</head>
<body>
</body>
</html>