@netless/window-manager 0.4.32 → 0.4.33
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/Helper.d.ts +2 -0
- package/dist/index.cjs.js +12 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +26 -8
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +12 -12
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/Helper.ts +17 -1
- package/src/ReconnectRefresher.ts +9 -3
- package/src/index.ts +6 -12
package/package.json
CHANGED
package/src/Helper.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import { getVersionNumber } from "./Utils/Common";
|
1
|
+
import { getVersionNumber, wait } from "./Utils/Common";
|
2
|
+
import { log } from "./Utils/log";
|
2
3
|
import { REQUIRE_VERSION } from "./constants";
|
3
4
|
import { WhiteVersion } from "white-web-sdk";
|
4
5
|
import { WhiteWebSDKInvalidError } from "./Utils/error";
|
@@ -45,3 +46,18 @@ export const findMemberByUid = (room: Room | undefined, uid: string) => {
|
|
45
46
|
const roomMembers = room?.state.roomMembers;
|
46
47
|
return roomMembers?.find(member => member.payload?.uid === uid);
|
47
48
|
};
|
49
|
+
|
50
|
+
export const createInvisiblePlugin = async (room: Room) => {
|
51
|
+
try {
|
52
|
+
const manager = (await room.createInvisiblePlugin(WindowManager, {})) as WindowManager;
|
53
|
+
return manager;
|
54
|
+
} catch (error) {
|
55
|
+
// 如果有两个用户同时调用 WindowManager.mount 有概率出现这个错误
|
56
|
+
if (error.message === `invisible plugin "WindowManager" exits`) {
|
57
|
+
await wait(200);
|
58
|
+
return room.getInvisiblePlugin(WindowManager.kind) as WindowManager;
|
59
|
+
} else {
|
60
|
+
log("createInvisiblePlugin failed", error);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
};
|
@@ -4,6 +4,7 @@ import { RoomPhase } from "white-web-sdk";
|
|
4
4
|
import type { Room } from "white-web-sdk";
|
5
5
|
import type { EmitterType } from "./InternalEmitter";
|
6
6
|
import { EnsureReconnectEvent } from "./constants";
|
7
|
+
import { wait } from "./Utils/Common";
|
7
8
|
|
8
9
|
export type ReconnectRefresherContext = {
|
9
10
|
emitter: EmitterType;
|
@@ -41,19 +42,24 @@ export class ReconnectRefresher {
|
|
41
42
|
this.ctx = ctx;
|
42
43
|
}
|
43
44
|
|
44
|
-
private onPhaseChanged = (phase: RoomPhase) => {
|
45
|
+
private onPhaseChanged = async (phase: RoomPhase) => {
|
45
46
|
if (phase === RoomPhase.Reconnecting) {
|
46
47
|
this.ctx.emitter.emit("startReconnect");
|
47
48
|
}
|
48
49
|
if (phase === RoomPhase.Connected && this.phase === RoomPhase.Reconnecting) {
|
49
|
-
this.room?.
|
50
|
+
if (this.room?.isWritable) {
|
51
|
+
this.room?.dispatchMagixEvent(EnsureReconnectEvent, {});
|
52
|
+
} else {
|
53
|
+
await wait(500);
|
54
|
+
this.onReconnected();
|
55
|
+
}
|
50
56
|
}
|
51
57
|
this.phase = phase;
|
52
58
|
};
|
53
59
|
|
54
60
|
private onReconnected = debounce(() => {
|
55
61
|
this._onReconnected();
|
56
|
-
},
|
62
|
+
}, 1000);
|
57
63
|
|
58
64
|
private _onReconnected = () => {
|
59
65
|
log("onReconnected refresh reactors");
|
package/src/index.ts
CHANGED
@@ -2,7 +2,7 @@ import pRetry from "p-retry";
|
|
2
2
|
import { AppManager } from "./AppManager";
|
3
3
|
import { appRegister } from "./Register";
|
4
4
|
import { callbacks } from "./callback";
|
5
|
-
import { checkVersion, setupWrapper } from "./Helper";
|
5
|
+
import { checkVersion, createInvisiblePlugin, setupWrapper } from "./Helper";
|
6
6
|
import { ContainerResizeObserver } from "./ContainerResizeObserver";
|
7
7
|
import { createBoxManager } from "./BoxManager";
|
8
8
|
import { CursorManager } from "./Cursor";
|
@@ -254,8 +254,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
254
254
|
return manager;
|
255
255
|
}
|
256
256
|
|
257
|
-
private static async initManager(room: Room): Promise<WindowManager> {
|
258
|
-
let manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager;
|
257
|
+
private static async initManager(room: Room): Promise<WindowManager | undefined> {
|
258
|
+
let manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager | undefined;
|
259
259
|
if (!manager) {
|
260
260
|
if (isRoom(room)) {
|
261
261
|
if (room.isWritable === false) {
|
@@ -264,18 +264,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
264
264
|
} catch (error) {
|
265
265
|
throw new Error("[WindowManger]: room must be switched to be writable");
|
266
266
|
}
|
267
|
-
manager =
|
268
|
-
|
269
|
-
{}
|
270
|
-
)) as WindowManager;
|
271
|
-
manager.ensureAttributes();
|
267
|
+
manager = await createInvisiblePlugin(room);
|
268
|
+
manager?.ensureAttributes();
|
272
269
|
await wait(500);
|
273
270
|
await room.setWritable(false);
|
274
271
|
} else {
|
275
|
-
manager =
|
276
|
-
WindowManager,
|
277
|
-
{}
|
278
|
-
)) as WindowManager;
|
272
|
+
manager = await createInvisiblePlugin(room);
|
279
273
|
}
|
280
274
|
}
|
281
275
|
}
|