@netless/window-manager 0.4.69 → 0.4.71-beta.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/dist/typings.d.ts CHANGED
@@ -78,3 +78,7 @@ export type { SceneState, SceneDefinition, View, AnimationMode, Displayer, Room,
78
78
  export type { Storage, StorageStateChangedEvent, StorageStateChangedListener } from "./App/Storage";
79
79
  export * from "./Page";
80
80
  export * from "./Utils/error";
81
+ export declare type AppPayload = {
82
+ appId: string;
83
+ view: View;
84
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "0.4.69",
3
+ "version": "0.4.71-beta.0",
4
4
  "description": "Multi-window mode for Netless Whiteboard",
5
5
  "author": "l1shen <lishen1635@gmail.com> (https://github.com/l1shen)",
6
6
  "license": "MIT",
@@ -29,6 +29,8 @@ import type {
29
29
  } from "./MagixEvent";
30
30
  import type { AddPageParams, PageController, PageState } from "../Page";
31
31
  import { internalEmitter } from "../InternalEmitter";
32
+ import { WindowManager } from "../index";
33
+ import { callbacks } from "../callback";
32
34
 
33
35
  export class AppContext<TAttributes extends {} = any, TMagixEventPayloads = any, TAppOptions = any>
34
36
  implements PageController
@@ -90,6 +92,9 @@ export class AppContext<TAttributes extends {} = any, TMagixEventPayloads = any,
90
92
  setTimeout(() => {
91
93
  // 渲染需要时间,延迟 refresh
92
94
  this.getRoom()?.refreshViewSize();
95
+ if (WindowManager.supportTeachingAidsPlugin) {
96
+ callbacks.emit("onAppViewMounted", {appId: this.appId, view});
97
+ }
93
98
  }, 1000);
94
99
  }
95
100
  };
@@ -30,6 +30,8 @@ import type { ReadonlyTeleBox } from "@netless/telebox-insider";
30
30
  import type { PageRemoveService, PageState } from "../Page";
31
31
  import { calculateNextIndex } from "../Page";
32
32
  import { boxEmitter } from "../BoxEmitter";
33
+ import { WindowManager } from "../index";
34
+ import { callbacks } from "../callback";
33
35
 
34
36
  export type AppEmitter = Emittery<AppEmitterEvent>;
35
37
 
@@ -194,6 +196,9 @@ export class AppProxy implements PageRemoveService {
194
196
  appRegister.notifyApp(this.kind, "created", { appId, result });
195
197
  this.afterSetupApp(boxInitState);
196
198
  this.fixMobileSize();
199
+ if (WindowManager.supportTeachingAidsPlugin) {
200
+ callbacks.emit("onAppSetup", appId);
201
+ }
197
202
  }, SETUP_APP_DELAY);
198
203
  });
199
204
  this.boxManager?.createBox({
@@ -391,6 +396,9 @@ export class AppProxy implements PageRemoveService {
391
396
  private setFocusScenePathHandler = debounce((fullPath: string | undefined) => {
392
397
  if (this.view && fullPath && fullPath !== this.view?.focusScenePath) {
393
398
  setViewFocusScenePath(this.view, fullPath);
399
+ if (WindowManager.supportTeachingAidsPlugin) {
400
+ callbacks.emit("onAppScenePathChange", {appId: this.id, view:this.view});
401
+ }
394
402
  }
395
403
  }, 50);
396
404
 
package/src/AppManager.ts CHANGED
@@ -31,13 +31,7 @@ import {
31
31
  } from "./Utils/Common";
32
32
  import type { ReconnectRefresher } from "./ReconnectRefresher";
33
33
  import type { BoxManager } from "./BoxManager";
34
- import type {
35
- Displayer,
36
- Room,
37
- ScenesCallbacksNode,
38
- SceneState,
39
- RoomState,
40
- } from "white-web-sdk";
34
+ import type { Displayer, Room, ScenesCallbacksNode, SceneState, RoomState } from "white-web-sdk";
41
35
  import type { AddAppParams, BaseInsertParams, TeleBoxRect } from "./index";
42
36
  import type {
43
37
  BoxClosePayload,
@@ -47,7 +41,6 @@ import type {
47
41
  BoxStateChangePayload,
48
42
  } from "./BoxEmitter";
49
43
 
50
-
51
44
  export class AppManager {
52
45
  public displayer: Displayer;
53
46
  public viewManager: ViewManager;
@@ -380,6 +373,9 @@ export class AppManager {
380
373
  x: payload.x,
381
374
  y: payload.y,
382
375
  });
376
+ if (WindowManager.supportTeachingAidsPlugin) {
377
+ callbacks.emit("onBoxMove", payload);
378
+ }
383
379
  };
384
380
 
385
381
  private onBoxResize = (payload: BoxResizePayload) => {
@@ -389,11 +385,18 @@ export class AppManager {
389
385
  width: payload.width,
390
386
  height: payload.height,
391
387
  });
388
+ if (WindowManager.supportTeachingAidsPlugin) {
389
+ callbacks.emit("onBoxResize", payload);
390
+ }
392
391
  }
393
392
  };
394
393
 
395
394
  private onBoxFocus = (payload: BoxFocusPayload) => {
396
395
  this.windowManger.safeSetAttributes({ focus: payload.appId });
396
+ if (WindowManager.supportTeachingAidsPlugin) {
397
+ // (WindowManager.externalNotifyManager as any).emit('onBoxFocus', payload)
398
+ callbacks.emit("onBoxFocus", payload);
399
+ }
397
400
  };
398
401
 
399
402
  private onBoxClose = (payload: BoxClosePayload) => {
@@ -401,10 +404,16 @@ export class AppManager {
401
404
  if (appProxy) {
402
405
  appProxy.destroy(false, true, true, payload.error);
403
406
  }
407
+ if (WindowManager.supportTeachingAidsPlugin) {
408
+ callbacks.emit("onBoxClose", payload);
409
+ }
404
410
  };
405
411
 
406
412
  private onBoxStateChange = (payload: BoxStateChangePayload) => {
407
413
  this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
414
+ if (WindowManager.supportTeachingAidsPlugin) {
415
+ callbacks.emit("onBoxStateChange", payload);
416
+ }
408
417
  };
409
418
 
410
419
  public addAppsChangeListener = () => {
@@ -462,7 +471,10 @@ export class AppManager {
462
471
 
463
472
  private _appIds: string[] = [];
464
473
  public notifyAppsChange(appIds: string[]): void {
465
- if (this._appIds.length !== appIds.length || !this._appIds.every(id => appIds.includes(id))) {
474
+ if (
475
+ this._appIds.length !== appIds.length ||
476
+ !this._appIds.every(id => appIds.includes(id))
477
+ ) {
466
478
  this._appIds = appIds;
467
479
  callbacks.emit("appsChange", appIds);
468
480
  }
@@ -480,12 +492,16 @@ export class AppManager {
480
492
  if (appIds.length === 0) {
481
493
  this.appCreateQueue.emitReady();
482
494
  }
483
- const appsWithCreatedAt = orderBy(appIds.map(appId => {
484
- return {
485
- id: appId,
486
- createdAt: apps[appId].createdAt,
487
- };
488
- }), "createdAt", "asc");
495
+ const appsWithCreatedAt = orderBy(
496
+ appIds.map(appId => {
497
+ return {
498
+ id: appId,
499
+ createdAt: apps[appId].createdAt,
500
+ };
501
+ }),
502
+ "createdAt",
503
+ "asc"
504
+ );
489
505
  const orderedAppIds = appsWithCreatedAt.map(({ id }) => id);
490
506
  this.notifyAppsChange(orderedAppIds);
491
507
  for (const id of orderedAppIds) {
@@ -581,6 +597,9 @@ export class AppManager {
581
597
  this.setMainViewFocusPath();
582
598
  }
583
599
  internalEmitter.emit("mainViewMounted");
600
+ if (WindowManager.supportTeachingAidsPlugin) {
601
+ callbacks.emit("onMainViewMounted", mainView);
602
+ }
584
603
  }
585
604
 
586
605
  public setMainViewFocusPath(scenePath?: string) {
@@ -663,16 +682,6 @@ export class AppManager {
663
682
  }
664
683
 
665
684
  private displayerStateListener = (state: Partial<RoomState>) => {
666
- const sceneState = state.sceneState;
667
- if (sceneState) {
668
- const scenePath = sceneState.scenePath;
669
- this.appProxies.forEach(appProxy => {
670
- if (appProxy.scenePath && scenePath.startsWith(appProxy.scenePath)) {
671
- appProxy.emitAppSceneStateChange(sceneState);
672
- appProxy.setFullPath(scenePath);
673
- }
674
- });
675
- }
676
685
  this.appProxies.forEach(appProxy => {
677
686
  appProxy.appEmitter.emit("roomStateChange", state);
678
687
  });
@@ -1,4 +1,4 @@
1
- import { ApplianceNames } from "white-web-sdk";
1
+ import { ApplianceNames, isRoom } from "white-web-sdk";
2
2
  import { Cursor } from "./Cursor";
3
3
  import { CursorState, Events } from "../constants";
4
4
  import { internalEmitter } from "../InternalEmitter";
@@ -6,7 +6,7 @@ import { SideEffectManager } from "side-effect-manager";
6
6
  import { WindowManager } from "../index";
7
7
  import type { CursorMovePayload, ApplianceIcons } from "../index";
8
8
  import type { PositionType } from "../AttributesDelegate";
9
- import type { Point, RoomMember, View } from "white-web-sdk";
9
+ import type { Point, Room, RoomMember, View } from "white-web-sdk";
10
10
  import type { AppManager } from "../AppManager";
11
11
  import { ApplianceMap } from "./icons";
12
12
  import { findMemberByUid } from "../Helper";
@@ -31,6 +31,8 @@ export class CursorManager {
31
31
  private sideEffectManager = new SideEffectManager();
32
32
  private store = this.manager.store;
33
33
  public applianceIcons: ApplianceIcons = ApplianceMap;
34
+ private onceCount = true;
35
+
34
36
 
35
37
  constructor(private manager: AppManager, private enableCursor: boolean, applianceIcons?: ApplianceIcons) {
36
38
  this.roomMembers = this.manager.room?.state.roomMembers;
@@ -115,14 +117,24 @@ export class CursorManager {
115
117
  private mouseMoveListener = (event: PointerEvent) => {
116
118
  const isTouch = event.pointerType === "touch";
117
119
  if (isTouch && !event.isPrimary) return;
118
-
119
120
  const now = Date.now()
120
121
  if (now - this.mouseMoveTimer > 48) {
121
122
  this.mouseMoveTimer = now;
123
+ if (WindowManager.supportTeachingAidsPlugin && isRoom(WindowManager.displayer) && (WindowManager.displayer as Room).disableDeviceInputs) {
124
+ if(this.onceCount){
125
+ this.manager.dispatchInternalEvent(Events.CursorMove, {
126
+ uid: this.manager.uid,
127
+ state: CursorState.Leave
128
+ } as CursorMovePayload);
129
+ this.onceCount = false;
130
+ }
131
+ return ;
132
+ }
122
133
  this.mouseMoveListener_(event, isTouch);
134
+ this.onceCount = true;
123
135
  }
124
136
  }
125
-
137
+
126
138
  private mouseLeaveListener = () => {
127
139
  this.hideCursor(this.manager.uid);
128
140
  }
package/src/callback.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import Emittery from "emittery";
2
2
  import type { TeleBoxColorScheme, TELE_BOX_STATE } from "@netless/telebox-insider";
3
- import type { CameraState, SceneState, ViewVisionMode } from "white-web-sdk";
3
+ import type { CameraState, SceneState, View, ViewVisionMode } from "white-web-sdk";
4
4
  import type { LoadAppEvent } from "./Register";
5
5
  import type { PageState } from "./Page";
6
+ import type { BoxClosePayload, BoxFocusPayload, BoxMovePayload, BoxResizePayload, BoxStateChangePayload } from "./BoxEmitter";
7
+ import type { AppPayload } from "./typings";
6
8
 
7
9
  export type PublicEvent = {
8
10
  mainViewModeChange: ViewVisionMode;
@@ -22,6 +24,15 @@ export type PublicEvent = {
22
24
  pageStateChange: PageState;
23
25
  fullscreenChange: boolean;
24
26
  appsChange: string[]; // APP 列表变化时触发
27
+ onBoxMove: BoxMovePayload;
28
+ onBoxResize: BoxResizePayload;
29
+ onBoxFocus: BoxFocusPayload;
30
+ onBoxClose: BoxClosePayload;
31
+ onBoxStateChange: BoxStateChangePayload;
32
+ onMainViewMounted: View;
33
+ onAppViewMounted: AppPayload;
34
+ onAppSetup: string;
35
+ onAppScenePathChange: AppPayload;
25
36
  };
26
37
 
27
38
  export type CallbacksType = Emittery<PublicEvent>;
package/src/index.ts CHANGED
@@ -143,6 +143,7 @@ export type MountParams = {
143
143
  applianceIcons?: ApplianceIcons;
144
144
  fullscreen?: boolean;
145
145
  polling?: boolean;
146
+ supportTeachingAidsPlugin?: boolean;
146
147
  };
147
148
 
148
149
  export const reconnectRefresher = new ReconnectRefresher({ emitter: internalEmitter });
@@ -156,6 +157,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
156
157
  public static container?: HTMLElement;
157
158
  public static debug = false;
158
159
  public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
160
+ public static supportTeachingAidsPlugin?: boolean;
159
161
  private static isCreated = false;
160
162
 
161
163
  public version = __APP_VERSION__;
@@ -187,6 +189,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
187
189
  public static async mount(params: MountParams): Promise<WindowManager> {
188
190
  const room = params.room;
189
191
  WindowManager.container = params.container;
192
+ WindowManager.supportTeachingAidsPlugin = params.supportTeachingAidsPlugin;
190
193
  const containerSizeRatio = params.containerSizeRatio;
191
194
  const debug = params.debug;
192
195
 
@@ -367,7 +370,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
367
370
  this.appManager?.resetMaximized();
368
371
  this.appManager?.resetMinimized();
369
372
  this.appManager?.displayerWritableListener(!this.room.isWritable);
370
- WindowManager.container = container;
373
+ WindowManager.container = container;
371
374
  }
372
375
 
373
376
  public bindCollectorContainer(container: HTMLElement) {
package/src/typings.ts CHANGED
@@ -88,3 +88,8 @@ export type { SceneState, SceneDefinition, View, AnimationMode, Displayer, Room,
88
88
  export type { Storage, StorageStateChangedEvent, StorageStateChangedListener } from "./App/Storage";
89
89
  export * from "./Page";
90
90
  export * from "./Utils/error";
91
+
92
+ export type AppPayload = {
93
+ appId: string,
94
+ view: View
95
+ }