@netless/window-manager 1.0.0-canary.0 → 1.0.0-canary.3

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/index.es.js CHANGED
@@ -19,10 +19,11 @@ var __spreadValues = (a2, b2) => {
19
19
  var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
20
20
  import pRetry from "p-retry";
21
21
  import Emittery from "emittery";
22
- import { debounce, isEqual, omit, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, throttle, delay, isInteger, orderBy, isEmpty, isFunction, isNumber, isNull } from "lodash";
23
- import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, autorun, toJS, listenDisposed, unlistenDisposed, AnimationMode, isPlayer, isRoom, WhiteVersion, ApplianceNames, RoomPhase, InvisiblePlugin, ViewMode } from "white-web-sdk";
22
+ import { debounce, isEqual, omit, isObject, has, get, size as size$1, mapValues, noop as noop$1, isNumber, pick, throttle, delay, isInteger, orderBy, isEmpty, isFunction, isNull } from "lodash";
23
+ import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, WhiteVersion, autorun, toJS, listenDisposed, unlistenDisposed, AnimationMode, isPlayer, isRoom, ApplianceNames, RoomPhase, InvisiblePlugin, ViewMode } from "white-web-sdk";
24
24
  import { v4 } from "uuid";
25
25
  import { genUID, SideEffectManager } from "side-effect-manager";
26
+ import { Val, ValManager, combine, withReadonlyValueEnhancer, withValueEnhancer, derive } from "value-enhancer";
26
27
  import { ResizeObserver as ResizeObserver$2 } from "@juggle/resize-observer";
27
28
  import p$1 from "video.js";
28
29
  var Events = /* @__PURE__ */ ((Events2) => {
@@ -77,6 +78,7 @@ const DEFAULT_CONTAINER_RATIO = 9 / 16;
77
78
  const ROOT_DIR = "/";
78
79
  const INIT_DIR = "/init";
79
80
  const SETUP_APP_DELAY = 50;
81
+ const MAX_PAGE_SIZE = 500;
80
82
  const callbacks$1 = new Emittery();
81
83
  class AppCreateQueue {
82
84
  constructor() {
@@ -688,7 +690,7 @@ class Storage {
688
690
  this.id = id2 || null;
689
691
  this._state = {};
690
692
  const rawState = this._getRawState(this._state);
691
- if (this._context.getIsWritable()) {
693
+ if (this._context.isWritable) {
692
694
  if (this.id === null) {
693
695
  if (context.isAddApp && defaultState) {
694
696
  this.setState(defaultState);
@@ -748,7 +750,7 @@ class Storage {
748
750
  console.error(new Error(`Cannot call setState on destroyed Storage "${this.id}".`));
749
751
  return;
750
752
  }
751
- if (!this._context.getIsWritable()) {
753
+ if (!this._context.isWritable) {
752
754
  console.error(new Error(`Cannot setState on Storage "${this.id}" without writable access`), state);
753
755
  return;
754
756
  }
@@ -788,7 +790,7 @@ class Storage {
788
790
  console.error(new Error(`Cannot empty destroyed Storage "${this.id}".`));
789
791
  return;
790
792
  }
791
- if (!this._context.getIsWritable()) {
793
+ if (!this._context.isWritable) {
792
794
  console.error(new Error(`Cannot empty Storage "${this.id}" without writable access.`));
793
795
  return;
794
796
  }
@@ -798,7 +800,7 @@ class Storage {
798
800
  if (this.id === null) {
799
801
  throw new Error(`Cannot delete main Storage`);
800
802
  }
801
- if (!this._context.getIsWritable()) {
803
+ if (!this._context.isWritable) {
802
804
  console.error(new Error(`Cannot delete Storage "${this.id}" without writable access.`));
803
805
  return;
804
806
  }
@@ -890,6 +892,95 @@ class Storage {
890
892
  }
891
893
  }
892
894
  }
895
+ class WhiteBoardView {
896
+ constructor(appContext, appProxy, removeViewWrapper) {
897
+ this.appContext = appContext;
898
+ this.appProxy = appProxy;
899
+ this.removeViewWrapper = removeViewWrapper;
900
+ this.nextPage = async () => {
901
+ const nextIndex = this.pageState.index + 1;
902
+ return this.jumpPage(nextIndex);
903
+ };
904
+ this.prevPage = async () => {
905
+ const nextIndex = this.pageState.index - 1;
906
+ return this.jumpPage(nextIndex);
907
+ };
908
+ this.jumpPage = async (index2) => {
909
+ if (index2 < 0 || index2 >= this.pageState.length) {
910
+ console.warn(`[WindowManager]: index ${index2} out of range`);
911
+ return false;
912
+ }
913
+ this.appProxy.setSceneIndex(index2);
914
+ return true;
915
+ };
916
+ this.addPage = async (params) => {
917
+ const after = params == null ? void 0 : params.after;
918
+ const scene = params == null ? void 0 : params.scene;
919
+ const scenePath = this.appProxy.scenePath;
920
+ if (!scenePath)
921
+ return;
922
+ if (after) {
923
+ const nextIndex = this.pageState.index + 1;
924
+ putScenes(this.appContext.room, scenePath, [scene || {}], nextIndex);
925
+ } else {
926
+ putScenes(this.appContext.room, scenePath, [scene || {}]);
927
+ }
928
+ };
929
+ this.removePage = async (index2) => {
930
+ const needRemoveIndex = index2 === void 0 ? this.pageState.index : index2;
931
+ if (this.pageState.length === 1) {
932
+ console.warn(`[WindowManager]: can not remove the last page`);
933
+ return false;
934
+ }
935
+ if (needRemoveIndex < 0 || needRemoveIndex >= this.pageState.length) {
936
+ console.warn(`[WindowManager]: page index ${index2} out of range`);
937
+ return false;
938
+ }
939
+ return this.appProxy.removeSceneByIndex(needRemoveIndex);
940
+ };
941
+ const pageState$ = new Val(appProxy.pageState);
942
+ this.pageState$ = pageState$;
943
+ appProxy.appEmitter.on("pageStateChange", (pageState) => {
944
+ pageState$.setValue(pageState);
945
+ });
946
+ }
947
+ get pageState() {
948
+ return this.pageState$.value;
949
+ }
950
+ destroy() {
951
+ this.removeViewWrapper();
952
+ }
953
+ }
954
+ const setupWrapper = (root) => {
955
+ const playground = document.createElement("div");
956
+ playground.className = "netless-window-manager-playground";
957
+ const mainViewElement = document.createElement("div");
958
+ mainViewElement.className = "netless-window-manager-main-view";
959
+ playground.appendChild(mainViewElement);
960
+ root.appendChild(playground);
961
+ return { playground, mainViewElement };
962
+ };
963
+ const checkVersion = () => {
964
+ const version = getVersionNumber(WhiteVersion);
965
+ if (version < getVersionNumber(REQUIRE_VERSION)) {
966
+ throw new WhiteWebSDKInvalidError(REQUIRE_VERSION);
967
+ }
968
+ };
969
+ const findMemberByUid = (room, uid) => {
970
+ const roomMembers = room == null ? void 0 : room.state.roomMembers;
971
+ return roomMembers == null ? void 0 : roomMembers.find((member) => {
972
+ var _a;
973
+ return ((_a = member.payload) == null ? void 0 : _a.uid) === uid;
974
+ });
975
+ };
976
+ const serializeRoomMembers = (members) => {
977
+ return members.map((member) => {
978
+ var _a;
979
+ return __spreadValues({
980
+ uid: ((_a = member.payload) == null ? void 0 : _a.uid) || ""
981
+ }, member);
982
+ });
983
+ };
893
984
  class AppContext {
894
985
  constructor(manager, boxManager, appId, appProxy, appOptions) {
895
986
  this.manager = manager;
@@ -910,9 +1001,6 @@ class AppContext {
910
1001
  };
911
1002
  this.store = this.manager.store;
912
1003
  this.isReplay = this.manager.isReplay;
913
- this.getDisplayer = () => {
914
- return this.manager.displayer;
915
- };
916
1004
  this.getAttributes = () => {
917
1005
  return this.appProxy.attributes;
918
1006
  };
@@ -924,36 +1012,49 @@ class AppContext {
924
1012
  return appAttr == null ? void 0 : appAttr.options["scenes"];
925
1013
  }
926
1014
  };
927
- this.getView = () => {
928
- return this.appProxy.view;
1015
+ this.createWhiteBoardView = (size2) => {
1016
+ var _a;
1017
+ if (this.whiteBoardView) {
1018
+ return this.whiteBoardView;
1019
+ }
1020
+ let view = this.view;
1021
+ if (!view) {
1022
+ view = this.appProxy.createAppDir();
1023
+ }
1024
+ const viewWrapper = document.createElement("div");
1025
+ viewWrapper.className = "window-manager-view-wrapper";
1026
+ (_a = this.box.$content.parentElement) == null ? void 0 : _a.appendChild(viewWrapper);
1027
+ const removeViewWrapper = () => {
1028
+ var _a2;
1029
+ (_a2 = this.box.$content.parentElement) == null ? void 0 : _a2.removeChild(viewWrapper);
1030
+ };
1031
+ view.divElement = viewWrapper;
1032
+ if (this.isAddApp) {
1033
+ this.initPageSize(size2);
1034
+ }
1035
+ this.whiteBoardView = new WhiteBoardView(this, this.appProxy, removeViewWrapper);
1036
+ return this.whiteBoardView;
929
1037
  };
930
- this.mountView = (dom) => {
931
- const view = this.getView();
932
- if (view) {
933
- view.divElement = dom;
934
- setTimeout(() => {
935
- var _a;
936
- (_a = this.getRoom()) == null ? void 0 : _a.refreshViewSize();
937
- }, 1e3);
1038
+ this.initPageSize = (size2) => {
1039
+ if (!isNumber(size2))
1040
+ return;
1041
+ if (!this.appProxy.scenePath)
1042
+ return;
1043
+ if (this.appProxy.pageState.length >= size2)
1044
+ return;
1045
+ if (size2 <= 0 || size2 >= MAX_PAGE_SIZE) {
1046
+ throw Error(`[WindowManager]: size ${size2} muse be in range [1, ${MAX_PAGE_SIZE}]`);
938
1047
  }
1048
+ const needInsert = size2 - this.appProxy.pageState.length;
1049
+ const startPageNumber = this.appProxy.pageState.length;
1050
+ const scenes = new Array(needInsert).fill({}).map((_2, index2) => {
1051
+ return { name: `${startPageNumber + index2 + 1}` };
1052
+ });
1053
+ putScenes(this.room, this.appProxy.scenePath, scenes);
939
1054
  };
940
1055
  this.getInitScenePath = () => {
941
1056
  return this.manager.getAppInitPath(this.appId);
942
1057
  };
943
- this.getIsWritable = () => {
944
- return this.manager.canOperate;
945
- };
946
- this.getBox = () => {
947
- const box = this.boxManager.getBox(this.appId);
948
- if (box) {
949
- return box;
950
- } else {
951
- throw new BoxNotCreatedError();
952
- }
953
- };
954
- this.getRoom = () => {
955
- return this.manager.room;
956
- };
957
1058
  this.setAttributes = (attributes) => {
958
1059
  this.manager.safeSetAttributes({ [this.appId]: attributes });
959
1060
  };
@@ -967,7 +1068,7 @@ class AppContext {
967
1068
  if (!this.appProxy.box)
968
1069
  return;
969
1070
  this.appProxy.setFullPath(scenePath);
970
- (_a = this.getRoom()) == null ? void 0 : _a.setScenePath(scenePath);
1071
+ (_a = this.room) == null ? void 0 : _a.setScenePath(scenePath);
971
1072
  };
972
1073
  this.getAppOptions = () => {
973
1074
  return typeof this.appOptions === "function" ? this.appOptions() : this.appOptions;
@@ -990,92 +1091,93 @@ class AppContext {
990
1091
  return () => this.manager.displayer.removeMagixEventListener(appScopeEvent, handler);
991
1092
  };
992
1093
  this.removeMagixEventListener = this.manager.displayer.removeMagixEventListener.bind(this.manager.displayer);
993
- this.nextPage = async () => {
994
- const nextIndex = this.pageState.index + 1;
995
- if (nextIndex > this.pageState.length - 1) {
996
- console.warn("[WindowManager] nextPage: index out of range");
997
- return false;
998
- }
999
- this.appProxy.setSceneIndex(nextIndex);
1000
- return true;
1001
- };
1002
- this.prevPage = async () => {
1003
- const nextIndex = this.pageState.index - 1;
1004
- if (nextIndex < 0) {
1005
- console.warn("[WindowManager] prevPage: index out of range");
1006
- return false;
1007
- }
1008
- this.appProxy.setSceneIndex(nextIndex);
1009
- return true;
1010
- };
1011
- this.addPage = async (params) => {
1012
- const after = params == null ? void 0 : params.after;
1013
- const scene = params == null ? void 0 : params.scene;
1014
- const scenePath = this.appProxy.scenePath;
1015
- if (!scenePath)
1016
- return;
1017
- if (after) {
1018
- const nextIndex = this.pageState.index + 1;
1019
- putScenes(this.manager.room, scenePath, [scene || {}], nextIndex);
1020
- } else {
1021
- putScenes(this.manager.room, scenePath, [scene || {}]);
1022
- }
1023
- };
1024
- this.removePage = async (index2) => {
1025
- const needRemoveIndex = index2 === void 0 ? this.pageState.index : index2;
1026
- if (this.pageState.length === 1) {
1027
- console.warn(`[WindowManager]: can not remove the last page`);
1028
- return false;
1029
- }
1030
- if (needRemoveIndex < 0 || needRemoveIndex >= this.pageState.length) {
1031
- console.warn(`[WindowManager]: page index ${index2} out of range`);
1032
- return false;
1033
- }
1034
- return this.appProxy.removeSceneByIndex(needRemoveIndex);
1035
- };
1036
1094
  this.emitter = appProxy.appEmitter;
1037
1095
  this.isAddApp = appProxy.isAddApp;
1038
1096
  }
1097
+ get displayer() {
1098
+ return this.manager.displayer;
1099
+ }
1100
+ get view() {
1101
+ return this.appProxy.view;
1102
+ }
1103
+ get isWritable() {
1104
+ return this.manager.canOperate;
1105
+ }
1106
+ get box() {
1107
+ const box = this.boxManager.getBox(this.appId);
1108
+ if (box) {
1109
+ return box;
1110
+ } else {
1111
+ throw new BoxNotCreatedError();
1112
+ }
1113
+ }
1114
+ get room() {
1115
+ return this.manager.room;
1116
+ }
1117
+ get members() {
1118
+ return this.manager.members;
1119
+ }
1120
+ get memberState() {
1121
+ const self2 = findMemberByUid(this.room, this.manager.uid);
1122
+ if (!self2) {
1123
+ throw new Error(`Member ${this.manager.uid} not found.`);
1124
+ }
1125
+ return __spreadValues({
1126
+ uid: this.manager.uid
1127
+ }, self2);
1128
+ }
1039
1129
  get storage() {
1040
1130
  if (!this._storage) {
1041
1131
  this._storage = new Storage(this);
1042
1132
  }
1043
1133
  return this._storage;
1044
1134
  }
1045
- get pageState() {
1046
- return this.appProxy.pageState;
1047
- }
1048
1135
  }
1049
1136
  class AppPageStateImpl {
1050
1137
  constructor(params) {
1051
1138
  this.params = params;
1052
1139
  this.sceneNode = null;
1053
- this.onSceneChange = (node) => {
1054
- this.sceneNode = node;
1140
+ this.createSceneNode = (scenePath2) => {
1141
+ this.scenePath = scenePath2;
1142
+ if (this.sceneNode) {
1143
+ this.sceneNode.dispose();
1144
+ }
1145
+ this.sceneNode = this.params.displayer.createScenesCallback(scenePath2, {
1146
+ onAddScene: this.onSceneChange,
1147
+ onRemoveScene: this.onSceneChange
1148
+ });
1149
+ return this.sceneNode;
1150
+ };
1151
+ this.onSceneChange = () => {
1055
1152
  this.params.notifyPageStateChange();
1056
1153
  };
1057
1154
  const { displayer, scenePath } = this.params;
1155
+ this.view = this.params.view;
1058
1156
  if (scenePath) {
1157
+ this.scenePath = scenePath;
1059
1158
  this.sceneNode = displayer.createScenesCallback(scenePath, {
1060
1159
  onAddScene: this.onSceneChange,
1061
1160
  onRemoveScene: this.onSceneChange
1062
1161
  });
1063
1162
  }
1064
1163
  }
1164
+ setView(view) {
1165
+ this.view = view;
1166
+ }
1065
1167
  getFullPath(index2) {
1066
1168
  var _a;
1067
1169
  const scenes = (_a = this.sceneNode) == null ? void 0 : _a.scenes;
1068
- if (this.params.scenePath && scenes) {
1170
+ if (this.scenePath && scenes) {
1069
1171
  const name = scenes[index2];
1070
1172
  if (name) {
1071
- return `${this.params.scenePath}/${name}`;
1173
+ return `${this.scenePath}/${name}`;
1072
1174
  }
1073
1175
  }
1074
1176
  }
1075
1177
  toObject() {
1076
1178
  var _a, _b;
1077
1179
  return {
1078
- index: ((_a = this.params.view) == null ? void 0 : _a.focusSceneIndex) || 0,
1180
+ index: ((_a = this.view) == null ? void 0 : _a.focusSceneIndex) || 0,
1079
1181
  length: ((_b = this.sceneNode) == null ? void 0 : _b.scenes.length) || 0
1080
1182
  };
1081
1183
  }
@@ -1282,6 +1384,7 @@ class AppProxy {
1282
1384
  this.viewManager = this.manager.viewManager;
1283
1385
  this.store = this.manager.store;
1284
1386
  this.status = "normal";
1387
+ this.sideEffectManager = new SideEffectManager();
1285
1388
  this.getAppInitState = (id2) => {
1286
1389
  var _a2, _b;
1287
1390
  const attrs = this.store.getAppState(id2);
@@ -1347,10 +1450,13 @@ class AppProxy {
1347
1450
  }
1348
1451
  }, 50);
1349
1452
  this.notifyPageStateChange = debounce(() => {
1350
- this.appEmitter.emit("pageStateChange", this.pageState);
1453
+ if (this.pageState) {
1454
+ this.appEmitter.emit("pageStateChange", this.pageState);
1455
+ }
1351
1456
  }, 50);
1352
1457
  this.kind = params.kind;
1353
1458
  this.id = appId;
1459
+ this.appScenePath = `/${this.id}-app-dir`;
1354
1460
  this.stateKey = `${this.id}_state`;
1355
1461
  this.appProxies.set(this.id, this);
1356
1462
  this.appEmitter = new Emittery();
@@ -1360,12 +1466,36 @@ class AppProxy {
1360
1466
  if ((_a = this.params.options) == null ? void 0 : _a.scenePath) {
1361
1467
  this.createView();
1362
1468
  }
1469
+ if (!this.scenePath) {
1470
+ this.scenePath = this.appScenePath;
1471
+ }
1363
1472
  this._pageState = new AppPageStateImpl({
1364
1473
  displayer: this.manager.displayer,
1365
1474
  scenePath: this.scenePath,
1366
1475
  view: this.view,
1367
1476
  notifyPageStateChange: this.notifyPageStateChange
1368
1477
  });
1478
+ this.sideEffectManager.add(() => {
1479
+ return () => this._pageState.destroy();
1480
+ });
1481
+ this.sideEffectManager.add(() => {
1482
+ return emitter.on("roomMembersChange", (members) => {
1483
+ this.appEmitter.emit("roomMembersChange", members);
1484
+ });
1485
+ });
1486
+ }
1487
+ createAppDir() {
1488
+ const scenePath = this.scenePath || this.appScenePath;
1489
+ const sceneNode = this._pageState.createSceneNode(scenePath);
1490
+ if (!sceneNode) {
1491
+ putScenes(this.manager.room, scenePath, [{ name: "1" }]);
1492
+ this._pageState.createSceneNode(scenePath);
1493
+ this.setSceneIndex(0);
1494
+ }
1495
+ this.scenes = entireScenes(this.manager.displayer)[scenePath];
1496
+ const view = this.createView();
1497
+ this._pageState.setView(view);
1498
+ return view;
1369
1499
  }
1370
1500
  initScenes() {
1371
1501
  var _a;
@@ -1594,8 +1724,8 @@ class AppProxy {
1594
1724
  }
1595
1725
  return fullPath;
1596
1726
  }
1597
- async createView() {
1598
- const view = await this.viewManager.createView(this.id);
1727
+ createView() {
1728
+ const view = this.viewManager.createView(this.id);
1599
1729
  this.setViewFocusScenePath();
1600
1730
  return view;
1601
1731
  }
@@ -1604,7 +1734,7 @@ class AppProxy {
1604
1734
  }
1605
1735
  async removeSceneByIndex(index2) {
1606
1736
  const scenePath = this._pageState.getFullPath(index2);
1607
- if (scenePath) {
1737
+ if (scenePath && this.pageState) {
1608
1738
  const nextIndex = calculateNextIndex(index2, this.pageState);
1609
1739
  this.setSceneIndexWithoutSync(nextIndex);
1610
1740
  this.manager.dispatchInternalEvent(Events.SetAppFocusIndex, {
@@ -1657,13 +1787,13 @@ class AppProxy {
1657
1787
  }
1658
1788
  }
1659
1789
  this.appProxies.delete(this.id);
1660
- this._pageState.destroy();
1661
1790
  this.viewManager.destroyView(this.id);
1662
1791
  this.manager.appStatus.delete(this.id);
1663
1792
  (_b = this.manager.refresher) == null ? void 0 : _b.remove(this.id);
1664
1793
  (_c = this.manager.refresher) == null ? void 0 : _c.remove(this.stateKey);
1665
1794
  (_d = this.manager.refresher) == null ? void 0 : _d.remove(`${this.id}-fullPath`);
1666
1795
  this._prevFullPath = void 0;
1796
+ this.sideEffectManager.flushAll();
1667
1797
  }
1668
1798
  close() {
1669
1799
  return this.destroy(true, true, false);
@@ -1844,7 +1974,7 @@ class MainViewProxy {
1844
1974
  }
1845
1975
  });
1846
1976
  });
1847
- const rect = (_a = this.manager.boxManager) == null ? void 0 : _a.teleBoxManager.stageRect;
1977
+ const rect = (_a = this.manager.boxManager) == null ? void 0 : _a.stageRect;
1848
1978
  if (rect) {
1849
1979
  this.synchronizer.setRect(rect);
1850
1980
  }
@@ -1933,7 +2063,7 @@ class MainViewProxy {
1933
2063
  }
1934
2064
  getStageSize() {
1935
2065
  var _a;
1936
- const stage = (_a = this.manager.boxManager) == null ? void 0 : _a.teleBoxManager.stageRect;
2066
+ const stage = (_a = this.manager.boxManager) == null ? void 0 : _a.stageRect;
1937
2067
  if (stage) {
1938
2068
  return { width: stage.width, height: stage.height };
1939
2069
  }
@@ -2299,6 +2429,9 @@ class AppManager {
2299
2429
  this.appProxies.forEach((appProxy) => {
2300
2430
  appProxy.appEmitter.emit("roomStateChange", state);
2301
2431
  });
2432
+ if (state.roomMembers) {
2433
+ emitter.emit("roomMembersChange", this.members);
2434
+ }
2302
2435
  emitter.emit("observerIdChange", this.displayer.observerId);
2303
2436
  };
2304
2437
  this.displayerWritableListener = (isReadonly) => {
@@ -2412,6 +2545,9 @@ class AppManager {
2412
2545
  var _a;
2413
2546
  return ((_a = this.room) == null ? void 0 : _a.uid) || "";
2414
2547
  }
2548
+ get members() {
2549
+ return serializeRoomMembers(this.displayer.state.roomMembers);
2550
+ }
2415
2551
  getMainViewSceneDir() {
2416
2552
  const scenePath = this.store.getMainViewScenePath();
2417
2553
  if (scenePath) {
@@ -2723,28 +2859,6 @@ class AppManager {
2723
2859
  this._prevSceneIndex = void 0;
2724
2860
  }
2725
2861
  }
2726
- const setupWrapper = (root) => {
2727
- const playground = document.createElement("div");
2728
- playground.className = "netless-window-manager-playground";
2729
- const mainViewElement = document.createElement("div");
2730
- mainViewElement.className = "netless-window-manager-main-view";
2731
- playground.appendChild(mainViewElement);
2732
- root.appendChild(playground);
2733
- return { playground, mainViewElement };
2734
- };
2735
- const checkVersion = () => {
2736
- const version = getVersionNumber(WhiteVersion);
2737
- if (version < getVersionNumber(REQUIRE_VERSION)) {
2738
- throw new WhiteWebSDKInvalidError(REQUIRE_VERSION);
2739
- }
2740
- };
2741
- const findMemberByUid = (room, uid) => {
2742
- const roomMembers = room == null ? void 0 : room.state.roomMembers;
2743
- return roomMembers == null ? void 0 : roomMembers.find((member) => {
2744
- var _a;
2745
- return ((_a = member.payload) == null ? void 0 : _a.uid) === uid;
2746
- });
2747
- };
2748
2862
  /*! *****************************************************************************
2749
2863
  Copyright (c) Microsoft Corporation.
2750
2864
 
@@ -3587,279 +3701,6 @@ var shallowequal = function shallowEqual(objA, objB, compare, compareContext) {
3587
3701
  }
3588
3702
  return true;
3589
3703
  };
3590
- var __defProp$1 = Object.defineProperty;
3591
- var __defProps$1 = Object.defineProperties;
3592
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
3593
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
3594
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
3595
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
3596
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3597
- var __spreadValues$1 = (a2, b2) => {
3598
- for (var prop in b2 || (b2 = {}))
3599
- if (__hasOwnProp$1.call(b2, prop))
3600
- __defNormalProp$1(a2, prop, b2[prop]);
3601
- if (__getOwnPropSymbols$1)
3602
- for (var prop of __getOwnPropSymbols$1(b2)) {
3603
- if (__propIsEnum$1.call(b2, prop))
3604
- __defNormalProp$1(a2, prop, b2[prop]);
3605
- }
3606
- return a2;
3607
- };
3608
- var __spreadProps$1 = (a2, b2) => __defProps$1(a2, __getOwnPropDescs$1(b2));
3609
- var __publicField = (obj, key, value) => {
3610
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
3611
- return value;
3612
- };
3613
- class Subscribers {
3614
- constructor(beforeSubscribe) {
3615
- __publicField(this, "_subscribers");
3616
- __publicField(this, "_bSub");
3617
- __publicField(this, "_bSubDisposer");
3618
- this._bSub = beforeSubscribe;
3619
- }
3620
- get size() {
3621
- return this._subscribers ? this._subscribers.size : 0;
3622
- }
3623
- invoke(newValue, meta) {
3624
- if (this._subscribers) {
3625
- this._subscribers.forEach((subscriber) => subscriber(newValue, meta));
3626
- }
3627
- }
3628
- add(subscribe) {
3629
- if (this._bSub && (!this._subscribers || this._subscribers.size <= 0)) {
3630
- this._bSubDisposer = this._bSub();
3631
- }
3632
- if (!this._subscribers) {
3633
- this._subscribers = /* @__PURE__ */ new Set();
3634
- }
3635
- this._subscribers.add(subscribe);
3636
- }
3637
- remove(subscriber) {
3638
- if (this._subscribers) {
3639
- this._subscribers.delete(subscriber);
3640
- }
3641
- if (this._subscribers && this._subscribers.size <= 0) {
3642
- if (this._bSubDisposer) {
3643
- const _bSubDisposer = this._bSubDisposer;
3644
- this._bSubDisposer = null;
3645
- _bSubDisposer();
3646
- }
3647
- }
3648
- }
3649
- clear() {
3650
- if (this._subscribers) {
3651
- this._subscribers.clear();
3652
- }
3653
- if (this._bSubDisposer) {
3654
- const _bSubDisposer = this._bSubDisposer;
3655
- this._bSubDisposer = null;
3656
- _bSubDisposer();
3657
- }
3658
- }
3659
- destroy() {
3660
- this.clear();
3661
- }
3662
- }
3663
- class ReadonlyVal {
3664
- constructor(value, config) {
3665
- __publicField(this, "_subscribers");
3666
- __publicField(this, "_value");
3667
- this._value = value;
3668
- let beforeSubscribe;
3669
- if (config) {
3670
- if (config.compare) {
3671
- this.compare = config.compare;
3672
- }
3673
- if (config.beforeSubscribe) {
3674
- const _beforeSubscribe = config.beforeSubscribe;
3675
- const _setValue = this._setValue.bind(this);
3676
- beforeSubscribe = () => _beforeSubscribe(_setValue);
3677
- }
3678
- }
3679
- this._subscribers = new Subscribers(beforeSubscribe);
3680
- }
3681
- _setValue(value, meta) {
3682
- if (!this.compare(value, this._value)) {
3683
- this._value = value;
3684
- this._subscribers.invoke(value, meta);
3685
- }
3686
- }
3687
- get value() {
3688
- return this._value;
3689
- }
3690
- reaction(subscriber) {
3691
- this._subscribers.add(subscriber);
3692
- return () => {
3693
- this._subscribers.remove(subscriber);
3694
- };
3695
- }
3696
- subscribe(subscriber, meta) {
3697
- const disposer = this.reaction(subscriber);
3698
- subscriber(this._value, meta);
3699
- return disposer;
3700
- }
3701
- destroy() {
3702
- this._subscribers.destroy();
3703
- }
3704
- unsubscribe(subscriber) {
3705
- this._subscribers.remove(subscriber);
3706
- }
3707
- compare(newValue, oldValue) {
3708
- return newValue === oldValue;
3709
- }
3710
- }
3711
- class Val extends ReadonlyVal {
3712
- constructor() {
3713
- super(...arguments);
3714
- __publicField(this, "setValue", this._setValue);
3715
- }
3716
- }
3717
- class DerivedVal extends ReadonlyVal {
3718
- constructor(val, transform, config = {}) {
3719
- super(transform(val.value), __spreadProps$1(__spreadValues$1({}, config), {
3720
- beforeSubscribe: (setValue) => {
3721
- const disposer = val.subscribe((newValue, meta) => setValue(transform(newValue), meta));
3722
- if (config.beforeSubscribe) {
3723
- const beforeSubscribeDisposer = config.beforeSubscribe(setValue);
3724
- if (beforeSubscribeDisposer) {
3725
- return () => {
3726
- disposer();
3727
- beforeSubscribeDisposer();
3728
- };
3729
- }
3730
- }
3731
- return disposer;
3732
- }
3733
- }));
3734
- __publicField(this, "_srcValue");
3735
- this._srcValue = () => transform(val.value);
3736
- }
3737
- get value() {
3738
- if (this._subscribers.size <= 0) {
3739
- const value = this._srcValue();
3740
- return this.compare(value, this._value) ? this._value : value;
3741
- }
3742
- return this._value;
3743
- }
3744
- }
3745
- function derive(val, transform = (value) => value, config = {}) {
3746
- return new DerivedVal(val, transform, config);
3747
- }
3748
- class CombinedVal extends ReadonlyVal {
3749
- constructor(valInputs, transform, config = {}) {
3750
- super(transform(getValues(valInputs)), __spreadProps$1(__spreadValues$1({}, config), {
3751
- beforeSubscribe: (setValue) => {
3752
- let lastValueInputs = getValues(valInputs);
3753
- setValue(transform(lastValueInputs));
3754
- const disposers = valInputs.map((val, i2) => val.reaction((value, meta) => {
3755
- lastValueInputs = lastValueInputs.slice();
3756
- lastValueInputs[i2] = value;
3757
- setValue(transform(lastValueInputs), meta);
3758
- }));
3759
- const disposer = () => disposers.forEach((disposer2) => disposer2());
3760
- if (config.beforeSubscribe) {
3761
- const beforeSubscribeDisposer = config.beforeSubscribe(setValue);
3762
- if (beforeSubscribeDisposer) {
3763
- return () => {
3764
- disposer();
3765
- beforeSubscribeDisposer();
3766
- };
3767
- }
3768
- }
3769
- return disposer;
3770
- }
3771
- }));
3772
- __publicField(this, "_srcValue");
3773
- this._srcValue = () => transform(getValues(valInputs));
3774
- }
3775
- get value() {
3776
- if (this._subscribers.size <= 0) {
3777
- const value = this._srcValue();
3778
- return this.compare(value, this._value) ? this._value : value;
3779
- }
3780
- return this._value;
3781
- }
3782
- }
3783
- function getValues(valInputs) {
3784
- return valInputs.map(getValue);
3785
- }
3786
- function getValue(val) {
3787
- return val.value;
3788
- }
3789
- function combine(valInputs, transform = (value) => value, config = {}) {
3790
- return new CombinedVal(valInputs, transform, config);
3791
- }
3792
- function withReadonlyValueEnhancer(instance2, config, valManager) {
3793
- Object.keys(config).forEach((key) => {
3794
- bindInstance$1(instance2, key, config[key]);
3795
- if (valManager) {
3796
- valManager.attach(config[key]);
3797
- }
3798
- });
3799
- }
3800
- function bindInstance$1(instance2, key, val) {
3801
- Object.defineProperties(instance2, {
3802
- [key]: {
3803
- get() {
3804
- return val.value;
3805
- }
3806
- },
3807
- [`_${key}$`]: {
3808
- value: val
3809
- }
3810
- });
3811
- return instance2;
3812
- }
3813
- function withValueEnhancer(instance2, config, valManager) {
3814
- Object.keys(config).forEach((key) => {
3815
- bindInstance(instance2, key, config[key]);
3816
- if (valManager) {
3817
- valManager.attach(config[key]);
3818
- }
3819
- });
3820
- }
3821
- function bindInstance(instance2, key, val) {
3822
- Object.defineProperties(instance2, {
3823
- [key]: {
3824
- get() {
3825
- return val.value;
3826
- },
3827
- set(value) {
3828
- val.setValue(value);
3829
- }
3830
- },
3831
- [`_${key}$`]: {
3832
- value: val
3833
- },
3834
- [`set${capitalize(key)}`]: {
3835
- value: (value, meta) => val.setValue(value, meta)
3836
- }
3837
- });
3838
- return instance2;
3839
- }
3840
- function capitalize(str) {
3841
- return str[0].toUpperCase() + str.slice(1);
3842
- }
3843
- class ValManager {
3844
- constructor() {
3845
- __publicField(this, "vals", /* @__PURE__ */ new Set());
3846
- }
3847
- attach(val) {
3848
- this.vals.add(val);
3849
- return val;
3850
- }
3851
- detach(val) {
3852
- this.vals.delete(val);
3853
- return val;
3854
- }
3855
- destroy() {
3856
- this.vals.forEach(destroyVal);
3857
- this.vals.clear();
3858
- }
3859
- }
3860
- function destroyVal(val) {
3861
- val.destroy();
3862
- }
3863
3704
  var e$2 = Object.defineProperty, t$3 = Object.defineProperties, i$1 = Object.getOwnPropertyDescriptors, s$2 = Object.getOwnPropertySymbols, a$1 = Object.prototype.hasOwnProperty, o$2 = Object.prototype.propertyIsEnumerable, r$4 = (t2, i2, s2) => i2 in t2 ? e$2(t2, i2, { enumerable: true, configurable: true, writable: true, value: s2 }) : t2[i2] = s2, n$3 = (e2, t2) => {
3864
3705
  for (var i2 in t2 || (t2 = {}))
3865
3706
  a$1.call(t2, i2) && r$4(e2, i2, t2[i2]);
@@ -4701,6 +4542,9 @@ class BoxManager {
4701
4542
  get boxSize() {
4702
4543
  return this.teleBoxManager.boxes.length;
4703
4544
  }
4545
+ get stageRect() {
4546
+ return this.teleBoxManager.stageRect;
4547
+ }
4704
4548
  createBox(params) {
4705
4549
  var _a, _b, _c;
4706
4550
  if (!this.teleBoxManager)
@@ -4729,7 +4573,7 @@ class BoxManager {
4729
4573
  setupBoxManager(createTeleBoxManagerConfig) {
4730
4574
  const root = WindowManager.playground;
4731
4575
  const initManagerState = {
4732
- stageRatio: 3 / 4,
4576
+ stageRatio: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.stageRatio,
4733
4577
  root,
4734
4578
  fence: false,
4735
4579
  prefersColorScheme: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.prefersColorScheme
@@ -4847,6 +4691,9 @@ class BoxManager {
4847
4691
  setRoot(root) {
4848
4692
  this.teleBoxManager._root$.setValue(root);
4849
4693
  }
4694
+ setCollector(collector) {
4695
+ this.teleBoxManager.collector.set$collector(collector);
4696
+ }
4850
4697
  destroy() {
4851
4698
  this.sideEffectManager.flushAll();
4852
4699
  this.teleBoxManager.destroy();
@@ -15469,14 +15316,14 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
15469
15316
  const _WindowManager = class extends InvisiblePlugin {
15470
15317
  constructor(context) {
15471
15318
  super(context);
15472
- this.version = "1.0.0-canary.0";
15473
- this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.8", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
15319
+ this.version = "1.0.0-canary.3";
15320
+ this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.9", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.2.1", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
15474
15321
  this.emitter = callbacks$1;
15475
15322
  this.viewMode = ViewMode.Broadcaster;
15476
15323
  this.isReplay = isPlayer(this.displayer);
15477
15324
  this.containerSizeRatio = _WindowManager.containerSizeRatio;
15478
15325
  _WindowManager.displayer = context.displayer;
15479
- window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.8", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
15326
+ window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.9", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.2.1", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
15480
15327
  }
15481
15328
  static async mount(params) {
15482
15329
  var _a;
@@ -15618,7 +15465,7 @@ const _WindowManager = class extends InvisiblePlugin {
15618
15465
  }
15619
15466
  bindCollectorContainer(container) {
15620
15467
  if (_WindowManager.isCreated && this.boxManager) {
15621
- this.boxManager.teleBoxManager.collector.set$collector(container);
15468
+ this.boxManager.setCollector(container);
15622
15469
  } else {
15623
15470
  if (_WindowManager.params) {
15624
15471
  _WindowManager.params.collectorContainer = container;