@netless/window-manager 1.0.12 → 1.0.13-bate.1

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/src/index.ts CHANGED
@@ -12,7 +12,7 @@ import { Fields } from "./AttributesDelegate";
12
12
  import { initDb } from "./Register/storage";
13
13
  import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
14
14
  import { isEqual, isNull, isObject, omit, isNumber } from "lodash";
15
- import { log } from "./Utils/log";
15
+ import { ArgusLog, log } from "./Utils/log";
16
16
  import { PageStateImpl } from "./PageState";
17
17
  import { ReconnectRefresher } from "./ReconnectRefresher";
18
18
  import { replaceRoomFunction } from "./Utils/RoomHacker";
@@ -47,6 +47,7 @@ import type {
47
47
  Player,
48
48
  ImageInformation,
49
49
  SceneState,
50
+ Logger,
50
51
  } from "white-web-sdk";
51
52
  import type { AppListeners } from "./AppListener";
52
53
  import type { ApplianceIcons, NetlessApp, RegisterParams } from "./typings";
@@ -242,10 +243,19 @@ export class WindowManager
242
243
 
243
244
  private extendPluginManager?: ExtendPluginManager;
244
245
 
246
+ private _roomLogger?: Logger;
247
+
248
+ public attributesDeboundceLog?: ArgusLog;
249
+
250
+ get Logger(): Logger | undefined {
251
+ return this._roomLogger;
252
+ }
253
+
245
254
  constructor(context: InvisiblePluginContext) {
246
255
  super(context);
247
256
  WindowManager.displayer = context.displayer;
248
257
  (window as any).NETLESS_DEPS = __APP_DEPENDENCIES__;
258
+ this.emitter.on('mainViewScenePathChange', this.onMainViewScenePathChangeHandler)
249
259
  }
250
260
 
251
261
  public static onCreate(manager: WindowManager) {
@@ -277,6 +287,17 @@ export class WindowManager
277
287
  room.disableSerialization = false;
278
288
  }
279
289
  manager = await this.initManager(room);
290
+ if (manager) {
291
+ manager._roomLogger = (room as unknown as { logger: Logger }).logger;
292
+ manager.attributesDeboundceLog = new ArgusLog(manager._roomLogger, "attributes", 300);
293
+ if (WindowManager.registered.size > 0) {
294
+ manager._roomLogger.info(
295
+ `[WindowManager] registered apps: ${JSON.stringify(
296
+ Array.from(WindowManager.registered.keys())
297
+ )}`
298
+ );
299
+ }
300
+ }
280
301
  }
281
302
  if (WindowManager.isCreated) {
282
303
  throw new Error("[WindowManager]: Already created cannot be created again");
@@ -286,7 +307,13 @@ export class WindowManager
286
307
  if (this.debug) {
287
308
  setOptions({ verbose: true });
288
309
  }
289
- log("Already insert room", manager);
310
+ if (manager?._roomLogger) {
311
+ manager._roomLogger.info(
312
+ `[WindowManager] Already insert room version: ${manager.version}`
313
+ );
314
+ } else {
315
+ log("Already insert room", manager);
316
+ }
290
317
 
291
318
  if (isRoom(this.displayer)) {
292
319
  if (!manager) {
@@ -345,15 +372,46 @@ export class WindowManager
345
372
  replaceRoomFunction(room, manager);
346
373
  internalEmitter.emit("onCreated");
347
374
  WindowManager.isCreated = true;
375
+ if (
376
+ manager._roomLogger &&
377
+ manager.attributes.registered &&
378
+ Object.keys(manager.attributes.registered).length > 0
379
+ ) {
380
+ manager._roomLogger.info(
381
+ `[WindowManager] attributes registered apps: ${JSON.stringify(
382
+ Array.from(Object.keys(manager.attributes.registered))
383
+ )}`
384
+ );
385
+ }
348
386
  try {
349
387
  await initDb();
350
388
  } catch (error) {
389
+ manager._roomLogger?.warn(`[WindowManager] indexedDB open failed: ${error.message}`);
351
390
  console.warn("[WindowManager]: indexedDB open failed");
352
391
  console.log(error);
353
392
  }
393
+ manager.emitter.on('mainViewScenePathChange', manager.onMainViewScenePathChangeHandler)
354
394
  return manager;
355
395
  }
356
396
 
397
+ public onMainViewScenePathChangeHandler = (scenePath: string) => {
398
+ const mainViewElement = this.mainView.divElement;
399
+ if (mainViewElement) {
400
+ const backgroundImage = mainViewElement.querySelector('.background img');
401
+ if (backgroundImage) {
402
+ const backgroundImageRect = backgroundImage?.getBoundingClientRect();
403
+ const backgroundImageCSS = window.getComputedStyle(backgroundImage);
404
+ const backgroundImageVisible = backgroundImageRect?.width > 0 && backgroundImageRect?.height > 0 && backgroundImageCSS.display !== 'none';
405
+ const camera = this.mainView.camera;
406
+ console.log("[window-manager] backgroundImageVisible:" + backgroundImageVisible + " camera:" + JSON.stringify(camera));
407
+ return;
408
+ }
409
+ console.log("[window-manager] onMainViewScenePathChange scenePath:" + scenePath + ' backgroundImageVisible is not found');
410
+ return;
411
+ }
412
+ console.log("[window-manager] onMainViewScenePathChange scenePath:" + scenePath + ' mainViewElement is not found');
413
+ }
414
+
357
415
  private static initManager(room: Room): Promise<WindowManager | undefined> {
358
416
  return createInvisiblePlugin(room);
359
417
  }
@@ -975,7 +1033,6 @@ export class WindowManager
975
1033
  const mainViewCamera = { ...this.mainView.camera };
976
1034
  if (isEqual({ ...mainViewCamera, ...pureCamera }, mainViewCamera)) return;
977
1035
  this.mainView.moveCamera(camera);
978
- // this.appManager?.dispatchInternalEvent(Events.MoveCamera, camera);
979
1036
  setTimeout(() => {
980
1037
  this.appManager?.mainViewProxy.setCameraAndSize();
981
1038
  }, 500);
@@ -988,7 +1045,6 @@ export class WindowManager
988
1045
  }>
989
1046
  ): void {
990
1047
  this.mainView.moveCameraToContain(rectangle);
991
- // this.appManager?.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
992
1048
  setTimeout(() => {
993
1049
  this.appManager?.mainViewProxy.setCameraAndSize();
994
1050
  }, 500);
@@ -1011,6 +1067,8 @@ export class WindowManager
1011
1067
  }
1012
1068
 
1013
1069
  private _destroy() {
1070
+ this.attributesDeboundceLog?.destroy();
1071
+ this.attributesDeboundceLog = undefined;
1014
1072
  this.containerResizeObserver?.disconnect();
1015
1073
  this.appManager?.destroy();
1016
1074
  this.cursorManager?.destroy();
@@ -1023,6 +1081,7 @@ export class WindowManager
1023
1081
  WindowManager.playground.parentNode?.removeChild(WindowManager.playground);
1024
1082
  }
1025
1083
  WindowManager.params = undefined;
1084
+ this.emitter.off('mainViewScenePathChange', this.onMainViewScenePathChangeHandler);
1026
1085
  this._iframeBridge?.destroy();
1027
1086
  this._iframeBridge = undefined;
1028
1087
  log("Destroyed");
@@ -1053,12 +1112,18 @@ export class WindowManager
1053
1112
  public safeSetAttributes(attributes: any): void {
1054
1113
  if (this.canOperate) {
1055
1114
  this.setAttributes(attributes);
1115
+ if (this.attributesDeboundceLog) {
1116
+ this.attributesDeboundceLog.logDebouncedShallowMerge("safeSetAttributes", attributes);
1117
+ }
1056
1118
  }
1057
1119
  }
1058
1120
 
1059
1121
  public safeUpdateAttributes(keys: string[], value: any): void {
1060
1122
  if (this.canOperate) {
1061
1123
  this.updateAttributes(keys, value);
1124
+ if (this.attributesDeboundceLog) {
1125
+ this.attributesDeboundceLog.logDebouncedUpdateAttributes(keys, value);
1126
+ }
1062
1127
  }
1063
1128
  }
1064
1129
 
@@ -1069,6 +1134,7 @@ export class WindowManager
1069
1134
  public cleanCurrentScene(): void {
1070
1135
  log("clean current scene");
1071
1136
  this.focusedView?.cleanCurrentScene();
1137
+ this.Logger && this.Logger.info(`[WindowManager]: cleanCurrentScene ${this.focusedView?.focusScenePath}`);
1072
1138
  }
1073
1139
 
1074
1140
  public redo(): number {
@@ -1081,6 +1147,7 @@ export class WindowManager
1081
1147
 
1082
1148
  public delete(): void {
1083
1149
  this.focusedView?.delete();
1150
+ this.Logger && this.Logger.info(`[WindowManager]: delete ${this.focusedView?.focusScenePath}`);
1084
1151
  }
1085
1152
 
1086
1153
  public copy(): void {