floating-live 0.15.0-beta.0 → 0.15.0-beta.10
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 +3 -34
- package/dist/core/LiveRoom.d.ts +5 -7
- package/dist/core/LiveRoom.js +7 -5
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/core/plugin.d.ts +17 -0
- package/dist/core/plugin.js +28 -0
- package/dist/enums.d.ts +16 -1
- package/dist/enums.js +17 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/live.d.ts +25 -20
- package/dist/live.js +27 -41
- package/dist/module/command.d.ts +16 -0
- package/dist/module/command.js +29 -0
- package/dist/module/hook.d.ts +14 -0
- package/dist/module/hook.js +44 -0
- package/dist/module/manifest.d.ts +15 -0
- package/dist/module/manifest.js +44 -0
- package/dist/module/plugin.d.ts +15 -0
- package/dist/module/{ModPlugin.js → plugin.js} +19 -25
- package/dist/module/{ModRoom.d.ts → room.d.ts} +6 -12
- package/dist/module/room.js +150 -0
- package/dist/module/value.d.ts +25 -0
- package/dist/module/value.js +53 -0
- package/dist/types/command.d.ts +9 -0
- package/dist/types/events.d.ts +37 -0
- package/dist/types/events.js +2 -0
- package/dist/types/hook.d.ts +9 -0
- package/dist/types/hook.js +2 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/index.js +5 -1
- package/dist/types/manifest.d.ts +4 -0
- package/dist/types/manifest.js +2 -0
- package/dist/types/message.d.ts +43 -5
- package/dist/types/plugin.d.ts +9 -2
- package/dist/types/room.d.ts +23 -12
- package/dist/types/value.d.ts +2 -0
- package/dist/types/value.js +2 -0
- package/package.json +8 -15
- package/dist/core/Reglist.d.ts +0 -29
- package/dist/core/Reglist.js +0 -69
- package/dist/module/ModAuth.d.ts +0 -10
- package/dist/module/ModAuth.js +0 -35
- package/dist/module/ModCommand.d.ts +0 -9
- package/dist/module/ModCommand.js +0 -19
- package/dist/module/ModMessage.d.ts +0 -9
- package/dist/module/ModMessage.js +0 -16
- package/dist/module/ModPlugin.d.ts +0 -20
- package/dist/module/ModRoom.js +0 -164
- package/dist/module/ModState.d.ts +0 -12
- package/dist/module/ModState.js +0 -29
- package/dist/types/auth.d.ts +0 -19
- /package/dist/types/{auth.js → command.js} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Floating Live
|
|
2
2
|
一个用于处理和保存直播弹幕的Node.js小工具,开箱即用。
|
|
3
3
|
|
|
4
|
+
本体无弹幕获取功能,需要配合[floating-live-danmaku](https://github.com/Minteea/floating-live-danmaku)中的弹幕获取插件使用。
|
|
5
|
+
|
|
4
6
|
目前支持bilibili和AcFun的直播弹幕,不同平台的弹幕会转换为同一种格式便于保存。
|
|
5
7
|
|
|
6
8
|
项目仍在开发中,功能尚未完善,目前除了记录保存直播弹幕外暂时没有别的用处啦,敬请期待。
|
|
@@ -18,7 +20,7 @@ npm install floating-live
|
|
|
18
20
|
// 导入FloatingLive
|
|
19
21
|
const { FloatingLive } = require("floating-live")
|
|
20
22
|
// 导入bilibili房间生成插件
|
|
21
|
-
const bilibili = require("floating-live/plugin
|
|
23
|
+
const bilibili = require("@floating-live/bilibili/plugin")
|
|
22
24
|
|
|
23
25
|
// 创建一个FloatingLive实例
|
|
24
26
|
const live = new FloatingLive()
|
|
@@ -28,36 +30,3 @@ live.plugin.register(bilibili)
|
|
|
28
30
|
// 添加房间并自动打开
|
|
29
31
|
live.room.add("bilibili", 6, true)
|
|
30
32
|
```
|
|
31
|
-
|
|
32
|
-
### 拆包即用模式
|
|
33
|
-
* 下载并安装 `Node.js` ,建议下载最新LTS版本(如果已经安装可跳过这一步)。
|
|
34
|
-
* 下载该项目的zip压缩包,解压,并在项目根目录下新建一个名为 `save` 的文件夹。
|
|
35
|
-
* 在项目根目录的控制台输入下列命令,安装所有依赖包。
|
|
36
|
-
```
|
|
37
|
-
npm install
|
|
38
|
-
```
|
|
39
|
-
#### 运行Demo文件
|
|
40
|
-
* 打开demo/demo.ts
|
|
41
|
-
``` typescript
|
|
42
|
-
// ...
|
|
43
|
-
const config = {
|
|
44
|
-
rooms: [
|
|
45
|
-
{
|
|
46
|
-
platform: "bilibili", // 直播平台
|
|
47
|
-
id: 2064239, // 直播间号
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
};
|
|
51
|
-
// ...
|
|
52
|
-
```
|
|
53
|
-
* 根据需要修改直播平台和直播间号,目前支持的 `platform` 值有:`acfun`、`bilibili`(注意是小写),也可以通过自定义插件添加直播平台
|
|
54
|
-
* 在项目根目录的控制台输入下列命令:
|
|
55
|
-
```
|
|
56
|
-
npm run test
|
|
57
|
-
```
|
|
58
|
-
即可接收来自平台的直播弹幕。
|
|
59
|
-
|
|
60
|
-
## 感谢
|
|
61
|
-
### 使用开源库
|
|
62
|
-
* [simon300000/bilibili-live-ws](https://github.com/simon300000/bilibili-live-ws/)
|
|
63
|
-
* [ACFUN-FOSS/ac-danmu](https://github.com/ACFUN-FOSS/ac-danmu.js)
|
package/dist/core/LiveRoom.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
|
-
import { RoomStatus } from "../enums";
|
|
3
|
+
import { ConnectStatus, RoomStatus } from "../enums";
|
|
4
4
|
import { RoomDetail, RoomInfo, RoomStatsInfo } from "../types";
|
|
5
5
|
import { Message, UserInfo } from "../types/message";
|
|
6
6
|
export declare abstract class LiveRoom extends EventEmitter implements RoomInfo {
|
|
@@ -23,23 +23,21 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
|
|
|
23
23
|
liveId?: string;
|
|
24
24
|
/** 房间是否打开 */
|
|
25
25
|
opened: boolean;
|
|
26
|
+
/** 是否连接上房间 */
|
|
27
|
+
connection: ConnectStatus;
|
|
26
28
|
/** 房间是否可用 */
|
|
27
29
|
abstract available: boolean;
|
|
28
|
-
/** 是否连接上房间 */
|
|
29
|
-
abstract connected: boolean;
|
|
30
30
|
/** 打开连接 */
|
|
31
31
|
abstract open(): void;
|
|
32
32
|
/** 关闭连接 */
|
|
33
33
|
abstract close(): void;
|
|
34
34
|
/** 从服务器获取信息 */
|
|
35
35
|
abstract getInfo(): Promise<void>;
|
|
36
|
-
/** 设置用户凭据 */
|
|
37
|
-
setAuth?(auth: string): void;
|
|
38
36
|
/** 销毁事件 */
|
|
39
|
-
protected
|
|
37
|
+
protected onDestroy?(): void;
|
|
40
38
|
/** 销毁 */
|
|
41
39
|
destroy(): void;
|
|
42
|
-
protected
|
|
40
|
+
protected emitMessage(msg: Message.All): void;
|
|
43
41
|
protected emitRaw(msg: any): void;
|
|
44
42
|
get info(): RoomInfo;
|
|
45
43
|
get key(): string;
|
package/dist/core/LiveRoom.js
CHANGED
|
@@ -12,15 +12,17 @@ class LiveRoom extends events_1.EventEmitter {
|
|
|
12
12
|
this.timestamp = 0;
|
|
13
13
|
/** 房间是否打开 */
|
|
14
14
|
this.opened = false;
|
|
15
|
+
/** 是否连接上房间 */
|
|
16
|
+
this.connection = enums_1.ConnectStatus.off;
|
|
15
17
|
}
|
|
16
18
|
/** 销毁 */
|
|
17
19
|
destroy() {
|
|
18
20
|
this.close();
|
|
19
21
|
this.removeAllListeners();
|
|
20
|
-
this.
|
|
22
|
+
this.onDestroy?.();
|
|
21
23
|
}
|
|
22
24
|
// 发送消息
|
|
23
|
-
|
|
25
|
+
emitMessage(msg) {
|
|
24
26
|
// 其他消息 => 先更改状态再发送消息
|
|
25
27
|
// 直播结束消息 => 先发送消息再更改状态
|
|
26
28
|
switch (msg.type) {
|
|
@@ -42,15 +44,15 @@ class LiveRoom extends events_1.EventEmitter {
|
|
|
42
44
|
break;
|
|
43
45
|
case "live_end":
|
|
44
46
|
case "live_cut":
|
|
45
|
-
this.emit("msg", msg);
|
|
46
47
|
this.status = msg.status || enums_1.RoomStatus.off;
|
|
47
48
|
this.timestamp = msg.timestamp;
|
|
49
|
+
this.emit("message", msg);
|
|
48
50
|
this.emit("status", msg.status || enums_1.RoomStatus.off, {
|
|
49
51
|
timestamp: msg.timestamp,
|
|
50
52
|
});
|
|
51
53
|
return;
|
|
52
54
|
}
|
|
53
|
-
this.emit("
|
|
55
|
+
this.emit("message", msg);
|
|
54
56
|
}
|
|
55
57
|
// 发送源消息
|
|
56
58
|
emitRaw(msg) {
|
|
@@ -68,7 +70,7 @@ class LiveRoom extends events_1.EventEmitter {
|
|
|
68
70
|
liveId: this.liveId,
|
|
69
71
|
available: this.available,
|
|
70
72
|
opened: this.opened,
|
|
71
|
-
|
|
73
|
+
connection: this.connection,
|
|
72
74
|
key: this.key,
|
|
73
75
|
};
|
|
74
76
|
}
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FloatingLive } from "../live";
|
|
2
|
+
import { FloatingEventMap } from "../types/events";
|
|
3
|
+
export declare abstract class BasePlugin {
|
|
4
|
+
static pluginName: string;
|
|
5
|
+
protected main: FloatingLive;
|
|
6
|
+
private registerList;
|
|
7
|
+
constructor(main: FloatingLive);
|
|
8
|
+
/** 插件监听事件 */
|
|
9
|
+
on<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): void;
|
|
10
|
+
/** 插件一次性监听事件 */
|
|
11
|
+
once<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): void;
|
|
12
|
+
/** 插件移除监听事件 */
|
|
13
|
+
off<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): void;
|
|
14
|
+
/** 插件发送事件 */
|
|
15
|
+
emit<T extends keyof FloatingEventMap>(eventName: T, ...args: Parameters<FloatingEventMap[T]>): void;
|
|
16
|
+
abstract destroy(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasePlugin = void 0;
|
|
4
|
+
class BasePlugin {
|
|
5
|
+
constructor(main) {
|
|
6
|
+
this.registerList = [];
|
|
7
|
+
this.main = main;
|
|
8
|
+
}
|
|
9
|
+
/** 插件监听事件 */
|
|
10
|
+
on(eventName, listener) {
|
|
11
|
+
this.main.on(eventName, listener);
|
|
12
|
+
this.registerList.push(["event", eventName, listener]);
|
|
13
|
+
}
|
|
14
|
+
/** 插件一次性监听事件 */
|
|
15
|
+
once(eventName, listener) {
|
|
16
|
+
this.main.once(eventName, listener);
|
|
17
|
+
this.registerList.push(["event", eventName, listener]);
|
|
18
|
+
}
|
|
19
|
+
/** 插件移除监听事件 */
|
|
20
|
+
off(eventName, listener) {
|
|
21
|
+
this.main.off(eventName, listener);
|
|
22
|
+
}
|
|
23
|
+
/** 插件发送事件 */
|
|
24
|
+
emit(eventName, ...args) {
|
|
25
|
+
this.main.emit(eventName, ...args);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.BasePlugin = BasePlugin;
|
package/dist/enums.d.ts
CHANGED
|
@@ -7,7 +7,22 @@ export declare enum RoomStatus {
|
|
|
7
7
|
/** 正在轮播 */
|
|
8
8
|
round = 2,
|
|
9
9
|
/** 被封禁 */
|
|
10
|
-
banned = -1
|
|
10
|
+
banned = -1,
|
|
11
|
+
/** 已上锁 */
|
|
12
|
+
locked = -2
|
|
13
|
+
}
|
|
14
|
+
/** 直播间状态 */
|
|
15
|
+
export declare enum ConnectStatus {
|
|
16
|
+
/** 未连接 */
|
|
17
|
+
off = 0,
|
|
18
|
+
/** 连接中 */
|
|
19
|
+
connecting = 1,
|
|
20
|
+
/** 连接到服务器 */
|
|
21
|
+
connected = 2,
|
|
22
|
+
/** 连接到房间 */
|
|
23
|
+
entered = 3,
|
|
24
|
+
/** 连接失败或断开 */
|
|
25
|
+
disconnected = -1
|
|
11
26
|
}
|
|
12
27
|
/** 图片大小 */
|
|
13
28
|
export declare enum ImageSize {
|
package/dist/enums.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserType = exports.DanmakuMode = exports.ImageSize = exports.RoomStatus = void 0;
|
|
3
|
+
exports.UserType = exports.DanmakuMode = exports.ImageSize = exports.ConnectStatus = exports.RoomStatus = void 0;
|
|
4
4
|
/** 直播间状态 */
|
|
5
5
|
var RoomStatus;
|
|
6
6
|
(function (RoomStatus) {
|
|
@@ -12,7 +12,23 @@ var RoomStatus;
|
|
|
12
12
|
RoomStatus[RoomStatus["round"] = 2] = "round";
|
|
13
13
|
/** 被封禁 */
|
|
14
14
|
RoomStatus[RoomStatus["banned"] = -1] = "banned";
|
|
15
|
+
/** 已上锁 */
|
|
16
|
+
RoomStatus[RoomStatus["locked"] = -2] = "locked";
|
|
15
17
|
})(RoomStatus = exports.RoomStatus || (exports.RoomStatus = {}));
|
|
18
|
+
/** 直播间状态 */
|
|
19
|
+
var ConnectStatus;
|
|
20
|
+
(function (ConnectStatus) {
|
|
21
|
+
/** 未连接 */
|
|
22
|
+
ConnectStatus[ConnectStatus["off"] = 0] = "off";
|
|
23
|
+
/** 连接中 */
|
|
24
|
+
ConnectStatus[ConnectStatus["connecting"] = 1] = "connecting";
|
|
25
|
+
/** 连接到服务器 */
|
|
26
|
+
ConnectStatus[ConnectStatus["connected"] = 2] = "connected";
|
|
27
|
+
/** 连接到房间 */
|
|
28
|
+
ConnectStatus[ConnectStatus["entered"] = 3] = "entered";
|
|
29
|
+
/** 连接失败或断开 */
|
|
30
|
+
ConnectStatus[ConnectStatus["disconnected"] = -1] = "disconnected";
|
|
31
|
+
})(ConnectStatus = exports.ConnectStatus || (exports.ConnectStatus = {}));
|
|
16
32
|
/** 图片大小 */
|
|
17
33
|
var ImageSize;
|
|
18
34
|
(function (ImageSize) {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -20,5 +20,4 @@ Object.defineProperty(exports, "FloatingLive", { enumerable: true, get: function
|
|
|
20
20
|
__exportStar(require("./types"), exports);
|
|
21
21
|
__exportStar(require("./enums"), exports);
|
|
22
22
|
__exportStar(require("./core/LiveRoom"), exports);
|
|
23
|
-
__exportStar(require("./core/Reglist"), exports);
|
|
24
23
|
__exportStar(require("./utils"), exports);
|
package/dist/live.d.ts
CHANGED
|
@@ -1,30 +1,35 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
|
-
import { ModPlugin } from "./module/
|
|
4
|
-
import { ModRoom } from "./module/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
3
|
+
import { ModPlugin } from "./module/plugin";
|
|
4
|
+
import { ModRoom } from "./module/room";
|
|
5
|
+
import { ModManifest } from "./module/manifest";
|
|
6
|
+
import { ModCommand } from "./module/command";
|
|
7
|
+
import { ModValue } from "./module/value";
|
|
8
|
+
import { ModHook } from "./module/hook";
|
|
9
|
+
import { FloatingEventMap } from "./types/events";
|
|
10
|
+
import { FloatingCommandMap } from "./types";
|
|
9
11
|
export declare class FloatingLive extends EventEmitter {
|
|
10
12
|
/** 房间控制模块 */
|
|
11
13
|
room: ModRoom;
|
|
12
|
-
/** 消息处理模块 */
|
|
13
|
-
message: ModMessage;
|
|
14
|
-
/** 用户登录凭据模块 */
|
|
15
|
-
auth: ModAuth;
|
|
16
14
|
/** 插件处理模块 */
|
|
17
|
-
plugin: ModPlugin
|
|
15
|
+
plugin: ModPlugin;
|
|
18
16
|
/** 命令模块 */
|
|
19
17
|
command: ModCommand;
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
|
|
18
|
+
/** Manifest模块 */
|
|
19
|
+
manifest: ModManifest;
|
|
20
|
+
/** 数值模块 */
|
|
21
|
+
value: ModValue;
|
|
22
|
+
/** 钩子模块 */
|
|
23
|
+
hook: ModHook;
|
|
24
24
|
constructor();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
call<T extends keyof FloatingCommandMap>(name: T, ...args: Parameters<FloatingCommandMap[T]>): ReturnType<FloatingCommandMap[T]>;
|
|
26
|
+
on<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): this;
|
|
27
|
+
emit<T extends keyof FloatingEventMap>(eventName: T, ...args: Parameters<FloatingEventMap[T]>): boolean;
|
|
28
|
+
throw(err: Error): void;
|
|
29
|
+
getSnapshot(): {
|
|
30
|
+
room: import("./types").RoomInfo[];
|
|
31
|
+
value: Record<string, any>;
|
|
32
|
+
manifest: Record<string, Record<string, any>>;
|
|
33
|
+
command: string[];
|
|
34
|
+
};
|
|
30
35
|
}
|
package/dist/live.js
CHANGED
|
@@ -1,56 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.FloatingLive = void 0;
|
|
7
4
|
const events_1 = require("events");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
5
|
+
const plugin_1 = require("./module/plugin");
|
|
6
|
+
const room_1 = require("./module/room");
|
|
7
|
+
const manifest_1 = require("./module/manifest");
|
|
8
|
+
const command_1 = require("./module/command");
|
|
9
|
+
const value_1 = require("./module/value");
|
|
10
|
+
const hook_1 = require("./module/hook");
|
|
14
11
|
class FloatingLive extends events_1.EventEmitter {
|
|
15
12
|
constructor() {
|
|
16
13
|
super();
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.message = new ModMessage_1.ModMessage(this);
|
|
24
|
-
this.auth = new ModAuth_1.ModAuth(this);
|
|
25
|
-
this.init();
|
|
14
|
+
this.command = new command_1.ModCommand(this);
|
|
15
|
+
this.manifest = new manifest_1.ModManifest(this);
|
|
16
|
+
this.plugin = new plugin_1.ModPlugin(this);
|
|
17
|
+
this.room = new room_1.ModRoom(this);
|
|
18
|
+
this.value = new value_1.ModValue(this);
|
|
19
|
+
this.hook = new hook_1.ModHook(this);
|
|
26
20
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// 设置在插件卸载时移除由插件注册的事件
|
|
30
|
-
this.on("plugin:remove", (name) => {
|
|
31
|
-
this.regEventMap.get(name)?.forEach(([eventName, listener]) => {
|
|
32
|
-
this.removeListener(eventName, listener);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
21
|
+
call(name, ...args) {
|
|
22
|
+
return this.command.call(name, ...args);
|
|
35
23
|
}
|
|
36
|
-
/** 重写事件监听 */
|
|
37
24
|
on(eventName, listener) {
|
|
38
|
-
super.on(eventName, listener);
|
|
39
|
-
// 检测是否为插件添加事件,并添加进事件列表
|
|
40
|
-
if (this.plugin.currentPlugin) {
|
|
41
|
-
if (!this.regEventMap.has(this.plugin.currentPlugin)) {
|
|
42
|
-
this.regEventMap.set(this.plugin.currentPlugin, []);
|
|
43
|
-
}
|
|
44
|
-
this.regEventMap
|
|
45
|
-
.get(this.plugin.currentPlugin)
|
|
46
|
-
?.push([eventName, listener]);
|
|
47
|
-
}
|
|
48
|
-
return this;
|
|
25
|
+
return super.on(eventName, listener);
|
|
49
26
|
}
|
|
50
27
|
emit(eventName, ...args) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
28
|
+
return super.emit(eventName, ...args);
|
|
29
|
+
}
|
|
30
|
+
throw(err) {
|
|
31
|
+
this.emit("error", err);
|
|
32
|
+
}
|
|
33
|
+
getSnapshot() {
|
|
34
|
+
return {
|
|
35
|
+
room: this.room.getSnapshot(),
|
|
36
|
+
value: this.value.getSnapshot(),
|
|
37
|
+
manifest: this.manifest.getSnapshot(),
|
|
38
|
+
command: this.command.getSnapshot(),
|
|
39
|
+
};
|
|
54
40
|
}
|
|
55
41
|
}
|
|
56
42
|
exports.FloatingLive = FloatingLive;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FloatingLive } from "../live";
|
|
2
|
+
import { FloatingCommandMap } from "../types";
|
|
3
|
+
export declare class ModCommand {
|
|
4
|
+
/** 功能列表 */
|
|
5
|
+
private readonly list;
|
|
6
|
+
protected readonly main: FloatingLive;
|
|
7
|
+
constructor(main: FloatingLive);
|
|
8
|
+
/** 注册命令 */
|
|
9
|
+
register<T extends keyof FloatingCommandMap>(name: T, func: FloatingCommandMap[T]): void;
|
|
10
|
+
/** 取消注册命令 */
|
|
11
|
+
unregister(name: string): void;
|
|
12
|
+
/** 调用命令 */
|
|
13
|
+
call<T extends keyof FloatingCommandMap>(name: T, ...args: Parameters<FloatingCommandMap[T]>): any;
|
|
14
|
+
/** 获取快照 */
|
|
15
|
+
getSnapshot(): string[];
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModCommand = void 0;
|
|
4
|
+
class ModCommand {
|
|
5
|
+
constructor(main) {
|
|
6
|
+
/** 功能列表 */
|
|
7
|
+
this.list = new Map();
|
|
8
|
+
this.main = main;
|
|
9
|
+
}
|
|
10
|
+
/** 注册命令 */
|
|
11
|
+
register(name, func) {
|
|
12
|
+
this.list.set(name, func);
|
|
13
|
+
this.main.emit("command:add", name);
|
|
14
|
+
}
|
|
15
|
+
/** 取消注册命令 */
|
|
16
|
+
unregister(name) {
|
|
17
|
+
this.list.delete(name);
|
|
18
|
+
this.main.emit("command:remove", name);
|
|
19
|
+
}
|
|
20
|
+
/** 调用命令 */
|
|
21
|
+
call(name, ...args) {
|
|
22
|
+
return this.list.get(name)?.(...args);
|
|
23
|
+
}
|
|
24
|
+
/** 获取快照 */
|
|
25
|
+
getSnapshot() {
|
|
26
|
+
return [...this.list].map(([key]) => key);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ModCommand = ModCommand;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FloatingLive } from "../live";
|
|
2
|
+
import { FloatingHookMap } from "../types/hook";
|
|
3
|
+
export declare type HookFunction<T> = (ctx: T) => boolean | void | Promise<boolean | void>;
|
|
4
|
+
export declare class ModHook {
|
|
5
|
+
private list;
|
|
6
|
+
protected readonly main: FloatingLive;
|
|
7
|
+
constructor(main: FloatingLive);
|
|
8
|
+
/** 注册钩子函数 */
|
|
9
|
+
register<T extends keyof FloatingHookMap>(name: T, func: HookFunction<FloatingHookMap[T]>): void;
|
|
10
|
+
/** 取消注册钩子函数 */
|
|
11
|
+
unregister<T extends keyof FloatingHookMap>(name: T, func: HookFunction<FloatingHookMap[T]>): void;
|
|
12
|
+
/** 调用钩子函数 */
|
|
13
|
+
call<T extends keyof FloatingHookMap>(name: T, ctx: FloatingHookMap[T]): Promise<boolean>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModHook = void 0;
|
|
4
|
+
class ModHook {
|
|
5
|
+
constructor(main) {
|
|
6
|
+
this.list = new Map();
|
|
7
|
+
this.main = main;
|
|
8
|
+
}
|
|
9
|
+
/** 注册钩子函数 */
|
|
10
|
+
register(name, func) {
|
|
11
|
+
let hooks = this.list.get(name);
|
|
12
|
+
if (!hooks) {
|
|
13
|
+
hooks = [];
|
|
14
|
+
this.list.set(name, hooks);
|
|
15
|
+
}
|
|
16
|
+
hooks.push(func);
|
|
17
|
+
}
|
|
18
|
+
/** 取消注册钩子函数 */
|
|
19
|
+
unregister(name, func) {
|
|
20
|
+
let hooks = this.list.get(name);
|
|
21
|
+
if (hooks) {
|
|
22
|
+
const index = hooks.indexOf(func);
|
|
23
|
+
index > -1 && hooks.splice(index, 1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** 调用钩子函数 */
|
|
27
|
+
async call(name, ctx) {
|
|
28
|
+
const hooks = this.list.get(name);
|
|
29
|
+
if (!hooks) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
for (const func of hooks) {
|
|
33
|
+
const result = await func(ctx);
|
|
34
|
+
if (result == true) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
else if (result == false) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ModHook = ModHook;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FloatingLive } from "../live";
|
|
2
|
+
import { FloatingManifestMap } from "../types/manifest";
|
|
3
|
+
export declare class ModManifest {
|
|
4
|
+
private list;
|
|
5
|
+
protected readonly main: FloatingLive;
|
|
6
|
+
constructor(main: FloatingLive);
|
|
7
|
+
/** 注册manifest */
|
|
8
|
+
register<T extends keyof FloatingManifestMap>(name: T, id: string, value: FloatingManifestMap[T]): void;
|
|
9
|
+
/** 取消注册manifest */
|
|
10
|
+
unregister<T extends keyof FloatingManifestMap>(name: T, id: string): void;
|
|
11
|
+
/** 获取值 */
|
|
12
|
+
get(name: string): Map<string, any> | undefined;
|
|
13
|
+
/** 获取快照 */
|
|
14
|
+
getSnapshot(): Record<string, Record<string, any>>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModManifest = void 0;
|
|
4
|
+
class ModManifest {
|
|
5
|
+
constructor(main) {
|
|
6
|
+
this.list = new Map();
|
|
7
|
+
this.main = main;
|
|
8
|
+
}
|
|
9
|
+
/** 注册manifest */
|
|
10
|
+
register(name, id, value) {
|
|
11
|
+
let store = this.list.get(name);
|
|
12
|
+
if (!store) {
|
|
13
|
+
store = new Map();
|
|
14
|
+
this.list.set(name, store);
|
|
15
|
+
}
|
|
16
|
+
store.set(id, value);
|
|
17
|
+
this.main.emit("manifest:add", name, id, value);
|
|
18
|
+
}
|
|
19
|
+
/** 取消注册manifest */
|
|
20
|
+
unregister(name, id) {
|
|
21
|
+
let store = this.list.get(name);
|
|
22
|
+
if (store) {
|
|
23
|
+
store.delete(id);
|
|
24
|
+
this.main.emit("manifest:remove", name, id);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** 获取值 */
|
|
28
|
+
get(name) {
|
|
29
|
+
return this.list.get(name);
|
|
30
|
+
}
|
|
31
|
+
/** 获取快照 */
|
|
32
|
+
getSnapshot() {
|
|
33
|
+
const map = {};
|
|
34
|
+
this.list.forEach((store, name) => {
|
|
35
|
+
const part = {};
|
|
36
|
+
map[name] = part;
|
|
37
|
+
store.forEach((value, id) => {
|
|
38
|
+
part[id] = value;
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
return map;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ModManifest = ModManifest;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FloatingLive } from "../live";
|
|
2
|
+
import { PluginConstructor } from "../types/plugin";
|
|
3
|
+
export declare class ModPlugin {
|
|
4
|
+
private current;
|
|
5
|
+
/** 插件列表 */
|
|
6
|
+
private list;
|
|
7
|
+
protected readonly main: FloatingLive;
|
|
8
|
+
constructor(main: FloatingLive);
|
|
9
|
+
/** 获取当前安装插件 */
|
|
10
|
+
get currentPlugin(): string | null;
|
|
11
|
+
/** 注册插件 */
|
|
12
|
+
register(pluginFunc: PluginConstructor, options?: any): void;
|
|
13
|
+
/** 移除插件 */
|
|
14
|
+
unregister(name: string): void;
|
|
15
|
+
}
|
|
@@ -6,50 +6,44 @@ class ModPlugin {
|
|
|
6
6
|
this.current = null;
|
|
7
7
|
/** 插件列表 */
|
|
8
8
|
this.list = new Map();
|
|
9
|
-
this.pluginEvent = new Map();
|
|
10
|
-
this.exports = new Map();
|
|
11
9
|
this.main = main;
|
|
12
10
|
}
|
|
13
11
|
/** 获取当前安装插件 */
|
|
14
12
|
get currentPlugin() {
|
|
15
13
|
return this.current;
|
|
16
14
|
}
|
|
17
|
-
addPluginEvent(eventName, listener) {
|
|
18
|
-
if (this.currentPlugin) {
|
|
19
|
-
if (!this.pluginEvent.has(this.currentPlugin)) {
|
|
20
|
-
this.pluginEvent.set(this.currentPlugin, []);
|
|
21
|
-
}
|
|
22
|
-
this.pluginEvent.get(this.currentPlugin)?.push([eventName, listener]);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/** 访问插件操作对象 */
|
|
26
|
-
access(name) {
|
|
27
|
-
return this.exports.get(name);
|
|
28
|
-
}
|
|
29
15
|
/** 注册插件 */
|
|
30
|
-
register(pluginFunc,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
register(pluginFunc, options) {
|
|
17
|
+
const name = pluginFunc.name;
|
|
18
|
+
if (!name) {
|
|
19
|
+
this.main.throw(Object.assign(new TypeError("缺少插件id"), {
|
|
20
|
+
from: "plugin",
|
|
21
|
+
signal: "plugin_id_missing",
|
|
22
|
+
}));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
34
25
|
if (this.list.has(name)) {
|
|
35
|
-
this.main.
|
|
26
|
+
this.main.throw(Object.assign(new Error("插件id重复"), {
|
|
27
|
+
from: "plugin",
|
|
28
|
+
signal: "plugin_id_duplicate",
|
|
29
|
+
}));
|
|
36
30
|
return;
|
|
37
31
|
}
|
|
32
|
+
// 执行插件函数
|
|
33
|
+
const plugin = new pluginFunc(this.main, options);
|
|
38
34
|
this.list.set(name, plugin);
|
|
39
|
-
this.current = name;
|
|
40
|
-
// 调用register函数,并保存获取值
|
|
41
|
-
let pluginExpose = plugin.register?.(this.main, pluginConfig) || {};
|
|
42
|
-
this.exports.set(name, pluginExpose);
|
|
43
35
|
this.main.emit("plugin:add", name);
|
|
44
36
|
this.current = null;
|
|
45
|
-
return pluginExpose;
|
|
46
37
|
}
|
|
47
38
|
/** 移除插件 */
|
|
48
39
|
unregister(name) {
|
|
49
40
|
const plugin = this.list.get(name);
|
|
50
41
|
// 检测插件是否存在
|
|
51
42
|
if (!plugin) {
|
|
52
|
-
this.main.
|
|
43
|
+
this.main.throw(Object.assign(new Error("插件不存在"), {
|
|
44
|
+
from: "plugin",
|
|
45
|
+
signal: "plugin_unexist",
|
|
46
|
+
}));
|
|
53
47
|
return;
|
|
54
48
|
}
|
|
55
49
|
// 获取该插件的销毁函数
|