@netless/window-manager 0.4.0-canary.26 → 0.4.0-canary.27
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/AppManager.d.ts +1 -0
- package/dist/Utils/AppCreateQueue.d.ts +11 -0
- package/dist/Utils/RoomHacker.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.es.js +5 -5
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +5 -5
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/AppManager.ts +35 -31
- package/src/AppProxy.ts +1 -1
- package/src/Utils/AppCreateQueue.ts +54 -0
- package/src/Utils/RoomHacker.ts +2 -1
- package/src/index.ts +10 -3
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@netless/window-manager",
|
3
|
-
"version": "0.4.0-canary.
|
3
|
+
"version": "0.4.0-canary.27",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.es.js",
|
6
6
|
"module": "dist/index.es.js",
|
@@ -33,7 +33,7 @@
|
|
33
33
|
"devDependencies": {
|
34
34
|
"@netless/app-docs-viewer": "^0.2.6",
|
35
35
|
"@netless/app-media-player": "0.1.0-beta.5",
|
36
|
-
"@netless/telebox-insider": "0.2.
|
36
|
+
"@netless/telebox-insider": "0.2.22",
|
37
37
|
"@rollup/plugin-commonjs": "^20.0.0",
|
38
38
|
"@rollup/plugin-node-resolve": "^13.0.4",
|
39
39
|
"@rollup/plugin-url": "^6.1.0",
|
package/src/AppManager.ts
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
import pRetry from "p-retry";
|
2
1
|
import { AppAttributes, AppStatus, Events, MagixEventName, ROOT_DIR } from "./constants";
|
3
2
|
import { AppListeners } from "./AppListener";
|
4
3
|
import { AppProxy } from "./AppProxy";
|
4
|
+
import { appRegister } from "./Register";
|
5
5
|
import { autorun, isPlayer, isRoom, ScenePathType } from "white-web-sdk";
|
6
|
-
import { callbacks, emitter,
|
6
|
+
import { callbacks, emitter, reconnectRefresher, WindowManager } from "./index";
|
7
|
+
import { get, isInteger, orderBy } from "lodash";
|
8
|
+
import { log } from "./Utils/log";
|
9
|
+
import { MainViewProxy } from "./View/MainView";
|
10
|
+
import { onObjectRemoved, safeListenPropsUpdated } from "./Utils/Reactive";
|
11
|
+
import { store } from "./AttributesDelegate";
|
12
|
+
import { ViewManager } from "./View/ViewManager";
|
7
13
|
import {
|
8
14
|
entireScenes,
|
9
15
|
genAppId,
|
@@ -12,17 +18,11 @@ import {
|
|
12
18
|
setScenePath,
|
13
19
|
setViewFocusScenePath,
|
14
20
|
} from "./Utils/Common";
|
15
|
-
import { log } from "./Utils/log";
|
16
|
-
import { MainViewProxy } from "./View/MainView";
|
17
|
-
import { onObjectRemoved, safeListenPropsUpdated } from "./Utils/Reactive";
|
18
|
-
import { get, isInteger, sortBy } from "lodash";
|
19
|
-
import { store } from "./AttributesDelegate";
|
20
|
-
import { ViewManager } from "./View/ViewManager";
|
21
21
|
import type { ReconnectRefresher } from "./ReconnectRefresher";
|
22
22
|
import type { BoxManager } from "./BoxManager";
|
23
23
|
import type { Displayer, DisplayerState, Room, ScenesCallbacksNode } from "white-web-sdk";
|
24
24
|
import type { AddAppParams, BaseInsertParams, TeleBoxRect, EmitterEvent } from "./index";
|
25
|
-
import {
|
25
|
+
import { AppCreateQueue } from "./Utils/AppCreateQueue";
|
26
26
|
|
27
27
|
export class AppManager {
|
28
28
|
public displayer: Displayer;
|
@@ -41,6 +41,7 @@ export class AppManager {
|
|
41
41
|
private _prevSceneIndex: number | undefined;
|
42
42
|
private _prevFocused: string | undefined;
|
43
43
|
private callbacksNode: ScenesCallbacksNode | null;
|
44
|
+
private appCreateQueue = new AppCreateQueue();
|
44
45
|
|
45
46
|
constructor(public windowManger: WindowManager) {
|
46
47
|
this.displayer = windowManger.displayer;
|
@@ -185,13 +186,18 @@ export class AppManager {
|
|
185
186
|
return autorun(() => {
|
186
187
|
const focused = get(this.attributes, "focus");
|
187
188
|
if (this._prevFocused !== focused) {
|
188
|
-
this.boxManager?.focusBox({ appId: focused });
|
189
|
-
const appProxy = this.appProxies.get(focused);
|
190
|
-
if (appProxy) {
|
191
|
-
appRegister.notifyApp(appProxy.kind, "focus", { appId: focused });
|
192
|
-
}
|
193
189
|
callbacks.emit("focusedChange", focused);
|
194
190
|
this._prevFocused = focused;
|
191
|
+
if (focused !== undefined) {
|
192
|
+
this.boxManager?.focusBox({ appId: focused });
|
193
|
+
// 确保 focus 修改的时候, appProxy 已经创建
|
194
|
+
setTimeout(() => {
|
195
|
+
const appProxy = this.appProxies.get(focused);
|
196
|
+
if (appProxy) {
|
197
|
+
appRegister.notifyApp(appProxy.kind, "focus", { appId: focused });
|
198
|
+
}
|
199
|
+
}, 0);
|
200
|
+
}
|
195
201
|
}
|
196
202
|
});
|
197
203
|
});
|
@@ -223,19 +229,18 @@ export class AppManager {
|
|
223
229
|
createdAt: apps[appId].createdAt,
|
224
230
|
};
|
225
231
|
});
|
226
|
-
for (const { id } of
|
232
|
+
for (const { id } of orderBy(appsWithCreatedAt, "createdAt", "asc")) {
|
227
233
|
if (!this.appProxies.has(id) && !this.appStatus.has(id)) {
|
228
234
|
const app = apps[id];
|
229
235
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
await this.baseInsertApp(
|
236
|
+
this.appStatus.set(id, AppStatus.StartCreate);
|
237
|
+
try {
|
238
|
+
const appAttributes = this.attributes[id];
|
239
|
+
if (!appAttributes) {
|
240
|
+
throw new Error("appAttributes is undefined");
|
241
|
+
}
|
242
|
+
this.appCreateQueue.push(() => {
|
243
|
+
return this.baseInsertApp(
|
239
244
|
{
|
240
245
|
kind: app.kind,
|
241
246
|
options: app.options,
|
@@ -244,13 +249,11 @@ export class AppManager {
|
|
244
249
|
id,
|
245
250
|
false
|
246
251
|
);
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
this.appStatus.delete(id);
|
253
|
-
});
|
252
|
+
});
|
253
|
+
this.focusByAttributes(apps);
|
254
|
+
} catch (error) {
|
255
|
+
console.warn(`[WindowManager]: Insert App Error`, error);
|
256
|
+
}
|
254
257
|
}
|
255
258
|
}
|
256
259
|
}
|
@@ -583,6 +586,7 @@ export class AppManager {
|
|
583
586
|
this.mainViewProxy.destroy();
|
584
587
|
callbacks.clearListeners();
|
585
588
|
this.callbacksNode?.dispose();
|
589
|
+
this.appCreateQueue.destroy();
|
586
590
|
this._prevSceneIndex = undefined;
|
587
591
|
}
|
588
592
|
}
|
package/src/AppProxy.ts
CHANGED
@@ -165,7 +165,7 @@ export class AppProxy {
|
|
165
165
|
// 延迟执行 setup, 防止初始化的属性没有更新成功
|
166
166
|
const result = await app.setup(context);
|
167
167
|
this.appResult = result;
|
168
|
-
appRegister.notifyApp(
|
168
|
+
appRegister.notifyApp(this.kind, "created", { appId, result });
|
169
169
|
this.afterSetupApp(boxInitState);
|
170
170
|
this.fixMobileSize();
|
171
171
|
}, 50);
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import type { AppProxy } from "../AppProxy";
|
2
|
+
|
3
|
+
export type Invoker = () => Promise<AppProxy | undefined>;
|
4
|
+
|
5
|
+
export class AppCreateQueue {
|
6
|
+
private list: Invoker[] = [];
|
7
|
+
private currentInvoker: Invoker | undefined;
|
8
|
+
private timer: number | undefined;
|
9
|
+
|
10
|
+
private initInterval() {
|
11
|
+
return setInterval(() => {
|
12
|
+
this.invoke();
|
13
|
+
}, 50);
|
14
|
+
}
|
15
|
+
|
16
|
+
public push(item: Invoker) {
|
17
|
+
this.list.push(item);
|
18
|
+
this.invoke();
|
19
|
+
if (this.timer === undefined && this.list.length > 0) {
|
20
|
+
this.timer = this.initInterval();
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
public invoke() {
|
25
|
+
if (this.list.length === 0) {
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
if (this.currentInvoker !== undefined) {
|
29
|
+
return;
|
30
|
+
}
|
31
|
+
|
32
|
+
const item = this.list.shift();
|
33
|
+
if (item) {
|
34
|
+
this.currentInvoker = item;
|
35
|
+
item()
|
36
|
+
.then(() => {
|
37
|
+
this.currentInvoker = undefined;
|
38
|
+
if (this.list.length === 0) {
|
39
|
+
clearInterval(this.timer);
|
40
|
+
}
|
41
|
+
})
|
42
|
+
.catch(error => {
|
43
|
+
console.error(`[WindowManager]: create app error: ${error.message}`);
|
44
|
+
clearInterval(this.timer);
|
45
|
+
});
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
public destroy() {
|
50
|
+
if (this.timer) {
|
51
|
+
clearInterval(this.timer);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
package/src/Utils/RoomHacker.ts
CHANGED
@@ -4,11 +4,12 @@ import type { WindowManager } from "../index";
|
|
4
4
|
import type { Camera, Room, Player, PlayerSeekingResult } from "white-web-sdk";
|
5
5
|
|
6
6
|
// 修改多窗口状态下一些失效的方法实现到 manager 的 mainview 上, 降低迁移成本
|
7
|
-
export const replaceRoomFunction = (room: Room, manager: WindowManager) => {
|
7
|
+
export const replaceRoomFunction = (room: Room | Player, manager: WindowManager) => {
|
8
8
|
if (isPlayer(room)) {
|
9
9
|
const player = room as unknown as Player;
|
10
10
|
delegateSeekToProgressTime(player);
|
11
11
|
} else {
|
12
|
+
room = room as unknown as Room;
|
12
13
|
const descriptor = Object.getOwnPropertyDescriptor(room, "disableCameraTransform");
|
13
14
|
if (descriptor) return;
|
14
15
|
Object.defineProperty(room, "disableCameraTransform", {
|
package/src/index.ts
CHANGED
@@ -54,6 +54,7 @@ import type {
|
|
54
54
|
Rectangle,
|
55
55
|
ViewVisionMode,
|
56
56
|
CameraState,
|
57
|
+
Player,
|
57
58
|
} from "white-web-sdk";
|
58
59
|
import type { AppListeners } from "./AppListener";
|
59
60
|
import type { NetlessApp, RegisterParams } from "./typings";
|
@@ -161,7 +162,7 @@ export type PublicEvent = {
|
|
161
162
|
};
|
162
163
|
|
163
164
|
export type MountParams = {
|
164
|
-
room: Room;
|
165
|
+
room: Room | Player;
|
165
166
|
container?: HTMLElement;
|
166
167
|
/** 白板高宽比例, 默认为 9 / 16 */
|
167
168
|
containerSizeRatio?: number;
|
@@ -224,6 +225,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
224
225
|
WindowManager.params = params;
|
225
226
|
|
226
227
|
this.checkVersion();
|
228
|
+
let manager: WindowManager | undefined = undefined;
|
227
229
|
if (isRoom(room)) {
|
228
230
|
if (room.phase !== RoomPhase.Connected) {
|
229
231
|
throw new Error("[WindowManager]: Room only Connected can be mount");
|
@@ -232,11 +234,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
232
234
|
// redo undo 需要设置这个属性
|
233
235
|
room.disableSerialization = false;
|
234
236
|
}
|
237
|
+
manager = await this.initManager(room);
|
235
238
|
}
|
236
239
|
if (WindowManager.isCreated) {
|
237
240
|
throw new Error("[WindowManager]: Already created cannot be created again");
|
238
241
|
}
|
239
|
-
|
242
|
+
|
240
243
|
this.debug = Boolean(debug);
|
241
244
|
log("Already insert room", manager);
|
242
245
|
|
@@ -247,7 +250,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
247
250
|
} else {
|
248
251
|
await pRetry(
|
249
252
|
async count => {
|
250
|
-
manager = await
|
253
|
+
manager = (await room.getInvisiblePlugin(WindowManager.kind)) as WindowManager;
|
251
254
|
if (!manager) {
|
252
255
|
log(`manager is empty. retrying ${count}`);
|
253
256
|
throw new Error();
|
@@ -257,6 +260,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
257
260
|
);
|
258
261
|
}
|
259
262
|
|
263
|
+
if (!manager) {
|
264
|
+
throw new Error("[WindowManager]: create manager failed");
|
265
|
+
}
|
266
|
+
|
260
267
|
if (containerSizeRatio) {
|
261
268
|
WindowManager.containerSizeRatio = containerSizeRatio;
|
262
269
|
}
|