@netless/window-manager 0.3.0-canary.1 → 0.3.1

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/example/index.tsx CHANGED
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import ReactDom from "react-dom";
3
3
  import { PlayerPhase, WhiteWebSdk } from "white-web-sdk";
4
4
  import type { AppContext} from "../dist";
5
- import { BuiltinApps, WindowManager } from "../dist";
5
+ import { BuiltinApps, WindowManager } from "../dist/index.es";
6
6
  import "../dist/style.css";
7
7
  import "video.js/dist/video-js.css";
8
8
 
@@ -214,7 +214,7 @@ const replay = () => {
214
214
  sdk.replayRoom({
215
215
  room: process.env.ROOM_UUID,
216
216
  roomToken: process.env.ROOM_TOKEN,
217
- invisiblePlugins: [WindowManager],
217
+ invisiblePlugins: [WindowManager as any],
218
218
  useMultiViews: true,
219
219
  }).then(async player => {
220
220
  await anyWindow.manager.destroy();
@@ -240,7 +240,7 @@ const onRef = (ref) => {
240
240
  sdk.joinRoom({
241
241
  uuid: process.env.ROOM_UUID,
242
242
  roomToken: process.env.ROOM_TOKEN,
243
- invisiblePlugins: [WindowManager],
243
+ invisiblePlugins: [WindowManager as any],
244
244
  useMultiViews: true,
245
245
  userPayload: {
246
246
  userId: "111",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "0.3.0-canary.1",
3
+ "version": "0.3.1",
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",
@@ -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
@@ -12,6 +12,7 @@ import { callbacks, emitter } from './index';
12
12
  import { CameraStore } from './Utils/CameraStore';
13
13
  import { genAppId, makeValidScenePath, setScenePath } from './Utils/Common';
14
14
  import {
15
+ autorun,
15
16
  isPlayer,
16
17
  isRoom,
17
18
  ScenePathType,
@@ -76,12 +77,32 @@ export class AppManager {
76
77
  this.onAppDelete(this.attributes.apps);
77
78
  });
78
79
  });
80
+ this.refresher?.add("maximized", () => {
81
+ return autorun(
82
+ () => {
83
+ const maximized = this.attributes.maximized;
84
+ if (this.boxManager.teleBoxManager.maximized !== maximized) {
85
+ this.boxManager.teleBoxManager.setMaximized(Boolean(maximized), true);
86
+ }
87
+ }
88
+ )
89
+ });
90
+ this.refresher?.add("minimized", () => {
91
+ return autorun(
92
+ () => {
93
+ const minimized = this.attributes.minimized;
94
+ if (this.boxManager.teleBoxManager.minimized !== minimized) {
95
+ this.boxManager.teleBoxManager.setMinimized(Boolean(minimized), true);
96
+ }
97
+ }
98
+ )
99
+ });
79
100
  if (!this.attributes.apps || Object.keys(this.attributes.apps).length === 0) {
80
101
  const mainScenePath = this.store.getMainViewScenePath();
81
102
  if (!mainScenePath) return;
82
103
  const sceneState = this.displayer.state.sceneState;
83
104
  if (sceneState.scenePath !== mainScenePath) {
84
- this.room?.setScenePath(mainScenePath);
105
+ setScenePath(this.room, mainScenePath);
85
106
  }
86
107
  }
87
108
  this.displayerWritableListener(!this.room?.isWritable);
@@ -442,6 +463,7 @@ export class AppManager {
442
463
  });
443
464
  }
444
465
  this.viewManager.destroy();
466
+ this.boxManager.destroy();
445
467
  this.refresher?.destroy();
446
468
  this.mainViewProxy.destroy();
447
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,12 +216,16 @@ 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
- if (state.focus) {
223
- this.teleBoxManager.update(box.id, { focus: true }, true);
224
- }
223
+ setTimeout(() => {
224
+ if (state.focus) {
225
+ this.teleBoxManager.update(box.id, { focus: true }, true);
226
+ }
227
+ }, 50);
228
+ callbacks.emit("boxStateChange", this.teleBoxManager.state);
225
229
  }
226
230
  }
227
231
 
@@ -281,4 +285,8 @@ export class BoxManager {
281
285
  this.teleBoxManager.setState(state, true);
282
286
  callbacks.emit("boxStateChange", state);
283
287
  }
288
+
289
+ public destroy() {
290
+ this.teleBoxManager.destroy();
291
+ }
284
292
  }
@@ -142,6 +142,7 @@ export class Cursor extends Base {
142
142
  }
143
143
  this.timer = window.setTimeout(() => {
144
144
  this.hide();
145
+ this.store.updateCursorState(this.context.uid, CursorState.Leave);
145
146
  }, 1000 * 10); // 10 秒钟自动隐藏
146
147
  }
147
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,
@@ -45,7 +45,6 @@ import type {
45
45
  Room,
46
46
  InvisiblePluginContext,
47
47
  Camera,
48
-
49
48
  AnimationMode,
50
49
  CameraBound,
51
50
  Point,
@@ -61,6 +60,8 @@ const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
61
60
  export type WindowMangerAttributes = {
62
61
  modelValue?: string;
63
62
  boxState: TELE_BOX_STATE;
63
+ maximized?: boolean;
64
+ minimized?: boolean;
64
65
  [key: string]: any;
65
66
  };
66
67
 
@@ -169,7 +170,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
169
170
  public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
170
171
  private static isCreated = false;
171
172
 
172
- public version = "0.3.0-canary.1";
173
+ public version = "0.3.1";
173
174
 
174
175
  public appListeners?: AppListeners;
175
176
 
@@ -503,7 +504,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
503
504
 
504
505
  public get boxState(): TeleBoxState {
505
506
  if (this.appManager) {
506
- return this.appManager.store.getBoxState() || TELE_BOX_STATE.Normal;
507
+ return this.appManager.boxManager.teleBoxManager.state;
507
508
  } else {
508
509
  throw new AppManagerNotInitError();
509
510
  }
@@ -136,10 +136,7 @@ export class ViewManager extends Base {
136
136
  setTimeout(() => {
137
137
  const appProxy = this.manager.appProxies.get(id);
138
138
  if (appProxy) {
139
- const boxState = this.store.getBoxState();
140
- if (boxState && boxState === TELE_BOX_STATE.Minimized) {
141
- return;
142
- }
139
+ if (this.manager.boxManager.teleBoxManager.minimized) return;
143
140
  appProxy.setScenePath();
144
141
  appProxy.switchToWritable();
145
142
  appProxy.focusBox();