@netless/window-manager 1.0.13-test.11 → 1.0.13-test.13

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.mjs CHANGED
@@ -7791,6 +7791,7 @@ class MainViewProxy {
7791
7791
  this.polling = false;
7792
7792
  this.started = false;
7793
7793
  this.mainViewIsAddListener = false;
7794
+ this.isForcingMainViewDivElement = false;
7794
7795
  this.store = this.manager.store;
7795
7796
  this.viewMode = this.manager.windowManger.viewMode;
7796
7797
  this.sideEffectManager = new o$2();
@@ -7857,15 +7858,52 @@ class MainViewProxy {
7857
7858
  this.setMainViewSize = debounce((size2) => {
7858
7859
  this.store.setMainViewSize({ ...size2, id: this.manager.uid });
7859
7860
  }, 50);
7861
+ this.onResize = (entries) => {
7862
+ const entry = entries[0];
7863
+ if (!entry)
7864
+ return;
7865
+ const target = entry.target;
7866
+ const child = target.children[0];
7867
+ const observedSize = {
7868
+ width: entry.contentRect.width,
7869
+ height: entry.contentRect.height
7870
+ };
7871
+ console.log("[window-manager] mainViewResizeObserver " + JSON.stringify({
7872
+ sameTarget: target === this.mainView.divElement,
7873
+ contentRect: {
7874
+ width: observedSize.width,
7875
+ height: observedSize.height
7876
+ },
7877
+ client: {
7878
+ width: target.clientWidth,
7879
+ height: target.clientHeight
7880
+ },
7881
+ offset: {
7882
+ width: target.offsetWidth,
7883
+ height: target.offsetHeight
7884
+ },
7885
+ rect: {
7886
+ width: target.getBoundingClientRect().width,
7887
+ height: target.getBoundingClientRect().height
7888
+ },
7889
+ childRect: child ? {
7890
+ width: child.getBoundingClientRect().width,
7891
+ height: child.getBoundingClientRect().height
7892
+ } : null,
7893
+ viewSize: this.mainView.size
7894
+ }));
7895
+ this.forceSyncMainViewDivElement("mainViewResizeObserver", observedSize, target);
7896
+ };
7860
7897
  this._syncMainViewTimer = 0;
7861
- this.onCameraOrSizeUpdated = () => {
7862
- console.log("[window-manager] onCameraOrSizeUpdated " + JSON.stringify(this.cameraState));
7898
+ this.handleCameraOrSizeUpdated = (source, payload) => {
7899
+ console.log("[window-manager] " + source + " payload " + JSON.stringify(payload));
7900
+ console.log("[window-manager] " + source + " state " + JSON.stringify(this.cameraState));
7863
7901
  if (this.mainView.divElement) {
7864
7902
  const children2 = this.mainView.divElement.children;
7865
- console.log("[window-manager] onCameraOrSizeUpdated " + this.mainView.divElement.getBoundingClientRect());
7903
+ console.log("[window-manager] " + source + " rect " + JSON.stringify(this.mainView.divElement.getBoundingClientRect()));
7866
7904
  const child = children2[0];
7867
7905
  if (child) {
7868
- console.log("[window-manager] child" + JSON.stringify(child.getBoundingClientRect()));
7906
+ console.log("[window-manager] " + source + " child" + JSON.stringify(child.getBoundingClientRect()));
7869
7907
  }
7870
7908
  }
7871
7909
  callbacks$1.emit("cameraStateChange", this.cameraState);
@@ -7875,6 +7913,12 @@ class MainViewProxy {
7875
7913
  }
7876
7914
  this.ensureMainViewSize();
7877
7915
  };
7916
+ this.onCameraUpdated = (camera) => {
7917
+ this.handleCameraOrSizeUpdated("onCameraUpdated", camera);
7918
+ };
7919
+ this.onSizeUpdated = (size2) => {
7920
+ this.handleCameraOrSizeUpdated("onSizeUpdated", size2);
7921
+ };
7878
7922
  this.syncMainView = (room) => {
7879
7923
  if (room.isWritable) {
7880
7924
  console.log("[window-manager] syncMainView ");
@@ -7887,6 +7931,7 @@ class MainViewProxy {
7887
7931
  this.mainView = this.createMainView();
7888
7932
  this.moveCameraSizeByAttributes();
7889
7933
  internalEmitter.once("mainViewMounted").then(() => {
7934
+ this.observeMainViewDivElement();
7890
7935
  this.addMainViewListener();
7891
7936
  this.start();
7892
7937
  this.ensureCameraAndSize();
@@ -7894,7 +7939,6 @@ class MainViewProxy {
7894
7939
  });
7895
7940
  const playgroundSizeChangeListener = () => {
7896
7941
  var _a, _b, _c, _d, _e, _f, _g, _h;
7897
- this.refreshScreenSizeIfStale();
7898
7942
  this.playgroundSizeChangeListenerLocalConsole.log(
7899
7943
  JSON.stringify(this.mainView.camera),
7900
7944
  JSON.stringify(this.mainView.size),
@@ -7946,22 +7990,46 @@ class MainViewProxy {
7946
7990
  this.moveCamera(this.mainViewCamera);
7947
7991
  }
7948
7992
  refreshScreenSizeIfStale() {
7949
- var _a;
7950
7993
  const element2 = this.mainView.divElement;
7951
7994
  if (!element2)
7952
7995
  return;
7953
7996
  const { width, height } = element2.getBoundingClientRect();
7954
7997
  if (width <= 0 || height <= 0)
7955
7998
  return;
7999
+ this.forceSyncMainViewDivElement("playgroundSizeChange", { width, height }, element2);
8000
+ }
8001
+ forceSyncMainViewDivElement(reason, observedSize, element2) {
7956
8002
  const { width: viewWidth, height: viewHeight } = this.mainView.size;
7957
- if (Math.abs(viewWidth - width) > 0.5 || Math.abs(viewHeight - height) > 0.5) {
7958
- const resizableView = this.mainView;
7959
- console.log("[window-manager] forceResizeScreen stale size" + JSON.stringify({
7960
- viewSize: this.mainView.size,
7961
- domSize: { width, height }
8003
+ if (Math.abs(viewWidth - observedSize.width) <= 0.5 && Math.abs(viewHeight - observedSize.height) <= 0.5) {
8004
+ return;
8005
+ }
8006
+ if (this.isForcingMainViewDivElement) {
8007
+ console.log("[window-manager] skipForceSyncMainViewDivElement " + JSON.stringify({
8008
+ reason,
8009
+ observedSize,
8010
+ viewSize: this.mainView.size
7962
8011
  }));
7963
- (_a = resizableView.resizeScreen) == null ? void 0 : _a.call(resizableView);
8012
+ return;
7964
8013
  }
8014
+ this.isForcingMainViewDivElement = true;
8015
+ console.log("[window-manager] forceSyncMainViewDivElement " + JSON.stringify({
8016
+ reason,
8017
+ observedSize,
8018
+ viewSize: this.mainView.size,
8019
+ mainViewSize: this.mainViewSize,
8020
+ mainViewCamera: this.mainViewCamera
8021
+ }));
8022
+ this.mainView.divElement = null;
8023
+ this.mainView.divElement = element2;
8024
+ queueMicrotask(() => {
8025
+ const rect = element2.getBoundingClientRect();
8026
+ console.log("[window-manager] forceSyncMainViewDivElementResult " + JSON.stringify({
8027
+ reason,
8028
+ viewSize: this.mainView.size,
8029
+ rect: { width: rect.width, height: rect.height }
8030
+ }));
8031
+ this.isForcingMainViewDivElement = false;
8032
+ });
7965
8033
  }
7966
8034
  start() {
7967
8035
  console.log("[window-manager] start " + JSON.stringify(this.mainViewSize));
@@ -7973,6 +8041,7 @@ class MainViewProxy {
7973
8041
  if (this.manager.room)
7974
8042
  this.syncMainView(this.manager.room);
7975
8043
  this.started = true;
8044
+ console.log("[window-manager] start end " + JSON.stringify(this.mainViewSize), JSON.stringify(this.mainView.size));
7976
8045
  }
7977
8046
  setCameraAndSize() {
7978
8047
  const camera = { ...this.mainView.camera, id: this.manager.uid };
@@ -8014,9 +8083,11 @@ class MainViewProxy {
8014
8083
  this.mainView.release();
8015
8084
  }
8016
8085
  this.removeMainViewListener();
8086
+ this.disconnectMainViewResizeObserver();
8017
8087
  this.mainView = this.createMainView();
8018
8088
  this.mainView.disableCameraTransform = disableCameraTransform;
8019
8089
  this.mainView.divElement = divElement;
8090
+ this.observeMainViewDivElement();
8020
8091
  this.addMainViewListener();
8021
8092
  this.start();
8022
8093
  callbacks$1.emit("onMainViewRebind", this.mainView);
@@ -8046,13 +8117,31 @@ class MainViewProxy {
8046
8117
  }
8047
8118
  addCameraListener() {
8048
8119
  this.view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
8049
- this.view.callbacks.on("onCameraUpdated", this.onCameraOrSizeUpdated);
8050
- this.view.callbacks.on("onSizeUpdated", this.onCameraOrSizeUpdated);
8120
+ this.view.callbacks.on("onCameraUpdated", this.onCameraUpdated);
8121
+ this.view.callbacks.on("onSizeUpdated", this.onSizeUpdated);
8051
8122
  }
8052
8123
  removeCameraListener() {
8053
8124
  this.view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
8054
- this.view.callbacks.off("onCameraUpdated", this.onCameraOrSizeUpdated);
8055
- this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
8125
+ this.view.callbacks.off("onCameraUpdated", this.onCameraUpdated);
8126
+ this.view.callbacks.off("onSizeUpdated", this.onSizeUpdated);
8127
+ }
8128
+ observeMainViewDivElement() {
8129
+ this.disconnectMainViewResizeObserver();
8130
+ if (!("ResizeObserver" in window))
8131
+ return;
8132
+ if (!this.mainView.divElement)
8133
+ return;
8134
+ console.log("[window-manager] observeMainViewDivElement " + JSON.stringify({
8135
+ rect: this.mainView.divElement.getBoundingClientRect(),
8136
+ viewSize: this.mainView.size
8137
+ }));
8138
+ this.mainViewResizeObserver = new window.ResizeObserver(this.onResize);
8139
+ this.mainViewResizeObserver.observe(this.mainView.divElement);
8140
+ }
8141
+ disconnectMainViewResizeObserver() {
8142
+ var _a;
8143
+ (_a = this.mainViewResizeObserver) == null ? void 0 : _a.disconnect();
8144
+ this.mainViewResizeObserver = void 0;
8056
8145
  }
8057
8146
  ensureMainViewSize() {
8058
8147
  if ((!this.mainViewSize || this.mainViewSize.width === 0 || this.mainViewSize.height === 0) && this.mainView.size.width > 0 && this.mainView.size.height > 0) {
@@ -8092,7 +8181,9 @@ class MainViewProxy {
8092
8181
  this.started = false;
8093
8182
  }
8094
8183
  destroy() {
8184
+ console.log("[window-manager] destroy ");
8095
8185
  this.removeMainViewListener();
8186
+ this.disconnectMainViewResizeObserver();
8096
8187
  this.stop();
8097
8188
  this.sideEffectManager.flushAll();
8098
8189
  }
@@ -19801,7 +19892,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter: internalEmitter });
19801
19892
  const _WindowManager = class extends InvisiblePlugin {
19802
19893
  constructor(context) {
19803
19894
  super(context);
19804
- this.version = "1.0.13-test.11";
19895
+ this.version = "1.0.13-test.13";
19805
19896
  this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.3.0", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.53" }, "devDependencies": { "@hyrious/dts": "^0.2.2", "@netless/app-docs-viewer": "^0.2.19", "@netless/app-media-player": "0.1.4", "@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.30", "@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", "jspdf": "^2.5.1", "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", "side-effect-manager": "0.1.5", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.9.9", "vitest": "^0.14.1", "white-web-sdk": "^2.16.53" } };
19806
19897
  this.emitter = callbacks$1;
19807
19898
  this.viewMode = ViewMode.Broadcaster;