@didask/scol-r 3.0.0-beta-1 → 3.0.0-beta.2

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,9 +1,5 @@
1
1
  export interface HTMLGeneratorProps {
2
2
  dataSource: string;
3
3
  libPath?: string;
4
- sentry?: {
5
- dsn: string;
6
- tags?: Record<string, string>;
7
- };
8
4
  }
9
5
  export declare function HTMLGenerator(props: HTMLGeneratorProps): string;
@@ -1,20 +1,8 @@
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
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.HTMLGenerator = void 0;
15
4
  function HTMLGenerator(props) {
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>";
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>";
19
7
  }
20
8
  exports.HTMLGenerator = HTMLGenerator;
@@ -5,6 +5,7 @@ export declare class SCORMAdapter {
5
5
  private _ignorableErrorCodes;
6
6
  constructor(errorCallback?: Function);
7
7
  get foundAPI(): boolean;
8
+ private _initialize;
8
9
  private _findAndSetAPI;
9
10
  private _findAPIInWindow;
10
11
  private _callAPIFunction;
@@ -20,6 +20,16 @@ var SCORMAdapter = /** @class */ (function () {
20
20
  enumerable: false,
21
21
  configurable: true
22
22
  });
23
+ SCORMAdapter.prototype._initialize = function () {
24
+ if (this._isSCORM2004) {
25
+ this.LMSSetValue("cmi.score.min", 0);
26
+ this.LMSSetValue("cmi.score.max", 100);
27
+ }
28
+ else {
29
+ this.LMSSetValue("cmi.core.score.min", 0);
30
+ this.LMSSetValue("cmi.core.score.max", 100);
31
+ }
32
+ };
23
33
  SCORMAdapter.prototype._findAndSetAPI = function () {
24
34
  var _this = this;
25
35
  if (typeof window === "undefined") {
@@ -116,6 +126,9 @@ var SCORMAdapter = /** @class */ (function () {
116
126
  (this._isSCORM2004
117
127
  ? lastErrorCode === 103 // 103 in 2004.* = already initialized
118
128
  : lastErrorCode === 101); // 101 in 1.2 = already initialized
129
+ if (success) {
130
+ this._initialize();
131
+ }
119
132
  return success || this._handleError(functionName);
120
133
  };
121
134
  SCORMAdapter.prototype.LMSTerminate = function () {
@@ -160,10 +173,13 @@ var SCORMAdapter = /** @class */ (function () {
160
173
  return this.LMSGetValue(CMIVariableName);
161
174
  };
162
175
  SCORMAdapter.prototype.setScore = function (score) {
163
- var CMIVariableName = this._isSCORM2004
164
- ? "cmi.score.raw"
165
- : "cmi.core.score.raw";
166
- this.LMSSetValue(CMIVariableName, score);
176
+ if (this._isSCORM2004) {
177
+ this.LMSSetValue("cmi.score.raw", score);
178
+ this.LMSSetValue("cmi.score.scaled", score / 100);
179
+ }
180
+ else {
181
+ this.LMSSetValue("cmi.core.score.raw", score);
182
+ }
167
183
  };
168
184
  SCORMAdapter.prototype.getScore = function () {
169
185
  var CMIVariableName = this._isSCORM2004
@@ -1,4 +1,5 @@
1
1
  function loadContent() {
2
+ var _this = this;
2
3
  var messages = {
3
4
  en: {
4
5
  pageTitle: "Your content is loading...",
@@ -48,11 +49,6 @@ function loadContent() {
48
49
  newMessage.innerHTML = localizeMessage(message);
49
50
  messagesContainer.length && messagesContainer[0].appendChild(newMessage);
50
51
  };
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
- };
56
52
  var displayRuntimeError = function () {
57
53
  var errorContainer = document.getElementById("runtime-error");
58
54
  if (!(arguments && arguments.length)) {
@@ -68,62 +64,66 @@ function loadContent() {
68
64
  thisError.innerHTML = localizeMessage(arguments[i]);
69
65
  errorContainer.appendChild(thisError);
70
66
  }
71
- captureSentryException(arguments);
72
67
  // Remove the messages after 6 seconds
73
68
  setTimeout(function () {
74
69
  errorContainer.innerHTML = "";
75
70
  }, 6000);
76
71
  };
77
- var ADAPTER = new SCORMAdapter(displayRuntimeError);
78
- if (!ADAPTER.foundAPI) {
79
- displayInitError("apiNotFound");
80
- return;
81
- }
82
- if (!ADAPTER.LMSInitialize()) {
83
- displayInitError("couldNotInitialize");
84
- return;
85
- }
86
- var lessonStatus = ADAPTER.getLessonStatus();
87
- if (lessonStatus === "not attempted") {
88
- ADAPTER.setLessonStatus("incomplete");
89
- }
90
- var sourceUrl = document.body.getAttribute("data-source");
91
- if (!sourceUrl) {
92
- displayInitError("sourceUrlMissing");
93
- return;
94
- }
95
- var sourceUrlParser = document.createElement("a");
96
- sourceUrlParser.href = sourceUrl;
97
- var learnerId = ADAPTER.getLearnerId();
98
- if (learnerId == null) {
99
- displayInitError("learnerIdMissing");
100
- return;
101
- }
102
- sourceUrlParser.search +=
103
- (sourceUrlParser.search.indexOf("?") === -1 ? "?" : "&") +
104
- "scorm&learner_id=" +
105
- learnerId +
106
- "&lms_origin=" +
107
- encodeURIComponent(location.origin) +
108
- "&data_from_lms=" +
109
- ADAPTER.getDataFromLMS();
72
+ // var ADAPTER = new SCORMAdapter(displayRuntimeError);
73
+ // if (!ADAPTER.foundAPI) {
74
+ // displayInitError("apiNotFound");
75
+ // return;
76
+ // }
77
+ // if (!ADAPTER.LMSInitialize()) {
78
+ // displayInitError("couldNotInitialize");
79
+ // return;
80
+ // }
81
+ // var lessonStatus = ADAPTER.getLessonStatus();
82
+ // if (lessonStatus === "not attempted") {
83
+ // ADAPTER.setLessonStatus("incomplete");
84
+ // }
85
+ // var sourceUrl = document.body.getAttribute("data-source");
86
+ // if (!sourceUrl) {
87
+ // displayInitError("sourceUrlMissing");
88
+ // return;
89
+ // }
90
+ // var learnerId = ADAPTER.getLearnerId();
91
+ // if (learnerId == null) {
92
+ // displayInitError("learnerIdMissing");
93
+ // return;
94
+ // }
95
+ var url = new URL(sourceUrl);
96
+ url.searchParams.append("scorm", true);
97
+ url.searchParams.append("learner_id", learnerId);
98
+ url.searchParams.append("lms_origin", encodeURIComponent(location.origin));
99
+ // url.searchParams.append("data_from_lms", ADAPTER.getDataFromLMS());
110
100
  var iframe = document.createElement("iframe");
111
- iframe.setAttribute("src", sourceUrlParser.href);
112
101
  iframe.setAttribute("frameborder", "0");
113
102
  iframe.setAttribute("height", "100%");
114
103
  iframe.setAttribute("width", "100%");
115
- document.body.insertBefore(iframe, document.getElementById("wrapper"));
104
+ var wrapper = document.getElementById("wrapper");
105
+ var xhr = new XMLHttpRequest();
106
+ xhr.open("GET", url.toString());
107
+ xhr.onreadystatechange = function () {
108
+ if (_this.readyState === _this.DONE && _this.status === 200) {
109
+ iframe.setAttribute("src", url.toString());
110
+ document.body.insertBefore(iframe, wrapper);
111
+ }
112
+ };
113
+ xhr.responseType = "blob";
114
+ xhr.setRequestHeader("Authorization", "Bearer " + token);
115
+ xhr.send();
116
116
  var sessionStart = new Date();
117
- var host = sourceUrlParser.host;
117
+ var host = url.host;
118
118
  // The `host` variable may or may not contain the port number depending on the browser.
119
119
  // We remove it if it wasnt' explicitly set.
120
120
  if (host.indexOf(":") > -1 &&
121
- sourceUrl.indexOf(host) !== sourceUrlParser.protocol.length + 2) {
121
+ sourceUrl.indexOf(host) !== url.protocol.length + 2) {
122
122
  host = host.slice(0, host.indexOf(":"));
123
123
  }
124
- var sourceOrigin = sourceUrlParser.protocol + "//" + host;
125
- new MessageReceiver(window, sourceOrigin, ADAPTER);
126
- window.addEventListener("beforeunload", function (e) {
127
- ADAPTER.LMSTerminate();
128
- });
124
+ var sourceOrigin = url.protocol + "//" + host;
125
+ // new MessageReceiver(window, sourceOrigin, ADAPTER);
126
+ // window.addEventListener("beforeunload", function (e) {
127
+ // ADAPTER.LMSTerminate();
128
+ // });
129
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@didask/scol-r",
3
- "version": "3.0.0-beta-1",
3
+ "version": "3.0.0-beta.2",
4
4
  "description": "Shareable Cross-Origin Learning Resources",
5
5
  "main": "index.html",
6
6
  "types": "lib/index.d.ts",
@@ -8,7 +8,8 @@
8
8
  "lib/"
9
9
  ],
10
10
  "scripts": {
11
- "build": "tsc"
11
+ "build": "tsc",
12
+ "clean": "rm -rf node_modules lib"
12
13
  },
13
14
  "repository": {
14
15
  "type": "git",