floating-live 0.17.0-alpha.6 → 0.17.0-alpha.9

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.
@@ -1,3 +1,4 @@
1
+ import { PluginInfo } from "../plugin/index.js";
1
2
  export interface AppEventEmitOptions {
2
3
  /** 事件来源 */
3
4
  source?: string;
@@ -19,11 +20,10 @@ 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;
26
+ role: string;
27
27
  };
28
28
  "value:register": {
29
29
  name: string;
@@ -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
  }
@@ -1,8 +1,12 @@
1
1
  export class BasePlugin {
2
2
  static pluginName;
3
+ static role;
3
4
  get pluginName() {
4
5
  return this.constructor.pluginName;
5
6
  }
7
+ get role() {
8
+ return this.constructor.role;
9
+ }
6
10
  ctx;
7
11
  constructor(ctx, options) {
8
12
  this.ctx = ctx;
@@ -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, core, unremovable, accessApp, pluginType, }?: PluginRegisterOptions): P;
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, core, unremovable, accessApp, pluginType, }?: PluginRegisterOptions): Promise<P>;
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
  /** 获取插件实例 */
@@ -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, core, unremovable, accessApp, pluginType, } = {}) {
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: "插件注册失败",
@@ -45,13 +46,20 @@ export class PluginManager {
45
46
  // 将插件数据注册到列表中
46
47
  this.list.set(pluginName, {
47
48
  plugin,
49
+ role,
48
50
  context: pluginCtx,
49
51
  exposes,
50
- unremovable: core || unremovable || false,
51
- accessApp: core || accessApp || false,
52
- pluginType: core ? "core" : pluginType || "",
52
+ unremovable: unremovable || false,
53
+ accessApp: accessApp || false,
54
+ pluginType: pluginType || "",
55
+ });
56
+ this.app.emit("plugin:register", {
57
+ pluginName,
58
+ role,
59
+ unremovable,
60
+ accessApp,
61
+ pluginType,
53
62
  });
54
- this.app.emit("plugin:register", { pluginName });
55
63
  // 如果有whenRegister的回调,调用回调函数
56
64
  const callbackMap = this.whenRegisterMap.get(pluginName);
57
65
  if (callbackMap) {
@@ -71,8 +79,9 @@ export class PluginManager {
71
79
  }
72
80
  }
73
81
  /** 注册插件 */
74
- async register(pluginConstructor, options = {}, { context, core, unremovable, accessApp, pluginType, } = {}) {
82
+ async register(pluginConstructor, options = {}, { context, unremovable = false, accessApp = false, pluginType = "", } = {}) {
75
83
  const pluginName = pluginConstructor.pluginName;
84
+ const role = pluginConstructor.role || "";
76
85
  if (!pluginName) {
77
86
  throw appError("plugin:register_id_missing", {
78
87
  message: "插件注册失败",
@@ -106,13 +115,20 @@ export class PluginManager {
106
115
  const exposes = await plugin.expose?.(pluginCtx);
107
116
  this.list.set(pluginName, {
108
117
  plugin,
118
+ role,
109
119
  context: pluginCtx,
110
120
  exposes,
111
- unremovable: core || unremovable || false,
112
- accessApp: core || accessApp || false,
113
- pluginType: core ? "core" : pluginType || "",
121
+ unremovable: unremovable,
122
+ accessApp: accessApp,
123
+ pluginType: pluginType,
124
+ });
125
+ this.app.emit("plugin:register", {
126
+ pluginName,
127
+ role,
128
+ unremovable,
129
+ accessApp,
130
+ pluginType,
114
131
  });
115
- this.app.emit("plugin:register", { pluginName });
116
132
  // 如果有whenRegister的回调,调用回调函数
117
133
  const callbackMap = this.whenRegisterMap.get(pluginName);
118
134
  if (callbackMap) {
@@ -157,7 +173,7 @@ export class PluginManager {
157
173
  // 从列表中移除插件
158
174
  this.list.delete(pluginName);
159
175
  // 移除插件注册事件
160
- this.app.emit("plugin:unregister", { pluginName });
176
+ this.app.emit("plugin:unregister", { pluginName, role: pluginData.role });
161
177
  // 如果有whenRegister的回调,调用whenUnregistered函数并将回调函数从列表中移除
162
178
  const callbackMap = this.whenRegisterMap.get(pluginName);
163
179
  if (callbackMap) {
@@ -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实例 */
@@ -44,6 +43,7 @@ export interface PluginRegisterOptions {
44
43
  }
45
44
  export interface PluginData<T> {
46
45
  plugin: PluginItem;
46
+ role: string;
47
47
  context: PluginContext;
48
48
  exposes?: T;
49
49
  unremovable: boolean;
@@ -52,6 +52,15 @@ export interface PluginData<T> {
52
52
  /** 插件类型 */
53
53
  pluginType: "core" | "framework" | "";
54
54
  }
55
+ export interface PluginInfo {
56
+ pluginName: string;
57
+ role: string;
58
+ unremovable: boolean;
59
+ /** 可访问App实例 */
60
+ accessApp: boolean;
61
+ /** 插件类型 */
62
+ pluginType: "core" | "framework" | "";
63
+ }
55
64
  /** 插件上下文 */
56
65
  export interface PluginContext {
57
66
  /** 安全插件上下文 */
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.17.0-alpha.6",
3
+ "version": "0.17.0-alpha.9",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",