floating-live 0.15.3 → 0.15.5
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/README.md +2 -2
- package/dist/live.d.ts +5 -2
- package/dist/live.js +8 -2
- package/dist/module/command.js +10 -1
- package/dist/module/plugin.d.ts +3 -3
- package/dist/module/plugin.js +17 -15
- package/dist/module/room.d.ts +1 -1
- package/dist/module/room.js +22 -17
- package/dist/types/command.d.ts +3 -1
- package/dist/types/error.d.ts +8 -0
- package/dist/types/error.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/plugin.d.ts +5 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Floating Live
|
|
2
2
|
一个用于处理和保存直播弹幕的Node.js小工具,开箱即用。
|
|
3
3
|
|
|
4
|
-
本体无弹幕获取功能,需要配合[floating-live-
|
|
4
|
+
本体无弹幕获取功能,需要配合[floating-live-plugins](https://github.com/Minteea/floating-live-plugins)中的插件使用。
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
目前插件库支持bilibili和AcFun的直播弹幕,不同平台的弹幕会转换为同一种格式便于保存。
|
|
7
7
|
|
|
8
8
|
项目仍在开发中,功能尚未完善,目前除了记录保存直播弹幕外暂时没有别的用处啦,敬请期待。
|
|
9
9
|
|
package/dist/live.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { ModCommand } from "./module/command";
|
|
|
7
7
|
import { ModValue } from "./module/value";
|
|
8
8
|
import { ModHook } from "./module/hook";
|
|
9
9
|
import { FloatingEventMap } from "./types/events";
|
|
10
|
-
import { FloatingCommandMap } from "./types";
|
|
10
|
+
import { ErrorOptions, FloatingCommandMap } from "./types";
|
|
11
11
|
export declare class FloatingLive extends EventEmitter {
|
|
12
12
|
/** 房间控制模块 */
|
|
13
13
|
room: ModRoom;
|
|
@@ -25,11 +25,14 @@ export declare class FloatingLive extends EventEmitter {
|
|
|
25
25
|
call<T extends keyof FloatingCommandMap>(name: T, ...args: Parameters<FloatingCommandMap[T]>): ReturnType<FloatingCommandMap[T]>;
|
|
26
26
|
on<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): this;
|
|
27
27
|
emit<T extends keyof FloatingEventMap>(eventName: T, ...args: Parameters<FloatingEventMap[T]>): boolean;
|
|
28
|
-
|
|
28
|
+
/** 抛出错误 */
|
|
29
|
+
throw(err: Error, options?: ErrorOptions): void;
|
|
30
|
+
throw(options: ErrorOptions): void;
|
|
29
31
|
getSnapshot(): {
|
|
30
32
|
room: import("./types").RoomInfo[];
|
|
31
33
|
value: Record<string, any>;
|
|
32
34
|
manifest: Record<string, Record<string, any>>;
|
|
33
35
|
command: string[];
|
|
36
|
+
hook: Record<string, any>;
|
|
34
37
|
};
|
|
35
38
|
}
|
package/dist/live.js
CHANGED
|
@@ -29,8 +29,13 @@ class FloatingLive extends events_1.EventEmitter {
|
|
|
29
29
|
super.emit("event", eventName, ...args);
|
|
30
30
|
return emit;
|
|
31
31
|
}
|
|
32
|
-
throw(err) {
|
|
33
|
-
|
|
32
|
+
throw(err, options) {
|
|
33
|
+
if (err instanceof Error) {
|
|
34
|
+
throw Object.assign(err, options);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw Object.assign(new Error(), err);
|
|
38
|
+
}
|
|
34
39
|
}
|
|
35
40
|
getSnapshot() {
|
|
36
41
|
return {
|
|
@@ -38,6 +43,7 @@ class FloatingLive extends events_1.EventEmitter {
|
|
|
38
43
|
value: this.value.getSnapshot(),
|
|
39
44
|
manifest: this.manifest.getSnapshot(),
|
|
40
45
|
command: this.command.getSnapshot(),
|
|
46
|
+
hook: this.value.getSnapshot(),
|
|
41
47
|
};
|
|
42
48
|
}
|
|
43
49
|
}
|
package/dist/module/command.js
CHANGED
|
@@ -19,7 +19,16 @@ class ModCommand {
|
|
|
19
19
|
}
|
|
20
20
|
/** 调用命令 */
|
|
21
21
|
call(name, ...args) {
|
|
22
|
-
|
|
22
|
+
const command = this.list.get(name);
|
|
23
|
+
if (!command) {
|
|
24
|
+
this.main.throw({
|
|
25
|
+
message: "命令不存在",
|
|
26
|
+
id: "command:call_unexist",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return command(...args);
|
|
31
|
+
}
|
|
23
32
|
}
|
|
24
33
|
/** 检测命令是否存在 */
|
|
25
34
|
has(name) {
|
package/dist/module/plugin.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { FloatingLive } from "../live";
|
|
2
|
-
import {
|
|
2
|
+
import { PluginItem, PluginConstructor } from "../types/plugin";
|
|
3
3
|
export declare class ModPlugin {
|
|
4
4
|
/** 插件列表 */
|
|
5
5
|
private list;
|
|
6
6
|
protected readonly main: FloatingLive;
|
|
7
7
|
constructor(main: FloatingLive);
|
|
8
8
|
/** 注册插件 */
|
|
9
|
-
register(pluginFunc: PluginConstructor, options?: Record<string, any>): Promise<
|
|
9
|
+
register(pluginFunc: PluginConstructor, options?: Record<string, any>): Promise<PluginItem | undefined>;
|
|
10
10
|
/** 移除插件 */
|
|
11
11
|
unregister(name: string): Promise<void>;
|
|
12
12
|
/** 获取插件实例 */
|
|
13
|
-
get(name: string):
|
|
13
|
+
get(name: string): PluginItem | undefined;
|
|
14
14
|
}
|
package/dist/module/plugin.js
CHANGED
|
@@ -11,15 +11,15 @@ class ModPlugin {
|
|
|
11
11
|
async register(pluginFunc, options = {}) {
|
|
12
12
|
const name = pluginFunc.pluginName;
|
|
13
13
|
if (!name) {
|
|
14
|
-
throw
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
this.main.throw({
|
|
15
|
+
message: "缺少插件id",
|
|
16
|
+
id: "plugin:register_id_missing",
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
if (this.list.has(name)) {
|
|
20
|
-
throw
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
this.main.throw({
|
|
21
|
+
message: "已存在相同id的插件",
|
|
22
|
+
id: "plugin:register_id_duplicate",
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
return await this.main.hook
|
|
@@ -41,17 +41,19 @@ class ModPlugin {
|
|
|
41
41
|
const plugin = this.list.get(name);
|
|
42
42
|
// 检测插件是否存在
|
|
43
43
|
if (!plugin) {
|
|
44
|
-
throw
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
this.main.throw({
|
|
45
|
+
message: "插件不存在",
|
|
46
|
+
id: "plugin:unregister_unexist",
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
else {
|
|
50
|
+
// 调用该插件的destroy钩子
|
|
51
|
+
await plugin.destroy?.();
|
|
52
|
+
// 从列表中移除插件
|
|
53
|
+
this.list.delete(name);
|
|
54
|
+
// 移除插件注册
|
|
55
|
+
this.main.emit("plugin:remove", name);
|
|
56
|
+
}
|
|
55
57
|
}
|
|
56
58
|
/** 获取插件实例 */
|
|
57
59
|
get(name) {
|
package/dist/module/room.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class ModRoom {
|
|
|
9
9
|
/** 添加房间监听实例 */
|
|
10
10
|
addRoom(room: LiveRoom, open?: boolean): void;
|
|
11
11
|
/** 添加房间 */
|
|
12
|
-
add(platform: string, id: number, options?: boolean | Record<string, any>): void
|
|
12
|
+
add(platform: string, id: number, options?: boolean | Record<string, any>): Promise<void>;
|
|
13
13
|
/** 移除房间 */
|
|
14
14
|
remove(roomKey: string): void;
|
|
15
15
|
/** 获取房间 */
|
package/dist/module/room.js
CHANGED
|
@@ -17,10 +17,10 @@ class ModRoom {
|
|
|
17
17
|
addRoom(room, open) {
|
|
18
18
|
let key = room.key;
|
|
19
19
|
if (this.list.has(key)) {
|
|
20
|
-
this.main.throw(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})
|
|
20
|
+
this.main.throw({
|
|
21
|
+
message: "房间已存在",
|
|
22
|
+
id: "room:add_exist",
|
|
23
|
+
});
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
this.list.set(key, room);
|
|
@@ -81,24 +81,29 @@ class ModRoom {
|
|
|
81
81
|
this.main.emit("room:add", key, room.info);
|
|
82
82
|
}
|
|
83
83
|
/** 添加房间 */
|
|
84
|
-
add(platform, id, options) {
|
|
85
|
-
const opt = typeof options == "boolean" ? { open: options } : options;
|
|
86
|
-
const ctx = { platform, id, options: opt
|
|
87
|
-
this.main.hook.call("room.add", ctx)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
async add(platform, id, options) {
|
|
85
|
+
const opt = typeof options == "boolean" ? { open: options } : options || {};
|
|
86
|
+
const ctx = { platform, id, options: opt };
|
|
87
|
+
const res = await this.main.hook.call("room.add", ctx);
|
|
88
|
+
if (!res) {
|
|
89
|
+
this.main.throw({ message: "无法添加房间", id: "room:add_fail" });
|
|
90
|
+
}
|
|
91
|
+
const room = await this.main.call(`${platform}.room.create`, id, opt);
|
|
92
|
+
if (!room) {
|
|
93
|
+
this.main.throw({ message: "无法创建房间", id: "room:create_fail" });
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this.addRoom(room);
|
|
97
|
+
}
|
|
93
98
|
}
|
|
94
99
|
/** 移除房间 */
|
|
95
100
|
remove(roomKey) {
|
|
96
101
|
let room = this.list.get(roomKey);
|
|
97
102
|
if (!room) {
|
|
98
|
-
this.main.throw(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
})
|
|
103
|
+
this.main.throw({
|
|
104
|
+
message: "房间不存在",
|
|
105
|
+
id: "room:remove_unexist",
|
|
106
|
+
});
|
|
102
107
|
}
|
|
103
108
|
this.list.delete(roomKey); // 从表中删除房间
|
|
104
109
|
room?.removeAllListeners(); // 移除房间监听实例
|
package/dist/types/command.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { LiveRoom } from "../core";
|
|
2
|
+
import { RoomInfo } from "./room";
|
|
2
3
|
export interface FloatingCommandMap {
|
|
3
4
|
add: (platform: string, id: number, options?: boolean | Record<string, any>) => void;
|
|
4
5
|
remove: (key: string) => void;
|
|
5
6
|
open: (key: string) => void;
|
|
6
7
|
close: (key: string) => void;
|
|
7
8
|
update: (key: string) => void;
|
|
8
|
-
[name: `${string}.room.create`]: (id: string | number, options?: Record<string, any>) => LiveRoom;
|
|
9
|
+
[name: `${string}.room.create`]: (id: string | number, options?: Record<string, any>) => Promise<LiveRoom> | LiveRoom;
|
|
10
|
+
[name: `${string}.room.info`]: (id: string | number) => Promise<RoomInfo>;
|
|
9
11
|
}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
package/dist/types/plugin.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { FloatingLive } from "../live";
|
|
2
|
-
/**
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
name: string;
|
|
6
|
-
register: (ctx: FloatingLive, options?: C) => void;
|
|
7
|
-
destroy?: (ctx: FloatingLive) => void;
|
|
8
|
-
};
|
|
9
|
-
export interface IPlugin {
|
|
2
|
+
/** 插件对象 */
|
|
3
|
+
export interface PluginItem {
|
|
4
|
+
pluginName?: string;
|
|
10
5
|
register?(ctx: FloatingLive, options: any): void | Promise<void>;
|
|
11
6
|
destroy?(): void | Promise<void>;
|
|
12
7
|
[name: string]: any;
|
|
13
8
|
}
|
|
9
|
+
/** 插件构造器 */
|
|
14
10
|
export interface PluginConstructor {
|
|
15
11
|
pluginName: string;
|
|
16
|
-
new (ctx: FloatingLive, options: any):
|
|
12
|
+
new (ctx: FloatingLive, options: any): PluginItem;
|
|
17
13
|
}
|