floating-live 0.17.0-alpha.5 → 0.17.0-alpha.6
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 +8 -8
- package/README.md +36 -36
- package/dist/FloatingLive.d.ts +2 -2
- package/dist/app.d.ts +0 -4
- package/dist/app.js +0 -9
- package/dist/command/manager.js +2 -2
- package/dist/error/index.d.ts +1 -13
- package/dist/error/index.js +0 -18
- package/dist/hook/manager.js +5 -5
- package/dist/plugin/context/CommonPluginContext.d.ts +0 -7
- package/dist/plugin/context/CommonPluginContext.js +0 -12
- package/dist/plugin/context/SafePluginContext.js +5 -5
- package/dist/plugin/manager.js +21 -21
- package/dist/plugins/room/index.d.ts +4 -4
- package/dist/plugins/room/index.js +12 -4
- package/dist/value/manager.js +2 -2
- package/package.json +1 -1
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
|
+
```
|
package/dist/FloatingLive.d.ts
CHANGED
|
@@ -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 |
|
|
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) {
|
package/dist/command/manager.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
28
|
+
throw appError("command:call_unexist", {
|
|
29
29
|
message: `命令不存在: ${name}`,
|
|
30
30
|
target: `command/${name}`,
|
|
31
31
|
});
|
package/dist/error/index.d.ts
CHANGED
|
@@ -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;
|
package/dist/error/index.js
CHANGED
|
@@ -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: {
|
package/dist/hook/manager.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
19
|
+
throw appError("hook:use_duplicate", {
|
|
20
20
|
message: `钩子函数挂载失败: ${name}`,
|
|
21
|
-
|
|
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
|
|
32
|
+
throw appError("hook:unuse_unexist", {
|
|
33
33
|
message: `钩子函数卸载失败: ${name}`,
|
|
34
|
-
|
|
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 {
|
|
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,
|
|
13
|
-
|
|
12
|
+
throwNotPermitted(permission, reason) {
|
|
13
|
+
throw appError("plugin:no_permission", {
|
|
14
14
|
message: "插件权限不足",
|
|
15
|
-
|
|
15
|
+
reason,
|
|
16
16
|
permission,
|
|
17
|
-
})
|
|
17
|
+
});
|
|
18
18
|
}
|
|
19
19
|
register(plugin, options) {
|
|
20
20
|
if (!this.#permissions["plugin.register"]) {
|
package/dist/plugin/manager.js
CHANGED
|
@@ -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();
|
|
@@ -13,16 +13,16 @@ export class PluginManager {
|
|
|
13
13
|
registerSync(pluginConstructor, options = {}, { context, core, unremovable, accessApp, pluginType, } = {}) {
|
|
14
14
|
const pluginName = pluginConstructor.pluginName;
|
|
15
15
|
if (!pluginName) {
|
|
16
|
-
throw
|
|
16
|
+
throw appError("plugin:register_id_missing", {
|
|
17
17
|
message: "插件注册失败",
|
|
18
|
-
|
|
18
|
+
reason: "插件缺少pluginName字段",
|
|
19
19
|
target: "plugin/#unnamed",
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
if (this.list.has(pluginName)) {
|
|
23
|
-
throw
|
|
23
|
+
throw appError("plugin:register_id_duplicate", {
|
|
24
24
|
message: `插件注册失败: ${pluginName}`,
|
|
25
|
-
|
|
25
|
+
reason: "已存在相同id的插件",
|
|
26
26
|
target: `plugin/${pluginName}`,
|
|
27
27
|
});
|
|
28
28
|
}
|
|
@@ -31,9 +31,9 @@ export class PluginManager {
|
|
|
31
31
|
try {
|
|
32
32
|
const ctx = this.app.callHookSync("plugin.register", registerCtx);
|
|
33
33
|
if (ctx.defaultPrevented)
|
|
34
|
-
throw
|
|
34
|
+
throw appError("plugin:register_hook_prevented", {
|
|
35
35
|
message: `插件注册失败: ${pluginName}`,
|
|
36
|
-
|
|
36
|
+
reason: "插件注册被钩子函数阻止",
|
|
37
37
|
target: `plugin/${pluginName}`,
|
|
38
38
|
});
|
|
39
39
|
// 执行插件函数
|
|
@@ -63,9 +63,9 @@ export class PluginManager {
|
|
|
63
63
|
return plugin;
|
|
64
64
|
}
|
|
65
65
|
catch (err) {
|
|
66
|
-
throw
|
|
66
|
+
throw appError("plugin:register_fail", {
|
|
67
67
|
message: `插件注册失败: ${pluginName}`,
|
|
68
|
-
|
|
68
|
+
reason: err,
|
|
69
69
|
target: `plugin/${pluginName}`,
|
|
70
70
|
});
|
|
71
71
|
}
|
|
@@ -74,16 +74,16 @@ export class PluginManager {
|
|
|
74
74
|
async register(pluginConstructor, options = {}, { context, core, unremovable, accessApp, pluginType, } = {}) {
|
|
75
75
|
const pluginName = pluginConstructor.pluginName;
|
|
76
76
|
if (!pluginName) {
|
|
77
|
-
throw
|
|
77
|
+
throw appError("plugin:register_id_missing", {
|
|
78
78
|
message: "插件注册失败",
|
|
79
|
-
|
|
79
|
+
reason: "插件缺少pluginName字段",
|
|
80
80
|
target: "plugin/#unnamed",
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
if (this.list.has(pluginName)) {
|
|
84
|
-
throw
|
|
84
|
+
throw appError("plugin:register_id_duplicate", {
|
|
85
85
|
message: `插件注册失败: ${pluginName}`,
|
|
86
|
-
|
|
86
|
+
reason: "已存在相同id的插件",
|
|
87
87
|
target: `plugin/${pluginName}`,
|
|
88
88
|
});
|
|
89
89
|
}
|
|
@@ -93,9 +93,9 @@ export class PluginManager {
|
|
|
93
93
|
.callHook("plugin.register", registerCtx)
|
|
94
94
|
.then(async (ctx) => {
|
|
95
95
|
if (ctx.defaultPrevented)
|
|
96
|
-
throw
|
|
96
|
+
throw appError("plugin:register_hook_prevented", {
|
|
97
97
|
message: `插件注册失败: ${pluginName}`,
|
|
98
|
-
|
|
98
|
+
reason: "插件注册被钩子函数阻止",
|
|
99
99
|
target: `plugin/${pluginName}`,
|
|
100
100
|
});
|
|
101
101
|
// 执行插件函数
|
|
@@ -124,9 +124,9 @@ export class PluginManager {
|
|
|
124
124
|
return plugin;
|
|
125
125
|
})
|
|
126
126
|
.catch((err) => {
|
|
127
|
-
throw
|
|
127
|
+
throw appError("plugin:register_fail", {
|
|
128
128
|
message: `插件注册失败: ${pluginName}`,
|
|
129
|
-
|
|
129
|
+
reason: err,
|
|
130
130
|
target: `plugin/${pluginName}`,
|
|
131
131
|
});
|
|
132
132
|
});
|
|
@@ -136,18 +136,18 @@ export class PluginManager {
|
|
|
136
136
|
const pluginData = this.list.get(pluginName);
|
|
137
137
|
// 检测插件是否存在
|
|
138
138
|
if (!pluginData) {
|
|
139
|
-
throw
|
|
139
|
+
throw appError("plugin:unregister_unexist", {
|
|
140
140
|
message: `插件移除失败: ${pluginName}`,
|
|
141
|
-
|
|
141
|
+
reason: "插件不存在",
|
|
142
142
|
target: `plugin/${pluginName}`,
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
else {
|
|
146
146
|
const { plugin, context, unremovable } = pluginData;
|
|
147
147
|
if (unremovable) {
|
|
148
|
-
throw
|
|
148
|
+
throw appError("plugin:unregister_unremovable", {
|
|
149
149
|
message: `插件移除失败: ${pluginName}`,
|
|
150
|
-
|
|
150
|
+
reason: "不可移除的插件",
|
|
151
151
|
target: `plugin/${pluginName}`,
|
|
152
152
|
});
|
|
153
153
|
}
|
|
@@ -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 |
|
|
11
|
+
add(platform: string, id: number, options?: boolean | RoomCreateOptions): void;
|
|
12
12
|
remove(key: string): void;
|
|
13
13
|
get(key: string): LiveRoom | InvalidLiveRoom | undefined;
|
|
14
14
|
has(key: string): boolean;
|
|
@@ -20,7 +20,7 @@ interface PluginExposes {
|
|
|
20
20
|
}
|
|
21
21
|
declare module "../../index.js" {
|
|
22
22
|
interface AppCommandMap {
|
|
23
|
-
add: (platform: string, id: number, options?: boolean |
|
|
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;
|
|
@@ -29,7 +29,7 @@ declare module "../../index.js" {
|
|
|
29
29
|
"room.snapshot": () => LiveRoomData[];
|
|
30
30
|
"room.validate": (key: string) => void;
|
|
31
31
|
"room.invalidate": (key: string) => void;
|
|
32
|
-
[name: `${string}.room.create`]: (id: string | number, options:
|
|
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:
|
|
116
|
+
options: RoomCreateOptions;
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
interface AppSnapshotMap {
|
|
@@ -83,7 +83,12 @@ export class Room extends BasePlugin {
|
|
|
83
83
|
const ctx = { key, platform, roomId, message };
|
|
84
84
|
this.ctx.callHook("live.message", ctx).then((ctx) => {
|
|
85
85
|
!ctx.defaultPrevented &&
|
|
86
|
-
this.ctx.emit("live:message", {
|
|
86
|
+
this.ctx.emit("live:message", {
|
|
87
|
+
key,
|
|
88
|
+
platform,
|
|
89
|
+
roomId,
|
|
90
|
+
message: ctx.message,
|
|
91
|
+
});
|
|
87
92
|
});
|
|
88
93
|
});
|
|
89
94
|
// 直播消息源数据
|
|
@@ -202,7 +207,10 @@ export class Room extends BasePlugin {
|
|
|
202
207
|
});
|
|
203
208
|
}
|
|
204
209
|
const { serviceId, id } = invalidRoom;
|
|
205
|
-
const room = await this.create(serviceId, id, {
|
|
210
|
+
const room = await this.create(serviceId, id, {
|
|
211
|
+
...options,
|
|
212
|
+
allowInvalidRoom: false,
|
|
213
|
+
});
|
|
206
214
|
this.map.set(key, room);
|
|
207
215
|
if (room.valid) {
|
|
208
216
|
this.ctx.emit("room:validate", { key, room: room.toData() });
|
|
@@ -271,10 +279,10 @@ export class Room extends BasePlugin {
|
|
|
271
279
|
open(key) {
|
|
272
280
|
let room = this.map.get(key);
|
|
273
281
|
if (!room) {
|
|
274
|
-
throw
|
|
282
|
+
throw appError("room:open_unexist", {
|
|
275
283
|
message: "要打开的房间不存在",
|
|
276
284
|
target: `room/${key}`,
|
|
277
|
-
})
|
|
285
|
+
});
|
|
278
286
|
}
|
|
279
287
|
if (!room.valid) {
|
|
280
288
|
throw appError("room:open_invalid", {
|
package/dist/value/manager.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
29
|
+
throw appError("value:get_unexist", {
|
|
30
30
|
message: "无法获取未注册的值",
|
|
31
31
|
});
|
|
32
32
|
return item.get(options);
|