@netless/window-manager 0.4.28 → 0.4.30-canary.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.
package/dist/index.d.ts CHANGED
@@ -144,7 +144,12 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
144
144
  nextPage(): Promise<boolean>;
145
145
  prevPage(): Promise<boolean>;
146
146
  addPage(params?: AddPageParams): Promise<void>;
147
- removePage(index: number): Promise<boolean>;
147
+ /**
148
+ * 删除一页
149
+ * 默认删除当前页, 可以删除指定 index 页
150
+ * 最低保留一页
151
+ */
152
+ removePage(index?: number): Promise<boolean>;
148
153
  /**
149
154
  * 返回 mainView 的 ScenePath
150
155
  */
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";
@@ -1021,12 +1022,16 @@ class AppContext {
1021
1022
  }
1022
1023
  };
1023
1024
  this.removePage = async (index) => {
1024
- if (index < 0 || index >= this.pageState.length) {
1025
+ const needRemoveIndex = index === void 0 ? this.pageState.index : index;
1026
+ if (this.pageState.length === 1) {
1027
+ console.warn(`[WindowManager]: can not remove the last page`);
1028
+ return false;
1029
+ }
1030
+ if (needRemoveIndex < 0 || needRemoveIndex >= this.pageState.length) {
1025
1031
  console.warn(`[WindowManager]: page index ${index} out of range`);
1026
1032
  return false;
1027
1033
  }
1028
- this.appProxy.removeSceneByIndex(index);
1029
- return true;
1034
+ return this.appProxy.removeSceneByIndex(needRemoveIndex);
1030
1035
  };
1031
1036
  this.emitter = appProxy.appEmitter;
1032
1037
  this.isAddApp = appProxy.isAddApp;
@@ -1502,6 +1507,11 @@ class AppProxy {
1502
1507
  }
1503
1508
  async onReconnected() {
1504
1509
  var _a;
1510
+ const isExist = Boolean(this.manager.attributes.apps[this.id]);
1511
+ if (!isExist) {
1512
+ await this.destroy(true, false, true);
1513
+ return;
1514
+ }
1505
1515
  this.appEmitter.emit("reconnected", void 0);
1506
1516
  const currentAppState = this.getAppInitState(this.id);
1507
1517
  await this.destroy(true, false, true);
@@ -1603,9 +1613,6 @@ class AppProxy {
1603
1613
  async removeSceneByIndex(index) {
1604
1614
  const scenePath = this._pageState.getFullPath(index);
1605
1615
  if (scenePath) {
1606
- if (this.pageState.length <= 1) {
1607
- return false;
1608
- }
1609
1616
  const nextIndex = calculateNextIndex(index, this.pageState);
1610
1617
  this.setSceneIndexWithoutSync(nextIndex);
1611
1618
  this.manager.dispatchInternalEvent(Events.SetAppFocusIndex, {
@@ -2063,7 +2070,10 @@ class AppManager {
2063
2070
  }
2064
2071
  this.callbacksNode = this.displayer.createScenesCallback(ROOT_DIR, {
2065
2072
  onAddScene: this.onSceneChange,
2066
- onRemoveScene: this.onSceneChange
2073
+ onRemoveScene: async (node, name) => {
2074
+ await this.onSceneChange(node);
2075
+ emitter.emit("rootDirSceneRemoved", name);
2076
+ }
2067
2077
  });
2068
2078
  if (this.callbacksNode) {
2069
2079
  this.updateSceneState(this.callbacksNode);
@@ -2074,17 +2084,26 @@ class AppManager {
2074
2084
  }
2075
2085
  };
2076
2086
  this.removeSceneByIndex = async (index) => {
2087
+ var _a;
2077
2088
  const nextIndex = calculateNextIndex(index, this.windowManger.pageState);
2078
2089
  this.setSceneIndexWithoutSync(nextIndex);
2079
2090
  this.dispatchInternalEvent(Events.SetAppFocusIndex, { type: "main", index: nextIndex });
2091
+ const scene = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[index];
2080
2092
  setTimeout(() => {
2081
- var _a;
2082
- const scene = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[index];
2083
2093
  if (scene) {
2084
2094
  removeScenes(this.room, `${ROOT_DIR}${scene}`, index);
2085
2095
  }
2086
2096
  }, 100);
2087
- return true;
2097
+ return new Promise((resolve, reject) => {
2098
+ emitter.once("rootDirSceneRemoved").then((name) => {
2099
+ if (name === scene) {
2100
+ resolve(true);
2101
+ }
2102
+ }).catch((e2) => {
2103
+ console.log(`[WindowManager]: removePage error: ${e2}`);
2104
+ reject(false);
2105
+ });
2106
+ });
2088
2107
  };
2089
2108
  this.setSceneIndexWithoutSync = (index) => {
2090
2109
  var _a;
@@ -2096,11 +2115,13 @@ class AppManager {
2096
2115
  this.onSceneChange = (node) => {
2097
2116
  this.mainViewScenesLength = node.scenes.length;
2098
2117
  this.updateSceneState(node);
2099
- this.emitMainViewScenesChange(this.mainViewScenesLength);
2118
+ return this.emitMainViewScenesChange(this.mainViewScenesLength);
2100
2119
  };
2101
2120
  this.emitMainViewScenesChange = (length) => {
2102
- callbacks$1.emit("mainViewScenesLengthChange", length);
2103
- emitter.emit("changePageState");
2121
+ return Promise.all([
2122
+ callbacks$1.emit("mainViewScenesLengthChange", length),
2123
+ emitter.emit("changePageState")
2124
+ ]);
2104
2125
  };
2105
2126
  this.updateSceneState = (node) => {
2106
2127
  const currentIndex = this.store.getMainViewSceneIndex() || 0;
@@ -5733,11 +5754,12 @@ class ReconnectRefresher {
5733
5754
  this.reactors = /* @__PURE__ */ new Map();
5734
5755
  this.disposers = /* @__PURE__ */ new Map();
5735
5756
  this.onPhaseChanged = (phase) => {
5757
+ var _a;
5736
5758
  if (phase === RoomPhase.Reconnecting) {
5737
5759
  this.ctx.emitter.emit("startReconnect");
5738
5760
  }
5739
5761
  if (phase === RoomPhase.Connected && this.phase === RoomPhase.Reconnecting) {
5740
- this.onReconnected();
5762
+ (_a = this.room) == null ? void 0 : _a.dispatchMagixEvent(EnsureReconnectEvent, {});
5741
5763
  }
5742
5764
  this.phase = phase;
5743
5765
  };
@@ -5758,8 +5780,15 @@ class ReconnectRefresher {
5758
5780
  setRoom(room) {
5759
5781
  this.room = room;
5760
5782
  this.phase = room == null ? void 0 : room.phase;
5761
- room == null ? void 0 : room.callbacks.off("onPhaseChanged", this.onPhaseChanged);
5762
- room == null ? void 0 : room.callbacks.on("onPhaseChanged", this.onPhaseChanged);
5783
+ if (room) {
5784
+ room.callbacks.off("onPhaseChanged", this.onPhaseChanged);
5785
+ room.callbacks.on("onPhaseChanged", this.onPhaseChanged);
5786
+ room.addMagixEventListener(EnsureReconnectEvent, (payload) => {
5787
+ if (payload.authorId === room.observerId) {
5788
+ this.onReconnected();
5789
+ }
5790
+ }, { fireSelfEventAfterCommit: true });
5791
+ }
5763
5792
  }
5764
5793
  setContext(ctx) {
5765
5794
  this.ctx = ctx;
@@ -5801,8 +5830,9 @@ class ReconnectRefresher {
5801
5830
  return this.reactors.has(id2);
5802
5831
  }
5803
5832
  destroy() {
5804
- var _a;
5833
+ var _a, _b;
5805
5834
  (_a = this.room) == null ? void 0 : _a.callbacks.off("onPhaseChanged", this.onPhaseChanged);
5835
+ (_b = this.room) == null ? void 0 : _b.removeMagixEventListener(EnsureReconnectEvent, this.onReconnected);
5806
5836
  this.releaseDisposers();
5807
5837
  }
5808
5838
  }
@@ -15047,7 +15077,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
15047
15077
  const _WindowManager = class extends InvisiblePlugin {
15048
15078
  constructor(context) {
15049
15079
  super(context);
15050
- this.version = "0.4.28";
15080
+ this.version = "0.4.30-canary.1";
15051
15081
  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" } };
15052
15082
  this.emitter = callbacks$1;
15053
15083
  this.viewMode = ViewMode.Broadcaster;
@@ -15349,15 +15379,16 @@ const _WindowManager = class extends InvisiblePlugin {
15349
15379
  }
15350
15380
  async removePage(index) {
15351
15381
  if (this.appManager) {
15382
+ const needRemoveIndex = index === void 0 ? this.pageState.index : index;
15352
15383
  if (this.pageState.length === 1) {
15353
15384
  console.warn(`[WindowManager]: can not remove the last page`);
15354
15385
  return false;
15355
15386
  }
15356
- if (index < 0 || index >= this.pageState.length) {
15387
+ if (needRemoveIndex < 0 || needRemoveIndex >= this.pageState.length) {
15357
15388
  console.warn(`[WindowManager]: index ${index} out of range`);
15358
15389
  return false;
15359
15390
  }
15360
- return this.appManager.removeSceneByIndex(index);
15391
+ return this.appManager.removeSceneByIndex(needRemoveIndex);
15361
15392
  } else {
15362
15393
  return false;
15363
15394
  }