@didask/scol-r 2.6.0-beta.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ManifestGenerator.js +1 -1
- package/lib/SCORMAdapter.d.ts +4 -3
- package/lib/SCORMAdapter.js +31 -11
- package/lib/loadContent.js +8 -0
- package/package.json +3 -8
package/lib/ManifestGenerator.js
CHANGED
|
@@ -55,7 +55,7 @@ function ManifestGenerator(_a) {
|
|
|
55
55
|
var courseGlobalLearningTime = scoList.length
|
|
56
56
|
? scoList.reduce(function (acc, sco) { return acc + sco.learningTime; }, 0)
|
|
57
57
|
: totalLearningTime;
|
|
58
|
-
return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n <manifest xmlns=\"http://www.imsproject.org/xsd/imscp_rootv1p1p2\" identifier=\"".concat(courseId, "\" version=\"1.0\" xmlns:imsmd=\"http://www.imsglobal.org/xsd/imsmd_rootv1p2p1\" xmlns:adlcp=\"http://www.adlnet.org/xsd/adlcp_rootv1p2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd\">\n <metadata>\n <schema>ADL SCORM</schema>\n <schemaversion>").concat(scormVersion, "</schemaversion>\n <imsmd:lom xmlns=\"http://ltsc.ieee.org/xsd/LOM\">\n <imsmd:general>\n <imsmd:identifier>").concat(courseId, "</imsmd:identifier>\n </imsmd:general>\n <imsmd:lifecycle>\n <imsmd:contribute>\n <imsmd:role>\n <imsmd:source>\n <imsmd:langstring xml:lang=\"fr\">LOMv1.0</imsmd:langstring>\n </imsmd:source>\n <imsmd:value>\n <imsmd:langstring xml:lang=\"fr\">Author</imsmd:langstring>\n </imsmd:value>\n </imsmd:role>\n <imsmd:centity>\n <imsmd:vcard>\n begin:vcard\n fn:").concat(courseAuthor, "\n end:vcard\n </imsmd:vcard>\n </imsmd:centity>\n </imsmd:contribute>\n </imsmd:lifecycle>\n <imsmd:educational>\n <imsmd:typicallearningtime>\n <imsmd:datetime>").concat(formatLearningTime(courseGlobalLearningTime), "</imsmd:datetime>\n </imsmd:typicallearningtime>\n </imsmd:educational>\n </imsmd:lom>\n </metadata>\n <organizations default=\"Org1\">\n <organization identifier=\"Org1\">\n <title>").concat(courseTitle, "</title>\n ").concat(scoList
|
|
58
|
+
return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n <manifest xmlns=\"http://www.imsproject.org/xsd/imscp_rootv1p1p2\" identifier=\"".concat(courseId, "\" version=\"1.0\" xmlns:imsmd=\"http://www.imsglobal.org/xsd/imsmd_rootv1p2p1\" xmlns:adlcp=\"http://www.adlnet.org/xsd/adlcp_rootv1p2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd\">\n <metadata>\n <schema>ADL SCORM</schema>\n <schemaversion>").concat(scormVersion, "</schemaversion>\n <imsmd:lom xmlns=\"http://ltsc.ieee.org/xsd/LOM\">\n <imsmd:general>\n <imsmd:identifier>").concat(courseId, "</imsmd:identifier>\n <imsmd:title>\n <imsmd:langstring xml:lang=\"fr\">").concat(courseTitle, "</imsmd:langstring>\n </imsmd:title>\n </imsmd:general>\n <imsmd:lifecycle>\n <imsmd:contribute>\n <imsmd:role>\n <imsmd:source>\n <imsmd:langstring xml:lang=\"fr\">LOMv1.0</imsmd:langstring>\n </imsmd:source>\n <imsmd:value>\n <imsmd:langstring xml:lang=\"fr\">Author</imsmd:langstring>\n </imsmd:value>\n </imsmd:role>\n <imsmd:centity>\n <imsmd:vcard>\n begin:vcard\n fn:").concat(courseAuthor, "\n end:vcard\n </imsmd:vcard>\n </imsmd:centity>\n </imsmd:contribute>\n </imsmd:lifecycle>\n <imsmd:educational>\n <imsmd:typicallearningtime>\n <imsmd:datetime>").concat(formatLearningTime(courseGlobalLearningTime), "</imsmd:datetime>\n </imsmd:typicallearningtime>\n </imsmd:educational>\n </imsmd:lom>\n </metadata>\n <organizations default=\"Org1\">\n <organization identifier=\"Org1\">\n <title>").concat(courseTitle, "</title>\n ").concat(scoList
|
|
59
59
|
.map(function (_a) {
|
|
60
60
|
var scoID = _a.scoID, learningTime = _a.learningTime, resources = _a.resources, props = __rest(_a, ["scoID", "learningTime", "resources"]);
|
|
61
61
|
var _b = removeSpecialChars(props), scoTitle = _b.scoTitle, author = _b.author;
|
package/lib/SCORMAdapter.d.ts
CHANGED
|
@@ -12,10 +12,11 @@ export declare class SCORMAdapter {
|
|
|
12
12
|
private _callAPIFunction;
|
|
13
13
|
private _handleError;
|
|
14
14
|
private _warnNOAPI;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
private validateResult;
|
|
16
|
+
LMSInitialize(): true | void;
|
|
17
|
+
LMSTerminate(): true | void;
|
|
17
18
|
LMSGetValue(name: string): any;
|
|
18
|
-
LMSSetValue(name: string, value: string | number):
|
|
19
|
+
LMSSetValue(name: string, value: string | number): true | void;
|
|
19
20
|
LMSCommit(): any;
|
|
20
21
|
LMSGetLastError(): number;
|
|
21
22
|
LMSGetErrorString(errorCode: number): any;
|
package/lib/SCORMAdapter.js
CHANGED
|
@@ -144,11 +144,20 @@ var SCORMAdapter = /** @class */ (function () {
|
|
|
144
144
|
console.warn("Cannot execute this function because the SCORM API is not available.");
|
|
145
145
|
this._errorCallback("apiNotFound");
|
|
146
146
|
};
|
|
147
|
+
SCORMAdapter.prototype.validateResult = function (result) {
|
|
148
|
+
if (typeof result === "string") {
|
|
149
|
+
return result === "true";
|
|
150
|
+
}
|
|
151
|
+
else if (typeof result === "boolean") {
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
};
|
|
147
156
|
SCORMAdapter.prototype.LMSInitialize = function () {
|
|
148
157
|
var functionName = "Initialize";
|
|
149
158
|
var result = this._callAPIFunction(functionName);
|
|
150
159
|
var lastErrorCode = this.LMSGetLastError();
|
|
151
|
-
var success =
|
|
160
|
+
var success = this.validateResult(result) ||
|
|
152
161
|
(this._isSCORM2004
|
|
153
162
|
? lastErrorCode === 103 // 103 in 2004.* = already initialized
|
|
154
163
|
: lastErrorCode === 101); // 101 in 1.2 = already initialized
|
|
@@ -160,7 +169,7 @@ var SCORMAdapter = /** @class */ (function () {
|
|
|
160
169
|
SCORMAdapter.prototype.LMSTerminate = function () {
|
|
161
170
|
var functionName = this._isSCORM2004 ? "Terminate" : "Finish";
|
|
162
171
|
var result = this._callAPIFunction(functionName);
|
|
163
|
-
var success =
|
|
172
|
+
var success = this.validateResult(result);
|
|
164
173
|
return success || this._handleError(functionName);
|
|
165
174
|
};
|
|
166
175
|
SCORMAdapter.prototype.LMSGetValue = function (name) {
|
|
@@ -174,13 +183,24 @@ var SCORMAdapter = /** @class */ (function () {
|
|
|
174
183
|
this._lastRequest = { method: "set", key: name };
|
|
175
184
|
var functionName = "SetValue";
|
|
176
185
|
var result = this._callAPIFunction(functionName, [name, value]);
|
|
177
|
-
var success =
|
|
186
|
+
var success = this.validateResult(result);
|
|
178
187
|
return success || this._handleError("".concat(functionName, ": {").concat(name, ": ").concat(value, "}"));
|
|
179
188
|
};
|
|
180
189
|
SCORMAdapter.prototype.LMSCommit = function () {
|
|
190
|
+
var _this = this;
|
|
181
191
|
var result = this._callAPIFunction("Commit");
|
|
182
|
-
|
|
183
|
-
|
|
192
|
+
if ("then" in result && typeof result.then === "function") {
|
|
193
|
+
result.then(function (success) {
|
|
194
|
+
if (!_this.validateResult(success)) {
|
|
195
|
+
_this._errorCallback("commitFailed");
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
var success = this.validateResult(result);
|
|
202
|
+
return success || this._errorCallback("commitFailed");
|
|
203
|
+
}
|
|
184
204
|
};
|
|
185
205
|
SCORMAdapter.prototype.LMSGetLastError = function () {
|
|
186
206
|
return parseInt(this._callAPIFunction("GetLastError"));
|
|
@@ -360,12 +380,12 @@ var convertToTimeInterval = function (milliseconds) {
|
|
|
360
380
|
var minutes = data.minutes % 60;
|
|
361
381
|
var seconds = data.seconds % 60;
|
|
362
382
|
var cents = data.cents % 100;
|
|
363
|
-
var daysString = days ? days +
|
|
364
|
-
var hoursString = hours ? hours +
|
|
365
|
-
var minutesString = minutes ? minutes +
|
|
366
|
-
var secondsString = seconds ||
|
|
367
|
-
var hms = [hoursString, minutesString, secondsString].join(
|
|
368
|
-
return
|
|
383
|
+
var daysString = days ? days + "D" : "";
|
|
384
|
+
var hoursString = hours ? hours + "H" : "";
|
|
385
|
+
var minutesString = minutes ? minutes + "M" : "";
|
|
386
|
+
var secondsString = seconds || "0" + (cents ? "." + cents : "") + "S";
|
|
387
|
+
var hms = [hoursString, minutesString, secondsString].join("");
|
|
388
|
+
return "P" + daysString + "T" + hms;
|
|
369
389
|
};
|
|
370
390
|
exports.convertToTimeInterval = convertToTimeInterval;
|
|
371
391
|
var convertMsToCMITimespan = function (milliseconds) {
|
package/lib/loadContent.js
CHANGED
|
@@ -123,6 +123,14 @@ function loadContent() {
|
|
|
123
123
|
var sourceOrigin = sourceUrlParser.protocol + "//" + host;
|
|
124
124
|
new MessageReceiver(window, sourceOrigin, ADAPTER);
|
|
125
125
|
var sessionStart = new Date().getTime();
|
|
126
|
+
/*
|
|
127
|
+
* In case the beforeunload event is not triggered, we still want to send the session time to the LMS.
|
|
128
|
+
* This is why we send the session time every 10 seconds.
|
|
129
|
+
*/
|
|
130
|
+
setInterval(function () {
|
|
131
|
+
var now = new Date().getTime();
|
|
132
|
+
ADAPTER.setSessionTime(now - sessionStart);
|
|
133
|
+
}, 10000);
|
|
126
134
|
window.addEventListener("beforeunload", function (e) {
|
|
127
135
|
var sessionEnd = new Date().getTime();
|
|
128
136
|
ADAPTER.setSessionTime(sessionEnd - sessionStart);
|
package/package.json
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@didask/scol-r",
|
|
3
|
-
"version": "2.6.0
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Shareable Cross-Origin Learning Resources",
|
|
5
5
|
"main": "index.html",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"lib/"
|
|
9
|
-
],
|
|
7
|
+
"files": ["lib/"],
|
|
10
8
|
"scripts": {
|
|
11
9
|
"build": "tsc",
|
|
12
10
|
"clean": "rm -rf node_modules lib",
|
|
@@ -16,10 +14,7 @@
|
|
|
16
14
|
"type": "git",
|
|
17
15
|
"url": "git+https://github.com/Didask/scol-r.git"
|
|
18
16
|
},
|
|
19
|
-
"keywords": [
|
|
20
|
-
"SCORM",
|
|
21
|
-
"CORS"
|
|
22
|
-
],
|
|
17
|
+
"keywords": ["SCORM", "CORS"],
|
|
23
18
|
"author": "Didask",
|
|
24
19
|
"license": "ISC",
|
|
25
20
|
"bugs": {
|