@netless/window-manager 1.0.0-canary.8 → 1.0.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.
Files changed (135) hide show
  1. package/LICENSE.txt +21 -0
  2. package/README.md +90 -64
  3. package/README.zh-cn.md +224 -0
  4. package/dist/index.d.ts +1133 -39
  5. package/dist/index.js +62 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/{index.es.js → index.mjs} +8393 -5913
  8. package/dist/index.mjs.map +1 -0
  9. package/dist/style.css +1 -1
  10. package/docs/advanced.md +55 -55
  11. package/docs/api.md +124 -113
  12. package/docs/app-context.md +248 -209
  13. package/docs/basic.md +25 -26
  14. package/docs/camera.md +19 -20
  15. package/docs/cn/advanced.md +137 -0
  16. package/docs/cn/api.md +309 -0
  17. package/docs/cn/app-context.md +369 -0
  18. package/docs/cn/basic.md +64 -0
  19. package/docs/cn/camera.md +53 -0
  20. package/docs/cn/concept.md +9 -0
  21. package/docs/cn/custom-max-bar.md +31 -0
  22. package/docs/cn/develop-app.md +94 -0
  23. package/docs/cn/export-pdf.md +48 -0
  24. package/docs/cn/migrate.md +60 -0
  25. package/docs/cn/replay.md +40 -0
  26. package/docs/concept.md +6 -5
  27. package/docs/custom-max-bar.md +31 -0
  28. package/docs/develop-app.md +22 -19
  29. package/docs/export-pdf.md +48 -0
  30. package/docs/migrate.md +25 -27
  31. package/docs/quickstart.md +50 -0
  32. package/docs/replay.md +20 -20
  33. package/package.json +32 -22
  34. package/src/App/AppContext.ts +104 -71
  35. package/src/App/AppPageStateImpl.ts +6 -25
  36. package/src/App/AppProxy.ts +42 -147
  37. package/src/App/MagixEvent/index.ts +38 -38
  38. package/src/App/Storage/StorageEvent.ts +13 -13
  39. package/src/App/Storage/index.ts +269 -245
  40. package/src/App/Storage/typings.ts +4 -2
  41. package/src/App/Storage/utils.ts +3 -3
  42. package/src/App/index.ts +0 -1
  43. package/src/AppListener.ts +8 -8
  44. package/src/AppManager.ts +84 -75
  45. package/src/AttributesDelegate.ts +42 -22
  46. package/src/BoxEmitter.ts +12 -6
  47. package/src/BoxManager.ts +122 -106
  48. package/src/ContainerResizeObserver.ts +75 -0
  49. package/src/Cursor/Cursor.svelte +16 -5
  50. package/src/Cursor/Cursor.svelte.d.ts +21 -0
  51. package/src/Cursor/Cursor.ts +77 -13
  52. package/src/Cursor/icons.ts +6 -0
  53. package/src/Cursor/icons2.ts +66 -0
  54. package/src/Cursor/index.ts +127 -26
  55. package/src/Helper.ts +94 -14
  56. package/src/InternalEmitter.ts +2 -7
  57. package/src/Page/PageController.ts +1 -0
  58. package/src/Page/index.ts +1 -1
  59. package/src/PageState.ts +6 -5
  60. package/src/ReconnectRefresher.ts +9 -4
  61. package/src/RedoUndo.ts +3 -3
  62. package/src/Register/index.ts +22 -17
  63. package/src/Register/loader.ts +26 -22
  64. package/src/Register/storage.ts +13 -13
  65. package/src/Utils/Common.ts +18 -14
  66. package/src/Utils/Reactive.ts +26 -25
  67. package/src/Utils/RoomHacker.ts +4 -4
  68. package/src/Utils/error.ts +0 -1
  69. package/src/View/IframeBridge.ts +680 -0
  70. package/src/View/MainView.ts +114 -53
  71. package/src/callback.ts +21 -1
  72. package/src/constants.ts +0 -2
  73. package/src/image/pencil-eraser-1.svg +3 -0
  74. package/src/image/pencil-eraser-2.svg +3 -0
  75. package/src/image/pencil-eraser-3.svg +3 -0
  76. package/src/index.ts +224 -74
  77. package/src/style.css +27 -10
  78. package/src/typings.ts +20 -10
  79. package/.prettierignore +0 -7
  80. package/.prettierrc.json +0 -9
  81. package/CHANGELOG.md +0 -196
  82. package/__mocks__/white-web-sdk.ts +0 -50
  83. package/dist/App/AppContext.d.ts +0 -76
  84. package/dist/App/AppPageStateImpl.d.ts +0 -21
  85. package/dist/App/AppProxy.d.ts +0 -81
  86. package/dist/App/AppViewSync.d.ts +0 -11
  87. package/dist/App/MagixEvent/index.d.ts +0 -29
  88. package/dist/App/Storage/StorageEvent.d.ts +0 -8
  89. package/dist/App/Storage/index.d.ts +0 -39
  90. package/dist/App/Storage/typings.d.ts +0 -22
  91. package/dist/App/Storage/utils.d.ts +0 -5
  92. package/dist/App/WhiteboardView.d.ts +0 -22
  93. package/dist/App/index.d.ts +0 -3
  94. package/dist/AppListener.d.ts +0 -21
  95. package/dist/AppManager.d.ts +0 -107
  96. package/dist/AttributesDelegate.d.ts +0 -80
  97. package/dist/BoxEmitter.d.ts +0 -34
  98. package/dist/BoxManager.d.ts +0 -100
  99. package/dist/BuiltinApps.d.ts +0 -5
  100. package/dist/Cursor/Cursor.d.ts +0 -39
  101. package/dist/Cursor/icons.d.ts +0 -3
  102. package/dist/Cursor/index.d.ts +0 -46
  103. package/dist/Helper.d.ts +0 -17
  104. package/dist/InternalEmitter.d.ts +0 -39
  105. package/dist/Page/PageController.d.ts +0 -20
  106. package/dist/Page/index.d.ts +0 -3
  107. package/dist/PageState.d.ts +0 -9
  108. package/dist/ReconnectRefresher.d.ts +0 -24
  109. package/dist/RedoUndo.d.ts +0 -18
  110. package/dist/Register/index.d.ts +0 -28
  111. package/dist/Register/loader.d.ts +0 -4
  112. package/dist/Register/storage.d.ts +0 -8
  113. package/dist/Utils/AppCreateQueue.d.ts +0 -15
  114. package/dist/Utils/Common.d.ts +0 -23
  115. package/dist/Utils/Reactive.d.ts +0 -6
  116. package/dist/Utils/RoomHacker.d.ts +0 -3
  117. package/dist/Utils/error.d.ts +0 -27
  118. package/dist/Utils/log.d.ts +0 -1
  119. package/dist/View/CameraSynchronizer.d.ts +0 -17
  120. package/dist/View/MainView.d.ts +0 -48
  121. package/dist/View/ViewManager.d.ts +0 -13
  122. package/dist/View/ViewSync.d.ts +0 -7
  123. package/dist/callback.d.ts +0 -24
  124. package/dist/constants.d.ts +0 -49
  125. package/dist/index.cjs.js +0 -46
  126. package/dist/index.umd.js +0 -46
  127. package/dist/typings.d.ts +0 -82
  128. package/jest.config.js +0 -27
  129. package/pnpm-lock.yaml +0 -6302
  130. package/src/App/AppViewSync.ts +0 -68
  131. package/src/App/WhiteboardView.ts +0 -83
  132. package/src/View/CameraSynchronizer.ts +0 -73
  133. package/src/View/ViewSync.ts +0 -10
  134. package/vite.config.js +0 -51
  135. /package/docs/{qickstart.md → cn/quickstart.md} +0 -0
package/src/AppManager.ts CHANGED
@@ -3,19 +3,18 @@ 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, toJS } from "white-web-sdk";
6
+ import { autorun, isPlayer, isRoom, ScenePathType } from "white-web-sdk";
7
7
  import { boxEmitter } from "./BoxEmitter";
8
8
  import { calculateNextIndex } from "./Page";
9
9
  import { callbacks } from "./callback";
10
10
  import { debounce, get, isInteger, orderBy } from "lodash";
11
- import { emitter } from "./InternalEmitter";
11
+ import { internalEmitter } from "./InternalEmitter";
12
12
  import { Fields, store } from "./AttributesDelegate";
13
13
  import { log } from "./Utils/log";
14
14
  import { MainViewProxy } from "./View/MainView";
15
15
  import { onObjectRemoved, safeListenPropsUpdated } from "./Utils/Reactive";
16
16
  import { reconnectRefresher, WindowManager } from "./index";
17
17
  import { RedoUndo } from "./RedoUndo";
18
- import { serializeRoomMembers } from "./Helper";
19
18
  import { SideEffectManager } from "side-effect-manager";
20
19
  import { ViewManager } from "./View/ViewManager";
21
20
  import type { SyncRegisterAppPayload } from "./Register";
@@ -38,6 +37,7 @@ import type {
38
37
  ScenesCallbacksNode,
39
38
  SceneState,
40
39
  RoomState,
40
+ MemberState,
41
41
  } from "white-web-sdk";
42
42
  import type { AddAppParams, BaseInsertParams, TeleBoxRect } from "./index";
43
43
  import type {
@@ -47,7 +47,6 @@ import type {
47
47
  BoxResizePayload,
48
48
  BoxStateChangePayload,
49
49
  } from "./BoxEmitter";
50
- import type { Member } from "./Helper";
51
50
 
52
51
  export class AppManager {
53
52
  public displayer: Displayer;
@@ -90,29 +89,27 @@ export class AppManager {
90
89
 
91
90
  this.refresher = reconnectRefresher;
92
91
  this.refresher.setRoom(this.room);
93
- this.refresher.setContext({ emitter });
94
-
95
- this.sideEffectManager.add(() => {
96
- return () => {
97
- this.appCreateQueue.destroy();
98
- this.mainViewProxy.destroy();
99
- this.refresher?.destroy();
100
- this.viewManager.destroy();
101
- this.boxManager?.destroy();
102
- this.callbacksNode?.dispose();
103
- };
92
+ this.refresher.setContext({ emitter: internalEmitter });
93
+
94
+ this.sideEffectManager.addDisposer(() => {
95
+ this.appCreateQueue.destroy();
96
+ this.mainViewProxy.destroy();
97
+ this.refresher.destroy();
98
+ this.viewManager.destroy();
99
+ this.boxManager?.destroy();
100
+ this.callbacksNode?.dispose();
104
101
  });
105
102
 
106
- emitter.once("onCreated").then(() => this.onCreated());
107
- emitter.on("onReconnected", () => this.onReconnected());
103
+ internalEmitter.once("onCreated").then(() => this.onCreated());
104
+ internalEmitter.on("onReconnected", () => this.onReconnected());
108
105
 
109
106
  if (isPlayer(this.displayer)) {
110
- emitter.on("seekStart", this.onPlayerSeekStart);
111
- emitter.on("seek", this.onPlayerSeekDone);
107
+ internalEmitter.on("seekStart", this.onPlayerSeekStart);
108
+ internalEmitter.on("seek", this.onPlayerSeekDone);
112
109
  }
113
110
 
114
- emitter.on("removeScenes", this.onRemoveScenes);
115
- emitter.on("setReadonly", this.onReadonlyChanged);
111
+ internalEmitter.on("removeScenes", this.onRemoveScenes);
112
+ internalEmitter.on("setReadonly", this.onReadonlyChanged);
116
113
 
117
114
  this.createRootDirScenesCallback();
118
115
 
@@ -121,6 +118,10 @@ export class AppManager {
121
118
  });
122
119
  }
123
120
 
121
+ public getMemberState(): MemberState {
122
+ return this.room?.state.memberState || ({ strokeColor: [0, 0, 0] } as MemberState);
123
+ }
124
+
124
125
  private onRemoveScenes = async (params: RemoveSceneParams) => {
125
126
  const { scenePath } = params;
126
127
  // 如果移除根目录就把 scenePath 设置为初始值
@@ -162,7 +163,7 @@ export class AppManager {
162
163
  }
163
164
  // 删除了根目录的 scenes 之后 mainview 需要重新绑定, 否则主白板会不能渲染
164
165
  this.mainViewProxy.rebind();
165
- emitter.emit("rootDirRemoved");
166
+ internalEmitter.emit("rootDirRemoved");
166
167
  this.updateRootDirRemoving(false);
167
168
  }
168
169
 
@@ -193,7 +194,7 @@ export class AppManager {
193
194
  onAddScene: this.onSceneChange,
194
195
  onRemoveScene: async (node, name) => {
195
196
  await this.onSceneChange(node);
196
- emitter.emit("rootDirSceneRemoved", name);
197
+ internalEmitter.emit("rootDirSceneRemoved", name);
197
198
  },
198
199
  });
199
200
  if (this.callbacksNode) {
@@ -216,7 +217,7 @@ export class AppManager {
216
217
  }
217
218
  }, 100);
218
219
  return new Promise<boolean>((resolve, reject) => {
219
- emitter
220
+ internalEmitter
220
221
  .once("rootDirSceneRemoved")
221
222
  .then(name => {
222
223
  if (name === scene) {
@@ -246,7 +247,7 @@ export class AppManager {
246
247
  private emitMainViewScenesChange = (length: number) => {
247
248
  return Promise.all([
248
249
  callbacks.emit("mainViewScenesLengthChange", length),
249
- emitter.emit("changePageState"),
250
+ internalEmitter.emit("changePageState"),
250
251
  ]);
251
252
  };
252
253
 
@@ -290,6 +291,14 @@ export class AppManager {
290
291
  return this.mainViewProxy.view;
291
292
  }
292
293
 
294
+ public get polling() {
295
+ return this.mainViewProxy.polling;
296
+ }
297
+
298
+ public set polling(b: boolean) {
299
+ this.mainViewProxy.polling = b;
300
+ }
301
+
293
302
  public get focusApp() {
294
303
  if (this.store.focus) {
295
304
  return this.appProxies.get(this.store.focus);
@@ -300,10 +309,6 @@ export class AppManager {
300
309
  return this.room?.uid || "";
301
310
  }
302
311
 
303
- public get members(): Member[] {
304
- return serializeRoomMembers(this.displayer.state.roomMembers);
305
- }
306
-
307
312
  public getMainViewSceneDir() {
308
313
  const scenePath = this.store.getMainViewScenePath();
309
314
  if (scenePath) {
@@ -315,7 +320,7 @@ export class AppManager {
315
320
 
316
321
  private async onCreated() {
317
322
  await this.attributesUpdateCallback(this.attributes.apps);
318
- emitter.emit("updateManagerRect");
323
+ internalEmitter.emit("updateManagerRect");
319
324
  boxEmitter.on("move", this.onBoxMove);
320
325
  boxEmitter.on("resize", this.onBoxResize);
321
326
  boxEmitter.on("focus", this.onBoxFocus);
@@ -324,31 +329,31 @@ export class AppManager {
324
329
 
325
330
  this.addAppsChangeListener();
326
331
  this.addAppCloseListener();
327
- this.refresher?.add("maximized", () => {
332
+ this.refresher.add("maximized", () => {
328
333
  return autorun(() => {
329
334
  const maximized = this.attributes.maximized;
330
335
  this.boxManager?.setMaximized(Boolean(maximized));
331
336
  });
332
337
  });
333
- this.refresher?.add("minimized", () => {
338
+ this.refresher.add("minimized", () => {
334
339
  return autorun(() => {
335
340
  const minimized = this.attributes.minimized;
336
341
  this.onMinimized(minimized);
337
342
  });
338
343
  });
339
- this.refresher?.add("mainViewIndex", () => {
344
+ this.refresher.add("mainViewIndex", () => {
340
345
  return autorun(() => {
341
346
  const mainSceneIndex = get(this.attributes, "_mainSceneIndex");
342
347
  this.onMainViewIndexChange(mainSceneIndex);
343
348
  });
344
349
  });
345
- this.refresher?.add("focusedChange", () => {
350
+ this.refresher.add("focusedChange", () => {
346
351
  return autorun(() => {
347
352
  const focused = get(this.attributes, "focus");
348
353
  this.onFocusChange(focused);
349
354
  });
350
355
  });
351
- this.refresher?.add("registeredChange", () => {
356
+ this.refresher.add("registeredChange", () => {
352
357
  return autorun(() => {
353
358
  const registered = get(this.attributes, Fields.Registered);
354
359
  this.onRegisteredChange(registered);
@@ -379,6 +384,7 @@ export class AppManager {
379
384
  x: payload.x,
380
385
  y: payload.y,
381
386
  });
387
+ callbacks.emit("onBoxMove", payload);
382
388
  };
383
389
 
384
390
  private onBoxResize = (payload: BoxResizePayload) => {
@@ -388,11 +394,13 @@ export class AppManager {
388
394
  width: payload.width,
389
395
  height: payload.height,
390
396
  });
397
+ callbacks.emit("onBoxResize", payload);
391
398
  }
392
399
  };
393
400
 
394
401
  private onBoxFocus = (payload: BoxFocusPayload) => {
395
402
  this.windowManger.safeSetAttributes({ focus: payload.appId });
403
+ callbacks.emit("onBoxFocus", payload);
396
404
  };
397
405
 
398
406
  private onBoxClose = (payload: BoxClosePayload) => {
@@ -400,14 +408,16 @@ export class AppManager {
400
408
  if (appProxy) {
401
409
  appProxy.destroy(false, true, true, payload.error);
402
410
  }
411
+ callbacks.emit("onBoxClose", payload);
403
412
  };
404
413
 
405
414
  private onBoxStateChange = (payload: BoxStateChangePayload) => {
406
415
  this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
416
+ callbacks.emit("onBoxStateChange", payload);
407
417
  };
408
418
 
409
419
  public addAppsChangeListener = () => {
410
- this.refresher?.add("apps", () => {
420
+ this.refresher.add("apps", () => {
411
421
  return safeListenPropsUpdated(
412
422
  () => this.attributes.apps,
413
423
  () => {
@@ -418,7 +428,7 @@ export class AppManager {
418
428
  };
419
429
 
420
430
  public addAppCloseListener = () => {
421
- this.refresher?.add("appsClose", () => {
431
+ this.refresher.add("appsClose", () => {
422
432
  return onObjectRemoved(this.attributes.apps, () => {
423
433
  this.onAppDelete(this.attributes.apps);
424
434
  });
@@ -428,7 +438,7 @@ export class AppManager {
428
438
  private onMainViewIndexChange = (index: number) => {
429
439
  if (index !== undefined && this._prevSceneIndex !== index) {
430
440
  callbacks.emit("mainViewSceneIndexChange", index);
431
- emitter.emit("changePageState");
441
+ internalEmitter.emit("changePageState");
432
442
  if (this.callbacksNode) {
433
443
  this.updateSceneState(this.callbacksNode);
434
444
  }
@@ -439,7 +449,7 @@ export class AppManager {
439
449
  private onFocusChange = (focused: string | undefined) => {
440
450
  if (this._prevFocused !== focused) {
441
451
  callbacks.emit("focusedChange", focused);
442
- emitter.emit("focusedChange", { focused, prev: this._prevFocused });
452
+ internalEmitter.emit("focusedChange", { focused, prev: this._prevFocused });
443
453
  this._prevFocused = focused;
444
454
  if (focused !== undefined) {
445
455
  this.boxManager?.focusBox({ appId: focused });
@@ -459,6 +469,17 @@ export class AppManager {
459
469
  100
460
470
  );
461
471
 
472
+ private _appIds: string[] = [];
473
+ public notifyAppsChange(appIds: string[]): void {
474
+ if (
475
+ this._appIds.length !== appIds.length ||
476
+ !this._appIds.every(id => appIds.includes(id))
477
+ ) {
478
+ this._appIds = appIds;
479
+ callbacks.emit("appsChange", appIds);
480
+ }
481
+ }
482
+
462
483
  /**
463
484
  * 插件更新 attributes 时的回调
464
485
  *
@@ -471,13 +492,19 @@ export class AppManager {
471
492
  if (appIds.length === 0) {
472
493
  this.appCreateQueue.emitReady();
473
494
  }
474
- const appsWithCreatedAt = appIds.map(appId => {
475
- return {
476
- id: appId,
477
- createdAt: apps[appId].createdAt,
478
- };
479
- });
480
- for (const { id } of orderBy(appsWithCreatedAt, "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
+ );
505
+ const orderedAppIds = appsWithCreatedAt.map(({ id }) => id);
506
+ this.notifyAppsChange(orderedAppIds);
507
+ for (const id of orderedAppIds) {
481
508
  if (!this.appProxies.has(id) && !this.appStatus.has(id)) {
482
509
  const app = apps[id];
483
510
  try {
@@ -569,7 +596,8 @@ export class AppManager {
569
596
  if (!mainView.focusScenePath) {
570
597
  this.setMainViewFocusPath();
571
598
  }
572
- emitter.emit("mainViewMounted");
599
+ internalEmitter.emit("mainViewMounted");
600
+ callbacks.emit("onMainViewMounted", mainView);
573
601
  }
574
602
 
575
603
  public setMainViewFocusPath(scenePath?: string) {
@@ -652,26 +680,10 @@ export class AppManager {
652
680
  }
653
681
 
654
682
  private displayerStateListener = (state: Partial<RoomState>) => {
655
- const sceneState = state.sceneState;
656
- if (sceneState) {
657
- const scenePath = sceneState.scenePath;
658
- this.appProxies.forEach(appProxy => {
659
- if (appProxy.scenePath && scenePath.startsWith(appProxy.scenePath)) {
660
- appProxy.emitAppSceneStateChange(sceneState);
661
- appProxy.setFullPath(scenePath);
662
- }
663
- });
664
- }
665
683
  this.appProxies.forEach(appProxy => {
666
684
  appProxy.appEmitter.emit("roomStateChange", state);
667
685
  });
668
- if (state.roomMembers) {
669
- emitter.emit("roomMembersChange", this.members);
670
- }
671
- emitter.emit("observerIdChange", this.displayer.observerId);
672
- if (state.memberState) {
673
- emitter.emit("memberStateChange", toJS(state.memberState));
674
- }
686
+ internalEmitter.emit("observerIdChange", this.displayer.observerId);
675
687
  };
676
688
 
677
689
  public displayerWritableListener = (isReadonly: boolean) => {
@@ -686,15 +698,7 @@ export class AppManager {
686
698
  this.appProxies.forEach(appProxy => {
687
699
  appProxy.emitAppIsWritableChange();
688
700
  });
689
- if (isWritable === true) {
690
- this.mainView.disableCameraTransform = false;
691
- if (this.room && this.room.disableSerialization === true) {
692
- this.room.disableSerialization = false;
693
- }
694
- } else {
695
- this.mainView.disableCameraTransform = true;
696
- }
697
- emitter.emit("writableChange", isWritable);
701
+ internalEmitter.emit("writableChange", isWritable);
698
702
  };
699
703
 
700
704
  public safeSetAttributes(attributes: any) {
@@ -758,7 +762,7 @@ export class AppManager {
758
762
  const success = this.setMainViewFocusPath(scenePath);
759
763
  if (success) {
760
764
  this.store.setMainViewScenePath(scenePath);
761
- this.safeSetAttributes({ _mainSceneIndex: index });
765
+ this.store.setMainViewSceneIndex(index);
762
766
  this.dispatchSetMainViewScenePath(scenePath);
763
767
  }
764
768
  } else {
@@ -769,6 +773,7 @@ export class AppManager {
769
773
 
770
774
  private dispatchSetMainViewScenePath(scenePath: string): void {
771
775
  this.dispatchInternalEvent(Events.SetMainViewScenePath, { nextScenePath: scenePath });
776
+ callbacks.emit("mainViewScenePathChange", scenePath);
772
777
  // 兼容 15 的 SDK, 需要 room 的当前 ScenePath
773
778
  setScenePath(this.room, scenePath);
774
779
  }
@@ -796,12 +801,16 @@ export class AppManager {
796
801
  }
797
802
 
798
803
  public async onReconnected() {
804
+ this.attributesUpdateCallback(this.attributes.apps);
799
805
  const appProxies = Array.from(this.appProxies.values());
800
806
  const reconnected = appProxies.map(appProxy => {
801
807
  return appProxy.onReconnected();
802
808
  });
803
809
  this.mainViewProxy.onReconnect();
804
810
  await Promise.all(reconnected);
811
+ if (this.callbacksNode) {
812
+ this.onSceneChange(this.callbacksNode);
813
+ }
805
814
  }
806
815
 
807
816
  public notifyContainerRectUpdate(rect: TeleBoxRect) {
@@ -826,7 +835,7 @@ export class AppManager {
826
835
  this.displayer.callbacks.off("onEnableWriteNowChanged", this.displayerWritableListener);
827
836
  this.appListeners.removeListeners();
828
837
  boxEmitter.clearListeners();
829
- emitter.clearListeners();
838
+ internalEmitter.clearListeners();
830
839
  if (this.appProxies.size) {
831
840
  this.appProxies.forEach(appProxy => {
832
841
  appProxy.destroy(true, false, true);
@@ -1,5 +1,5 @@
1
1
  import { AppAttributes } from "./constants";
2
- import { get, pick } from "lodash";
2
+ import { get, isObject, pick } from "lodash";
3
3
  import { setViewFocusScenePath } from "./Utils/Common";
4
4
  import type { AddAppParams, AppSyncAttributes } from "./index";
5
5
  import type { Camera, Size, View } from "white-web-sdk";
@@ -18,8 +18,7 @@ export enum Fields {
18
18
  CursorState = "cursorState",
19
19
  FullPath = "fullPath",
20
20
  Registered = "registered",
21
- Camera = "camera",
22
- Size = "size",
21
+ IframeBridge = "iframeBridge",
23
22
  }
24
23
 
25
24
  export type Apps = {
@@ -39,18 +38,13 @@ export type StoreContext = {
39
38
  getAttributes: () => any;
40
39
  safeUpdateAttributes: (keys: string[], value: any) => void;
41
40
  safeSetAttributes: (attributes: any) => void;
42
- }
43
-
44
- export type ICamera = Camera & {
45
- id: string; // room uid
46
41
  };
47
42
 
48
- export type ISize = Size & {
49
- id: string; // room uid
50
- };
43
+ export type ICamera = Camera & { id: string };
51
44
 
52
- export class AttributesDelegate {
45
+ export type ISize = Size & { id: string };
53
46
 
47
+ export class AttributesDelegate {
54
48
  constructor(private context: StoreContext) {}
55
49
 
56
50
  public setContext(context: StoreContext) {
@@ -114,10 +108,6 @@ export class AttributesDelegate {
114
108
  }
115
109
  }
116
110
 
117
- public updateAppAttributes(appId: string, key: string, value: any) {
118
- this.context.safeUpdateAttributes([Fields.Apps, appId, key], value);
119
- }
120
-
121
111
  public cleanAppAttributes(id: string) {
122
112
  this.context.safeUpdateAttributes([Fields.Apps, id], undefined);
123
113
  this.context.safeSetAttributes({ [id]: undefined });
@@ -159,11 +149,11 @@ export class AttributesDelegate {
159
149
  this.context.safeSetAttributes({ _mainSceneIndex: index });
160
150
  }
161
151
 
162
- public getMainViewCamera(): ICamera {
152
+ public getMainViewCamera(): MainViewCamera {
163
153
  return get(this.attributes, [Fields.MainViewCamera]);
164
154
  }
165
155
 
166
- public getMainViewSize(): ISize {
156
+ public getMainViewSize(): MainViewSize {
167
157
  return get(this.attributes, [Fields.MainViewSize]);
168
158
  }
169
159
 
@@ -172,10 +162,12 @@ export class AttributesDelegate {
172
162
  }
173
163
 
174
164
  public setMainViewSize(size: ISize) {
165
+ if (size.width === 0 || size.height === 0) return;
175
166
  this.context.safeSetAttributes({ [Fields.MainViewSize]: { ...size } });
176
167
  }
177
168
 
178
169
  public setMainViewCameraAndSize(camera: ICamera, size: ISize) {
170
+ if (size.width === 0 || size.height === 0) return;
179
171
  this.context.safeSetAttributes({
180
172
  [Fields.MainViewCamera]: { ...camera },
181
173
  [Fields.MainViewSize]: { ...size },
@@ -188,7 +180,7 @@ export class AttributesDelegate {
188
180
  } else {
189
181
  this.context.safeSetAttributes({ [Fields.Focus]: undefined });
190
182
  }
191
- }
183
+ };
192
184
 
193
185
  public updateCursor(uid: string, position: Position) {
194
186
  if (!get(this.attributes, [Fields.Cursors])) {
@@ -222,21 +214,49 @@ export class AttributesDelegate {
222
214
  setViewFocusScenePath(mainView, scenePath);
223
215
  }
224
216
  }
217
+
218
+ public getIframeBridge() {
219
+ return get(this.attributes, [Fields.IframeBridge]);
220
+ }
221
+
222
+ public setIframeBridge(data: any) {
223
+ if (isObject(data)) {
224
+ const oldState = this.getIframeBridge();
225
+ for (const key in data) {
226
+ const value = (data as any)[key];
227
+ if (oldState[key] !== value) {
228
+ this.context.safeUpdateAttributes([Fields.IframeBridge, key], value);
229
+ }
230
+ }
231
+ }
232
+ }
225
233
  }
226
234
 
235
+ export type MainViewSize = {
236
+ id: string;
237
+ width: number;
238
+ height: number;
239
+ };
240
+
241
+ export type MainViewCamera = {
242
+ id: string;
243
+ centerX: number;
244
+ centerY: number;
245
+ scale: number;
246
+ };
247
+
227
248
  export type Cursors = {
228
249
  [key: string]: Cursor;
229
250
  };
230
251
 
231
-
232
252
  export const store = new AttributesDelegate({
233
253
  getAttributes: () => {
234
- throw new Error("getAttributes not implemented")
254
+ throw new Error("getAttributes not implemented");
235
255
  },
236
256
  safeSetAttributes: () => {
237
- throw new Error("safeSetAttributes not implemented")
257
+ throw new Error("safeSetAttributes not implemented");
238
258
  },
239
259
  safeUpdateAttributes: () => {
240
- throw new Error("safeUpdateAttributes not implemented")
260
+ throw new Error("safeUpdateAttributes not implemented");
241
261
  },
242
262
  });
package/src/BoxEmitter.ts CHANGED
@@ -1,19 +1,25 @@
1
1
  import type { TELE_BOX_STATE } from "@netless/telebox-insider";
2
2
  import Emittery from "emittery";
3
3
 
4
- export type BoxMovePayload = { appId: string, x: number; y: number };
4
+ export type BoxMovePayload = { appId: string; x: number; y: number };
5
5
  export type BoxFocusPayload = { appId: string };
6
- export type BoxResizePayload = { appId: string, width: number; height: number, x?: number, y?: number };
7
- export type BoxClosePayload = { appId: string, error?: Error };
8
- export type BoxStateChangePayload = { appId: string, state: TELE_BOX_STATE };
6
+ export type BoxResizePayload = {
7
+ appId: string;
8
+ width: number;
9
+ height: number;
10
+ x?: number;
11
+ y?: number;
12
+ };
13
+ export type BoxClosePayload = { appId: string; error?: Error };
14
+ export type BoxStateChangePayload = { appId: string; state: TELE_BOX_STATE };
9
15
 
10
16
  export type BoxEvent = {
11
17
  move: BoxMovePayload;
12
18
  focus: BoxFocusPayload;
13
19
  resize: BoxResizePayload;
14
20
  close: BoxClosePayload;
15
- boxStateChange: BoxStateChangePayload
16
- }
21
+ boxStateChange: BoxStateChangePayload;
22
+ };
17
23
 
18
24
  export type BoxEmitterType = Emittery<BoxEvent>;
19
25
  export const boxEmitter: BoxEmitterType = new Emittery();