@netless/window-manager 0.4.67-beta.1 → 0.4.68
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 +3 -1
- package/dist/View/MainView.d.ts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/App/AppProxy.ts +6 -6
- package/src/AppManager.ts +23 -17
- package/src/View/MainView.ts +16 -3
- package/src/index.ts +19 -4
package/package.json
CHANGED
package/src/App/AppProxy.ts
CHANGED
@@ -359,7 +359,7 @@ export class AppProxy implements PageRemoveService {
|
|
359
359
|
}
|
360
360
|
|
361
361
|
private appAttributesUpdateListener = (appId: string) => {
|
362
|
-
this.manager.refresher
|
362
|
+
this.manager.refresher.add(appId, () => {
|
363
363
|
return autorun(() => {
|
364
364
|
const attrs = this.manager.attributes[appId];
|
365
365
|
if (attrs) {
|
@@ -367,7 +367,7 @@ export class AppProxy implements PageRemoveService {
|
|
367
367
|
}
|
368
368
|
});
|
369
369
|
});
|
370
|
-
this.manager.refresher
|
370
|
+
this.manager.refresher.add(this.stateKey, () => {
|
371
371
|
return autorun(() => {
|
372
372
|
const appState = this.appAttributes?.state;
|
373
373
|
if (appState?.zIndex > 0 && appState.zIndex !== this.box?.zIndex) {
|
@@ -376,7 +376,7 @@ export class AppProxy implements PageRemoveService {
|
|
376
376
|
}
|
377
377
|
});
|
378
378
|
});
|
379
|
-
this.manager.refresher
|
379
|
+
this.manager.refresher.add(`${appId}-fullPath`, () => {
|
380
380
|
return autorun(() => {
|
381
381
|
const fullPath = this.appAttributes?.fullPath;
|
382
382
|
this.setFocusScenePathHandler(fullPath);
|
@@ -493,9 +493,9 @@ export class AppProxy implements PageRemoveService {
|
|
493
493
|
|
494
494
|
this.viewManager.destroyView(this.id);
|
495
495
|
this.manager.appStatus.delete(this.id);
|
496
|
-
this.manager.refresher
|
497
|
-
this.manager.refresher
|
498
|
-
this.manager.refresher
|
496
|
+
this.manager.refresher.remove(this.id);
|
497
|
+
this.manager.refresher.remove(this.stateKey);
|
498
|
+
this.manager.refresher.remove(`${this.id}-fullPath`);
|
499
499
|
this._prevFullPath = undefined;
|
500
500
|
}
|
501
501
|
|
package/src/AppManager.ts
CHANGED
@@ -55,7 +55,7 @@ export class AppManager {
|
|
55
55
|
public appStatus: Map<string, AppStatus> = new Map();
|
56
56
|
public store = store;
|
57
57
|
public mainViewProxy: MainViewProxy;
|
58
|
-
public refresher
|
58
|
+
public refresher: ReconnectRefresher;
|
59
59
|
public isReplay = this.windowManger.isReplay;
|
60
60
|
public mainViewScenesLength = 0;
|
61
61
|
|
@@ -91,15 +91,13 @@ export class AppManager {
|
|
91
91
|
this.refresher.setRoom(this.room);
|
92
92
|
this.refresher.setContext({ emitter: internalEmitter });
|
93
93
|
|
94
|
-
this.sideEffectManager.
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
this.callbacksNode?.dispose();
|
102
|
-
};
|
94
|
+
this.sideEffectManager.addDisposer(() => {
|
95
|
+
this.appCreateQueue.destroy();
|
96
|
+
this.mainViewProxy.destroy();
|
97
|
+
this.refresher.destroy();
|
98
|
+
this.viewManager.destroy();
|
99
|
+
this.boxManager?.destroy();
|
100
|
+
this.callbacksNode?.dispose();
|
103
101
|
});
|
104
102
|
|
105
103
|
internalEmitter.once("onCreated").then(() => this.onCreated());
|
@@ -289,6 +287,14 @@ export class AppManager {
|
|
289
287
|
return this.mainViewProxy.view;
|
290
288
|
}
|
291
289
|
|
290
|
+
public get polling() {
|
291
|
+
return this.mainViewProxy.polling;
|
292
|
+
}
|
293
|
+
|
294
|
+
public set polling(b: boolean) {
|
295
|
+
this.mainViewProxy.polling = b;
|
296
|
+
}
|
297
|
+
|
292
298
|
public get focusApp() {
|
293
299
|
if (this.store.focus) {
|
294
300
|
return this.appProxies.get(this.store.focus);
|
@@ -319,31 +325,31 @@ export class AppManager {
|
|
319
325
|
|
320
326
|
this.addAppsChangeListener();
|
321
327
|
this.addAppCloseListener();
|
322
|
-
this.refresher
|
328
|
+
this.refresher.add("maximized", () => {
|
323
329
|
return autorun(() => {
|
324
330
|
const maximized = this.attributes.maximized;
|
325
331
|
this.boxManager?.setMaximized(Boolean(maximized));
|
326
332
|
});
|
327
333
|
});
|
328
|
-
this.refresher
|
334
|
+
this.refresher.add("minimized", () => {
|
329
335
|
return autorun(() => {
|
330
336
|
const minimized = this.attributes.minimized;
|
331
337
|
this.onMinimized(minimized);
|
332
338
|
});
|
333
339
|
});
|
334
|
-
this.refresher
|
340
|
+
this.refresher.add("mainViewIndex", () => {
|
335
341
|
return autorun(() => {
|
336
342
|
const mainSceneIndex = get(this.attributes, "_mainSceneIndex");
|
337
343
|
this.onMainViewIndexChange(mainSceneIndex);
|
338
344
|
});
|
339
345
|
});
|
340
|
-
this.refresher
|
346
|
+
this.refresher.add("focusedChange", () => {
|
341
347
|
return autorun(() => {
|
342
348
|
const focused = get(this.attributes, "focus");
|
343
349
|
this.onFocusChange(focused);
|
344
350
|
});
|
345
351
|
});
|
346
|
-
this.refresher
|
352
|
+
this.refresher.add("registeredChange", () => {
|
347
353
|
return autorun(() => {
|
348
354
|
const registered = get(this.attributes, Fields.Registered);
|
349
355
|
this.onRegisteredChange(registered);
|
@@ -402,7 +408,7 @@ export class AppManager {
|
|
402
408
|
};
|
403
409
|
|
404
410
|
public addAppsChangeListener = () => {
|
405
|
-
this.refresher
|
411
|
+
this.refresher.add("apps", () => {
|
406
412
|
return safeListenPropsUpdated(
|
407
413
|
() => this.attributes.apps,
|
408
414
|
() => {
|
@@ -413,7 +419,7 @@ export class AppManager {
|
|
413
419
|
};
|
414
420
|
|
415
421
|
public addAppCloseListener = () => {
|
416
|
-
this.refresher
|
422
|
+
this.refresher.add("appsClose", () => {
|
417
423
|
return onObjectRemoved(this.attributes.apps, () => {
|
418
424
|
this.onAppDelete(this.attributes.apps);
|
419
425
|
});
|
package/src/View/MainView.ts
CHANGED
@@ -11,6 +11,9 @@ import type { AppManager } from "../AppManager";
|
|
11
11
|
import { Events } from "../constants";
|
12
12
|
|
13
13
|
export class MainViewProxy {
|
14
|
+
/** Refresh the view's camera in an interval of 1.5s. */
|
15
|
+
public polling = false;
|
16
|
+
|
14
17
|
private scale?: number;
|
15
18
|
private started = false;
|
16
19
|
private mainViewIsAddListener = false;
|
@@ -45,8 +48,18 @@ export class MainViewProxy {
|
|
45
48
|
}
|
46
49
|
});
|
47
50
|
});
|
51
|
+
this.sideEffectManager.setInterval(this.syncCamera, 1500);
|
48
52
|
}
|
49
53
|
|
54
|
+
// Guard function when the camera is not synced
|
55
|
+
private syncCamera = () => {
|
56
|
+
if (!this.polling || this.viewMode !== ViewMode.Broadcaster) return;
|
57
|
+
const { mainViewCamera } = this;
|
58
|
+
if (mainViewCamera && mainViewCamera.id !== this.manager.uid) {
|
59
|
+
this.moveCameraSizeByAttributes();
|
60
|
+
}
|
61
|
+
};
|
62
|
+
|
50
63
|
private startListenWritableChange = () => {
|
51
64
|
this.sideEffectManager.add(() => {
|
52
65
|
return internalEmitter.on("writableChange", isWritable => {
|
@@ -93,7 +106,7 @@ export class MainViewProxy {
|
|
93
106
|
}
|
94
107
|
|
95
108
|
public addCameraReaction = () => {
|
96
|
-
this.manager.refresher
|
109
|
+
this.manager.refresher.add(Fields.MainViewCamera, this.cameraReaction);
|
97
110
|
};
|
98
111
|
|
99
112
|
public setCameraAndSize(): void {
|
@@ -280,8 +293,8 @@ export class MainViewProxy {
|
|
280
293
|
|
281
294
|
public stop() {
|
282
295
|
this.removeCameraListener();
|
283
|
-
this.manager.refresher
|
284
|
-
this.manager.refresher
|
296
|
+
this.manager.refresher.remove(Fields.MainViewCamera);
|
297
|
+
this.manager.refresher.remove(Fields.MainViewSize);
|
285
298
|
this.started = false;
|
286
299
|
}
|
287
300
|
|
package/src/index.ts
CHANGED
@@ -141,6 +141,7 @@ export type MountParams = {
|
|
141
141
|
prefersColorScheme?: TeleBoxColorScheme;
|
142
142
|
applianceIcons?: ApplianceIcons;
|
143
143
|
fullscreen?: boolean;
|
144
|
+
polling?: boolean;
|
144
145
|
};
|
145
146
|
|
146
147
|
export const reconnectRefresher = new ReconnectRefresher({ emitter: internalEmitter });
|
@@ -217,7 +218,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
|
|
217
218
|
} else {
|
218
219
|
await pRetry(
|
219
220
|
async count => {
|
220
|
-
manager =
|
221
|
+
manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager;
|
221
222
|
if (!manager) {
|
222
223
|
log(`manager is empty. retrying ${count}`);
|
223
224
|
throw new Error();
|
@@ -239,6 +240,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
|
|
239
240
|
|
240
241
|
manager._fullscreen = params.fullscreen;
|
241
242
|
manager.appManager = new AppManager(manager);
|
243
|
+
manager.appManager.polling = params.polling || false;
|
242
244
|
manager._pageState = new PageStateImpl(manager.appManager);
|
243
245
|
manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor), params.applianceIcons);
|
244
246
|
if (containerSizeRatio) {
|
@@ -418,6 +420,9 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
|
|
418
420
|
if (!params.kind || typeof params.kind !== "string") {
|
419
421
|
throw new Errors.ParamsInvalidError();
|
420
422
|
}
|
423
|
+
if (params.src && typeof params.src === "string") {
|
424
|
+
appRegister.register({ kind: params.kind, src: params.src });
|
425
|
+
}
|
421
426
|
const appImpl = await appRegister.appClasses.get(params.kind)?.();
|
422
427
|
if (appImpl && appImpl.config?.singleton) {
|
423
428
|
if (this.appManager.appProxies.has(params.kind)) {
|
@@ -614,7 +619,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
|
|
614
619
|
|
615
620
|
/**
|
616
621
|
* app 本地自定义事件回调
|
617
|
-
*
|
622
|
+
*
|
618
623
|
* 返回一个用于撤销此监听的函数
|
619
624
|
*/
|
620
625
|
public onAppEvent(kind: string, listener: (args: { kind: string, appId: string, type: string, value: any }) => void): () => void {
|
@@ -731,6 +736,16 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
|
|
731
736
|
return this.appManager?.focusApp?.view || this.mainView;
|
732
737
|
}
|
733
738
|
|
739
|
+
public get polling(): boolean {
|
740
|
+
return this.appManager?.polling || false;
|
741
|
+
}
|
742
|
+
|
743
|
+
public set polling(b: boolean) {
|
744
|
+
if (this.appManager) {
|
745
|
+
this.appManager.polling = b;
|
746
|
+
}
|
747
|
+
}
|
748
|
+
|
734
749
|
public get mainViewSceneIndex(): number {
|
735
750
|
return this._pageState?.index || 0;
|
736
751
|
}
|
@@ -963,14 +978,14 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any>
|
|
963
978
|
this._refresh();
|
964
979
|
this.appManager?.dispatchInternalEvent(Events.Refresh);
|
965
980
|
}
|
966
|
-
|
981
|
+
|
967
982
|
/** @inner */
|
968
983
|
public _refresh() {
|
969
984
|
this.appManager?.mainViewProxy.rebind();
|
970
985
|
if (WindowManager.container) {
|
971
986
|
this.bindContainer(WindowManager.container);
|
972
987
|
}
|
973
|
-
this.appManager?.refresher
|
988
|
+
this.appManager?.refresher.refresh();
|
974
989
|
}
|
975
990
|
|
976
991
|
public setContainerSizeRatio(ratio: number) {
|