floating-live 0.15.11 → 0.16.0-alpha.0
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 +14 -10
- package/dist/FloatingLive.d.ts +6 -0
- package/dist/FloatingLive.js +8 -0
- package/dist/app.d.ts +46 -0
- package/dist/app.js +126 -0
- package/dist/command/index.d.ts +1 -0
- package/dist/command/index.js +1 -0
- package/dist/command/manager.d.ts +23 -0
- package/dist/command/manager.js +46 -0
- package/dist/command/types.d.ts +25 -0
- package/{esm/types/command.js → dist/command/types.js} +1 -1
- package/dist/error/index.d.ts +11 -0
- package/dist/error/index.js +9 -0
- package/dist/error/types.d.ts +6 -0
- package/{esm/types/error.js → dist/error/types.js} +1 -1
- package/dist/event/index.d.ts +1 -0
- package/dist/event/index.js +1 -0
- package/dist/event/manager.d.ts +9 -0
- package/dist/event/manager.js +17 -0
- package/dist/event/types.d.ts +42 -0
- package/{esm/types/events.js → dist/event/types.js} +1 -1
- package/dist/hook/index.d.ts +1 -0
- package/dist/hook/index.js +1 -0
- package/dist/hook/manager.d.ts +25 -0
- package/dist/hook/manager.js +79 -0
- package/dist/hook/types.d.ts +22 -0
- package/{esm/types/hook.js → dist/hook/types.js} +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.js +8 -23
- package/dist/{types → live}/message.d.ts +185 -248
- package/{esm/types → dist/live}/message.js +1 -1
- package/dist/live/messageInfo.d.ts +93 -0
- package/dist/live/messageInfo.js +28 -0
- package/dist/live/platform.d.ts +40 -0
- package/dist/live/platform.js +1 -0
- package/dist/live/room.d.ts +150 -0
- package/dist/live/room.js +120 -0
- package/dist/plugin/context/CommonPluginContext.d.ts +45 -0
- package/dist/plugin/context/CommonPluginContext.js +273 -0
- package/dist/plugin/context/SafePluginContext.d.ts +34 -0
- package/dist/plugin/context/SafePluginContext.js +91 -0
- package/dist/plugin/index.d.ts +8 -0
- package/dist/plugin/index.js +5 -0
- package/dist/plugin/manager.d.ts +31 -0
- package/dist/plugin/manager.js +93 -0
- package/dist/plugin/types.d.ts +73 -0
- package/dist/plugin/types.js +1 -0
- package/dist/plugins/room/index.d.ts +116 -0
- package/dist/plugins/room/index.js +172 -0
- package/dist/utils/EventEmitter.d.ts +6 -0
- package/dist/utils/EventEmitter.js +26 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +4 -0
- package/dist/value/index.d.ts +1 -0
- package/dist/value/index.js +1 -0
- package/dist/value/manager.d.ts +24 -0
- package/dist/value/manager.js +63 -0
- package/dist/value/types.d.ts +19 -0
- package/dist/value/types.js +1 -0
- package/package.json +9 -40
- package/src/source.md +29 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/core/LiveRoom.d.ts +0 -44
- package/dist/core/LiveRoom.js +0 -81
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -17
- package/dist/core/plugin.d.ts +0 -17
- package/dist/core/plugin.js +0 -28
- package/dist/enums.d.ts +0 -51
- package/dist/enums.js +0 -59
- package/dist/live.d.ts +0 -39
- package/dist/live.js +0 -51
- package/dist/module/command.d.ts +0 -18
- package/dist/module/command.js +0 -42
- package/dist/module/hook.d.ts +0 -15
- package/dist/module/hook.js +0 -51
- package/dist/module/manifest.d.ts +0 -15
- package/dist/module/manifest.js +0 -44
- package/dist/module/plugin.d.ts +0 -16
- package/dist/module/plugin.js +0 -85
- package/dist/module/room.d.ts +0 -34
- package/dist/module/room.js +0 -164
- package/dist/module/value.d.ts +0 -26
- package/dist/module/value.js +0 -60
- package/dist/types/command.d.ts +0 -23
- package/dist/types/command.js +0 -2
- package/dist/types/error.d.ts +0 -10
- package/dist/types/error.js +0 -2
- package/dist/types/events.d.ts +0 -41
- package/dist/types/events.js +0 -2
- package/dist/types/hook.d.ts +0 -15
- package/dist/types/hook.js +0 -2
- package/dist/types/index.d.ts +0 -9
- package/dist/types/index.js +0 -25
- package/dist/types/manifest.d.ts +0 -4
- package/dist/types/manifest.js +0 -2
- package/dist/types/message.js +0 -2
- package/dist/types/plugin.d.ts +0 -13
- package/dist/types/plugin.js +0 -2
- package/dist/types/room.d.ts +0 -98
- package/dist/types/room.js +0 -2
- package/dist/types/value.d.ts +0 -2
- package/dist/types/value.js +0 -2
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +0 -21
- package/esm/core/LiveRoom.js +0 -77
- package/esm/core/index.js +0 -1
- package/esm/core/plugin.js +0 -24
- package/esm/enums.js +0 -56
- package/esm/index.js +0 -5
- package/esm/live.js +0 -47
- package/esm/module/command.js +0 -38
- package/esm/module/hook.js +0 -47
- package/esm/module/manifest.js +0 -40
- package/esm/module/plugin.js +0 -81
- package/esm/module/room.js +0 -160
- package/esm/module/value.js +0 -56
- package/esm/types/index.js +0 -9
- package/esm/types/manifest.js +0 -1
- package/esm/types/plugin.js +0 -1
- package/esm/types/room.js +0 -1
- package/esm/types/value.js +0 -1
- package/esm/utils.js +0 -17
package/dist/types/plugin.js
DELETED
package/dist/types/room.d.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { ConnectStatus, RoomStatus } from "../enums";
|
|
2
|
-
import { UserInfo } from "./message";
|
|
3
|
-
/** 房间配置 */
|
|
4
|
-
export interface RoomConfig {
|
|
5
|
-
/** 添加后是否打开房间 */
|
|
6
|
-
open?: boolean;
|
|
7
|
-
/** 口令 */
|
|
8
|
-
tokens?: Record<string, number>;
|
|
9
|
-
/** 凭据 */
|
|
10
|
-
credentials?: string;
|
|
11
|
-
}
|
|
12
|
-
/** 房间信息 */
|
|
13
|
-
export interface RoomInfo {
|
|
14
|
-
/** 平台id */
|
|
15
|
-
platform: string;
|
|
16
|
-
/** 房间id */
|
|
17
|
-
id: number | string;
|
|
18
|
-
/** 房间key */
|
|
19
|
-
key: string;
|
|
20
|
-
/** 基本信息 */
|
|
21
|
-
detail: RoomDetail;
|
|
22
|
-
/** 统计信息 */
|
|
23
|
-
stats?: RoomStatsInfo;
|
|
24
|
-
/** 主播信息 */
|
|
25
|
-
anchor: UserInfo;
|
|
26
|
-
/** 时间戳 */
|
|
27
|
-
timestamp: number;
|
|
28
|
-
/** 当前直播id */
|
|
29
|
-
liveId?: string;
|
|
30
|
-
/** 直播状态 */
|
|
31
|
-
status: RoomStatus;
|
|
32
|
-
/** 直播间是否可用 */
|
|
33
|
-
available: boolean;
|
|
34
|
-
/** 房间监听是否打开 */
|
|
35
|
-
opened: boolean;
|
|
36
|
-
/** 房间连接状态 */
|
|
37
|
-
connection: ConnectStatus;
|
|
38
|
-
}
|
|
39
|
-
/** 房间展示信息 */
|
|
40
|
-
export interface RoomDetail {
|
|
41
|
-
/** 直播标题 */
|
|
42
|
-
title?: string;
|
|
43
|
-
/** 分区 */
|
|
44
|
-
area?: string[];
|
|
45
|
-
/** 封面 */
|
|
46
|
-
cover?: string;
|
|
47
|
-
}
|
|
48
|
-
/** 房间统计数据信息 */
|
|
49
|
-
export interface RoomStatsInfo {
|
|
50
|
-
/** 点赞数 */
|
|
51
|
-
like?: number;
|
|
52
|
-
/** 观看数 */
|
|
53
|
-
view?: number;
|
|
54
|
-
/** 在线人数 */
|
|
55
|
-
online?: number;
|
|
56
|
-
/** 人气值 */
|
|
57
|
-
popularity?: number;
|
|
58
|
-
}
|
|
59
|
-
export interface PlatformInfo {
|
|
60
|
-
/** 平台名称 */
|
|
61
|
-
name: string;
|
|
62
|
-
/** 平台vip信息 */
|
|
63
|
-
vip?: {
|
|
64
|
-
/** 平台vip对应id */
|
|
65
|
-
id: string;
|
|
66
|
-
/** 平台vip名称 */
|
|
67
|
-
name: string;
|
|
68
|
-
/** 平台vip等级名称 */
|
|
69
|
-
level?: string[];
|
|
70
|
-
};
|
|
71
|
-
/** 粉丝vip信息 */
|
|
72
|
-
membership?: {
|
|
73
|
-
/** 粉丝vip对应id */
|
|
74
|
-
id: string;
|
|
75
|
-
/** 粉丝vip名称 */
|
|
76
|
-
name: string;
|
|
77
|
-
/** 粉丝vip等级名称 */
|
|
78
|
-
level?: string[];
|
|
79
|
-
};
|
|
80
|
-
/** 礼物信息 */
|
|
81
|
-
gift?: {
|
|
82
|
-
/** 默认送出礼物行为 */
|
|
83
|
-
action: string;
|
|
84
|
-
};
|
|
85
|
-
/** 统计信息 */
|
|
86
|
-
stats?: Record<string, string>;
|
|
87
|
-
/** 货币信息 */
|
|
88
|
-
currency?: {
|
|
89
|
-
[key: string | number]: {
|
|
90
|
-
/** 货币名称 */
|
|
91
|
-
name: string;
|
|
92
|
-
/** 1货币面值等值value (1面值/1数值) */
|
|
93
|
-
ratio: number;
|
|
94
|
-
/** 1单位消费金额等值value (1.00CNY/1数值) (若为0则为免费货币) */
|
|
95
|
-
money?: number;
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
}
|
package/dist/types/room.js
DELETED
package/dist/types/value.d.ts
DELETED
package/dist/types/value.js
DELETED
package/dist/utils.d.ts
DELETED
package/dist/utils.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateId = void 0;
|
|
4
|
-
function generateId(msg) {
|
|
5
|
-
switch (msg.type) {
|
|
6
|
-
case "gift":
|
|
7
|
-
return `gift:${msg.info.user.id}-${msg.timestamp}`;
|
|
8
|
-
case "superchat":
|
|
9
|
-
return `superchat:${msg.info.id}`;
|
|
10
|
-
case "membership":
|
|
11
|
-
return `membership:${msg.info.user.id}-${msg.info.level || 0}-${msg.timestamp}`;
|
|
12
|
-
default:
|
|
13
|
-
if (/^live_/.test(msg.type)) {
|
|
14
|
-
return `${msg.type}:${msg.platform}:${msg.room}-${msg.timestamp}`;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
return `${msg.type}:${msg.info.user?.id || 0}-${msg.timestamp}`;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.generateId = generateId;
|
package/esm/core/LiveRoom.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "events";
|
|
2
|
-
import { ConnectStatus, RoomStatus } from "../enums";
|
|
3
|
-
export class LiveRoom extends EventEmitter {
|
|
4
|
-
constructor() {
|
|
5
|
-
super();
|
|
6
|
-
/** 直播状态 */
|
|
7
|
-
this.status = RoomStatus.off;
|
|
8
|
-
/** 时间戳 */
|
|
9
|
-
this.timestamp = 0;
|
|
10
|
-
/** 房间是否打开 */
|
|
11
|
-
this.opened = false;
|
|
12
|
-
/** 是否连接上房间 */
|
|
13
|
-
this.connection = ConnectStatus.off;
|
|
14
|
-
}
|
|
15
|
-
/** 销毁 */
|
|
16
|
-
destroy() {
|
|
17
|
-
this.close();
|
|
18
|
-
this.removeAllListeners();
|
|
19
|
-
this.onDestroy?.();
|
|
20
|
-
}
|
|
21
|
-
// 发送消息
|
|
22
|
-
emitMessage(msg) {
|
|
23
|
-
// 其他消息 => 先更改状态再发送消息
|
|
24
|
-
// 直播结束消息 => 先发送消息再更改状态
|
|
25
|
-
switch (msg.type) {
|
|
26
|
-
case "live_start":
|
|
27
|
-
this.status = RoomStatus.live;
|
|
28
|
-
this.timestamp = msg.timestamp;
|
|
29
|
-
this.emit("status", RoomStatus.live, {
|
|
30
|
-
timestamp: msg.timestamp,
|
|
31
|
-
id: msg.info.id,
|
|
32
|
-
});
|
|
33
|
-
break;
|
|
34
|
-
case "live_detail":
|
|
35
|
-
this.detail = Object.assign(this.detail, msg.info);
|
|
36
|
-
this.emit("detail", msg.info);
|
|
37
|
-
break;
|
|
38
|
-
case "live_stats":
|
|
39
|
-
this.stats = Object.assign(this.stats, msg.info);
|
|
40
|
-
this.emit("stats", msg.info);
|
|
41
|
-
break;
|
|
42
|
-
case "live_end":
|
|
43
|
-
case "live_cut":
|
|
44
|
-
this.status = msg.status || RoomStatus.off;
|
|
45
|
-
this.timestamp = msg.timestamp;
|
|
46
|
-
this.emit("message", msg);
|
|
47
|
-
this.emit("status", msg.status || RoomStatus.off, {
|
|
48
|
-
timestamp: msg.timestamp,
|
|
49
|
-
});
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
this.emit("message", msg);
|
|
53
|
-
}
|
|
54
|
-
// 发送源消息
|
|
55
|
-
emitRaw(msg) {
|
|
56
|
-
this.emit("raw", msg, { platform: this.platform, room: this.id });
|
|
57
|
-
}
|
|
58
|
-
get info() {
|
|
59
|
-
return {
|
|
60
|
-
platform: this.platform,
|
|
61
|
-
id: this.id,
|
|
62
|
-
detail: this.detail,
|
|
63
|
-
stats: this.stats,
|
|
64
|
-
anchor: this.anchor,
|
|
65
|
-
timestamp: this.timestamp,
|
|
66
|
-
status: this.status,
|
|
67
|
-
liveId: this.liveId,
|
|
68
|
-
available: this.available,
|
|
69
|
-
opened: this.opened,
|
|
70
|
-
connection: this.connection,
|
|
71
|
-
key: this.key,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
get key() {
|
|
75
|
-
return `${this.platform}:${this.id}`;
|
|
76
|
-
}
|
|
77
|
-
}
|
package/esm/core/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./LiveRoom";
|
package/esm/core/plugin.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export class BasePlugin {
|
|
2
|
-
constructor(main) {
|
|
3
|
-
this.registerList = [];
|
|
4
|
-
this.main = main;
|
|
5
|
-
}
|
|
6
|
-
/** 插件监听事件 */
|
|
7
|
-
on(eventName, listener) {
|
|
8
|
-
this.main.on(eventName, listener);
|
|
9
|
-
this.registerList.push(["event", eventName, listener]);
|
|
10
|
-
}
|
|
11
|
-
/** 插件一次性监听事件 */
|
|
12
|
-
once(eventName, listener) {
|
|
13
|
-
this.main.once(eventName, listener);
|
|
14
|
-
this.registerList.push(["event", eventName, listener]);
|
|
15
|
-
}
|
|
16
|
-
/** 插件移除监听事件 */
|
|
17
|
-
off(eventName, listener) {
|
|
18
|
-
this.main.off(eventName, listener);
|
|
19
|
-
}
|
|
20
|
-
/** 插件发送事件 */
|
|
21
|
-
emit(eventName, ...args) {
|
|
22
|
-
this.main.emit(eventName, ...args);
|
|
23
|
-
}
|
|
24
|
-
}
|
package/esm/enums.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/** 直播间状态 */
|
|
2
|
-
export var RoomStatus;
|
|
3
|
-
(function (RoomStatus) {
|
|
4
|
-
/** 未开播 */
|
|
5
|
-
RoomStatus[RoomStatus["off"] = 0] = "off";
|
|
6
|
-
/** 正在直播 */
|
|
7
|
-
RoomStatus[RoomStatus["live"] = 1] = "live";
|
|
8
|
-
/** 正在轮播 */
|
|
9
|
-
RoomStatus[RoomStatus["round"] = 2] = "round";
|
|
10
|
-
/** 被封禁 */
|
|
11
|
-
RoomStatus[RoomStatus["banned"] = -1] = "banned";
|
|
12
|
-
/** 已上锁 */
|
|
13
|
-
RoomStatus[RoomStatus["locked"] = -2] = "locked";
|
|
14
|
-
})(RoomStatus || (RoomStatus = {}));
|
|
15
|
-
/** 直播间状态 */
|
|
16
|
-
export var ConnectStatus;
|
|
17
|
-
(function (ConnectStatus) {
|
|
18
|
-
/** 未连接 */
|
|
19
|
-
ConnectStatus[ConnectStatus["off"] = 0] = "off";
|
|
20
|
-
/** 连接中 */
|
|
21
|
-
ConnectStatus[ConnectStatus["connecting"] = 1] = "connecting";
|
|
22
|
-
/** 连接到服务器 */
|
|
23
|
-
ConnectStatus[ConnectStatus["connected"] = 2] = "connected";
|
|
24
|
-
/** 连接到房间 */
|
|
25
|
-
ConnectStatus[ConnectStatus["entered"] = 3] = "entered";
|
|
26
|
-
/** 连接失败或断开 */
|
|
27
|
-
ConnectStatus[ConnectStatus["disconnected"] = -1] = "disconnected";
|
|
28
|
-
})(ConnectStatus || (ConnectStatus = {}));
|
|
29
|
-
/** 图片大小 */
|
|
30
|
-
export var ImageSize;
|
|
31
|
-
(function (ImageSize) {
|
|
32
|
-
/** 自定义大小 */
|
|
33
|
-
ImageSize[ImageSize["custom"] = 0] = "custom";
|
|
34
|
-
/** 小表情(文字行高) */
|
|
35
|
-
ImageSize[ImageSize["small"] = 1] = "small";
|
|
36
|
-
/** 大表情 */
|
|
37
|
-
ImageSize[ImageSize["large"] = 2] = "large";
|
|
38
|
-
})(ImageSize || (ImageSize = {}));
|
|
39
|
-
/** 弹幕模式 */
|
|
40
|
-
export var DanmakuMode;
|
|
41
|
-
(function (DanmakuMode) {
|
|
42
|
-
DanmakuMode[DanmakuMode["left"] = 1] = "left";
|
|
43
|
-
DanmakuMode[DanmakuMode["bottom"] = 4] = "bottom";
|
|
44
|
-
DanmakuMode[DanmakuMode["top"] = 5] = "top";
|
|
45
|
-
DanmakuMode[DanmakuMode["right"] = 6] = "right";
|
|
46
|
-
})(DanmakuMode || (DanmakuMode = {}));
|
|
47
|
-
/** 用户类型 */
|
|
48
|
-
export var UserType;
|
|
49
|
-
(function (UserType) {
|
|
50
|
-
/** 普通观众 */
|
|
51
|
-
UserType[UserType["normal"] = 0] = "normal";
|
|
52
|
-
/** 房管 */
|
|
53
|
-
UserType[UserType["admin"] = 1] = "admin";
|
|
54
|
-
/** 主播 */
|
|
55
|
-
UserType[UserType["anchor"] = 2] = "anchor";
|
|
56
|
-
})(UserType || (UserType = {}));
|
package/esm/index.js
DELETED
package/esm/live.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "events";
|
|
2
|
-
import { ModPlugin } from "./module/plugin";
|
|
3
|
-
import { ModRoom } from "./module/room";
|
|
4
|
-
import { ModManifest } from "./module/manifest";
|
|
5
|
-
import { ModCommand } from "./module/command";
|
|
6
|
-
import { ModValue } from "./module/value";
|
|
7
|
-
import { ModHook } from "./module/hook";
|
|
8
|
-
export class FloatingLive extends EventEmitter {
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
this.command = new ModCommand(this);
|
|
12
|
-
this.manifest = new ModManifest(this);
|
|
13
|
-
this.plugin = new ModPlugin(this);
|
|
14
|
-
this.room = new ModRoom(this);
|
|
15
|
-
this.value = new ModValue(this);
|
|
16
|
-
this.hook = new ModHook(this);
|
|
17
|
-
}
|
|
18
|
-
call(name, ...args) {
|
|
19
|
-
return this.command.call(name, ...args);
|
|
20
|
-
}
|
|
21
|
-
on(eventName, listener) {
|
|
22
|
-
return super.on(eventName, listener);
|
|
23
|
-
}
|
|
24
|
-
emit(eventName, ...args) {
|
|
25
|
-
const emit = super.emit(eventName, ...args);
|
|
26
|
-
super.emit("event", eventName, ...args);
|
|
27
|
-
return emit;
|
|
28
|
-
}
|
|
29
|
-
throw(err, options) {
|
|
30
|
-
if (err instanceof Error) {
|
|
31
|
-
throw Object.assign(err, options);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
throw Object.assign(new Error(), err);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
getSnapshot() {
|
|
38
|
-
return {
|
|
39
|
-
room: this.room.getSnapshot(),
|
|
40
|
-
value: this.value.getSnapshot(),
|
|
41
|
-
manifest: this.manifest.getSnapshot(),
|
|
42
|
-
command: this.command.getSnapshot(),
|
|
43
|
-
hook: this.hook.getSnapshot(),
|
|
44
|
-
plugin: this.plugin.getSnapshot(),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
package/esm/module/command.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export class ModCommand {
|
|
2
|
-
constructor(main) {
|
|
3
|
-
/** 功能列表 */
|
|
4
|
-
this.list = new Map();
|
|
5
|
-
this.main = main;
|
|
6
|
-
}
|
|
7
|
-
/** 注册命令 */
|
|
8
|
-
register(name, func) {
|
|
9
|
-
this.list.set(name, func);
|
|
10
|
-
this.main.emit("command:add", name);
|
|
11
|
-
}
|
|
12
|
-
/** 取消注册命令 */
|
|
13
|
-
unregister(name) {
|
|
14
|
-
this.list.delete(name);
|
|
15
|
-
this.main.emit("command:remove", name);
|
|
16
|
-
}
|
|
17
|
-
/** 调用命令 */
|
|
18
|
-
call(name, ...args) {
|
|
19
|
-
const command = this.list.get(name);
|
|
20
|
-
if (!command) {
|
|
21
|
-
this.main.throw({
|
|
22
|
-
message: "命令不存在",
|
|
23
|
-
id: "command:call_unexist",
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return command(...args);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/** 检测命令是否存在 */
|
|
31
|
-
has(name) {
|
|
32
|
-
return this.list.has(name);
|
|
33
|
-
}
|
|
34
|
-
/** 获取快照 */
|
|
35
|
-
getSnapshot() {
|
|
36
|
-
return [...this.list].map(([key]) => key);
|
|
37
|
-
}
|
|
38
|
-
}
|
package/esm/module/hook.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export class ModHook {
|
|
2
|
-
constructor(main) {
|
|
3
|
-
this.list = new Map();
|
|
4
|
-
this.main = main;
|
|
5
|
-
}
|
|
6
|
-
/** 注册钩子函数 */
|
|
7
|
-
register(name, func) {
|
|
8
|
-
let hooks = this.list.get(name);
|
|
9
|
-
if (!hooks) {
|
|
10
|
-
hooks = [];
|
|
11
|
-
this.list.set(name, hooks);
|
|
12
|
-
}
|
|
13
|
-
hooks.push(func);
|
|
14
|
-
}
|
|
15
|
-
/** 取消注册钩子函数 */
|
|
16
|
-
unregister(name, func) {
|
|
17
|
-
let hooks = this.list.get(name);
|
|
18
|
-
if (hooks) {
|
|
19
|
-
const index = hooks.indexOf(func);
|
|
20
|
-
index > -1 && hooks.splice(index, 1);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/** 调用钩子函数 */
|
|
24
|
-
async call(name, ctx) {
|
|
25
|
-
const hooks = this.list.get(name);
|
|
26
|
-
if (!hooks) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
for (const func of hooks) {
|
|
30
|
-
const result = await func(ctx);
|
|
31
|
-
if (result == true) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
else if (result == false) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
getSnapshot() {
|
|
41
|
-
const map = {};
|
|
42
|
-
this.list.forEach((fnList, name) => {
|
|
43
|
-
map[name] = fnList.length;
|
|
44
|
-
});
|
|
45
|
-
return map;
|
|
46
|
-
}
|
|
47
|
-
}
|
package/esm/module/manifest.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export class ModManifest {
|
|
2
|
-
constructor(main) {
|
|
3
|
-
this.list = new Map();
|
|
4
|
-
this.main = main;
|
|
5
|
-
}
|
|
6
|
-
/** 注册manifest */
|
|
7
|
-
register(name, id, value) {
|
|
8
|
-
let store = this.list.get(name);
|
|
9
|
-
if (!store) {
|
|
10
|
-
store = new Map();
|
|
11
|
-
this.list.set(name, store);
|
|
12
|
-
}
|
|
13
|
-
store.set(id, value);
|
|
14
|
-
this.main.emit("manifest:add", name, id, value);
|
|
15
|
-
}
|
|
16
|
-
/** 取消注册manifest */
|
|
17
|
-
unregister(name, id) {
|
|
18
|
-
let store = this.list.get(name);
|
|
19
|
-
if (store) {
|
|
20
|
-
store.delete(id);
|
|
21
|
-
this.main.emit("manifest:remove", name, id);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/** 获取值 */
|
|
25
|
-
get(name) {
|
|
26
|
-
return this.list.get(name);
|
|
27
|
-
}
|
|
28
|
-
/** 获取快照 */
|
|
29
|
-
getSnapshot() {
|
|
30
|
-
const map = {};
|
|
31
|
-
this.list.forEach((store, name) => {
|
|
32
|
-
const part = {};
|
|
33
|
-
map[name] = part;
|
|
34
|
-
store.forEach((value, id) => {
|
|
35
|
-
part[id] = value;
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
return map;
|
|
39
|
-
}
|
|
40
|
-
}
|
package/esm/module/plugin.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
export class ModPlugin {
|
|
2
|
-
constructor(main) {
|
|
3
|
-
/** 插件列表 */
|
|
4
|
-
this.list = new Map();
|
|
5
|
-
this.main = main;
|
|
6
|
-
}
|
|
7
|
-
/** 注册插件 */
|
|
8
|
-
async register(pluginFunc, options = {}) {
|
|
9
|
-
const name = pluginFunc.pluginName;
|
|
10
|
-
if (!name) {
|
|
11
|
-
this.main.throw({
|
|
12
|
-
message: "添加插件失败",
|
|
13
|
-
reason: "缺少插件id",
|
|
14
|
-
id: "plugin:register_id_missing",
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
if (this.list.has(name)) {
|
|
18
|
-
this.main.throw({
|
|
19
|
-
message: `添加插件失败: ${name}`,
|
|
20
|
-
reason: "已存在相同id的插件",
|
|
21
|
-
id: "plugin:register_id_duplicate",
|
|
22
|
-
pluginName: name,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
const ctx = { name, options };
|
|
26
|
-
return await this.main.hook
|
|
27
|
-
.call("plugin.register", ctx)
|
|
28
|
-
.then(async (res) => {
|
|
29
|
-
if (!res)
|
|
30
|
-
return;
|
|
31
|
-
// 执行插件函数
|
|
32
|
-
const plugin = new pluginFunc(this.main, ctx.options || {});
|
|
33
|
-
// 调用插件的register钩子
|
|
34
|
-
await plugin.register?.(this.main, ctx.options || {});
|
|
35
|
-
this.list.set(name, plugin);
|
|
36
|
-
this.main.emit("plugin:add", name);
|
|
37
|
-
return plugin;
|
|
38
|
-
})
|
|
39
|
-
.catch((err) => {
|
|
40
|
-
this.main.throw({
|
|
41
|
-
message: `添加插件失败: ${name}`,
|
|
42
|
-
reason: err?.message && err?.reason
|
|
43
|
-
? `${err.message}: ${err.reason}`
|
|
44
|
-
: err?.message || err?.reason,
|
|
45
|
-
id: "plugin:register_fail",
|
|
46
|
-
pluginName: name,
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
/** 移除插件 */
|
|
51
|
-
async unregister(name) {
|
|
52
|
-
const plugin = this.list.get(name);
|
|
53
|
-
// 检测插件是否存在
|
|
54
|
-
if (!plugin) {
|
|
55
|
-
this.main.throw({
|
|
56
|
-
message: `移除插件失败: ${name}`,
|
|
57
|
-
reason: "插件不存在",
|
|
58
|
-
id: "plugin:unregister_unexist",
|
|
59
|
-
pluginName: name,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
// 调用该插件的destroy钩子
|
|
64
|
-
await plugin.destroy?.();
|
|
65
|
-
// 从列表中移除插件
|
|
66
|
-
this.list.delete(name);
|
|
67
|
-
// 移除插件注册
|
|
68
|
-
this.main.emit("plugin:remove", name);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/** 获取插件实例 */
|
|
72
|
-
get(name) {
|
|
73
|
-
return this.list.get(name);
|
|
74
|
-
}
|
|
75
|
-
has(name) {
|
|
76
|
-
return this.list.has(name);
|
|
77
|
-
}
|
|
78
|
-
getSnapshot() {
|
|
79
|
-
return [...this.list.keys()];
|
|
80
|
-
}
|
|
81
|
-
}
|