@netless/window-manager 1.0.0-canary.5 → 1.0.0-canary.50
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/README.md +30 -6
- package/dist/index.cjs.js +12477 -34
- package/dist/index.es.js +6839 -10495
- package/dist/index.umd.js +12485 -46
- package/dist/{App → src/App}/AppContext.d.ts +12 -7
- package/dist/{App → src/App}/AppPageStateImpl.d.ts +0 -0
- package/dist/{App → src/App}/AppProxy.d.ts +29 -11
- 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 +1 -0
- package/dist/src/App/type.d.ts +21 -0
- package/dist/{AppListener.d.ts → src/AppListener.d.ts} +2 -2
- package/dist/{AppManager.d.ts → src/AppManager.d.ts} +6 -5
- package/dist/{AttributesDelegate.d.ts → src/AttributesDelegate.d.ts} +5 -2
- package/dist/{BoxEmitter.d.ts → src/BoxEmitter.d.ts} +0 -0
- package/dist/{BoxManager.d.ts → src/BoxManager.d.ts} +12 -6
- 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 +2 -1
- 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} +0 -0
- package/dist/{RedoUndo.d.ts → src/RedoUndo.d.ts} +0 -0
- package/dist/{Register → src/Register}/index.d.ts +4 -2
- package/dist/{Register → src/Register}/loader.d.ts +1 -1
- package/dist/src/Register/storage.d.ts +11 -0
- package/dist/{Utils → src/Utils}/AppCreateQueue.d.ts +0 -0
- package/dist/{Utils → src/Utils}/Common.d.ts +0 -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 +1 -1
- package/dist/{Utils → src/Utils}/log.d.ts +0 -0
- package/dist/src/View/CameraSynchronizer.d.ts +19 -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 +29 -0
- package/dist/{callback.d.ts → src/callback.d.ts} +10 -1
- package/dist/{constants.d.ts → src/constants.d.ts} +10 -5
- package/dist/src/image.d.ts +19 -0
- package/dist/{index.d.ts → src/index.d.ts} +49 -14
- package/dist/src/shim.d.ts +11 -0
- package/dist/{typings.d.ts → src/typings.d.ts} +12 -3
- package/dist/style.css +795 -1
- package/docs/app-context.md +155 -27
- package/docs/mirgrate-to-1.0.md +68 -0
- package/package.json +23 -19
- package/playwright.config.ts +29 -0
- package/pnpm-lock.yaml +3078 -4412
- package/src/App/AppContext.ts +62 -29
- package/src/App/AppProxy.ts +235 -113
- package/src/App/WhiteboardView.ts +34 -12
- package/src/App/index.ts +1 -0
- package/src/App/type.ts +22 -0
- package/src/AppListener.ts +30 -21
- package/src/AppManager.ts +66 -43
- package/src/AttributesDelegate.ts +6 -3
- package/src/BoxManager.ts +76 -38
- package/src/BuiltinApps.ts +9 -8
- 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 +2 -1
- package/src/PageState.ts +1 -1
- package/src/ReconnectRefresher.ts +6 -2
- package/src/Register/index.ts +36 -14
- package/src/Register/loader.ts +20 -9
- package/src/Register/storage.ts +26 -5
- package/src/Utils/Common.ts +3 -0
- package/src/Utils/Reactive.ts +27 -26
- package/src/Utils/RoomHacker.ts +3 -0
- package/src/Utils/error.ts +2 -2
- package/src/View/CameraSynchronizer.ts +41 -38
- package/src/View/MainView.ts +116 -75
- package/src/View/ViewSync.ts +123 -6
- package/src/callback.ts +6 -1
- package/src/constants.ts +8 -3
- package/src/index.ts +201 -63
- package/src/style.css +3 -46
- package/src/typings.ts +14 -3
- package/vite.config.js +12 -7
- package/dist/App/AppViewSync.d.ts +0 -11
- package/dist/App/WhiteboardView.d.ts +0 -21
- package/dist/Register/storage.d.ts +0 -8
- package/dist/View/CameraSynchronizer.d.ts +0 -17
- package/dist/View/ViewSync.d.ts +0 -7
- package/src/App/AppViewSync.ts +0 -69
package/src/View/MainView.ts
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
import { callbacks } from "../callback";
|
2
|
-
import { CameraSynchronizer } from "./CameraSynchronizer";
|
3
2
|
import { createView } from "./ViewManager";
|
4
3
|
import { debounce, get, isEqual } from "lodash";
|
5
4
|
import { emitter } from "../InternalEmitter";
|
6
5
|
import { Events } from "../constants";
|
7
6
|
import { Fields } from "../AttributesDelegate";
|
8
|
-
import { reaction } from "white-web-sdk";
|
9
|
-
import { releaseView, setViewFocusScenePath } from "../Utils/Common";
|
7
|
+
import { AnimationMode, reaction, toJS } from "white-web-sdk";
|
8
|
+
import { releaseView, setScenePath, setViewFocusScenePath } from "../Utils/Common";
|
10
9
|
import { SideEffectManager } from "side-effect-manager";
|
11
|
-
import
|
10
|
+
import { Val } from "value-enhancer";
|
11
|
+
import { ViewSync } from "./ViewSync";
|
12
|
+
import type { ICamera, ISize } from "../AttributesDelegate";
|
13
|
+
import type { Size, View } from "white-web-sdk";
|
12
14
|
import type { AppManager } from "../AppManager";
|
13
15
|
|
14
16
|
export class MainViewProxy {
|
@@ -16,56 +18,89 @@ export class MainViewProxy {
|
|
16
18
|
private mainViewIsAddListener = false;
|
17
19
|
private mainView: View;
|
18
20
|
private store = this.manager.store;
|
19
|
-
private synchronizer: CameraSynchronizer;
|
20
21
|
|
21
22
|
private sideEffectManager = new SideEffectManager();
|
22
23
|
|
24
|
+
public camera$ = new Val<ICamera | undefined>(undefined);
|
25
|
+
public size$ = new Val<ISize | undefined>(undefined);
|
26
|
+
public view$ = new Val<View | undefined>(undefined);
|
27
|
+
|
28
|
+
public viewSync?: ViewSync;
|
29
|
+
|
23
30
|
constructor(private manager: AppManager) {
|
24
|
-
this.synchronizer = new CameraSynchronizer(camera =>
|
25
|
-
this.store.setMainViewCamera({ ...camera, id: this.manager.uid })
|
26
|
-
);
|
27
31
|
this.mainView = this.createMainView();
|
28
|
-
this.moveCameraSizeByAttributes();
|
29
32
|
emitter.once("mainViewMounted").then(() => {
|
30
33
|
this.addMainViewListener();
|
31
34
|
this.start();
|
32
35
|
this.ensureCameraAndSize();
|
33
36
|
this.startListenWritableChange();
|
34
37
|
});
|
35
|
-
this.sideEffectManager.add(() =>
|
36
|
-
|
37
|
-
});
|
38
|
-
this.sideEffectManager.add(() => {
|
39
|
-
return emitter.on("startReconnect", () => {
|
38
|
+
this.sideEffectManager.add(() => [
|
39
|
+
emitter.on("startReconnect", () => {
|
40
40
|
releaseView(this.mainView);
|
41
|
-
})
|
41
|
+
}),
|
42
|
+
]);
|
43
|
+
this.createViewSync();
|
44
|
+
this.sideEffectManager.add(() => emitter.on("focusedChange", ({ focused }) => {
|
45
|
+
if (focused === undefined) {
|
46
|
+
const scenePath = this.store.getMainViewScenePath();
|
47
|
+
if (scenePath) {
|
48
|
+
setScenePath(this.manager.room, scenePath);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}));
|
52
|
+
this.camera$.reaction(camera => {
|
53
|
+
if (camera) {
|
54
|
+
callbacks.emit("baseCameraChange", camera);
|
55
|
+
}
|
42
56
|
});
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
this.sideEffectManager.add(() => {
|
48
|
-
return emitter.on("playgroundSizeChange", rect => {
|
49
|
-
this.synchronizer.setRect(rect);
|
50
|
-
// this.synchronizer.onLocalSizeUpdate(rect);
|
51
|
-
});
|
57
|
+
this.size$.reaction(size => {
|
58
|
+
if (size) {
|
59
|
+
callbacks.emit("baseSizeChange", size);
|
60
|
+
}
|
52
61
|
});
|
53
62
|
}
|
54
63
|
|
64
|
+
public createViewSync = () => {
|
65
|
+
if (this.manager.boxManager && !this.viewSync) {
|
66
|
+
this.viewSync = new ViewSync({
|
67
|
+
uid: this.manager.uid,
|
68
|
+
view$: this.view$,
|
69
|
+
camera$: this.camera$,
|
70
|
+
size$: this.size$,
|
71
|
+
stageRect$: this.manager.boxManager?.stageRect$,
|
72
|
+
viewMode$: this.manager.windowManger.viewMode$,
|
73
|
+
storeCamera: this.storeCamera,
|
74
|
+
storeSize: this.storeSize,
|
75
|
+
});
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
55
79
|
private startListenWritableChange = () => {
|
56
|
-
this.sideEffectManager.add(() =>
|
57
|
-
|
80
|
+
this.sideEffectManager.add(() =>
|
81
|
+
emitter.on("writableChange", isWritable => {
|
58
82
|
if (isWritable) {
|
59
83
|
this.ensureCameraAndSize();
|
60
84
|
}
|
61
|
-
})
|
62
|
-
|
85
|
+
})
|
86
|
+
);
|
63
87
|
};
|
64
88
|
|
65
89
|
public ensureCameraAndSize() {
|
66
90
|
if (!this.mainViewCamera || !this.mainViewSize) {
|
67
91
|
this.manager.dispatchInternalEvent(Events.InitMainViewCamera);
|
68
|
-
this.
|
92
|
+
this.storeCamera({
|
93
|
+
id: this.manager.uid,
|
94
|
+
...this.view.camera
|
95
|
+
});
|
96
|
+
const stageRect = this.manager.boxManager?.stageRect;
|
97
|
+
if (stageRect && !this.mainViewSize) {
|
98
|
+
this.storeSize({
|
99
|
+
id: this.manager.uid,
|
100
|
+
width: stageRect.width,
|
101
|
+
height: stageRect.height
|
102
|
+
});
|
103
|
+
}
|
69
104
|
}
|
70
105
|
}
|
71
106
|
|
@@ -81,55 +116,73 @@ export class MainViewProxy {
|
|
81
116
|
return get(this.view, ["didRelease"]);
|
82
117
|
}
|
83
118
|
|
84
|
-
private moveCameraSizeByAttributes() {
|
85
|
-
this.synchronizer.onRemoteUpdate(this.mainViewCamera, this.mainViewSize);
|
86
|
-
}
|
87
|
-
|
88
119
|
public start() {
|
89
120
|
if (this.started) return;
|
90
|
-
this.sizeChangeHandler(this.mainViewSize);
|
91
121
|
this.addCameraListener();
|
92
122
|
this.addCameraReaction();
|
93
123
|
this.started = true;
|
94
124
|
}
|
95
125
|
|
96
126
|
public addCameraReaction = () => {
|
97
|
-
this.manager.refresher
|
127
|
+
this.manager.refresher.add(Fields.MainViewCamera, this.cameraReaction);
|
128
|
+
this.manager.refresher.add(Fields.MainViewSize, this.sizeReaction);
|
98
129
|
};
|
99
130
|
|
100
|
-
public
|
101
|
-
const
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
131
|
+
public storeCurrentCamera = () => {
|
132
|
+
const iCamera = this.view.camera;
|
133
|
+
this.storeCamera({
|
134
|
+
id: this.manager.uid,
|
135
|
+
...iCamera
|
136
|
+
});
|
137
|
+
}
|
138
|
+
|
139
|
+
public storeCurrentSize = () => {
|
140
|
+
const rect = this.manager.boxManager?.stageRect;
|
141
|
+
if (rect) {
|
142
|
+
this.storeSize({
|
143
|
+
id: this.manager.uid,
|
144
|
+
width: rect.width,
|
145
|
+
height: rect.height
|
146
|
+
});
|
106
147
|
}
|
107
148
|
}
|
108
149
|
|
150
|
+
public storeCamera = (camera: ICamera) => {
|
151
|
+
this.store.setMainViewCamera(camera);
|
152
|
+
};
|
153
|
+
|
154
|
+
public storeSize = (size: ISize) => {
|
155
|
+
this.store.setMainViewSize(size);
|
156
|
+
};
|
157
|
+
|
109
158
|
private cameraReaction = () => {
|
110
159
|
return reaction(
|
111
160
|
() => this.mainViewCamera,
|
112
161
|
camera => {
|
113
|
-
if (camera
|
114
|
-
|
162
|
+
if (camera) {
|
163
|
+
const rawCamera = toJS(camera);
|
164
|
+
if (!isEqual(rawCamera, this.camera$.value)) {
|
165
|
+
this.camera$.setValue(rawCamera);
|
166
|
+
}
|
115
167
|
}
|
116
168
|
},
|
117
169
|
{ fireImmediately: true }
|
118
170
|
);
|
119
171
|
};
|
120
172
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
173
|
+
private sizeReaction = () => {
|
174
|
+
return reaction(
|
175
|
+
() => this.mainViewSize,
|
176
|
+
size => {
|
177
|
+
if (size) {
|
178
|
+
const rawSize = toJS(size);
|
179
|
+
if (!isEqual(rawSize, this.size$.value)) {
|
180
|
+
this.size$.setValue(rawSize);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
},
|
184
|
+
{ fireImmediately: true }
|
185
|
+
);
|
133
186
|
};
|
134
187
|
|
135
188
|
public get view(): View {
|
@@ -146,7 +199,7 @@ export class MainViewProxy {
|
|
146
199
|
if (mainViewScenePath) {
|
147
200
|
setViewFocusScenePath(mainView, mainViewScenePath);
|
148
201
|
}
|
149
|
-
this.
|
202
|
+
this.view$.setValue(mainView);
|
150
203
|
return mainView;
|
151
204
|
}
|
152
205
|
|
@@ -168,31 +221,18 @@ export class MainViewProxy {
|
|
168
221
|
public rebind(): void {
|
169
222
|
const divElement = this.mainView.divElement;
|
170
223
|
const disableCameraTransform = this.mainView.disableCameraTransform;
|
224
|
+
const camera = { ...this.mainView.camera };
|
171
225
|
this.stop();
|
172
226
|
releaseView(this.mainView);
|
173
227
|
this.removeMainViewListener();
|
174
228
|
this.mainView = this.createMainView();
|
175
229
|
this.mainView.disableCameraTransform = disableCameraTransform;
|
176
230
|
this.mainView.divElement = divElement;
|
231
|
+
this.mainView.moveCamera({ ...camera, animationMode: AnimationMode.Immediately });
|
177
232
|
this.addMainViewListener();
|
178
233
|
this.start();
|
179
234
|
}
|
180
235
|
|
181
|
-
private onCameraUpdatedByDevice = (camera: Camera) => {
|
182
|
-
this.synchronizer.onLocalCameraUpdate(camera);
|
183
|
-
const size = this.getStageSize();
|
184
|
-
if (size && !isEqual(size, this.mainViewSize)) {
|
185
|
-
this.setMainViewSize(size);
|
186
|
-
}
|
187
|
-
};
|
188
|
-
|
189
|
-
private getStageSize(): Size | undefined {
|
190
|
-
const stage = this.manager.boxManager?.stageRect;
|
191
|
-
if (stage) {
|
192
|
-
return { width: stage.width, height: stage.height };
|
193
|
-
}
|
194
|
-
}
|
195
|
-
|
196
236
|
public addMainViewListener(): void {
|
197
237
|
if (this.mainViewIsAddListener) return;
|
198
238
|
if (this.view.divElement) {
|
@@ -225,13 +265,11 @@ export class MainViewProxy {
|
|
225
265
|
}, 50);
|
226
266
|
|
227
267
|
private addCameraListener() {
|
228
|
-
this.view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
|
229
268
|
this.view.callbacks.on("onCameraUpdated", this.onCameraOrSizeUpdated);
|
230
269
|
this.view.callbacks.on("onSizeUpdated", this.onCameraOrSizeUpdated);
|
231
270
|
}
|
232
271
|
|
233
272
|
private removeCameraListener() {
|
234
|
-
this.view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
|
235
273
|
this.view.callbacks.off("onCameraUpdated", this.onCameraOrSizeUpdated);
|
236
274
|
this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
|
237
275
|
}
|
@@ -242,12 +280,15 @@ export class MainViewProxy {
|
|
242
280
|
|
243
281
|
public stop() {
|
244
282
|
this.removeCameraListener();
|
245
|
-
this.manager.refresher
|
246
|
-
this.manager.refresher
|
283
|
+
this.manager.refresher.remove(Fields.MainViewCamera);
|
284
|
+
this.manager.refresher.remove(Fields.MainViewSize);
|
247
285
|
this.started = false;
|
248
286
|
}
|
249
287
|
|
250
288
|
public destroy() {
|
289
|
+
this.camera$.destroy();
|
290
|
+
this.size$.destroy();
|
291
|
+
this.view$.destroy();
|
251
292
|
this.removeMainViewListener();
|
252
293
|
this.stop();
|
253
294
|
this.sideEffectManager.flushAll();
|
package/src/View/ViewSync.ts
CHANGED
@@ -1,10 +1,127 @@
|
|
1
|
-
import
|
1
|
+
import { ViewMode, AnimationMode } from "white-web-sdk";
|
2
|
+
import { CameraSynchronizer, computedMinScale } from "./CameraSynchronizer";
|
3
|
+
import { combine } from "value-enhancer";
|
4
|
+
import { SideEffectManager } from "side-effect-manager";
|
5
|
+
import type { Camera, View } from "white-web-sdk";
|
6
|
+
import type { Val, ReadonlyVal } from "value-enhancer";
|
7
|
+
import type { ICamera, ISize } from "../AttributesDelegate";
|
8
|
+
import type { TeleBoxRect } from "@netless/telebox-insider";
|
2
9
|
|
10
|
+
export type ViewSyncContext = {
|
11
|
+
uid: string;
|
12
|
+
// 远端 camera
|
13
|
+
camera$: Val<ICamera | undefined, boolean>;
|
14
|
+
// 远端 size
|
15
|
+
size$: Val<ISize | undefined>;
|
3
16
|
|
4
|
-
|
5
|
-
readonly camera: Camera;
|
6
|
-
readonly size: Size;
|
17
|
+
stageRect$: ReadonlyVal<TeleBoxRect>;
|
7
18
|
|
8
|
-
|
9
|
-
|
19
|
+
viewMode$?: Val<ViewMode>;
|
20
|
+
|
21
|
+
storeCamera: (camera: ICamera) => void;
|
22
|
+
|
23
|
+
storeSize: (size: ISize) => void;
|
24
|
+
|
25
|
+
view$: Val<View | undefined>;
|
26
|
+
};
|
27
|
+
|
28
|
+
export class ViewSync {
|
29
|
+
private sem = new SideEffectManager();
|
30
|
+
private synchronizer: CameraSynchronizer;
|
31
|
+
|
32
|
+
constructor(private context: ViewSyncContext) {
|
33
|
+
this.synchronizer = this.createSynchronizer();
|
34
|
+
this.bindView(this.context.view$.value);
|
35
|
+
this.sem.add(() => [
|
36
|
+
this.subscribeView(),
|
37
|
+
this.subscribeCamera(),
|
38
|
+
this.subscribeSize(),
|
39
|
+
this.subscribeStageRect(),
|
40
|
+
]);
|
41
|
+
const camera$size$ = combine([this.context.camera$, this.context.size$]);
|
42
|
+
camera$size$.reaction(([camera, size]) => {
|
43
|
+
if (camera && size) {
|
44
|
+
this.synchronizer.onRemoteUpdate(camera, size);
|
45
|
+
camera$size$.destroy();
|
46
|
+
}
|
47
|
+
});
|
48
|
+
}
|
49
|
+
|
50
|
+
private createSynchronizer = () => {
|
51
|
+
return new CameraSynchronizer((camera: ICamera) => {
|
52
|
+
this.context.camera$.setValue(camera, true);
|
53
|
+
const notStoreCamera =
|
54
|
+
this.context.viewMode$ && this.context.viewMode$.value === ViewMode.Freedom;
|
55
|
+
if (notStoreCamera) {
|
56
|
+
return;
|
57
|
+
} else {
|
58
|
+
this.context.storeCamera(camera);
|
59
|
+
}
|
60
|
+
});
|
61
|
+
}
|
62
|
+
|
63
|
+
private subscribeView = () => {
|
64
|
+
return this.context.view$.subscribe(view => {
|
65
|
+
const currentCamera = this.context.camera$.value;
|
66
|
+
if (currentCamera && this.context.size$.value) {
|
67
|
+
view?.moveCamera({
|
68
|
+
scale: 1,
|
69
|
+
animationMode: AnimationMode.Immediately,
|
70
|
+
});
|
71
|
+
this.synchronizer.onRemoteUpdate(currentCamera, this.context.size$.value);
|
72
|
+
}
|
73
|
+
this.bindView(view);
|
74
|
+
});
|
75
|
+
}
|
76
|
+
|
77
|
+
private subscribeCamera = () => {
|
78
|
+
return this.context.camera$.subscribe((camera, skipUpdate) => {
|
79
|
+
if (skipUpdate) return;
|
80
|
+
const size = this.context.size$.value;
|
81
|
+
if (camera && size) {
|
82
|
+
this.synchronizer.onRemoteUpdate(camera, size);
|
83
|
+
}
|
84
|
+
});
|
85
|
+
}
|
86
|
+
|
87
|
+
private subscribeSize = () => {
|
88
|
+
return this.context.size$.subscribe(size => {
|
89
|
+
if (size) {
|
90
|
+
this.synchronizer.onRemoteSizeUpdate(size);
|
91
|
+
}
|
92
|
+
});
|
93
|
+
}
|
94
|
+
|
95
|
+
private subscribeStageRect = () => {
|
96
|
+
return this.context.stageRect$.subscribe(rect => {
|
97
|
+
if (rect) {
|
98
|
+
this.synchronizer.setRect(rect);
|
99
|
+
}
|
100
|
+
});
|
101
|
+
}
|
102
|
+
|
103
|
+
public bindView = (view?: View) => {
|
104
|
+
if (!view) return;
|
105
|
+
this.synchronizer.setView(view);
|
106
|
+
this.sem.flush("view");
|
107
|
+
this.sem.add(() => {
|
108
|
+
view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
|
109
|
+
return () =>
|
110
|
+
view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
|
111
|
+
}, "view");
|
112
|
+
};
|
113
|
+
|
114
|
+
private onCameraUpdatedByDevice = (camera: Camera) => {
|
115
|
+
if (!camera) return;
|
116
|
+
if (this.context.size$.value && this.context.stageRect$.value) {
|
117
|
+
// 始终以远端的 size 为标准, 设置到 attributes 时根据尺寸的大小还原回去
|
118
|
+
const diffScale = computedMinScale(this.context.size$.value, this.context.stageRect$.value);
|
119
|
+
const remoteScale = camera.scale / diffScale;
|
120
|
+
this.synchronizer.onLocalCameraUpdate({ ...camera, scale: remoteScale, id: this.context.uid });
|
121
|
+
}
|
122
|
+
};
|
123
|
+
|
124
|
+
public destroy() {
|
125
|
+
this.sem.flushAll();
|
126
|
+
}
|
10
127
|
}
|
package/src/callback.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
import Emittery from "emittery";
|
2
|
-
import type { TeleBoxColorScheme, TELE_BOX_STATE } from "@netless/telebox-insider";
|
2
|
+
import type { TeleBoxColorScheme, TeleBoxFullscreen, TELE_BOX_STATE } from "@netless/telebox-insider";
|
3
3
|
import type { CameraState, SceneState, ViewVisionMode } from "white-web-sdk";
|
4
4
|
import type { LoadAppEvent } from "./Register";
|
5
5
|
import type { PageState } from "./Page";
|
6
|
+
import type { ICamera, ISize } from "./AttributesDelegate";
|
6
7
|
|
7
8
|
export type PublicEvent = {
|
8
9
|
mainViewModeChange: ViewVisionMode;
|
@@ -20,6 +21,10 @@ export type PublicEvent = {
|
|
20
21
|
ready: undefined; // 所有 APP 创建完毕时触发
|
21
22
|
sceneStateChange: SceneState;
|
22
23
|
pageStateChange: PageState;
|
24
|
+
appClose: { appId: string; kind: string, error?: Error };
|
25
|
+
baseCameraChange: ICamera;
|
26
|
+
baseSizeChange: ISize;
|
27
|
+
fullscreenChange: TeleBoxFullscreen;
|
23
28
|
};
|
24
29
|
|
25
30
|
export type CallbacksType = Emittery<PublicEvent>;
|
package/src/constants.ts
CHANGED
@@ -5,18 +5,18 @@ export enum Events {
|
|
5
5
|
AppBoxStateChange = "AppBoxStateChange",
|
6
6
|
GetAttributes = "GetAttributes",
|
7
7
|
UpdateWindowManagerWrapper = "UpdateWindowManagerWrapper",
|
8
|
-
InitReplay = "InitReplay",
|
9
8
|
WindowCreated = "WindowCreated",
|
10
9
|
SetMainViewScenePath = "SetMainViewScenePath",
|
11
10
|
SetMainViewSceneIndex = "SetMainViewSceneIndex",
|
12
11
|
SetAppFocusIndex = "SetAppFocusIndex",
|
13
12
|
SwitchViewsToFreedom = "SwitchViewsToFreedom",
|
14
|
-
MoveCamera = "MoveCamera",
|
15
|
-
MoveCameraToContain = "MoveCameraToContain",
|
16
13
|
CursorMove = "CursorMove",
|
17
14
|
RootDirRemoved = "RootDirRemoved",
|
18
15
|
Refresh = "Refresh",
|
19
16
|
InitMainViewCamera = "InitMainViewCamera",
|
17
|
+
InvokeAttributesUpdateCallback = "InvokeAttributesUpdateCallback",
|
18
|
+
MoveCamera = "MoveCamera",
|
19
|
+
MoveCameraToContain = "moveCameraToContain",
|
20
20
|
}
|
21
21
|
|
22
22
|
export const MagixEventName = "__WindowManger";
|
@@ -27,6 +27,11 @@ export enum AppAttributes {
|
|
27
27
|
Position = "position",
|
28
28
|
SceneIndex = "SceneIndex",
|
29
29
|
ZIndex = "zIndex",
|
30
|
+
Visible = "visible",
|
31
|
+
Ratio = "ratio",
|
32
|
+
StageRatio = "stageRatio",
|
33
|
+
Draggable = "draggable",
|
34
|
+
Resizable = "resizable",
|
30
35
|
}
|
31
36
|
|
32
37
|
export enum AppEvents {
|