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

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.4",
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,30 @@ 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),
717
+ window.outerHeight, window.outerWidth,
718
+ window.visualViewport?.width ?? "null", window.visualViewport?.height ?? "null",
719
+ window.visualViewport?.offsetLeft ?? "null", window.visualViewport?.offsetTop ?? "null",
720
+ );
721
+ }
722
+
723
+ private hasRoot(divElement: HTMLDivElement){
724
+ let current = divElement;
725
+ while (current) {
726
+ if (current.parentElement === document.body) {
727
+ return true;
728
+ }
729
+ current = current.parentElement as HTMLDivElement;
730
+ }
731
+ return false;
732
+ }
733
+
734
+ private getRectByDivElement(divElement: HTMLDivElement){
735
+ // 获取当前divElement的矩形区域
736
+ const rect = divElement.getBoundingClientRect();
737
+ return rect;
713
738
  }
714
739
 
715
740
  public setMainViewFocusPath(scenePath?: string) {
@@ -854,7 +879,7 @@ export class AppManager {
854
879
  private async _setMainViewScenePath(scenePath: string) {
855
880
  const success = this.setMainViewFocusPath(scenePath);
856
881
  if (success) {
857
- console.log("[window-manager] _setMainViewScenePath====>", scenePath);
882
+ console.log("[window-manager] _setMainViewScenePath ", scenePath);
858
883
  this.safeSetAttributes({ _mainScenePath: scenePath });
859
884
  this.store.setMainViewFocusPath(this.mainView);
860
885
  this.updateSceneIndex();
@@ -871,7 +896,7 @@ export class AppManager {
871
896
  const pageName = scenePath.replace(sceneDir, "").replace("/", "");
872
897
  const index = scenes.findIndex(scene => scene.name === pageName);
873
898
  if (isInteger(index) && index >= 0) {
874
- console.log("[window-manager] updateSceneIndex====>", index);
899
+ console.log("[window-manager] updateSceneIndex ", index);
875
900
  this.safeSetAttributes({ _mainSceneIndex: index });
876
901
  }
877
902
  }
@@ -897,7 +922,7 @@ export class AppManager {
897
922
  }
898
923
 
899
924
  private dispatchSetMainViewScenePath(scenePath: string): void {
900
- console.log("[window-manager] dispatchSetMainViewScenePath====>", JSON.stringify(scenePath));
925
+ console.log("[window-manager] dispatchSetMainViewScenePath ", JSON.stringify(scenePath));
901
926
  this.dispatchInternalEvent(Events.SetMainViewScenePath, { nextScenePath: scenePath });
902
927
  callbacks.emit("mainViewScenePathChange", scenePath);
903
928
  // 兼容 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,14 @@ 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(
41
+ JSON.stringify(this.mainViewSize),
42
+ JSON.stringify(this.mainViewCamera),
43
+ window.outerHeight, window.outerWidth,
44
+ window.visualViewport?.width ?? "null", window.visualViewport?.height ?? "null",
45
+ window.visualViewport?.offsetLeft ?? "null", window.visualViewport?.offsetTop ?? "null",
46
+ );
37
47
  this.sizeChangeHandler(this.mainViewSize);
38
48
  };
39
49
  this.sideEffectManager.add(() => {
@@ -98,7 +108,7 @@ export class MainViewProxy {
98
108
  }
99
109
 
100
110
  public start() {
101
- console.log("[window-manager] start====>", JSON.stringify(this.mainViewSize));
111
+ console.log("[window-manager] start ", JSON.stringify(this.mainViewSize));
102
112
  this.sizeChangeHandler(this.mainViewSize);
103
113
  if (this.started) return;
104
114
  this.addCameraListener();
@@ -122,7 +132,7 @@ export class MainViewProxy {
122
132
  () => this.mainViewCamera,
123
133
  camera => {
124
134
  if (camera && camera.id !== this.manager.uid) {
125
- console.log("[window-manager] cameraReaction====>", JSON.stringify(camera), JSON.stringify(this.mainViewSize));
135
+ console.log("[window-manager] cameraReaction ", JSON.stringify(camera), JSON.stringify(this.mainViewSize));
126
136
  this.moveCameraToContian(this.mainViewSize);
127
137
  this.moveCamera(camera);
128
138
  }
@@ -133,16 +143,16 @@ export class MainViewProxy {
133
143
 
134
144
  public sizeChangeHandler = debounce((size: Size) => {
135
145
  if (size) {
146
+ console.log("[window-manager] sizeChangeHandler current size and camera", JSON.stringify(size), JSON.stringify(this.mainViewCamera));
136
147
  this.moveCameraToContian(size);
137
148
  this.moveCamera(this.mainViewCamera);
138
- console.log("[window-manager] sizeChangeHandler====> current size and camera", JSON.stringify(size), JSON.stringify(this.mainViewCamera));
139
149
  }
140
150
  this.ensureMainViewSize();
141
151
  }, 30);
142
152
 
143
153
  public onUpdateContainerSizeRatio = () => {
144
154
  const size = this.store.getMainViewSize();
145
- console.log("[window-manager] onUpdateContainerSizeRatio====>", JSON.stringify(size));
155
+ console.log("[window-manager] onUpdateContainerSizeRatio ", JSON.stringify(size));
146
156
  this.sizeChangeHandler(size);
147
157
  };
148
158
 
@@ -254,7 +264,6 @@ export class MainViewProxy {
254
264
  clearTimeout(this._syncMainViewTimer);
255
265
  this._syncMainViewTimer = setTimeout(this.syncMainView, 100, this.manager.room);
256
266
  }
257
- console.log("[window-manager] onCameraOrSizeUpdated====>", JSON.stringify(this.cameraState));
258
267
  this.ensureMainViewSize();
259
268
  };
260
269
 
@@ -272,7 +281,7 @@ export class MainViewProxy {
272
281
 
273
282
  private syncMainView = (room: Room) => {
274
283
  if (room.isWritable) {
275
- console.log("[window-manager] syncMainView====>");
284
+ console.log("[window-manager] syncMainView ");
276
285
  room.syncMainView(this.mainView);
277
286
  }
278
287
  };
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");