@netless/window-manager 1.0.13-test.2 → 1.0.13-test.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "1.0.13-test.2",
3
+ "version": "1.0.13-test.3",
4
4
  "description": "Multi-window mode for Netless Whiteboard",
5
5
  "author": "l1shen <lishen1635@gmail.com> (https://github.com/l1shen)",
6
6
  "license": "MIT",
@@ -47,18 +47,10 @@ export class AppListeners {
47
47
  break;
48
48
  }
49
49
  case Events.SetMainViewScenePath: {
50
- console.log("[window-manager] mainMagixEventListener====>", JSON.stringify(data.payload));
50
+ console.log("[window-manager] mainMagixEventListener ", JSON.stringify(data.payload));
51
51
  this.setMainViewScenePathHandler(data.payload);
52
52
  break;
53
53
  }
54
- // case Events.MoveCamera: {
55
- // this.moveCameraHandler(data.payload);
56
- // break;
57
- // }
58
- // case Events.MoveCameraToContain: {
59
- // this.moveCameraToContainHandler(data.payload);
60
- // break;
61
- // }
62
54
  case Events.CursorMove: {
63
55
  this.cursorMoveHandler(data.payload);
64
56
  break;
@@ -103,17 +95,6 @@ export class AppListeners {
103
95
  callbacks.emit("mainViewScenePathChange", nextScenePath);
104
96
  };
105
97
 
106
- // private moveCameraHandler = (
107
- // payload: Camera & { animationMode?: AnimationMode | undefined }
108
- // ) => {
109
- // if (isEqual(omit(payload, ["animationMode"]), { ...this.manager.mainView.camera })) return;
110
- // this.manager.mainView.moveCamera(payload);
111
- // };
112
-
113
- // private moveCameraToContainHandler = (payload: any) => {
114
- // this.manager.mainView.moveCameraToContain(payload);
115
- // };
116
-
117
98
  private cursorMoveHandler = (payload: any) => {
118
99
  internalEmitter.emit("cursorMove", payload);
119
100
  };
package/src/AppManager.ts CHANGED
@@ -51,7 +51,6 @@ import type {
51
51
  } from "./BoxEmitter";
52
52
  import { getExtendClass } from "./Utils/extendClass";
53
53
  import type { TeleBoxState } from "@netless/telebox-insider";
54
- import { getAttribute } from "video.js/dist/types/utils/dom";
55
54
 
56
55
  export class AppManager {
57
56
  static readonly kind = "AppManager";
@@ -147,6 +146,7 @@ export class AppManager {
147
146
  const { scenePath } = params;
148
147
  // 如果移除根目录就把 scenePath 设置为初始值
149
148
  if (scenePath === ROOT_DIR) {
149
+ console.log("[window-manager] onRemoveScenes ROOT_DIR");
150
150
  await this.onRootDirRemoved();
151
151
  this.dispatchInternalEvent(Events.RootDirRemoved);
152
152
  return;
@@ -159,6 +159,7 @@ export class AppManager {
159
159
  sceneName = this.callbacksNode?.scenes[nextIndex];
160
160
  }
161
161
  if (sceneName) {
162
+ console.log("[window-manager] onRemoveScenes setMainViewScenePath", `${ROOT_DIR}${sceneName}`);
162
163
  this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
163
164
  }
164
165
  await this.setMainViewSceneIndex(nextIndex);
@@ -710,6 +711,26 @@ export class AppManager {
710
711
  }
711
712
  internalEmitter.emit("mainViewMounted");
712
713
  callbacks.emit("onMainViewMounted", mainView);
714
+ const hasRoot = this.hasRoot(mainView.divElement);
715
+ const rect = this.getRectByDivElement(mainView.divElement);
716
+ console.log("[window-manager] bindMainView hasRoot", hasRoot, JSON.stringify(rect), window.outerHeight, window.outerWidth);
717
+ }
718
+
719
+ private hasRoot(divElement: HTMLDivElement){
720
+ let current = divElement;
721
+ while (current) {
722
+ if (current.parentElement === document.body) {
723
+ return true;
724
+ }
725
+ current = current.parentElement as HTMLDivElement;
726
+ }
727
+ return false;
728
+ }
729
+
730
+ private getRectByDivElement(divElement: HTMLDivElement){
731
+ // 获取当前divElement的矩形区域
732
+ const rect = divElement.getBoundingClientRect();
733
+ return rect;
713
734
  }
714
735
 
715
736
  public setMainViewFocusPath(scenePath?: string) {
@@ -854,7 +875,7 @@ export class AppManager {
854
875
  private async _setMainViewScenePath(scenePath: string) {
855
876
  const success = this.setMainViewFocusPath(scenePath);
856
877
  if (success) {
857
- console.log("[window-manager] _setMainViewScenePath====>", scenePath);
878
+ console.log("[window-manager] _setMainViewScenePath ", scenePath);
858
879
  this.safeSetAttributes({ _mainScenePath: scenePath });
859
880
  this.store.setMainViewFocusPath(this.mainView);
860
881
  this.updateSceneIndex();
@@ -871,7 +892,7 @@ export class AppManager {
871
892
  const pageName = scenePath.replace(sceneDir, "").replace("/", "");
872
893
  const index = scenes.findIndex(scene => scene.name === pageName);
873
894
  if (isInteger(index) && index >= 0) {
874
- console.log("[window-manager] updateSceneIndex====>", index);
895
+ console.log("[window-manager] updateSceneIndex ", index);
875
896
  this.safeSetAttributes({ _mainSceneIndex: index });
876
897
  }
877
898
  }
@@ -897,7 +918,7 @@ export class AppManager {
897
918
  }
898
919
 
899
920
  private dispatchSetMainViewScenePath(scenePath: string): void {
900
- console.log("[window-manager] dispatchSetMainViewScenePath====>", JSON.stringify(scenePath));
921
+ console.log("[window-manager] dispatchSetMainViewScenePath ", JSON.stringify(scenePath));
901
922
  this.dispatchInternalEvent(Events.SetMainViewScenePath, { nextScenePath: scenePath });
902
923
  callbacks.emit("mainViewScenePathChange", scenePath);
903
924
  // 兼容 15 的 SDK, 需要 room 的当前 ScenePath
@@ -7,6 +7,7 @@ import type { Cursor } from "./Cursor/Cursor";
7
7
  import { getExtendClass } from "./Utils/extendClass";
8
8
  import type { ExtendClass } from "./Utils/extendClass";
9
9
  import type { NotMinimizedBoxState, TeleBoxState } from "@netless/telebox-insider";
10
+ import { LocalConsole } from "./Utils/log";
10
11
 
11
12
  export enum Fields {
12
13
  Apps = "apps",
@@ -54,6 +55,7 @@ export type ISize = Size & { id: string };
54
55
 
55
56
  export class AttributesDelegate {
56
57
  static readonly kind = "AttributesDelegate";
58
+ private setMainViewCameraConsole = new LocalConsole("setMainViewCamera", 50);
57
59
  constructor(private context: StoreContext) {}
58
60
 
59
61
  public setContext(context: StoreContext) {
@@ -194,12 +196,12 @@ export class AttributesDelegate {
194
196
  }
195
197
 
196
198
  public setMainViewScenePath(scenePath: string) {
197
- console.log("[window-manager] setMainViewScenePath====>", scenePath);
199
+ console.log("[window-manager] setMainViewScenePath ", scenePath);
198
200
  this.context.safeSetAttributes({ _mainScenePath: scenePath });
199
201
  }
200
202
 
201
203
  public setMainViewSceneIndex(index: number) {
202
- console.log("[window-manager] setMainViewSceneIndex====>", index);
204
+ console.log("[window-manager] setMainViewSceneIndex ", index);
203
205
  this.context.safeSetAttributes({ _mainSceneIndex: index });
204
206
  }
205
207
 
@@ -212,19 +214,19 @@ export class AttributesDelegate {
212
214
  }
213
215
 
214
216
  public setMainViewCamera(camera: ICamera) {
215
- console.log("[window-manager] setMainViewCamera====>", JSON.stringify(camera));
217
+ this.setMainViewCameraConsole.log(JSON.stringify(camera));
216
218
  this.context.safeSetAttributes({ [Fields.MainViewCamera]: { ...camera } });
217
219
  }
218
220
 
219
221
  public setMainViewSize(size: ISize) {
220
222
  if (size.width === 0 || size.height === 0) return;
221
- console.log("[window-manager] setMainViewSize====>", JSON.stringify(size));
223
+ console.log("[window-manager] setMainViewSize ", JSON.stringify(size));
222
224
  this.context.safeSetAttributes({ [Fields.MainViewSize]: { ...size } });
223
225
  }
224
226
 
225
227
  public setMainViewCameraAndSize(camera: ICamera, size: ISize) {
226
228
  if (size.width === 0 || size.height === 0) return;
227
- console.log("[window-manager] setMainViewCameraAndSize====>", JSON.stringify(camera), JSON.stringify(size));
229
+ console.log("[window-manager] setMainViewCameraAndSize ", JSON.stringify(camera), JSON.stringify(size));
228
230
  this.context.safeSetAttributes({
229
231
  [Fields.MainViewCamera]: { ...camera },
230
232
  [Fields.MainViewSize]: { ...size },
@@ -34,7 +34,7 @@ export const setScenePath = (room: Room | undefined, scenePath: string) => {
34
34
  if (room && room.isWritable) {
35
35
  if (room.state.sceneState.scenePath !== scenePath) {
36
36
  const nextScenePath = scenePath === "/" ? "" : scenePath;
37
- console.log("[window-manager] real setScenePath for current room====>", nextScenePath);
37
+ console.log("[window-manager] real setScenePath for current room ", nextScenePath);
38
38
  room.setScenePath(nextScenePath);
39
39
  }
40
40
  }
@@ -35,8 +35,11 @@ export const replaceRoomFunction = (room: Room | Player, manager: WindowManager)
35
35
  });
36
36
  const _scalePptToFit = room.scalePptToFit;
37
37
  room.scalePptToFit = (...args) => {
38
- console.log("[window-manager] scalePptToFit====>", JSON.stringify(args));
39
38
  _scalePptToFit.call(room, ...args);
39
+ if (manager.appManager?.mainViewProxy) {
40
+ console.log("[window-manager] scalePptToFit ", JSON.stringify(args));
41
+ manager.appManager.mainViewProxy.setCameraAndSize();
42
+ }
40
43
  };
41
44
  room.moveCamera = (camera: Camera) => manager.moveCamera(camera);
42
45
  room.moveCameraToContain = (...args) => manager.moveCameraToContain(...args);
package/src/Utils/log.ts CHANGED
@@ -5,3 +5,40 @@ export const log = (...args: any[]): void => {
5
5
  console.log(`[WindowManager]:`, ...args);
6
6
  }
7
7
  };
8
+
9
+ /**
10
+ * 按 `[window-manager][tagName]` 前缀输出。
11
+ * 若传入 `debounceTime`(毫秒):窗口内多次 `log` 不立即输出,只在连续停止调用满 `debounceTime` 后输出**最后一次**的参数(尾部 debounce)。
12
+ */
13
+ export class LocalConsole {
14
+ private pendingArgs: unknown[] | null = null;
15
+ private flushTimer: ReturnType<typeof setTimeout> | null = null;
16
+
17
+ constructor(
18
+ private readonly name: string,
19
+ private readonly debounceTime?: number,
20
+ ) {}
21
+
22
+ private flush(): void {
23
+ this.flushTimer = null;
24
+ const args = this.pendingArgs;
25
+ this.pendingArgs = null;
26
+ if (args === null) {
27
+ return;
28
+ }
29
+ console.log(`[window-manager][${this.name}]:`, ...args);
30
+ }
31
+
32
+ log(...args: unknown[]): void {
33
+ const ms = this.debounceTime;
34
+ if (ms != null && ms > 0) {
35
+ this.pendingArgs = args;
36
+ if (this.flushTimer != null) {
37
+ clearTimeout(this.flushTimer);
38
+ }
39
+ this.flushTimer = setTimeout(() => this.flush(), ms);
40
+ return;
41
+ }
42
+ console.log(`[window-manager][${this.name}]:`, ...args);
43
+ }
44
+ }
@@ -9,6 +9,7 @@ import { SideEffectManager } from "side-effect-manager";
9
9
  import type { Camera, Room, Size, View } from "white-web-sdk";
10
10
  import type { AppManager } from "../AppManager";
11
11
  import { Events } from "../constants";
12
+ import { LocalConsole } from "../Utils/log";
12
13
 
13
14
  export class MainViewProxy {
14
15
  /** Refresh the view's camera in an interval of 1.5s. */
@@ -23,6 +24,8 @@ export class MainViewProxy {
23
24
 
24
25
  private sideEffectManager = new SideEffectManager();
25
26
 
27
+ private playgroundSizeChangeListenerLocalConsole = new LocalConsole("playgroundSizeChangeListener", 30);
28
+
26
29
  constructor(private manager: AppManager) {
27
30
  this.mainView = this.createMainView();
28
31
  this.moveCameraSizeByAttributes();
@@ -33,7 +36,8 @@ export class MainViewProxy {
33
36
  this.startListenWritableChange();
34
37
  });
35
38
  const playgroundSizeChangeListener = () => {
36
- console.log("[window-manager] playgroundSizeChangeListener====>", JSON.stringify(this.mainViewSize));
39
+ // console.log("[window-manager] playgroundSizeChangeListener ", JSON.stringify(this.mainViewSize), JSON.stringify(this.mainViewCamera));
40
+ this.playgroundSizeChangeListenerLocalConsole.log(JSON.stringify(this.mainViewSize), JSON.stringify(this.mainViewCamera));
37
41
  this.sizeChangeHandler(this.mainViewSize);
38
42
  };
39
43
  this.sideEffectManager.add(() => {
@@ -98,7 +102,7 @@ export class MainViewProxy {
98
102
  }
99
103
 
100
104
  public start() {
101
- console.log("[window-manager] start====>", JSON.stringify(this.mainViewSize));
105
+ console.log("[window-manager] start ", JSON.stringify(this.mainViewSize));
102
106
  this.sizeChangeHandler(this.mainViewSize);
103
107
  if (this.started) return;
104
108
  this.addCameraListener();
@@ -122,7 +126,7 @@ export class MainViewProxy {
122
126
  () => this.mainViewCamera,
123
127
  camera => {
124
128
  if (camera && camera.id !== this.manager.uid) {
125
- console.log("[window-manager] cameraReaction====>", JSON.stringify(camera), JSON.stringify(this.mainViewSize));
129
+ console.log("[window-manager] cameraReaction ", JSON.stringify(camera), JSON.stringify(this.mainViewSize));
126
130
  this.moveCameraToContian(this.mainViewSize);
127
131
  this.moveCamera(camera);
128
132
  }
@@ -133,16 +137,16 @@ export class MainViewProxy {
133
137
 
134
138
  public sizeChangeHandler = debounce((size: Size) => {
135
139
  if (size) {
140
+ console.log("[window-manager] sizeChangeHandler current size and camera", JSON.stringify(size), JSON.stringify(this.mainViewCamera));
136
141
  this.moveCameraToContian(size);
137
142
  this.moveCamera(this.mainViewCamera);
138
- console.log("[window-manager] sizeChangeHandler====> current size and camera", JSON.stringify(size), JSON.stringify(this.mainViewCamera));
139
143
  }
140
144
  this.ensureMainViewSize();
141
145
  }, 30);
142
146
 
143
147
  public onUpdateContainerSizeRatio = () => {
144
148
  const size = this.store.getMainViewSize();
145
- console.log("[window-manager] onUpdateContainerSizeRatio====>", JSON.stringify(size));
149
+ console.log("[window-manager] onUpdateContainerSizeRatio ", JSON.stringify(size));
146
150
  this.sizeChangeHandler(size);
147
151
  };
148
152
 
@@ -254,7 +258,6 @@ export class MainViewProxy {
254
258
  clearTimeout(this._syncMainViewTimer);
255
259
  this._syncMainViewTimer = setTimeout(this.syncMainView, 100, this.manager.room);
256
260
  }
257
- console.log("[window-manager] onCameraOrSizeUpdated====>", JSON.stringify(this.cameraState));
258
261
  this.ensureMainViewSize();
259
262
  };
260
263
 
@@ -272,7 +275,7 @@ export class MainViewProxy {
272
275
 
273
276
  private syncMainView = (room: Room) => {
274
277
  if (room.isWritable) {
275
- console.log("[window-manager] syncMainView====>");
278
+ console.log("[window-manager] syncMainView ");
276
279
  room.syncMainView(this.mainView);
277
280
  }
278
281
  };
package/src/index.ts CHANGED
@@ -253,6 +253,12 @@ export class WindowManager
253
253
  super(context);
254
254
  WindowManager.displayer = context.displayer;
255
255
  (window as any).NETLESS_DEPS = __APP_DEPENDENCIES__;
256
+ this.visibleStateListener();
257
+ document.addEventListener("visibilitychange", this.visibleStateListener);
258
+ }
259
+
260
+ private visibleStateListener = () => {
261
+ console.log("[window-manager] visibleStateListener isVisible:", !document.hidden);
256
262
  }
257
263
 
258
264
  public static onCreate(manager: WindowManager) {
@@ -386,10 +392,11 @@ export class WindowManager
386
392
  console.warn("[WindowManager]: indexedDB open failed");
387
393
  console.log(error);
388
394
  }
389
-
390
395
  return manager;
391
396
  }
392
397
 
398
+
399
+
393
400
  private static initManager(room: Room): Promise<WindowManager | undefined> {
394
401
  return createInvisiblePlugin(room);
395
402
  }
@@ -1011,7 +1018,6 @@ export class WindowManager
1011
1018
  const mainViewCamera = { ...this.mainView.camera };
1012
1019
  if (isEqual({ ...mainViewCamera, ...pureCamera }, mainViewCamera)) return;
1013
1020
  this.mainView.moveCamera(camera);
1014
- // this.appManager?.dispatchInternalEvent(Events.MoveCamera, camera);
1015
1021
  setTimeout(() => {
1016
1022
  this.appManager?.mainViewProxy.setCameraAndSize();
1017
1023
  }, 500);
@@ -1024,7 +1030,6 @@ export class WindowManager
1024
1030
  }>
1025
1031
  ): void {
1026
1032
  this.mainView.moveCameraToContain(rectangle);
1027
- // this.appManager?.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
1028
1033
  setTimeout(() => {
1029
1034
  this.appManager?.mainViewProxy.setCameraAndSize();
1030
1035
  }, 500);
@@ -1059,6 +1064,7 @@ export class WindowManager
1059
1064
  WindowManager.playground.parentNode?.removeChild(WindowManager.playground);
1060
1065
  }
1061
1066
  WindowManager.params = undefined;
1067
+ document.removeEventListener("visibilitychange", this.visibleStateListener);
1062
1068
  this._iframeBridge?.destroy();
1063
1069
  this._iframeBridge = undefined;
1064
1070
  log("Destroyed");