@netless/window-manager 1.0.0-canary.12 → 1.0.0-canary.15

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.0-canary.12",
3
+ "version": "1.0.0-canary.15",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
@@ -23,13 +23,13 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@juggle/resize-observer": "^3.3.1",
26
- "@netless/telebox-insider": "1.0.0-alpha.15",
26
+ "@netless/telebox-insider": "1.0.0-alpha.17",
27
27
  "emittery": "^0.9.2",
28
28
  "lodash": "^4.17.21",
29
29
  "p-retry": "^4.6.1",
30
30
  "side-effect-manager": "^1.1.0",
31
31
  "uuid": "^7.0.3",
32
- "value-enhancer": "^1.2.1",
32
+ "value-enhancer": "^1.3.0",
33
33
  "video.js": ">=7"
34
34
  },
35
35
  "devDependencies": {
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.14
7
+ '@netless/telebox-insider': 1.0.0-alpha.17
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
@@ -35,7 +35,7 @@ specifiers:
35
35
  svelte: ^3.42.4
36
36
  typescript: ^4.5.5
37
37
  uuid: ^7.0.3
38
- value-enhancer: ^1.2.1
38
+ value-enhancer: ^1.3.0
39
39
  video.js: '>=7'
40
40
  vite: ^2.5.3
41
41
  vitest: ^0.14.1
@@ -43,13 +43,13 @@ 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.14
46
+ '@netless/telebox-insider': 1.0.0-alpha.17
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
50
50
  side-effect-manager: 1.1.0
51
51
  uuid: registry.npmmirror.com/uuid/7.0.3
52
- value-enhancer: 1.2.1
52
+ value-enhancer: 1.3.0
53
53
  video.js: registry.npmmirror.com/video.js/7.18.1
54
54
 
55
55
  devDependencies:
@@ -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.14:
101
- resolution: {integrity: sha512-kDhoxnEZUOCjQDf/lDgHVBb/TaKywlnUXhSlSbyVDWefcVXcaXi6/zEPwDR0gMYWCqQQoEPFz9Jr8hd8hcEkyQ==}
100
+ /@netless/telebox-insider/1.0.0-alpha.17:
101
+ resolution: {integrity: sha512-FoiX5tKKT26EyDiO/gT4P7rhr9Pvkcf2RJuSPxt5PO0ij73vUaU6OwjXJzZkcnIZlHPHhleJoqt1difaJpmyLQ==}
102
102
  dependencies:
103
103
  '@juggle/resize-observer': 3.3.1
104
104
  '@types/shallowequal': 1.1.1
@@ -1002,10 +1002,6 @@ packages:
1002
1002
  engines: {node: '>= 4.0.0'}
1003
1003
  dev: true
1004
1004
 
1005
- /value-enhancer/1.2.1:
1006
- resolution: {integrity: sha512-11IrGi9xmVbr3twzuaMRrdUGzhdaE4eXvT6qYZlB5VrhK5uQzSPlYOEBlsIGH+dMvkakNkWGNIbxdZi87/MWuQ==}
1007
- dev: false
1008
-
1009
1005
  /value-enhancer/1.3.0:
1010
1006
  resolution: {integrity: sha512-shI9N5ML4MGwD6bMu/My1l1+REFqhZGOuIjDN5Gf+k7gACfY2k8WtJEcqgdZMfepwivfhQxIfZp0riobUDZpDQ==}
1011
1007
  dev: false
@@ -110,6 +110,12 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
110
110
  this.ensurePageSize(size);
111
111
  }
112
112
  this.whiteBoardView = new WhiteBoardView(view, this, this.appProxy, removeViewWrapper, this.ensurePageSize);
113
+ this.appProxy.sideEffectManager.add(() => {
114
+ return () => {
115
+ this.whiteBoardView?.destroy();
116
+ this.whiteBoardView = undefined;
117
+ }
118
+ });
113
119
  return this.whiteBoardView;
114
120
  }
115
121
 
@@ -58,10 +58,10 @@ export class AppProxy implements PageRemoveService {
58
58
  private stateKey: string;
59
59
  public _pageState: AppPageStateImpl;
60
60
 
61
- public appResult?: NetlessApp<any>;
62
- public appContext?: AppContext<any, any>;
61
+ public appResult?: NetlessApp;
62
+ public appContext?: AppContext;
63
63
 
64
- private sideEffectManager = new SideEffectManager();
64
+ public sideEffectManager = new SideEffectManager();
65
65
  private valManager = new ValManager();
66
66
 
67
67
  private fullPath$ = this.valManager.attach(new Val<string | undefined>(undefined));
@@ -563,6 +563,7 @@ export class AppProxy implements PageRemoveService {
563
563
  const fullPath = this._pageState.getFullPath(index);
564
564
  if (fullPath) {
565
565
  this.setFullPath(fullPath);
566
+ setScenePath(this.manager.room, fullPath);
566
567
  }
567
568
  }
568
569
  }
@@ -584,12 +585,13 @@ export class AppProxy implements PageRemoveService {
584
585
  this.size$.setValue(iSize);
585
586
  }
586
587
 
587
- public moveCamera = (camera: Camera) => {
588
+ public moveCamera = (camera: Partial<Camera>) => {
588
589
  if (!this.camera$.value) {
589
590
  return;
590
591
  }
591
- const nextCamera = { ...this.camera$.value, ...camera };
592
+ const nextCamera = { ...this.camera$.value, ...camera, id: this.uid };
592
593
  this.storeCamera(nextCamera);
594
+ this.camera$.setValue(nextCamera);
593
595
  };
594
596
 
595
597
  public async destroy(
@@ -664,6 +666,10 @@ export class AppProxy implements PageRemoveService {
664
666
  , "size");
665
667
  }
666
668
 
669
+ public onFocus = () => {
670
+ this.setScenePath();
671
+ }
672
+
667
673
  public close(): Promise<void> {
668
674
  return this.destroy(true, true, false);
669
675
  }
@@ -1,5 +1,6 @@
1
1
  import { putScenes } from "../Utils/Common";
2
2
  import { Val } from "value-enhancer";
3
+ import { pick } from "lodash";
3
4
 
4
5
  import type { ReadonlyVal } from "value-enhancer";
5
6
  import type { AddPageParams, PageController, PageState } from "../Page";
@@ -8,8 +9,11 @@ import type { AppContext } from "./AppContext";
8
9
  import type { Camera, View } from "white-web-sdk";
9
10
  import type { TeleBoxRect } from "@netless/telebox-insider";
10
11
 
12
+ export type WhiteBoardViewCamera = Omit<Camera, "scale">;
13
+
11
14
  export class WhiteBoardView implements PageController {
12
15
  public readonly pageState$: ReadonlyVal<PageState>;
16
+ public readonly camera$: ReadonlyVal<WhiteBoardViewCamera>;
13
17
 
14
18
  constructor(
15
19
  public view: View,
@@ -20,16 +24,30 @@ export class WhiteBoardView implements PageController {
20
24
  ) {
21
25
  const pageState$ = new Val<PageState>(appProxy.pageState);
22
26
  this.pageState$ = pageState$;
23
- appProxy.appEmitter.on("pageStateChange", pageState => {
24
- pageState$.setValue(pageState);
25
- });
27
+ this.appProxy.sideEffectManager.add(() =>
28
+ appProxy.appEmitter.on("pageStateChange", pageState => {
29
+ pageState$.setValue(pageState);
30
+ })
31
+ );
32
+ const camera$ = new Val<WhiteBoardViewCamera>(
33
+ pick(this.view.camera, ["centerX", "centerY"])
34
+ );
35
+ this.camera$ = camera$;
36
+ this.appProxy.sideEffectManager.add(() =>
37
+ appProxy.camera$.subscribe(camera => {
38
+ if (camera) {
39
+ camera$.setValue(pick(camera, ["centerX", "centerY"]));
40
+ }
41
+ })
42
+ );
43
+ view.disableCameraTransform = true;
26
44
  }
27
45
 
28
46
  public get pageState() {
29
47
  return this.pageState$.value;
30
48
  }
31
49
 
32
- public moveCamera(camera: Camera) {
50
+ public moveCamera(camera: Partial<WhiteBoardViewCamera>) {
33
51
  this.appProxy.moveCamera(camera);
34
52
  }
35
53
 
@@ -84,6 +102,7 @@ export class WhiteBoardView implements PageController {
84
102
 
85
103
  public destroy() {
86
104
  this.pageState$.destroy();
105
+ this.camera$.destroy();
87
106
  this.removeViewWrapper();
88
107
  }
89
108
  }
package/src/AppManager.ts CHANGED
@@ -138,7 +138,7 @@ export class AppManager {
138
138
  sceneName = this.callbacksNode?.scenes[nextIndex];
139
139
  }
140
140
  if (sceneName) {
141
- this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
141
+ await this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
142
142
  }
143
143
  await this.setMainViewSceneIndex(nextIndex);
144
144
  } else {
@@ -153,7 +153,7 @@ export class AppManager {
153
153
  * 所以需要关掉所有开启了 view 的 app
154
154
  */
155
155
  public async onRootDirRemoved(needClose = true) {
156
- this.setMainViewScenePath(INIT_DIR);
156
+ await this.setMainViewScenePath(INIT_DIR);
157
157
  this.createRootDirScenesCallback();
158
158
 
159
159
  for (const [id, appProxy] of this.appProxies.entries()) {
@@ -161,9 +161,9 @@ export class AppManager {
161
161
  await this.closeApp(id, needClose);
162
162
  }
163
163
  }
164
- // 删除了根目录的 scenes 之后 mainview 需要重新绑定, 否则主白板会不能渲染
164
+ // 删除了根目录的 scenes 之后 main-view 需要重新绑定, 否则主白板会不能渲染
165
165
  this.mainViewProxy.rebind();
166
- emitter.emit("rootDirRemoved");
166
+ await emitter.emit("rootDirRemoved");
167
167
  this.updateRootDirRemoving(false);
168
168
  }
169
169
 
@@ -448,6 +448,7 @@ export class AppManager {
448
448
  setTimeout(() => {
449
449
  const appProxy = this.appProxies.get(focused);
450
450
  if (appProxy) {
451
+ appProxy.onFocus();
451
452
  appRegister.notifyApp(appProxy.kind, "focus", { appId: focused });
452
453
  }
453
454
  }, 0);
@@ -461,9 +462,9 @@ export class AppManager {
461
462
  );
462
463
 
463
464
  /**
464
- * 插件更新 attributes 时的回调
465
+ * 插件更新 apps 时的回调
465
466
  *
466
- * @param {*} attributes
467
+ * @param {*} apps
467
468
  * @memberof WindowManager
468
469
  */
469
470
  public async _attributesUpdateCallback(apps: any) {
@@ -657,6 +658,7 @@ export class AppManager {
657
658
  if (sceneState) {
658
659
  const scenePath = sceneState.scenePath;
659
660
  this.appProxies.forEach(appProxy => {
661
+ console.log("scenePath", scenePath, appProxy.scenePath);
660
662
  if (appProxy.scenePath && scenePath.startsWith(appProxy.scenePath)) {
661
663
  appProxy.emitAppSceneStateChange(sceneState);
662
664
  appProxy.setFullPath(scenePath);
@@ -678,7 +680,7 @@ export class AppManager {
678
680
  public displayerWritableListener = (isReadonly: boolean) => {
679
681
  const isWritable = !isReadonly;
680
682
  const isManualWritable =
681
- this.windowManger.readonly === undefined || this.windowManger.readonly === false;
683
+ this.windowManger.readonly === undefined || !this.windowManger.readonly;
682
684
  if (this.windowManger.readonly === undefined) {
683
685
  this.boxManager?.setReadonly(isReadonly);
684
686
  } else {
@@ -687,7 +689,7 @@ export class AppManager {
687
689
  this.appProxies.forEach(appProxy => {
688
690
  appProxy.emitAppIsWritableChange();
689
691
  });
690
- if (isWritable === true) {
692
+ if (isWritable) {
691
693
  if (this.room && this.room.disableSerialization === true) {
692
694
  this.room.disableSerialization = false;
693
695
  }
package/src/BoxManager.ts CHANGED
@@ -80,7 +80,7 @@ export const createBoxManager = (
80
80
  setAppFocus: (appId: string) => manager.appManager?.store.setAppFocus(appId, true),
81
81
  callbacks,
82
82
  emitter,
83
- boxEmitter
83
+ boxEmitter,
84
84
  },
85
85
  options
86
86
  );
@@ -99,17 +99,17 @@ export class BoxManager {
99
99
  this.teleBoxManager = this.setupBoxManager(createTeleBoxManagerConfig);
100
100
  this.sideEffectManager.add(() => [
101
101
  // 使用 _xxx$.reaction 订阅修改的值, 不管有没有 skipUpdate, 修改值都会触发回调
102
- this.teleBoxManager._state$.reaction(state => {
102
+ this.teleBoxManager.onValChanged("state", state => {
103
103
  callbacks.emit("boxStateChange", state);
104
104
  emitter.emit("boxStateChange", state);
105
105
  }),
106
- this.teleBoxManager._darkMode$.reaction(darkMode => {
106
+ this.teleBoxManager.onValChanged("darkMode", darkMode => {
107
107
  callbacks.emit("darkModeChange", darkMode);
108
108
  }),
109
- this.teleBoxManager._prefersColorScheme$.reaction(colorScheme => {
109
+ this.teleBoxManager.onValChanged("prefersColorScheme", colorScheme => {
110
110
  callbacks.emit("prefersColorSchemeChange", colorScheme);
111
111
  }),
112
- this.teleBoxManager._minimized$.reaction((minimized, skipUpdate) => {
112
+ this.teleBoxManager.onValChanged("minimized", (minimized, skipUpdate) => {
113
113
  if (skipUpdate) {
114
114
  return;
115
115
  }
@@ -125,7 +125,7 @@ export class BoxManager {
125
125
  }
126
126
  }
127
127
  }),
128
- this.teleBoxManager._maximized$.reaction((maximized, skipUpdate) => {
128
+ this.teleBoxManager.onValChanged("maximized", (maximized, skipUpdate) => {
129
129
  if (skipUpdate) {
130
130
  return;
131
131
  }
@@ -139,7 +139,11 @@ export class BoxManager {
139
139
  this.teleBoxManager.events.on(
140
140
  "intrinsic_move",
141
141
  debounce((box: ReadonlyTeleBox): void => {
142
- boxEmitter.emit("move", { appId: box.id, x: box.intrinsicX, y: box.intrinsicY });
142
+ boxEmitter.emit("move", {
143
+ appId: box.id,
144
+ x: box.intrinsicX,
145
+ y: box.intrinsicY,
146
+ });
143
147
  }, 50)
144
148
  ),
145
149
  this.teleBoxManager.events.on(
package/src/PageState.ts CHANGED
@@ -6,7 +6,7 @@ import type { PageState } from "./Page";
6
6
  export class PageStateImpl {
7
7
  constructor(private manager: AppManager) {
8
8
  emitter.on("changePageState", () => {
9
- callbacks.emit("pageStateChange", this.toObject());
9
+ callbacks.emit("pageStateChange", this.toObject());
10
10
  });
11
11
  }
12
12
 
@@ -19,7 +19,7 @@ export class CameraSynchronizer {
19
19
  if (this.remoteCamera && this.remoteSize) {
20
20
  this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
21
21
  }
22
- }, 50);
22
+ }, 10);
23
23
 
24
24
  public setView(view: View) {
25
25
  this.view = view;
@@ -46,10 +46,11 @@ export class CameraSynchronizer {
46
46
  animationMode: AnimationMode.Immediately,
47
47
  });
48
48
  }
49
+ moveCamera();
49
50
  // TODO 直接调用 moveCamera 依然会出现 camera 错误的情况,这里暂时加一个 delay 保证 camera 是对的, 后续需要 SDK 进行修改
50
51
  delay(moveCamera, 50);
51
52
  }
52
- }, 50);
53
+ }, 10);
53
54
 
54
55
  public onRemoteSizeUpdate(size: ISize) {
55
56
  if (this.rect) {
package/src/index.ts CHANGED
@@ -906,7 +906,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
906
906
  if (WindowManager.container) {
907
907
  this.bindContainer(WindowManager.container);
908
908
  }
909
- this.appManager?.refresher?.refresh();
909
+ this.appManager?.refresher.refresh();
910
910
  }
911
911
 
912
912
  public setContainerSizeRatio(ratio: number) {