@didask/scol-r 2.6.4 → 2.7.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 +12 -1
- package/lib/MessageHandler.js +44 -39
- package/lib/SCORMAdapter.d.ts +3 -3
- package/lib/SCORMAdapter.js +9 -3
- package/package.json +8 -3
- package/lib/SCORMAdapter.test.d.ts +0 -1
- package/lib/SCORMAdapter.test.js +0 -14
package/lib/MessageHandler.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare class MessageReceiver {
|
|
2
|
+
private readonly adapter;
|
|
3
|
+
constructor(win: Window, sourceOrigin: string, adapter: any);
|
|
4
|
+
commit(): void;
|
|
5
|
+
setTitle(title: string): void;
|
|
6
|
+
setScore(score: string): void;
|
|
7
|
+
setStudent(studentId: string, studentName: string): void;
|
|
8
|
+
setLessonStatus(lessonStatus: string): void;
|
|
9
|
+
setObjectives(objectivesIds: string[]): void;
|
|
10
|
+
setObjectiveScore(objectiveId: string, score: number): void;
|
|
11
|
+
setObjectiveStatus(objectiveId: string, status: string): void;
|
|
12
|
+
}
|
|
2
13
|
export declare class MessageEmitter {
|
|
3
14
|
private currentWindow;
|
|
4
15
|
private lmsOrigin;
|
package/lib/MessageHandler.js
CHANGED
|
@@ -1,58 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MessageEmitter = exports.MessageReceiver = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
functionArgs
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
var MessageReceiver = /** @class */ (function () {
|
|
5
|
+
function MessageReceiver(win, sourceOrigin, adapter) {
|
|
6
|
+
this.adapter = adapter;
|
|
7
|
+
var timeoutId = null;
|
|
8
|
+
win.addEventListener("message", function (e) {
|
|
9
|
+
var _this = this;
|
|
10
|
+
if (e.origin !== sourceOrigin)
|
|
11
|
+
return;
|
|
12
|
+
var functionName = e.data["function"];
|
|
13
|
+
var functionArgs = e.data["arguments"];
|
|
14
|
+
if (functionName &&
|
|
15
|
+
functionArgs &&
|
|
16
|
+
typeof this[functionName] === "function") {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
this[functionName].apply(this, functionArgs);
|
|
19
|
+
if (timeoutId) {
|
|
20
|
+
clearTimeout(timeoutId);
|
|
21
|
+
}
|
|
22
|
+
timeoutId = setTimeout(function () {
|
|
23
|
+
_this.commit();
|
|
24
|
+
timeoutId = null;
|
|
25
|
+
}, 500);
|
|
18
26
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
}.bind(this));
|
|
25
|
-
this.commit = function () {
|
|
26
|
-
adapter.LMSCommit();
|
|
27
|
+
}.bind(this));
|
|
28
|
+
}
|
|
29
|
+
MessageReceiver.prototype.commit = function () {
|
|
30
|
+
this.adapter.LMSCommit();
|
|
27
31
|
};
|
|
28
|
-
|
|
32
|
+
MessageReceiver.prototype.setTitle = function (title) {
|
|
29
33
|
document.title = title;
|
|
30
34
|
};
|
|
31
|
-
|
|
32
|
-
adapter.setScore(score);
|
|
35
|
+
MessageReceiver.prototype.setScore = function (score) {
|
|
36
|
+
this.adapter.setScore(score);
|
|
33
37
|
};
|
|
34
|
-
|
|
35
|
-
adapter.setStudent(studentId, studentName);
|
|
38
|
+
MessageReceiver.prototype.setStudent = function (studentId, studentName) {
|
|
39
|
+
this.adapter.setStudent(studentId, studentName);
|
|
36
40
|
};
|
|
37
|
-
|
|
38
|
-
adapter.setLessonStatus(lessonStatus);
|
|
41
|
+
MessageReceiver.prototype.setLessonStatus = function (lessonStatus) {
|
|
42
|
+
this.adapter.setLessonStatus(lessonStatus);
|
|
39
43
|
};
|
|
40
|
-
|
|
41
|
-
if (adapter.objectivesAreAvailable) {
|
|
42
|
-
adapter.setObjectives(objectivesIds);
|
|
44
|
+
MessageReceiver.prototype.setObjectives = function (objectivesIds) {
|
|
45
|
+
if (this.adapter.objectivesAreAvailable) {
|
|
46
|
+
this.adapter.setObjectives(objectivesIds);
|
|
43
47
|
}
|
|
44
48
|
};
|
|
45
|
-
|
|
46
|
-
if (adapter.objectivesAreAvailable) {
|
|
47
|
-
adapter.setObjectiveScore(objectiveId, score);
|
|
49
|
+
MessageReceiver.prototype.setObjectiveScore = function (objectiveId, score) {
|
|
50
|
+
if (this.adapter.objectivesAreAvailable) {
|
|
51
|
+
this.adapter.setObjectiveScore(objectiveId, score);
|
|
48
52
|
}
|
|
49
53
|
};
|
|
50
|
-
|
|
51
|
-
if (adapter.objectivesAreAvailable) {
|
|
52
|
-
adapter.setObjectiveStatus(objectiveId, status);
|
|
54
|
+
MessageReceiver.prototype.setObjectiveStatus = function (objectiveId, status) {
|
|
55
|
+
if (this.adapter.objectivesAreAvailable) {
|
|
56
|
+
this.adapter.setObjectiveStatus(objectiveId, status);
|
|
53
57
|
}
|
|
54
58
|
};
|
|
55
|
-
|
|
59
|
+
return MessageReceiver;
|
|
60
|
+
}());
|
|
56
61
|
exports.MessageReceiver = MessageReceiver;
|
|
57
62
|
var MessageEmitter = /** @class */ (function () {
|
|
58
63
|
function MessageEmitter(lmsOrigin) {
|
package/lib/SCORMAdapter.d.ts
CHANGED
|
@@ -17,14 +17,14 @@ export declare class SCORMAdapter {
|
|
|
17
17
|
LMSTerminate(): true | void;
|
|
18
18
|
LMSGetValue(name: string): any;
|
|
19
19
|
LMSSetValue(name: string, value: string | number): true | void;
|
|
20
|
-
LMSCommit():
|
|
20
|
+
LMSCommit(): true | undefined;
|
|
21
21
|
LMSGetLastError(): number;
|
|
22
22
|
LMSGetErrorString(errorCode: number): any;
|
|
23
23
|
LMSGetDiagnostic(errorCode: number): any;
|
|
24
24
|
get lastRequest(): {
|
|
25
|
-
method
|
|
25
|
+
method?: "get" | "set" | undefined;
|
|
26
26
|
key: string;
|
|
27
|
-
};
|
|
27
|
+
} | null;
|
|
28
28
|
getDataFromLMS(): any;
|
|
29
29
|
getLearnerId(): any;
|
|
30
30
|
getLearnerName(): any;
|
package/lib/SCORMAdapter.js
CHANGED
|
@@ -15,7 +15,7 @@ var SCORMAdapter = /** @class */ (function () {
|
|
|
15
15
|
code: 401,
|
|
16
16
|
getShouldBeIgnored: function () {
|
|
17
17
|
return !_this._isSCORM2004 &&
|
|
18
|
-
_this._lastRequest &&
|
|
18
|
+
!!_this._lastRequest &&
|
|
19
19
|
_this._lastRequest.method === "get" &&
|
|
20
20
|
_this._lastRequest.key === "cmi.objectives._children";
|
|
21
21
|
},
|
|
@@ -24,7 +24,7 @@ var SCORMAdapter = /** @class */ (function () {
|
|
|
24
24
|
code: 402,
|
|
25
25
|
getShouldBeIgnored: function () {
|
|
26
26
|
return _this._isSCORM2004 &&
|
|
27
|
-
_this._lastRequest &&
|
|
27
|
+
!!_this._lastRequest &&
|
|
28
28
|
_this._lastRequest.method === "get" &&
|
|
29
29
|
_this._lastRequest.key === "cmi.objectives._children";
|
|
30
30
|
},
|
|
@@ -32,11 +32,16 @@ var SCORMAdapter = /** @class */ (function () {
|
|
|
32
32
|
{
|
|
33
33
|
code: 351,
|
|
34
34
|
getShouldBeIgnored: function () {
|
|
35
|
-
|
|
35
|
+
var _a;
|
|
36
|
+
return ((_a = _this._lastRequest) === null || _a === void 0 ? void 0 : _a.method) === "set" &&
|
|
36
37
|
new RegExp("^cmi.objectives.\\d+.id$").test(_this._lastRequest.key) &&
|
|
37
38
|
!!_this.LMSGetValue(_this._lastRequest.key);
|
|
38
39
|
},
|
|
39
40
|
},
|
|
41
|
+
{
|
|
42
|
+
code: 113,
|
|
43
|
+
getShouldBeIgnored: function () { var _a; return ((_a = _this._lastRequest) === null || _a === void 0 ? void 0 : _a.key) === "Terminate"; },
|
|
44
|
+
},
|
|
40
45
|
];
|
|
41
46
|
this._API = null;
|
|
42
47
|
this._isSCORM2004 = false;
|
|
@@ -167,6 +172,7 @@ var SCORMAdapter = /** @class */ (function () {
|
|
|
167
172
|
return success || this._handleError(functionName);
|
|
168
173
|
};
|
|
169
174
|
SCORMAdapter.prototype.LMSTerminate = function () {
|
|
175
|
+
this._lastRequest = { key: "Terminate" };
|
|
170
176
|
var functionName = this._isSCORM2004 ? "Terminate" : "Finish";
|
|
171
177
|
var result = this._callAPIFunction(functionName);
|
|
172
178
|
var success = this.validateResult(result);
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@didask/scol-r",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Shareable Cross-Origin Learning Resources",
|
|
5
5
|
"main": "index.html",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
|
-
"files": [
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/"
|
|
9
|
+
],
|
|
8
10
|
"scripts": {
|
|
9
11
|
"build": "tsc",
|
|
10
12
|
"clean": "rm -rf node_modules lib",
|
|
@@ -14,7 +16,10 @@
|
|
|
14
16
|
"type": "git",
|
|
15
17
|
"url": "git+https://github.com/Didask/scol-r.git"
|
|
16
18
|
},
|
|
17
|
-
"keywords": [
|
|
19
|
+
"keywords": [
|
|
20
|
+
"SCORM",
|
|
21
|
+
"CORS"
|
|
22
|
+
],
|
|
18
23
|
"author": "Didask",
|
|
19
24
|
"license": "ISC",
|
|
20
25
|
"bugs": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/SCORMAdapter.test.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var bun_test_1 = require("bun:test");
|
|
4
|
-
var SCORMAdapter_1 = require("./SCORMAdapter");
|
|
5
|
-
bun_test_1.test('convertMsToCMITimespan ("0000:00:00.00")', function () {
|
|
6
|
-
var milliseconds = (36 * 60 * 60 * 1000) + (6 * 60 * 1000) + (2 * 1000) + (23 * 10);
|
|
7
|
-
var CMITimespan = SCORMAdapter_1.convertMsToCMITimespan(milliseconds);
|
|
8
|
-
bun_test_1.expect(CMITimespan).toBe('0036:06:02.23');
|
|
9
|
-
});
|
|
10
|
-
bun_test_1.test('convertToTimeInterval', function () {
|
|
11
|
-
var milliseconds = (36 * 60 * 60 * 1000) + (6 * 60 * 1000) + (2 * 1000) + (23 * 10);
|
|
12
|
-
var timeInterval = SCORMAdapter_1.convertToTimeInterval(milliseconds);
|
|
13
|
-
bun_test_1.expect(timeInterval).toBe('P1DT12H6M2');
|
|
14
|
-
});
|