@netless/window-manager 0.4.30-canary.0 → 0.4.31

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
@@ -47,6 +47,7 @@ var Events = /* @__PURE__ */ ((Events2) => {
47
47
  return Events2;
48
48
  })(Events || {});
49
49
  const MagixEventName = "__WindowManger";
50
+ const EnsureReconnectEvent = "__WindowMangerEnsureReconnected__";
50
51
  var AppAttributes = /* @__PURE__ */ ((AppAttributes2) => {
51
52
  AppAttributes2["Size"] = "size";
52
53
  AppAttributes2["Position"] = "position";
@@ -1270,6 +1271,7 @@ const calculateNextIndex = (index, pageState) => {
1270
1271
  }
1271
1272
  return nextIndex;
1272
1273
  };
1274
+ const boxEmitter = new Emittery();
1273
1275
  class AppProxy {
1274
1276
  constructor(params, manager, appId, isAddApp) {
1275
1277
  var _a;
@@ -1506,6 +1508,11 @@ class AppProxy {
1506
1508
  }
1507
1509
  async onReconnected() {
1508
1510
  var _a;
1511
+ const isExist = Boolean(this.manager.attributes.apps[this.id]);
1512
+ if (!isExist) {
1513
+ await this.destroy(true, false, true);
1514
+ return;
1515
+ }
1509
1516
  this.appEmitter.emit("reconnected", void 0);
1510
1517
  const currentAppState = this.getAppInitState(this.id);
1511
1518
  await this.destroy(true, false, true);
@@ -1575,7 +1582,7 @@ class AppProxy {
1575
1582
  }
1576
1583
  case "focus": {
1577
1584
  (_d = this.boxManager) == null ? void 0 : _d.focusBox({ appId: this.id });
1578
- emitter.emit("focus", { appId: this.id });
1585
+ boxEmitter.emit("focus", { appId: this.id });
1579
1586
  break;
1580
1587
  }
1581
1588
  }
@@ -2136,6 +2143,34 @@ class AppManager {
2136
2143
  };
2137
2144
  callbacks$1.emit("sceneStateChange", this.sceneState);
2138
2145
  };
2146
+ this.onBoxMove = (payload) => {
2147
+ this.dispatchInternalEvent(Events.AppMove, payload);
2148
+ this.store.updateAppState(payload.appId, AppAttributes.Position, {
2149
+ x: payload.x,
2150
+ y: payload.y
2151
+ });
2152
+ };
2153
+ this.onBoxResize = (payload) => {
2154
+ if (payload.width && payload.height) {
2155
+ this.dispatchInternalEvent(Events.AppResize, payload);
2156
+ this.store.updateAppState(payload.appId, AppAttributes.Size, {
2157
+ width: payload.width,
2158
+ height: payload.height
2159
+ });
2160
+ }
2161
+ };
2162
+ this.onBoxFocus = (payload) => {
2163
+ this.windowManger.safeSetAttributes({ focus: payload.appId });
2164
+ };
2165
+ this.onBoxClose = (payload) => {
2166
+ const appProxy = this.appProxies.get(payload.appId);
2167
+ if (appProxy) {
2168
+ appProxy.destroy(false, true, true, payload.error);
2169
+ }
2170
+ };
2171
+ this.onBoxStateChange = (payload) => {
2172
+ this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
2173
+ };
2139
2174
  this.addAppsChangeListener = () => {
2140
2175
  var _a;
2141
2176
  (_a = this.refresher) == null ? void 0 : _a.add("apps", () => {
@@ -2268,43 +2303,6 @@ class AppManager {
2268
2303
  }
2269
2304
  }
2270
2305
  };
2271
- this.boxEventListener = (eventName, payload) => {
2272
- switch (eventName) {
2273
- case "move": {
2274
- this.dispatchInternalEvent(Events.AppMove, payload);
2275
- this.store.updateAppState(payload.appId, AppAttributes.Position, {
2276
- x: payload.x,
2277
- y: payload.y
2278
- });
2279
- break;
2280
- }
2281
- case "focus": {
2282
- this.windowManger.safeSetAttributes({ focus: payload.appId });
2283
- break;
2284
- }
2285
- case "resize": {
2286
- if (payload.width && payload.height) {
2287
- this.dispatchInternalEvent(Events.AppResize, payload);
2288
- this.store.updateAppState(payload.appId, AppAttributes.Size, {
2289
- width: payload.width,
2290
- height: payload.height
2291
- });
2292
- }
2293
- break;
2294
- }
2295
- case "close": {
2296
- const appProxy = this.appProxies.get(payload.appId);
2297
- if (appProxy) {
2298
- appProxy.destroy(false, true, payload.error);
2299
- }
2300
- break;
2301
- }
2302
- case "boxStateChange": {
2303
- this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
2304
- break;
2305
- }
2306
- }
2307
- };
2308
2306
  this.updateRootDirRemoving = (removing) => {
2309
2307
  this.rootDirRemoving = removing;
2310
2308
  };
@@ -2394,7 +2392,11 @@ class AppManager {
2394
2392
  var _a, _b, _c, _d, _e2, _f;
2395
2393
  await this.attributesUpdateCallback(this.attributes.apps);
2396
2394
  emitter.emit("updateManagerRect");
2397
- emitter.onAny(this.boxEventListener);
2395
+ boxEmitter.on("move", this.onBoxMove);
2396
+ boxEmitter.on("resize", this.onBoxResize);
2397
+ boxEmitter.on("focus", this.onBoxFocus);
2398
+ boxEmitter.on("close", this.onBoxClose);
2399
+ boxEmitter.on("boxStateChange", this.onBoxStateChange);
2398
2400
  this.addAppsChangeListener();
2399
2401
  this.addAppCloseListener();
2400
2402
  (_a = this.refresher) == null ? void 0 : _a.add("maximized", () => {
@@ -2543,7 +2545,7 @@ class AppManager {
2543
2545
  var _a, _b;
2544
2546
  if (appProxy && appProxy.box) {
2545
2547
  const box = appProxy.box;
2546
- emitter.emit("move", {
2548
+ boxEmitter.emit("move", {
2547
2549
  appId: appProxy.id,
2548
2550
  x: box == null ? void 0 : box.intrinsicX,
2549
2551
  y: box == null ? void 0 : box.intrinsicY
@@ -2676,7 +2678,7 @@ class AppManager {
2676
2678
  this.displayer.callbacks.off(this.eventName, this.displayerStateListener);
2677
2679
  this.displayer.callbacks.off("onEnableWriteNowChanged", this.displayerWritableListener);
2678
2680
  this.appListeners.removeListeners();
2679
- emitter.offAny(this.boxEventListener);
2681
+ boxEmitter.clearListeners();
2680
2682
  emitter.clearListeners();
2681
2683
  if (this.appProxies.size) {
2682
2684
  this.appProxies.forEach((appProxy) => {
@@ -4529,7 +4531,7 @@ class Bt {
4529
4531
  return typeof e2 == "string" ? this.boxes.find((t2) => t2.id === e2) : e2;
4530
4532
  }
4531
4533
  }
4532
- const createBoxManager = (manager, callbacks2, emitter2, options) => {
4534
+ const createBoxManager = (manager, callbacks2, emitter2, boxEmitter2, options) => {
4533
4535
  return new BoxManager({
4534
4536
  safeSetAttributes: (attributes) => manager.safeSetAttributes(attributes),
4535
4537
  getMainView: () => manager.mainView,
@@ -4551,14 +4553,15 @@ const createBoxManager = (manager, callbacks2, emitter2, options) => {
4551
4553
  return (_a = manager.appManager) == null ? void 0 : _a.store.setAppFocus(appId, true);
4552
4554
  },
4553
4555
  callbacks: callbacks2,
4554
- emitter: emitter2
4556
+ emitter: emitter2,
4557
+ boxEmitter: boxEmitter2
4555
4558
  }, options);
4556
4559
  };
4557
4560
  class BoxManager {
4558
4561
  constructor(context, createTeleBoxManagerConfig) {
4559
4562
  this.context = context;
4560
4563
  this.createTeleBoxManagerConfig = createTeleBoxManagerConfig;
4561
- const { emitter: emitter2, callbacks: callbacks2 } = context;
4564
+ const { emitter: emitter2, callbacks: callbacks2, boxEmitter: boxEmitter2 } = context;
4562
4565
  this.teleBoxManager = this.setupBoxManager(createTeleBoxManagerConfig);
4563
4566
  this.teleBoxManager._state$.reaction((state) => {
4564
4567
  callbacks2.emit("boxStateChange", state);
@@ -4588,14 +4591,14 @@ class BoxManager {
4588
4591
  });
4589
4592
  this.teleBoxManager.events.on("removed", (boxes) => {
4590
4593
  boxes.forEach((box) => {
4591
- emitter2.emit("close", { appId: box.id });
4594
+ boxEmitter2.emit("close", { appId: box.id });
4592
4595
  });
4593
4596
  });
4594
4597
  this.teleBoxManager.events.on("intrinsic_move", debounce((box) => {
4595
- emitter2.emit("move", { appId: box.id, x: box.intrinsicX, y: box.intrinsicY });
4598
+ boxEmitter2.emit("move", { appId: box.id, x: box.intrinsicX, y: box.intrinsicY });
4596
4599
  }, 50));
4597
4600
  this.teleBoxManager.events.on("intrinsic_resize", debounce((box) => {
4598
- emitter2.emit("resize", {
4601
+ boxEmitter2.emit("resize", {
4599
4602
  appId: box.id,
4600
4603
  width: box.intrinsicWidth,
4601
4604
  height: box.intrinsicHeight
@@ -4604,7 +4607,7 @@ class BoxManager {
4604
4607
  this.teleBoxManager.events.on("focused", (box) => {
4605
4608
  if (box) {
4606
4609
  if (this.canOperate) {
4607
- emitter2.emit("focus", { appId: box.id });
4610
+ boxEmitter2.emit("focus", { appId: box.id });
4608
4611
  } else {
4609
4612
  this.teleBoxManager.blurBox(box.id);
4610
4613
  }
@@ -4669,7 +4672,7 @@ class BoxManager {
4669
4672
  const box = this.teleBoxManager.queryOne({ id: appId });
4670
4673
  if (box) {
4671
4674
  if (box.state === Ke$1.Maximized) {
4672
- this.context.emitter.emit("resize", {
4675
+ this.context.boxEmitter.emit("resize", {
4673
4676
  appId,
4674
4677
  x: box.x,
4675
4678
  y: box.y,
@@ -5748,11 +5751,12 @@ class ReconnectRefresher {
5748
5751
  this.reactors = /* @__PURE__ */ new Map();
5749
5752
  this.disposers = /* @__PURE__ */ new Map();
5750
5753
  this.onPhaseChanged = (phase) => {
5754
+ var _a;
5751
5755
  if (phase === RoomPhase.Reconnecting) {
5752
5756
  this.ctx.emitter.emit("startReconnect");
5753
5757
  }
5754
5758
  if (phase === RoomPhase.Connected && this.phase === RoomPhase.Reconnecting) {
5755
- this.onReconnected();
5759
+ (_a = this.room) == null ? void 0 : _a.dispatchMagixEvent(EnsureReconnectEvent, {});
5756
5760
  }
5757
5761
  this.phase = phase;
5758
5762
  };
@@ -5773,8 +5777,15 @@ class ReconnectRefresher {
5773
5777
  setRoom(room) {
5774
5778
  this.room = room;
5775
5779
  this.phase = room == null ? void 0 : room.phase;
5776
- room == null ? void 0 : room.callbacks.off("onPhaseChanged", this.onPhaseChanged);
5777
- room == null ? void 0 : room.callbacks.on("onPhaseChanged", this.onPhaseChanged);
5780
+ if (room) {
5781
+ room.callbacks.off("onPhaseChanged", this.onPhaseChanged);
5782
+ room.callbacks.on("onPhaseChanged", this.onPhaseChanged);
5783
+ room.addMagixEventListener(EnsureReconnectEvent, (payload) => {
5784
+ if (payload.authorId === room.observerId) {
5785
+ this.onReconnected();
5786
+ }
5787
+ }, { fireSelfEventAfterCommit: true });
5788
+ }
5778
5789
  }
5779
5790
  setContext(ctx) {
5780
5791
  this.ctx = ctx;
@@ -5816,8 +5827,9 @@ class ReconnectRefresher {
5816
5827
  return this.reactors.has(id2);
5817
5828
  }
5818
5829
  destroy() {
5819
- var _a;
5830
+ var _a, _b;
5820
5831
  (_a = this.room) == null ? void 0 : _a.callbacks.off("onPhaseChanged", this.onPhaseChanged);
5832
+ (_b = this.room) == null ? void 0 : _b.removeMagixEventListener(EnsureReconnectEvent, this.onReconnected);
5821
5833
  this.releaseDisposers();
5822
5834
  }
5823
5835
  }
@@ -15062,14 +15074,14 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
15062
15074
  const _WindowManager = class extends InvisiblePlugin {
15063
15075
  constructor(context) {
15064
15076
  super(context);
15065
- this.version = "0.4.30-canary.0";
15066
- 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", "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.12.4", "white-web-sdk": "2.16.10" } };
15077
+ this.version = "0.4.31";
15078
+ 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" } };
15067
15079
  this.emitter = callbacks$1;
15068
15080
  this.viewMode = ViewMode.Broadcaster;
15069
15081
  this.isReplay = isPlayer(this.displayer);
15070
15082
  this.containerSizeRatio = _WindowManager.containerSizeRatio;
15071
15083
  _WindowManager.displayer = context.displayer;
15072
- window.NETLESS_DEPS = { "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", "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.12.4", "white-web-sdk": "2.16.10" } };
15084
+ window.NETLESS_DEPS = { "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" } };
15073
15085
  }
15074
15086
  static async mount(params) {
15075
15087
  const room = params.room;
@@ -15179,7 +15191,7 @@ const _WindowManager = class extends InvisiblePlugin {
15179
15191
  }
15180
15192
  bindContainer(container) {
15181
15193
  var _a, _b, _c, _d, _e2, _f;
15182
- if (this.room.phase !== RoomPhase.Connected) {
15194
+ if (isRoom(this.displayer) && this.room.phase !== RoomPhase.Connected) {
15183
15195
  throw new BindContainerRoomPhaseInvalidError();
15184
15196
  }
15185
15197
  if (_WindowManager.isCreated && _WindowManager.container) {
@@ -15193,7 +15205,7 @@ const _WindowManager = class extends InvisiblePlugin {
15193
15205
  if (this.boxManager) {
15194
15206
  this.boxManager.destroy();
15195
15207
  }
15196
- const boxManager = createBoxManager(this, callbacks$1, emitter, {
15208
+ const boxManager = createBoxManager(this, callbacks$1, emitter, boxEmitter, {
15197
15209
  collectorContainer: params.collectorContainer,
15198
15210
  collectorStyles: params.collectorStyles,
15199
15211
  prefersColorScheme: params.prefersColorScheme