@netless/window-manager 1.0.13-test.12 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "1.0.13-test.12",
3
+ "version": "1.0.13-test.13",
4
4
  "description": "Multi-window mode for Netless Whiteboard",
5
5
  "author": "l1shen <lishen1635@gmail.com> (https://github.com/l1shen)",
6
6
  "license": "MIT",
@@ -20,6 +20,7 @@ export class MainViewProxy {
20
20
  private started = false;
21
21
  private mainViewIsAddListener = false;
22
22
  private mainViewResizeObserver?: ResizeObserver;
23
+ private isForcingMainViewDivElement = false;
23
24
  private mainView: View;
24
25
  private store = this.manager.store;
25
26
  private viewMode = this.manager.windowManger.viewMode;
@@ -39,7 +40,7 @@ export class MainViewProxy {
39
40
  this.startListenWritableChange();
40
41
  });
41
42
  const playgroundSizeChangeListener = () => {
42
- this.refreshScreenSizeIfStale();
43
+ // this.refreshScreenSizeIfStale();
43
44
  this.playgroundSizeChangeListenerLocalConsole.log(
44
45
  JSON.stringify(this.mainView.camera),
45
46
  JSON.stringify(this.mainView.size),
@@ -118,16 +119,48 @@ export class MainViewProxy {
118
119
 
119
120
  const { width, height } = element.getBoundingClientRect();
120
121
  if (width <= 0 || height <= 0) return;
122
+ this.forceSyncMainViewDivElement("playgroundSizeChange", { width, height }, element);
123
+ }
121
124
 
125
+ private forceSyncMainViewDivElement(
126
+ reason: string,
127
+ observedSize: Pick<Size, "width" | "height">,
128
+ element: HTMLDivElement
129
+ ) {
122
130
  const { width: viewWidth, height: viewHeight } = this.mainView.size;
123
- if (Math.abs(viewWidth - width) > 0.5 || Math.abs(viewHeight - height) > 0.5) {
124
- const resizableView = this.mainView as View & { resizeScreen?: () => void };
125
- console.log("[window-manager] forceResizeScreen stale size" + JSON.stringify({
131
+ if (
132
+ Math.abs(viewWidth - observedSize.width) <= 0.5 &&
133
+ Math.abs(viewHeight - observedSize.height) <= 0.5
134
+ ) {
135
+ return;
136
+ }
137
+ if (this.isForcingMainViewDivElement) {
138
+ console.log("[window-manager] skipForceSyncMainViewDivElement " + JSON.stringify({
139
+ reason,
140
+ observedSize,
126
141
  viewSize: this.mainView.size,
127
- domSize: { width, height },
128
142
  }));
129
- resizableView.resizeScreen?.();
143
+ return;
130
144
  }
145
+ this.isForcingMainViewDivElement = true;
146
+ console.log("[window-manager] forceSyncMainViewDivElement " + JSON.stringify({
147
+ reason,
148
+ observedSize,
149
+ viewSize: this.mainView.size,
150
+ mainViewSize: this.mainViewSize,
151
+ mainViewCamera: this.mainViewCamera,
152
+ }));
153
+ this.mainView.divElement = null;
154
+ this.mainView.divElement = element;
155
+ queueMicrotask(() => {
156
+ const rect = element.getBoundingClientRect();
157
+ console.log("[window-manager] forceSyncMainViewDivElementResult " + JSON.stringify({
158
+ reason,
159
+ viewSize: this.mainView.size,
160
+ rect: { width: rect.width, height: rect.height },
161
+ }));
162
+ this.isForcingMainViewDivElement = false;
163
+ });
131
164
  }
132
165
 
133
166
  public start() {
@@ -138,6 +171,7 @@ export class MainViewProxy {
138
171
  this.addCameraReaction();
139
172
  if (this.manager.room) this.syncMainView(this.manager.room);
140
173
  this.started = true;
174
+ console.log("[window-manager] start end " + JSON.stringify(this.mainViewSize), JSON.stringify(this.mainView.size));
141
175
  }
142
176
 
143
177
  public addCameraReaction = () => {
@@ -271,20 +305,24 @@ export class MainViewProxy {
271
305
 
272
306
  private addCameraListener() {
273
307
  this.view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
274
- this.view.callbacks.on("onCameraUpdated", this.onCameraOrSizeUpdated);
275
- this.view.callbacks.on("onSizeUpdated", this.onCameraOrSizeUpdated);
308
+ this.view.callbacks.on("onCameraUpdated", this.onCameraUpdated);
309
+ this.view.callbacks.on("onSizeUpdated", this.onSizeUpdated);
276
310
  }
277
311
 
278
312
  private removeCameraListener() {
279
313
  this.view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
280
- this.view.callbacks.off("onCameraUpdated", this.onCameraOrSizeUpdated);
281
- this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
314
+ this.view.callbacks.off("onCameraUpdated", this.onCameraUpdated);
315
+ this.view.callbacks.off("onSizeUpdated", this.onSizeUpdated);
282
316
  }
283
317
 
284
318
  private observeMainViewDivElement() {
285
319
  this.disconnectMainViewResizeObserver();
286
320
  if (!("ResizeObserver" in window)) return;
287
321
  if (!this.mainView.divElement) return;
322
+ console.log("[window-manager] observeMainViewDivElement " + JSON.stringify({
323
+ rect: this.mainView.divElement.getBoundingClientRect(),
324
+ viewSize: this.mainView.size,
325
+ }));
288
326
  this.mainViewResizeObserver = new window.ResizeObserver(this.onResize);
289
327
  this.mainViewResizeObserver.observe(this.mainView.divElement);
290
328
  }
@@ -299,10 +337,15 @@ export class MainViewProxy {
299
337
  if (!entry) return;
300
338
  const target = entry.target as HTMLDivElement;
301
339
  const child = target.children[0] as HTMLElement | undefined;
340
+ const observedSize = {
341
+ width: entry.contentRect.width,
342
+ height: entry.contentRect.height,
343
+ };
302
344
  console.log("[window-manager] mainViewResizeObserver " + JSON.stringify({
345
+ sameTarget: target === this.mainView.divElement,
303
346
  contentRect: {
304
- width: entry.contentRect.width,
305
- height: entry.contentRect.height,
347
+ width: observedSize.width,
348
+ height: observedSize.height,
306
349
  },
307
350
  client: {
308
351
  width: target.clientWidth,
@@ -324,17 +367,22 @@ export class MainViewProxy {
324
367
  : null,
325
368
  viewSize: this.mainView.size,
326
369
  }));
370
+ this.forceSyncMainViewDivElement("mainViewResizeObserver", observedSize, target);
327
371
  };
328
372
 
329
373
  private _syncMainViewTimer = 0;
330
- private onCameraOrSizeUpdated = () => {
331
- console.log("[window-manager] onCameraOrSizeUpdated " + JSON.stringify(this.cameraState));
374
+ private handleCameraOrSizeUpdated = (
375
+ source: "onCameraUpdated" | "onSizeUpdated",
376
+ payload: Camera | Size
377
+ ) => {
378
+ console.log("[window-manager] " + source + " payload " + JSON.stringify(payload));
379
+ console.log("[window-manager] " + source + " state " + JSON.stringify(this.cameraState));
332
380
  if(this.mainView.divElement){
333
381
  const children = this.mainView.divElement.children;
334
- console.log("[window-manager] onCameraOrSizeUpdated " + this.mainView.divElement.getBoundingClientRect());
382
+ console.log("[window-manager] " + source + " rect " + JSON.stringify(this.mainView.divElement.getBoundingClientRect()));
335
383
  const child = children[0];
336
384
  if (child) {
337
- console.log("[window-manager] child" + JSON.stringify(child.getBoundingClientRect()));
385
+ console.log("[window-manager] " + source + " child" + JSON.stringify(child.getBoundingClientRect()));
338
386
  }
339
387
  }
340
388
  callbacks.emit("cameraStateChange", this.cameraState);
@@ -347,6 +395,14 @@ export class MainViewProxy {
347
395
  this.ensureMainViewSize();
348
396
  };
349
397
 
398
+ private onCameraUpdated = (camera: Camera) => {
399
+ this.handleCameraOrSizeUpdated("onCameraUpdated", camera);
400
+ };
401
+
402
+ private onSizeUpdated = (size: Size) => {
403
+ this.handleCameraOrSizeUpdated("onSizeUpdated", size);
404
+ };
405
+
350
406
  private ensureMainViewSize() {
351
407
  if (
352
408
  (!this.mainViewSize ||
@@ -405,6 +461,7 @@ export class MainViewProxy {
405
461
  };
406
462
 
407
463
  public destroy() {
464
+ console.log("[window-manager] destroy ");
408
465
  this.removeMainViewListener();
409
466
  this.disconnectMainViewResizeObserver();
410
467
  this.stop();