@didask/scol-r 1.0.1-beta-1 → 2.0.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/MessageHandler.d.ts +11 -10
- package/lib/MessageHandler.js +39 -1
- package/lib/SCORMAdapter.d.ts +1 -0
- package/lib/SCORMAdapter.js +20 -8
- package/lib/index.d.ts +9 -0
- package/lib/index.js +12 -1
- package/lib/loadContent.js +1 -1
- package/package.json +1 -1
package/lib/MessageHandler.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
declare function
|
|
2
|
-
declare class
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
setObjectives
|
|
10
|
-
setObjectiveScore
|
|
1
|
+
export declare function MessageReceiver(win: Window, sourceOrigin: string, adapter: any): void;
|
|
2
|
+
export declare class MessageEmitter {
|
|
3
|
+
private currentWindow;
|
|
4
|
+
private lmsOrigin;
|
|
5
|
+
constructor(lmsOrigin: string);
|
|
6
|
+
private sendMessage;
|
|
7
|
+
setLessonStatus(status: string): void;
|
|
8
|
+
setScore(score: number): void;
|
|
9
|
+
setObjectives(objectives: string[]): void;
|
|
10
|
+
setObjectiveScore(objectiveId: string, score: number): void;
|
|
11
|
+
setObjectiveStatus(objectiveId: string, status: "completed" | "incomplete"): void;
|
|
11
12
|
}
|
package/lib/MessageHandler.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageEmitter = exports.MessageReceiver = void 0;
|
|
4
|
+
function MessageReceiver(win, sourceOrigin, adapter) {
|
|
2
5
|
this.timeoutId = null;
|
|
3
6
|
win.addEventListener("message", function (e) {
|
|
4
7
|
var _this = this;
|
|
@@ -41,4 +44,39 @@ function MessageHandler(win, sourceOrigin, adapter) {
|
|
|
41
44
|
adapter.setObjectiveScore(objectiveId, score);
|
|
42
45
|
}
|
|
43
46
|
};
|
|
47
|
+
this.setObjectiveStatus = function (objectiveId, status) {
|
|
48
|
+
if (adapter.objectivesAreAvailable) {
|
|
49
|
+
adapter.setObjectiveStatus(objectiveId, status);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
44
52
|
}
|
|
53
|
+
exports.MessageReceiver = MessageReceiver;
|
|
54
|
+
var MessageEmitter = /** @class */ (function () {
|
|
55
|
+
function MessageEmitter(lmsOrigin) {
|
|
56
|
+
this.currentWindow = window.parent || window.opener;
|
|
57
|
+
this.lmsOrigin = lmsOrigin;
|
|
58
|
+
}
|
|
59
|
+
MessageEmitter.prototype.sendMessage = function (name, values) {
|
|
60
|
+
this.currentWindow.postMessage({
|
|
61
|
+
function: name,
|
|
62
|
+
arguments: values,
|
|
63
|
+
}, this.lmsOrigin);
|
|
64
|
+
};
|
|
65
|
+
MessageEmitter.prototype.setLessonStatus = function (status) {
|
|
66
|
+
this.sendMessage("setLessonStatus", [status]);
|
|
67
|
+
};
|
|
68
|
+
MessageEmitter.prototype.setScore = function (score) {
|
|
69
|
+
this.sendMessage("setScore", [score]);
|
|
70
|
+
};
|
|
71
|
+
MessageEmitter.prototype.setObjectives = function (objectives) {
|
|
72
|
+
this.sendMessage("setObjectives", [objectives]);
|
|
73
|
+
};
|
|
74
|
+
MessageEmitter.prototype.setObjectiveScore = function (objectiveId, score) {
|
|
75
|
+
this.sendMessage("setObjectiveScore", [objectiveId, score]);
|
|
76
|
+
};
|
|
77
|
+
MessageEmitter.prototype.setObjectiveStatus = function (objectiveId, status) {
|
|
78
|
+
this.sendMessage("setObjectiveStatus", [objectiveId, status]);
|
|
79
|
+
};
|
|
80
|
+
return MessageEmitter;
|
|
81
|
+
}());
|
|
82
|
+
exports.MessageEmitter = MessageEmitter;
|
package/lib/SCORMAdapter.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export declare class SCORMAdapter {
|
|
|
29
29
|
setObjectives(objectivesIds: string[]): void;
|
|
30
30
|
get objectives(): any[];
|
|
31
31
|
setObjectiveScore(objectiveId: string, score: number): void;
|
|
32
|
+
setObjectiveStatus(objectiveId: string, status: "completed" | "incomplete"): void;
|
|
32
33
|
getObjectiveScore(objectiveId: string): any;
|
|
33
34
|
setSuspendData(data: string): void;
|
|
34
35
|
get suspendData(): any;
|
package/lib/SCORMAdapter.js
CHANGED
|
@@ -204,7 +204,8 @@ var SCORMAdapter = /** @class */ (function () {
|
|
|
204
204
|
SCORMAdapter.prototype.setSessionTime = function (msSessionTime) {
|
|
205
205
|
var CMIVariableName = this._isSCORM2004
|
|
206
206
|
? "cmi.session_time"
|
|
207
|
-
: "cmi.core.session_time"
|
|
207
|
+
: "cmi.core.session_time";
|
|
208
|
+
var duration;
|
|
208
209
|
if (this._isSCORM2004) {
|
|
209
210
|
duration = Math.round(msSessionTime / 1000);
|
|
210
211
|
}
|
|
@@ -252,9 +253,23 @@ var SCORMAdapter = /** @class */ (function () {
|
|
|
252
253
|
for (var index = 0; index < objectivesNbr; index++) {
|
|
253
254
|
var storedObjectiveId = this.LMSGetValue("cmi.objectives." + index + ".id");
|
|
254
255
|
if (objectiveId === storedObjectiveId) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
this.LMSSetValue("cmi.objectives." + index + ".score.raw", score);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
SCORMAdapter.prototype.setObjectiveStatus = function (objectiveId, status) {
|
|
262
|
+
var objectivesNbr = this.LMSGetValue("cmi.objectives._count");
|
|
263
|
+
for (var index = 0; index < objectivesNbr; index++) {
|
|
264
|
+
var storedObjectiveId = this.LMSGetValue("cmi.objectives." + index + ".id");
|
|
265
|
+
if (objectiveId === storedObjectiveId) {
|
|
266
|
+
if (this._isSCORM2004) {
|
|
267
|
+
this.LMSSetValue("cmi.objectives." + index + ".success_status", status === "completed" ? "passed" : "unknown");
|
|
268
|
+
this.LMSSetValue("cmi.objectives." + index + ".completion_status", status === "completed" ? "completed" : "incomplete");
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
this.LMSSetValue("cmi.objectives." + index + ".status", status === "completed" ? "passed" : "incomplete");
|
|
272
|
+
}
|
|
258
273
|
return;
|
|
259
274
|
}
|
|
260
275
|
}
|
|
@@ -264,10 +279,7 @@ var SCORMAdapter = /** @class */ (function () {
|
|
|
264
279
|
for (var index = 0; index < objectivesNbr; index++) {
|
|
265
280
|
var storedObjectiveId = this.LMSGetValue("cmi.objectives." + index + ".id");
|
|
266
281
|
if (objectiveId === storedObjectiveId) {
|
|
267
|
-
|
|
268
|
-
if (this._isSCORM2004)
|
|
269
|
-
score = score * 100;
|
|
270
|
-
return score;
|
|
282
|
+
return this.LMSGetValue("cmi.objectives." + index + ".score.raw");
|
|
271
283
|
}
|
|
272
284
|
}
|
|
273
285
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
export * from "./ManifestGenerator";
|
|
2
2
|
export * from "./SCORMAdapter";
|
|
3
3
|
export * from "./HTMLGenerator";
|
|
4
|
+
export { MessageEmitter } from "./MessageHandler";
|
|
4
5
|
export declare const libFiles: readonly ["loadContent.js", "MessageHandler.js", "SCORMAdapter.js"];
|
|
5
6
|
export declare const scormVersions: readonly ["1.2", "2004 3rd Edition", "2004 4th Edition"];
|
|
7
|
+
export declare enum LessonStatus {
|
|
8
|
+
Passed = "passed",
|
|
9
|
+
Failed = "failed",
|
|
10
|
+
Completed = "completed",
|
|
11
|
+
Incomplete = "incomplete",
|
|
12
|
+
NotAttempted = "not attempted",
|
|
13
|
+
Browsed = "browsed"
|
|
14
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -10,10 +10,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.scormVersions = exports.libFiles = void 0;
|
|
13
|
+
exports.LessonStatus = exports.scormVersions = exports.libFiles = exports.MessageEmitter = void 0;
|
|
14
14
|
__exportStar(require("./ManifestGenerator"), exports);
|
|
15
15
|
__exportStar(require("./SCORMAdapter"), exports);
|
|
16
16
|
__exportStar(require("./HTMLGenerator"), exports);
|
|
17
|
+
var MessageHandler_1 = require("./MessageHandler");
|
|
18
|
+
Object.defineProperty(exports, "MessageEmitter", { enumerable: true, get: function () { return MessageHandler_1.MessageEmitter; } });
|
|
17
19
|
exports.libFiles = [
|
|
18
20
|
"loadContent.js",
|
|
19
21
|
"MessageHandler.js",
|
|
@@ -24,3 +26,12 @@ exports.scormVersions = [
|
|
|
24
26
|
"2004 3rd Edition",
|
|
25
27
|
"2004 4th Edition",
|
|
26
28
|
];
|
|
29
|
+
var LessonStatus;
|
|
30
|
+
(function (LessonStatus) {
|
|
31
|
+
LessonStatus["Passed"] = "passed";
|
|
32
|
+
LessonStatus["Failed"] = "failed";
|
|
33
|
+
LessonStatus["Completed"] = "completed";
|
|
34
|
+
LessonStatus["Incomplete"] = "incomplete";
|
|
35
|
+
LessonStatus["NotAttempted"] = "not attempted";
|
|
36
|
+
LessonStatus["Browsed"] = "browsed";
|
|
37
|
+
})(LessonStatus = exports.LessonStatus || (exports.LessonStatus = {}));
|
package/lib/loadContent.js
CHANGED
|
@@ -116,7 +116,7 @@ function loadContent() {
|
|
|
116
116
|
host = host.slice(0, host.indexOf(":"));
|
|
117
117
|
}
|
|
118
118
|
var sourceOrigin = sourceUrlParser.protocol + "//" + host;
|
|
119
|
-
new
|
|
119
|
+
new MessageReceiver(window, sourceOrigin, ADAPTER);
|
|
120
120
|
window.addEventListener("beforeunload", function (e) {
|
|
121
121
|
ADAPTER.LMSTerminate();
|
|
122
122
|
});
|