@netless/window-manager 1.0.0-canary.3 → 1.0.0-canary.32
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/__mocks__/white-web-sdk.ts +10 -1
- package/dist/index.cjs.js +120 -12
- package/dist/index.es.js +2284 -954
- package/dist/index.umd.js +120 -12
- package/dist/{App → src/App}/AppContext.d.ts +12 -8
- package/dist/{App → src/App}/AppPageStateImpl.d.ts +0 -0
- package/dist/{App → src/App}/AppProxy.d.ts +36 -7
- package/dist/{App → src/App}/MagixEvent/index.d.ts +0 -0
- package/dist/{App → src/App}/Storage/StorageEvent.d.ts +0 -0
- package/dist/{App → src/App}/Storage/index.d.ts +0 -0
- package/dist/{App → src/App}/Storage/typings.d.ts +0 -0
- package/dist/{App → src/App}/Storage/utils.d.ts +0 -0
- package/dist/src/App/WhiteboardView.d.ts +27 -0
- package/dist/{App → src/App}/index.d.ts +2 -1
- package/dist/src/App/type.d.ts +21 -0
- package/dist/{AppListener.d.ts → src/AppListener.d.ts} +0 -2
- package/dist/{AppManager.d.ts → src/AppManager.d.ts} +7 -6
- package/dist/{AttributesDelegate.d.ts → src/AttributesDelegate.d.ts} +11 -16
- package/dist/{BoxEmitter.d.ts → src/BoxEmitter.d.ts} +0 -0
- package/dist/{BoxManager.d.ts → src/BoxManager.d.ts} +10 -7
- package/dist/{BuiltinApps.d.ts → src/BuiltinApps.d.ts} +3 -0
- package/dist/{Cursor → src/Cursor}/Cursor.d.ts +0 -0
- package/dist/{Cursor → src/Cursor}/icons.d.ts +0 -0
- package/dist/{Cursor → src/Cursor}/index.d.ts +3 -3
- package/dist/{Helper.d.ts → src/Helper.d.ts} +4 -8
- package/dist/{InternalEmitter.d.ts → src/InternalEmitter.d.ts} +3 -4
- package/dist/{Page → src/Page}/PageController.d.ts +1 -0
- package/dist/{Page → src/Page}/index.d.ts +0 -0
- package/dist/{PageState.d.ts → src/PageState.d.ts} +0 -0
- package/dist/{ReconnectRefresher.d.ts → src/ReconnectRefresher.d.ts} +1 -1
- package/dist/{RedoUndo.d.ts → src/RedoUndo.d.ts} +0 -0
- package/dist/{Register → src/Register}/index.d.ts +0 -0
- package/dist/{Register → src/Register}/loader.d.ts +0 -0
- package/dist/{Register → src/Register}/storage.d.ts +0 -0
- package/dist/{Utils → src/Utils}/AppCreateQueue.d.ts +0 -0
- package/dist/{Utils → src/Utils}/Common.d.ts +1 -0
- package/dist/{Utils → src/Utils}/Reactive.d.ts +0 -0
- package/dist/{Utils → src/Utils}/RoomHacker.d.ts +0 -0
- package/dist/{Utils → src/Utils}/error.d.ts +0 -0
- package/dist/{Utils → src/Utils}/log.d.ts +0 -0
- package/dist/src/View/CameraSynchronizer.d.ts +18 -0
- package/dist/{View → src/View}/MainView.d.ts +18 -7
- package/dist/{View → src/View}/ViewManager.d.ts +0 -0
- package/dist/src/View/ViewSync.d.ts +24 -0
- package/dist/{callback.d.ts → src/callback.d.ts} +5 -0
- package/dist/{constants.d.ts → src/constants.d.ts} +8 -5
- package/dist/src/image.d.ts +19 -0
- package/dist/{index.d.ts → src/index.d.ts} +40 -14
- package/dist/src/shim.d.ts +11 -0
- package/dist/{typings.d.ts → src/typings.d.ts} +8 -2
- package/dist/style.css +1 -1
- package/docs/app-context.md +157 -25
- package/docs/mirgrate-to-1.0.md +28 -0
- package/package.json +12 -7
- package/playwright.config.ts +29 -0
- package/pnpm-lock.yaml +517 -35
- package/src/App/AppContext.ts +50 -28
- package/src/App/AppProxy.ts +266 -80
- package/src/App/{WhiteBoardView.ts → WhiteboardView.ts} +38 -7
- package/src/App/index.ts +2 -1
- package/src/App/type.ts +22 -0
- package/src/AppListener.ts +5 -21
- package/src/AppManager.ts +56 -43
- package/src/AttributesDelegate.ts +19 -19
- package/src/BoxManager.ts +60 -40
- package/src/BuiltinApps.ts +5 -0
- package/src/Cursor/Cursor.ts +7 -3
- package/src/Cursor/index.ts +7 -8
- package/src/Helper.ts +25 -7
- package/src/InternalEmitter.ts +3 -4
- package/src/Page/PageController.ts +1 -0
- package/src/PageState.ts +1 -1
- package/src/ReconnectRefresher.ts +7 -2
- package/src/Utils/Common.ts +9 -0
- package/src/Utils/Reactive.ts +27 -26
- package/src/Utils/RoomHacker.ts +3 -0
- package/src/View/CameraSynchronizer.ts +37 -34
- package/src/View/MainView.ts +108 -81
- package/src/View/ViewSync.ts +110 -0
- package/src/callback.ts +1 -0
- package/src/constants.ts +6 -3
- package/src/index.ts +141 -57
- package/src/style.css +3 -46
- package/src/typings.ts +8 -2
- package/vite.config.js +5 -3
- package/dist/App/WhiteBoardView.d.ts +0 -18
- package/dist/View/CameraSynchronizer.d.ts +0 -17
@@ -1,30 +1,61 @@
|
|
1
1
|
import { putScenes } from "../Utils/Common";
|
2
2
|
import { Val } from "value-enhancer";
|
3
|
+
import { pick } from "lodash";
|
3
4
|
|
4
5
|
import type { ReadonlyVal } from "value-enhancer";
|
5
6
|
import type { AddPageParams, PageController, PageState } from "../Page";
|
6
7
|
import type { AppProxy } from "./AppProxy";
|
7
8
|
import type { AppContext } from "./AppContext";
|
9
|
+
import type { Camera, View } from "white-web-sdk";
|
10
|
+
import type { TeleBoxRect } from "@netless/telebox-insider";
|
11
|
+
import type { ICamera, ISize } from "../AttributesDelegate";
|
12
|
+
|
13
|
+
export type WhiteBoardViewCamera = Omit<ICamera, "id">;
|
14
|
+
export type WhiteBoardViewRect = Omit<ISize, "id">;
|
8
15
|
|
9
16
|
export class WhiteBoardView implements PageController {
|
10
17
|
public readonly pageState$: ReadonlyVal<PageState>;
|
18
|
+
public readonly baseCamera$: ReadonlyVal<WhiteBoardViewCamera>;
|
19
|
+
public readonly baseRect$: ReadonlyVal<WhiteBoardViewRect | undefined>;
|
11
20
|
|
12
21
|
constructor(
|
13
|
-
|
22
|
+
public view: View,
|
23
|
+
protected appContext: AppContext,
|
14
24
|
protected appProxy: AppProxy,
|
15
|
-
|
25
|
+
public ensureSize: (size: number) => void
|
16
26
|
) {
|
17
27
|
const pageState$ = new Val<PageState>(appProxy.pageState);
|
28
|
+
const baseRect$ = new Val<WhiteBoardViewRect | undefined>(appProxy.size$.value);
|
29
|
+
const pickCamera = (camera: Camera | ICamera) =>
|
30
|
+
pick(camera, ["centerX", "centerY", "scale"]);
|
31
|
+
const camera$ = new Val<WhiteBoardViewCamera>(pickCamera(this.view.camera));
|
32
|
+
this.baseRect$ = baseRect$;
|
18
33
|
this.pageState$ = pageState$;
|
19
|
-
|
20
|
-
|
21
|
-
|
34
|
+
this.baseCamera$ = camera$;
|
35
|
+
this.appProxy.sideEffectManager.add(() => [
|
36
|
+
appProxy.appEmitter.on("pageStateChange", pageState => pageState$.setValue(pageState)),
|
37
|
+
appProxy.camera$.subscribe(camera => {
|
38
|
+
if (camera) {
|
39
|
+
camera$.setValue(pickCamera(camera));
|
40
|
+
}
|
41
|
+
}),
|
42
|
+
appProxy.size$.subscribe(size => {
|
43
|
+
if (size) {
|
44
|
+
baseRect$.setValue(pick(size, ["width", "height"]));
|
45
|
+
}
|
46
|
+
}),
|
47
|
+
]);
|
48
|
+
view.disableCameraTransform = true;
|
22
49
|
}
|
23
50
|
|
24
51
|
public get pageState() {
|
25
52
|
return this.pageState$.value;
|
26
53
|
}
|
27
54
|
|
55
|
+
public moveCamera(camera: Partial<WhiteBoardViewCamera>) {
|
56
|
+
this.appProxy.moveCamera(camera);
|
57
|
+
}
|
58
|
+
|
28
59
|
public nextPage = async (): Promise<boolean> => {
|
29
60
|
const nextIndex = this.pageState.index + 1;
|
30
61
|
return this.jumpPage(nextIndex);
|
@@ -70,7 +101,7 @@ export class WhiteBoardView implements PageController {
|
|
70
101
|
return this.appProxy.removeSceneByIndex(needRemoveIndex);
|
71
102
|
};
|
72
103
|
|
73
|
-
public
|
74
|
-
this.
|
104
|
+
public setBaseRect(rect: Omit<TeleBoxRect, "x" | "y">) {
|
105
|
+
this.appProxy.updateSize(rect.width, rect.height);
|
75
106
|
}
|
76
107
|
}
|
package/src/App/index.ts
CHANGED
package/src/App/type.ts
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
export type AppState = {
|
3
|
+
id: string;
|
4
|
+
focus?: boolean;
|
5
|
+
SceneIndex?: number;
|
6
|
+
draggable?: boolean;
|
7
|
+
position?: {
|
8
|
+
x: number;
|
9
|
+
y: number;
|
10
|
+
}
|
11
|
+
ratio?: number;
|
12
|
+
resizable?: boolean;
|
13
|
+
size?: {
|
14
|
+
width: number;
|
15
|
+
height: number;
|
16
|
+
}
|
17
|
+
stageRatio?: number;
|
18
|
+
visible?: boolean;
|
19
|
+
zIndex?: number;
|
20
|
+
maximized: boolean | null;
|
21
|
+
minimized: boolean | null;
|
22
|
+
}
|
package/src/AppListener.ts
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
import { callbacks } from "./callback";
|
2
2
|
import { emitter } from "./InternalEmitter";
|
3
3
|
import { Events, MagixEventName } from "./constants";
|
4
|
-
import { isEqual, omit } from "lodash";
|
5
4
|
import { setViewFocusScenePath } from "./Utils/Common";
|
6
|
-
import type {
|
5
|
+
import type { Event } from "white-web-sdk";
|
7
6
|
import type { AppManager } from "./AppManager";
|
8
7
|
import type { TeleBoxState } from "@netless/telebox-insider";
|
9
8
|
|
@@ -50,14 +49,6 @@ export class AppListeners {
|
|
50
49
|
this.setMainViewScenePathHandler(data.payload);
|
51
50
|
break;
|
52
51
|
}
|
53
|
-
case Events.MoveCamera: {
|
54
|
-
this.moveCameraHandler(data.payload);
|
55
|
-
break;
|
56
|
-
}
|
57
|
-
case Events.MoveCameraToContain: {
|
58
|
-
this.moveCameraToContainHandler(data.payload);
|
59
|
-
break;
|
60
|
-
}
|
61
52
|
case Events.CursorMove: {
|
62
53
|
this.cursorMoveHandler(data.payload);
|
63
54
|
break;
|
@@ -78,6 +69,10 @@ export class AppListeners {
|
|
78
69
|
this.setAppFocusViewIndexHandler(data.payload);
|
79
70
|
break;
|
80
71
|
}
|
72
|
+
case Events.InvokeAttributesUpdateCallback: {
|
73
|
+
this.manager.attributesUpdateCallback(this.manager.attributes.apps);
|
74
|
+
break;
|
75
|
+
}
|
81
76
|
default:
|
82
77
|
break;
|
83
78
|
}
|
@@ -102,17 +97,6 @@ export class AppListeners {
|
|
102
97
|
callbacks.emit("mainViewScenePathChange", nextScenePath);
|
103
98
|
};
|
104
99
|
|
105
|
-
private moveCameraHandler = (
|
106
|
-
payload: Camera & { animationMode?: AnimationMode | undefined }
|
107
|
-
) => {
|
108
|
-
if (isEqual(omit(payload, ["animationMode"]), { ...this.manager.mainView.camera })) return;
|
109
|
-
this.manager.mainView.moveCamera(payload);
|
110
|
-
};
|
111
|
-
|
112
|
-
private moveCameraToContainHandler = (payload: any) => {
|
113
|
-
this.manager.mainView.moveCameraToContain(payload);
|
114
|
-
};
|
115
|
-
|
116
100
|
private cursorMoveHandler = (payload: any) => {
|
117
101
|
emitter.emit("cursorMove", payload);
|
118
102
|
};
|
package/src/AppManager.ts
CHANGED
@@ -3,7 +3,7 @@ import { AppCreateQueue } from "./Utils/AppCreateQueue";
|
|
3
3
|
import { AppListeners } from "./AppListener";
|
4
4
|
import { AppProxy } from "./App";
|
5
5
|
import { appRegister } from "./Register";
|
6
|
-
import { autorun, isPlayer, isRoom, ScenePathType } from "white-web-sdk";
|
6
|
+
import { autorun, isPlayer, isRoom, ScenePathType, toJS } from "white-web-sdk";
|
7
7
|
import { boxEmitter } from "./BoxEmitter";
|
8
8
|
import { calculateNextIndex } from "./Page";
|
9
9
|
import { callbacks } from "./callback";
|
@@ -18,6 +18,7 @@ import { RedoUndo } from "./RedoUndo";
|
|
18
18
|
import { serializeRoomMembers } from "./Helper";
|
19
19
|
import { SideEffectManager } from "side-effect-manager";
|
20
20
|
import { ViewManager } from "./View/ViewManager";
|
21
|
+
import { Val } from "value-enhancer";
|
21
22
|
import type { SyncRegisterAppPayload } from "./Register";
|
22
23
|
import type { RemoveSceneParams } from "./InternalEmitter";
|
23
24
|
import {
|
@@ -29,15 +30,16 @@ import {
|
|
29
30
|
removeScenes,
|
30
31
|
setScenePath,
|
31
32
|
setViewFocusScenePath,
|
33
|
+
wait,
|
32
34
|
} from "./Utils/Common";
|
33
35
|
import type { ReconnectRefresher } from "./ReconnectRefresher";
|
34
36
|
import type { BoxManager } from "./BoxManager";
|
35
37
|
import type {
|
36
38
|
Displayer,
|
37
|
-
DisplayerState,
|
38
39
|
Room,
|
39
40
|
ScenesCallbacksNode,
|
40
41
|
SceneState,
|
42
|
+
RoomState,
|
41
43
|
} from "white-web-sdk";
|
42
44
|
import type { AddAppParams, BaseInsertParams, TeleBoxRect } from "./index";
|
43
45
|
import type {
|
@@ -56,17 +58,18 @@ export class AppManager {
|
|
56
58
|
public appStatus: Map<string, AppStatus> = new Map();
|
57
59
|
public store = store;
|
58
60
|
public mainViewProxy: MainViewProxy;
|
59
|
-
public refresher
|
61
|
+
public refresher: ReconnectRefresher;
|
60
62
|
public isReplay = this.windowManger.isReplay;
|
61
63
|
public mainViewScenesLength = 0;
|
62
64
|
|
63
65
|
private appListeners: AppListeners;
|
64
66
|
public boxManager?: BoxManager;
|
65
67
|
|
66
|
-
private _prevSceneIndex: number | undefined;
|
67
|
-
private _prevFocused: string | undefined;
|
68
68
|
private callbacksNode: ScenesCallbacksNode | null = null;
|
69
69
|
private appCreateQueue = new AppCreateQueue();
|
70
|
+
private sceneIndex$ = new Val<number | undefined>(undefined);
|
71
|
+
private focused$ = new Val<string | undefined>(undefined);
|
72
|
+
public members$ = new Val<Member[]>([]);
|
70
73
|
|
71
74
|
private sideEffectManager = new SideEffectManager();
|
72
75
|
|
@@ -119,6 +122,7 @@ export class AppManager {
|
|
119
122
|
appRegister.setSyncRegisterApp(payload => {
|
120
123
|
this.safeUpdateAttributes([Fields.Registered, payload.kind], payload);
|
121
124
|
});
|
125
|
+
this.members$.setValue(serializeRoomMembers(this.displayer.state.roomMembers));
|
122
126
|
}
|
123
127
|
|
124
128
|
private onRemoveScenes = async (params: RemoveSceneParams) => {
|
@@ -137,7 +141,7 @@ export class AppManager {
|
|
137
141
|
sceneName = this.callbacksNode?.scenes[nextIndex];
|
138
142
|
}
|
139
143
|
if (sceneName) {
|
140
|
-
this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
|
144
|
+
await this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
|
141
145
|
}
|
142
146
|
await this.setMainViewSceneIndex(nextIndex);
|
143
147
|
} else {
|
@@ -152,7 +156,7 @@ export class AppManager {
|
|
152
156
|
* 所以需要关掉所有开启了 view 的 app
|
153
157
|
*/
|
154
158
|
public async onRootDirRemoved(needClose = true) {
|
155
|
-
this.setMainViewScenePath(INIT_DIR);
|
159
|
+
await this.setMainViewScenePath(INIT_DIR);
|
156
160
|
this.createRootDirScenesCallback();
|
157
161
|
|
158
162
|
for (const [id, appProxy] of this.appProxies.entries()) {
|
@@ -160,9 +164,9 @@ export class AppManager {
|
|
160
164
|
await this.closeApp(id, needClose);
|
161
165
|
}
|
162
166
|
}
|
163
|
-
// 删除了根目录的 scenes 之后
|
167
|
+
// 删除了根目录的 scenes 之后 main-view 需要重新绑定, 否则主白板会不能渲染
|
164
168
|
this.mainViewProxy.rebind();
|
165
|
-
emitter.emit("rootDirRemoved");
|
169
|
+
await emitter.emit("rootDirRemoved");
|
166
170
|
this.updateRootDirRemoving(false);
|
167
171
|
}
|
168
172
|
|
@@ -300,10 +304,6 @@ export class AppManager {
|
|
300
304
|
return this.room?.uid || "";
|
301
305
|
}
|
302
306
|
|
303
|
-
public get members(): Member[] {
|
304
|
-
return serializeRoomMembers(this.displayer.state.roomMembers);
|
305
|
-
}
|
306
|
-
|
307
307
|
public getMainViewSceneDir() {
|
308
308
|
const scenePath = this.store.getMainViewScenePath();
|
309
309
|
if (scenePath) {
|
@@ -324,31 +324,31 @@ export class AppManager {
|
|
324
324
|
|
325
325
|
this.addAppsChangeListener();
|
326
326
|
this.addAppCloseListener();
|
327
|
-
this.refresher
|
327
|
+
this.refresher.add("maximized", () => {
|
328
328
|
return autorun(() => {
|
329
329
|
const maximized = this.attributes.maximized;
|
330
330
|
this.boxManager?.setMaximized(Boolean(maximized));
|
331
331
|
});
|
332
332
|
});
|
333
|
-
this.refresher
|
333
|
+
this.refresher.add("minimized", () => {
|
334
334
|
return autorun(() => {
|
335
335
|
const minimized = this.attributes.minimized;
|
336
336
|
this.onMinimized(minimized);
|
337
337
|
});
|
338
338
|
});
|
339
|
-
this.refresher
|
339
|
+
this.refresher.add("mainViewIndex", () => {
|
340
340
|
return autorun(() => {
|
341
341
|
const mainSceneIndex = get(this.attributes, "_mainSceneIndex");
|
342
342
|
this.onMainViewIndexChange(mainSceneIndex);
|
343
343
|
});
|
344
344
|
});
|
345
|
-
this.refresher
|
345
|
+
this.refresher.add("focusedChange", () => {
|
346
346
|
return autorun(() => {
|
347
347
|
const focused = get(this.attributes, "focus");
|
348
348
|
this.onFocusChange(focused);
|
349
349
|
});
|
350
350
|
});
|
351
|
-
this.refresher
|
351
|
+
this.refresher.add("registeredChange", () => {
|
352
352
|
return autorun(() => {
|
353
353
|
const registered = get(this.attributes, Fields.Registered);
|
354
354
|
this.onRegisteredChange(registered);
|
@@ -361,7 +361,7 @@ export class AppManager {
|
|
361
361
|
}
|
362
362
|
this.displayerWritableListener(!this.room?.isWritable);
|
363
363
|
this.displayer.callbacks.on("onEnableWriteNowChanged", this.displayerWritableListener);
|
364
|
-
this.
|
364
|
+
this.focused$.setValue(this.attributes.focus);
|
365
365
|
|
366
366
|
this.sideEffectManager.add(() => {
|
367
367
|
const redoUndo = new RedoUndo({
|
@@ -407,7 +407,7 @@ export class AppManager {
|
|
407
407
|
};
|
408
408
|
|
409
409
|
public addAppsChangeListener = () => {
|
410
|
-
this.refresher
|
410
|
+
this.refresher.add("apps", () => {
|
411
411
|
return safeListenPropsUpdated(
|
412
412
|
() => this.attributes.apps,
|
413
413
|
() => {
|
@@ -426,27 +426,28 @@ export class AppManager {
|
|
426
426
|
};
|
427
427
|
|
428
428
|
private onMainViewIndexChange = (index: number) => {
|
429
|
-
if (index !== undefined && this.
|
429
|
+
if (index !== undefined && this.sceneIndex$.value !== index) {
|
430
430
|
callbacks.emit("mainViewSceneIndexChange", index);
|
431
431
|
emitter.emit("changePageState");
|
432
432
|
if (this.callbacksNode) {
|
433
433
|
this.updateSceneState(this.callbacksNode);
|
434
434
|
}
|
435
|
-
this.
|
435
|
+
this.sceneIndex$.setValue(index);
|
436
436
|
}
|
437
437
|
};
|
438
438
|
|
439
439
|
private onFocusChange = (focused: string | undefined) => {
|
440
|
-
if (this.
|
440
|
+
if (this.focused$.value !== focused) {
|
441
441
|
callbacks.emit("focusedChange", focused);
|
442
|
-
emitter.emit("focusedChange", { focused, prev: this.
|
443
|
-
this.
|
442
|
+
emitter.emit("focusedChange", { focused, prev: this.focused$.value });
|
443
|
+
this.focused$.setValue(focused);
|
444
444
|
if (focused !== undefined) {
|
445
445
|
this.boxManager?.focusBox({ appId: focused });
|
446
446
|
// 确保 focus 修改的时候, appProxy 已经创建
|
447
447
|
setTimeout(() => {
|
448
448
|
const appProxy = this.appProxies.get(focused);
|
449
449
|
if (appProxy) {
|
450
|
+
appProxy.onFocus();
|
450
451
|
appRegister.notifyApp(appProxy.kind, "focus", { appId: focused });
|
451
452
|
}
|
452
453
|
}, 0);
|
@@ -460,9 +461,9 @@ export class AppManager {
|
|
460
461
|
);
|
461
462
|
|
462
463
|
/**
|
463
|
-
* 插件更新
|
464
|
+
* 插件更新 apps 时的回调
|
464
465
|
*
|
465
|
-
* @param {*}
|
466
|
+
* @param {*} apps
|
466
467
|
* @memberof WindowManager
|
467
468
|
*/
|
468
469
|
public async _attributesUpdateCallback(apps: any) {
|
@@ -472,13 +473,17 @@ export class AppManager {
|
|
472
473
|
this.appCreateQueue.emitReady();
|
473
474
|
}
|
474
475
|
const appsWithCreatedAt = appIds.map(appId => {
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
476
|
+
if (apps[appId].setup) {
|
477
|
+
return {
|
478
|
+
id: appId,
|
479
|
+
createdAt: apps[appId].createdAt,
|
480
|
+
};
|
481
|
+
} else {
|
482
|
+
return {}
|
483
|
+
}
|
479
484
|
});
|
480
485
|
for (const { id } of orderBy(appsWithCreatedAt, "createdAt", "asc")) {
|
481
|
-
if (!this.appProxies.has(id) && !this.appStatus.has(id)) {
|
486
|
+
if (id && !this.appProxies.has(id) && !this.appStatus.has(id)) {
|
482
487
|
const app = apps[id];
|
483
488
|
try {
|
484
489
|
const appAttributes = this.attributes[id];
|
@@ -536,6 +541,7 @@ export class AppManager {
|
|
536
541
|
|
537
542
|
public setBoxManager(boxManager: BoxManager) {
|
538
543
|
this.boxManager = boxManager;
|
544
|
+
this.mainViewProxy.createViewSync();
|
539
545
|
}
|
540
546
|
|
541
547
|
public resetMaximized() {
|
@@ -565,11 +571,14 @@ export class AppManager {
|
|
565
571
|
public bindMainView(divElement: HTMLDivElement, disableCameraTransform: boolean) {
|
566
572
|
const mainView = this.mainViewProxy.view;
|
567
573
|
mainView.disableCameraTransform = disableCameraTransform;
|
568
|
-
mainView
|
574
|
+
// 延迟挂载 mainView 的 dom, 避免因为同步 camera 的闪动
|
575
|
+
wait(30).then(() => {
|
576
|
+
mainView.divElement = divElement;
|
577
|
+
emitter.emit("mainViewMounted");
|
578
|
+
});
|
569
579
|
if (!mainView.focusScenePath) {
|
570
580
|
this.setMainViewFocusPath();
|
571
581
|
}
|
572
|
-
emitter.emit("mainViewMounted");
|
573
582
|
}
|
574
583
|
|
575
584
|
public setMainViewFocusPath(scenePath?: string) {
|
@@ -589,6 +598,7 @@ export class AppManager {
|
|
589
598
|
|
590
599
|
public async addApp(params: AddAppParams, isDynamicPPT: boolean): Promise<string | undefined> {
|
591
600
|
log("addApp", params);
|
601
|
+
// 初始化 app 的属性创建
|
592
602
|
const { appId, needFocus } = await this.beforeAddApp(params, isDynamicPPT);
|
593
603
|
const appProxy = await this.baseInsertApp(params, appId, true, needFocus);
|
594
604
|
this.afterAddApp(appProxy);
|
@@ -600,6 +610,7 @@ export class AppManager {
|
|
600
610
|
this.appStatus.set(appId, AppStatus.StartCreate);
|
601
611
|
const attrs = params.attributes ?? {};
|
602
612
|
this.safeUpdateAttributes([appId], attrs);
|
613
|
+
// 初始化的时候时需要一些异步的工作, 完成后其他端才可以创建
|
603
614
|
this.store.setupAppAttributes(params, appId, isDynamicPPT);
|
604
615
|
const needFocus = !this.boxManager?.minimized;
|
605
616
|
if (needFocus) {
|
@@ -651,7 +662,7 @@ export class AppManager {
|
|
651
662
|
}
|
652
663
|
}
|
653
664
|
|
654
|
-
private displayerStateListener = (state: Partial<
|
665
|
+
private displayerStateListener = (state: Partial<RoomState>) => {
|
655
666
|
const sceneState = state.sceneState;
|
656
667
|
if (sceneState) {
|
657
668
|
const scenePath = sceneState.scenePath;
|
@@ -666,15 +677,18 @@ export class AppManager {
|
|
666
677
|
appProxy.appEmitter.emit("roomStateChange", state);
|
667
678
|
});
|
668
679
|
if (state.roomMembers) {
|
669
|
-
|
680
|
+
this.members$.setValue(serializeRoomMembers(state.roomMembers));
|
670
681
|
}
|
671
682
|
emitter.emit("observerIdChange", this.displayer.observerId);
|
683
|
+
if (state.memberState) {
|
684
|
+
emitter.emit("memberStateChange", toJS(state.memberState));
|
685
|
+
}
|
672
686
|
};
|
673
687
|
|
674
688
|
public displayerWritableListener = (isReadonly: boolean) => {
|
675
689
|
const isWritable = !isReadonly;
|
676
690
|
const isManualWritable =
|
677
|
-
this.windowManger.readonly === undefined || this.windowManger.readonly
|
691
|
+
this.windowManger.readonly === undefined || !this.windowManger.readonly;
|
678
692
|
if (this.windowManger.readonly === undefined) {
|
679
693
|
this.boxManager?.setReadonly(isReadonly);
|
680
694
|
} else {
|
@@ -683,13 +697,10 @@ export class AppManager {
|
|
683
697
|
this.appProxies.forEach(appProxy => {
|
684
698
|
appProxy.emitAppIsWritableChange();
|
685
699
|
});
|
686
|
-
if (isWritable
|
687
|
-
this.mainView.disableCameraTransform = false;
|
700
|
+
if (isWritable) {
|
688
701
|
if (this.room && this.room.disableSerialization === true) {
|
689
702
|
this.room.disableSerialization = false;
|
690
703
|
}
|
691
|
-
} else {
|
692
|
-
this.mainView.disableCameraTransform = true;
|
693
704
|
}
|
694
705
|
emitter.emit("writableChange", isWritable);
|
695
706
|
};
|
@@ -793,6 +804,7 @@ export class AppManager {
|
|
793
804
|
}
|
794
805
|
|
795
806
|
public async onReconnected() {
|
807
|
+
this.attributesUpdateCallback(this.attributes.apps);
|
796
808
|
const appProxies = Array.from(this.appProxies.values());
|
797
809
|
const reconnected = appProxies.map(appProxy => {
|
798
810
|
return appProxy.onReconnected();
|
@@ -831,7 +843,8 @@ export class AppManager {
|
|
831
843
|
}
|
832
844
|
callbacks.clearListeners();
|
833
845
|
this.sideEffectManager.flushAll();
|
834
|
-
this.
|
835
|
-
this.
|
846
|
+
this.sceneIndex$.destroy();
|
847
|
+
this.focused$.destroy();
|
848
|
+
this.members$.destroy();
|
836
849
|
}
|
837
850
|
}
|
@@ -2,7 +2,7 @@ import { AppAttributes } from "./constants";
|
|
2
2
|
import { get, pick } from "lodash";
|
3
3
|
import { setViewFocusScenePath } from "./Utils/Common";
|
4
4
|
import type { AddAppParams, AppSyncAttributes } from "./index";
|
5
|
-
import type {
|
5
|
+
import type { Size, View } from "white-web-sdk";
|
6
6
|
import type { Cursor } from "./Cursor/Cursor";
|
7
7
|
|
8
8
|
export enum Fields {
|
@@ -18,6 +18,8 @@ export enum Fields {
|
|
18
18
|
CursorState = "cursorState",
|
19
19
|
FullPath = "fullPath",
|
20
20
|
Registered = "registered",
|
21
|
+
Camera = "camera",
|
22
|
+
Size = "size",
|
21
23
|
}
|
22
24
|
|
23
25
|
export type Apps = {
|
@@ -39,9 +41,16 @@ export type StoreContext = {
|
|
39
41
|
safeSetAttributes: (attributes: any) => void;
|
40
42
|
}
|
41
43
|
|
42
|
-
export type ICamera =
|
44
|
+
export type ICamera = & {
|
45
|
+
id: string; // room uid
|
46
|
+
centerX: number | null,
|
47
|
+
centerY: number | null,
|
48
|
+
scale: number
|
49
|
+
};
|
43
50
|
|
44
|
-
export type ISize = Size & {
|
51
|
+
export type ISize = Size & {
|
52
|
+
id: string; // room uid
|
53
|
+
};
|
45
54
|
|
46
55
|
export class AttributesDelegate {
|
47
56
|
|
@@ -89,7 +98,7 @@ export class AttributesDelegate {
|
|
89
98
|
attrNames.push("scenes");
|
90
99
|
}
|
91
100
|
const options = pick(params.options, attrNames);
|
92
|
-
const attrs: AppSyncAttributes = { kind: params.kind, options, isDynamicPPT };
|
101
|
+
const attrs: AppSyncAttributes = { kind: params.kind, options, isDynamicPPT, setup: false };
|
93
102
|
if (typeof params.src === "string") {
|
94
103
|
attrs.src = params.src;
|
95
104
|
}
|
@@ -108,6 +117,10 @@ export class AttributesDelegate {
|
|
108
117
|
}
|
109
118
|
}
|
110
119
|
|
120
|
+
public updateAppAttributes(appId: string, key: string, value: any) {
|
121
|
+
this.context.safeUpdateAttributes([Fields.Apps, appId, key], value);
|
122
|
+
}
|
123
|
+
|
111
124
|
public cleanAppAttributes(id: string) {
|
112
125
|
this.context.safeUpdateAttributes([Fields.Apps, id], undefined);
|
113
126
|
this.context.safeSetAttributes({ [id]: undefined });
|
@@ -149,11 +162,11 @@ export class AttributesDelegate {
|
|
149
162
|
this.context.safeSetAttributes({ _mainSceneIndex: index });
|
150
163
|
}
|
151
164
|
|
152
|
-
public getMainViewCamera():
|
165
|
+
public getMainViewCamera(): ICamera {
|
153
166
|
return get(this.attributes, [Fields.MainViewCamera]);
|
154
167
|
}
|
155
168
|
|
156
|
-
public getMainViewSize():
|
169
|
+
public getMainViewSize(): ISize {
|
157
170
|
return get(this.attributes, [Fields.MainViewSize]);
|
158
171
|
}
|
159
172
|
|
@@ -214,19 +227,6 @@ export class AttributesDelegate {
|
|
214
227
|
}
|
215
228
|
}
|
216
229
|
|
217
|
-
export type MainViewSize = {
|
218
|
-
id: string;
|
219
|
-
width: number;
|
220
|
-
height: number;
|
221
|
-
};
|
222
|
-
|
223
|
-
export type MainViewCamera = {
|
224
|
-
id: string;
|
225
|
-
centerX: number;
|
226
|
-
centerY: number;
|
227
|
-
scale: number;
|
228
|
-
};
|
229
|
-
|
230
230
|
export type Cursors = {
|
231
231
|
[key: string]: Cursor;
|
232
232
|
};
|