@netless/window-manager 0.3.0-canary.2 → 0.3.2-canary.0

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": "0.3.0-canary.2",
3
+ "version": "0.3.2-canary.0",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",
@@ -24,7 +24,7 @@
24
24
  "@juggle/resize-observer": "^3.3.1",
25
25
  "@netless/app-docs-viewer": "^0.1.21",
26
26
  "@netless/app-media-player": "0.1.0-beta.5",
27
- "@netless/telebox-insider": "0.2.3",
27
+ "@netless/telebox-insider": "0.2.4",
28
28
  "emittery": "^0.9.2",
29
29
  "lodash": "^4.17.21",
30
30
  "p-retry": "^4.6.1",
package/src/AppContext.ts CHANGED
@@ -102,13 +102,8 @@ export class AppContext<TAttrs extends Record<string, any>, AppOptions = any> {
102
102
 
103
103
  public async setScenePath(scenePath: string): Promise<void> {
104
104
  if (!this.appProxy.box) return;
105
- if (this.appProxy.box.focus) {
106
- setScenePath(this.getRoom(), scenePath);
107
- } else {
108
- this.emitter.emit("focus", true);
109
- await wait(50);
110
- setScenePath(this.getRoom(), scenePath);
111
- }
105
+ this.appProxy.setFullPath(scenePath);
106
+ this.manager.viewManager.switchAppToWriter(this.appId);
112
107
  }
113
108
 
114
109
  public mountView(dom: HTMLDivElement): void {
@@ -30,10 +30,6 @@ export class AppListeners {
30
30
  this.appResizeHandler(data.payload);
31
31
  break;
32
32
  }
33
- case Events.AppBlur: {
34
- this.appBlurHandler(data.payload);
35
- break;
36
- }
37
33
  case Events.AppBoxStateChange: {
38
34
  this.appBoxStateHandler(data.payload);
39
35
  break;
@@ -57,21 +53,10 @@ export class AppListeners {
57
53
  this.manager.room?.refreshViewSize();
58
54
  };
59
55
 
60
- private appBlurHandler = (payload: any) => {
61
- const proxy = this.appProxies.get(payload.appId);
62
- if (proxy) {
63
- proxy.appEmitter.emit("writableChange", false);
64
- if (proxy.view?.mode === ViewVisionMode.Writable) {
65
- this.manager.viewManager.refreshViews();
66
- }
67
- }
68
- };
69
-
70
56
  private appBoxStateHandler = (payload: any) => {
71
57
  this.boxManager.setBoxState(payload.state);
72
58
  };
73
59
 
74
-
75
60
  private switchViewsToFreedomHandler = () => {
76
61
  this.manager.viewManager.freedomAllViews();
77
62
  };
package/src/AppManager.ts CHANGED
@@ -80,16 +80,20 @@ export class AppManager {
80
80
  this.refresher?.add("maximized", () => {
81
81
  return autorun(
82
82
  () => {
83
- const maximized = this.attributes.maximized
84
- this.boxManager.teleBoxManager.setMaximized(Boolean(maximized), true);
83
+ const maximized = this.attributes.maximized;
84
+ if (this.boxManager.teleBoxManager.maximized !== maximized) {
85
+ this.boxManager.teleBoxManager.setMaximized(Boolean(maximized), true);
86
+ }
85
87
  }
86
88
  )
87
89
  });
88
90
  this.refresher?.add("minimized", () => {
89
91
  return autorun(
90
92
  () => {
91
- const minimized = this.attributes.minimized
92
- this.boxManager.teleBoxManager.setMinimized(Boolean(minimized), true);
93
+ const minimized = this.attributes.minimized;
94
+ if (this.boxManager.teleBoxManager.minimized !== minimized) {
95
+ this.boxManager.teleBoxManager.setMinimized(Boolean(minimized), true);
96
+ }
93
97
  }
94
98
  )
95
99
  });
@@ -98,7 +102,7 @@ export class AppManager {
98
102
  if (!mainScenePath) return;
99
103
  const sceneState = this.displayer.state.sceneState;
100
104
  if (sceneState.scenePath !== mainScenePath) {
101
- this.room?.setScenePath(mainScenePath);
105
+ setScenePath(this.room, mainScenePath);
102
106
  }
103
107
  }
104
108
  this.displayerWritableListener(!this.room?.isWritable);
@@ -459,6 +463,7 @@ export class AppManager {
459
463
  });
460
464
  }
461
465
  this.viewManager.destroy();
466
+ this.boxManager.destroy();
462
467
  this.refresher?.destroy();
463
468
  this.mainViewProxy.destroy();
464
469
  callbacks.clearListeners();
@@ -52,6 +52,10 @@ export class AttributesDelegate {
52
52
  return get(this.apps(), [id, Fields.State]);
53
53
  }
54
54
 
55
+ public getMaximized() {
56
+ return get(this.manager.attributes, ["maximized"])
57
+ }
58
+
55
59
  public setupAppAttributes(params: AddAppParams, id: string, isDynamicPPT: boolean) {
56
60
  const attributes = this.manager.attributes;
57
61
  if (!attributes.apps) {
package/src/BoxManager.ts CHANGED
@@ -216,7 +216,8 @@ export class BoxManager {
216
216
  if (state.maximized != null) {
217
217
  this.teleBoxManager.setMaximized(Boolean(state.maximized), true);
218
218
  this.teleBoxManager.setMinimized(Boolean(state.minimized), true);
219
- } else if (state.boxState) {
219
+ }
220
+ if (state.boxState) {
220
221
  this.teleBoxManager.setState(state.boxState, true);
221
222
  }
222
223
  setTimeout(() => {
@@ -224,6 +225,7 @@ export class BoxManager {
224
225
  this.teleBoxManager.update(box.id, { focus: true }, true);
225
226
  }
226
227
  }, 50);
228
+ callbacks.emit("boxStateChange", this.teleBoxManager.state);
227
229
  }
228
230
  }
229
231
 
@@ -283,4 +285,8 @@ export class BoxManager {
283
285
  this.teleBoxManager.setState(state, true);
284
286
  callbacks.emit("boxStateChange", state);
285
287
  }
288
+
289
+ public destroy() {
290
+ this.teleBoxManager.destroy();
291
+ }
286
292
  }
@@ -38,9 +38,6 @@ export class Cursor extends Base {
38
38
  if (!this.cursorPosition) {
39
39
  throw new Error();
40
40
  }
41
- if (this.memberId === this.context.uid) {
42
- return;
43
- }
44
41
  this.startReaction();
45
42
  }, { retries: 3 });
46
43
  this.autoHidden();
@@ -145,6 +142,7 @@ export class Cursor extends Base {
145
142
  }
146
143
  this.timer = window.setTimeout(() => {
147
144
  this.hide();
145
+ this.store.updateCursorState(this.context.uid, CursorState.Leave);
148
146
  }, 1000 * 10); // 10 秒钟自动隐藏
149
147
  }
150
148
 
@@ -22,7 +22,6 @@ export type MoveCursorParams = {
22
22
  export class CursorManager extends Base {
23
23
  public containerRect?: DOMRect;
24
24
  public wrapperRect?: DOMRect;
25
- private disposer: any;
26
25
  public cursorInstances: Map<string, Cursor> = new Map();
27
26
  public roomMembers?: readonly RoomMember[];
28
27
  private mainViewElement?: HTMLDivElement;
@@ -48,20 +47,25 @@ export class CursorManager extends Base {
48
47
  }
49
48
 
50
49
  private startReaction(wrapper: HTMLElement) {
51
- this.disposer = onObjectInserted(this.cursors, () => {
52
- this.handleRoomMembersChange(wrapper);
53
- });
50
+ this.manager.refresher?.add("cursors", () => {
51
+ return onObjectInserted(this.cursors, () => {
52
+ this.handleRoomMembersChange(wrapper);
53
+ });
54
+ })
54
55
  }
55
56
 
56
- private handleRoomMembersChange(wrapper: HTMLElement) {
57
+ private handleRoomMembersChange = debounce((wrapper: HTMLElement) => {
57
58
  const uids = this.roomMembers?.map(member => member.payload?.uid);
59
+ const cursors = Object.keys(this.cursors);
58
60
  if (uids?.length) {
59
- for (const uid in this.cursors) {
61
+ cursors.map(uid => {
60
62
  if (
61
63
  uids.includes(uid) &&
62
- !this.cursorInstances.has(uid) &&
63
- uid !== this.context.uid
64
+ !this.cursorInstances.has(uid)
64
65
  ) {
66
+ if (uid === this.context.uid) {
67
+ return;
68
+ }
65
69
  const component = new Cursor(
66
70
  this.appManager,
67
71
  this.cursors,
@@ -71,9 +75,9 @@ export class CursorManager extends Base {
71
75
  );
72
76
  this.cursorInstances.set(uid, component);
73
77
  }
74
- }
78
+ })
75
79
  }
76
- }
80
+ }, 100);
77
81
 
78
82
  public get cursors() {
79
83
  return this.manager.attributes?.[Fields.Cursors];
@@ -221,10 +225,10 @@ export class CursorManager extends Base {
221
225
  wrapper.removeEventListener("mouseleave", this.mouseLeaveListener);
222
226
  wrapper.removeEventListener("touchend", this.mouseLeaveListener);
223
227
  }
224
- this.disposer && this.disposer();
225
228
  if (this.cursorInstances.size) {
226
229
  this.cursorInstances.forEach(cursor => cursor.destroy());
227
230
  this.cursorInstances.clear();
228
231
  }
232
+ this.manager.refresher?.remove("cursors");
229
233
  }
230
234
  }
@@ -26,7 +26,7 @@ export const setScenePath = (room: Room | undefined, scenePath: string) => {
26
26
  room.setScenePath(scenePath);
27
27
  }
28
28
  }
29
- };
29
+ }
30
30
 
31
31
  export const setViewMode = (view: View, mode: ViewVisionMode) => {
32
32
  if (view.mode !== mode) {
package/src/index.ts CHANGED
@@ -20,9 +20,9 @@ import { log } from './Utils/log';
20
20
  import { replaceRoomFunction } from './Utils/RoomHacker';
21
21
  import { ResizeObserver as ResizeObserverPolyfill } from '@juggle/resize-observer';
22
22
  import { setupWrapper } from './ViewManager';
23
- import { TELE_BOX_STATE } from './BoxManager';
24
23
  import './style.css';
25
24
  import '@netless/telebox-insider/dist/style.css';
25
+ import type { TELE_BOX_STATE } from './BoxManager';
26
26
  import {
27
27
  AppCreateError,
28
28
  AppManagerNotInitError,
@@ -170,7 +170,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
170
170
  public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
171
171
  private static isCreated = false;
172
172
 
173
- public version = "0.3.0-canary.2";
173
+ public version = "0.3.2-canary.0";
174
174
 
175
175
  public appListeners?: AppListeners;
176
176
 
@@ -504,7 +504,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
504
504
 
505
505
  public get boxState(): TeleBoxState {
506
506
  if (this.appManager) {
507
- return this.appManager.store.getBoxState() || TELE_BOX_STATE.Normal;
507
+ return this.appManager.boxManager.teleBoxManager.state;
508
508
  } else {
509
509
  throw new AppManagerNotInitError();
510
510
  }
@@ -2,7 +2,6 @@ import { Base } from "./Base";
2
2
  import { callbacks, WindowManager } from "./index";
3
3
  import { reaction, ViewVisionMode } from "white-web-sdk";
4
4
  import { SET_SCENEPATH_DELAY } from "./constants";
5
- import { TELE_BOX_STATE } from "@netless/telebox-insider";
6
5
  import {
7
6
  notifyMainViewModeChange,
8
7
  setScenePath,
@@ -15,6 +14,7 @@ import type { AppManager } from "./AppManager";
15
14
  export class ViewManager extends Base {
16
15
  private views: Map<string, View> = new Map();
17
16
  private timer?: number;
17
+ private appTimer?: number;
18
18
 
19
19
  private mainViewProxy = this.manager.mainViewProxy;
20
20
  private displayer = this.manager.displayer;
@@ -133,13 +133,13 @@ export class ViewManager extends Base {
133
133
  public switchAppToWriter(id: string): void {
134
134
  this.freedomAllViews();
135
135
  // 为了同步端不闪烁, 需要给 room setScenePath 一个延迟
136
- setTimeout(() => {
136
+ if (this.appTimer) {
137
+ clearTimeout(this.appTimer);
138
+ }
139
+ this.appTimer = setTimeout(() => {
137
140
  const appProxy = this.manager.appProxies.get(id);
138
141
  if (appProxy) {
139
- const boxState = this.store.getBoxState();
140
- if (boxState && boxState === TELE_BOX_STATE.Minimized) {
141
- return;
142
- }
142
+ if (this.manager.boxManager.teleBoxManager.minimized) return;
143
143
  appProxy.setScenePath();
144
144
  appProxy.switchToWritable();
145
145
  appProxy.focusBox();