@netless/window-manager 1.0.0-canary.21 → 1.0.0-canary.24

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,7 +19,7 @@ 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, isNumber, throttle, delay, omitBy, isUndefined, isInteger, orderBy, isEmpty, isFunction, isNull } from "lodash";
22
+ import { debounce, isEqual, omit, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, isBoolean, isNumber, throttle, omitBy, isUndefined, isInteger, orderBy, isEmpty, isFunction, isNull } from "lodash";
23
23
  import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, WhiteVersion, autorun, toJS, listenDisposed, unlistenDisposed, AnimationMode, ViewMode, isPlayer, isRoom, ApplianceNames, RoomPhase, InvisiblePlugin } from "white-web-sdk";
24
24
  import { v4 } from "uuid";
25
25
  import { genUID, SideEffectManager } from "side-effect-manager";
@@ -1032,7 +1032,7 @@ class AppContext {
1032
1032
  return appAttr == null ? void 0 : appAttr.options["scenes"];
1033
1033
  }
1034
1034
  };
1035
- this.createWhiteBoardView = (size2) => {
1035
+ this.createWhiteBoardView = (params) => {
1036
1036
  var _a;
1037
1037
  if (this.whiteBoardView) {
1038
1038
  return this.whiteBoardView;
@@ -1041,6 +1041,11 @@ class AppContext {
1041
1041
  if (!view) {
1042
1042
  view = this.appProxy.createAppDir();
1043
1043
  }
1044
+ if (params) {
1045
+ if (isBoolean(params.syncCamera)) {
1046
+ this.appProxy.syncCamera$.setValue(params.syncCamera);
1047
+ }
1048
+ }
1044
1049
  const viewWrapper = document.createElement("div");
1045
1050
  this._viewWrapper = viewWrapper;
1046
1051
  viewWrapper.className = "window-manager-view-wrapper";
@@ -1048,7 +1053,7 @@ class AppContext {
1048
1053
  view.divElement = viewWrapper;
1049
1054
  this.appProxy.fireMemberStateChange();
1050
1055
  if (this.isAddApp) {
1051
- this.ensurePageSize(size2);
1056
+ this.ensurePageSize(params == null ? void 0 : params.size);
1052
1057
  }
1053
1058
  this.whiteBoardView = new WhiteBoardView(view, this, this.appProxy, this.ensurePageSize);
1054
1059
  this.appProxy.sideEffectManager.add(() => {
@@ -1056,6 +1061,7 @@ class AppContext {
1056
1061
  this.whiteBoardView = void 0;
1057
1062
  };
1058
1063
  });
1064
+ this.appProxy.whiteBoardViewCreated$.setValue(true);
1059
1065
  return this.whiteBoardView;
1060
1066
  };
1061
1067
  this.ensurePageSize = (size2) => {
@@ -1213,13 +1219,14 @@ class AppPageStateImpl {
1213
1219
  class CameraSynchronizer {
1214
1220
  constructor(saveCamera) {
1215
1221
  this.saveCamera = saveCamera;
1216
- this.setRect = debounce((rect) => {
1222
+ this.setRect = (rect) => {
1217
1223
  this.rect = rect;
1218
1224
  if (this.remoteCamera && this.remoteSize) {
1219
1225
  this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
1220
1226
  }
1221
- }, 10);
1227
+ };
1222
1228
  this.onRemoteUpdate = throttle((camera, size2) => {
1229
+ var _a;
1223
1230
  this.remoteCamera = camera;
1224
1231
  this.remoteSize = size2;
1225
1232
  if (this.remoteSize && this.rect) {
@@ -1230,22 +1237,17 @@ class CameraSynchronizer {
1230
1237
  scale2 = this.rect.height / size2.height;
1231
1238
  }
1232
1239
  const nextScale = camera.scale * scale2;
1233
- const moveCamera = () => {
1234
- var _a;
1235
- const config = {
1236
- scale: nextScale,
1237
- animationMode: AnimationMode.Immediately
1238
- };
1239
- if (camera.centerX !== null) {
1240
- config.centerX = camera.centerX;
1241
- }
1242
- if (camera.centerY !== null) {
1243
- config.centerY = camera.centerY;
1244
- }
1245
- (_a = this.view) == null ? void 0 : _a.moveCamera(config);
1240
+ const config = {
1241
+ scale: nextScale,
1242
+ animationMode: AnimationMode.Immediately
1246
1243
  };
1247
- moveCamera();
1248
- delay(moveCamera, 50);
1244
+ if (camera.centerX !== null) {
1245
+ config.centerX = camera.centerX;
1246
+ }
1247
+ if (camera.centerY !== null) {
1248
+ config.centerY = camera.centerY;
1249
+ }
1250
+ (_a = this.view) == null ? void 0 : _a.moveCamera(config);
1249
1251
  }
1250
1252
  }, 10);
1251
1253
  }
@@ -1253,20 +1255,16 @@ class CameraSynchronizer {
1253
1255
  this.view = view;
1254
1256
  }
1255
1257
  onRemoteSizeUpdate(size2) {
1258
+ var _a;
1256
1259
  this.remoteSize = size2;
1257
1260
  const needMoveCamera = !isEqual(pick(this.rect, ["width", "height"]), pick(size2, ["width", "height"]));
1258
1261
  if (this.rect && this.remoteCamera && needMoveCamera) {
1259
1262
  const scale2 = this.rect.width / size2.width;
1260
1263
  const nextScale = this.remoteCamera.scale * scale2;
1261
- const moveCamera = () => {
1262
- var _a;
1263
- (_a = this.view) == null ? void 0 : _a.moveCamera({
1264
- scale: nextScale,
1265
- animationMode: AnimationMode.Immediately
1266
- });
1267
- };
1268
- moveCamera();
1269
- delay(moveCamera, 50);
1264
+ (_a = this.view) == null ? void 0 : _a.moveCamera({
1265
+ scale: nextScale,
1266
+ animationMode: AnimationMode.Immediately
1267
+ });
1270
1268
  }
1271
1269
  }
1272
1270
  onLocalCameraUpdate(camera) {
@@ -1289,7 +1287,9 @@ class ViewSync {
1289
1287
  }, "view");
1290
1288
  };
1291
1289
  this.onCameraUpdatedByDevice = (camera) => {
1292
- this.synchronizer.onLocalCameraUpdate(Object.assign(toJS(camera), { id: this.context.uid }));
1290
+ if (!camera)
1291
+ return;
1292
+ this.synchronizer.onLocalCameraUpdate(__spreadProps(__spreadValues({}, camera), { id: this.context.uid }));
1293
1293
  const stage = this.context.stageRect$.value;
1294
1294
  if (stage) {
1295
1295
  const size2 = { width: stage.width, height: stage.height, id: this.context.uid };
@@ -1560,6 +1560,8 @@ class AppProxy {
1560
1560
  this.size$ = this.valManager.attach(new Val(void 0));
1561
1561
  this.box$ = this.valManager.attach(new Val(void 0));
1562
1562
  this.view$ = this.valManager.attach(new Val(void 0));
1563
+ this.syncCamera$ = this.valManager.attach(new Val(true));
1564
+ this.whiteBoardViewCreated$ = this.valManager.attach(new Val(false));
1563
1565
  this.fireMemberStateChange = () => {
1564
1566
  if (this.manager.room) {
1565
1567
  this.onMemberStateChange(this.manager.room.state.memberState);
@@ -1613,34 +1615,36 @@ class AppProxy {
1613
1615
  return Object.assign(payload, state);
1614
1616
  };
1615
1617
  this.appAttributesUpdateListener = (appId2) => {
1616
- this.manager.refresher.add(appId2, () => {
1617
- return autorun(() => {
1618
- const attrs = this.manager.attributes[appId2];
1619
- if (attrs) {
1620
- this.appEmitter.emit("attributesUpdate", attrs);
1621
- }
1622
- });
1623
- });
1624
- this.manager.refresher.add(this.stateKey, () => {
1625
- return autorun(() => {
1626
- var _a2, _b, _c;
1627
- const appState = (_a2 = this.appAttributes) == null ? void 0 : _a2.state;
1628
- if ((appState == null ? void 0 : appState.zIndex) > 0 && appState.zIndex !== ((_b = this.box) == null ? void 0 : _b.zIndex)) {
1629
- (_c = this.boxManager) == null ? void 0 : _c.setZIndex(appId2, appState.zIndex);
1630
- }
1631
- });
1632
- });
1633
- this.manager.refresher.add(`${appId2}-fullPath`, () => {
1634
- return autorun(() => {
1635
- var _a2;
1636
- const fullPath = (_a2 = this.appAttributes) == null ? void 0 : _a2.fullPath;
1637
- this.setFocusScenePathHandler(fullPath);
1638
- if (this.fullPath$.value !== fullPath) {
1639
- this.notifyPageStateChange();
1640
- this.fullPath$.setValue(fullPath);
1641
- }
1642
- });
1643
- });
1618
+ this.sideEffectManager.add(() => [
1619
+ this.manager.refresher.add(appId2, () => {
1620
+ return autorun(() => {
1621
+ const attrs = this.manager.attributes[appId2];
1622
+ if (attrs) {
1623
+ this.appEmitter.emit("attributesUpdate", attrs);
1624
+ }
1625
+ });
1626
+ }),
1627
+ this.manager.refresher.add(this.stateKey, () => {
1628
+ return autorun(() => {
1629
+ var _a2, _b, _c;
1630
+ const appState = (_a2 = this.appAttributes) == null ? void 0 : _a2.state;
1631
+ if ((appState == null ? void 0 : appState.zIndex) > 0 && appState.zIndex !== ((_b = this.box) == null ? void 0 : _b.zIndex)) {
1632
+ (_c = this.boxManager) == null ? void 0 : _c.setZIndex(appId2, appState.zIndex);
1633
+ }
1634
+ });
1635
+ }),
1636
+ this.manager.refresher.add(`${appId2}-fullPath`, () => {
1637
+ return autorun(() => {
1638
+ var _a2;
1639
+ const fullPath = (_a2 = this.appAttributes) == null ? void 0 : _a2.fullPath;
1640
+ this.setFocusScenePathHandler(fullPath);
1641
+ if (this.fullPath$.value !== fullPath) {
1642
+ this.notifyPageStateChange();
1643
+ this.fullPath$.setValue(fullPath);
1644
+ }
1645
+ });
1646
+ })
1647
+ ]);
1644
1648
  };
1645
1649
  this.setFocusScenePathHandler = debounce((fullPath) => {
1646
1650
  var _a2;
@@ -1734,101 +1738,63 @@ class AppProxy {
1734
1738
  this.size$.setValue(toJS(this.appAttributes.size));
1735
1739
  this.addCameraReaction();
1736
1740
  this.addSizeReaction();
1737
- this.sideEffectManager.add(() => combine([this.box$, this.view$]).subscribe(([box, view]) => {
1738
- if (box && view) {
1739
- if (!this.camera$.value) {
1740
- this.storeCamera({
1741
- centerX: null,
1742
- centerY: null,
1743
- scale: 1,
1744
- id: this.uid
1745
- });
1746
- this.camera$.setValue(toJS(this.appAttributes.camera));
1747
- }
1748
- if (!this.size$.value && box.contentStageRect) {
1749
- const initialRect = this.computedInitialRect(box.contentStageRect);
1750
- const width = (initialRect == null ? void 0 : initialRect.width) || box.contentStageRect.width;
1751
- const height = (initialRect == null ? void 0 : initialRect.height) || box.contentStageRect.height;
1752
- this.storeSize({
1753
- id: this.uid,
1754
- width,
1755
- height
1756
- });
1757
- this.size$.setValue(toJS(this.appAttributes.size));
1758
- }
1759
- this.viewSync = new ViewSync({
1760
- uid: this.uid,
1761
- view$: this.view$,
1762
- camera$: this.camera$,
1763
- size$: this.size$,
1764
- stageRect$: box._contentStageRect$,
1765
- storeCamera: this.storeCamera,
1766
- storeSize: this.storeSize
1767
- });
1768
- this.sideEffectManager.add(() => () => {
1769
- var _a2;
1770
- return (_a2 = this.viewSync) == null ? void 0 : _a2.destroy();
1771
- });
1772
- }
1773
- }));
1774
1741
  this.sideEffectManager.add(() => emitter.on("memberStateChange", this.onMemberStateChange));
1775
- this.box$.subscribe((box) => {
1776
- if (!box)
1777
- return;
1778
- this.sideEffectManager.add(() => [
1779
- createValSync(() => {
1780
- var _a2;
1781
- return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.visible;
1782
- }, box._visible$),
1783
- createValSync(() => {
1784
- var _a2;
1785
- return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.ratio;
1786
- }, box._ratio$),
1787
- createValSync(() => {
1788
- var _a2;
1789
- return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.stageRatio;
1790
- }, box._stageRatio$),
1791
- createValSync(() => {
1792
- var _a2;
1793
- return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.draggable;
1794
- }, box._draggable$),
1795
- createValSync(() => {
1796
- var _a2;
1797
- return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.resizable;
1798
- }, box._resizable$),
1799
- box._visible$.reaction((visible, skipUpdate) => {
1800
- if (skipUpdate) {
1801
- return;
1802
- }
1803
- this.store.updateAppState(this.id, AppAttributes.Visible, visible);
1804
- }),
1805
- box._ratio$.reaction((ratio, skipUpdate) => {
1806
- console.log("ratio change", ratio, skipUpdate);
1807
- if (skipUpdate) {
1808
- return;
1809
- }
1810
- this.store.updateAppState(this.id, AppAttributes.Ratio, ratio);
1811
- }),
1812
- box._stageRatio$.reaction((stageRatio, skipUpdate) => {
1813
- if (skipUpdate) {
1814
- return;
1815
- }
1816
- this.store.updateAppState(this.id, AppAttributes.StageRatio, stageRatio);
1817
- }),
1818
- box._draggable$.reaction((draggable, skipUpdate) => {
1819
- if (skipUpdate) {
1820
- return;
1742
+ this.sideEffectManager.add(() => [
1743
+ this.syncCamera$.reaction((syncCamera) => {
1744
+ if (!syncCamera) {
1745
+ if (this.viewSync) {
1746
+ this.viewSync.destroy();
1747
+ this.viewSync = void 0;
1748
+ this.sideEffectManager.flush("camera");
1749
+ this.sideEffectManager.flush("size");
1821
1750
  }
1822
- this.store.updateAppState(this.id, AppAttributes.Draggable, draggable);
1823
- }),
1824
- box._resizable$.reaction((resizable, skipUpdate) => {
1825
- if (skipUpdate) {
1751
+ }
1752
+ }),
1753
+ this.whiteBoardViewCreated$.reaction((created) => {
1754
+ if (created && this.box) {
1755
+ if (!this.syncCamera$.value)
1826
1756
  return;
1827
- }
1828
- this.store.updateAppState(this.id, AppAttributes.Resizable, resizable);
1829
- })
1830
- ]);
1831
- });
1757
+ combine([this.box$, this.view$]).subscribe(([box, view]) => {
1758
+ if (box && view) {
1759
+ if (!this.camera$.value) {
1760
+ this.storeCamera({
1761
+ centerX: null,
1762
+ centerY: null,
1763
+ scale: 1,
1764
+ id: this.uid
1765
+ });
1766
+ this.camera$.setValue(toJS(this.appAttributes.camera));
1767
+ }
1768
+ if (!this.size$.value && box.contentStageRect) {
1769
+ const initialRect = this.computedInitialRect(box.contentStageRect);
1770
+ const width = (initialRect == null ? void 0 : initialRect.width) || box.contentStageRect.width;
1771
+ const height = (initialRect == null ? void 0 : initialRect.height) || box.contentStageRect.height;
1772
+ this.storeSize({
1773
+ id: this.uid,
1774
+ width,
1775
+ height
1776
+ });
1777
+ this.size$.setValue(toJS(this.appAttributes.size));
1778
+ }
1779
+ this.viewSync = new ViewSync({
1780
+ uid: this.uid,
1781
+ view$: this.view$,
1782
+ camera$: this.camera$,
1783
+ size$: this.size$,
1784
+ stageRect$: box._contentStageRect$,
1785
+ storeCamera: this.storeCamera,
1786
+ storeSize: this.storeSize
1787
+ });
1788
+ this.sideEffectManager.add(() => () => {
1789
+ var _a2;
1790
+ return (_a2 = this.viewSync) == null ? void 0 : _a2.destroy();
1791
+ });
1792
+ this.whiteBoardViewCreated$.destroy();
1793
+ }
1794
+ });
1795
+ }
1796
+ })
1797
+ ]);
1832
1798
  }
1833
1799
  createAppDir() {
1834
1800
  const scenePath = this.scenePath || this.appScenePath;
@@ -1946,11 +1912,6 @@ class AppProxy {
1946
1912
  this.box$.setValue(box);
1947
1913
  if (this.isAddApp && this.box) {
1948
1914
  this.store.updateAppState(appId, AppAttributes.ZIndex, this.box.zIndex);
1949
- this.store.updateAppState(appId, AppAttributes.Visible, this.box.visible);
1950
- this.store.updateAppState(appId, AppAttributes.Ratio, this.box.ratio);
1951
- this.store.updateAppState(appId, AppAttributes.StageRatio, this.box.stageRatio);
1952
- this.store.updateAppState(appId, AppAttributes.Draggable, this.box.draggable);
1953
- this.store.updateAppState(appId, AppAttributes.Resizable, this.box.resizable);
1954
1915
  this.boxManager.focusBox({ appId }, false);
1955
1916
  }
1956
1917
  } catch (error) {
@@ -2145,24 +2106,12 @@ class AppProxy {
2145
2106
  this.appProxies.delete(this.id);
2146
2107
  this.viewManager.destroyView(this.id);
2147
2108
  this.manager.appStatus.delete(this.id);
2148
- this.manager.refresher.remove(this.id);
2149
- this.manager.refresher.remove(this.stateKey);
2150
- this.manager.refresher.remove(`${this.id}-fullPath`);
2151
- this.manager.refresher.remove(`${this.id}-camera`);
2152
- this.manager.refresher.remove(`${this.id}-size`);
2153
2109
  this.valManager.destroy();
2154
2110
  }
2155
2111
  close() {
2156
2112
  return this.destroy(true, true, false);
2157
2113
  }
2158
2114
  }
2159
- const createValSync = (expr, Val2) => {
2160
- return reaction(expr, (val) => {
2161
- if (Val2.value !== val && val !== void 0) {
2162
- Val2.setValue(val, true);
2163
- }
2164
- }, { fireImmediately: true });
2165
- };
2166
2115
  class ViewManager {
2167
2116
  constructor(displayer) {
2168
2117
  this.displayer = displayer;
@@ -5998,12 +5947,16 @@ class ReconnectRefresher {
5998
5947
  this.reactors = /* @__PURE__ */ new Map();
5999
5948
  this.disposers = /* @__PURE__ */ new Map();
6000
5949
  this.onPhaseChanged = (phase) => {
6001
- var _a;
5950
+ var _a, _b;
6002
5951
  if (phase === RoomPhase.Reconnecting) {
6003
5952
  this.ctx.emitter.emit("startReconnect");
6004
5953
  }
6005
5954
  if (phase === RoomPhase.Connected && this.phase === RoomPhase.Reconnecting) {
6006
- (_a = this.room) == null ? void 0 : _a.dispatchMagixEvent(EnsureReconnectEvent, {});
5955
+ if ((_a = this.room) == null ? void 0 : _a.isWritable) {
5956
+ (_b = this.room) == null ? void 0 : _b.dispatchMagixEvent(EnsureReconnectEvent, {});
5957
+ } else {
5958
+ this.onReconnected();
5959
+ }
6007
5960
  }
6008
5961
  this.phase = phase;
6009
5962
  };
@@ -15686,7 +15639,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
15686
15639
  const _WindowManager = class extends InvisiblePlugin {
15687
15640
  constructor(context) {
15688
15641
  super(context);
15689
- this.version = "1.0.0-canary.21";
15642
+ this.version = "1.0.0-canary.24";
15690
15643
  this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.18", "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.3.0", "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" } };
15691
15644
  this.emitter = callbacks$1;
15692
15645
  this.viewMode = ViewMode.Broadcaster;