floating-live 0.15.0-beta.1 → 0.15.0-beta.11
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/dist/core/LiveRoom.d.ts +5 -5
- 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 -17
- package/dist/live.js +27 -39
- package/dist/module/command.d.ts +18 -0
- package/dist/module/command.js +33 -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 -10
- 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/command.js +2 -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 -0
- package/dist/types/index.js +5 -0
- package/dist/types/manifest.d.ts +4 -0
- package/dist/types/manifest.js +2 -0
- package/dist/types/message.d.ts +44 -6
- package/dist/types/plugin.d.ts +9 -2
- package/dist/types/room.d.ts +29 -16
- package/dist/types/value.d.ts +2 -0
- package/dist/types/value.js +2 -0
- package/package.json +1 -1
- package/dist/core/Reglist.d.ts +0 -29
- package/dist/core/Reglist.js +0 -69
- 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 -155
- package/dist/module/ModState.d.ts +0 -12
- package/dist/module/ModState.js +0 -29
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,10 +23,10 @@ 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
|
/** 关闭连接 */
|
|
@@ -34,10 +34,10 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
|
|
|
34
34
|
/** 从服务器获取信息 */
|
|
35
35
|
abstract getInfo(): Promise<void>;
|
|
36
36
|
/** 销毁事件 */
|
|
37
|
-
protected
|
|
37
|
+
protected onDestroy?(): void;
|
|
38
38
|
/** 销毁 */
|
|
39
39
|
destroy(): void;
|
|
40
|
-
protected
|
|
40
|
+
protected emitMessage(msg: Message.All): void;
|
|
41
41
|
protected emitRaw(msg: any): void;
|
|
42
42
|
get info(): RoomInfo;
|
|
43
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,27 +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
|
|
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";
|
|
8
11
|
export declare class FloatingLive extends EventEmitter {
|
|
9
12
|
/** 房间控制模块 */
|
|
10
13
|
room: ModRoom;
|
|
11
|
-
/** 消息处理模块 */
|
|
12
|
-
message: ModMessage;
|
|
13
14
|
/** 插件处理模块 */
|
|
14
|
-
plugin: ModPlugin
|
|
15
|
+
plugin: ModPlugin;
|
|
15
16
|
/** 命令模块 */
|
|
16
17
|
command: ModCommand;
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
|
|
18
|
+
/** Manifest模块 */
|
|
19
|
+
manifest: ModManifest;
|
|
20
|
+
/** 数值模块 */
|
|
21
|
+
value: ModValue;
|
|
22
|
+
/** 钩子模块 */
|
|
23
|
+
hook: ModHook;
|
|
21
24
|
constructor();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
};
|
|
27
35
|
}
|
package/dist/live.js
CHANGED
|
@@ -1,54 +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
|
|
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");
|
|
13
11
|
class FloatingLive extends events_1.EventEmitter {
|
|
14
12
|
constructor() {
|
|
15
13
|
super();
|
|
16
|
-
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.message = new ModMessage_1.ModMessage(this);
|
|
23
|
-
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);
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// 设置在插件卸载时移除由插件注册的事件
|
|
28
|
-
this.on("plugin:remove", (name) => {
|
|
29
|
-
this.regEventMap.get(name)?.forEach(([eventName, listener]) => {
|
|
30
|
-
this.removeListener(eventName, listener);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
21
|
+
call(name, ...args) {
|
|
22
|
+
return this.command.call(name, ...args);
|
|
33
23
|
}
|
|
34
|
-
/** 重写事件监听 */
|
|
35
24
|
on(eventName, listener) {
|
|
36
|
-
super.on(eventName, listener);
|
|
37
|
-
// 检测是否为插件添加事件,并添加进事件列表
|
|
38
|
-
if (this.plugin.currentPlugin) {
|
|
39
|
-
if (!this.regEventMap.has(this.plugin.currentPlugin)) {
|
|
40
|
-
this.regEventMap.set(this.plugin.currentPlugin, []);
|
|
41
|
-
}
|
|
42
|
-
this.regEventMap
|
|
43
|
-
.get(this.plugin.currentPlugin)
|
|
44
|
-
?.push([eventName, listener]);
|
|
45
|
-
}
|
|
46
|
-
return this;
|
|
25
|
+
return super.on(eventName, listener);
|
|
47
26
|
}
|
|
48
27
|
emit(eventName, ...args) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
};
|
|
52
40
|
}
|
|
53
41
|
}
|
|
54
42
|
exports.FloatingLive = FloatingLive;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
has<T extends keyof FloatingCommandMap>(name: T): boolean;
|
|
16
|
+
/** 获取快照 */
|
|
17
|
+
getSnapshot(): string[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
has(name) {
|
|
26
|
+
return this.list.has(name);
|
|
27
|
+
}
|
|
28
|
+
/** 获取快照 */
|
|
29
|
+
getSnapshot() {
|
|
30
|
+
return [...this.list].map(([key]) => key);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
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
|
// 获取该插件的销毁函数
|
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
import { Reglist } from "../core/Reglist";
|
|
2
1
|
import { LiveRoom } from "../core/LiveRoom";
|
|
3
2
|
import { FloatingLive } from "../live";
|
|
4
3
|
import { RoomInfo } from "../types";
|
|
5
4
|
/** 直播间监听实例控制器 */
|
|
6
5
|
export declare class ModRoom {
|
|
6
|
+
private list;
|
|
7
7
|
readonly main: FloatingLive;
|
|
8
|
-
private roomMap;
|
|
9
|
-
private auths;
|
|
10
|
-
private configs;
|
|
11
|
-
generator: Reglist<(id: string | number, open?: boolean, config?: object) => LiveRoom>;
|
|
12
8
|
constructor(main: FloatingLive);
|
|
13
|
-
/** 设置房间配置 */
|
|
14
|
-
setConfig(platform: string, config: any): void;
|
|
15
|
-
/** 生成房间 */
|
|
16
|
-
generate(platform: string, id: string | number, open?: boolean): LiveRoom | undefined;
|
|
17
9
|
/** 添加房间监听实例 */
|
|
18
10
|
addRoom(room: LiveRoom, open?: boolean): void;
|
|
19
11
|
/** 添加房间 */
|
|
20
|
-
add(platform: string, id: number,
|
|
12
|
+
add(platform: string, id: number, options?: boolean | Record<string, any>): void;
|
|
21
13
|
/** 移除房间 */
|
|
22
14
|
remove(roomKey: string): void;
|
|
23
15
|
/** 获取房间 */
|
|
@@ -32,4 +24,8 @@ export declare class ModRoom {
|
|
|
32
24
|
open(roomKey: string): void;
|
|
33
25
|
/** 关闭房间连接 */
|
|
34
26
|
close(roomKey: string): void;
|
|
27
|
+
/** 更改某个房间的顺序 */
|
|
28
|
+
move(roomKey: string, position: number): void;
|
|
29
|
+
/** 获取快照 */
|
|
30
|
+
getSnapshot(): RoomInfo[];
|
|
35
31
|
}
|