floating-live 0.17.0-alpha.5 → 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/LICENSE CHANGED
@@ -1,9 +1,9 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Minteea
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Minteea
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
9
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,36 +1,36 @@
1
- # Floating Live
2
-
3
- 一个用于处理和保存直播弹幕的 Web 小工具,开箱即用。
4
-
5
- 本体无弹幕获取功能,需要配合[floating-live-plugins](https://github.com/Minteea/floating-live-plugins)中的插件使用。
6
-
7
- 目前插件库支持 bilibili 和 AcFun 的直播弹幕,不同平台的弹幕会转换为同一种格式便于保存。
8
-
9
- 项目仍在开发中,功能尚未完善,目前除了记录保存直播弹幕外暂时没有别的用处啦,敬请期待。
10
-
11
- 注意:当前项目未进入正式版本阶段,程序结构及导出数据结构可能随时改动,**非常不建议用于正式项目中**。
12
-
13
- GUI 版本:[Minteea/floating-live-gui](https://github.com/Minteea/floating-live-gui)
14
-
15
- ## 使用方法
16
-
17
- ### npm 安装
18
-
19
- ```
20
- npm install floating-live
21
- ```
22
-
23
- ```javascript
24
- // 导入FloatingLive本体
25
- import { FloatingLive } from "floating-live";
26
- // 导入bilibili房间生成插件
27
- import bilibili from "@floating-live/bilibili";
28
-
29
- // 创建一个FloatingLive实例
30
- const live = new FloatingLive();
31
- // 注册插件
32
- live.plugin.register(bilibili);
33
-
34
- // 添加房间并自动打开
35
- live.room.add("bilibili", 6, true);
36
- ```
1
+ # Floating Live
2
+
3
+ 一个用于处理和保存直播弹幕的 Web 小工具,开箱即用。
4
+
5
+ 本体无弹幕获取功能,需要配合[floating-live-plugins](https://github.com/Minteea/floating-live-plugins)中的插件使用。
6
+
7
+ 目前插件库支持 bilibili 和 AcFun 的直播弹幕,不同平台的弹幕会转换为同一种格式便于保存。
8
+
9
+ 项目仍在开发中,功能尚未完善,目前除了记录保存直播弹幕外暂时没有别的用处啦,敬请期待。
10
+
11
+ 注意:当前项目未进入正式版本阶段,程序结构及导出数据结构可能随时改动,**非常不建议用于正式项目中**。
12
+
13
+ GUI 版本:[Minteea/floating-live-gui](https://github.com/Minteea/floating-live-gui)
14
+
15
+ ## 使用方法
16
+
17
+ ### npm 安装
18
+
19
+ ```
20
+ npm install floating-live
21
+ ```
22
+
23
+ ```javascript
24
+ // 导入FloatingLive本体
25
+ import { FloatingLive } from "floating-live";
26
+ // 导入bilibili房间生成插件
27
+ import bilibili from "@floating-live/bilibili";
28
+
29
+ // 创建一个FloatingLive实例
30
+ const live = new FloatingLive();
31
+ // 注册插件
32
+ live.plugin.register(bilibili);
33
+
34
+ // 添加房间并自动打开
35
+ live.room.add("bilibili", 6, true);
36
+ ```
@@ -1,13 +1,13 @@
1
1
  import { LiveRoom } from "./index.js";
2
2
  import { App } from "./app.js";
3
- import { Room } from "./plugins/room/index.js";
3
+ import { Room, RoomCreateOptions } from "./plugins/room/index.js";
4
4
  import { Platform } from "./plugins/platform/index.js";
5
5
  export declare class FloatingLive extends App {
6
6
  room: Room;
7
7
  platform: Platform;
8
8
  constructor();
9
9
  /** 添加房间 */
10
- add(platform: string, id: number, options?: boolean | Record<string, any>): Promise<void>;
10
+ add(platform: string, id: number, options?: boolean | RoomCreateOptions): Promise<void>;
11
11
  /** 移除房间 */
12
12
  remove(key: string): void;
13
13
  /** 获取房间 */
package/dist/app.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { CommandOptions, CommandCallOptions, AppCommandMap, CommandFunction } from "./command/index.js";
2
2
  import { CommandManager } from "./command/manager.js";
3
- import { AppErrorLegacy } from "./error/index.js";
4
3
  import { AppEventDetailMap, AppEventEmitOptions, AppEventListener } from "./event/index.js";
5
4
  import { AppHookMap, HookCallOptions, HookContext, HookFunction, HookUseOptions } from "./hook/index.js";
6
5
  import { HookManager } from "./hook/manager.js";
@@ -20,9 +19,6 @@ export declare class App extends CustomEventEmitter implements PluginContext {
20
19
  once<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]>, signal?: AbortSignal): void;
21
20
  off<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]>): void;
22
21
  emit<K extends keyof AppEventDetailMap>(type: K, detail: AppEventDetailMap[K], options?: AppEventEmitOptions & EventInit): void;
23
- /** 发送错误 */
24
- throw(err?: Error): never;
25
- error(id: string, detail?: Record<string, any>): AppErrorLegacy;
26
22
  /** 注册插件 */
27
23
  register<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions, registerOptions?: PluginRegisterOptions): Promise<P>;
28
24
  /** 同步注册插件 */
package/dist/app.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { CommandManager } from "./command/manager.js";
2
- import { AppErrorLegacy } from "./error/index.js";
3
2
  import { HookManager } from "./hook/manager.js";
4
3
  import { PluginManager } from "./plugin/manager.js";
5
4
  import { CustomEventEmitter } from "./utils/EventEmitter.js";
@@ -35,14 +34,6 @@ export class App extends CustomEventEmitter {
35
34
  super.emit(type, { ...detail, source, remote }, options);
36
35
  super.emit("event", { name: type, detail: { ...detail, source, remote } });
37
36
  }
38
- //--- 错误机制 ---//
39
- /** 发送错误 */
40
- throw(err) {
41
- throw err;
42
- }
43
- error(id, detail) {
44
- return new AppErrorLegacy(id, detail || {});
45
- }
46
37
  //--- 插件机制 ---//
47
38
  /** 注册插件 */
48
39
  register(plugin, options, registerOptions) {
@@ -1,4 +1,4 @@
1
- import { AppErrorLegacy } from "../error/index.js";
1
+ import { appError } from "../error/index.js";
2
2
  export class CommandManager {
3
3
  /** 功能列表 */
4
4
  list = new Map();
@@ -25,7 +25,7 @@ export class CommandManager {
25
25
  callWithOptions(name, options, ...args) {
26
26
  const command = this.list.get(name);
27
27
  if (!command) {
28
- throw new AppErrorLegacy("command:call_unexist", {
28
+ throw appError("command:call_unexist", {
29
29
  message: `命令不存在: ${name}`,
30
30
  target: `command/${name}`,
31
31
  });
@@ -1,17 +1,4 @@
1
- import { ErrorOptions } from "./types.js";
2
1
  export * from "./types.js";
3
- /** @deprecated 应使用 appError 函数代替 */
4
- export declare class AppErrorLegacy extends Error {
5
- /** 错误id */
6
- id: string;
7
- /** 错误来源 */
8
- source?: string;
9
- /** 错误目标 */
10
- target?: string;
11
- /** 错误原因 */
12
- cause?: Error | string;
13
- constructor(id: string, options: ErrorOptions);
14
- }
15
2
  export interface AppError extends Error {
16
3
  /** 错误发生信息 */
17
4
  cause: {
@@ -32,5 +19,6 @@ export interface AppErrorOptions {
32
19
  reason?: string | Error | AppError;
33
20
  /** 错误构造函数 */
34
21
  errorConstructor?: ErrorConstructor;
22
+ [key: string]: unknown;
35
23
  }
36
24
  export declare function appError(id: string, { message, target, reason, errorConstructor }: AppErrorOptions): Error;
@@ -1,22 +1,4 @@
1
1
  export * from "./types.js";
2
- /** @deprecated 应使用 appError 函数代替 */
3
- export class AppErrorLegacy extends Error {
4
- /** 错误id */
5
- id;
6
- /** 错误来源 */
7
- source;
8
- /** 错误目标 */
9
- target;
10
- /** 错误原因 */
11
- cause;
12
- constructor(id, options) {
13
- super(options.message);
14
- this.id = id;
15
- this.source = options?.source;
16
- this.cause = options?.cause;
17
- this.target = options?.target;
18
- }
19
- }
20
2
  export function appError(id, { message, target, reason, errorConstructor = Error }) {
21
3
  return new errorConstructor(message, {
22
4
  cause: {
@@ -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
  };
@@ -1,4 +1,4 @@
1
- import { AppErrorLegacy } from "../error/index.js";
1
+ import { appError } from "../error/index.js";
2
2
  export class HookManager {
3
3
  list = new Map();
4
4
  pluginMap = new Map();
@@ -16,9 +16,9 @@ export class HookManager {
16
16
  this.list.set(name, hooks);
17
17
  }
18
18
  else if (hooks.includes(call)) {
19
- throw new AppErrorLegacy("hook:use_duplicate", {
19
+ throw appError("hook:use_duplicate", {
20
20
  message: `钩子函数挂载失败: ${name}`,
21
- cause: "重复挂载同一函数",
21
+ reason: "重复挂载同一函数",
22
22
  target: `hook/${name}`,
23
23
  });
24
24
  }
@@ -29,9 +29,9 @@ export class HookManager {
29
29
  let hooks = this.list.get(name);
30
30
  const index = hooks?.findIndex((item) => item.call == call) ?? -1;
31
31
  if (!hooks || index < 0)
32
- throw new AppErrorLegacy("hook:unuse_unexist", {
32
+ throw appError("hook:unuse_unexist", {
33
33
  message: `钩子函数卸载失败: ${name}`,
34
- cause: "卸载不存在的钩子函数",
34
+ reason: "卸载不存在的钩子函数",
35
35
  target: `hook/${name}`,
36
36
  });
37
37
  hooks.splice(index, 1);
@@ -1,6 +1,5 @@
1
1
  import { App } from "../../app.js";
2
2
  import type { CommandOptions, CommandCallOptions, CommandFunction, AppCommandMap } from "../../command/index.js";
3
- import { AppErrorLegacy, ErrorOptions } from "../../error/index.js";
4
3
  import { AppEventListener, AppEventEmitOptions, AppEventDetailMap } from "../../event/index.js";
5
4
  import { HookUseOptions, HookCallOptions, AppHookMap, HookFunction, HookContext } from "../../hook/index.js";
6
5
  import { AppValueMap, ValueContext, ValueOptions } from "../../value/index.js";
@@ -15,12 +14,6 @@ export declare class CommonPluginContext implements PluginContext {
15
14
  constructor(app: App, pluginName: string, options?: {
16
15
  accessApp?: boolean;
17
16
  });
18
- /** 抛出错误
19
- *
20
- * 一般用于自身导致的错误,若非插件本身导致的错误,使用throw语句即可
21
- */
22
- throw(err: AppErrorLegacy): never;
23
- error(id: string, options: ErrorOptions): AppErrorLegacy;
24
17
  register<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions): Promise<P>;
25
18
  unregister(pluginName: string): void;
26
19
  getPluginExposes<K extends keyof AppPluginExposesMap>(pluginName: K): AppPluginExposesMap[K];
@@ -1,4 +1,3 @@
1
- import { AppErrorLegacy } from "../../error/index.js";
2
1
  class ListMap extends Map {
3
2
  addItem(key, value) {
4
3
  const list = this.get(key);
@@ -43,17 +42,6 @@ export class CommonPluginContext {
43
42
  this.pluginName = pluginName;
44
43
  this.#accessApp = options?.accessApp ?? false;
45
44
  }
46
- /** 抛出错误
47
- *
48
- * 一般用于自身导致的错误,若非插件本身导致的错误,使用throw语句即可
49
- */
50
- throw(err) {
51
- err.source ??= `plugin:${this.pluginName}`;
52
- throw err;
53
- }
54
- error(id, options) {
55
- return new AppErrorLegacy(id, options);
56
- }
57
45
  register(plugin, options) {
58
46
  const p = this.#app.register(plugin, options);
59
47
  this.#registered.plugins.add(plugin.name);
@@ -1,4 +1,4 @@
1
- import { AppErrorLegacy } from "../../error/index.js";
1
+ import { appError } from "../../error/index.js";
2
2
  import { CommonPluginContext } from "./CommonPluginContext.js";
3
3
  export class SafePluginContext extends CommonPluginContext {
4
4
  get safe() {
@@ -9,12 +9,12 @@ export class SafePluginContext extends CommonPluginContext {
9
9
  super(app, pluginName);
10
10
  this.#permissions = options.permissions;
11
11
  }
12
- throwNotPermitted(permission, cause) {
13
- this.throw(new AppErrorLegacy("plugin:no_permission", {
12
+ throwNotPermitted(permission, reason) {
13
+ throw appError("plugin:no_permission", {
14
14
  message: "插件权限不足",
15
- cause,
15
+ reason,
16
16
  permission,
17
- }));
17
+ });
18
18
  }
19
19
  register(plugin, options) {
20
20
  if (!this.#permissions["plugin.register"]) {
@@ -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
  /** 获取插件实例 */
@@ -1,6 +1,6 @@
1
1
  import { CommonPluginContext } from "./context/CommonPluginContext.js";
2
- import { AppErrorLegacy } from "../error/index.js";
3
2
  import { bindCommand } from "../utils/index.js";
3
+ import { appError } from "../error/index.js";
4
4
  export class PluginManager {
5
5
  /** 插件列表 */
6
6
  list = new Map();
@@ -10,19 +10,20 @@ 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
- throw new AppErrorLegacy("plugin:register_id_missing", {
17
+ throw appError("plugin:register_id_missing", {
17
18
  message: "插件注册失败",
18
- cause: "插件缺少pluginName字段",
19
+ reason: "插件缺少pluginName字段",
19
20
  target: "plugin/#unnamed",
20
21
  });
21
22
  }
22
23
  if (this.list.has(pluginName)) {
23
- throw new AppErrorLegacy("plugin:register_id_duplicate", {
24
+ throw appError("plugin:register_id_duplicate", {
24
25
  message: `插件注册失败: ${pluginName}`,
25
- cause: "已存在相同id的插件",
26
+ reason: "已存在相同id的插件",
26
27
  target: `plugin/${pluginName}`,
27
28
  });
28
29
  }
@@ -31,9 +32,9 @@ export class PluginManager {
31
32
  try {
32
33
  const ctx = this.app.callHookSync("plugin.register", registerCtx);
33
34
  if (ctx.defaultPrevented)
34
- throw new AppErrorLegacy("plugin:register_hook_prevented", {
35
+ throw appError("plugin:register_hook_prevented", {
35
36
  message: `插件注册失败: ${pluginName}`,
36
- cause: "插件注册被钩子函数阻止",
37
+ reason: "插件注册被钩子函数阻止",
37
38
  target: `plugin/${pluginName}`,
38
39
  });
39
40
  // 执行插件函数
@@ -47,11 +48,17 @@ export class PluginManager {
47
48
  plugin,
48
49
  context: pluginCtx,
49
50
  exposes,
50
- unremovable: core || unremovable || false,
51
- accessApp: core || accessApp || false,
52
- pluginType: core ? "core" : 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) {
@@ -63,27 +70,28 @@ export class PluginManager {
63
70
  return plugin;
64
71
  }
65
72
  catch (err) {
66
- throw new AppErrorLegacy("plugin:register_fail", {
73
+ throw appError("plugin:register_fail", {
67
74
  message: `插件注册失败: ${pluginName}`,
68
- cause: err,
75
+ reason: err,
69
76
  target: `plugin/${pluginName}`,
70
77
  });
71
78
  }
72
79
  }
73
80
  /** 注册插件 */
74
- async register(pluginConstructor, options = {}, { context, core, unremovable, accessApp, pluginType, } = {}) {
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
- throw new AppErrorLegacy("plugin:register_id_missing", {
85
+ throw appError("plugin:register_id_missing", {
78
86
  message: "插件注册失败",
79
- cause: "插件缺少pluginName字段",
87
+ reason: "插件缺少pluginName字段",
80
88
  target: "plugin/#unnamed",
81
89
  });
82
90
  }
83
91
  if (this.list.has(pluginName)) {
84
- throw new AppErrorLegacy("plugin:register_id_duplicate", {
92
+ throw appError("plugin:register_id_duplicate", {
85
93
  message: `插件注册失败: ${pluginName}`,
86
- cause: "已存在相同id的插件",
94
+ reason: "已存在相同id的插件",
87
95
  target: `plugin/${pluginName}`,
88
96
  });
89
97
  }
@@ -93,9 +101,9 @@ export class PluginManager {
93
101
  .callHook("plugin.register", registerCtx)
94
102
  .then(async (ctx) => {
95
103
  if (ctx.defaultPrevented)
96
- throw new AppErrorLegacy("plugin:register_hook_prevented", {
104
+ throw appError("plugin:register_hook_prevented", {
97
105
  message: `插件注册失败: ${pluginName}`,
98
- cause: "插件注册被钩子函数阻止",
106
+ reason: "插件注册被钩子函数阻止",
99
107
  target: `plugin/${pluginName}`,
100
108
  });
101
109
  // 执行插件函数
@@ -108,11 +116,17 @@ export class PluginManager {
108
116
  plugin,
109
117
  context: pluginCtx,
110
118
  exposes,
111
- unremovable: core || unremovable || false,
112
- accessApp: core || accessApp || false,
113
- pluginType: core ? "core" : 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) {
@@ -124,9 +138,9 @@ export class PluginManager {
124
138
  return plugin;
125
139
  })
126
140
  .catch((err) => {
127
- throw new AppErrorLegacy("plugin:register_fail", {
141
+ throw appError("plugin:register_fail", {
128
142
  message: `插件注册失败: ${pluginName}`,
129
- cause: err,
143
+ reason: err,
130
144
  target: `plugin/${pluginName}`,
131
145
  });
132
146
  });
@@ -136,18 +150,18 @@ export class PluginManager {
136
150
  const pluginData = this.list.get(pluginName);
137
151
  // 检测插件是否存在
138
152
  if (!pluginData) {
139
- throw new AppErrorLegacy("plugin:unregister_unexist", {
153
+ throw appError("plugin:unregister_unexist", {
140
154
  message: `插件移除失败: ${pluginName}`,
141
- cause: "插件不存在",
155
+ reason: "插件不存在",
142
156
  target: `plugin/${pluginName}`,
143
157
  });
144
158
  }
145
159
  else {
146
160
  const { plugin, context, unremovable } = pluginData;
147
161
  if (unremovable) {
148
- throw new AppErrorLegacy("plugin:unregister_unremovable", {
162
+ throw appError("plugin:unregister_unremovable", {
149
163
  message: `插件移除失败: ${pluginName}`,
150
- cause: "不可移除的插件",
164
+ reason: "不可移除的插件",
151
165
  target: `plugin/${pluginName}`,
152
166
  });
153
167
  }
@@ -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 | Record<string, any>): 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;
@@ -20,16 +20,16 @@ interface PluginExposes {
20
20
  }
21
21
  declare module "../../index.js" {
22
22
  interface AppCommandMap {
23
- add: (platform: string, id: number, options?: boolean | Record<string, any>) => void;
23
+ add: (platform: string, id: number, options?: boolean | RoomCreateOptions) => void;
24
24
  remove: (key: string) => void;
25
25
  move: (key: string, position: number) => void;
26
26
  open: (key: string) => void;
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
- [name: `${string}.room.create`]: (id: string | number, options: Record<string, any>) => LiveRoom | Promise<LiveRoom>;
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>;
34
34
  }
35
35
  interface AppEventDetailMap {
@@ -113,7 +113,7 @@ declare module "../../index.js" {
113
113
  "room.create": {
114
114
  serviceId: string;
115
115
  id: string | number;
116
- options: Record<string, any>;
116
+ options: RoomCreateOptions;
117
117
  };
118
118
  }
119
119
  interface AppSnapshotMap {
@@ -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) {
@@ -83,7 +85,12 @@ export class Room extends BasePlugin {
83
85
  const ctx = { key, platform, roomId, message };
84
86
  this.ctx.callHook("live.message", ctx).then((ctx) => {
85
87
  !ctx.defaultPrevented &&
86
- this.ctx.emit("live:message", { key, platform, roomId, message: ctx.message });
88
+ this.ctx.emit("live:message", {
89
+ key,
90
+ platform,
91
+ roomId,
92
+ message: ctx.message,
93
+ });
87
94
  });
88
95
  });
89
96
  // 直播消息源数据
@@ -202,7 +209,10 @@ export class Room extends BasePlugin {
202
209
  });
203
210
  }
204
211
  const { serviceId, id } = invalidRoom;
205
- const room = await this.create(serviceId, id, { ...options, allowInvalidRoom: false });
212
+ const room = await this.create(serviceId, id, {
213
+ ...options,
214
+ allowInvalidRoom: false,
215
+ });
206
216
  this.map.set(key, room);
207
217
  if (room.valid) {
208
218
  this.ctx.emit("room:validate", { key, room: room.toData() });
@@ -271,10 +281,10 @@ export class Room extends BasePlugin {
271
281
  open(key) {
272
282
  let room = this.map.get(key);
273
283
  if (!room) {
274
- throw (appError("room:open_unexist", {
284
+ throw appError("room:open_unexist", {
275
285
  message: "要打开的房间不存在",
276
286
  target: `room/${key}`,
277
- }));
287
+ });
278
288
  }
279
289
  if (!room.valid) {
280
290
  throw appError("room:open_invalid", {
@@ -1,4 +1,4 @@
1
- import { AppErrorLegacy } from "../error/index.js";
1
+ import { appError } from "../error/index.js";
2
2
  import { bindCommand } from "../utils/index.js";
3
3
  export class ValueManager {
4
4
  list = new Map();
@@ -26,7 +26,7 @@ export class ValueManager {
26
26
  get(name, options) {
27
27
  const item = this.list.get(name);
28
28
  if (!item)
29
- throw new AppErrorLegacy("value:get_unexist", {
29
+ throw appError("value:get_unexist", {
30
30
  message: "无法获取未注册的值",
31
31
  });
32
32
  return item.get(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.17.0-alpha.5",
3
+ "version": "0.17.0-alpha.8",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",