@didask/scol-r 1.0.1-beta-3 → 3.0.0-beta-1

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.
@@ -1,5 +1,9 @@
1
1
  export interface HTMLGeneratorProps {
2
2
  dataSource: string;
3
3
  libPath?: string;
4
+ sentry?: {
5
+ dsn: string;
6
+ tags?: Record<string, string>;
7
+ };
4
8
  }
5
9
  export declare function HTMLGenerator(props: HTMLGeneratorProps): string;
@@ -1,8 +1,20 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.HTMLGenerator = void 0;
4
15
  function HTMLGenerator(props) {
5
- var dataSource = props.dataSource, _a = props.libPath, libPath = _a === void 0 ? "lib" : _a;
6
- return "<!DOCTYPE html>\n <html>\n <head>\n <title>SCO local endpoint</title>\n <meta charset=\"UTF-8\"/>\n <script>var exports = {};</script>\n <script type=\"text/javascript\" src=\"" + libPath + "/SCORMAdapter.js\"></script>\n <script type=\"text/javascript\" src=\"" + libPath + "/MessageHandler.js\"></script>\n <script type=\"text/javascript\" src=\"" + libPath + "/loadContent.js\"></script>\n <style type=\"text/css\">\n html, body { margin: 0; padding:0; overflow:hidden; width: 100%; height: 100%; }\n body {\n font-size: 20px;\n font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n color: #1d1046;\n }\n #wrapper { display: flex; flex-direction: column; height: 100%; }\n .container { width: 80%; max-width: 1200px; padding: 15px; margin: auto; }\n #wrapper .header {\n padding-top: 20px; padding-bottom: 20px;\n background-color: #f3f4f5;\n }\n #wrapper .messages { flex-grow: 1; padding-top: 20px; padding-bottom: 20px; }\n #wrapper .messages p { color: red; }\n #title-error-messages { color: #1d1046; }\n #wrapper .footer {\n background-color: #1d1046; color: white;\n padding-top: 10px; padding-bottom: 10px;\n }\n #wrapper .footer a { color: white; }\n\n iframe { overflow: hidden; height: 100%; width: 100%; }\n iframe + #wrapper { display: none; }\n #runtime-error {\n position: fixed;\n left: 20px; bottom: 20px; padding: 15px;\n background-color: #f44a3d; color: white;\n font-size: 16px;\n }\n #runtime-error h6, #runtime-error p { margin: 0 0 10px;}\n #runtime-error p:last-child { margin: 0;}\n #runtime-error:empty { display: none; }\n </style>\n </head>\n <!-- Set the body's data-source attribute to the SCO's remote endpoint. -->\n <body onload=\"loadContent();\" data-source=\"" + dataSource + "\">\n <div id=\"wrapper\">\n <div class=\"header\"><div class=\"container\">\n <h1 id=\"title\">Your content is loading...</h1>\n <p id=\"subtitle\">Please wait, or if your content doesn't appear, try closing and opening this window again.</p>\n </div></div>\n <div class=\"messages container\">\n <h2 id=\"title-error-messages\">If the initialization fails, error messages will appear below:</h2>\n </div>\n <div class=\"footer\"><div class=\"container\" id=\"footer-content\">\n This content is loaded via <a href=\"https://github.com/Didask/scol-r\" target=\"_blank\">SCOL-R</a>, a cross-domain SCORM connector created by <a href=\"https://www.didask.com\" target=\"_blank\">Didask</a>.\n </div></div>\n </div>\n <div id=\"runtime-error\"></div>\n </body>\n </html>";
16
+ var dataSource = props.dataSource, _a = props.libPath, libPath = _a === void 0 ? "lib" : _a, _b = props.sentry, dsn = _b.dsn, tags = _b.tags;
17
+ return "<!DOCTYPE html>\n <html>\n <head>\n <title>SCO local endpoint</title>\n <meta charset=\"UTF-8\"/>\n <script>var exports = {};</script>\n " + (dsn &&
18
+ "<script\n src=\"https://browser.sentry-cdn.com/7.3.1/bundle.min.js\"\n integrity=\"sha384-07qUw81m8MXGTEXf9FQODO4Vop82t3F03SS3v3EOfrf8j7bOb/oJNg6inMDKFk2I\"\n crossorigin=\"anonymous\"\n ></script>\n <script>Sentry.init(" + JSON.stringify(__assign({ dsn: dsn }, (tags && { initialScope: { tags: tags } }))) + ");</script>") + "\n <script type=\"text/javascript\" src=\"" + libPath + "/SCORMAdapter.js\"></script>\n <script type=\"text/javascript\" src=\"" + libPath + "/MessageHandler.js\"></script>\n <script type=\"text/javascript\" src=\"" + libPath + "/loadContent.js\"></script>\n <style type=\"text/css\">\n html, body { margin: 0; padding:0; overflow:hidden; width: 100%; height: 100%; }\n body {\n font-size: 20px;\n font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n color: #1d1046;\n }\n #wrapper { display: flex; flex-direction: column; height: 100%; }\n .container { width: 80%; max-width: 1200px; padding: 15px; margin: auto; }\n #wrapper .header {\n padding-top: 20px; padding-bottom: 20px;\n background-color: #f3f4f5;\n }\n #wrapper .messages { flex-grow: 1; padding-top: 20px; padding-bottom: 20px; }\n #wrapper .messages p { color: red; }\n #title-error-messages { color: #1d1046; }\n #wrapper .footer {\n background-color: #1d1046; color: white;\n padding-top: 10px; padding-bottom: 10px;\n }\n #wrapper .footer a { color: white; }\n\n iframe { overflow: hidden; height: 100%; width: 100%; }\n iframe + #wrapper { display: none; }\n #runtime-error {\n position: fixed;\n left: 20px; bottom: 20px; padding: 15px;\n background-color: #f44a3d; color: white;\n font-size: 16px;\n }\n #runtime-error h6, #runtime-error p { margin: 0 0 10px;}\n #runtime-error p:last-child { margin: 0;}\n #runtime-error:empty { display: none; }\n </style>\n </head>\n <!-- Set the body's data-source attribute to the SCO's remote endpoint. -->\n <body onload=\"loadContent();\" data-source=\"" + dataSource + "\">\n <div id=\"wrapper\">\n <div class=\"header\"><div class=\"container\">\n <h1 id=\"title\">Your content is loading...</h1>\n <p id=\"subtitle\">Please wait, or if your content doesn't appear, try closing and opening this window again.</p>\n </div></div>\n <div class=\"messages container\">\n <h2 id=\"title-error-messages\">If the initialization fails, error messages will appear below:</h2>\n </div>\n <div class=\"footer\"><div class=\"container\" id=\"footer-content\">\n This content is loaded via <a href=\"https://github.com/Didask/scol-r\" target=\"_blank\">SCOL-R</a>, a cross-domain SCORM connector created by <a href=\"https://www.didask.com\" target=\"_blank\">Didask</a>.\n </div></div>\n </div>\n <div id=\"runtime-error\"></div>\n </body>\n </html>";
7
19
  }
8
20
  exports.HTMLGenerator = HTMLGenerator;
@@ -1,21 +1,12 @@
1
- export declare class MessageReceiver {
2
- private timeoutId;
3
- private adapter;
4
- constructor(win: Window, sourceOrigin: string, adapter: any);
5
- commit(): void;
6
- setTitle(title: string): void;
7
- setScore(score: number): void;
8
- setLessonStatus(lessonStatus: string): void;
9
- setObjectives(objectivesIds: string[]): void;
10
- setObjectiveScore(objectiveId: string, score: number): void;
11
- }
1
+ export declare function MessageReceiver(win: Window, sourceOrigin: string, adapter: any): void;
12
2
  export declare class MessageEmitter {
13
3
  private currentWindow;
14
4
  private lmsOrigin;
15
- constructor(currentWindow: Window, lmsOrigin: string);
5
+ constructor(lmsOrigin: string);
16
6
  private sendMessage;
17
7
  setLessonStatus(status: string): void;
18
- setObjectiveScore(objectiveId: string, score: number): void;
19
8
  setScore(score: number): void;
20
9
  setObjectives(objectives: string[]): void;
10
+ setObjectiveScore(objectiveId: string, score: number): void;
11
+ setObjectiveStatus(objectiveId: string, status: "completed" | "incomplete"): void;
21
12
  }
@@ -1,65 +1,59 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MessageEmitter = exports.MessageReceiver = void 0;
4
- var MessageReceiver = /** @class */ (function () {
5
- function MessageReceiver(win, sourceOrigin, adapter) {
4
+ function MessageReceiver(win, sourceOrigin, adapter) {
5
+ this.timeoutId = null;
6
+ win.addEventListener("message", function (e) {
6
7
  var _this = this;
7
- this.adapter = adapter;
8
- var handler = function (e) {
9
- if (e.origin !== sourceOrigin)
10
- return;
11
- var functionName = e.data["function"];
12
- var functionArgs = e.data["arguments"];
13
- typeof _this["adapter"] === "function";
14
- if (functionName && Array.isArray(functionArgs)) {
15
- var func = Object.entries(_this).reduce(function (acc, _a) {
16
- var key = _a[0], value = _a[1];
17
- if (key === functionName && typeof value === "function")
18
- return value;
19
- return acc;
20
- }, undefined);
21
- if (func) {
22
- func.apply(void 0, functionArgs);
23
- if (_this.timeoutId) {
24
- clearTimeout(_this.timeoutId);
25
- }
26
- _this.timeoutId = setTimeout(function () {
27
- _this.commit();
28
- _this.timeoutId = null;
29
- }, 500);
30
- }
8
+ if (e.origin !== sourceOrigin)
9
+ return;
10
+ var functionName = e.data["function"];
11
+ var functionArgs = e.data["arguments"];
12
+ if (functionName &&
13
+ functionArgs &&
14
+ typeof this[functionName] === "function") {
15
+ this[functionName].apply(this, functionArgs);
16
+ if (this.timeoutId) {
17
+ clearTimeout(this.timeoutId);
31
18
  }
32
- };
33
- win.addEventListener("message", handler);
34
- }
35
- MessageReceiver.prototype.commit = function () {
36
- this.adapter.LMSCommit();
19
+ this.timeoutId = setTimeout(function () {
20
+ _this.commit();
21
+ _this.timeoutId = null;
22
+ }, 500);
23
+ }
24
+ }.bind(this));
25
+ this.commit = function () {
26
+ adapter.LMSCommit();
37
27
  };
38
- MessageReceiver.prototype.setTitle = function (title) {
28
+ this.setTitle = function (title) {
39
29
  document.title = title;
40
30
  };
41
- MessageReceiver.prototype.setScore = function (score) {
42
- this.adapter.setScore(score);
31
+ this.setScore = function (score) {
32
+ adapter.setScore(score);
43
33
  };
44
- MessageReceiver.prototype.setLessonStatus = function (lessonStatus) {
45
- this.adapter.setLessonStatus(lessonStatus);
34
+ this.setLessonStatus = function (lessonStatus) {
35
+ adapter.setLessonStatus(lessonStatus);
46
36
  };
47
- MessageReceiver.prototype.setObjectives = function (objectivesIds) {
48
- if (this.adapter.objectivesAreAvailable) {
49
- this.adapter.setObjectives(objectivesIds);
37
+ this.setObjectives = function (objectivesIds) {
38
+ if (adapter.objectivesAreAvailable) {
39
+ adapter.setObjectives(objectivesIds);
50
40
  }
51
41
  };
52
- MessageReceiver.prototype.setObjectiveScore = function (objectiveId, score) {
53
- if (this.adapter.objectivesAreAvailable) {
54
- this.adapter.setObjectiveScore(objectiveId, score);
42
+ this.setObjectiveScore = function (objectiveId, score) {
43
+ if (adapter.objectivesAreAvailable) {
44
+ adapter.setObjectiveScore(objectiveId, score);
55
45
  }
56
46
  };
57
- return MessageReceiver;
58
- }());
47
+ this.setObjectiveStatus = function (objectiveId, status) {
48
+ if (adapter.objectivesAreAvailable) {
49
+ adapter.setObjectiveStatus(objectiveId, status);
50
+ }
51
+ };
52
+ }
59
53
  exports.MessageReceiver = MessageReceiver;
60
54
  var MessageEmitter = /** @class */ (function () {
61
- function MessageEmitter(currentWindow, lmsOrigin) {
62
- this.currentWindow = currentWindow;
55
+ function MessageEmitter(lmsOrigin) {
56
+ this.currentWindow = window.parent || window.opener;
63
57
  this.lmsOrigin = lmsOrigin;
64
58
  }
65
59
  MessageEmitter.prototype.sendMessage = function (name, values) {
@@ -71,15 +65,18 @@ var MessageEmitter = /** @class */ (function () {
71
65
  MessageEmitter.prototype.setLessonStatus = function (status) {
72
66
  this.sendMessage("setLessonStatus", [status]);
73
67
  };
74
- MessageEmitter.prototype.setObjectiveScore = function (objectiveId, score) {
75
- this.sendMessage("setObjectiveScore", [objectiveId, score]);
76
- };
77
68
  MessageEmitter.prototype.setScore = function (score) {
78
69
  this.sendMessage("setScore", [score]);
79
70
  };
80
71
  MessageEmitter.prototype.setObjectives = function (objectives) {
81
72
  this.sendMessage("setObjectives", [objectives]);
82
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
+ };
83
80
  return MessageEmitter;
84
81
  }());
85
82
  exports.MessageEmitter = MessageEmitter;
@@ -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;
@@ -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", duration;
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
- if (this._isSCORM2004)
256
- score = score / 100;
257
- this.LMSSetValue("cmi.objectives." + index + ".score." + (this._isSCORM2004 ? "scaled" : "raw"), score);
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
- var score = this.LMSGetValue("cmi.objectives." + index + ".score." + (this._isSCORM2004 ? "scaled" : "raw"));
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
  };
@@ -48,6 +48,11 @@ function loadContent() {
48
48
  newMessage.innerHTML = localizeMessage(message);
49
49
  messagesContainer.length && messagesContainer[0].appendChild(newMessage);
50
50
  };
51
+ var captureSentryException = function (args) {
52
+ if ("Sentry" in window) {
53
+ Sentry.captureException(new Error(args.reduce(function (acc, arg) { return (arg ? acc + " -- " + arg : acc); }, "")));
54
+ }
55
+ };
51
56
  var displayRuntimeError = function () {
52
57
  var errorContainer = document.getElementById("runtime-error");
53
58
  if (!(arguments && arguments.length)) {
@@ -63,6 +68,7 @@ function loadContent() {
63
68
  thisError.innerHTML = localizeMessage(arguments[i]);
64
69
  errorContainer.appendChild(thisError);
65
70
  }
71
+ captureSentryException(arguments);
66
72
  // Remove the messages after 6 seconds
67
73
  setTimeout(function () {
68
74
  errorContainer.innerHTML = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@didask/scol-r",
3
- "version": "1.0.1-beta-3",
3
+ "version": "3.0.0-beta-1",
4
4
  "description": "Shareable Cross-Origin Learning Resources",
5
5
  "main": "index.html",
6
6
  "types": "lib/index.d.ts",