floating-live 0.17.0-alpha.6 → 0.17.0-alpha.8
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/event/types.d.ts +2 -3
- package/dist/plugin/index.d.ts +2 -0
- package/dist/plugin/index.js +4 -0
- package/dist/plugin/manager.d.ts +2 -2
- package/dist/plugin/manager.js +24 -10
- package/dist/plugin/types.d.ts +10 -2
- package/dist/plugins/room/index.d.ts +2 -2
- package/dist/plugins/room/index.js +3 -1
- package/package.json +1 -1
package/dist/event/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PluginInfo } from "../plugin/index.js";
|
|
1
2
|
export interface AppEventEmitOptions {
|
|
2
3
|
/** 事件来源 */
|
|
3
4
|
source?: string;
|
|
@@ -19,9 +20,7 @@ export interface AppEventDetailMap {
|
|
|
19
20
|
"command:unregister": {
|
|
20
21
|
name: string;
|
|
21
22
|
};
|
|
22
|
-
"plugin:register":
|
|
23
|
-
pluginName: string;
|
|
24
|
-
};
|
|
23
|
+
"plugin:register": PluginInfo;
|
|
25
24
|
"plugin:unregister": {
|
|
26
25
|
pluginName: string;
|
|
27
26
|
};
|
package/dist/plugin/index.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import type { PluginItem, PluginContext } from "./types.js";
|
|
|
2
2
|
export type * from "./types.js";
|
|
3
3
|
export declare class BasePlugin implements PluginItem {
|
|
4
4
|
static pluginName: string;
|
|
5
|
+
static role?: string;
|
|
5
6
|
get pluginName(): string;
|
|
7
|
+
get role(): string | undefined;
|
|
6
8
|
ctx: PluginContext;
|
|
7
9
|
constructor(ctx: PluginContext, options?: any);
|
|
8
10
|
}
|
package/dist/plugin/index.js
CHANGED
package/dist/plugin/manager.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ export declare class PluginManager {
|
|
|
6
6
|
private whenRegisterMap;
|
|
7
7
|
protected readonly app: App;
|
|
8
8
|
constructor(app: App);
|
|
9
|
-
registerSync<P extends PluginItem>(pluginConstructor: PluginConstructor<P>, options?: Record<string, any>, { context,
|
|
9
|
+
registerSync<P extends PluginItem>(pluginConstructor: PluginConstructor<P>, options?: Record<string, any>, { context, unremovable, accessApp, pluginType, }?: PluginRegisterOptions): P;
|
|
10
10
|
/** 注册插件 */
|
|
11
|
-
register<P extends PluginItem>(pluginConstructor: PluginConstructor<P>, options?: Record<string, any>, { context,
|
|
11
|
+
register<P extends PluginItem>(pluginConstructor: PluginConstructor<P>, options?: Record<string, any>, { context, unremovable, accessApp, pluginType, }?: PluginRegisterOptions): Promise<P>;
|
|
12
12
|
/** 移除插件 */
|
|
13
13
|
unregister(pluginName: string): Promise<void>;
|
|
14
14
|
/** 获取插件实例 */
|
package/dist/plugin/manager.js
CHANGED
|
@@ -10,8 +10,9 @@ export class PluginManager {
|
|
|
10
10
|
this.app = app;
|
|
11
11
|
app.registerCommand("plugin.snapshot", bindCommand(this.toSnapshot, this));
|
|
12
12
|
}
|
|
13
|
-
registerSync(pluginConstructor, options = {}, { context,
|
|
13
|
+
registerSync(pluginConstructor, options = {}, { context, unremovable = false, accessApp = false, pluginType = "", } = {}) {
|
|
14
14
|
const pluginName = pluginConstructor.pluginName;
|
|
15
|
+
const role = pluginConstructor.role || "";
|
|
15
16
|
if (!pluginName) {
|
|
16
17
|
throw appError("plugin:register_id_missing", {
|
|
17
18
|
message: "插件注册失败",
|
|
@@ -47,11 +48,17 @@ export class PluginManager {
|
|
|
47
48
|
plugin,
|
|
48
49
|
context: pluginCtx,
|
|
49
50
|
exposes,
|
|
50
|
-
unremovable:
|
|
51
|
-
accessApp:
|
|
52
|
-
pluginType:
|
|
51
|
+
unremovable: unremovable || false,
|
|
52
|
+
accessApp: accessApp || false,
|
|
53
|
+
pluginType: pluginType || "",
|
|
54
|
+
});
|
|
55
|
+
this.app.emit("plugin:register", {
|
|
56
|
+
pluginName,
|
|
57
|
+
role,
|
|
58
|
+
unremovable,
|
|
59
|
+
accessApp,
|
|
60
|
+
pluginType,
|
|
53
61
|
});
|
|
54
|
-
this.app.emit("plugin:register", { pluginName });
|
|
55
62
|
// 如果有whenRegister的回调,调用回调函数
|
|
56
63
|
const callbackMap = this.whenRegisterMap.get(pluginName);
|
|
57
64
|
if (callbackMap) {
|
|
@@ -71,8 +78,9 @@ export class PluginManager {
|
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
80
|
/** 注册插件 */
|
|
74
|
-
async register(pluginConstructor, options = {}, { context,
|
|
81
|
+
async register(pluginConstructor, options = {}, { context, unremovable = false, accessApp = false, pluginType = "", } = {}) {
|
|
75
82
|
const pluginName = pluginConstructor.pluginName;
|
|
83
|
+
const role = pluginConstructor.role || "";
|
|
76
84
|
if (!pluginName) {
|
|
77
85
|
throw appError("plugin:register_id_missing", {
|
|
78
86
|
message: "插件注册失败",
|
|
@@ -108,11 +116,17 @@ export class PluginManager {
|
|
|
108
116
|
plugin,
|
|
109
117
|
context: pluginCtx,
|
|
110
118
|
exposes,
|
|
111
|
-
unremovable:
|
|
112
|
-
accessApp:
|
|
113
|
-
pluginType:
|
|
119
|
+
unremovable: unremovable,
|
|
120
|
+
accessApp: accessApp,
|
|
121
|
+
pluginType: pluginType,
|
|
122
|
+
});
|
|
123
|
+
this.app.emit("plugin:register", {
|
|
124
|
+
pluginName,
|
|
125
|
+
role,
|
|
126
|
+
unremovable,
|
|
127
|
+
accessApp,
|
|
128
|
+
pluginType,
|
|
114
129
|
});
|
|
115
|
-
this.app.emit("plugin:register", { pluginName });
|
|
116
130
|
// 如果有whenRegister的回调,调用回调函数
|
|
117
131
|
const callbackMap = this.whenRegisterMap.get(pluginName);
|
|
118
132
|
if (callbackMap) {
|
package/dist/plugin/types.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface PluginItem {
|
|
|
24
24
|
/** 插件构造器 */
|
|
25
25
|
export interface PluginConstructor<P extends PluginItem> {
|
|
26
26
|
pluginName: string;
|
|
27
|
+
role?: string;
|
|
27
28
|
new (ctx: PluginContext, options: any): P;
|
|
28
29
|
}
|
|
29
30
|
/** 插件初始化选项 */
|
|
@@ -33,8 +34,6 @@ export interface PluginInitOptions {
|
|
|
33
34
|
export interface PluginRegisterOptions {
|
|
34
35
|
/** 提供的插件上下文 */
|
|
35
36
|
context?: PluginContext;
|
|
36
|
-
/** 核心插件,不可解除注册 @deprecated */
|
|
37
|
-
core?: boolean;
|
|
38
37
|
/** 不可注销 */
|
|
39
38
|
unremovable?: boolean;
|
|
40
39
|
/** 可访问App实例 */
|
|
@@ -52,6 +51,15 @@ export interface PluginData<T> {
|
|
|
52
51
|
/** 插件类型 */
|
|
53
52
|
pluginType: "core" | "framework" | "";
|
|
54
53
|
}
|
|
54
|
+
export interface PluginInfo {
|
|
55
|
+
pluginName: string;
|
|
56
|
+
role: string;
|
|
57
|
+
unremovable: boolean;
|
|
58
|
+
/** 可访问App实例 */
|
|
59
|
+
accessApp: boolean;
|
|
60
|
+
/** 插件类型 */
|
|
61
|
+
pluginType: "core" | "framework" | "";
|
|
62
|
+
}
|
|
55
63
|
/** 插件上下文 */
|
|
56
64
|
export interface PluginContext {
|
|
57
65
|
/** 安全插件上下文 */
|
|
@@ -8,7 +8,7 @@ export interface RoomCreateOptions {
|
|
|
8
8
|
[option: string]: any;
|
|
9
9
|
}
|
|
10
10
|
interface PluginExposes {
|
|
11
|
-
add(platform: string, id: number, options?: boolean | RoomCreateOptions): void
|
|
11
|
+
add(platform: string, id: number, options?: boolean | RoomCreateOptions): Promise<void>;
|
|
12
12
|
remove(key: string): void;
|
|
13
13
|
get(key: string): LiveRoom | InvalidLiveRoom | undefined;
|
|
14
14
|
has(key: string): boolean;
|
|
@@ -27,7 +27,7 @@ declare module "../../index.js" {
|
|
|
27
27
|
close: (key: string) => void;
|
|
28
28
|
update: (key: string) => void;
|
|
29
29
|
"room.snapshot": () => LiveRoomData[];
|
|
30
|
-
"room.validate": (key: string) => void;
|
|
30
|
+
"room.validate": (key: string, options: RoomCreateOptions) => void;
|
|
31
31
|
"room.invalidate": (key: string) => void;
|
|
32
32
|
[name: `${string}.room.create`]: (id: string | number, options: RoomCreateOptions) => LiveRoom | Promise<LiveRoom>;
|
|
33
33
|
[name: `${string}.room.data`]: (id: string | number) => LiveRoomData | Promise<LiveRoomData>;
|
|
@@ -17,6 +17,8 @@ export class Room extends BasePlugin {
|
|
|
17
17
|
ctx.registerCommand("update", bindCommand(this.update, this));
|
|
18
18
|
ctx.registerCommand("move", bindCommand(this.move, this));
|
|
19
19
|
ctx.registerCommand("room.snapshot", bindCommand(this.toSnapshot, this));
|
|
20
|
+
ctx.registerCommand("room.validate", bindCommand(this.validate, this));
|
|
21
|
+
ctx.registerCommand("room.invalidate", bindCommand(this.invalidate, this));
|
|
20
22
|
}
|
|
21
23
|
expose() {
|
|
22
24
|
return {
|
|
@@ -47,8 +49,8 @@ export class Room extends BasePlugin {
|
|
|
47
49
|
if (open) {
|
|
48
50
|
room.open();
|
|
49
51
|
}
|
|
50
|
-
this.ctx.emit("room:add", { key, room: room.toData() });
|
|
51
52
|
}
|
|
53
|
+
this.ctx.emit("room:add", { key, room: room.toData() });
|
|
52
54
|
}
|
|
53
55
|
/** 移除房间监听实例 */
|
|
54
56
|
detach(key) {
|