@netless/window-manager 0.2.2 → 0.2.3-canary.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "0.2.2",
3
+ "version": "0.2.3-canary.0",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",
@@ -55,6 +55,6 @@
55
55
  "typescript": "^4.3.5",
56
56
  "video.js": "^7.14.3",
57
57
  "vite": "^2.5.3",
58
- "white-web-sdk": "^2.14.3"
58
+ "white-web-sdk": "2.14.3"
59
59
  }
60
60
  }
package/src/AppContext.ts CHANGED
@@ -36,7 +36,6 @@ export class AppContext<TAttrs extends Record<string, any>, AppOptions = any> {
36
36
  private manager: AppManager,
37
37
  public appId: string,
38
38
  private appProxy: AppProxy,
39
- public setScenes: (scenes: SceneDefinition[]) => void,
40
39
  private appOptions?: AppOptions | (() => AppOptions),
41
40
  ) {
42
41
  this.emitter = appProxy.appEmitter;
package/src/AppManager.ts CHANGED
@@ -167,9 +167,7 @@ export class AppManager {
167
167
  this.appProxies.forEach(appProxy => {
168
168
  if (appProxy.scenePath && scenePath.startsWith(appProxy.scenePath)) {
169
169
  appProxy.emitAppSceneStateChange(sceneState);
170
- if (sceneState.index !== appProxy.sceneIndex) {
171
- appProxy.setSceneIndex(sceneState.index);
172
- }
170
+ appProxy.setFullPath(scenePath);
173
171
  }
174
172
  });
175
173
  this.viewManager.refreshViews();
package/src/AppProxy.ts CHANGED
@@ -1,16 +1,17 @@
1
- import Emittery from "emittery";
2
- import { AppAttributes, AppEvents, Events } from "./constants";
3
- import { AppContext } from "./AppContext";
4
- import { appRegister } from "./Register";
5
- import { autorun, ViewVisionMode } from "white-web-sdk";
6
- import { log } from "./Utils/log";
1
+ import Emittery from 'emittery';
2
+ import { AppAttributes, AppEvents, Events } from './constants';
3
+ import { AppContext } from './AppContext';
4
+ import { appRegister } from './Register';
5
+ import { autorun, ViewVisionMode } from 'white-web-sdk';
6
+ import { callbacks, emitter } from './index';
7
+ import { Fields } from './AttributesDelegate';
8
+ import { log } from './Utils/log';
7
9
  import {
8
10
  notifyMainViewModeChange,
9
11
  setScenePath,
10
12
  setViewFocusScenePath,
11
13
  setViewMode,
12
14
  } from "./Utils/Common";
13
- import { callbacks, emitter } from "./index";
14
15
  import type {
15
16
  AppEmitterEvent,
16
17
  AppInitState,
@@ -18,7 +19,7 @@ import type {
18
19
  setAppOptions,
19
20
  AppListenerKeys,
20
21
  } from "./index";
21
- import type { Camera, SceneDefinition, SceneState, View } from "white-web-sdk";
22
+ import type { Camera, SceneState, View, SceneDefinition } from "white-web-sdk";
22
23
  import type { AppManager } from "./AppManager";
23
24
  import type { NetlessApp } from "./typings";
24
25
  import type { ReadonlyTeleBox } from "@netless/telebox-insider";
@@ -59,6 +60,7 @@ export class AppProxy {
59
60
  this.scenes = options.scenes;
60
61
  }
61
62
  }
63
+
62
64
  if (this.params.options?.scenePath) {
63
65
  // 只有传入了 scenePath 的 App 才会创建 View
64
66
  this.createView();
@@ -67,14 +69,6 @@ export class AppProxy {
67
69
  this.isAddApp = isAddApp;
68
70
  }
69
71
 
70
- public get sceneIndex(): number {
71
- return this.manager.delegate.getAppSceneIndex(this.id);
72
- }
73
-
74
- public setSceneIndex(index: number): void {
75
- return this.manager.delegate.updateAppState(this.id, AppAttributes.SceneIndex, index);
76
- }
77
-
78
72
  public get view(): View | undefined {
79
73
  return this.manager.viewManager.getView(this.id);
80
74
  }
@@ -87,20 +81,14 @@ export class AppProxy {
87
81
  return this.manager.attributes[this.id];
88
82
  }
89
83
 
90
- public getSceneName(): string | undefined {
91
- if (this.sceneIndex !== undefined) {
92
- return this.scenes?.[this.sceneIndex]?.name;
93
- }
94
- }
95
-
96
84
  public getFullScenePath(): string | undefined {
97
- if (this.scenePath && this.getSceneName()) {
98
- return `${this.scenePath}/${this.getSceneName()}`;
85
+ if (this.scenePath) {
86
+ return this.manager.delegate.getAppAttributes(this.id)[Fields.FullPath] || this.scenePath;
99
87
  }
100
88
  }
101
89
 
102
- public setScenes(scenes: SceneDefinition[]): void {
103
- this.scenes = scenes;
90
+ public setFullPath(path: string) {
91
+ this.manager.safeUpdateAttributes(["apps", this.id, Fields.FullPath], path);
104
92
  }
105
93
 
106
94
  public async baseInsertApp(focus?: boolean): Promise<{ appId: string; app: NetlessApp }> {
@@ -138,7 +126,7 @@ export class AppProxy {
138
126
 
139
127
  private async setupApp(appId: string, app: NetlessApp, options?: setAppOptions, appOptions?: any) {
140
128
  log("setupApp", appId, app, options);
141
- const context = new AppContext(this.manager, appId, this, this.setScenes, appOptions);
129
+ const context = new AppContext(this.manager, appId, this, appOptions);
142
130
  try {
143
131
  emitter.once(`${appId}${Events.WindowCreated}`).then(async () => {
144
132
  const boxInitState = this.getAppInitState(appId);
@@ -16,6 +16,7 @@ export enum Fields {
16
16
  Cursors = "cursors",
17
17
  Position = "position",
18
18
  CursorState = "cursorState",
19
+ FullPath = "fullPath"
19
20
  }
20
21
 
21
22
  export type Apps = {
@@ -59,6 +59,18 @@ export const makeValidScenePath = (displayer: Displayer, scenePath: string) => {
59
59
  }
60
60
  };
61
61
 
62
+ export const isValidScenePath = (scenePath: string) => {
63
+ return scenePath.startsWith("/");
64
+ }
65
+
66
+ export const ensureValidScenePath = (scenePath: string) => {
67
+ if (scenePath.endsWith("/")) {
68
+ return scenePath.slice(0, -1);
69
+ } else {
70
+ return scenePath;
71
+ }
72
+ }
73
+
62
74
  export const getVersionNumber = (version: string) => {
63
75
  const versionString = version.split(".").map(s => s.padStart(2, "0")).join("");
64
76
  return parseInt(versionString);
@@ -25,3 +25,7 @@ export class ParamsInvalidError extends Error {
25
25
  export class BoxNotCreatedError extends Error {
26
26
  override message = "[WindowManager]: box need created";
27
27
  }
28
+
29
+ export class InvalidScenePath extends Error {
30
+ override message = `[WindowManager]: ScenePath should start with "/"`;
31
+ }
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ import { isNull, isObject } from "lodash";
5
5
  import {
6
6
  AppCreateError,
7
7
  AppManagerNotInitError,
8
+ InvalidScenePath,
8
9
  ParamsInvalidError,
9
10
  WhiteWebSDKInvalidError,
10
11
  } from "./Utils/error";
@@ -13,7 +14,7 @@ import { appRegister } from "./Register";
13
14
  import { CursorManager } from "./Cursor";
14
15
  import type { Apps } from "./AttributesDelegate";
15
16
  import { Fields } from "./AttributesDelegate";
16
- import { getVersionNumber, wait } from "./Utils/Common";
17
+ import { ensureValidScenePath, getVersionNumber, isValidScenePath, wait } from "./Utils/Common";
17
18
  import {
18
19
  InvisiblePlugin,
19
20
  isRoom,
@@ -89,6 +90,7 @@ export type AppSyncAttributes = {
89
90
  options: any;
90
91
  state?: any;
91
92
  isDynamicPPT?: boolean;
93
+ fullPath?: string;
92
94
  };
93
95
 
94
96
  export type AppInitState = {
@@ -213,8 +215,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
213
215
  }
214
216
 
215
217
  this.checkVersion();
216
- if (room.phase !== RoomPhase.Connected) {
217
- throw new Error("[WindowManager]: Room only Connected can be mount");
218
+ if (isRoom(room)) {
219
+ if (room.phase !== RoomPhase.Connected) {
220
+ throw new Error("[WindowManager]: Room only Connected can be mount");
221
+ }
218
222
  }
219
223
  if (!container) {
220
224
  throw new Error("[WindowManager]: Container must provide");
@@ -227,7 +231,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
227
231
  if (this.debug) {
228
232
  setOptions({ verbose: true });
229
233
  }
230
- log("[WindowManager]: Already insert room", manager);
234
+ log("Already insert room", manager);
231
235
  if (containerSizeRatio) {
232
236
  WindowManager.containerSizeRatio = containerSizeRatio;
233
237
  }
@@ -322,6 +326,9 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
322
326
  if (isDynamicPPT === undefined) {
323
327
  return;
324
328
  }
329
+ if (params?.options?.scenePath) {
330
+ params.options.scenePath = ensureValidScenePath(params.options.scenePath);
331
+ }
325
332
  const appId = await this.appManager.addApp(params, Boolean(isDynamicPPT));
326
333
  return appId;
327
334
  } else {
@@ -334,10 +341,13 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
334
341
  if (params.options) {
335
342
  const { scenePath, scenes } = params.options;
336
343
  if (scenePath) {
344
+ if (!isValidScenePath(scenePath)) {
345
+ throw new InvalidScenePath();
346
+ }
337
347
  for (const appId in this.apps) {
338
348
  const appScenePath = appManager.delegate.getAppScenePath(appId);
339
349
  if (appScenePath && appScenePath === scenePath) {
340
- console.warn(`ScenePath ${scenePath} Already opened`);
350
+ console.warn(`[WindowManager]: ScenePath ${scenePath} Already opened`);
341
351
  return;
342
352
  }
343
353
  }
@@ -354,6 +364,9 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
354
364
  }
355
365
  }
356
366
  }
367
+ if (scenePath && scenes === undefined) {
368
+ this.room?.putScenes(scenePath, [{}])
369
+ }
357
370
  }
358
371
  return isDynamicPPT;
359
372
  }