@netless/window-manager 1.0.0-canary.1 → 1.0.0-canary.2

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,91 @@ class Storage {
890
892
  }
891
893
  }
892
894
  }
895
+ class WhiteBoardView {
896
+ constructor(appContext, appProxy) {
897
+ this.appContext = appContext;
898
+ this.appProxy = appProxy;
899
+ this.nextPage = async () => {
900
+ const nextIndex = this.pageState.index + 1;
901
+ return this.jumpPage(nextIndex);
902
+ };
903
+ this.prevPage = async () => {
904
+ const nextIndex = this.pageState.index - 1;
905
+ return this.jumpPage(nextIndex);
906
+ };
907
+ this.jumpPage = async (index2) => {
908
+ if (index2 < 0 || index2 >= this.pageState.length) {
909
+ console.warn(`[WindowManager]: index ${index2} out of range`);
910
+ return false;
911
+ }
912
+ this.appProxy.setSceneIndex(index2);
913
+ return true;
914
+ };
915
+ this.addPage = async (params) => {
916
+ const after = params == null ? void 0 : params.after;
917
+ const scene = params == null ? void 0 : params.scene;
918
+ const scenePath = this.appProxy.scenePath;
919
+ if (!scenePath)
920
+ return;
921
+ if (after) {
922
+ const nextIndex = this.pageState.index + 1;
923
+ putScenes(this.appContext.room, scenePath, [scene || {}], nextIndex);
924
+ } else {
925
+ putScenes(this.appContext.room, scenePath, [scene || {}]);
926
+ }
927
+ };
928
+ this.removePage = async (index2) => {
929
+ const needRemoveIndex = index2 === void 0 ? this.pageState.index : index2;
930
+ if (this.pageState.length === 1) {
931
+ console.warn(`[WindowManager]: can not remove the last page`);
932
+ return false;
933
+ }
934
+ if (needRemoveIndex < 0 || needRemoveIndex >= this.pageState.length) {
935
+ console.warn(`[WindowManager]: page index ${index2} out of range`);
936
+ return false;
937
+ }
938
+ return this.appProxy.removeSceneByIndex(needRemoveIndex);
939
+ };
940
+ const pageState$ = new Val(appProxy.pageState);
941
+ this.pageState$ = pageState$;
942
+ appProxy.appEmitter.on("pageStateChange", (pageState) => {
943
+ pageState$.setValue(pageState);
944
+ });
945
+ }
946
+ get pageState() {
947
+ return this.pageState$.value;
948
+ }
949
+ }
950
+ const setupWrapper = (root) => {
951
+ const playground = document.createElement("div");
952
+ playground.className = "netless-window-manager-playground";
953
+ const mainViewElement = document.createElement("div");
954
+ mainViewElement.className = "netless-window-manager-main-view";
955
+ playground.appendChild(mainViewElement);
956
+ root.appendChild(playground);
957
+ return { playground, mainViewElement };
958
+ };
959
+ const checkVersion = () => {
960
+ const version = getVersionNumber(WhiteVersion);
961
+ if (version < getVersionNumber(REQUIRE_VERSION)) {
962
+ throw new WhiteWebSDKInvalidError(REQUIRE_VERSION);
963
+ }
964
+ };
965
+ const findMemberByUid = (room, uid) => {
966
+ const roomMembers = room == null ? void 0 : room.state.roomMembers;
967
+ return roomMembers == null ? void 0 : roomMembers.find((member) => {
968
+ var _a;
969
+ return ((_a = member.payload) == null ? void 0 : _a.uid) === uid;
970
+ });
971
+ };
972
+ const serializeRoomMembers = (members) => {
973
+ return members.map((member) => {
974
+ var _a;
975
+ return __spreadValues({
976
+ uid: ((_a = member.payload) == null ? void 0 : _a.uid) || ""
977
+ }, member);
978
+ });
979
+ };
893
980
  class AppContext {
894
981
  constructor(manager, boxManager, appId, appProxy, appOptions) {
895
982
  this.manager = manager;
@@ -910,9 +997,6 @@ class AppContext {
910
997
  };
911
998
  this.store = this.manager.store;
912
999
  this.isReplay = this.manager.isReplay;
913
- this.getDisplayer = () => {
914
- return this.manager.displayer;
915
- };
916
1000
  this.getAttributes = () => {
917
1001
  return this.appProxy.attributes;
918
1002
  };
@@ -924,36 +1008,39 @@ class AppContext {
924
1008
  return appAttr == null ? void 0 : appAttr.options["scenes"];
925
1009
  }
926
1010
  };
927
- this.getView = () => {
928
- return this.appProxy.view;
1011
+ this.createWhiteBoardView = (size2) => {
1012
+ if (this.whiteBoardView) {
1013
+ return this.whiteBoardView;
1014
+ }
1015
+ let view = this.view;
1016
+ if (!view) {
1017
+ view = this.appProxy.createAppDir();
1018
+ }
1019
+ view.divElement = this.box.$content;
1020
+ this.initPageSize(size2);
1021
+ this.whiteBoardView = new WhiteBoardView(this, this.appProxy);
1022
+ return this.whiteBoardView;
929
1023
  };
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);
1024
+ this.initPageSize = (size2) => {
1025
+ if (!isNumber(size2))
1026
+ return;
1027
+ if (!this.appProxy.scenePath)
1028
+ return;
1029
+ if (this.appProxy.pageState.length >= size2)
1030
+ return;
1031
+ if (size2 <= 0 || size2 >= MAX_PAGE_SIZE) {
1032
+ throw Error(`[WindowManager]: size ${size2} muse be in range [1, ${MAX_PAGE_SIZE}]`);
938
1033
  }
1034
+ const needInsert = size2 - this.appProxy.pageState.length;
1035
+ const startPageNumber = this.appProxy.pageState.length;
1036
+ const scenes = new Array(needInsert).fill({}).map((_2, index2) => {
1037
+ return { name: `${startPageNumber + index2 + 1}` };
1038
+ });
1039
+ putScenes(this.room, this.appProxy.scenePath, scenes);
939
1040
  };
940
1041
  this.getInitScenePath = () => {
941
1042
  return this.manager.getAppInitPath(this.appId);
942
1043
  };
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
1044
  this.setAttributes = (attributes) => {
958
1045
  this.manager.safeSetAttributes({ [this.appId]: attributes });
959
1046
  };
@@ -967,7 +1054,7 @@ class AppContext {
967
1054
  if (!this.appProxy.box)
968
1055
  return;
969
1056
  this.appProxy.setFullPath(scenePath);
970
- (_a = this.getRoom()) == null ? void 0 : _a.setScenePath(scenePath);
1057
+ (_a = this.room) == null ? void 0 : _a.setScenePath(scenePath);
971
1058
  };
972
1059
  this.getAppOptions = () => {
973
1060
  return typeof this.appOptions === "function" ? this.appOptions() : this.appOptions;
@@ -990,92 +1077,93 @@ class AppContext {
990
1077
  return () => this.manager.displayer.removeMagixEventListener(appScopeEvent, handler);
991
1078
  };
992
1079
  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
1080
  this.emitter = appProxy.appEmitter;
1037
1081
  this.isAddApp = appProxy.isAddApp;
1038
1082
  }
1083
+ get displayer() {
1084
+ return this.manager.displayer;
1085
+ }
1086
+ get view() {
1087
+ return this.appProxy.view;
1088
+ }
1089
+ get isWritable() {
1090
+ return this.manager.canOperate;
1091
+ }
1092
+ get box() {
1093
+ const box = this.boxManager.getBox(this.appId);
1094
+ if (box) {
1095
+ return box;
1096
+ } else {
1097
+ throw new BoxNotCreatedError();
1098
+ }
1099
+ }
1100
+ get room() {
1101
+ return this.manager.room;
1102
+ }
1103
+ get members() {
1104
+ return this.manager.members;
1105
+ }
1106
+ get memberState() {
1107
+ const self2 = findMemberByUid(this.room, this.manager.uid);
1108
+ if (!self2) {
1109
+ throw new Error(`Member ${this.manager.uid} not found.`);
1110
+ }
1111
+ return __spreadValues({
1112
+ uid: this.manager.uid
1113
+ }, self2);
1114
+ }
1039
1115
  get storage() {
1040
1116
  if (!this._storage) {
1041
1117
  this._storage = new Storage(this);
1042
1118
  }
1043
1119
  return this._storage;
1044
1120
  }
1045
- get pageState() {
1046
- return this.appProxy.pageState;
1047
- }
1048
1121
  }
1049
1122
  class AppPageStateImpl {
1050
1123
  constructor(params) {
1051
1124
  this.params = params;
1052
1125
  this.sceneNode = null;
1053
- this.onSceneChange = (node) => {
1054
- this.sceneNode = node;
1126
+ this.createSceneNode = (scenePath2) => {
1127
+ this.scenePath = scenePath2;
1128
+ if (this.sceneNode) {
1129
+ this.sceneNode.dispose();
1130
+ }
1131
+ this.sceneNode = this.params.displayer.createScenesCallback(scenePath2, {
1132
+ onAddScene: this.onSceneChange,
1133
+ onRemoveScene: this.onSceneChange
1134
+ });
1135
+ return this.sceneNode;
1136
+ };
1137
+ this.onSceneChange = () => {
1055
1138
  this.params.notifyPageStateChange();
1056
1139
  };
1057
1140
  const { displayer, scenePath } = this.params;
1141
+ this.view = this.params.view;
1058
1142
  if (scenePath) {
1143
+ this.scenePath = scenePath;
1059
1144
  this.sceneNode = displayer.createScenesCallback(scenePath, {
1060
1145
  onAddScene: this.onSceneChange,
1061
1146
  onRemoveScene: this.onSceneChange
1062
1147
  });
1063
1148
  }
1064
1149
  }
1150
+ setView(view) {
1151
+ this.view = view;
1152
+ }
1065
1153
  getFullPath(index2) {
1066
1154
  var _a;
1067
1155
  const scenes = (_a = this.sceneNode) == null ? void 0 : _a.scenes;
1068
- if (this.params.scenePath && scenes) {
1156
+ if (this.scenePath && scenes) {
1069
1157
  const name = scenes[index2];
1070
1158
  if (name) {
1071
- return `${this.params.scenePath}/${name}`;
1159
+ return `${this.scenePath}/${name}`;
1072
1160
  }
1073
1161
  }
1074
1162
  }
1075
1163
  toObject() {
1076
1164
  var _a, _b;
1077
1165
  return {
1078
- index: ((_a = this.params.view) == null ? void 0 : _a.focusSceneIndex) || 0,
1166
+ index: ((_a = this.view) == null ? void 0 : _a.focusSceneIndex) || 0,
1079
1167
  length: ((_b = this.sceneNode) == null ? void 0 : _b.scenes.length) || 0
1080
1168
  };
1081
1169
  }
@@ -1282,6 +1370,7 @@ class AppProxy {
1282
1370
  this.viewManager = this.manager.viewManager;
1283
1371
  this.store = this.manager.store;
1284
1372
  this.status = "normal";
1373
+ this.sideEffectManager = new SideEffectManager();
1285
1374
  this.getAppInitState = (id2) => {
1286
1375
  var _a2, _b;
1287
1376
  const attrs = this.store.getAppState(id2);
@@ -1347,10 +1436,13 @@ class AppProxy {
1347
1436
  }
1348
1437
  }, 50);
1349
1438
  this.notifyPageStateChange = debounce(() => {
1350
- this.appEmitter.emit("pageStateChange", this.pageState);
1439
+ if (this.pageState) {
1440
+ this.appEmitter.emit("pageStateChange", this.pageState);
1441
+ }
1351
1442
  }, 50);
1352
1443
  this.kind = params.kind;
1353
1444
  this.id = appId;
1445
+ this.appScenePath = `/${this.id}-app-dir`;
1354
1446
  this.stateKey = `${this.id}_state`;
1355
1447
  this.appProxies.set(this.id, this);
1356
1448
  this.appEmitter = new Emittery();
@@ -1360,12 +1452,36 @@ class AppProxy {
1360
1452
  if ((_a = this.params.options) == null ? void 0 : _a.scenePath) {
1361
1453
  this.createView();
1362
1454
  }
1455
+ if (!this.scenePath) {
1456
+ this.scenePath = this.appScenePath;
1457
+ }
1363
1458
  this._pageState = new AppPageStateImpl({
1364
1459
  displayer: this.manager.displayer,
1365
1460
  scenePath: this.scenePath,
1366
1461
  view: this.view,
1367
1462
  notifyPageStateChange: this.notifyPageStateChange
1368
1463
  });
1464
+ this.sideEffectManager.add(() => {
1465
+ return () => this._pageState.destroy();
1466
+ });
1467
+ this.sideEffectManager.add(() => {
1468
+ return emitter.on("roomMembersChange", (members) => {
1469
+ this.appEmitter.emit("roomMembersChange", members);
1470
+ });
1471
+ });
1472
+ }
1473
+ createAppDir() {
1474
+ const scenePath = this.scenePath || this.appScenePath;
1475
+ const sceneNode = this._pageState.createSceneNode(scenePath);
1476
+ if (!sceneNode) {
1477
+ putScenes(this.manager.room, scenePath, [{ name: "1" }]);
1478
+ this._pageState.createSceneNode(scenePath);
1479
+ this.setSceneIndex(0);
1480
+ }
1481
+ this.scenes = entireScenes(this.manager.displayer)[scenePath];
1482
+ const view = this.createView();
1483
+ this._pageState.setView(view);
1484
+ return view;
1369
1485
  }
1370
1486
  initScenes() {
1371
1487
  var _a;
@@ -1594,8 +1710,8 @@ class AppProxy {
1594
1710
  }
1595
1711
  return fullPath;
1596
1712
  }
1597
- async createView() {
1598
- const view = await this.viewManager.createView(this.id);
1713
+ createView() {
1714
+ const view = this.viewManager.createView(this.id);
1599
1715
  this.setViewFocusScenePath();
1600
1716
  return view;
1601
1717
  }
@@ -1604,7 +1720,7 @@ class AppProxy {
1604
1720
  }
1605
1721
  async removeSceneByIndex(index2) {
1606
1722
  const scenePath = this._pageState.getFullPath(index2);
1607
- if (scenePath) {
1723
+ if (scenePath && this.pageState) {
1608
1724
  const nextIndex = calculateNextIndex(index2, this.pageState);
1609
1725
  this.setSceneIndexWithoutSync(nextIndex);
1610
1726
  this.manager.dispatchInternalEvent(Events.SetAppFocusIndex, {
@@ -1657,13 +1773,13 @@ class AppProxy {
1657
1773
  }
1658
1774
  }
1659
1775
  this.appProxies.delete(this.id);
1660
- this._pageState.destroy();
1661
1776
  this.viewManager.destroyView(this.id);
1662
1777
  this.manager.appStatus.delete(this.id);
1663
1778
  (_b = this.manager.refresher) == null ? void 0 : _b.remove(this.id);
1664
1779
  (_c = this.manager.refresher) == null ? void 0 : _c.remove(this.stateKey);
1665
1780
  (_d = this.manager.refresher) == null ? void 0 : _d.remove(`${this.id}-fullPath`);
1666
1781
  this._prevFullPath = void 0;
1782
+ this.sideEffectManager.flushAll();
1667
1783
  }
1668
1784
  close() {
1669
1785
  return this.destroy(true, true, false);
@@ -2299,6 +2415,9 @@ class AppManager {
2299
2415
  this.appProxies.forEach((appProxy) => {
2300
2416
  appProxy.appEmitter.emit("roomStateChange", state);
2301
2417
  });
2418
+ if (state.roomMembers) {
2419
+ emitter.emit("roomMembersChange", this.members);
2420
+ }
2302
2421
  emitter.emit("observerIdChange", this.displayer.observerId);
2303
2422
  };
2304
2423
  this.displayerWritableListener = (isReadonly) => {
@@ -2412,6 +2531,9 @@ class AppManager {
2412
2531
  var _a;
2413
2532
  return ((_a = this.room) == null ? void 0 : _a.uid) || "";
2414
2533
  }
2534
+ get members() {
2535
+ return serializeRoomMembers(this.displayer.state.roomMembers);
2536
+ }
2415
2537
  getMainViewSceneDir() {
2416
2538
  const scenePath = this.store.getMainViewScenePath();
2417
2539
  if (scenePath) {
@@ -2723,28 +2845,6 @@ class AppManager {
2723
2845
  this._prevSceneIndex = void 0;
2724
2846
  }
2725
2847
  }
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
2848
  /*! *****************************************************************************
2749
2849
  Copyright (c) Microsoft Corporation.
2750
2850
 
@@ -3587,279 +3687,6 @@ var shallowequal = function shallowEqual(objA, objB, compare, compareContext) {
3587
3687
  }
3588
3688
  return true;
3589
3689
  };
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
3690
  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
3691
  for (var i2 in t2 || (t2 = {}))
3865
3692
  a$1.call(t2, i2) && r$4(e2, i2, t2[i2]);
@@ -15475,14 +15302,14 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
15475
15302
  const _WindowManager = class extends InvisiblePlugin {
15476
15303
  constructor(context) {
15477
15304
  super(context);
15478
- this.version = "1.0.0-canary.1";
15479
- 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" } };
15305
+ this.version = "1.0.0-canary.2";
15306
+ 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", "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
15307
  this.emitter = callbacks$1;
15481
15308
  this.viewMode = ViewMode.Broadcaster;
15482
15309
  this.isReplay = isPlayer(this.displayer);
15483
15310
  this.containerSizeRatio = _WindowManager.containerSizeRatio;
15484
15311
  _WindowManager.displayer = context.displayer;
15485
- 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" } };
15312
+ 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", "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" } };
15486
15313
  }
15487
15314
  static async mount(params) {
15488
15315
  var _a;