@netless/window-manager 0.3.9-canary.0 → 0.3.11
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 -1
- package/dist/AppProxy.d.ts +2 -2
- package/dist/BoxManager.d.ts +1 -1
- package/dist/index.d.ts +6 -6
- 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 +3 -3
- package/src/AppManager.ts +8 -6
- package/src/AppProxy.ts +26 -12
- package/src/BoxManager.ts +2 -2
- package/src/Utils/RoomHacker.ts +3 -0
- package/src/index.ts +62 -47
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@netless/window-manager",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.11",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.es.js",
|
6
6
|
"module": "dist/index.es.js",
|
@@ -24,7 +24,7 @@
|
|
24
24
|
"@juggle/resize-observer": "^3.3.1",
|
25
25
|
"@netless/app-docs-viewer": "^0.1.21",
|
26
26
|
"@netless/app-media-player": "0.1.0-beta.5",
|
27
|
-
"@netless/telebox-insider": "0.2.
|
27
|
+
"@netless/telebox-insider": "0.2.7",
|
28
28
|
"emittery": "^0.9.2",
|
29
29
|
"lodash": "^4.17.21",
|
30
30
|
"p-retry": "^4.6.1",
|
@@ -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.12"
|
60
60
|
}
|
61
61
|
}
|
package/src/AppManager.ts
CHANGED
@@ -160,7 +160,7 @@ export class AppManager {
|
|
160
160
|
const ids = Object.keys(apps);
|
161
161
|
this.appProxies.forEach((appProxy, id) => {
|
162
162
|
if (!ids.includes(id)) {
|
163
|
-
appProxy.destroy(true, false);
|
163
|
+
appProxy.destroy(true, false, true);
|
164
164
|
}
|
165
165
|
});
|
166
166
|
};
|
@@ -217,7 +217,7 @@ export class AppManager {
|
|
217
217
|
public async closeApp(appId: string) {
|
218
218
|
const appProxy = this.appProxies.get(appId);
|
219
219
|
if (appProxy) {
|
220
|
-
appProxy.destroy(true, true);
|
220
|
+
appProxy.destroy(true, true, false);
|
221
221
|
}
|
222
222
|
}
|
223
223
|
|
@@ -415,10 +415,12 @@ export class AppManager {
|
|
415
415
|
}
|
416
416
|
}
|
417
417
|
|
418
|
-
public notifyReconnected() {
|
419
|
-
this.appProxies.
|
420
|
-
|
418
|
+
public async notifyReconnected() {
|
419
|
+
const appProxies = Array.from(this.appProxies.values());
|
420
|
+
const reconnected = appProxies.map(appProxy => {
|
421
|
+
return appProxy.onReconnected();
|
421
422
|
});
|
423
|
+
await Promise.all(reconnected);
|
422
424
|
}
|
423
425
|
|
424
426
|
public notifyContainerRectUpdate(rect: TeleBoxRect) {
|
@@ -442,7 +444,7 @@ export class AppManager {
|
|
442
444
|
emitter.clearListeners();
|
443
445
|
if (this.appProxies.size) {
|
444
446
|
this.appProxies.forEach(appProxy => {
|
445
|
-
appProxy.destroy(true, false);
|
447
|
+
appProxy.destroy(true, false, true);
|
446
448
|
});
|
447
449
|
}
|
448
450
|
this.viewManager.destroy();
|
package/src/AppProxy.ts
CHANGED
@@ -101,7 +101,10 @@ export class AppProxy extends Base {
|
|
101
101
|
this.manager.safeUpdateAttributes(["apps", this.id, Fields.FullPath], path);
|
102
102
|
}
|
103
103
|
|
104
|
-
public async baseInsertApp(
|
104
|
+
public async baseInsertApp(
|
105
|
+
skipUpdate = false,
|
106
|
+
focus?: boolean
|
107
|
+
): Promise<{ appId: string; app: NetlessApp }> {
|
105
108
|
const params = this.params;
|
106
109
|
if (!params.kind) {
|
107
110
|
throw new Error("[WindowManager]: kind require");
|
@@ -109,7 +112,7 @@ export class AppProxy extends Base {
|
|
109
112
|
const appImpl = await appRegister.appClasses.get(params.kind)?.();
|
110
113
|
const appParams = appRegister.registered.get(params.kind);
|
111
114
|
if (appImpl) {
|
112
|
-
await this.setupApp(this.id, appImpl, params.options, appParams?.appOptions);
|
115
|
+
await this.setupApp(this.id, skipUpdate, appImpl, params.options, appParams?.appOptions);
|
113
116
|
} else {
|
114
117
|
throw new Error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
|
115
118
|
}
|
@@ -139,6 +142,7 @@ export class AppProxy extends Base {
|
|
139
142
|
|
140
143
|
private async setupApp(
|
141
144
|
appId: string,
|
145
|
+
skipUpdate: boolean,
|
142
146
|
app: NetlessApp,
|
143
147
|
options?: setAppOptions,
|
144
148
|
appOptions?: any
|
@@ -147,8 +151,11 @@ export class AppProxy extends Base {
|
|
147
151
|
const context = new AppContext(this.manager, appId, this, appOptions);
|
148
152
|
try {
|
149
153
|
emitter.once(`${appId}${Events.WindowCreated}` as any).then(async () => {
|
150
|
-
|
151
|
-
|
154
|
+
let boxInitState: AppInitState | undefined;
|
155
|
+
if (!skipUpdate) {
|
156
|
+
boxInitState = this.getAppInitState(appId);
|
157
|
+
this.boxManager.updateBoxState(boxInitState);
|
158
|
+
}
|
152
159
|
this.appEmitter.onAny(this.appListener);
|
153
160
|
this.appAttributesUpdateListener(appId);
|
154
161
|
this.setViewFocusScenePath();
|
@@ -204,10 +211,12 @@ export class AppProxy extends Base {
|
|
204
211
|
|
205
212
|
public async onReconnected() {
|
206
213
|
this.appEmitter.emit("reconnected", undefined);
|
207
|
-
|
214
|
+
const currentAppState = this.getAppInitState(this.id);
|
215
|
+
await this.destroy(true, false, true);
|
208
216
|
const params = this.params;
|
209
217
|
const appProxy = new AppProxy(params, this.manager, this.id, this.isAddApp);
|
210
|
-
await appProxy.baseInsertApp(this.store.focus === this.id);
|
218
|
+
await appProxy.baseInsertApp(true, this.store.focus === this.id);
|
219
|
+
this.boxManager.updateBoxState(currentAppState);
|
211
220
|
}
|
212
221
|
|
213
222
|
public switchToWritable() {
|
@@ -236,8 +245,8 @@ export class AppProxy extends Base {
|
|
236
245
|
const focus = this.store.focus;
|
237
246
|
const size = attrs?.[AppAttributes.Size];
|
238
247
|
const sceneIndex = attrs?.[AppAttributes.SceneIndex];
|
239
|
-
const maximized = this.
|
240
|
-
const minimized = this.
|
248
|
+
const maximized = this.attributes?.["maximized"];
|
249
|
+
const minimized = this.attributes?.["minimized"];
|
241
250
|
let payload = { maximized, minimized } as AppInitState;
|
242
251
|
if (position) {
|
243
252
|
payload = { ...payload, id: id, x: position.x, y: position.y };
|
@@ -289,7 +298,7 @@ export class AppProxy extends Base {
|
|
289
298
|
}
|
290
299
|
case AppEvents.destroy: {
|
291
300
|
if (this.status === "destroyed") return;
|
292
|
-
this.destroy(true, data?.error);
|
301
|
+
this.destroy(true, false, true, data?.error);
|
293
302
|
if (data?.error) {
|
294
303
|
console.error(data?.error);
|
295
304
|
}
|
@@ -340,7 +349,12 @@ export class AppProxy extends Base {
|
|
340
349
|
return view;
|
341
350
|
}
|
342
351
|
|
343
|
-
public async destroy(
|
352
|
+
public async destroy(
|
353
|
+
needCloseBox: boolean,
|
354
|
+
cleanAttrs: boolean,
|
355
|
+
skipUpdate: boolean,
|
356
|
+
error?: Error
|
357
|
+
) {
|
344
358
|
if (this.status === "destroyed") return;
|
345
359
|
this.status = "destroyed";
|
346
360
|
await appRegister.notifyApp(this.kind, "destroy", { appId: this.id });
|
@@ -348,7 +362,7 @@ export class AppProxy extends Base {
|
|
348
362
|
this.appEmitter.clearListeners();
|
349
363
|
emitter.emit(`destroy-${this.id}` as any, { error });
|
350
364
|
if (needCloseBox) {
|
351
|
-
this.boxManager.closeBox(this.id);
|
365
|
+
this.boxManager.closeBox(this.id, skipUpdate);
|
352
366
|
}
|
353
367
|
if (cleanAttrs) {
|
354
368
|
this.store.cleanAppAttributes(this.id);
|
@@ -362,6 +376,6 @@ export class AppProxy extends Base {
|
|
362
376
|
}
|
363
377
|
|
364
378
|
public close(): Promise<void> {
|
365
|
-
return this.destroy(true, true);
|
379
|
+
return this.destroy(true, true, false);
|
366
380
|
}
|
367
381
|
}
|
package/src/BoxManager.ts
CHANGED
@@ -188,8 +188,8 @@ export class BoxManager {
|
|
188
188
|
return this.teleBoxManager.queryOne({ id: appId });
|
189
189
|
}
|
190
190
|
|
191
|
-
public closeBox(appId: string): ReadonlyTeleBox | undefined {
|
192
|
-
return this.teleBoxManager.remove(appId);
|
191
|
+
public closeBox(appId: string, skipUpdate = false): ReadonlyTeleBox | undefined {
|
192
|
+
return this.teleBoxManager.remove(appId, skipUpdate);
|
193
193
|
}
|
194
194
|
|
195
195
|
public boxIsFocus(appId: string): boolean | undefined {
|
package/src/Utils/RoomHacker.ts
CHANGED
@@ -33,6 +33,9 @@ export const replaceRoomFunction = (room: Room, manager: AppManager) => {
|
|
33
33
|
room.moveCameraToContain = (...args) => manager.mainView.moveCameraToContain(...args);
|
34
34
|
room.convertToPointInWorld = (...args) => manager.mainView.convertToPointInWorld(...args);
|
35
35
|
room.setCameraBound = (...args) => manager.mainView.setCameraBound(...args);
|
36
|
+
room.scenePreview = (...args) => manager.mainView.scenePreview(...args);
|
37
|
+
room.fillSceneSnapshot = (...args) => manager.mainView.fillSceneSnapshot(...args);
|
38
|
+
room.generateScreenshot = (...args) => manager.mainView.generateScreenshot(...args);
|
36
39
|
}
|
37
40
|
|
38
41
|
};
|
package/src/index.ts
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
import AppDocsViewer from
|
2
|
-
import AppMediaPlayer, { setOptions } from
|
3
|
-
import Emittery from
|
4
|
-
import pRetry from
|
1
|
+
import AppDocsViewer from "@netless/app-docs-viewer";
|
2
|
+
import AppMediaPlayer, { setOptions } from "@netless/app-media-player";
|
3
|
+
import Emittery from "emittery";
|
4
|
+
import pRetry from "p-retry";
|
5
|
+
import { AppManager } from "./AppManager";
|
6
|
+
import { appRegister } from "./Register";
|
7
|
+
import { CursorManager } from "./Cursor";
|
8
|
+
import { DEFAULT_CONTAINER_RATIO, REQUIRE_VERSION } from "./constants";
|
9
|
+
import { Fields } from "./AttributesDelegate";
|
10
|
+
import { initDb } from "./Register/storage";
|
11
|
+
import { isNull, isObject } from "lodash";
|
12
|
+
import { log } from "./Utils/log";
|
13
|
+
import { replaceRoomFunction } from "./Utils/RoomHacker";
|
14
|
+
import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
|
15
|
+
import { setupWrapper } from "./ViewManager";
|
16
|
+
import "./style.css";
|
17
|
+
import "@netless/telebox-insider/dist/style.css";
|
5
18
|
import {
|
6
19
|
addEmitterOnceListener,
|
7
20
|
ensureValidScenePath,
|
8
21
|
getVersionNumber,
|
9
22
|
isValidScenePath,
|
10
|
-
wait
|
11
|
-
|
12
|
-
import {
|
13
|
-
import { appRegister } from './Register';
|
14
|
-
import { CursorManager } from './Cursor';
|
15
|
-
import { DEFAULT_CONTAINER_RATIO, REQUIRE_VERSION } from './constants';
|
16
|
-
import { Fields } from './AttributesDelegate';
|
17
|
-
import { initDb } from './Register/storage';
|
18
|
-
import { isNull, isObject } from 'lodash';
|
19
|
-
import { log } from './Utils/log';
|
20
|
-
import { replaceRoomFunction } from './Utils/RoomHacker';
|
21
|
-
import { ResizeObserver as ResizeObserverPolyfill } from '@juggle/resize-observer';
|
22
|
-
import { setupWrapper } from './ViewManager';
|
23
|
-
import './style.css';
|
24
|
-
import '@netless/telebox-insider/dist/style.css';
|
25
|
-
import type { TELE_BOX_STATE } from './BoxManager';
|
23
|
+
wait,
|
24
|
+
} from "./Utils/Common";
|
25
|
+
import type { TELE_BOX_STATE } from "./BoxManager";
|
26
26
|
import {
|
27
27
|
AppCreateError,
|
28
28
|
AppManagerNotInitError,
|
@@ -50,7 +50,8 @@ import type {
|
|
50
50
|
CameraBound,
|
51
51
|
Point,
|
52
52
|
Rectangle,
|
53
|
-
ViewVisionMode
|
53
|
+
ViewVisionMode,
|
54
|
+
} from "white-web-sdk";
|
54
55
|
import type { AppListeners } from "./AppListener";
|
55
56
|
import type { NetlessApp, RegisterParams } from "./typings";
|
56
57
|
import type { TeleBoxState } from "@netless/telebox-insider";
|
@@ -122,18 +123,18 @@ export type AppInitState = {
|
|
122
123
|
};
|
123
124
|
|
124
125
|
export type EmitterEvent = {
|
125
|
-
onCreated: undefined
|
126
|
-
InitReplay: AppInitState
|
127
|
-
move: { appId: string
|
128
|
-
focus: { appId: string }
|
129
|
-
close: { appId: string }
|
130
|
-
resize: { appId: string
|
131
|
-
error: Error
|
132
|
-
seek: number
|
133
|
-
mainViewMounted: undefined
|
126
|
+
onCreated: undefined;
|
127
|
+
InitReplay: AppInitState;
|
128
|
+
move: { appId: string; x: number; y: number };
|
129
|
+
focus: { appId: string };
|
130
|
+
close: { appId: string };
|
131
|
+
resize: { appId: string; width: number; height: number; x?: number; y?: number };
|
132
|
+
error: Error;
|
133
|
+
seek: number;
|
134
|
+
mainViewMounted: undefined;
|
134
135
|
observerIdChange: number;
|
135
136
|
boxStateChange: string;
|
136
|
-
}
|
137
|
+
};
|
137
138
|
|
138
139
|
export const emitter: Emittery<EmitterEvent> = new Emittery();
|
139
140
|
|
@@ -169,7 +170,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
169
170
|
public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
|
170
171
|
private static isCreated = false;
|
171
172
|
|
172
|
-
public version = "0.3.
|
173
|
+
public version = "0.3.11";
|
173
174
|
|
174
175
|
public appListeners?: AppListeners;
|
175
176
|
|
@@ -272,13 +273,16 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
272
273
|
throw new Error("[WindowManager]: init InvisiblePlugin failed");
|
273
274
|
}
|
274
275
|
} else {
|
275
|
-
await pRetry(
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
276
|
+
await pRetry(
|
277
|
+
async count => {
|
278
|
+
manager = await this.initManager(room);
|
279
|
+
if (!manager) {
|
280
|
+
log(`manager is empty. retrying ${count}`);
|
281
|
+
throw new Error();
|
282
|
+
}
|
283
|
+
},
|
284
|
+
{ retries: 10 }
|
285
|
+
);
|
282
286
|
}
|
283
287
|
|
284
288
|
if (containerSizeRatio) {
|
@@ -327,12 +331,18 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
327
331
|
} catch (error) {
|
328
332
|
throw new Error("[WindowManger]: room must be switched to be writable");
|
329
333
|
}
|
330
|
-
manager = (await room.createInvisiblePlugin(
|
334
|
+
manager = (await room.createInvisiblePlugin(
|
335
|
+
WindowManager,
|
336
|
+
{}
|
337
|
+
)) as WindowManager;
|
331
338
|
manager.ensureAttributes();
|
332
339
|
await wait(500);
|
333
340
|
await room.setWritable(false);
|
334
341
|
} else {
|
335
|
-
manager = (await room.createInvisiblePlugin(
|
342
|
+
manager = (await room.createInvisiblePlugin(
|
343
|
+
WindowManager,
|
344
|
+
{}
|
345
|
+
)) as WindowManager;
|
336
346
|
}
|
337
347
|
}
|
338
348
|
}
|
@@ -342,7 +352,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
342
352
|
/**
|
343
353
|
* 注册插件
|
344
354
|
*/
|
345
|
-
|
355
|
+
public static register<AppOptions = any, SetupResult = any, Attributes = any>(
|
346
356
|
params: RegisterParams<AppOptions, SetupResult, Attributes>
|
347
357
|
): Promise<void> {
|
348
358
|
return appRegister.register(params);
|
@@ -406,7 +416,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
406
416
|
}
|
407
417
|
}
|
408
418
|
if (scenePath && scenes === undefined) {
|
409
|
-
this.room?.putScenes(scenePath, [{}])
|
419
|
+
this.room?.putScenes(scenePath, [{}]);
|
410
420
|
}
|
411
421
|
}
|
412
422
|
return isDynamicPPT;
|
@@ -532,13 +542,18 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
532
542
|
return this.appManager?.closeApp(appId);
|
533
543
|
}
|
534
544
|
|
535
|
-
public moveCamera(
|
545
|
+
public moveCamera(
|
546
|
+
camera: Partial<Camera> & { animationMode?: AnimationMode | undefined }
|
547
|
+
): void {
|
536
548
|
this.mainView.moveCamera(camera);
|
537
549
|
}
|
538
550
|
|
539
|
-
public moveCameraToContain(
|
540
|
-
|
541
|
-
|
551
|
+
public moveCameraToContain(
|
552
|
+
rectangle: Rectangle &
|
553
|
+
Readonly<{
|
554
|
+
animationMode?: AnimationMode;
|
555
|
+
}>
|
556
|
+
): void {
|
542
557
|
this.mainView.moveCameraToContain(rectangle);
|
543
558
|
}
|
544
559
|
|