@netless/window-manager 1.0.0-canary.16 → 1.0.0-canary.19

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.
@@ -0,0 +1,28 @@
1
+ ## 迁移至 `@netless/window-manager@1.0`
2
+
3
+ ### 样式
4
+
5
+ 1.0 之前
6
+
7
+ ```html
8
+ <div class="netless-window-manager-playground">
9
+ <div class="netless-window-manager-sizer">
10
+ <div class="netless-window-manager-wrapper">
11
+ <div class="netless-window-manager-main-view"></div>
12
+ </div>
13
+ </div>
14
+ </div>
15
+ ```
16
+
17
+ 1.0 之后
18
+
19
+ ```html
20
+ <div class="netless-window-manager-playground">
21
+ <div class="netless-window-manager-main-view"></div>
22
+ </div>
23
+ ```
24
+
25
+
26
+ ### `APP` 迁移
27
+
28
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "1.0.0-canary.16",
3
+ "version": "1.0.0-canary.19",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@juggle/resize-observer": "^3.3.1",
26
- "@netless/telebox-insider": "1.0.0-alpha.17",
26
+ "@netless/telebox-insider": "1.0.0-alpha.18",
27
27
  "emittery": "^0.9.2",
28
28
  "lodash": "^4.17.21",
29
29
  "p-retry": "^4.6.1",
package/pnpm-lock.yaml CHANGED
@@ -4,7 +4,7 @@ specifiers:
4
4
  '@juggle/resize-observer': ^3.3.1
5
5
  '@netless/app-docs-viewer': ^0.2.9
6
6
  '@netless/app-media-player': 0.1.0-beta.5
7
- '@netless/telebox-insider': 1.0.0-alpha.17
7
+ '@netless/telebox-insider': 1.0.0-alpha.18
8
8
  '@rollup/plugin-commonjs': ^20.0.0
9
9
  '@rollup/plugin-node-resolve': ^13.0.4
10
10
  '@rollup/plugin-url': ^6.1.0
@@ -43,7 +43,7 @@ specifiers:
43
43
 
44
44
  dependencies:
45
45
  '@juggle/resize-observer': registry.npmmirror.com/@juggle/resize-observer/3.3.1
46
- '@netless/telebox-insider': 1.0.0-alpha.17
46
+ '@netless/telebox-insider': 1.0.0-alpha.18
47
47
  emittery: registry.npmmirror.com/emittery/0.9.2
48
48
  lodash: registry.npmmirror.com/lodash/4.17.21
49
49
  p-retry: registry.npmmirror.com/p-retry/4.6.1
@@ -97,8 +97,8 @@ packages:
97
97
  vanilla-lazyload: 17.6.1
98
98
  dev: true
99
99
 
100
- /@netless/telebox-insider/1.0.0-alpha.17:
101
- resolution: {integrity: sha512-FoiX5tKKT26EyDiO/gT4P7rhr9Pvkcf2RJuSPxt5PO0ij73vUaU6OwjXJzZkcnIZlHPHhleJoqt1difaJpmyLQ==}
100
+ /@netless/telebox-insider/1.0.0-alpha.18:
101
+ resolution: {integrity: sha512-YTIJcBV9X7jP9KoBFtPMyzK7eWCox1aZmWD3453Bwe6aOHrM/7AsBcnw0VM6K1ij10wFXpsgDQT1m3XczlbeUg==}
102
102
  dependencies:
103
103
  '@juggle/resize-observer': 3.3.1
104
104
  '@types/shallowequal': 1.1.1
@@ -47,7 +47,7 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
47
47
  private store = this.manager.store;
48
48
  public readonly isAddApp: boolean;
49
49
  public readonly isReplay = this.manager.isReplay;
50
- private whiteBoardView?: WhiteBoardView;
50
+ public whiteBoardView?: WhiteBoardView;
51
51
  public _viewWrapper?: HTMLElement;
52
52
 
53
53
  constructor(
@@ -125,7 +125,7 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
125
125
  }
126
126
 
127
127
  public getInitScenePath = () => {
128
- return this.manager.getAppInitPath(this.appId);
128
+ return this.appProxy.scenePath;
129
129
  };
130
130
 
131
131
  /** Get App writable status. */
@@ -30,7 +30,7 @@ import type {
30
30
  setAppOptions,
31
31
  AppListenerKeys,
32
32
  } from "../index";
33
- import type { SceneState, View, SceneDefinition, Camera , MemberState} from "white-web-sdk";
33
+ import type { SceneState, View, SceneDefinition, MemberState} from "white-web-sdk";
34
34
  import type { AppManager } from "../AppManager";
35
35
  import type { NetlessApp } from "../typings";
36
36
  import type { ReadonlyTeleBox, TeleBoxRect } from "@netless/telebox-insider";
@@ -117,8 +117,8 @@ export class AppProxy implements PageRemoveService {
117
117
  if (box && view) {
118
118
  if (!this.camera$.value) {
119
119
  this.storeCamera({
120
- centerX: 0,
121
- centerY: 0,
120
+ centerX: null,
121
+ centerY: null,
122
122
  scale: 1,
123
123
  id: this.uid,
124
124
  });
@@ -339,12 +339,14 @@ export class AppProxy implements PageRemoveService {
339
339
  private fixMobileSize() {
340
340
  const box = this.boxManager?.getBox(this.id);
341
341
  if (box) {
342
- this.boxManager?.resizeBox({
343
- appId: this.id,
344
- width: box.intrinsicWidth + 0.001,
345
- height: box.intrinsicHeight + 0.001,
346
- skipUpdate: true,
347
- });
342
+ if (!box.minimized) {
343
+ this.boxManager?.resizeBox({
344
+ appId: this.id,
345
+ width: box.intrinsicWidth + 0.001,
346
+ height: box.intrinsicHeight + 0.001,
347
+ skipUpdate: true,
348
+ });
349
+ }
348
350
  }
349
351
  }
350
352
 
@@ -593,7 +595,7 @@ export class AppProxy implements PageRemoveService {
593
595
  this.size$.setValue(iSize);
594
596
  }
595
597
 
596
- public moveCamera = (camera: Partial<Camera>) => {
598
+ public moveCamera = (camera: Partial<ICamera>) => {
597
599
  if (!this.camera$.value) {
598
600
  return;
599
601
  }
@@ -635,6 +637,8 @@ export class AppProxy implements PageRemoveService {
635
637
  this.manager.refresher.remove(this.id);
636
638
  this.manager.refresher.remove(this.stateKey);
637
639
  this.manager.refresher.remove(`${this.id}-fullPath`);
640
+ this.manager.refresher.remove(`${this.id}-camera`);
641
+ this.manager.refresher.remove(`${this.id}-size`);
638
642
  this.valManager.destroy();
639
643
  }
640
644
 
@@ -6,10 +6,11 @@ import type { ReadonlyVal } from "value-enhancer";
6
6
  import type { AddPageParams, PageController, PageState } from "../Page";
7
7
  import type { AppProxy } from "./AppProxy";
8
8
  import type { AppContext } from "./AppContext";
9
- import type { Camera, View } from "white-web-sdk";
9
+ import type { View } from "white-web-sdk";
10
10
  import type { TeleBoxRect } from "@netless/telebox-insider";
11
+ import type { ICamera } from "../AttributesDelegate";
11
12
 
12
- export type WhiteBoardViewCamera = Omit<Camera, "scale">;
13
+ export type WhiteBoardViewCamera = Omit<ICamera, "scale" | "id">;
13
14
 
14
15
  export class WhiteBoardView implements PageController {
15
16
  public readonly pageState$: ReadonlyVal<PageState>;
package/src/AppManager.ts CHANGED
@@ -659,7 +659,6 @@ export class AppManager {
659
659
  if (sceneState) {
660
660
  const scenePath = sceneState.scenePath;
661
661
  this.appProxies.forEach(appProxy => {
662
- console.log("scenePath", scenePath, appProxy.scenePath);
663
662
  if (appProxy.scenePath && scenePath.startsWith(appProxy.scenePath)) {
664
663
  appProxy.emitAppSceneStateChange(sceneState);
665
664
  appProxy.setFullPath(scenePath);
@@ -2,7 +2,7 @@ import { AppAttributes } from "./constants";
2
2
  import { get, pick } from "lodash";
3
3
  import { setViewFocusScenePath } from "./Utils/Common";
4
4
  import type { AddAppParams, AppSyncAttributes } from "./index";
5
- import type { Camera, Size, View } from "white-web-sdk";
5
+ import type { Size, View } from "white-web-sdk";
6
6
  import type { Cursor } from "./Cursor/Cursor";
7
7
 
8
8
  export enum Fields {
@@ -41,8 +41,11 @@ export type StoreContext = {
41
41
  safeSetAttributes: (attributes: any) => void;
42
42
  }
43
43
 
44
- export type ICamera = Camera & {
44
+ export type ICamera = & {
45
45
  id: string; // room uid
46
+ centerX: number | null,
47
+ centerY: number | null,
48
+ scale: number
46
49
  };
47
50
 
48
51
  export type ISize = Size & {
@@ -53,7 +53,7 @@ export class ReconnectRefresher {
53
53
 
54
54
  private onReconnected = debounce(() => {
55
55
  this._onReconnected();
56
- }, 3000);
56
+ }, 1000);
57
57
 
58
58
  private _onReconnected = () => {
59
59
  log("onReconnected refresh reactors");
@@ -56,6 +56,9 @@ export const replaceRoomFunction = (room: Room | Player, manager: WindowManager)
56
56
  room.lockImages = (...args) => manager.lockImages(...args);
57
57
 
58
58
  delegateRemoveScenes(room, manager);
59
+ if (!(room as any).dynamicPpt.slideStateAdapter.pptHandler) {
60
+ (room as any).dynamicPpt.slideStateAdapter.pptHandler = manager.createPPTHandler();
61
+ }
59
62
  }
60
63
  };
61
64
 
@@ -2,12 +2,12 @@ import { AnimationMode } from "white-web-sdk";
2
2
  import { debounce, delay, isEqual, pick, throttle } from "lodash";
3
3
  import type { TeleBoxRect } from "@netless/telebox-insider";
4
4
  import type { Camera, View } from "white-web-sdk";
5
- import type { ISize } from "../AttributesDelegate";
5
+ import type { ICamera, ISize } from "../AttributesDelegate";
6
6
 
7
- export type SaveCamera = (camera: Camera) => void;
7
+ export type SaveCamera = (camera: ICamera) => void;
8
8
 
9
9
  export class CameraSynchronizer {
10
- public remoteCamera?: Camera;
10
+ public remoteCamera?: ICamera;
11
11
  public remoteSize?: ISize;
12
12
  protected rect?: TeleBoxRect;
13
13
  protected view?: View;
@@ -26,7 +26,7 @@ export class CameraSynchronizer {
26
26
  }
27
27
 
28
28
  // 远端 Camera 或者 size 更新
29
- public onRemoteUpdate = throttle((camera: Camera, size: ISize) => {
29
+ public onRemoteUpdate = throttle((camera: ICamera, size: ISize) => {
30
30
  this.remoteCamera = camera;
31
31
  this.remoteSize = size;
32
32
  if (this.remoteSize && this.rect) {
@@ -38,12 +38,17 @@ export class CameraSynchronizer {
38
38
  }
39
39
  const nextScale = camera.scale * scale;
40
40
  const moveCamera = () => {
41
- this.view?.moveCamera({
42
- centerX: camera.centerX,
43
- centerY: camera.centerY,
41
+ const config: Partial<Camera> & { animationMode: AnimationMode } = {
44
42
  scale: nextScale,
45
43
  animationMode: AnimationMode.Immediately,
46
- });
44
+ }
45
+ if (camera.centerX !== null) {
46
+ config.centerX = camera.centerX;
47
+ }
48
+ if (camera.centerY !== null) {
49
+ config.centerY = camera.centerY;
50
+ }
51
+ this.view?.moveCamera(config);
47
52
  }
48
53
  moveCamera();
49
54
  // TODO 直接调用 moveCamera 依然会出现 camera 错误的情况,这里暂时加一个 delay 保证 camera 是对的, 后续需要 SDK 进行修改
@@ -68,7 +73,7 @@ export class CameraSynchronizer {
68
73
  }
69
74
  }
70
75
 
71
- public onLocalCameraUpdate(camera: Camera) {
76
+ public onLocalCameraUpdate(camera: ICamera) {
72
77
  this.saveCamera(camera);
73
78
  this.remoteCamera = camera;
74
79
  }
@@ -5,7 +5,7 @@ import { emitter } from "../InternalEmitter";
5
5
  import { Events } from "../constants";
6
6
  import { Fields } from "../AttributesDelegate";
7
7
  import { reaction, toJS } from "white-web-sdk";
8
- import { releaseView, setViewFocusScenePath } from "../Utils/Common";
8
+ import { releaseView, setScenePath, setViewFocusScenePath } from "../Utils/Common";
9
9
  import { SideEffectManager } from "side-effect-manager";
10
10
  import { Val } from "value-enhancer";
11
11
  import { ViewSync } from "./ViewSync";
@@ -41,6 +41,14 @@ export class MainViewProxy {
41
41
  }),
42
42
  ]);
43
43
  this.createViewSync();
44
+ this.sideEffectManager.add(() => emitter.on("focusedChange", ({ focused }) => {
45
+ if (focused === undefined) {
46
+ const scenePath = this.store.getMainViewScenePath();
47
+ if (scenePath) {
48
+ setScenePath(this.manager.room, scenePath);
49
+ }
50
+ }
51
+ }));
44
52
  }
45
53
 
46
54
  public createViewSync = () => {
@@ -31,17 +31,14 @@ export class ViewSync {
31
31
  private synchronizer: CameraSynchronizer;
32
32
 
33
33
  constructor(private context: ViewSyncContext) {
34
- this.synchronizer = new CameraSynchronizer((camera: Camera) => {
35
- const iCamera = {
36
- id: this.context.uid,
37
- ...camera,
38
- }
39
- this.context.camera$.setValue(iCamera, true);
40
- const notStoreCamera = this.context.viewMode$ && this.context.viewMode$.value === ViewMode.Freedom;
34
+ this.synchronizer = new CameraSynchronizer((camera: ICamera) => {
35
+ this.context.camera$.setValue(camera, true);
36
+ const notStoreCamera =
37
+ this.context.viewMode$ && this.context.viewMode$.value === ViewMode.Freedom;
41
38
  if (notStoreCamera) {
42
39
  return;
43
40
  } else {
44
- this.context.storeCamera(iCamera);
41
+ this.context.storeCamera(camera);
45
42
  }
46
43
  });
47
44
  this.bindView(this.context.view$.value);
@@ -54,8 +51,8 @@ export class ViewSync {
54
51
  animationMode: AnimationMode.Immediately,
55
52
  });
56
53
  this.synchronizer.onRemoteUpdate(currentCamera, this.context.size$.value);
57
- }
58
-
54
+ }
55
+
59
56
  this.bindView(view);
60
57
  })
61
58
  );
@@ -74,18 +71,15 @@ export class ViewSync {
74
71
  }
75
72
  })
76
73
  );
77
- if (this.context.stageRect$.value) {
78
- this.synchronizer.setRect(this.context.stageRect$.value);
79
- this.sem.add(() =>
80
- this.context.stageRect$.subscribe(rect => {
81
- if (rect) {
82
- this.synchronizer.setRect(rect);
83
- }
84
- })
85
- );
86
- }
74
+ this.sem.add(() =>
75
+ this.context.stageRect$.reaction(rect => {
76
+ if (rect) {
77
+ this.synchronizer.setRect(rect);
78
+ }
79
+ })
80
+ );
87
81
  const camera$size$ = combine([this.context.camera$, this.context.size$]);
88
- camera$size$.subscribe(([camera, size]) => {
82
+ camera$size$.reaction(([camera, size]) => {
89
83
  if (camera && size) {
90
84
  this.synchronizer.onRemoteUpdate(camera, size);
91
85
  camera$size$.destroy();
@@ -105,7 +99,7 @@ export class ViewSync {
105
99
  };
106
100
 
107
101
  private onCameraUpdatedByDevice = (camera: Camera) => {
108
- this.synchronizer.onLocalCameraUpdate(camera);
102
+ this.synchronizer.onLocalCameraUpdate(Object.assign(camera, { id: this.context.uid }));
109
103
  const stage = this.context.stageRect$.value;
110
104
  if (stage) {
111
105
  const size = { width: stage.width, height: stage.height, id: this.context.uid };
package/src/index.ts CHANGED
@@ -130,6 +130,8 @@ export type MountParams = {
130
130
  container?: HTMLElement;
131
131
  /** 白板高宽比例, 默认为 9 / 16 */
132
132
  containerSizeRatio?: number;
133
+ /** @deprecated */
134
+ chessboard?: boolean;
133
135
  /** 是否高亮显示同步区域, 默认为 true */
134
136
  highlightStage?: boolean;
135
137
  collectorContainer?: HTMLElement;
@@ -923,6 +925,24 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
923
925
  emitter.emit("containerSizeRatioUpdate", ratio);
924
926
  }
925
927
 
928
+ public createPPTHandler() {
929
+ return {
930
+ onPageJumpTo: (_pptUUID: string, index: number) => {
931
+ this.appManager?.focusApp?.appContext?.whiteBoardView?.jumpPage(index);
932
+ },
933
+ onPageToNext: () => {
934
+ if (this.focused) {
935
+ this.appManager?.focusApp?.appContext?.whiteBoardView?.nextPage();
936
+ }
937
+ },
938
+ onPageToPrev: () => {
939
+ if (this.focused) {
940
+ this.appManager?.focusApp?.appContext?.whiteBoardView?.prevPage();
941
+ }
942
+ }
943
+ }
944
+ }
945
+
926
946
  private isDynamicPPT(scenes: SceneDefinition[]) {
927
947
  const sceneSrc = scenes[0]?.ppt?.src;
928
948
  return sceneSrc?.startsWith("pptx://");