@netless/window-manager 1.0.7-beta.4 → 1.0.7-beta.6

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.7-beta.4",
3
+ "version": "1.0.7-beta.6",
4
4
  "description": "Multi-window mode for Netless Whiteboard",
5
5
  "author": "l1shen <lishen1635@gmail.com> (https://github.com/l1shen)",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@ import type {
16
16
  View,
17
17
  EventListener as WhiteEventListener,
18
18
  } from "white-web-sdk";
19
- import type { ReadonlyTeleBox } from "@netless/telebox-insider";
19
+ import type { NotMinimizedBoxState, ReadonlyTeleBox, TeleBoxState } from "@netless/telebox-insider";
20
20
  import type Emittery from "emittery";
21
21
  import type { BoxManager } from "../BoxManager";
22
22
  import type { AppEmitterEvent, WindowManager } from "../index";
@@ -74,6 +74,14 @@ export class AppContext<TAttributes extends {} = any, TMagixEventPayloads = any,
74
74
  return this.manager.windowManger;
75
75
  };
76
76
 
77
+ public getBoxStatus = (): TeleBoxState | undefined => {
78
+ return this.manager.store.getBoxStatus(this.appId);
79
+ };
80
+
81
+ public getLastNotMinimizedBoxStatus = (): NotMinimizedBoxState | undefined => {
82
+ return this.manager.store.getLastNotMinimizedBoxStatus(this.appId);
83
+ };
84
+
77
85
  public getDisplayer = () => {
78
86
  return this.manager.displayer;
79
87
  };
@@ -450,6 +450,10 @@ export class AppProxy implements PageRemoveService {
450
450
  this.appEmitter.emit("pageStateChange", this.pageState);
451
451
  }, 50);
452
452
 
453
+ public notifyBoxStatusChange = (status: TeleBoxState) => {
454
+ this.appEmitter.emit("boxStatusChange", { appId: this.id, status });
455
+ };
456
+
453
457
  public get pageState(): PageState {
454
458
  return this._pageState.toObject();
455
459
  }
package/src/AppManager.ts CHANGED
@@ -50,6 +50,7 @@ import type {
50
50
  BoxStateChangePayload,
51
51
  } from "./BoxEmitter";
52
52
  import { getExtendClass } from "./Utils/extendClass";
53
+ import type { TeleBoxState } from "@netless/telebox-insider";
53
54
 
54
55
  export class AppManager {
55
56
  public displayer: Displayer;
@@ -454,12 +455,25 @@ export class AppManager {
454
455
  callbacks.emit("onBoxStateChange", payload);
455
456
  };
456
457
 
458
+ private notifyBoxesStatusChange = debounce(() => {
459
+ const entries = Object.entries(this.attributes.boxesStatus);
460
+ if (entries.length > 0) {
461
+ entries.forEach(([appId, status]) => {
462
+ const appProxy = this.appProxies.get(appId);
463
+ if (appProxy) {
464
+ appProxy.notifyBoxStatusChange(status as TeleBoxState);
465
+ }
466
+ });
467
+ }
468
+ }, 50);
469
+
457
470
  public addBoxesStatusChangeListener = () => {
458
471
  this.refresher.add("boxesStatus", () => {
459
472
  return safeListenPropsUpdated(
460
473
  () => this.attributes.boxesStatus,
461
474
  () => {
462
475
  this.boxManager?.setBoxesStatus(this.attributes.boxesStatus);
476
+ this.notifyBoxesStatusChange();
463
477
  }
464
478
  );
465
479
  });
@@ -474,7 +488,6 @@ export class AppManager {
474
488
  );
475
489
  });
476
490
  };
477
-
478
491
  public addAppsChangeListener = () => {
479
492
  this.refresher.add("apps", () => {
480
493
  return safeListenPropsUpdated(
@@ -5,7 +5,6 @@ import type { AddAppParams, AppSyncAttributes } from "./index";
5
5
  import type { Camera, Size, View } from "white-web-sdk";
6
6
  import type { Cursor } from "./Cursor/Cursor";
7
7
  import { getExtendClass } from "./Utils/extendClass";
8
- import type { TELE_BOX_STATE } from "@netless/telebox-insider";
9
8
  import type { ExtendClass } from "./Utils/extendClass";
10
9
  import type { NotMinimizedBoxState, TeleBoxState } from "@netless/telebox-insider";
11
10
 
@@ -88,11 +87,11 @@ export class AttributesDelegate {
88
87
  return get(this.attributes, ["minimized"]);
89
88
  }
90
89
 
91
- public getBoxesStatus(): Record<string, TELE_BOX_STATE> | undefined {
90
+ public getBoxesStatus(): Record<string, TeleBoxState> | undefined {
92
91
  return get(this.attributes, [Fields.BoxesStatus]);
93
92
  }
94
93
 
95
- public getBoxStatus(id: string): TELE_BOX_STATE | undefined {
94
+ public getBoxStatus(id: string): TeleBoxState | undefined {
96
95
  return get(this.attributes, [Fields.BoxesStatus, id]);
97
96
  }
98
97
 
package/src/BoxManager.ts CHANGED
@@ -290,23 +290,26 @@ export class BoxManager {
290
290
  }
291
291
  }
292
292
  public setBoxesStatus(status?: Record<string, TeleBoxState>): void {
293
- this.teleBoxManager.setBoxesStatus(new Map(Object.entries(status ?? {})), true);
293
+ const map = new Map(Object.entries(status ?? {}));
294
+ this.teleBoxManager.setBoxesStatus(map, true);
295
+ this.context.callbacks.emit("onBoxesStatusChange", map);
296
+ this.context.emitter.emit("boxesStatusChange", map);
294
297
  }
295
298
 
296
- public setBoxStatus(appId: string, status?: TeleBoxState): void {
297
- this.teleBoxManager.update(appId, { boxStatus: status }, true);
298
- }
299
+ // public setBoxStatus(appId: string, status?: TeleBoxState, skipUpdate = false): void {
300
+ // this.teleBoxManager.update(appId, { boxStatus: status }, true);
301
+ // }
299
302
 
300
303
  public setLastNotMinimizedBoxesStatus(status?: Record<string, NotMinimizedBoxState>): void {
301
- this.teleBoxManager.setLastNotMinimizedBoxesStatus(
302
- new Map(Object.entries(status ?? {})),
303
- true
304
- );
304
+ const map = new Map(Object.entries(status ?? {}));
305
+ this.teleBoxManager.setLastNotMinimizedBoxesStatus(map, true);
306
+ this.context.callbacks.emit("onLastNotMinimizedBoxesStatusChange", map);
307
+ this.context.emitter.emit("lastNotMinimizedBoxesStatusChange", map);
305
308
  }
306
309
 
307
- public setLastNotMinimizedBoxStatus(appId: string, status?: NotMinimizedBoxState): void {
308
- this.teleBoxManager.update(appId, { lastNotMinimizedBoxStatus: status }, true);
309
- }
310
+ // public setLastNotMinimizedBoxStatus(appId: string, status?: NotMinimizedBoxState): void {
311
+ // this.teleBoxManager.update(appId, { lastNotMinimizedBoxStatus: status }, true);
312
+ // }
310
313
 
311
314
  public setupBoxManager(
312
315
  createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig
@@ -1,5 +1,6 @@
1
1
  import Emittery from "emittery";
2
2
  import type { AppInitState, CursorMovePayload } from "./index";
3
+ import type { NotMinimizedBoxState, TeleBoxState } from "@netless/telebox-insider";
3
4
 
4
5
  export type RemoveSceneParams = {
5
6
  scenePath: string;
@@ -28,6 +29,8 @@ export type EmitterEvent = {
28
29
  changePageState: undefined;
29
30
  writableChange: boolean;
30
31
  containerSizeRatioUpdate: number;
32
+ boxesStatusChange: Map<string, TeleBoxState>;
33
+ lastNotMinimizedBoxesStatusChange: Map<string, NotMinimizedBoxState>;
31
34
  };
32
35
 
33
36
  export type EmitterType = Emittery<EmitterEvent>;
package/src/callback.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import Emittery from "emittery";
2
- import type { TeleBoxColorScheme, TELE_BOX_STATE } from "@netless/telebox-insider";
2
+ import type {
3
+ TeleBoxColorScheme,
4
+ TELE_BOX_STATE,
5
+ TeleBoxState,
6
+ NotMinimizedBoxState,
7
+ } from "@netless/telebox-insider";
3
8
  import type { CameraState, SceneState, View, ViewVisionMode } from "white-web-sdk";
4
9
  import type { LoadAppEvent } from "./Register";
5
10
  import type { PageState } from "./Page";
@@ -42,6 +47,8 @@ export type PublicEvent = {
42
47
  onAppViewMounted: AppPayload;
43
48
  onAppSetup: string;
44
49
  onAppScenePathChange: AppPayload;
50
+ onBoxesStatusChange: Map<string, TeleBoxState>;
51
+ onLastNotMinimizedBoxesStatusChange: Map<string, NotMinimizedBoxState>;
45
52
  };
46
53
 
47
54
  export type CallbacksType = Emittery<PublicEvent>;
package/src/index.ts CHANGED
@@ -725,7 +725,7 @@ export class WindowManager
725
725
  /** 设置指定 box 的状态, 如果为 undefined, 则移除状态*/
726
726
  public setBoxStatus(boxId: string, boxStatus?: TELE_BOX_STATE): void {
727
727
  if (!this.canOperate) return;
728
- this.boxManager?.setBoxStatus(boxId, boxStatus);
728
+ this.appManager?.store.setBoxStatus(boxId, boxStatus);
729
729
  }
730
730
 
731
731
  /** 设置指定 box 的非最小化状态, 如果为 undefined, 则移除状态 */
@@ -734,7 +734,7 @@ export class WindowManager
734
734
  lastNotMinimizedBoxStatus?: NotMinimizedBoxState
735
735
  ): void {
736
736
  if (!this.canOperate) return;
737
- this.boxManager?.setLastNotMinimizedBoxStatus(boxId, lastNotMinimizedBoxStatus);
737
+ this.appManager?.store.setLastNotMinimizedBoxStatus(boxId, lastNotMinimizedBoxStatus);
738
738
  }
739
739
 
740
740
  public setFullscreen(fullscreen: boolean): void {
@@ -802,7 +802,7 @@ export class WindowManager
802
802
  }
803
803
  }
804
804
 
805
- public get boxStatus(): Record<string, TELE_BOX_STATE> | undefined {
805
+ public get boxStatus(): Record<string, TeleBoxState> | undefined {
806
806
  if (this.appManager) {
807
807
  return this.appManager.store.getBoxesStatus();
808
808
  } else {
package/src/typings.ts CHANGED
@@ -11,7 +11,7 @@ import type {
11
11
  View,
12
12
  } from "white-web-sdk";
13
13
  import type { AppContext } from "./App";
14
- import type { ReadonlyTeleBox, TeleBoxRect } from "@netless/telebox-insider";
14
+ import type { ReadonlyTeleBox, TeleBoxRect, TeleBoxState } from "@netless/telebox-insider";
15
15
  import type { PageState } from "./Page";
16
16
 
17
17
  export interface NetlessApp<
@@ -58,6 +58,7 @@ export type AppEmitterEvent<T = any> = {
58
58
  reconnected: void;
59
59
  seek: number;
60
60
  pageStateChange: PageState;
61
+ boxStatusChange: { appId: string; status: TeleBoxState };
61
62
  };
62
63
 
63
64
  export type RegisterEventData = {