@netless/window-manager 1.0.19 → 1.0.20
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.d.ts +3 -0
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +140 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/App/AppBoxSizeSynchronizer.ts +1 -1
- package/src/App/AppProxy.ts +40 -1
- package/src/ContainerResizeObserver.ts +134 -4
- package/src/constants.ts +4 -0
- package/src/index.ts +13 -1
package/dist/index.mjs
CHANGED
|
@@ -56,6 +56,8 @@ const DEFAULT_CONTAINER_RATIO = 9 / 16;
|
|
|
56
56
|
const ROOT_DIR = "/";
|
|
57
57
|
const INIT_DIR = "/init";
|
|
58
58
|
const SETUP_APP_DELAY = 50;
|
|
59
|
+
const BOX_SIZE_SETTLE_DELAY = 650;
|
|
60
|
+
const CONTAINER_STATE_LOG_DEBOUNCE = 1e3;
|
|
59
61
|
const callbacks = new Emittery();
|
|
60
62
|
class AppCreateQueue {
|
|
61
63
|
constructor() {
|
|
@@ -7512,7 +7514,6 @@ const calculateNextIndex = (index2, pageState) => {
|
|
|
7512
7514
|
};
|
|
7513
7515
|
const boxEmitter = new Emittery();
|
|
7514
7516
|
const BOX_SIZE_EPSILON = 0.5;
|
|
7515
|
-
const BOX_SIZE_SETTLE_DELAY = 650;
|
|
7516
7517
|
const BOX_SIZE_CONFIRM_DELAY = 100;
|
|
7517
7518
|
const sizesEqual = (left, right) => Boolean(
|
|
7518
7519
|
left && Math.abs(left.width - right.width) <= BOX_SIZE_EPSILON && Math.abs(left.height - right.height) <= BOX_SIZE_EPSILON
|
|
@@ -7602,6 +7603,7 @@ class AppBoxSizeSynchronizer {
|
|
|
7602
7603
|
this.lastNotifiedSize = void 0;
|
|
7603
7604
|
}
|
|
7604
7605
|
}
|
|
7606
|
+
const APP_SETUP_WATCHDOG_TIMEOUT = 1e4;
|
|
7605
7607
|
const _AppProxy = class {
|
|
7606
7608
|
constructor(params, manager, appId, isAddApp) {
|
|
7607
7609
|
var _a;
|
|
@@ -7858,7 +7860,10 @@ const _AppProxy = class {
|
|
|
7858
7860
|
this.Logger && this.Logger.info(
|
|
7859
7861
|
`[WindowManager]: setup app ${this.kind}, appId: ${appId}`
|
|
7860
7862
|
);
|
|
7861
|
-
const
|
|
7863
|
+
const setupResult = await this.runAppSetup(appId, app, context);
|
|
7864
|
+
if (!setupResult.succeeded)
|
|
7865
|
+
return;
|
|
7866
|
+
const { result } = setupResult;
|
|
7862
7867
|
this.appResult = result;
|
|
7863
7868
|
this.scheduleBoxSizeSync();
|
|
7864
7869
|
appRegister.notifyApp(this.kind, "created", { appId, result });
|
|
@@ -7897,6 +7902,36 @@ const _AppProxy = class {
|
|
|
7897
7902
|
throw new Error(`[WindowManager]: app setup error: ${error.message}`);
|
|
7898
7903
|
}
|
|
7899
7904
|
}
|
|
7905
|
+
async runAppSetup(appId, app, context) {
|
|
7906
|
+
var _a;
|
|
7907
|
+
this.clearSetupWatchdog();
|
|
7908
|
+
this.setupWatchdogTimer = setTimeout(() => {
|
|
7909
|
+
var _a2;
|
|
7910
|
+
this.setupWatchdogTimer = void 0;
|
|
7911
|
+
if (this.status === "destroyed")
|
|
7912
|
+
return;
|
|
7913
|
+
(_a2 = this.Logger) == null ? void 0 : _a2.warn(
|
|
7914
|
+
`[WindowManager]: hydrate timeout, stage: app setup, kind: ${this.kind}, appId: ${appId}, timeout: ${APP_SETUP_WATCHDOG_TIMEOUT}ms`
|
|
7915
|
+
);
|
|
7916
|
+
}, APP_SETUP_WATCHDOG_TIMEOUT);
|
|
7917
|
+
try {
|
|
7918
|
+
return { succeeded: true, result: await app.setup(context) };
|
|
7919
|
+
} catch (error) {
|
|
7920
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
7921
|
+
(_a = this.Logger) == null ? void 0 : _a.error(
|
|
7922
|
+
`[WindowManager]: app setup error, kind: ${this.kind}, appId: ${appId}, status: ${this.status}, error: ${message}`
|
|
7923
|
+
);
|
|
7924
|
+
return { succeeded: false };
|
|
7925
|
+
} finally {
|
|
7926
|
+
this.clearSetupWatchdog();
|
|
7927
|
+
}
|
|
7928
|
+
}
|
|
7929
|
+
clearSetupWatchdog() {
|
|
7930
|
+
if (this.setupWatchdogTimer != null) {
|
|
7931
|
+
clearTimeout(this.setupWatchdogTimer);
|
|
7932
|
+
this.setupWatchdogTimer = void 0;
|
|
7933
|
+
}
|
|
7934
|
+
}
|
|
7900
7935
|
fixMobileSize() {
|
|
7901
7936
|
var _a, _b;
|
|
7902
7937
|
const box = (_a = this.boxManager) == null ? void 0 : _a.getBox(this.id);
|
|
@@ -8068,6 +8103,7 @@ const _AppProxy = class {
|
|
|
8068
8103
|
if (this.status === "destroyed")
|
|
8069
8104
|
return;
|
|
8070
8105
|
this.status = "destroyed";
|
|
8106
|
+
this.clearSetupWatchdog();
|
|
8071
8107
|
this.boxSizeSynchronizer.destroy();
|
|
8072
8108
|
try {
|
|
8073
8109
|
await appRegister.notifyApp(this.kind, "destroy", { appId: this.id });
|
|
@@ -9472,16 +9508,59 @@ class AppManager {
|
|
|
9472
9508
|
AppManager.kind = "AppManager";
|
|
9473
9509
|
const ResizeObserver = window.ResizeObserver || ResizeObserver$1;
|
|
9474
9510
|
class ContainerResizeObserver {
|
|
9475
|
-
constructor(emitter) {
|
|
9511
|
+
constructor(emitter, logger, getInternalState) {
|
|
9476
9512
|
this.emitter = emitter;
|
|
9513
|
+
this.getInternalState = getInternalState;
|
|
9477
9514
|
this.updateSizerLocalConsole = new LocalConsole("updateSizer", 100);
|
|
9515
|
+
this.flushContainerStateLog = () => {
|
|
9516
|
+
var _a, _b, _c, _d;
|
|
9517
|
+
this.containerStateLogTimer = void 0;
|
|
9518
|
+
const pendingState = this.pendingContainerState;
|
|
9519
|
+
this.pendingContainerState = void 0;
|
|
9520
|
+
if (!pendingState || !this.containerStateArgusLog || !this.container || !this.sizer || !this.wrapper) {
|
|
9521
|
+
return;
|
|
9522
|
+
}
|
|
9523
|
+
const internalState = (_a = this.getInternalState) == null ? void 0 : _a.call(this);
|
|
9524
|
+
const root = this.container.parentElement;
|
|
9525
|
+
const rootRect = root == null ? void 0 : root.getBoundingClientRect();
|
|
9526
|
+
const playgroundRect = this.container.getBoundingClientRect();
|
|
9527
|
+
const sizerRect = this.sizer.getBoundingClientRect();
|
|
9528
|
+
const wrapperRect = this.wrapper.getBoundingClientRect();
|
|
9529
|
+
const mainViewRect = (_b = internalState == null ? void 0 : internalState.mainViewElement) == null ? void 0 : _b.getBoundingClientRect();
|
|
9530
|
+
const rootStyle = root ? window.getComputedStyle(root) : void 0;
|
|
9531
|
+
this.containerStateArgusLog.log(
|
|
9532
|
+
`origin: ${pendingState.origin || "unknown"}, connected: ${Boolean(
|
|
9533
|
+
root == null ? void 0 : root.isConnected
|
|
9534
|
+
)}, observed: ${this.formatSize(
|
|
9535
|
+
pendingState.observedSize || playgroundRect
|
|
9536
|
+
)}, root: ${this.formatSize(rootRect)}, playground: ${this.formatSize(
|
|
9537
|
+
playgroundRect
|
|
9538
|
+
)}, sizer: ${this.formatSize(sizerRect)}, wrapper: ${this.formatSize(
|
|
9539
|
+
wrapperRect
|
|
9540
|
+
)}, mainViewDOM: ${this.formatSize(mainViewRect)}, mainViewSize: ${this.formatSize(
|
|
9541
|
+
internalState == null ? void 0 : internalState.mainViewSize
|
|
9542
|
+
)}, teleBoxRect: ${this.formatSize(
|
|
9543
|
+
internalState == null ? void 0 : internalState.teleBoxContainerRect
|
|
9544
|
+
)}, didRelease: ${(_c = internalState == null ? void 0 : internalState.mainViewDidRelease) != null ? _c : "unknown"}, ratio: ${(_d = internalState == null ? void 0 : internalState.containerSizeRatio) != null ? _d : "unknown"}, display: ${(rootStyle == null ? void 0 : rootStyle.display) || "unknown"}, visibility: ${(rootStyle == null ? void 0 : rootStyle.visibility) || "unknown"}, clientRects: ${(root == null ? void 0 : root.getClientRects().length) || 0}, inViewport: ${rootRect ? rootRect.bottom > 0 && rootRect.right > 0 && rootRect.top < window.innerHeight && rootRect.left < window.innerWidth : false}`
|
|
9545
|
+
);
|
|
9546
|
+
};
|
|
9547
|
+
if (logger) {
|
|
9548
|
+
this.containerStateArgusLog = new ArgusLog(logger, "containerState");
|
|
9549
|
+
}
|
|
9478
9550
|
}
|
|
9479
|
-
static create(container, sizer, wrapper, emitter) {
|
|
9480
|
-
const containerResizeObserver = new ContainerResizeObserver(
|
|
9551
|
+
static create(container, sizer, wrapper, emitter, logger, getInternalState) {
|
|
9552
|
+
const containerResizeObserver = new ContainerResizeObserver(
|
|
9553
|
+
emitter,
|
|
9554
|
+
logger,
|
|
9555
|
+
getInternalState
|
|
9556
|
+
);
|
|
9481
9557
|
containerResizeObserver.observePlaygroundSize(container, sizer, wrapper);
|
|
9482
9558
|
return containerResizeObserver;
|
|
9483
9559
|
}
|
|
9484
9560
|
observePlaygroundSize(container, sizer, wrapper) {
|
|
9561
|
+
this.container = container;
|
|
9562
|
+
this.sizer = sizer;
|
|
9563
|
+
this.wrapper = wrapper;
|
|
9485
9564
|
this.updateSizer(
|
|
9486
9565
|
container.getBoundingClientRect(),
|
|
9487
9566
|
sizer,
|
|
@@ -9504,6 +9583,7 @@ class ContainerResizeObserver {
|
|
|
9504
9583
|
this.containerResizeObserver.observe(container);
|
|
9505
9584
|
}
|
|
9506
9585
|
updateSizer({ width, height }, sizer, wrapper, origin) {
|
|
9586
|
+
const observedSize = { width, height };
|
|
9507
9587
|
if (width && height) {
|
|
9508
9588
|
if (height / width > WindowManager.containerSizeRatio) {
|
|
9509
9589
|
height = width * WindowManager.containerSizeRatio;
|
|
@@ -9524,13 +9604,48 @@ class ContainerResizeObserver {
|
|
|
9524
9604
|
origin
|
|
9525
9605
|
});
|
|
9526
9606
|
}
|
|
9607
|
+
this.scheduleContainerStateLog(origin, observedSize);
|
|
9608
|
+
}
|
|
9609
|
+
logCurrentState(origin) {
|
|
9610
|
+
this.scheduleContainerStateLog(origin);
|
|
9611
|
+
}
|
|
9612
|
+
scheduleContainerStateLog(origin, observedSize) {
|
|
9613
|
+
if (!this.containerStateArgusLog || !this.container || !this.sizer || !this.wrapper)
|
|
9614
|
+
return;
|
|
9615
|
+
this.pendingContainerState = {
|
|
9616
|
+
origin,
|
|
9617
|
+
observedSize: observedSize ? { width: observedSize.width, height: observedSize.height } : void 0
|
|
9618
|
+
};
|
|
9619
|
+
if (this.containerStateLogTimer != null) {
|
|
9620
|
+
clearTimeout(this.containerStateLogTimer);
|
|
9621
|
+
}
|
|
9622
|
+
this.containerStateLogTimer = setTimeout(
|
|
9623
|
+
this.flushContainerStateLog,
|
|
9624
|
+
CONTAINER_STATE_LOG_DEBOUNCE
|
|
9625
|
+
);
|
|
9626
|
+
}
|
|
9627
|
+
formatSize(rect) {
|
|
9628
|
+
if (!rect)
|
|
9629
|
+
return "unknown";
|
|
9630
|
+
return `${Math.round(rect.width * 100) / 100}x${Math.round(rect.height * 100) / 100}`;
|
|
9527
9631
|
}
|
|
9528
9632
|
disconnect() {
|
|
9529
|
-
var _a, _b;
|
|
9633
|
+
var _a, _b, _c;
|
|
9530
9634
|
this.updateSizerLocalConsole.destroy();
|
|
9531
|
-
(
|
|
9532
|
-
|
|
9635
|
+
if (this.containerStateLogTimer != null) {
|
|
9636
|
+
clearTimeout(this.containerStateLogTimer);
|
|
9637
|
+
this.containerStateLogTimer = void 0;
|
|
9638
|
+
}
|
|
9639
|
+
this.pendingContainerState = void 0;
|
|
9640
|
+
(_a = this.containerStateArgusLog) == null ? void 0 : _a.destroy();
|
|
9641
|
+
this.containerStateArgusLog = void 0;
|
|
9642
|
+
(_b = this.containerResizeObserver) == null ? void 0 : _b.disconnect();
|
|
9643
|
+
(_c = this.disposer) == null ? void 0 : _c.call(this);
|
|
9533
9644
|
this.disposer = void 0;
|
|
9645
|
+
this.container = void 0;
|
|
9646
|
+
this.sizer = void 0;
|
|
9647
|
+
this.wrapper = void 0;
|
|
9648
|
+
this.getInternalState = void 0;
|
|
9534
9649
|
}
|
|
9535
9650
|
}
|
|
9536
9651
|
class PageStateImpl {
|
|
@@ -10387,7 +10502,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter: internalEmitter });
|
|
|
10387
10502
|
const _WindowManager = class extends InvisiblePlugin {
|
|
10388
10503
|
constructor(context) {
|
|
10389
10504
|
super(context);
|
|
10390
|
-
this.version = "1.0.
|
|
10505
|
+
this.version = "1.0.20";
|
|
10391
10506
|
this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.3.0", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.57" }, "devDependencies": { "@hyrious/dts": "^0.2.2", "@netless/app-docs-viewer": "^0.2.19", "@netless/app-media-player": "0.1.4", "@netless/app-presentation": "^0.1.10", "@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.30", "@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", "jspdf": "^2.5.1", "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", "side-effect-manager": "0.1.5", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.9.9", "vitest": "^0.14.1", "white-web-sdk": "^2.16.57" } };
|
|
10392
10507
|
this.emitter = callbacks;
|
|
10393
10508
|
this.viewMode = ViewMode.Broadcaster;
|
|
@@ -10577,7 +10692,19 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
|
10577
10692
|
playground,
|
|
10578
10693
|
sizer,
|
|
10579
10694
|
wrapper,
|
|
10580
|
-
internalEmitter
|
|
10695
|
+
internalEmitter,
|
|
10696
|
+
manager.Logger,
|
|
10697
|
+
() => {
|
|
10698
|
+
var _a, _b;
|
|
10699
|
+
const mainView = (_a = manager.appManager) == null ? void 0 : _a.mainViewProxy.view;
|
|
10700
|
+
return {
|
|
10701
|
+
mainViewElement: mainView == null ? void 0 : mainView.divElement,
|
|
10702
|
+
mainViewSize: mainView == null ? void 0 : mainView.size,
|
|
10703
|
+
teleBoxContainerRect: (_b = manager.boxManager) == null ? void 0 : _b.teleBoxManager.containerRect,
|
|
10704
|
+
mainViewDidRelease: Boolean(mainView == null ? void 0 : mainView.didRelease),
|
|
10705
|
+
containerSizeRatio: manager.containerSizeRatio
|
|
10706
|
+
};
|
|
10707
|
+
}
|
|
10581
10708
|
);
|
|
10582
10709
|
_WindowManager.wrapper = wrapper;
|
|
10583
10710
|
_WindowManager.sizer = sizer;
|
|
@@ -10587,7 +10714,7 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
|
10587
10714
|
return appRegister.registered;
|
|
10588
10715
|
}
|
|
10589
10716
|
bindContainer(container) {
|
|
10590
|
-
var _a, _b, _c, _d, _e, _f;
|
|
10717
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
10591
10718
|
if (isRoom(this.displayer) && this.room.phase !== RoomPhase.Connected) {
|
|
10592
10719
|
throw new BindContainerRoomPhaseInvalidError();
|
|
10593
10720
|
}
|
|
@@ -10625,7 +10752,8 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
|
10625
10752
|
(_d = this.appManager) == null ? void 0 : _d.resetMinimized();
|
|
10626
10753
|
(_e = this.appManager) == null ? void 0 : _e.displayerWritableListener(!this.room.isWritable);
|
|
10627
10754
|
_WindowManager.container = container;
|
|
10628
|
-
(_f = this.
|
|
10755
|
+
(_f = this.containerResizeObserver) == null ? void 0 : _f.logCurrentState("bindContainer");
|
|
10756
|
+
(_g = this.extendPluginManager) == null ? void 0 : _g.refreshContainer(container);
|
|
10629
10757
|
}
|
|
10630
10758
|
bindCollectorContainer(container) {
|
|
10631
10759
|
if (_WindowManager.isCreated && this.boxManager) {
|