@netless/window-manager 0.4.38 → 0.4.39

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/dist/index.es.js CHANGED
@@ -223,30 +223,36 @@ const executeScript = (text2, appName) => {
223
223
  const loadApp = async (url, key, name) => {
224
224
  const appName = name || Prefix + key;
225
225
  callbacks$1.emit("loadApp", { kind: key, status: "start" });
226
+ let text2;
226
227
  try {
227
- const text2 = await getScript(url);
228
+ text2 = await getScript(url);
228
229
  if (!text2 || text2.length === 0) {
229
230
  callbacks$1.emit("loadApp", { kind: key, status: "failed", reason: "script is empty." });
230
- return;
231
+ throw new Error("[WindowManager]: script is empty.");
231
232
  }
232
- try {
233
+ } catch (error) {
234
+ callbacks$1.emit("loadApp", { kind: key, status: "failed", reason: error.message });
235
+ throw error;
236
+ }
237
+ return getResult(text2, appName, key);
238
+ };
239
+ const getResult = (text2, appName, key) => {
240
+ try {
241
+ const result = executeScript(text2, appName);
242
+ callbacks$1.emit("loadApp", { kind: key, status: "success" });
243
+ return result;
244
+ } catch (error) {
245
+ if (error.message.includes("Can only have one anonymous define call per script file")) {
246
+ const define = window.define;
247
+ if (typeof define == "function" && define.amd) {
248
+ delete define.amd;
249
+ }
233
250
  const result = executeScript(text2, appName);
234
251
  callbacks$1.emit("loadApp", { kind: key, status: "success" });
235
252
  return result;
236
- } catch (error) {
237
- if (error.message.includes("Can only have one anonymous define call per script file")) {
238
- const define = window.define;
239
- if (typeof define == "function" && define.amd) {
240
- delete define.amd;
241
- }
242
- const result = executeScript(text2, appName);
243
- callbacks$1.emit("loadApp", { kind: key, status: "success" });
244
- return result;
245
- }
246
- callbacks$1.emit("loadApp", { kind: key, status: "failed", reason: error.message });
247
253
  }
248
- } catch (error) {
249
254
  callbacks$1.emit("loadApp", { kind: key, status: "failed", reason: error.message });
255
+ throw error;
250
256
  }
251
257
  };
252
258
  async function fetchWithTimeout(resource, options) {
@@ -279,11 +285,18 @@ class AppRegister {
279
285
  async register(params) {
280
286
  this.appClassesCache.delete(params.kind);
281
287
  this.registered.set(params.kind, params);
282
- const srcOrAppOrFunction = params.src;
288
+ const paramSrc = params.src;
289
+ let srcOrAppOrFunction;
283
290
  let downloadApp;
284
- if (typeof srcOrAppOrFunction === "string") {
291
+ if (typeof paramSrc === "string") {
292
+ srcOrAppOrFunction = () => loadApp(paramSrc, params.kind, params.name);
293
+ if (this.syncRegisterApp) {
294
+ this.syncRegisterApp({ kind: params.kind, src: paramSrc, name: params.name });
295
+ }
296
+ }
297
+ if (typeof paramSrc === "function") {
285
298
  downloadApp = async () => {
286
- let appClass = await loadApp(srcOrAppOrFunction, params.kind, params.name);
299
+ let appClass = await srcOrAppOrFunction();
287
300
  if (appClass) {
288
301
  if (appClass.__esModule) {
289
302
  appClass = appClass.default;
@@ -293,13 +306,9 @@ class AppRegister {
293
306
  throw new Error(`[WindowManager]: load remote script failed, ${srcOrAppOrFunction}`);
294
307
  }
295
308
  };
296
- if (this.syncRegisterApp) {
297
- this.syncRegisterApp({ kind: params.kind, src: srcOrAppOrFunction, name: params.name });
298
- }
299
- } else if (typeof srcOrAppOrFunction === "function") {
300
- downloadApp = srcOrAppOrFunction;
301
- } else {
302
- downloadApp = async () => srcOrAppOrFunction;
309
+ }
310
+ if (typeof paramSrc === "object") {
311
+ downloadApp = async () => paramSrc;
303
312
  }
304
313
  this.appClasses.set(params.kind, async () => {
305
314
  let app = this.appClassesCache.get(params.kind);
@@ -15103,7 +15112,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
15103
15112
  const _WindowManager = class extends InvisiblePlugin {
15104
15113
  constructor(context) {
15105
15114
  super(context);
15106
- this.version = "0.4.38";
15115
+ this.version = "0.4.39";
15107
15116
  this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.2.26", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^0.1.5", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
15108
15117
  this.emitter = callbacks$1;
15109
15118
  this.viewMode = ViewMode.Broadcaster;