@netless/window-manager 1.0.0-canary.5 → 1.0.0-canary.8

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.5",
3
+ "version": "1.0.0-canary.8",
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.13",
26
+ "@netless/telebox-insider": "1.0.0-alpha.14",
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.13
7
+ '@netless/telebox-insider': 1.0.0-alpha.14
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.13
46
+ '@netless/telebox-insider': 1.0.0-alpha.14
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.13:
101
- resolution: {integrity: sha512-7hSnqOCXfvn0DECjYJPfiBfdtnoIBFvpniGvIBsXUVmRuLaQdzjMnLkXyGbfSF2yq//73lSJQDzaVxAf+icXEw==}
100
+ /@netless/telebox-insider/1.0.0-alpha.14:
101
+ resolution: {integrity: sha512-kDhoxnEZUOCjQDf/lDgHVBb/TaKywlnUXhSlSbyVDWefcVXcaXi6/zEPwDR0gMYWCqQQoEPFz9Jr8hd8hcEkyQ==}
102
102
  dependencies:
103
103
  '@juggle/resize-observer': 3.3.1
104
104
  '@types/shallowequal': 1.1.1
@@ -29,7 +29,6 @@ import type {
29
29
  import { WhiteBoardView } from "./WhiteboardView";
30
30
  import { findMemberByUid } from "../Helper";
31
31
  import { MAX_PAGE_SIZE } from "../constants";
32
- import { putScenes } from "../Utils/Common";
33
32
  import { isNumber } from "lodash";
34
33
 
35
34
  export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOptions = any> {
@@ -50,6 +49,7 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
50
49
  public readonly isAddApp: boolean;
51
50
  public readonly isReplay = this.manager.isReplay;
52
51
  private whiteBoardView?: WhiteBoardView;
52
+ public _viewWrapper?: HTMLElement;
53
53
 
54
54
  constructor(
55
55
  private manager: AppManager,
@@ -62,9 +62,13 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
62
62
  this.isAddApp = appProxy.isAddApp;
63
63
  }
64
64
 
65
- public get displayer(){
65
+ public get displayer() {
66
66
  return this.manager.displayer;
67
- };
67
+ }
68
+
69
+ public get destroyed() {
70
+ return this.appProxy.status === "destroyed";
71
+ }
68
72
 
69
73
  /** @deprecated Use context.storage.state instead. */
70
74
  public getAttributes = (): TAttributes | undefined => {
@@ -93,20 +97,22 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
93
97
  view = this.appProxy.createAppDir();
94
98
  }
95
99
  const viewWrapper = document.createElement("div");
100
+ this._viewWrapper = viewWrapper;
96
101
  viewWrapper.className = "window-manager-view-wrapper";
97
102
  this.box.$content.parentElement?.appendChild(viewWrapper);
98
103
  const removeViewWrapper = () => {
99
104
  this.box.$content.parentElement?.removeChild(viewWrapper);
105
+ this._viewWrapper = undefined;
100
106
  }
101
107
  view.divElement = viewWrapper;
102
108
  if (this.isAddApp) {
103
- this.initPageSize(size);
109
+ this.ensurePageSize(size);
104
110
  }
105
- this.whiteBoardView = new WhiteBoardView(this, this.appProxy, removeViewWrapper);
111
+ this.whiteBoardView = new WhiteBoardView(view, this, this.appProxy, removeViewWrapper, this.ensurePageSize);
106
112
  return this.whiteBoardView;
107
113
  }
108
114
 
109
- private initPageSize = (size?: number) => {
115
+ private ensurePageSize = (size?: number) => {
110
116
  if (!isNumber(size)) return;
111
117
  if (!this.appProxy.scenePath) return;
112
118
  if (this.appProxy.pageState.length >= size) return;
@@ -114,11 +120,8 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
114
120
  throw Error(`[WindowManager]: size ${size} muse be in range [1, ${MAX_PAGE_SIZE}]`);
115
121
  }
116
122
  const needInsert = size - this.appProxy.pageState.length;
117
- const startPageNumber = this.appProxy.pageState.length;
118
- const scenes = new Array(needInsert).fill({}).map((_, index) => {
119
- return { name: `${startPageNumber + index + 1}` };
120
- });
121
- putScenes(this.room, this.appProxy.scenePath, scenes);
123
+ const scenes = new Array(needInsert).fill({});
124
+ this.room?.putScenes(this.appProxy.scenePath, scenes);
122
125
  }
123
126
 
124
127
  public getInitScenePath = () => {
@@ -54,7 +54,7 @@ export class AppProxy implements PageRemoveService {
54
54
  public uid = this.manager.uid;
55
55
 
56
56
  public isAddApp: boolean;
57
- private status: "normal" | "destroyed" = "normal";
57
+ public status: "normal" | "destroyed" = "normal";
58
58
  private stateKey: string;
59
59
  public _pageState: AppPageStateImpl;
60
60
  private _prevFullPath: string | undefined;
@@ -136,11 +136,37 @@ export class AppProxy implements PageRemoveService {
136
136
  });
137
137
  combine([this.box$, this.view$]).subscribe(([box, view]) => {
138
138
  if (box && view) {
139
- const appViewSync = new AppViewSync(this);
140
- this.appViewSync = appViewSync;
141
- this.sideEffectManager.add(() => () => appViewSync.destroy());
139
+ if (!this.camera$.value) {
140
+ this.storeCamera({
141
+ centerX: 0, centerY: 0, scale: 1, id: this.uid,
142
+ });
143
+ this.camera$.setValue(toJS(this.appAttributes.camera));
144
+ }
145
+ if (!this.size$.value && box.contentStageRect) {
146
+ this.storeSize({
147
+ id: this.uid,
148
+ width: box.contentStageRect?.width,
149
+ height: box.contentStageRect?.height,
150
+ });
151
+ this.size$.setValue(toJS(this.appAttributes.size));
152
+ }
153
+ this.appViewSync = new AppViewSync(this);
154
+ this.sideEffectManager.add(() => () => this.appViewSync?.destroy());
142
155
  }
143
156
  });
157
+ this.sideEffectManager.add(() => emitter.on("memberStateChange", memberState => {
158
+ // clicker 教具把事件穿透给下层
159
+ const needPointerEventsNone = memberState.currentApplianceName === "clicker";
160
+ if (needPointerEventsNone) {
161
+ if (this.appContext?._viewWrapper) {
162
+ this.appContext._viewWrapper.style.pointerEvents = "none";
163
+ }
164
+ } else {
165
+ if (this.appContext?._viewWrapper) {
166
+ this.appContext._viewWrapper.style.pointerEvents = "auto";
167
+ }
168
+ }
169
+ }));
144
170
  }
145
171
 
146
172
  public createAppDir() {
@@ -3,6 +3,7 @@ import { SideEffectManager } from "side-effect-manager";
3
3
  import type { Camera, View } from "white-web-sdk";
4
4
  import type { AppProxy } from "./AppProxy";
5
5
  import { isEqual } from "lodash";
6
+ import { combine } from "value-enhancer";
6
7
 
7
8
  export class AppViewSync {
8
9
  private sem = new SideEffectManager();
@@ -32,14 +33,12 @@ export class AppViewSync {
32
33
  }
33
34
  }),
34
35
  );
35
- if (!this.appProxy.size$.value) {
36
- this.appProxy.storeSize({
37
- id: this.appProxy.uid,
38
- width: box.contentStageRect.width,
39
- height: box.contentStageRect.height,
40
- });
41
- }
42
36
  }
37
+ this.sem.add(() => combine([this.appProxy.camera$, this.appProxy.size$]).subscribe(([camera, size]) => {
38
+ if (camera && size) {
39
+ this.synchronizer.onRemoteUpdate(camera, size);
40
+ }
41
+ }));
43
42
  }
44
43
 
45
44
  public bindView = (view?: View) => {
@@ -5,15 +5,17 @@ import type { ReadonlyVal } from "value-enhancer";
5
5
  import type { AddPageParams, PageController, PageState } from "../Page";
6
6
  import type { AppProxy } from "./AppProxy";
7
7
  import type { AppContext } from "./AppContext";
8
- import type { Camera } from "white-web-sdk";
8
+ import type { Camera, View } from "white-web-sdk";
9
9
 
10
10
  export class WhiteBoardView implements PageController {
11
11
  public readonly pageState$: ReadonlyVal<PageState>;
12
12
 
13
13
  constructor(
14
+ public view: View,
14
15
  protected appContext: AppContext,
15
16
  protected appProxy: AppProxy,
16
- private removeViewWrapper: () => void
17
+ private removeViewWrapper: () => void,
18
+ public ensureSize: (size: number) => void
17
19
  ) {
18
20
  const pageState$ = new Val<PageState>(appProxy.pageState);
19
21
  this.pageState$ = pageState$;
@@ -22,10 +24,6 @@ export class WhiteBoardView implements PageController {
22
24
  });
23
25
  }
24
26
 
25
- public get view() {
26
- return this.appContext.view;
27
- }
28
-
29
27
  public get pageState() {
30
28
  return this.pageState$.value;
31
29
  }
package/src/AppManager.ts CHANGED
@@ -3,7 +3,7 @@ import { AppCreateQueue } from "./Utils/AppCreateQueue";
3
3
  import { AppListeners } from "./AppListener";
4
4
  import { AppProxy } from "./App";
5
5
  import { appRegister } from "./Register";
6
- import { autorun, isPlayer, isRoom, ScenePathType } from "white-web-sdk";
6
+ import { autorun, isPlayer, isRoom, ScenePathType, toJS } from "white-web-sdk";
7
7
  import { boxEmitter } from "./BoxEmitter";
8
8
  import { calculateNextIndex } from "./Page";
9
9
  import { callbacks } from "./callback";
@@ -34,10 +34,10 @@ import type { ReconnectRefresher } from "./ReconnectRefresher";
34
34
  import type { BoxManager } from "./BoxManager";
35
35
  import type {
36
36
  Displayer,
37
- DisplayerState,
38
37
  Room,
39
38
  ScenesCallbacksNode,
40
39
  SceneState,
40
+ RoomState,
41
41
  } from "white-web-sdk";
42
42
  import type { AddAppParams, BaseInsertParams, TeleBoxRect } from "./index";
43
43
  import type {
@@ -651,7 +651,7 @@ export class AppManager {
651
651
  }
652
652
  }
653
653
 
654
- private displayerStateListener = (state: Partial<DisplayerState>) => {
654
+ private displayerStateListener = (state: Partial<RoomState>) => {
655
655
  const sceneState = state.sceneState;
656
656
  if (sceneState) {
657
657
  const scenePath = sceneState.scenePath;
@@ -669,6 +669,9 @@ export class AppManager {
669
669
  emitter.emit("roomMembersChange", this.members);
670
670
  }
671
671
  emitter.emit("observerIdChange", this.displayer.observerId);
672
+ if (state.memberState) {
673
+ emitter.emit("memberStateChange", toJS(state.memberState));
674
+ }
672
675
  };
673
676
 
674
677
  public displayerWritableListener = (isReadonly: boolean) => {
@@ -2,6 +2,7 @@ import Emittery from "emittery";
2
2
  import type { TeleBoxRect } from "@netless/telebox-insider";
3
3
  import type { AppInitState, CursorMovePayload } from "./index";
4
4
  import type { Member } from "./Helper";
5
+ import type { MemberState } from "white-web-sdk";
5
6
 
6
7
  export type RemoveSceneParams = {
7
8
  scenePath: string;
@@ -31,6 +32,7 @@ export type EmitterEvent = {
31
32
  writableChange: boolean;
32
33
  containerSizeRatioUpdate: number;
33
34
  roomMembersChange: Member[];
35
+ memberStateChange: MemberState;
34
36
  };
35
37
 
36
38
  export type EmitterType = Emittery<EmitterEvent>;
@@ -7,8 +7,8 @@ import type { ISize } from "../AttributesDelegate";
7
7
  export type SaveCamera = (camera: Camera) => void;
8
8
 
9
9
  export class CameraSynchronizer {
10
- protected remoteCamera?: Camera;
11
- protected remoteSize?: ISize;
10
+ public remoteCamera?: Camera;
11
+ public remoteSize?: ISize;
12
12
  protected rect?: TeleBoxRect;
13
13
  protected view?: View;
14
14