@netless/window-manager 0.4.30-canary.0 → 0.4.31

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.4.30-canary.0",
3
+ "version": "0.4.31",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
@@ -45,6 +45,7 @@
45
45
  "@types/uuid": "^8.3.1",
46
46
  "@typescript-eslint/eslint-plugin": "^4.30.0",
47
47
  "@typescript-eslint/parser": "^4.30.0",
48
+ "@vitest/ui": "^0.14.1",
48
49
  "cypress": "^8.7.0",
49
50
  "dotenv": "^10.0.0",
50
51
  "eslint": "^7.32.0",
@@ -59,7 +60,7 @@
59
60
  "svelte": "^3.42.4",
60
61
  "typescript": "^4.5.5",
61
62
  "vite": "^2.5.3",
62
- "vitest": "^0.12.4",
63
+ "vitest": "^0.14.1",
63
64
  "white-web-sdk": "2.16.10"
64
65
  }
65
66
  }
package/pnpm-lock.yaml CHANGED
@@ -16,6 +16,7 @@ specifiers:
16
16
  '@types/uuid': ^8.3.1
17
17
  '@typescript-eslint/eslint-plugin': ^4.30.0
18
18
  '@typescript-eslint/parser': ^4.30.0
19
+ '@vitest/ui': ^0.14.1
19
20
  cypress: ^8.7.0
20
21
  dotenv: ^10.0.0
21
22
  emittery: ^0.9.2
@@ -36,7 +37,7 @@ specifiers:
36
37
  uuid: ^7.0.3
37
38
  video.js: '>=7'
38
39
  vite: ^2.5.3
39
- vitest: ^0.12.4
40
+ vitest: ^0.14.1
40
41
  white-web-sdk: 2.16.10
41
42
 
42
43
  dependencies:
@@ -63,6 +64,7 @@ devDependencies:
63
64
  '@types/uuid': registry.npmmirror.com/@types/uuid/8.3.4
64
65
  '@typescript-eslint/eslint-plugin': registry.npmmirror.com/@typescript-eslint/eslint-plugin/4.33.0_bre6cjtjfaculj7kh43nxjxlbi
65
66
  '@typescript-eslint/parser': registry.npmmirror.com/@typescript-eslint/parser/4.33.0_hrkuebk64jiu2ut2d2sm4oylnu
67
+ '@vitest/ui': 0.14.1
66
68
  cypress: registry.npmmirror.com/cypress/8.7.0
67
69
  dotenv: registry.npmmirror.com/dotenv/10.0.0
68
70
  eslint: registry.npmmirror.com/eslint/7.32.0
@@ -77,7 +79,7 @@ devDependencies:
77
79
  svelte: registry.npmmirror.com/svelte/3.46.4
78
80
  typescript: registry.npmmirror.com/typescript/4.6.3
79
81
  vite: registry.npmmirror.com/vite/2.8.6_less@4.1.2
80
- vitest: 0.12.4_jsdom@19.0.0+less@4.1.2
82
+ vitest: 0.14.1_nmqrau6oupbkt73pq2ukep6chi
81
83
  white-web-sdk: registry.npmmirror.com/white-web-sdk/2.16.10
82
84
 
83
85
  packages:
@@ -94,6 +96,10 @@ packages:
94
96
  vanilla-lazyload: 17.6.1
95
97
  dev: true
96
98
 
99
+ /@polka/url/1.0.0-next.21:
100
+ resolution: {integrity: sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==}
101
+ dev: true
102
+
97
103
  /@tootallnate/once/2.0.0:
98
104
  resolution: {integrity: sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==}
99
105
  engines: {node: '>= 10'}
@@ -113,14 +119,20 @@ packages:
113
119
  resolution: {integrity: sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==}
114
120
  dev: true
115
121
 
116
- /@types/yauzl/2.9.2:
117
- resolution: {integrity: sha512-8uALY5LTvSuHgloDVUvWP3pIauILm+8/0pDMokuDYIoNsOkSwd5AiHBTSEJjKTDcZr5z8UpgOWZkxBF4iJftoA==}
122
+ /@types/yauzl/2.10.0:
123
+ resolution: {integrity: sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==}
118
124
  requiresBuild: true
119
125
  dependencies:
120
126
  '@types/node': registry.npmmirror.com/@types/node/17.0.23
121
127
  dev: true
122
128
  optional: true
123
129
 
130
+ /@vitest/ui/0.14.1:
131
+ resolution: {integrity: sha512-rWhltzClVxTT9ktnS9DBQUe3RdRweP+XF1LspK5i3e+P66gn3rc2LChol3EYPYHJghL2Xsm91lvQO1pgE4vgHA==}
132
+ dependencies:
133
+ sirv: 2.0.2
134
+ dev: true
135
+
124
136
  /abab/2.0.5:
125
137
  resolution: {integrity: sha512-9IK9EadsbHo6jLWIpxpR6pL0sazTXV6+SQv25ZB+F7Bj9mJNaOc4nCRabwd5M/JwmUa8idz6Eci6eKfJryPs6Q==}
126
138
  dev: true
@@ -188,7 +200,7 @@ packages:
188
200
  dev: true
189
201
 
190
202
  /check-error/1.0.2:
191
- resolution: {integrity: sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=}
203
+ resolution: {integrity: sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==}
192
204
  dev: true
193
205
 
194
206
  /colors/1.4.0:
@@ -236,6 +248,18 @@ packages:
236
248
  mimic-fn: 4.0.0
237
249
  dev: true
238
250
 
251
+ /debug/3.2.7:
252
+ resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==}
253
+ peerDependencies:
254
+ supports-color: '*'
255
+ peerDependenciesMeta:
256
+ supports-color:
257
+ optional: true
258
+ dependencies:
259
+ ms: 2.1.3
260
+ dev: true
261
+ optional: true
262
+
239
263
  /debug/4.3.4:
240
264
  resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==}
241
265
  engines: {node: '>=6.0'}
@@ -547,11 +571,11 @@ packages:
547
571
  dev: true
548
572
 
549
573
  /get-func-name/2.0.0:
550
- resolution: {integrity: sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=}
574
+ resolution: {integrity: sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==}
551
575
  dev: true
552
576
 
553
- /graceful-fs/4.2.9:
554
- resolution: {integrity: sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==}
577
+ /graceful-fs/4.2.10:
578
+ resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==}
555
579
  dev: true
556
580
  optional: true
557
581
 
@@ -598,7 +622,7 @@ packages:
598
622
  dev: true
599
623
 
600
624
  /image-size/0.5.5:
601
- resolution: {integrity: sha1-Cd/Uq50g4p6xw+gLiZA3jfnjy5w=}
625
+ resolution: {integrity: sha512-6TDAlDPZxUFCv+fuOkIoXT/V/f3Qbq8e37p+YOiYrUv3v9cc3/6x78VdfPgFVaB9dZYeLUfKgHRebpkm/oP2VQ==}
602
626
  engines: {node: '>=0.10.0'}
603
627
  hasBin: true
604
628
  requiresBuild: true
@@ -711,10 +735,19 @@ packages:
711
735
  engines: {node: '>=12'}
712
736
  dev: true
713
737
 
738
+ /mrmime/1.0.1:
739
+ resolution: {integrity: sha512-hzzEagAgDyoU1Q6yg5uI+AorQgdvMCur3FcKf7NhMKWsaYg+RnbTyHRa/9IlLF9rf455MOCtcqqrQQ83pPP7Uw==}
740
+ engines: {node: '>=10'}
741
+ dev: true
742
+
714
743
  /ms/2.1.2:
715
744
  resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
716
745
  dev: true
717
746
 
747
+ /ms/2.1.3:
748
+ resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
749
+ dev: true
750
+
718
751
  /nanoid/3.3.4:
719
752
  resolution: {integrity: sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==}
720
753
  engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
@@ -727,7 +760,7 @@ packages:
727
760
  hasBin: true
728
761
  requiresBuild: true
729
762
  dependencies:
730
- debug: registry.npmmirror.com/debug/3.2.7
763
+ debug: 3.2.7
731
764
  iconv-lite: registry.npmmirror.com/iconv-lite/0.4.24
732
765
  sax: registry.npmmirror.com/sax/1.2.4
733
766
  transitivePeerDependencies:
@@ -818,6 +851,15 @@ packages:
818
851
  xmlchars: 2.2.0
819
852
  dev: true
820
853
 
854
+ /sirv/2.0.2:
855
+ resolution: {integrity: sha512-4Qog6aE29nIjAOKe/wowFTxOdmbEZKb+3tsLljaBRzJwtqto0BChD2zzH0LhgCSXiI+V7X+Y45v14wBZQ1TK3w==}
856
+ engines: {node: '>= 10'}
857
+ dependencies:
858
+ '@polka/url': 1.0.0-next.21
859
+ mrmime: 1.0.1
860
+ totalist: 3.0.0
861
+ dev: true
862
+
821
863
  /source-map-js/1.0.2:
822
864
  resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==}
823
865
  engines: {node: '>=0.10.0'}
@@ -847,6 +889,11 @@ packages:
847
889
  engines: {node: '>=14.0.0'}
848
890
  dev: true
849
891
 
892
+ /totalist/3.0.0:
893
+ resolution: {integrity: sha512-eM+pCBxXO/njtF7vdFsHuqb+ElbxqtI4r5EAvk6grfAFyJ6IvWlSkfZ5T9ozC6xWw3Fj1fGoSmrl0gUs46JVIw==}
894
+ engines: {node: '>=6'}
895
+ dev: true
896
+
850
897
  /tough-cookie/4.0.0:
851
898
  resolution: {integrity: sha512-tHdtEpQCMrc1YLrMaqXXcj6AxhYi/xgit6mZu1+EDWUn+qhUf8wMQoFIy9NXuq23zAwtcB0t/MjACGR18pcRbg==}
852
899
  engines: {node: '>=6'}
@@ -909,8 +956,8 @@ packages:
909
956
  fsevents: 2.3.2
910
957
  dev: true
911
958
 
912
- /vitest/0.12.4_jsdom@19.0.0+less@4.1.2:
913
- resolution: {integrity: sha512-EDxdhlAt6vcu6y4VouAI60z78iCAVFnfBL4VlSQVQnGmOk5altOtIKvp3xfZ+cfo4iVHgqq1QNyf5qOFiL4leg==}
959
+ /vitest/0.14.1_nmqrau6oupbkt73pq2ukep6chi:
960
+ resolution: {integrity: sha512-2UUm6jYgkwh7Y3VKSRR8OuaNCm+iA5LPDnal7jyITN39maZK9L+JVxqjtQ39PSFo5Fl3/BgaJvER6GGHX9JLxg==}
914
961
  engines: {node: '>=v14.16.0'}
915
962
  hasBin: true
916
963
  peerDependencies:
@@ -930,7 +977,9 @@ packages:
930
977
  dependencies:
931
978
  '@types/chai': 4.3.1
932
979
  '@types/chai-subset': 1.3.3
980
+ '@vitest/ui': 0.14.1
933
981
  chai: 4.3.6
982
+ debug: 4.3.4
934
983
  jsdom: 19.0.0
935
984
  local-pkg: 0.4.1
936
985
  tinypool: 0.1.3
@@ -940,6 +989,7 @@ packages:
940
989
  - less
941
990
  - sass
942
991
  - stylus
992
+ - supports-color
943
993
  dev: true
944
994
 
945
995
  /w3c-hr-time/1.0.2:
@@ -2477,20 +2527,6 @@ packages:
2477
2527
  version: 1.11.0
2478
2528
  dev: true
2479
2529
 
2480
- registry.npmmirror.com/debug/3.2.7:
2481
- resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/debug/-/debug-3.2.7.tgz}
2482
- name: debug
2483
- version: 3.2.7
2484
- peerDependencies:
2485
- supports-color: '*'
2486
- peerDependenciesMeta:
2487
- supports-color:
2488
- optional: true
2489
- dependencies:
2490
- ms: registry.npmmirror.com/ms/2.1.3
2491
- dev: true
2492
- optional: true
2493
-
2494
2530
  registry.npmmirror.com/debug/3.2.7_supports-color@8.1.1:
2495
2531
  resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/debug/-/debug-3.2.7.tgz}
2496
2532
  id: registry.npmmirror.com/debug/3.2.7
@@ -2502,7 +2538,7 @@ packages:
2502
2538
  supports-color:
2503
2539
  optional: true
2504
2540
  dependencies:
2505
- ms: registry.npmmirror.com/ms/2.1.3
2541
+ ms: 2.1.3
2506
2542
  supports-color: registry.npmmirror.com/supports-color/8.1.1
2507
2543
  dev: true
2508
2544
 
@@ -3086,7 +3122,7 @@ packages:
3086
3122
  get-stream: registry.npmmirror.com/get-stream/5.2.0
3087
3123
  yauzl: registry.npmmirror.com/yauzl/2.10.0
3088
3124
  optionalDependencies:
3089
- '@types/yauzl': 2.9.2
3125
+ '@types/yauzl': 2.10.0
3090
3126
  transitivePeerDependencies:
3091
3127
  - supports-color
3092
3128
  dev: true
@@ -3915,7 +3951,7 @@ packages:
3915
3951
  dependencies:
3916
3952
  universalify: registry.npmmirror.com/universalify/2.0.0
3917
3953
  optionalDependencies:
3918
- graceful-fs: 4.2.9
3954
+ graceful-fs: 4.2.10
3919
3955
  dev: true
3920
3956
 
3921
3957
  registry.npmmirror.com/jsprim/2.0.2:
@@ -3962,7 +3998,7 @@ packages:
3962
3998
  tslib: registry.npmmirror.com/tslib/2.3.1
3963
3999
  optionalDependencies:
3964
4000
  errno: 0.1.8
3965
- graceful-fs: 4.2.9
4001
+ graceful-fs: 4.2.10
3966
4002
  image-size: 0.5.5
3967
4003
  make-dir: 2.1.0
3968
4004
  mime: 1.6.0
@@ -4309,12 +4345,6 @@ packages:
4309
4345
  version: 2.1.2
4310
4346
  dev: true
4311
4347
 
4312
- registry.npmmirror.com/ms/2.1.3:
4313
- resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz}
4314
- name: ms
4315
- version: 2.1.3
4316
- dev: true
4317
-
4318
4348
  registry.npmmirror.com/mux.js/6.0.1:
4319
4349
  resolution: {integrity: sha512-22CHb59rH8pWGcPGW5Og7JngJ9s+z4XuSlYvnxhLuc58cA1WqGDQPzuG8I+sPm1/p0CdgpzVTaKW408k5DNn8w==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/mux.js/-/mux.js-6.0.1.tgz}
4320
4350
  name: mux.js
@@ -29,6 +29,7 @@ import type { NetlessApp } from "../typings";
29
29
  import type { ReadonlyTeleBox } from "@netless/telebox-insider";
30
30
  import type { PageRemoveService, PageState } from "../Page";
31
31
  import { calculateNextIndex } from "../Page";
32
+ import { boxEmitter } from "../BoxEmitter";
32
33
 
33
34
  export type AppEmitter = Emittery<AppEmitterEvent>;
34
35
 
@@ -241,6 +242,11 @@ export class AppProxy implements PageRemoveService {
241
242
  }
242
243
 
243
244
  public async onReconnected() {
245
+ const isExist = Boolean(this.manager.attributes.apps[this.id]);
246
+ if (!isExist) {
247
+ await this.destroy(true, false, true);
248
+ return;
249
+ }
244
250
  this.appEmitter.emit("reconnected", undefined);
245
251
  const currentAppState = this.getAppInitState(this.id);
246
252
  await this.destroy(true, false, true);
@@ -337,7 +343,7 @@ export class AppProxy implements PageRemoveService {
337
343
  }
338
344
  case "focus": {
339
345
  this.boxManager?.focusBox({ appId: this.id });
340
- emitter.emit("focus", { appId: this.id });
346
+ boxEmitter.emit("focus", { appId: this.id });
341
347
  break;
342
348
  }
343
349
  default: {
package/src/AppManager.ts CHANGED
@@ -4,6 +4,8 @@ import { AppListeners } from "./AppListener";
4
4
  import { AppProxy } from "./App";
5
5
  import { appRegister } from "./Register";
6
6
  import { autorun, isPlayer, isRoom, ScenePathType } from "white-web-sdk";
7
+ import { boxEmitter } from "./BoxEmitter";
8
+ import { calculateNextIndex } from "./Page";
7
9
  import { callbacks } from "./callback";
8
10
  import { debounce, get, isInteger, orderBy } from "lodash";
9
11
  import { emitter } from "./InternalEmitter";
@@ -16,7 +18,7 @@ import { RedoUndo } from "./RedoUndo";
16
18
  import { SideEffectManager } from "side-effect-manager";
17
19
  import { ViewManager } from "./View/ViewManager";
18
20
  import type { SyncRegisterAppPayload } from "./Register";
19
- import type { EmitterEvent , RemoveSceneParams } from "./InternalEmitter";
21
+ import type { RemoveSceneParams } from "./InternalEmitter";
20
22
  import {
21
23
  entireScenes,
22
24
  genAppId,
@@ -37,7 +39,14 @@ import type {
37
39
  SceneState,
38
40
  } from "white-web-sdk";
39
41
  import type { AddAppParams, BaseInsertParams, TeleBoxRect } from "./index";
40
- import { calculateNextIndex } from "./Page";
42
+ import type {
43
+ BoxClosePayload,
44
+ BoxFocusPayload,
45
+ BoxMovePayload,
46
+ BoxResizePayload,
47
+ BoxStateChangePayload,
48
+ } from "./BoxEmitter";
49
+
41
50
 
42
51
  export class AppManager {
43
52
  public displayer: Displayer;
@@ -202,27 +211,30 @@ export class AppManager {
202
211
  const scene = this.callbacksNode?.scenes[index];
203
212
  setTimeout(() => {
204
213
  if (scene) {
205
- removeScenes(this.room, `${ROOT_DIR}${scene}`, index)
214
+ removeScenes(this.room, `${ROOT_DIR}${scene}`, index);
206
215
  }
207
216
  }, 100);
208
217
  return new Promise<boolean>((resolve, reject) => {
209
- emitter.once("rootDirSceneRemoved").then(name => {
210
- if (name === scene) {
211
- resolve(true);
212
- }
213
- }).catch(e => {
214
- console.log(`[WindowManager]: removePage error: ${e}`);
215
- reject(false);
216
- });
218
+ emitter
219
+ .once("rootDirSceneRemoved")
220
+ .then(name => {
221
+ if (name === scene) {
222
+ resolve(true);
223
+ }
224
+ })
225
+ .catch(e => {
226
+ console.log(`[WindowManager]: removePage error: ${e}`);
227
+ reject(false);
228
+ });
217
229
  });
218
- }
230
+ };
219
231
 
220
232
  public setSceneIndexWithoutSync = (index: number) => {
221
233
  const sceneName = this.callbacksNode?.scenes[index];
222
234
  if (sceneName) {
223
235
  this.mainViewProxy.setFocusScenePath(`${ROOT_DIR}${sceneName}`);
224
236
  }
225
- }
237
+ };
226
238
 
227
239
  private onSceneChange = (node: ScenesCallbacksNode) => {
228
240
  this.mainViewScenesLength = node.scenes.length;
@@ -299,7 +311,11 @@ export class AppManager {
299
311
  private async onCreated() {
300
312
  await this.attributesUpdateCallback(this.attributes.apps);
301
313
  emitter.emit("updateManagerRect");
302
- emitter.onAny(this.boxEventListener);
314
+ boxEmitter.on("move", this.onBoxMove);
315
+ boxEmitter.on("resize", this.onBoxResize);
316
+ boxEmitter.on("focus", this.onBoxFocus);
317
+ boxEmitter.on("close", this.onBoxClose);
318
+ boxEmitter.on("boxStateChange", this.onBoxStateChange);
303
319
 
304
320
  this.addAppsChangeListener();
305
321
  this.addAppCloseListener();
@@ -352,6 +368,39 @@ export class AppManager {
352
368
  });
353
369
  }
354
370
 
371
+ private onBoxMove = (payload: BoxMovePayload) => {
372
+ this.dispatchInternalEvent(Events.AppMove, payload);
373
+ this.store.updateAppState(payload.appId, AppAttributes.Position, {
374
+ x: payload.x,
375
+ y: payload.y,
376
+ });
377
+ };
378
+
379
+ private onBoxResize = (payload: BoxResizePayload) => {
380
+ if (payload.width && payload.height) {
381
+ this.dispatchInternalEvent(Events.AppResize, payload);
382
+ this.store.updateAppState(payload.appId, AppAttributes.Size, {
383
+ width: payload.width,
384
+ height: payload.height,
385
+ });
386
+ }
387
+ };
388
+
389
+ private onBoxFocus = (payload: BoxFocusPayload) => {
390
+ this.windowManger.safeSetAttributes({ focus: payload.appId });
391
+ };
392
+
393
+ private onBoxClose = (payload: BoxClosePayload) => {
394
+ const appProxy = this.appProxies.get(payload.appId);
395
+ if (appProxy) {
396
+ appProxy.destroy(false, true, true, payload.error);
397
+ }
398
+ };
399
+
400
+ private onBoxStateChange = (payload: BoxStateChangePayload) => {
401
+ this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
402
+ };
403
+
355
404
  public addAppsChangeListener = () => {
356
405
  this.refresher?.add("apps", () => {
357
406
  return safeListenPropsUpdated(
@@ -371,7 +420,6 @@ export class AppManager {
371
420
  });
372
421
  };
373
422
 
374
-
375
423
  private onMainViewIndexChange = (index: number) => {
376
424
  if (index !== undefined && this._prevSceneIndex !== index) {
377
425
  callbacks.emit("mainViewSceneIndexChange", index);
@@ -432,7 +480,7 @@ export class AppManager {
432
480
  if (!appAttributes) {
433
481
  throw new Error("appAttributes is undefined");
434
482
  }
435
- this.appCreateQueue.push(() => {
483
+ this.appCreateQueue.push<AppProxy>(() => {
436
484
  this.appStatus.set(id, AppStatus.StartCreate);
437
485
  return this.baseInsertApp(
438
486
  {
@@ -558,7 +606,7 @@ export class AppManager {
558
606
  private afterAddApp(appProxy: AppProxy | undefined) {
559
607
  if (appProxy && appProxy.box) {
560
608
  const box = appProxy.box;
561
- emitter.emit("move", {
609
+ boxEmitter.emit("move", {
562
610
  appId: appProxy.id,
563
611
  x: box?.intrinsicX,
564
612
  y: box?.intrinsicY,
@@ -694,7 +742,7 @@ export class AppManager {
694
742
  if (this.room) {
695
743
  if (this.store.getMainViewSceneIndex() === index) return;
696
744
  const sceneName = this.callbacksNode?.scenes[index];
697
- const scenePath =`${ROOT_DIR}${sceneName}`;
745
+ const scenePath = `${ROOT_DIR}${sceneName}`;
698
746
  if (sceneName) {
699
747
  const success = this.setMainViewFocusPath(scenePath);
700
748
  if (success) {
@@ -727,46 +775,6 @@ export class AppManager {
727
775
  }
728
776
  }
729
777
 
730
- private boxEventListener = (eventName: keyof EmitterEvent, payload: any) => {
731
- switch (eventName) {
732
- case "move": {
733
- this.dispatchInternalEvent(Events.AppMove, payload);
734
- this.store.updateAppState(payload.appId, AppAttributes.Position, {
735
- x: payload.x,
736
- y: payload.y,
737
- });
738
- break;
739
- }
740
- case "focus": {
741
- this.windowManger.safeSetAttributes({ focus: payload.appId });
742
- break;
743
- }
744
- case "resize": {
745
- if (payload.width && payload.height) {
746
- this.dispatchInternalEvent(Events.AppResize, payload);
747
- this.store.updateAppState(payload.appId, AppAttributes.Size, {
748
- width: payload.width,
749
- height: payload.height,
750
- });
751
- }
752
- break;
753
- }
754
- case "close": {
755
- const appProxy = this.appProxies.get(payload.appId);
756
- if (appProxy) {
757
- appProxy.destroy(false, true, payload.error);
758
- }
759
- break;
760
- }
761
- case "boxStateChange": {
762
- this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
763
- break;
764
- }
765
- default:
766
- break;
767
- }
768
- };
769
-
770
778
  public focusByAttributes(apps: any) {
771
779
  if (apps && Object.keys(apps).length === this.boxManager?.boxSize) {
772
780
  const focusAppId = this.store.focus;
@@ -806,7 +814,7 @@ export class AppManager {
806
814
  this.displayer.callbacks.off(this.eventName, this.displayerStateListener);
807
815
  this.displayer.callbacks.off("onEnableWriteNowChanged", this.displayerWritableListener);
808
816
  this.appListeners.removeListeners();
809
- emitter.offAny(this.boxEventListener);
817
+ boxEmitter.clearListeners();
810
818
  emitter.clearListeners();
811
819
  if (this.appProxies.size) {
812
820
  this.appProxies.forEach(appProxy => {
@@ -0,0 +1,19 @@
1
+ import type { TELE_BOX_STATE } from "@netless/telebox-insider";
2
+ import Emittery from "emittery";
3
+
4
+ export type BoxMovePayload = { appId: string, x: number; y: number };
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 };
9
+
10
+ export type BoxEvent = {
11
+ move: BoxMovePayload;
12
+ focus: BoxFocusPayload;
13
+ resize: BoxResizePayload;
14
+ close: BoxClosePayload;
15
+ boxStateChange: BoxStateChangePayload
16
+ }
17
+
18
+ export type BoxEmitterType = Emittery<BoxEvent>;
19
+ export const boxEmitter: BoxEmitterType = new Emittery();
package/src/BoxManager.ts CHANGED
@@ -2,6 +2,7 @@ import { AppAttributes, Events, MIN_HEIGHT, MIN_WIDTH } from "./constants";
2
2
  import { debounce } from "lodash";
3
3
  import { TELE_BOX_STATE, TeleBoxCollector, TeleBoxManager } from "@netless/telebox-insider";
4
4
  import { WindowManager } from "./index";
5
+ import type { BoxEmitterType } from "./BoxEmitter";
5
6
  import type { AddAppOptions, AppInitState } from "./index";
6
7
  import type {
7
8
  TeleBoxManagerUpdateConfig,
@@ -51,6 +52,7 @@ export type BoxManagerContext = {
51
52
  getMainView: () => View;
52
53
  updateAppState: (appId: string, field: AppAttributes, value: any) => void;
53
54
  emitter: EmitterType;
55
+ boxEmitter: BoxEmitterType;
54
56
  callbacks: CallbacksType;
55
57
  canOperate: () => boolean;
56
58
  notifyContainerRectUpdate: (rect: TeleBoxRect) => void;
@@ -62,6 +64,7 @@ export const createBoxManager = (
62
64
  manager: WindowManager,
63
65
  callbacks: CallbacksType,
64
66
  emitter: EmitterType,
67
+ boxEmitter: BoxEmitterType,
65
68
  options: CreateTeleBoxManagerConfig
66
69
  ) => {
67
70
  return new BoxManager(
@@ -76,6 +79,7 @@ export const createBoxManager = (
76
79
  setAppFocus: (appId: string) => manager.appManager?.store.setAppFocus(appId, true),
77
80
  callbacks,
78
81
  emitter,
82
+ boxEmitter
79
83
  },
80
84
  options
81
85
  );
@@ -88,7 +92,7 @@ export class BoxManager {
88
92
  private context: BoxManagerContext,
89
93
  private createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig
90
94
  ) {
91
- const { emitter, callbacks } = context;
95
+ const { emitter, callbacks, boxEmitter } = context;
92
96
  this.teleBoxManager = this.setupBoxManager(createTeleBoxManagerConfig);
93
97
 
94
98
  // 使用 _xxx$.reaction 订阅修改的值, 不管有没有 skipUpdate, 修改值都会触发回调
@@ -123,19 +127,19 @@ export class BoxManager {
123
127
  });
124
128
  this.teleBoxManager.events.on("removed", boxes => {
125
129
  boxes.forEach(box => {
126
- emitter.emit("close", { appId: box.id });
130
+ boxEmitter.emit("close", { appId: box.id });
127
131
  });
128
132
  });
129
133
  this.teleBoxManager.events.on(
130
134
  "intrinsic_move",
131
135
  debounce((box: ReadonlyTeleBox): void => {
132
- emitter.emit("move", { appId: box.id, x: box.intrinsicX, y: box.intrinsicY });
136
+ boxEmitter.emit("move", { appId: box.id, x: box.intrinsicX, y: box.intrinsicY });
133
137
  }, 50)
134
138
  );
135
139
  this.teleBoxManager.events.on(
136
140
  "intrinsic_resize",
137
141
  debounce((box: ReadonlyTeleBox): void => {
138
- emitter.emit("resize", {
142
+ boxEmitter.emit("resize", {
139
143
  appId: box.id,
140
144
  width: box.intrinsicWidth,
141
145
  height: box.intrinsicHeight,
@@ -145,7 +149,7 @@ export class BoxManager {
145
149
  this.teleBoxManager.events.on("focused", box => {
146
150
  if (box) {
147
151
  if (this.canOperate) {
148
- emitter.emit("focus", { appId: box.id });
152
+ boxEmitter.emit("focus", { appId: box.id });
149
153
  } else {
150
154
  this.teleBoxManager.blurBox(box.id);
151
155
  }
@@ -221,7 +225,7 @@ export class BoxManager {
221
225
  const box = this.teleBoxManager.queryOne({ id: appId });
222
226
  if (box) {
223
227
  if (box.state === TELE_BOX_STATE.Maximized) {
224
- this.context.emitter.emit("resize", {
228
+ this.context.boxEmitter.emit("resize", {
225
229
  appId: appId,
226
230
  x: box.x,
227
231
  y: box.y,
@@ -8,10 +8,6 @@ export type RemoveSceneParams = {
8
8
  export type EmitterEvent = {
9
9
  onCreated: undefined;
10
10
  InitReplay: AppInitState;
11
- move: { appId: string; x: number; y: number };
12
- focus: { appId: string };
13
- close: { appId: string };
14
- resize: { appId: string; width: number; height: number; x?: number; y?: number };
15
11
  error: Error;
16
12
  seekStart: undefined;
17
13
  seek: number;