@netless/window-manager 0.3.7 → 0.3.8-canary.3
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/AppContext.d.ts +1 -0
- package/dist/AppListener.d.ts +1 -0
- package/dist/AppManager.d.ts +1 -0
- package/dist/BoxManager.d.ts +1 -1
- package/dist/Utils/Reactive.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/AppContext.ts +1 -0
- package/src/AppListener.ts +9 -0
- package/src/AppManager.ts +48 -19
- package/src/BoxManager.ts +2 -2
- package/src/Utils/Common.ts +1 -1
- package/src/Utils/Reactive.ts +26 -1
- package/src/index.ts +4 -2
- package/src/viewManager.ts +1 -5
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@netless/window-manager",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.8-canary.3",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.es.js",
|
6
6
|
"module": "dist/index.es.js",
|
@@ -56,6 +56,6 @@
|
|
56
56
|
"typescript": "^4.3.5",
|
57
57
|
"video.js": "^7.14.3",
|
58
58
|
"vite": "^2.5.3",
|
59
|
-
"white-web-sdk": "2.15.
|
59
|
+
"white-web-sdk": "^2.15.8"
|
60
60
|
}
|
61
61
|
}
|
package/src/AppContext.ts
CHANGED
@@ -32,6 +32,7 @@ export class AppContext<TAttrs extends Record<string, any>, AppOptions = any> {
|
|
32
32
|
private boxManager: BoxManager;
|
33
33
|
private store = this.manager.store;
|
34
34
|
public readonly isAddApp: boolean;
|
35
|
+
public readonly isReplay = this.manager.isReplay;
|
35
36
|
|
36
37
|
constructor(
|
37
38
|
private manager: AppManager,
|
package/src/AppListener.ts
CHANGED
@@ -3,6 +3,7 @@ import { Events, MagixEventName } from './constants';
|
|
3
3
|
import type { Event } from "white-web-sdk";
|
4
4
|
import type { AppManager } from "./AppManager";
|
5
5
|
import type { TeleBoxState } from "@netless/telebox-insider";
|
6
|
+
import { setViewFocusScenePath } from './Utils/Common';
|
6
7
|
|
7
8
|
export class AppListeners {
|
8
9
|
private displayer = this.manager.displayer;
|
@@ -38,6 +39,10 @@ export class AppListeners {
|
|
38
39
|
this.boxStateChangeHandler(data.payload);
|
39
40
|
break;
|
40
41
|
}
|
42
|
+
case Events.SetMainViewScenePath: {
|
43
|
+
this.setMainViewScenePathHandler(data.payload);
|
44
|
+
break;
|
45
|
+
}
|
41
46
|
default:
|
42
47
|
break;
|
43
48
|
}
|
@@ -60,4 +65,8 @@ export class AppListeners {
|
|
60
65
|
private boxStateChangeHandler = (state: TeleBoxState) => {
|
61
66
|
callbacks.emit("boxStateChange", state);
|
62
67
|
}
|
68
|
+
|
69
|
+
private setMainViewScenePathHandler = ({ nextScenePath }: { nextScenePath: string }) => {
|
70
|
+
setViewFocusScenePath(this.manager.mainView, nextScenePath);
|
71
|
+
}
|
63
72
|
}
|
package/src/AppManager.ts
CHANGED
@@ -1,15 +1,27 @@
|
|
1
|
-
import
|
1
|
+
import pRetry from "p-retry";
|
2
|
+
import {
|
3
|
+
AppAttributes,
|
4
|
+
AppStatus,
|
5
|
+
Events,
|
6
|
+
MagixEventName
|
7
|
+
} from "./constants";
|
2
8
|
import { AppListeners } from "./AppListener";
|
3
9
|
import { AppProxy } from "./AppProxy";
|
4
10
|
import { AttributesDelegate } from "./AttributesDelegate";
|
11
|
+
import {
|
12
|
+
autorun,
|
13
|
+
isPlayer,
|
14
|
+
isRoom,
|
15
|
+
ScenePathType,
|
16
|
+
ViewVisionMode
|
17
|
+
} from "white-web-sdk";
|
5
18
|
import { BoxManager } from "./BoxManager";
|
6
19
|
import { callbacks, emitter } from "./index";
|
7
20
|
import { CameraStore } from "./Utils/CameraStore";
|
8
21
|
import { genAppId, makeValidScenePath, setScenePath } from "./Utils/Common";
|
9
|
-
import { autorun, isPlayer, isRoom, ScenePathType, ViewVisionMode } from "white-web-sdk";
|
10
22
|
import { log } from "./Utils/log";
|
11
23
|
import { MainViewProxy } from "./MainView";
|
12
|
-
import {
|
24
|
+
import { onObjectRemoved, safeListenPropsUpdated } from "./Utils/Reactive";
|
13
25
|
import { ReconnectRefresher } from "./ReconnectRefresher";
|
14
26
|
import { ViewManager } from "./ViewManager";
|
15
27
|
import type { Displayer, DisplayerState, Room } from "white-web-sdk";
|
@@ -31,6 +43,7 @@ export class AppManager {
|
|
31
43
|
public store = new AttributesDelegate(this);
|
32
44
|
public mainViewProxy: MainViewProxy;
|
33
45
|
public refresher?: ReconnectRefresher;
|
46
|
+
public isReplay = this.windowManger.isReplay;
|
34
47
|
|
35
48
|
private appListeners: AppListeners;
|
36
49
|
|
@@ -54,15 +67,17 @@ export class AppManager {
|
|
54
67
|
appProxy.onSeek(time);
|
55
68
|
});
|
56
69
|
this.attributesUpdateCallback(this.attributes.apps);
|
70
|
+
this.onAppDelete(this.attributes.apps);
|
57
71
|
});
|
58
72
|
}
|
59
73
|
}
|
60
74
|
|
61
75
|
private async onCreated() {
|
62
76
|
await this.attributesUpdateCallback(this.attributes.apps);
|
77
|
+
this.boxManager.updateManagerRect();
|
63
78
|
emitter.onAny(this.boxEventListener);
|
64
79
|
this.refresher?.add("apps", () => {
|
65
|
-
return
|
80
|
+
return safeListenPropsUpdated(() => this.attributes.apps, () => {
|
66
81
|
this.attributesUpdateCallback(this.attributes.apps);
|
67
82
|
});
|
68
83
|
});
|
@@ -114,16 +129,28 @@ export class AppManager {
|
|
114
129
|
for (const id in apps) {
|
115
130
|
if (!this.appProxies.has(id) && !this.appStatus.has(id)) {
|
116
131
|
const app = apps[id];
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
132
|
+
|
133
|
+
pRetry(async () => {
|
134
|
+
this.appStatus.set(id, AppStatus.StartCreate);
|
135
|
+
// 防御 appAttributes 有可能为 undefined 的情况,这里做一个重试
|
136
|
+
const appAttributes = this.attributes[id];
|
137
|
+
if (!appAttributes) {
|
138
|
+
throw new Error("appAttributes is undefined");
|
139
|
+
}
|
140
|
+
await this.baseInsertApp(
|
141
|
+
{
|
142
|
+
kind: app.kind,
|
143
|
+
options: app.options,
|
144
|
+
isDynamicPPT: app.isDynamicPPT,
|
145
|
+
},
|
146
|
+
id,
|
147
|
+
false
|
148
|
+
);
|
149
|
+
this.focusByAttributes(apps);
|
150
|
+
}, { retries: 3 }).catch(err => {
|
151
|
+
console.warn(`[WindowManager]: Insert App Error`, err);
|
152
|
+
this.appStatus.delete(id);
|
153
|
+
});
|
127
154
|
}
|
128
155
|
}
|
129
156
|
}
|
@@ -166,9 +193,6 @@ export class AppManager {
|
|
166
193
|
const attrs = params.attributes ?? {};
|
167
194
|
this.safeUpdateAttributes([appId], attrs);
|
168
195
|
this.store.setupAppAttributes(params, appId, isDynamicPPT);
|
169
|
-
if (this.boxManager.minimized) {
|
170
|
-
this.boxManager.setMinimized(false);
|
171
|
-
}
|
172
196
|
const needFocus = !this.boxManager.minimized;
|
173
197
|
if (needFocus) {
|
174
198
|
this.store.setAppFocus(appId, true);
|
@@ -184,6 +208,9 @@ export class AppManager {
|
|
184
208
|
y: appProxy.box?.y,
|
185
209
|
});
|
186
210
|
}
|
211
|
+
if (this.boxManager.minimized) {
|
212
|
+
this.boxManager.setMinimized(false, false);
|
213
|
+
}
|
187
214
|
}
|
188
215
|
|
189
216
|
public async closeApp(appId: string) {
|
@@ -199,7 +226,6 @@ export class AppManager {
|
|
199
226
|
isAddApp: boolean,
|
200
227
|
focus?: boolean
|
201
228
|
) {
|
202
|
-
this.appStatus.set(appId, AppStatus.StartCreate);
|
203
229
|
if (this.appProxies.has(appId)) {
|
204
230
|
console.warn("[WindowManager]: app duplicate exists and cannot be created again");
|
205
231
|
return;
|
@@ -311,6 +337,7 @@ export class AppManager {
|
|
311
337
|
await this.viewManager.switchMainViewToWriter();
|
312
338
|
setScenePath(this.room, scenePath);
|
313
339
|
this.store.setMainViewFocusPath();
|
340
|
+
this.dispatchInternalEvent(Events.SetMainViewScenePath, { nextScenePath: scenePath });
|
314
341
|
}
|
315
342
|
|
316
343
|
public async setMainViewSceneIndex(index: number) {
|
@@ -318,8 +345,10 @@ export class AppManager {
|
|
318
345
|
this.safeSetAttributes({ _mainSceneIndex: index });
|
319
346
|
await this.viewManager.switchMainViewToWriter();
|
320
347
|
this.room.setSceneIndex(index);
|
321
|
-
this.
|
348
|
+
const nextScenePath = this.room.state.sceneState.scenePath;
|
349
|
+
this.store.setMainViewScenePath(nextScenePath);
|
322
350
|
this.store.setMainViewFocusPath();
|
351
|
+
this.dispatchInternalEvent(Events.SetMainViewScenePath, { nextScenePath });
|
323
352
|
}
|
324
353
|
}
|
325
354
|
|
package/src/BoxManager.ts
CHANGED
@@ -290,8 +290,8 @@ export class BoxManager {
|
|
290
290
|
this.teleBoxManager.setMaximized(maximized, true);
|
291
291
|
}
|
292
292
|
|
293
|
-
public setMinimized(minimized: boolean) {
|
294
|
-
this.teleBoxManager.setMinimized(minimized,
|
293
|
+
public setMinimized(minimized: boolean, skipUpdate = true) {
|
294
|
+
this.teleBoxManager.setMinimized(minimized, skipUpdate);
|
295
295
|
}
|
296
296
|
|
297
297
|
public setReadonly(readonly: boolean) {
|
package/src/Utils/Common.ts
CHANGED
@@ -29,7 +29,7 @@ export const setScenePath = (room: Room | undefined, scenePath: string) => {
|
|
29
29
|
}
|
30
30
|
|
31
31
|
export const setViewMode = (view: View, mode: ViewVisionMode) => {
|
32
|
-
if (view.mode !== mode) {
|
32
|
+
if (!(view as any).didRelease && view.mode !== mode) {
|
33
33
|
view.mode = mode;
|
34
34
|
}
|
35
35
|
};
|
package/src/Utils/Reactive.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { listenUpdated, unlistenUpdated, reaction, UpdateEventKind } from "white-web-sdk";
|
2
|
-
import type { AkkoObjectUpdatedProperty } from "white-web-sdk";
|
2
|
+
import type { AkkoObjectUpdatedProperty , AkkoObjectUpdatedListener } from "white-web-sdk";
|
3
3
|
|
4
4
|
// 兼容 13 和 14 版本 SDK
|
5
5
|
export const onObjectByEvent = (event: UpdateEventKind) => {
|
@@ -28,5 +28,30 @@ export const onObjectByEvent = (event: UpdateEventKind) => {
|
|
28
28
|
}
|
29
29
|
}
|
30
30
|
|
31
|
+
export const safeListenPropsUpdated = <T>(
|
32
|
+
getProps: () => T,
|
33
|
+
callback: AkkoObjectUpdatedListener<T>
|
34
|
+
) => {
|
35
|
+
let disposeListenUpdated: (() => void) | null = null;
|
36
|
+
const disposeReaction = reaction(
|
37
|
+
getProps,
|
38
|
+
() => {
|
39
|
+
if (disposeListenUpdated) {
|
40
|
+
disposeListenUpdated();
|
41
|
+
disposeListenUpdated = null;
|
42
|
+
}
|
43
|
+
const props = getProps();
|
44
|
+
disposeListenUpdated = () => unlistenUpdated(props, callback);
|
45
|
+
listenUpdated(props, callback);
|
46
|
+
},
|
47
|
+
{ fireImmediately: true }
|
48
|
+
);
|
49
|
+
|
50
|
+
return () => {
|
51
|
+
disposeListenUpdated?.();
|
52
|
+
disposeReaction();
|
53
|
+
};
|
54
|
+
}
|
55
|
+
|
31
56
|
export const onObjectRemoved = onObjectByEvent(UpdateEventKind.Removed);
|
32
57
|
export const onObjectInserted = onObjectByEvent(UpdateEventKind.Inserted);
|
package/src/index.ts
CHANGED
@@ -33,6 +33,7 @@ import {
|
|
33
33
|
import type { Apps } from "./AttributesDelegate";
|
34
34
|
import {
|
35
35
|
InvisiblePlugin,
|
36
|
+
isPlayer,
|
36
37
|
isRoom,
|
37
38
|
RoomPhase,
|
38
39
|
ViewMode,
|
@@ -168,7 +169,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
168
169
|
public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
|
169
170
|
private static isCreated = false;
|
170
171
|
|
171
|
-
public version = "0.3.
|
172
|
+
public version = "0.3.8-canary.3";
|
172
173
|
|
173
174
|
public appListeners?: AppListeners;
|
174
175
|
|
@@ -177,7 +178,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
177
178
|
public appManager?: AppManager;
|
178
179
|
public cursorManager?: CursorManager;
|
179
180
|
public viewMode = ViewMode.Broadcaster;
|
180
|
-
|
181
|
+
public isReplay = isPlayer(this.displayer);
|
182
|
+
|
181
183
|
constructor(context: InvisiblePluginContext) {
|
182
184
|
super(context);
|
183
185
|
}
|
package/src/viewManager.ts
CHANGED
@@ -2,11 +2,7 @@ import { Base } from "./Base";
|
|
2
2
|
import { callbacks, WindowManager } from "./index";
|
3
3
|
import { reaction, ViewVisionMode } from "white-web-sdk";
|
4
4
|
import { SET_SCENEPATH_DELAY } from "./constants";
|
5
|
-
import {
|
6
|
-
notifyMainViewModeChange,
|
7
|
-
setScenePath,
|
8
|
-
setViewMode,
|
9
|
-
} from "./Utils/Common";
|
5
|
+
import { notifyMainViewModeChange, setScenePath, setViewMode } from "./Utils/Common";
|
10
6
|
import type { View } from "white-web-sdk";
|
11
7
|
import type { AppManager } from "./AppManager";
|
12
8
|
|