@netless/window-manager 0.4.73-beta.0 → 0.4.73
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/index.d.ts +1093 -40
- package/dist/index.js +15 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +266 -164
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -13
- package/src/App/AppContext.ts +13 -8
- package/src/App/AppProxy.ts +3 -8
- package/src/App/MagixEvent/index.ts +38 -38
- package/src/App/Storage/StorageEvent.ts +13 -13
- package/src/App/Storage/index.ts +265 -242
- package/src/App/Storage/typings.ts +4 -2
- package/src/App/Storage/utils.ts +3 -3
- package/src/AppListener.ts +5 -5
- package/src/AppManager.ts +6 -19
- package/src/AttributesDelegate.ts +5 -7
- package/src/BoxEmitter.ts +12 -6
- package/src/BoxManager.ts +1 -1
- package/src/ContainerResizeObserver.ts +1 -1
- package/src/Cursor/Cursor.svelte +3 -1
- package/src/Cursor/Cursor.ts +1 -0
- package/src/Cursor/index.ts +1 -1
- package/src/Helper.ts +67 -15
- package/src/InternalEmitter.ts +4 -3
- package/src/Page/index.ts +1 -1
- package/src/Register/index.ts +5 -7
- package/src/Register/loader.ts +1 -1
- package/src/Register/storage.ts +13 -13
- package/src/Utils/Common.ts +10 -5
- package/src/Utils/Reactive.ts +26 -25
- package/src/Utils/RoomHacker.ts +1 -1
- package/src/Utils/error.ts +0 -1
- package/src/View/IframeBridge.ts +627 -583
- package/src/View/MainView.ts +8 -6
- package/src/callback.ts +7 -1
- package/src/index.ts +34 -24
- package/src/typings.ts +11 -6
- package/dist/App/AppContext.d.ts +0 -79
- package/dist/App/AppPageStateImpl.d.ts +0 -17
- package/dist/App/AppProxy.d.ts +0 -67
- package/dist/App/MagixEvent/index.d.ts +0 -29
- package/dist/App/Storage/StorageEvent.d.ts +0 -8
- package/dist/App/Storage/index.d.ts +0 -39
- package/dist/App/Storage/typings.d.ts +0 -22
- package/dist/App/Storage/utils.d.ts +0 -5
- package/dist/App/index.d.ts +0 -2
- package/dist/AppListener.d.ts +0 -21
- package/dist/AppManager.d.ts +0 -110
- package/dist/AttributesDelegate.d.ts +0 -91
- package/dist/BoxEmitter.d.ts +0 -34
- package/dist/BoxManager.d.ts +0 -98
- package/dist/BuiltinApps.d.ts +0 -5
- package/dist/ContainerResizeObserver.d.ts +0 -11
- package/dist/Cursor/Cursor.d.ts +0 -43
- package/dist/Cursor/icons.d.ts +0 -3
- package/dist/Cursor/icons2.d.ts +0 -4
- package/dist/Cursor/index.d.ts +0 -55
- package/dist/Helper.d.ts +0 -11
- package/dist/InternalEmitter.d.ts +0 -34
- package/dist/Page/PageController.d.ts +0 -21
- package/dist/Page/index.d.ts +0 -3
- package/dist/PageState.d.ts +0 -9
- package/dist/ReconnectRefresher.d.ts +0 -24
- package/dist/RedoUndo.d.ts +0 -18
- package/dist/Register/index.d.ts +0 -28
- package/dist/Register/loader.d.ts +0 -4
- package/dist/Register/storage.d.ts +0 -8
- package/dist/Utils/AppCreateQueue.d.ts +0 -15
- package/dist/Utils/Common.d.ts +0 -22
- package/dist/Utils/Reactive.d.ts +0 -6
- package/dist/Utils/RoomHacker.d.ts +0 -3
- package/dist/Utils/error.d.ts +0 -27
- package/dist/Utils/log.d.ts +0 -1
- package/dist/View/IframeBridge.d.ts +0 -146
- package/dist/View/MainView.d.ts +0 -58
- package/dist/View/ViewManager.d.ts +0 -13
- package/dist/callback.d.ts +0 -38
- package/dist/constants.d.ts +0 -48
- package/dist/typings.d.ts +0 -84
package/src/AppManager.ts
CHANGED
@@ -384,9 +384,7 @@ export class AppManager {
|
|
384
384
|
x: payload.x,
|
385
385
|
y: payload.y,
|
386
386
|
});
|
387
|
-
|
388
|
-
callbacks.emit("onBoxMove", payload);
|
389
|
-
}
|
387
|
+
callbacks.emit("onBoxMove", payload);
|
390
388
|
};
|
391
389
|
|
392
390
|
private onBoxResize = (payload: BoxResizePayload) => {
|
@@ -396,18 +394,13 @@ export class AppManager {
|
|
396
394
|
width: payload.width,
|
397
395
|
height: payload.height,
|
398
396
|
});
|
399
|
-
|
400
|
-
callbacks.emit("onBoxResize", payload);
|
401
|
-
}
|
397
|
+
callbacks.emit("onBoxResize", payload);
|
402
398
|
}
|
403
399
|
};
|
404
400
|
|
405
401
|
private onBoxFocus = (payload: BoxFocusPayload) => {
|
406
402
|
this.windowManger.safeSetAttributes({ focus: payload.appId });
|
407
|
-
|
408
|
-
// (WindowManager.externalNotifyManager as any).emit('onBoxFocus', payload)
|
409
|
-
callbacks.emit("onBoxFocus", payload);
|
410
|
-
}
|
403
|
+
callbacks.emit("onBoxFocus", payload);
|
411
404
|
};
|
412
405
|
|
413
406
|
private onBoxClose = (payload: BoxClosePayload) => {
|
@@ -415,16 +408,12 @@ export class AppManager {
|
|
415
408
|
if (appProxy) {
|
416
409
|
appProxy.destroy(false, true, true, payload.error);
|
417
410
|
}
|
418
|
-
|
419
|
-
callbacks.emit("onBoxClose", payload);
|
420
|
-
}
|
411
|
+
callbacks.emit("onBoxClose", payload);
|
421
412
|
};
|
422
413
|
|
423
414
|
private onBoxStateChange = (payload: BoxStateChangePayload) => {
|
424
415
|
this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
|
425
|
-
|
426
|
-
callbacks.emit("onBoxStateChange", payload);
|
427
|
-
}
|
416
|
+
callbacks.emit("onBoxStateChange", payload);
|
428
417
|
};
|
429
418
|
|
430
419
|
public addAppsChangeListener = () => {
|
@@ -608,9 +597,7 @@ export class AppManager {
|
|
608
597
|
this.setMainViewFocusPath();
|
609
598
|
}
|
610
599
|
internalEmitter.emit("mainViewMounted");
|
611
|
-
|
612
|
-
callbacks.emit("onMainViewMounted", mainView);
|
613
|
-
}
|
600
|
+
callbacks.emit("onMainViewMounted", mainView);
|
614
601
|
}
|
615
602
|
|
616
603
|
public setMainViewFocusPath(scenePath?: string) {
|
@@ -38,14 +38,13 @@ export type StoreContext = {
|
|
38
38
|
getAttributes: () => any;
|
39
39
|
safeUpdateAttributes: (keys: string[], value: any) => void;
|
40
40
|
safeSetAttributes: (attributes: any) => void;
|
41
|
-
}
|
41
|
+
};
|
42
42
|
|
43
43
|
export type ICamera = Camera & { id: string };
|
44
44
|
|
45
45
|
export type ISize = Size & { id: string };
|
46
46
|
|
47
47
|
export class AttributesDelegate {
|
48
|
-
|
49
48
|
constructor(private context: StoreContext) {}
|
50
49
|
|
51
50
|
public setContext(context: StoreContext) {
|
@@ -181,7 +180,7 @@ export class AttributesDelegate {
|
|
181
180
|
} else {
|
182
181
|
this.context.safeSetAttributes({ [Fields.Focus]: undefined });
|
183
182
|
}
|
184
|
-
}
|
183
|
+
};
|
185
184
|
|
186
185
|
public updateCursor(uid: string, position: Position) {
|
187
186
|
if (!get(this.attributes, [Fields.Cursors])) {
|
@@ -250,15 +249,14 @@ export type Cursors = {
|
|
250
249
|
[key: string]: Cursor;
|
251
250
|
};
|
252
251
|
|
253
|
-
|
254
252
|
export const store = new AttributesDelegate({
|
255
253
|
getAttributes: () => {
|
256
|
-
throw new Error("getAttributes not implemented")
|
254
|
+
throw new Error("getAttributes not implemented");
|
257
255
|
},
|
258
256
|
safeSetAttributes: () => {
|
259
|
-
throw new Error("safeSetAttributes not implemented")
|
257
|
+
throw new Error("safeSetAttributes not implemented");
|
260
258
|
},
|
261
259
|
safeUpdateAttributes: () => {
|
262
|
-
throw new Error("safeUpdateAttributes not implemented")
|
260
|
+
throw new Error("safeUpdateAttributes not implemented");
|
263
261
|
},
|
264
262
|
});
|
package/src/BoxEmitter.ts
CHANGED
@@ -1,19 +1,25 @@
|
|
1
1
|
import type { TELE_BOX_STATE } from "@netless/telebox-insider";
|
2
2
|
import Emittery from "emittery";
|
3
3
|
|
4
|
-
export type BoxMovePayload = { appId: string
|
4
|
+
export type BoxMovePayload = { appId: string; x: number; y: number };
|
5
5
|
export type BoxFocusPayload = { appId: string };
|
6
|
-
export type BoxResizePayload = {
|
7
|
-
|
8
|
-
|
6
|
+
export type BoxResizePayload = {
|
7
|
+
appId: string;
|
8
|
+
width: number;
|
9
|
+
height: number;
|
10
|
+
x?: number;
|
11
|
+
y?: number;
|
12
|
+
};
|
13
|
+
export type BoxClosePayload = { appId: string; error?: Error };
|
14
|
+
export type BoxStateChangePayload = { appId: string; state: TELE_BOX_STATE };
|
9
15
|
|
10
16
|
export type BoxEvent = {
|
11
17
|
move: BoxMovePayload;
|
12
18
|
focus: BoxFocusPayload;
|
13
19
|
resize: BoxResizePayload;
|
14
20
|
close: BoxClosePayload;
|
15
|
-
boxStateChange: BoxStateChangePayload
|
16
|
-
}
|
21
|
+
boxStateChange: BoxStateChangePayload;
|
22
|
+
};
|
17
23
|
|
18
24
|
export type BoxEmitterType = Emittery<BoxEvent>;
|
19
25
|
export const boxEmitter: BoxEmitterType = new Emittery();
|
package/src/BoxManager.ts
CHANGED
package/src/Cursor/Cursor.svelte
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
import { isEmpty } from "lodash";
|
3
3
|
import { ApplianceNames } from "white-web-sdk";
|
4
4
|
|
5
|
+
export let uid: string;
|
5
6
|
export let cursorName: string;
|
6
7
|
export let tagName: string | undefined;
|
7
8
|
export let backgroundColor: string;
|
@@ -21,7 +22,7 @@
|
|
21
22
|
$: hasName = !isEmpty(cursorName);
|
22
23
|
$: hasTagName = !isEmpty(tagName);
|
23
24
|
$: hasAvatar = !isEmpty(avatar);
|
24
|
-
$: display = visible ? "
|
25
|
+
$: display = visible ? "" : "none";
|
25
26
|
$: isLaserPointer = appliance === ApplianceNames.laserPointer;
|
26
27
|
$: isLaserPointerPencilEraser = isLaserPointer || appliance === ApplianceNames.pencilEraser;
|
27
28
|
$: offset = isLaserPointerPencilEraser ? "netless-window-manager-laserPointer-pencilEraser-offset" : "";
|
@@ -43,6 +44,7 @@
|
|
43
44
|
<div
|
44
45
|
class={"netless-window-manager-cursor-mid" + (custom ? " netless-window-manager-cursor-custom" : "")}
|
45
46
|
style="transform: translateX({x}px) translateY({y}px);display: {display}"
|
47
|
+
data-cursor-uid={uid}
|
46
48
|
>
|
47
49
|
{#if !isLaserPointer}
|
48
50
|
<div class="netless-window-manager-cursor-name {offset} {pencilEraserSize3ImageOffset}">
|
package/src/Cursor/Cursor.ts
CHANGED
package/src/Cursor/index.ts
CHANGED
@@ -169,7 +169,7 @@ export class CursorManager {
|
|
169
169
|
if (now - this.mouseMoveTimer > 48) {
|
170
170
|
this.mouseMoveTimer = now;
|
171
171
|
if (
|
172
|
-
WindowManager.
|
172
|
+
WindowManager.supportAppliancePlugin &&
|
173
173
|
isRoom(WindowManager.displayer) &&
|
174
174
|
(WindowManager.displayer as Room).disableDeviceInputs
|
175
175
|
) {
|
package/src/Helper.ts
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
import
|
2
|
-
import { log } from "./Utils/log";
|
3
|
-
import { REQUIRE_VERSION } from "./constants";
|
1
|
+
import pRetry from "p-retry";
|
4
2
|
import type { Room, RoomMember } from "white-web-sdk";
|
5
3
|
import { WhiteVersion } from "white-web-sdk";
|
6
|
-
import {
|
4
|
+
import { REQUIRE_VERSION } from "./constants";
|
7
5
|
import { WindowManager } from "./index";
|
6
|
+
import { getVersionNumber } from "./Utils/Common";
|
7
|
+
import { WhiteWebSDKInvalidError } from "./Utils/error";
|
8
|
+
import { log } from "./Utils/log";
|
8
9
|
|
9
10
|
export const setupWrapper = (
|
10
11
|
root: HTMLElement
|
@@ -53,19 +54,70 @@ export const findMemberByUid = (room: Room | undefined, uid: string) => {
|
|
53
54
|
}
|
54
55
|
}
|
55
56
|
return result;
|
56
|
-
}
|
57
|
+
};
|
58
|
+
|
59
|
+
export const createInvisiblePlugin = async (room: Room): Promise<WindowManager> => {
|
60
|
+
let manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager;
|
61
|
+
if (manager) return manager;
|
57
62
|
|
58
|
-
|
63
|
+
let resolve!: (manager: WindowManager) => void;
|
64
|
+
const promise = new Promise<WindowManager>(r => {
|
65
|
+
// @ts-expect-error Set private property.
|
66
|
+
WindowManager._resolve = resolve = r;
|
67
|
+
});
|
68
|
+
|
69
|
+
let wasReadonly = false;
|
70
|
+
const canOperate = isRoomTokenWritable(room);
|
71
|
+
if (!room.isWritable && canOperate) {
|
72
|
+
wasReadonly = true;
|
73
|
+
await pRetry(
|
74
|
+
async count => {
|
75
|
+
log(`switching to writable (x${count})`);
|
76
|
+
await room.setWritable(true);
|
77
|
+
},
|
78
|
+
{ retries: 10, maxTimeout: 5000 }
|
79
|
+
);
|
80
|
+
}
|
81
|
+
if (room.isWritable) {
|
82
|
+
log("creating InvisiblePlugin...");
|
83
|
+
room.createInvisiblePlugin(WindowManager, {}).catch(console.warn);
|
84
|
+
} else {
|
85
|
+
if (canOperate) console.warn("[WindowManager]: failed to switch to writable");
|
86
|
+
console.warn("[WindowManager]: waiting for others to create the plugin...");
|
87
|
+
}
|
88
|
+
|
89
|
+
const timeout = setTimeout(() => {
|
90
|
+
console.warn("[WindowManager]: no one called createInvisiblePlugin() after 20 seconds");
|
91
|
+
}, 20_000);
|
92
|
+
|
93
|
+
const abort = setTimeout(() => {
|
94
|
+
throw new Error("[WindowManager]: no one called createInvisiblePlugin() after 60 seconds");
|
95
|
+
}, 60_000);
|
96
|
+
|
97
|
+
const interval = setInterval(() => {
|
98
|
+
manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager;
|
99
|
+
if (manager) {
|
100
|
+
clearTimeout(abort);
|
101
|
+
clearTimeout(timeout);
|
102
|
+
clearInterval(interval);
|
103
|
+
resolve(manager);
|
104
|
+
if (wasReadonly && room.isWritable) {
|
105
|
+
setTimeout(() => room.setWritable(false).catch(console.warn), 500);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}, 200);
|
109
|
+
|
110
|
+
return promise;
|
111
|
+
};
|
112
|
+
|
113
|
+
const isRoomTokenWritable = (room: Room) => {
|
59
114
|
try {
|
60
|
-
const
|
61
|
-
|
115
|
+
const str = atob(room.roomToken.slice("NETLESSROOM_".length));
|
116
|
+
const index = str.indexOf("&role=");
|
117
|
+
const role = +str[index + "&role=".length];
|
118
|
+
return role < 2;
|
62
119
|
} catch (error) {
|
63
|
-
|
64
|
-
|
65
|
-
await wait(200);
|
66
|
-
return room.getInvisiblePlugin(WindowManager.kind) as WindowManager;
|
67
|
-
} else {
|
68
|
-
log("createInvisiblePlugin failed", error);
|
69
|
-
}
|
120
|
+
console.error(error);
|
121
|
+
return false;
|
70
122
|
}
|
71
123
|
};
|
package/src/InternalEmitter.ts
CHANGED
@@ -2,8 +2,9 @@ import Emittery from "emittery";
|
|
2
2
|
import type { AppInitState, CursorMovePayload } from "./index";
|
3
3
|
|
4
4
|
export type RemoveSceneParams = {
|
5
|
-
scenePath: string
|
6
|
-
|
5
|
+
scenePath: string;
|
6
|
+
index?: number;
|
7
|
+
};
|
7
8
|
|
8
9
|
export type EmitterEvent = {
|
9
10
|
onCreated: undefined;
|
@@ -21,7 +22,7 @@ export type EmitterEvent = {
|
|
21
22
|
cursorMove: CursorMovePayload;
|
22
23
|
updateManagerRect: undefined;
|
23
24
|
focusedChange: { focused: string | undefined; prev: string | undefined };
|
24
|
-
rootDirRemoved: undefined;
|
25
|
+
rootDirRemoved: undefined; // 根目录整个被删除
|
25
26
|
rootDirSceneRemoved: string; // 根目录下的场景被删除
|
26
27
|
setReadonly: boolean;
|
27
28
|
changePageState: undefined;
|
package/src/Page/index.ts
CHANGED
package/src/Register/index.ts
CHANGED
@@ -8,7 +8,7 @@ export type LoadAppEvent = {
|
|
8
8
|
reason?: string;
|
9
9
|
};
|
10
10
|
|
11
|
-
export type SyncRegisterAppPayload =
|
11
|
+
export type SyncRegisterAppPayload = { kind: string; src: string; name: string | undefined };
|
12
12
|
export type SyncRegisterApp = (payload: SyncRegisterAppPayload) => void;
|
13
13
|
|
14
14
|
class AppRegister {
|
@@ -25,7 +25,7 @@ class AppRegister {
|
|
25
25
|
|
26
26
|
public onSyncRegisterAppChange = (payload: SyncRegisterAppPayload) => {
|
27
27
|
this.register({ kind: payload.kind, src: payload.src });
|
28
|
-
}
|
28
|
+
};
|
29
29
|
|
30
30
|
public async register(params: RegisterParams): Promise<void> {
|
31
31
|
this.appClassesCache.delete(params.kind);
|
@@ -36,7 +36,7 @@ class AppRegister {
|
|
36
36
|
|
37
37
|
if (typeof paramSrc === "string") {
|
38
38
|
downloadApp = async () => {
|
39
|
-
const result = await loadApp(paramSrc, params.kind, params.name) as any;
|
39
|
+
const result = (await loadApp(paramSrc, params.kind, params.name)) as any;
|
40
40
|
if (result.__esModule) {
|
41
41
|
return result.default;
|
42
42
|
}
|
@@ -48,16 +48,14 @@ class AppRegister {
|
|
48
48
|
}
|
49
49
|
if (typeof paramSrc === "function") {
|
50
50
|
downloadApp = async () => {
|
51
|
-
let appClass = await paramSrc() as any;
|
51
|
+
let appClass = (await paramSrc()) as any;
|
52
52
|
if (appClass) {
|
53
53
|
if (appClass.__esModule || appClass.default) {
|
54
54
|
appClass = appClass.default;
|
55
55
|
}
|
56
56
|
return appClass;
|
57
57
|
} else {
|
58
|
-
throw new Error(
|
59
|
-
`[WindowManager]: load remote script failed, ${paramSrc}`
|
60
|
-
);
|
58
|
+
throw new Error(`[WindowManager]: load remote script failed, ${paramSrc}`);
|
61
59
|
}
|
62
60
|
};
|
63
61
|
}
|
package/src/Register/loader.ts
CHANGED
@@ -66,7 +66,7 @@ const getResult = (text: string, appName: string, key: string): NetlessApp => {
|
|
66
66
|
callbacks.emit("loadApp", { kind: key, status: "failed", reason: error.message });
|
67
67
|
throw error;
|
68
68
|
}
|
69
|
-
}
|
69
|
+
};
|
70
70
|
|
71
71
|
async function fetchWithTimeout(resource: string, options: RequestInit & { timeout: number }) {
|
72
72
|
const { timeout = 10000 } = options;
|
package/src/Register/storage.ts
CHANGED
@@ -6,15 +6,15 @@ let store: IDBObjectStore;
|
|
6
6
|
export type Item = {
|
7
7
|
kind: string;
|
8
8
|
sourceCode: string;
|
9
|
-
}
|
9
|
+
};
|
10
10
|
|
11
11
|
export const initDb = async () => {
|
12
12
|
db = await createDb();
|
13
|
-
}
|
13
|
+
};
|
14
14
|
|
15
15
|
export const setItem = (key: string, val: any) => {
|
16
16
|
if (!db) return;
|
17
|
-
return addRecord(db, { kind: key, sourceCode: val })
|
17
|
+
return addRecord(db, { kind: key, sourceCode: val });
|
18
18
|
};
|
19
19
|
|
20
20
|
export const getItem = async (key: string): Promise<Item | null> => {
|
@@ -30,9 +30,9 @@ export const removeItem = (key: string) => {
|
|
30
30
|
function createDb(): Promise<IDBDatabase> {
|
31
31
|
return new Promise((resolve, reject) => {
|
32
32
|
const request = indexedDB.open(DatabaseName, 2);
|
33
|
-
request.onerror =
|
33
|
+
request.onerror = e => {
|
34
34
|
reject(e);
|
35
|
-
}
|
35
|
+
};
|
36
36
|
|
37
37
|
request.onupgradeneeded = (event: any) => {
|
38
38
|
const db = event.target.result as IDBDatabase;
|
@@ -40,28 +40,28 @@ function createDb(): Promise<IDBDatabase> {
|
|
40
40
|
store = db.createObjectStore("apps", { keyPath: "kind" });
|
41
41
|
store.createIndex("kind", "kind", { unique: true });
|
42
42
|
}
|
43
|
-
}
|
43
|
+
};
|
44
44
|
|
45
45
|
request.onsuccess = () => {
|
46
46
|
const db = request.result;
|
47
47
|
resolve(db);
|
48
|
-
}
|
49
|
-
})
|
48
|
+
};
|
49
|
+
});
|
50
50
|
}
|
51
51
|
|
52
52
|
function query<T>(db: IDBDatabase, val: string): Promise<T | null> {
|
53
53
|
return new Promise((resolve, reject) => {
|
54
54
|
const index = db.transaction(["apps"]).objectStore("apps").index("kind");
|
55
55
|
const request = index.get(val);
|
56
|
-
request.onerror =
|
56
|
+
request.onerror = e => reject(e);
|
57
57
|
request.onsuccess = () => {
|
58
58
|
if (request.result) {
|
59
59
|
resolve(request.result);
|
60
60
|
} else {
|
61
61
|
resolve(null);
|
62
62
|
}
|
63
|
-
}
|
64
|
-
})
|
63
|
+
};
|
64
|
+
});
|
65
65
|
}
|
66
66
|
|
67
67
|
function addRecord(db: IDBDatabase, payload: any): Promise<void> {
|
@@ -69,7 +69,7 @@ function addRecord(db: IDBDatabase, payload: any): Promise<void> {
|
|
69
69
|
const request = db.transaction(["apps"], "readwrite").objectStore("apps").add(payload);
|
70
70
|
request.onsuccess = () => resolve();
|
71
71
|
request.onerror = () => reject();
|
72
|
-
})
|
72
|
+
});
|
73
73
|
}
|
74
74
|
|
75
75
|
function deleteRecord(db: IDBDatabase, key: string): Promise<void> {
|
@@ -77,5 +77,5 @@ function deleteRecord(db: IDBDatabase, key: string): Promise<void> {
|
|
77
77
|
const request = db.transaction(["apps"], "readwrite").objectStore("apps").delete(key);
|
78
78
|
request.onsuccess = () => resolve();
|
79
79
|
request.onerror = () => reject();
|
80
|
-
})
|
80
|
+
});
|
81
81
|
}
|
package/src/Utils/Common.ts
CHANGED
@@ -5,7 +5,7 @@ import { ROOT_DIR } from "../constants";
|
|
5
5
|
import { ScenePathType } from "white-web-sdk";
|
6
6
|
import { v4 } from "uuid";
|
7
7
|
import type { PublicEvent } from "../callback";
|
8
|
-
import type { Displayer, ViewVisionMode, Room, View
|
8
|
+
import type { Displayer, ViewVisionMode, Room, View, SceneDefinition } from "white-web-sdk";
|
9
9
|
import type Emittery from "emittery";
|
10
10
|
|
11
11
|
export const genAppId = async (kind: string) => {
|
@@ -104,14 +104,19 @@ export const entireScenes = (displayer: Displayer) => {
|
|
104
104
|
return displayer.entireScenes();
|
105
105
|
};
|
106
106
|
|
107
|
-
export const putScenes = (
|
107
|
+
export const putScenes = (
|
108
|
+
room: Room | undefined,
|
109
|
+
path: string,
|
110
|
+
scenes: SceneDefinition[],
|
111
|
+
index?: number
|
112
|
+
) => {
|
108
113
|
for (let i = 0; i < scenes.length; ++i) {
|
109
|
-
if (scenes[i].name?.includes(
|
114
|
+
if (scenes[i].name?.includes("/")) {
|
110
115
|
throw new Error("scenes name can not have '/'");
|
111
116
|
}
|
112
117
|
}
|
113
118
|
return room?.putScenes(path, scenes, index);
|
114
|
-
}
|
119
|
+
};
|
115
120
|
|
116
121
|
export const isValidScenePath = (scenePath: string) => {
|
117
122
|
return scenePath.startsWith("/");
|
@@ -156,4 +161,4 @@ export const isRootDirPage = (scenePath: string) => {
|
|
156
161
|
return prev;
|
157
162
|
}, 0);
|
158
163
|
return delimiterCount === 1;
|
159
|
-
}
|
164
|
+
};
|
package/src/Utils/Reactive.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { listenUpdated, unlistenUpdated, reaction, UpdateEventKind } from "white-web-sdk";
|
2
|
-
import type { AkkoObjectUpdatedProperty
|
2
|
+
import type { AkkoObjectUpdatedProperty, AkkoObjectUpdatedListener } from "white-web-sdk";
|
3
3
|
import { isObject } from "lodash";
|
4
4
|
|
5
5
|
// 兼容 13 和 14 版本 SDK
|
@@ -12,7 +12,7 @@ export const onObjectByEvent = (event: UpdateEventKind) => {
|
|
12
12
|
if (kinds.includes(event)) {
|
13
13
|
func();
|
14
14
|
}
|
15
|
-
}
|
15
|
+
};
|
16
16
|
listenUpdated(object, listener);
|
17
17
|
func();
|
18
18
|
return () => unlistenUpdated(object, listener);
|
@@ -21,43 +21,44 @@ export const onObjectByEvent = (event: UpdateEventKind) => {
|
|
21
21
|
() => object,
|
22
22
|
() => {
|
23
23
|
func();
|
24
|
-
},
|
24
|
+
},
|
25
|
+
{
|
25
26
|
fireImmediately: true,
|
26
27
|
}
|
27
|
-
)
|
28
|
+
);
|
28
29
|
}
|
29
|
-
}
|
30
|
-
}
|
30
|
+
};
|
31
|
+
};
|
31
32
|
|
32
33
|
export const safeListenPropsUpdated = <T>(
|
33
34
|
getProps: () => T,
|
34
35
|
callback: AkkoObjectUpdatedListener<T>,
|
35
36
|
onDestroyed?: (props: unknown) => void
|
36
|
-
|
37
|
+
) => {
|
37
38
|
let disposeListenUpdated: (() => void) | null = null;
|
38
39
|
const disposeReaction = reaction(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
40
|
+
getProps,
|
41
|
+
() => {
|
42
|
+
if (disposeListenUpdated) {
|
43
|
+
disposeListenUpdated();
|
44
|
+
disposeListenUpdated = null;
|
45
|
+
}
|
46
|
+
const props = getProps();
|
47
|
+
if (isObject(props)) {
|
48
|
+
disposeListenUpdated = () => unlistenUpdated(props, callback);
|
49
|
+
listenUpdated(props, callback);
|
50
|
+
} else {
|
51
|
+
onDestroyed?.(props);
|
52
|
+
}
|
53
|
+
},
|
54
|
+
{ fireImmediately: true }
|
54
55
|
);
|
55
56
|
|
56
57
|
return () => {
|
57
|
-
|
58
|
-
|
58
|
+
disposeListenUpdated?.();
|
59
|
+
disposeReaction();
|
59
60
|
};
|
60
|
-
}
|
61
|
+
};
|
61
62
|
|
62
63
|
export const onObjectRemoved = onObjectByEvent(UpdateEventKind.Removed);
|
63
64
|
export const onObjectInserted = onObjectByEvent(UpdateEventKind.Inserted);
|
package/src/Utils/RoomHacker.ts
CHANGED
@@ -78,7 +78,7 @@ const delegateSeekToProgressTime = (player: Player) => {
|
|
78
78
|
// seek 时需要先关闭所有的 app 防止内部使用的 mobx 出现错误
|
79
79
|
await internalEmitter.emit("seekStart");
|
80
80
|
const seekResult = await originSeek.call(player, time);
|
81
|
-
internalEmitter.emit("seek", time);
|
81
|
+
internalEmitter.emit("seek", time);
|
82
82
|
return seekResult;
|
83
83
|
}
|
84
84
|
player.seekToProgressTime = newSeek;
|
package/src/Utils/error.ts
CHANGED