floating-live 0.8.7 → 0.10.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 +6 -4
- package/index.d.ts +7 -2
- package/index.js +23 -4
- package/package.json +1 -1
- package/plugin/acfun/acfunLive.d.ts +24 -30
- package/plugin/acfun/acfunLive.js +38 -51
- package/plugin/acfun/index.d.ts +1 -1
- package/plugin/acfun/index.js +1 -3
- package/plugin/bilibili/bilibiliLive.d.ts +7 -15
- package/plugin/bilibili/bilibiliLive.js +86 -117
- package/plugin/bilibili/index.d.ts +1 -1
- package/plugin/bilibili/index.js +1 -3
- package/plugin/chatPrint/chatPrint.d.ts +6 -7
- package/plugin/chatPrint/chatPrint.js +12 -18
- package/plugin/chatPrint/index.d.ts +2 -2
- package/plugin/chatPrint/index.js +2 -5
- package/plugin/consoleEvent/index.d.ts +1 -1
- package/plugin/consoleEvent/index.js +14 -2
- package/plugin/msgSave/index.d.ts +1 -1
- package/plugin/msgSave/index.js +6 -6
- package/plugin/msgSave/msgSave.d.ts +3 -3
- package/src/index.d.ts +51 -25
- package/src/index.js +98 -41
- package/src/lib/LiveRoom.d.ts +88 -0
- package/src/lib/LiveRoom.js +72 -0
- package/src/lib/{Registerable.d.ts → Reglist.d.ts} +6 -8
- package/src/lib/{Registerable.js → Reglist.js} +13 -19
- package/src/module/Command.d.ts +2 -0
- package/src/{types/room/RoomInfo.js → module/Command.js} +4 -0
- package/src/module/Plugin.d.ts +24 -0
- package/src/module/Plugin.js +74 -0
- package/src/{controller → module}/Room.d.ts +7 -13
- package/src/{controller → module}/Room.js +24 -16
- package/src/types/message/AttributeInfo.d.ts +8 -6
- package/src/types/message/MessageData.d.ts +132 -44
- package/src/types/plugin/Plugin.d.ts +4 -2
- package/src/types/room/PlatformInfo.d.ts +1 -1
- package/plugin/chat/ChatCommand.d.ts +0 -9
- package/plugin/chat/ChatCommand.js +0 -39
- package/plugin/chat/ChatFilter.d.ts +0 -9
- package/plugin/chat/ChatFilter.js +0 -44
- package/plugin/chat/chatProcessor.d.ts +0 -12
- package/plugin/chat/chatProcessor.js +0 -24
- package/src/controller/Message.d.ts +0 -9
- package/src/controller/Message.js +0 -15
- package/src/controller/index.d.ts +0 -39
- package/src/controller/index.js +0 -74
- package/src/types/message/MessageInfo.d.ts +0 -123
- package/src/types/message/MessageInfo.js +0 -2
- package/src/types/room/LiveInfo.d.ts +0 -24
- package/src/types/room/LiveInfo.js +0 -2
- package/src/types/room/LiveRoom.d.ts +0 -20
- package/src/types/room/LiveRoom.js +0 -2
- package/src/types/room/RoomInfo.d.ts +0 -16
- package/src/utils/getRoomInfo.d.ts +0 -4
- package/src/utils/getRoomInfo.js +0 -25
package/src/index.d.ts
CHANGED
|
@@ -1,33 +1,59 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
|
-
import {
|
|
4
|
-
import LiveRoom from "./
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}>;
|
|
3
|
+
import { Reglist } from "./lib/Reglist";
|
|
4
|
+
import { LiveRoom } from "./lib/LiveRoom";
|
|
5
|
+
import { MessageData } from "./types/message/MessageData";
|
|
6
|
+
import { PluginHandler } from "./module/Plugin";
|
|
7
|
+
import { RoomController } from "./module/Room";
|
|
8
|
+
export declare class FloatingLive extends EventEmitter {
|
|
9
|
+
/** 房间控制模块 */
|
|
10
|
+
room: RoomController;
|
|
11
|
+
/** 插件处理模块 */
|
|
12
|
+
plugin: PluginHandler<this>;
|
|
14
13
|
helper: {
|
|
15
14
|
/** 房间生成器 */
|
|
16
|
-
roomGenerator:
|
|
17
|
-
key: string;
|
|
18
|
-
room: LiveRoom;
|
|
19
|
-
}>;
|
|
15
|
+
roomGenerator: Reglist<(id: string | number, open?: boolean) => LiveRoom>;
|
|
20
16
|
/** 消息处理 */
|
|
21
|
-
messageHandler:
|
|
17
|
+
messageHandler: Reglist<(msg: MessageData) => void>;
|
|
18
|
+
/** 插件销毁 */
|
|
19
|
+
pluginDestory: Reglist<() => void>;
|
|
20
|
+
/** 添加插件 */
|
|
21
|
+
pluginAddHandler: Reglist<(name: string) => void>;
|
|
22
|
+
/** 移除插件 */
|
|
23
|
+
pluginRemoveHandler: Reglist<(name: string) => void>;
|
|
22
24
|
};
|
|
25
|
+
/** 插件事件注册表 */
|
|
26
|
+
private pluginEventMap;
|
|
27
|
+
/** 状态 */
|
|
28
|
+
private status;
|
|
29
|
+
get started(): boolean;
|
|
30
|
+
get timestamp(): number;
|
|
23
31
|
constructor();
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
+
/** 初始化 */
|
|
33
|
+
private init;
|
|
34
|
+
/** 开始 */
|
|
35
|
+
start(): void;
|
|
36
|
+
/** 结束 */
|
|
37
|
+
end(): void;
|
|
38
|
+
/** 添加房间 */
|
|
39
|
+
addRoom({ platform, id }: {
|
|
40
|
+
platform: string;
|
|
41
|
+
id: string | number;
|
|
42
|
+
}, open?: boolean): void;
|
|
43
|
+
/** 移除房间 */
|
|
44
|
+
removeRoom(roomKey: string): void;
|
|
45
|
+
/** 添加房间实例 */
|
|
46
|
+
addLiveRoom(room: LiveRoom): void;
|
|
47
|
+
/** 打开房间 */
|
|
48
|
+
openRoom(roomKey: string): void;
|
|
49
|
+
/** 关闭房间 */
|
|
50
|
+
closeRoom(roomKey: string): void;
|
|
51
|
+
/** 打开所有房间 */
|
|
52
|
+
openAllRooms(): void;
|
|
53
|
+
/** 关闭所有房间 */
|
|
54
|
+
closeAllRooms(): void;
|
|
55
|
+
/** 更新房间信息 */
|
|
56
|
+
updateRoomInfo(roomKey: string): void;
|
|
57
|
+
/** 重写事件监听 */
|
|
58
|
+
on(eventName: string, listener: (...args: any[]) => void): this;
|
|
32
59
|
}
|
|
33
|
-
export default FloatingLive;
|
package/src/index.js
CHANGED
|
@@ -1,54 +1,111 @@
|
|
|
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 });
|
|
3
|
+
exports.FloatingLive = void 0;
|
|
6
4
|
const events_1 = require("events");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
5
|
+
const Reglist_1 = require("./lib/Reglist");
|
|
6
|
+
const Plugin_1 = require("./module/Plugin");
|
|
7
|
+
const Room_1 = require("./module/Room");
|
|
9
8
|
class FloatingLive extends events_1.EventEmitter {
|
|
10
9
|
constructor() {
|
|
11
10
|
super();
|
|
12
|
-
/**
|
|
13
|
-
this.
|
|
11
|
+
/** 插件事件注册表 */
|
|
12
|
+
this.pluginEventMap = new Map();
|
|
13
|
+
/** 状态 */
|
|
14
|
+
this.status = {
|
|
15
|
+
started: false,
|
|
16
|
+
timestamp: 0,
|
|
17
|
+
};
|
|
14
18
|
this.helper = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
roomGenerator: new Reglist_1.Reglist(this, "roomGenerator"),
|
|
20
|
+
messageHandler: new Reglist_1.Reglist(this, "messageHandler"),
|
|
21
|
+
pluginDestory: new Reglist_1.Reglist(this, "pluginDestory"),
|
|
22
|
+
pluginAddHandler: new Reglist_1.Reglist(this, "pluginAddHandler"),
|
|
23
|
+
pluginRemoveHandler: new Reglist_1.Reglist(this, "pluginRemoveHandler"),
|
|
19
24
|
};
|
|
20
|
-
this.
|
|
25
|
+
this.room = new Room_1.RoomController(this);
|
|
26
|
+
this.plugin = new Plugin_1.PluginHandler(this);
|
|
27
|
+
this.init();
|
|
28
|
+
}
|
|
29
|
+
get started() {
|
|
30
|
+
return this.status.started;
|
|
31
|
+
}
|
|
32
|
+
get timestamp() {
|
|
33
|
+
return this.status.timestamp;
|
|
34
|
+
}
|
|
35
|
+
/** 初始化 */
|
|
36
|
+
init() {
|
|
37
|
+
this.on("room_open", () => {
|
|
38
|
+
this.started || this.start();
|
|
39
|
+
});
|
|
40
|
+
this.helper.pluginRemoveHandler.register("removePluginEvent", (name) => {
|
|
41
|
+
this.pluginEventMap.get(name)?.forEach(([eventName, listener]) => {
|
|
42
|
+
this.removeListener(eventName, listener);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
21
45
|
}
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
46
|
+
/** 开始 */
|
|
47
|
+
start() {
|
|
48
|
+
this.status.started = true;
|
|
49
|
+
this.status.timestamp = new Date().valueOf();
|
|
50
|
+
this.emit("start", this.timestamp);
|
|
51
|
+
}
|
|
52
|
+
/** 结束 */
|
|
53
|
+
end() {
|
|
54
|
+
this.closeAllRooms();
|
|
55
|
+
this.status.started = false;
|
|
56
|
+
this.emit("end", this.timestamp);
|
|
57
|
+
this.status.timestamp = 0;
|
|
58
|
+
}
|
|
59
|
+
/** 添加房间 */
|
|
60
|
+
addRoom({ platform, id }, open) {
|
|
61
|
+
let generated = this.room.generate({ platform, id }, open);
|
|
62
|
+
if (generated) {
|
|
63
|
+
this.room.add(generated);
|
|
27
64
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
65
|
+
}
|
|
66
|
+
/** 移除房间 */
|
|
67
|
+
removeRoom(roomKey) {
|
|
68
|
+
this.room.remove(roomKey);
|
|
69
|
+
}
|
|
70
|
+
/** 添加房间实例 */
|
|
71
|
+
addLiveRoom(room) {
|
|
72
|
+
this.room.add(room);
|
|
73
|
+
}
|
|
74
|
+
/** 打开房间 */
|
|
75
|
+
openRoom(roomKey) {
|
|
76
|
+
this.room.open(roomKey);
|
|
77
|
+
}
|
|
78
|
+
/** 关闭房间 */
|
|
79
|
+
closeRoom(roomKey) {
|
|
80
|
+
this.room.close(roomKey);
|
|
81
|
+
}
|
|
82
|
+
/** 打开所有房间 */
|
|
83
|
+
openAllRooms() {
|
|
84
|
+
this.room.keyList.forEach((key) => {
|
|
85
|
+
this.room.open(key);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** 关闭所有房间 */
|
|
89
|
+
closeAllRooms() {
|
|
90
|
+
this.room.keyList.forEach((key) => {
|
|
91
|
+
this.room.close(key);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/** 更新房间信息 */
|
|
95
|
+
updateRoomInfo(roomKey) {
|
|
96
|
+
this.room.update(roomKey);
|
|
97
|
+
}
|
|
98
|
+
/** 重写事件监听 */
|
|
99
|
+
on(eventName, listener) {
|
|
100
|
+
super.on(eventName, listener);
|
|
101
|
+
// 检测是否为插件添加事件,并添加进事件列表
|
|
102
|
+
if (this.plugin.currentPlugin) {
|
|
103
|
+
if (!this.pluginEventMap.has(this.plugin.currentPlugin)) {
|
|
104
|
+
this.pluginEventMap.set(this.plugin.currentPlugin, []);
|
|
105
|
+
}
|
|
106
|
+
this.pluginEventMap.get(this.plugin.currentPlugin)?.push([eventName, listener]);
|
|
45
107
|
}
|
|
46
|
-
|
|
47
|
-
this.plugin.delete(name);
|
|
48
|
-
this.helper.roomGenerator.unregister(name);
|
|
49
|
-
this.helper.messageHandler.unregister(name);
|
|
50
|
-
pluginObject?.destory && pluginObject.destory();
|
|
51
|
-
this.emit("plugin_remove", name);
|
|
108
|
+
return this;
|
|
52
109
|
}
|
|
53
110
|
}
|
|
54
|
-
exports.
|
|
111
|
+
exports.FloatingLive = FloatingLive;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { UserInfo } from "../types/message/AttributeInfo";
|
|
4
|
+
import { MessageData } from "../types/message/MessageData";
|
|
5
|
+
export interface RoomInfo {
|
|
6
|
+
/** 平台id */
|
|
7
|
+
platform: string;
|
|
8
|
+
/** 房间id */
|
|
9
|
+
id: number | string;
|
|
10
|
+
/** 房间key */
|
|
11
|
+
key: string;
|
|
12
|
+
/** 基本信息 */
|
|
13
|
+
base: RoomBaseInfo;
|
|
14
|
+
/** 统计信息 */
|
|
15
|
+
stats?: RoomStatsInfo;
|
|
16
|
+
/** 主播信息 */
|
|
17
|
+
anchor: UserInfo;
|
|
18
|
+
/** 时间戳 */
|
|
19
|
+
timestamp: number;
|
|
20
|
+
/** 直播状态 */
|
|
21
|
+
status: RoomStatus;
|
|
22
|
+
/** 直播间是否可用 */
|
|
23
|
+
available: boolean;
|
|
24
|
+
/** 房间监听是否打开 */
|
|
25
|
+
opening: boolean;
|
|
26
|
+
/** 是否连接到房间 */
|
|
27
|
+
connected: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** 房间基本信息 */
|
|
30
|
+
export declare type RoomBaseInfo = {
|
|
31
|
+
/** 直播标题 */
|
|
32
|
+
title?: string;
|
|
33
|
+
/** 分区 */
|
|
34
|
+
area?: string[];
|
|
35
|
+
/** 封面 */
|
|
36
|
+
cover?: string;
|
|
37
|
+
};
|
|
38
|
+
/** 房间统计数据信息 */
|
|
39
|
+
export declare type RoomStatsInfo = {
|
|
40
|
+
/** 点赞数 */
|
|
41
|
+
like?: number;
|
|
42
|
+
/** 观看数 */
|
|
43
|
+
watch?: number;
|
|
44
|
+
/** 在线人数 */
|
|
45
|
+
online?: number;
|
|
46
|
+
/** 人气值 */
|
|
47
|
+
popularity?: number;
|
|
48
|
+
};
|
|
49
|
+
/** 房间状态 */
|
|
50
|
+
export declare type RoomStatus = "live" | "off" | "round" | "banned";
|
|
51
|
+
export declare abstract class LiveRoom extends EventEmitter implements RoomInfo {
|
|
52
|
+
constructor();
|
|
53
|
+
/** 平台 */
|
|
54
|
+
abstract readonly platform: string;
|
|
55
|
+
/** 房间id */
|
|
56
|
+
abstract readonly id: string | number;
|
|
57
|
+
/** 基本信息 */
|
|
58
|
+
abstract base: RoomBaseInfo;
|
|
59
|
+
/** 统计信息 */
|
|
60
|
+
stats?: RoomStatsInfo;
|
|
61
|
+
/** 主播信息 */
|
|
62
|
+
abstract anchor: UserInfo;
|
|
63
|
+
/** 直播状态 */
|
|
64
|
+
status: RoomStatus;
|
|
65
|
+
/** 时间戳 */
|
|
66
|
+
timestamp: number;
|
|
67
|
+
/** 房间是否打开 */
|
|
68
|
+
opening: boolean;
|
|
69
|
+
/** 房间是否可用 */
|
|
70
|
+
abstract available: boolean;
|
|
71
|
+
/** 是否连接上房间 */
|
|
72
|
+
abstract connected: boolean;
|
|
73
|
+
/** 打开连接 */
|
|
74
|
+
abstract open(): void;
|
|
75
|
+
/** 关闭连接 */
|
|
76
|
+
abstract close(): void;
|
|
77
|
+
/** 从服务器获取信息 */
|
|
78
|
+
abstract getInfo(): void;
|
|
79
|
+
/** 销毁事件 */
|
|
80
|
+
protected onDestory?(): void;
|
|
81
|
+
/** 销毁 */
|
|
82
|
+
destory(): void;
|
|
83
|
+
protected emitMsg(msg: MessageData): void;
|
|
84
|
+
protected emitOrigin(msg: any): void;
|
|
85
|
+
get info(): RoomInfo;
|
|
86
|
+
get key(): string;
|
|
87
|
+
private msgCheck;
|
|
88
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LiveRoom = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
class LiveRoom extends events_1.EventEmitter {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
/** 直播状态 */
|
|
9
|
+
this.status = "off";
|
|
10
|
+
/** 时间戳 */
|
|
11
|
+
this.timestamp = 0;
|
|
12
|
+
/** 房间是否打开 */
|
|
13
|
+
this.opening = false;
|
|
14
|
+
}
|
|
15
|
+
/** 销毁 */
|
|
16
|
+
destory() {
|
|
17
|
+
this.close();
|
|
18
|
+
this.removeAllListeners();
|
|
19
|
+
this.onDestory?.();
|
|
20
|
+
}
|
|
21
|
+
// 发送消息
|
|
22
|
+
emitMsg(msg) {
|
|
23
|
+
this.msgCheck(msg);
|
|
24
|
+
this.emit("msg", msg);
|
|
25
|
+
}
|
|
26
|
+
// 发送源消息
|
|
27
|
+
emitOrigin(msg) {
|
|
28
|
+
this.emit("origin", msg);
|
|
29
|
+
}
|
|
30
|
+
get info() {
|
|
31
|
+
return {
|
|
32
|
+
platform: this.platform,
|
|
33
|
+
id: this.id,
|
|
34
|
+
base: this.base,
|
|
35
|
+
stats: this.stats,
|
|
36
|
+
anchor: this.anchor,
|
|
37
|
+
timestamp: this.timestamp,
|
|
38
|
+
status: this.status,
|
|
39
|
+
available: this.available,
|
|
40
|
+
opening: this.opening,
|
|
41
|
+
connected: this.connected,
|
|
42
|
+
key: this.key,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
get key() {
|
|
46
|
+
return `${this.platform}:${this.id}`;
|
|
47
|
+
}
|
|
48
|
+
// 检测特定消息
|
|
49
|
+
msgCheck(msg) {
|
|
50
|
+
switch (msg.type) {
|
|
51
|
+
case "live_start":
|
|
52
|
+
this.status = "live";
|
|
53
|
+
this.timestamp = msg.info.timestamp || msg.record_time;
|
|
54
|
+
this.emit("status", "live", msg.info.timestamp);
|
|
55
|
+
break;
|
|
56
|
+
case "live_end":
|
|
57
|
+
case "live_cut":
|
|
58
|
+
this.status = msg.status || "off";
|
|
59
|
+
this.timestamp = msg.timestamp || msg.record_time;
|
|
60
|
+
this.emit("status", msg.status || "off", msg.timestamp || msg.record_time);
|
|
61
|
+
break;
|
|
62
|
+
case "live_change":
|
|
63
|
+
this.base = Object.assign(this.base, msg.info);
|
|
64
|
+
this.emit("change", msg.info);
|
|
65
|
+
break;
|
|
66
|
+
case "live_stats":
|
|
67
|
+
this.stats = Object.assign(this.stats, msg.info);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.LiveRoom = LiveRoom;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { FloatingLive } from "..";
|
|
1
2
|
/** 插件可注册对象模块 */
|
|
2
|
-
export declare class
|
|
3
|
-
/** 当前安装插件 */
|
|
4
|
-
static currentPlugin: string | null;
|
|
3
|
+
export declare class Reglist<T> {
|
|
5
4
|
/** 功能列表 */
|
|
6
5
|
private readonly list;
|
|
7
6
|
/** 插件与功能名称绑定表 */
|
|
8
7
|
private readonly pluginIdMap;
|
|
9
8
|
private readonly name;
|
|
10
|
-
|
|
9
|
+
private readonly main;
|
|
10
|
+
constructor(main: FloatingLive, name: string);
|
|
11
11
|
/** 注册一个对象 */
|
|
12
12
|
register(id: string, item: T): void;
|
|
13
13
|
/** 取消某一插件在该模块中的注册 */
|
|
@@ -20,8 +20,6 @@ export declare class Registerable<T> {
|
|
|
20
20
|
getList(): T[];
|
|
21
21
|
/** 获取注册id列表 */
|
|
22
22
|
getIdList(): string[];
|
|
23
|
+
/** 获取注册id列表 */
|
|
24
|
+
getIdByPlugin(name: string): string[];
|
|
23
25
|
}
|
|
24
|
-
/** 设置当前安装插件名称 */
|
|
25
|
-
export declare const setCurrentPluginName: (name?: string | null) => void;
|
|
26
|
-
/** 获取当前安装插件名称 */
|
|
27
|
-
export declare const getCurrentPluginName: () => string | null;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Plugin System modified from PicGo
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
3
|
+
exports.Reglist = void 0;
|
|
5
4
|
/** 插件可注册对象模块 */
|
|
6
|
-
class
|
|
7
|
-
constructor(name) {
|
|
5
|
+
class Reglist {
|
|
6
|
+
constructor(main, name) {
|
|
7
|
+
this.main = main;
|
|
8
8
|
this.name = name;
|
|
9
9
|
this.list = new Map();
|
|
10
10
|
this.pluginIdMap = new Map();
|
|
@@ -19,12 +19,12 @@ class Registerable {
|
|
|
19
19
|
// 将组件添加至列表中
|
|
20
20
|
this.list.set(id, item);
|
|
21
21
|
// 将插件名称与注册id关联
|
|
22
|
-
if (
|
|
23
|
-
if (this.pluginIdMap.has(
|
|
24
|
-
this.pluginIdMap.get(
|
|
22
|
+
if (this.main.plugin.currentPlugin) {
|
|
23
|
+
if (this.pluginIdMap.has(this.main.plugin.currentPlugin)) {
|
|
24
|
+
this.pluginIdMap.get(this.main.plugin.currentPlugin)?.push(id);
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
this.pluginIdMap.set(
|
|
27
|
+
this.pluginIdMap.set(this.main.plugin.currentPlugin, [id]);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -53,15 +53,9 @@ class Registerable {
|
|
|
53
53
|
getIdList() {
|
|
54
54
|
return [...this.list.keys()];
|
|
55
55
|
}
|
|
56
|
+
/** 获取注册id列表 */
|
|
57
|
+
getIdByPlugin(name) {
|
|
58
|
+
return [...(this.pluginIdMap.get(name) || [])];
|
|
59
|
+
}
|
|
56
60
|
}
|
|
57
|
-
exports.
|
|
58
|
-
/** 设置当前安装插件名称 */
|
|
59
|
-
const setCurrentPluginName = (name = null) => {
|
|
60
|
-
Registerable.currentPlugin = name;
|
|
61
|
-
};
|
|
62
|
-
exports.setCurrentPluginName = setCurrentPluginName;
|
|
63
|
-
/** 获取当前安装插件名称 */
|
|
64
|
-
const getCurrentPluginName = () => {
|
|
65
|
-
return Registerable.currentPlugin;
|
|
66
|
-
};
|
|
67
|
-
exports.getCurrentPluginName = getCurrentPluginName;
|
|
61
|
+
exports.Reglist = Reglist;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FloatingLive } from "..";
|
|
2
|
+
export declare class PluginHandler<T extends FloatingLive> {
|
|
3
|
+
private current;
|
|
4
|
+
private list;
|
|
5
|
+
private pluginEvent;
|
|
6
|
+
private main;
|
|
7
|
+
private helper;
|
|
8
|
+
constructor(main: T);
|
|
9
|
+
/** 获取当前安装插件 */
|
|
10
|
+
get currentPlugin(): string | null;
|
|
11
|
+
addPluginEvent(eventName: string, listener: (...args: any[]) => void): void;
|
|
12
|
+
/** 获取插件操作对象 */
|
|
13
|
+
get(name: string): {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
} | undefined;
|
|
16
|
+
/** 注册插件 */
|
|
17
|
+
register(name: string, pluginFunc: (main: T) => {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
} | void): void | {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
};
|
|
22
|
+
/** 移除插件 */
|
|
23
|
+
unregister(name: string): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginHandler = void 0;
|
|
4
|
+
class PluginHandler {
|
|
5
|
+
constructor(main) {
|
|
6
|
+
this.current = null;
|
|
7
|
+
this.list = new Map();
|
|
8
|
+
this.pluginEvent = new Map();
|
|
9
|
+
this.main = main;
|
|
10
|
+
this.helper = main.helper;
|
|
11
|
+
}
|
|
12
|
+
/** 获取当前安装插件 */
|
|
13
|
+
get currentPlugin() {
|
|
14
|
+
return this.current;
|
|
15
|
+
}
|
|
16
|
+
addPluginEvent(eventName, listener) {
|
|
17
|
+
if (this.currentPlugin) {
|
|
18
|
+
if (!this.pluginEvent.has(this.currentPlugin)) {
|
|
19
|
+
this.pluginEvent.set(this.currentPlugin, []);
|
|
20
|
+
}
|
|
21
|
+
this.pluginEvent.get(this.currentPlugin)?.push([eventName, listener]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** 获取插件操作对象 */
|
|
25
|
+
get(name) {
|
|
26
|
+
return this.list.get(name);
|
|
27
|
+
}
|
|
28
|
+
/** 注册插件 */
|
|
29
|
+
register(name, pluginFunc) {
|
|
30
|
+
if (this.list.has(name)) {
|
|
31
|
+
this.main.emit("plugin_duplicate", name);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.current = name;
|
|
35
|
+
// 执行插件函数并获取插件操作对象
|
|
36
|
+
let pluginObject = pluginFunc(this.main);
|
|
37
|
+
this.list.set(name, pluginObject || {});
|
|
38
|
+
// 执行钩子函数
|
|
39
|
+
this.helper.pluginAddHandler.getList().forEach(handler => {
|
|
40
|
+
handler(name);
|
|
41
|
+
});
|
|
42
|
+
this.main.emit("plugin_add", name);
|
|
43
|
+
this.current = null;
|
|
44
|
+
return pluginObject;
|
|
45
|
+
}
|
|
46
|
+
/** 移除插件 */
|
|
47
|
+
unregister(name) {
|
|
48
|
+
// 检测插件是否存在
|
|
49
|
+
if (!this.list.has(name)) {
|
|
50
|
+
this.main.emit("plugin_unexist", name);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// 获取该插件的销毁函数
|
|
54
|
+
let destoryFunc = this.helper.pluginDestory.getIdByPlugin(name).map(id => this.helper.pluginDestory.get(id));
|
|
55
|
+
// 从列表中移除插件
|
|
56
|
+
this.list.delete(name);
|
|
57
|
+
// 移除helper注册
|
|
58
|
+
this.helper.roomGenerator.unregister(name);
|
|
59
|
+
this.helper.messageHandler.unregister(name);
|
|
60
|
+
this.helper.pluginAddHandler.unregister(name);
|
|
61
|
+
this.helper.pluginRemoveHandler.unregister(name);
|
|
62
|
+
this.helper.pluginDestory.unregister(name);
|
|
63
|
+
// 执行钩子函数
|
|
64
|
+
this.helper.pluginRemoveHandler.getList().forEach(handler => {
|
|
65
|
+
handler(name);
|
|
66
|
+
});
|
|
67
|
+
// 执行销毁函数
|
|
68
|
+
destoryFunc.forEach(handler => {
|
|
69
|
+
handler?.();
|
|
70
|
+
});
|
|
71
|
+
this.main.emit("plugin_remove", name);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.PluginHandler = PluginHandler;
|
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
import LiveRoom from "../
|
|
2
|
-
import FloatingLive from "..";
|
|
3
|
-
import Controller from ".";
|
|
1
|
+
import { LiveRoom } from "../lib/LiveRoom";
|
|
2
|
+
import { FloatingLive } from "..";
|
|
4
3
|
/** 直播间监听实例控制器 */
|
|
5
|
-
declare class
|
|
6
|
-
readonly controller: Controller;
|
|
4
|
+
export declare class RoomController {
|
|
7
5
|
readonly main: FloatingLive;
|
|
8
6
|
private roomMap;
|
|
9
|
-
constructor(
|
|
7
|
+
constructor(main: FloatingLive);
|
|
10
8
|
generate(r: {
|
|
11
9
|
platform: string;
|
|
12
10
|
id: string | number;
|
|
13
|
-
}, open?: boolean):
|
|
14
|
-
key: string;
|
|
15
|
-
room: LiveRoom;
|
|
16
|
-
} | undefined;
|
|
11
|
+
}, open?: boolean): LiveRoom | undefined;
|
|
17
12
|
/** 添加房间监听对象 */
|
|
18
|
-
add(
|
|
13
|
+
add(room: LiveRoom, open?: boolean): void;
|
|
19
14
|
/** 移除房间 */
|
|
20
15
|
remove(roomKey: string): void;
|
|
21
16
|
/** 获取房间 */
|
|
22
17
|
get(roomKey: string): LiveRoom | undefined;
|
|
23
18
|
/** 获取房间信息 */
|
|
24
|
-
info(roomKey: string): import("../
|
|
19
|
+
info(roomKey: string): import("../lib/LiveRoom").RoomInfo | undefined;
|
|
25
20
|
/** 更新房间信息 */
|
|
26
21
|
update(roomKey: string): void;
|
|
27
22
|
/** 获取roomKey列表 */
|
|
@@ -29,4 +24,3 @@ declare class Room {
|
|
|
29
24
|
open(roomKey: string): void;
|
|
30
25
|
close(roomKey: string): void;
|
|
31
26
|
}
|
|
32
|
-
export default Room;
|