@netless/window-manager 0.2.12-canary.2 → 0.2.15

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/sdk.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { MountParams } from "./index";
3
3
  import type { WhiteWebSdkConfiguration, JoinRoomParams } from "white-web-sdk";
4
4
  declare type WhiteWindowSDKConfiguration = Omit<WhiteWebSdkConfiguration, "useMobXState">;
5
5
  declare type WindowJoinRoomParams = {
6
- joinRoomParams: Omit<JoinRoomParams, "useMultiViews">;
6
+ joinRoomParams: Omit<JoinRoomParams, "useMultiViews" | "disableMagixEventDispatchLimit">;
7
7
  mountParams: Omit<MountParams, "room">;
8
8
  };
9
9
  export declare class WhiteWindowSDK {
package/dist/typings.d.ts CHANGED
@@ -46,6 +46,7 @@ export declare type AppEmitterEvent<T = any> = {
46
46
  roomStateChange: Partial<DisplayerState>;
47
47
  focus: boolean;
48
48
  reconnected: void;
49
+ seek: number;
49
50
  };
50
51
  export declare type RegisterEventData = {
51
52
  appId: string;
package/docs/camera.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # 视角
2
- 在多窗口模式下, 可以同时存在多块白板,但是大多数情况下用户都只需要对主白板也就是 `mainView` 进行操作
2
+ 在多窗口模式下, 可以同时存在多块白板,但是大多数情况下用户都只需要对主白板也就是 `mainView` 进行操作
3
3
 
4
4
 
5
5
  ## 获取 `mainView` 的 `camera`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "0.2.12-canary.2",
3
+ "version": "0.2.15",
4
4
  "description": "",
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",
package/src/AppManager.ts CHANGED
@@ -6,14 +6,14 @@ import {
6
6
  } from './constants';
7
7
  import { AppListeners } from './AppListener';
8
8
  import { AppProxy } from './AppProxy';
9
- import { AttributesDelegate, Fields } from './AttributesDelegate';
9
+ import { AttributesDelegate } from './AttributesDelegate';
10
10
  import { BoxManager, TELE_BOX_STATE } from './BoxManager';
11
11
  import { callbacks, emitter } from './index';
12
12
  import { CameraStore } from './Utils/CameraStore';
13
13
  import { genAppId, makeValidScenePath } from './Utils/Common';
14
14
  import {
15
+ isPlayer,
15
16
  isRoom,
16
- reaction,
17
17
  ScenePathType
18
18
  } from 'white-web-sdk';
19
19
  import { log } from './Utils/log';
@@ -51,17 +51,20 @@ export class AppManager {
51
51
  this.appProxies
52
52
  );
53
53
  this.displayer.callbacks.on(this.eventName, this.displayerStateListener);
54
- this.displayerWritableListener(!this.room?.isWritable);
55
- this.displayer.callbacks.on("onEnableWriteNowChanged", this.displayerWritableListener);
56
54
  this.appListeners.addListeners();
57
55
 
58
- if (this.room) {
59
- this.refresher = new ReconnectRefresher(this.room, this);
60
- }
56
+ this.refresher = new ReconnectRefresher(this.room, this);
61
57
 
62
58
  this.mainViewProxy = new MainViewProxy(this);
63
59
 
64
60
  emitter.once("onCreated").then(() => this.onCreated());
61
+
62
+ if (isPlayer(this.displayer)) {
63
+ emitter.on("seek", time => {
64
+ this.appProxies.forEach(appProxy => appProxy.appEmitter.emit("seek", time));
65
+ this.attributesUpdateCallback(this.attributes.apps);
66
+ })
67
+ }
65
68
  }
66
69
 
67
70
  private async onCreated() {
@@ -85,6 +88,8 @@ export class AppManager {
85
88
  this.room?.setScenePath(mainScenePath);
86
89
  }
87
90
  }
91
+ this.displayerWritableListener(!this.room?.isWritable);
92
+ this.displayer.callbacks.on("onEnableWriteNowChanged", this.displayerWritableListener);
88
93
  }
89
94
 
90
95
  /**
@@ -221,6 +226,9 @@ export class AppManager {
221
226
  if (!this.delegate.focus) {
222
227
  this.viewManager.switchMainViewModeToWriter();
223
228
  }
229
+ this.mainView.disableCameraTransform = false;
230
+ } else {
231
+ this.mainView.disableCameraTransform = true;
224
232
  }
225
233
  }
226
234
 
@@ -420,7 +428,7 @@ export class AppManager {
420
428
  this.displayer.callbacks.off("onEnableWriteNowChanged", this.displayerWritableListener);
421
429
  this.appListeners.removeListeners();
422
430
  emitter.offAny(this.boxEventListener);
423
-
431
+ emitter.clearListeners();
424
432
  if (this.appProxies.size) {
425
433
  this.appProxies.forEach(appProxy => {
426
434
  appProxy.destroy(true, false);
@@ -135,7 +135,7 @@ export class AttributesDelegate {
135
135
  return get(this.manager.attributes, [Fields.MainViewCamera]);
136
136
  }
137
137
 
138
- public getMainViewSize(): Size {
138
+ public getMainViewSize(): Size & { id: number } | undefined {
139
139
  return get(this.manager.attributes, [Fields.MainViewSize]);
140
140
  }
141
141
 
@@ -143,7 +143,7 @@ export class AttributesDelegate {
143
143
  this.manager.safeSetAttributes({ [Fields.MainViewCamera]: { ...camera } });
144
144
  }
145
145
 
146
- public setMainViewSize(size: Size | undefined) {
146
+ public setMainViewSize(size: Size & { id: number } | undefined) {
147
147
  this.manager.safeSetAttributes({ [Fields.MainViewSize]: { ...size } });
148
148
  }
149
149
 
@@ -45,6 +45,7 @@ export class Cursor {
45
45
  this.disposer = autorun(() => {
46
46
  const cursor = this.cursorPosition;
47
47
  const state = this.cursorState;
48
+ if (!cursor) return;
48
49
  if (cursor.type === "main") {
49
50
  const rect = this.cursorManager.wrapperRect;
50
51
  if (this.component && rect) {
@@ -125,11 +126,11 @@ export class Cursor {
125
126
  }
126
127
  }
127
128
 
128
- public get cursorState(): CursorState {
129
+ public get cursorState(): CursorState | undefined {
129
130
  return get(this.cursors, [this.memberId, Fields.CursorState]);
130
131
  }
131
132
 
132
- public get cursorPosition(): Position {
133
+ public get cursorPosition(): Position | undefined {
133
134
  return get(this.cursors, [this.memberId, Fields.Position]);
134
135
  }
135
136
 
package/src/MainView.ts CHANGED
@@ -3,23 +3,29 @@ import { Fields } from './AttributesDelegate';
3
3
  import { debounce, isEmpty, isEqual } from 'lodash';
4
4
  import type { Camera, Size, View } from "white-web-sdk";
5
5
  import type { AppManager } from "./AppManager";
6
+ import { emitter } from './index';
6
7
 
7
8
  export class MainViewProxy {
8
9
  private scale?: number;
9
10
  private delegate = this.manager.delegate;
10
11
  private started = false;
12
+ private observerId = this.manager.displayer.observerId;
11
13
 
12
14
  constructor(
13
15
  private manager: AppManager,
14
16
  ) {
15
- this.start();
17
+ emitter.once("mainViewMounted").then(() => {
18
+ setTimeout(() => {
19
+ this.start();
20
+ }, 300); // 等待 mainView 挂载完毕再进行监听,否则会触发不必要的 onSizeUpdated
21
+ })
16
22
  }
17
23
 
18
24
  private cameraReaction = () => {
19
25
  return reaction(
20
26
  () => this.manager.attributes?.[Fields.MainViewCamera],
21
27
  camera => {
22
- if (camera && camera.id !== this.manager.displayer.observerId) {
28
+ if (camera && camera.id !== this.observerId) {
23
29
  this.moveCamera(camera);
24
30
  }
25
31
  },
@@ -33,7 +39,7 @@ export class MainViewProxy {
33
39
  return reaction(
34
40
  () => this.manager.attributes?.[Fields.MainViewSize],
35
41
  size => {
36
- if (size) {
42
+ if (size && size.id !== this.observerId) {
37
43
  this.moveCameraToContian(size);
38
44
  this.moveCamera(this.delegate.getMainViewCamera());
39
45
  }
@@ -49,7 +55,10 @@ export class MainViewProxy {
49
55
  }
50
56
 
51
57
  private cameraListener = (camera: Camera) => {
52
- this.delegate.setMainViewCamera({ ...camera, id: this.manager.displayer.observerId });
58
+ this.delegate.setMainViewCamera({ ...camera, id: this.observerId});
59
+ if (this.delegate.getMainViewSize()?.id !== this.observerId) {
60
+ this.setMainViewSize(this.view.size);
61
+ }
53
62
  }
54
63
 
55
64
  private sizeListener = (size: Size) => {
@@ -57,8 +66,8 @@ export class MainViewProxy {
57
66
  }
58
67
 
59
68
  public setMainViewSize = debounce(size => {
60
- this.manager.delegate.setMainViewSize({ ...size });
61
- }, 200);
69
+ this.manager.delegate.setMainViewSize({ ...size, id: this.observerId });
70
+ }, 50);
62
71
 
63
72
  private addCameraListener() {
64
73
  this.view.callbacks.on("onCameraUpdatedByDevice", this.cameraListener);
@@ -109,5 +118,6 @@ export class MainViewProxy {
109
118
  this.manager.refresher?.remove(Fields.MainViewCamera);
110
119
  this.manager.refresher?.remove(Fields.MainViewSize);
111
120
  this.view.callbacks.off("onSizeUpdated", this.sizeListener);
121
+ this.started = false;
112
122
  }
113
123
  }
@@ -2,18 +2,19 @@ import { isFunction } from 'lodash';
2
2
  import { RoomPhase } from 'white-web-sdk';
3
3
  import type { Room } from "white-web-sdk";
4
4
  import type { AppManager } from './AppManager';
5
+ import { log } from './Utils/log';
5
6
 
6
7
  // 白板重连之后会刷新所有的对象,导致 listener 失效, 所以这里在重连之后重新对所有对象进行监听
7
8
  export class ReconnectRefresher {
8
- private phase: RoomPhase;
9
- private room: Room;
9
+ private phase?: RoomPhase;
10
+ private room: Room | undefined;
10
11
  private reactors: Map<string, any> = new Map();
11
12
  private disposers: Map<string, any> = new Map();
12
13
 
13
- constructor(room: Room, private manager: AppManager) {
14
+ constructor(room: Room | undefined, private manager: AppManager) {
14
15
  this.room = room;
15
- this.phase = room.phase;
16
- room.callbacks.on("onPhaseChanged", this.onPhaseChanged);
16
+ this.phase = room?.phase;
17
+ room?.callbacks.on("onPhaseChanged", this.onPhaseChanged);
17
18
  }
18
19
 
19
20
  private onPhaseChanged = (phase: RoomPhase) => {
@@ -24,6 +25,7 @@ export class ReconnectRefresher {
24
25
  }
25
26
 
26
27
  private onReconnected = () => {
28
+ log("onReconnected refresh reactors");
27
29
  this.releaseDisposers();
28
30
  this.reactors.forEach((func, id) => {
29
31
  if (isFunction(func)) {
@@ -63,7 +65,7 @@ export class ReconnectRefresher {
63
65
  }
64
66
 
65
67
  public destroy() {
66
- this.room.callbacks.off("onPhaseChanged", this.onPhaseChanged);
68
+ this.room?.callbacks.off("onPhaseChanged", this.onPhaseChanged);
67
69
  this.releaseDisposers();
68
70
  }
69
71
  }
@@ -1,7 +1,7 @@
1
+ import { emitter } from '../index';
1
2
  import { isPlayer } from 'white-web-sdk';
2
- import type { Camera, Room , Player } from "white-web-sdk";
3
+ import type { Camera, Room , Player , PlayerSeekingResult } from "white-web-sdk";
3
4
  import type { AppManager } from "../AppManager";
4
- import { emitter } from "../index";
5
5
 
6
6
  // 修改多窗口状态下一些失效的方法实现到 manager 的 mainview 上, 降低迁移成本
7
7
  export const replaceRoomFunction = (room: Room, manager: AppManager) => {
@@ -9,11 +9,14 @@ export const replaceRoomFunction = (room: Room, manager: AppManager) => {
9
9
  const player = room as unknown as Player;
10
10
  const originSeek = player.seekToProgressTime;
11
11
  // eslint-disable-next-line no-inner-declarations
12
- function newSeek(time: number) {
13
- originSeek.call(player, time);
14
- emitter.emit("seek", time);
12
+ async function newSeek(time: number): Promise<PlayerSeekingResult> {
13
+ const seekResult = await originSeek.call(player, time);
14
+ if (seekResult === "success") {
15
+ emitter.emit("seek", time);
16
+ }
17
+ return seekResult;
15
18
  }
16
- player.seekToProgressTime = newSeek as any;
19
+ player.seekToProgressTime = newSeek;
17
20
  } else {
18
21
  const descriptor = Object.getOwnPropertyDescriptor(room, "disableCameraTransform");
19
22
  if (descriptor) return;
package/src/index.ts CHANGED
@@ -128,6 +128,7 @@ type EmitterEvent = {
128
128
  snapshot: { appId: string, rect: any },
129
129
  error: Error,
130
130
  seek: number,
131
+ mainViewMounted: undefined,
131
132
  [TELE_BOX_STATE.Normal]: undefined,
132
133
  [TELE_BOX_STATE.Maximized]: undefined,
133
134
  [TELE_BOX_STATE.Minimized]: undefined,
@@ -466,9 +467,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
466
467
  * 设置 ViewMode
467
468
  */
468
469
  public setViewMode(mode: ViewMode): void {
470
+ if (!this.canOperate) return;
469
471
  if (mode === ViewMode.Broadcaster) {
470
472
  this.appManager?.delegate.setMainViewCamera({ ...this.mainView.camera, id: this.displayer.observerId });
471
- this.appManager?.delegate.setMainViewSize(this.mainView.size);
473
+ this.appManager?.delegate.setMainViewSize({ ...this.mainView.size, id: this.displayer.observerId });
472
474
  this.appManager?.mainViewProxy.start();
473
475
  }
474
476
  if (mode === ViewMode.Freedom) {
@@ -581,6 +583,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
581
583
  this.appManager.viewManager.switchMainViewToWriter();
582
584
  }
583
585
  this.appManager.viewManager.addMainViewListener();
586
+ emitter.emit("mainViewMounted");
584
587
  }
585
588
  }
586
589
 
package/src/sdk.ts CHANGED
@@ -7,7 +7,7 @@ import type { WhiteWebSdkConfiguration, JoinRoomParams } from "white-web-sdk";
7
7
 
8
8
  type WhiteWindowSDKConfiguration = Omit<WhiteWebSdkConfiguration, "useMobXState">
9
9
  type WindowJoinRoomParams = {
10
- joinRoomParams: Omit<JoinRoomParams, "useMultiViews">,
10
+ joinRoomParams: Omit<JoinRoomParams, "useMultiViews" | "disableMagixEventDispatchLimit">,
11
11
  mountParams: Omit<MountParams, "room">,
12
12
  }
13
13
 
@@ -24,6 +24,7 @@ export class WhiteWindowSDK {
24
24
  ...params.joinRoomParams,
25
25
  useMultiViews: true,
26
26
  invisiblePlugins: [...invisiblePlugins, WindowManager],
27
+ disableMagixEventDispatchLimit: true,
27
28
  });
28
29
  const manager = await WindowManager.mount({
29
30
  room,
package/src/typings.ts CHANGED
@@ -49,6 +49,7 @@ export type AppEmitterEvent<T = any> = {
49
49
  roomStateChange: Partial<DisplayerState>;
50
50
  focus: boolean;
51
51
  reconnected: void;
52
+ seek: number;
52
53
  };
53
54
 
54
55
  export type RegisterEventData = {