floating-live 0.12.0 → 0.13.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 +7 -8
- package/index.d.ts +3 -3
- package/index.js +3 -3
- package/package.json +4 -2
- package/plugin/acfun/acfunLive.d.ts +3 -3
- package/plugin/acfun/acfunLive.js +10 -10
- package/plugin/acfun/index.d.ts +1 -0
- package/plugin/acfun/index.js +3 -2
- package/plugin/bilibili/index.d.ts +1 -0
- package/plugin/bilibili/index.js +17 -4
- package/plugin/bilibili/parser.d.ts +6 -0
- package/plugin/bilibili/{bilibiliLive.js → parser.js} +132 -231
- package/plugin/bilibili/room.d.ts +77 -0
- package/plugin/bilibili/room.js +261 -0
- package/plugin/bilibili/types.d.ts +424 -0
- package/plugin/bilibili/utils.d.ts +16 -0
- package/plugin/bilibili/utils.js +140 -0
- package/plugin/chatPrint/chatPrint.d.ts +2 -2
- package/plugin/chatPrint/chatPrint.js +16 -6
- package/plugin/chatPrint/index.d.ts +1 -0
- package/plugin/chatPrint/index.js +2 -1
- package/plugin/consoleEvent/index.d.ts +1 -0
- package/plugin/consoleEvent/index.js +16 -21
- package/plugin/msgSave/index.d.ts +3 -1
- package/plugin/msgSave/index.js +25 -30
- package/plugin/msgSave/msgSave.d.ts +5 -5
- package/plugin/msgSave/msgSave.js +25 -9
- package/src/abstract/LiveRoom.d.ts +44 -0
- package/src/{lib → abstract}/LiveRoom.js +12 -7
- package/src/enum.d.ts +4 -2
- package/src/enum.js +9 -7
- package/src/index.d.ts +13 -37
- package/src/index.js +12 -74
- package/src/module/ModAuth.d.ts +8 -0
- package/src/module/ModAuth.js +14 -0
- package/src/module/ModCommand.d.ts +3 -0
- package/src/module/ModCommand.js +6 -0
- package/src/module/ModMessage.d.ts +9 -0
- package/src/module/ModMessage.js +12 -0
- package/src/module/{Plugin.d.ts → ModPlugin.d.ts} +2 -6
- package/src/module/{Plugin.js → ModPlugin.js} +20 -18
- package/src/module/ModRooms.d.ts +36 -0
- package/src/module/{Room.js → ModRooms.js} +50 -31
- package/src/types/index.d.ts +1 -2
- package/src/types/index.js +1 -2
- package/src/types/message.d.ts +210 -0
- package/src/types/plugin.d.ts +4 -5
- package/src/types/room.d.ts +48 -2
- package/src/utils.d.ts +2 -0
- package/src/{tool.js → utils.js} +4 -4
- package/test/type/bilibili_getInfoByRoom.d.ts +492 -0
- package/plugin/bilibili/bilibiliLive.d.ts +0 -58
- package/src/lib/LiveRoom.d.ts +0 -89
- package/src/module/Command.d.ts +0 -3
- package/src/module/Command.js +0 -6
- package/src/module/Room.d.ts +0 -26
- package/src/tool.d.ts +0 -2
- package/src/types/message/AttributeInfo.d.ts +0 -67
- package/src/types/message/MessageData.d.ts +0 -166
- /package/{src/types/message/AttributeInfo.js → plugin/bilibili/types.js} +0 -0
- /package/src/{lib → abstract}/Reglist.d.ts +0 -0
- /package/src/{lib → abstract}/Reglist.js +0 -0
- /package/src/types/{message/MessageData.js → message.js} +0 -0
package/src/enum.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.UserType = exports.DanmakuMode = exports.ImageSize = exports.RoomStatus = void 0;
|
|
4
4
|
/** 直播间状态 */
|
|
5
5
|
var RoomStatus;
|
|
6
6
|
(function (RoomStatus) {
|
|
@@ -31,11 +31,13 @@ var DanmakuMode;
|
|
|
31
31
|
DanmakuMode[DanmakuMode["top"] = 5] = "top";
|
|
32
32
|
DanmakuMode[DanmakuMode["right"] = 6] = "right";
|
|
33
33
|
})(DanmakuMode = exports.DanmakuMode || (exports.DanmakuMode = {}));
|
|
34
|
-
/**
|
|
35
|
-
var
|
|
36
|
-
(function (
|
|
34
|
+
/** 用户类型 */
|
|
35
|
+
var UserType;
|
|
36
|
+
(function (UserType) {
|
|
37
|
+
/** 普通观众 */
|
|
38
|
+
UserType[UserType["normal"] = 0] = "normal";
|
|
37
39
|
/** 房管 */
|
|
38
|
-
|
|
40
|
+
UserType[UserType["admin"] = 1] = "admin";
|
|
39
41
|
/** 主播 */
|
|
40
|
-
|
|
41
|
-
})(
|
|
42
|
+
UserType[UserType["anchor"] = 2] = "anchor";
|
|
43
|
+
})(UserType = exports.UserType || (exports.UserType = {}));
|
package/src/index.d.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
|
-
import { Reglist } from "./
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { Reglist } from "./abstract/Reglist";
|
|
4
|
+
import { Message } from "./types";
|
|
5
|
+
import { ModPlugin } from "./module/ModPlugin";
|
|
6
|
+
import { ModRooms } from "./module/ModRooms";
|
|
7
|
+
import { ModAuth } from "./module/ModAuth";
|
|
8
|
+
import { ModMessage } from "./module/ModMessage";
|
|
8
9
|
export declare class FloatingLive extends EventEmitter {
|
|
9
10
|
/** 房间控制模块 */
|
|
10
|
-
|
|
11
|
+
rooms: ModRooms;
|
|
12
|
+
/** 消息处理模块 */
|
|
13
|
+
message: ModMessage;
|
|
14
|
+
/** 用户登录凭据模块 */
|
|
15
|
+
auth: ModAuth;
|
|
11
16
|
/** 插件处理模块 */
|
|
12
|
-
plugin:
|
|
17
|
+
plugin: ModPlugin<this>;
|
|
13
18
|
helper: {
|
|
14
|
-
/** 房间生成器 */
|
|
15
|
-
roomGenerator: Reglist<(id: string | number, open?: boolean) => LiveRoom>;
|
|
16
19
|
/** 消息处理 */
|
|
17
|
-
messageHandler: Reglist<(msg:
|
|
20
|
+
messageHandler: Reglist<(msg: Message.All) => void>;
|
|
18
21
|
/** 插件销毁 */
|
|
19
22
|
pluginDestory: Reglist<() => void>;
|
|
20
23
|
/** 添加插件 */
|
|
@@ -24,36 +27,9 @@ export declare class FloatingLive extends EventEmitter {
|
|
|
24
27
|
};
|
|
25
28
|
/** 插件事件注册表 */
|
|
26
29
|
private regEventMap;
|
|
27
|
-
/** 状态 */
|
|
28
|
-
private status;
|
|
29
|
-
get started(): boolean;
|
|
30
|
-
get timestamp(): number;
|
|
31
30
|
constructor();
|
|
32
31
|
/** 初始化 */
|
|
33
32
|
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, config?: {}): 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
33
|
/** 重写事件监听 */
|
|
58
34
|
on(eventName: string, listener: (...args: any[]) => void): this;
|
|
59
35
|
}
|
package/src/index.js
CHANGED
|
@@ -2,42 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FloatingLive = void 0;
|
|
4
4
|
const events_1 = require("events");
|
|
5
|
-
const Reglist_1 = require("./
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const Reglist_1 = require("./abstract/Reglist");
|
|
6
|
+
const ModPlugin_1 = require("./module/ModPlugin");
|
|
7
|
+
const ModRooms_1 = require("./module/ModRooms");
|
|
8
|
+
const ModAuth_1 = require("./module/ModAuth");
|
|
9
|
+
const ModMessage_1 = require("./module/ModMessage");
|
|
8
10
|
class FloatingLive extends events_1.EventEmitter {
|
|
9
11
|
constructor() {
|
|
10
12
|
super();
|
|
11
13
|
/** 插件事件注册表 */
|
|
12
14
|
this.regEventMap = new Map();
|
|
13
|
-
/** 状态 */
|
|
14
|
-
this.status = {
|
|
15
|
-
started: false,
|
|
16
|
-
timestamp: 0,
|
|
17
|
-
};
|
|
18
15
|
this.helper = {
|
|
19
|
-
roomGenerator: new Reglist_1.Reglist(this, "roomGenerator"),
|
|
20
16
|
messageHandler: new Reglist_1.Reglist(this, "messageHandler"),
|
|
21
17
|
pluginDestory: new Reglist_1.Reglist(this, "pluginDestory"),
|
|
22
18
|
pluginAddHandler: new Reglist_1.Reglist(this, "pluginAddHandler"),
|
|
23
19
|
pluginRemoveHandler: new Reglist_1.Reglist(this, "pluginRemoveHandler"),
|
|
24
20
|
};
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
21
|
+
this.rooms = new ModRooms_1.ModRooms(this);
|
|
22
|
+
this.message = new ModMessage_1.ModMessage(this);
|
|
23
|
+
this.auth = new ModAuth_1.ModAuth(this);
|
|
24
|
+
this.plugin = new ModPlugin_1.ModPlugin(this);
|
|
27
25
|
this.init();
|
|
28
26
|
}
|
|
29
|
-
get started() {
|
|
30
|
-
return this.status.started;
|
|
31
|
-
}
|
|
32
|
-
get timestamp() {
|
|
33
|
-
return this.status.timestamp;
|
|
34
|
-
}
|
|
35
27
|
/** 初始化 */
|
|
36
28
|
init() {
|
|
37
|
-
// 监听到有房间打开,则开始记录
|
|
38
|
-
this.on("room_open", () => {
|
|
39
|
-
this.started || this.start();
|
|
40
|
-
});
|
|
41
29
|
// 设置在插件卸载时移除由插件注册的事件
|
|
42
30
|
this.helper.pluginRemoveHandler.register("removePluginEvent", (name) => {
|
|
43
31
|
this.regEventMap.get(name)?.forEach(([eventName, listener]) => {
|
|
@@ -45,58 +33,6 @@ class FloatingLive extends events_1.EventEmitter {
|
|
|
45
33
|
});
|
|
46
34
|
});
|
|
47
35
|
}
|
|
48
|
-
/** 开始 */
|
|
49
|
-
start() {
|
|
50
|
-
this.status.started = true;
|
|
51
|
-
this.status.timestamp = Date.now();
|
|
52
|
-
this.emit("start", this.timestamp);
|
|
53
|
-
}
|
|
54
|
-
/** 结束 */
|
|
55
|
-
end() {
|
|
56
|
-
this.closeAllRooms();
|
|
57
|
-
this.status.started = false;
|
|
58
|
-
this.emit("end", this.timestamp);
|
|
59
|
-
this.status.timestamp = 0;
|
|
60
|
-
}
|
|
61
|
-
/** 添加房间 */
|
|
62
|
-
addRoom({ platform, id }, open, config) {
|
|
63
|
-
let generated = this.room.generate({ platform, id }, open);
|
|
64
|
-
if (generated) {
|
|
65
|
-
this.room.add(generated);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/** 移除房间 */
|
|
69
|
-
removeRoom(roomKey) {
|
|
70
|
-
this.room.remove(roomKey);
|
|
71
|
-
}
|
|
72
|
-
/** 添加房间实例 */
|
|
73
|
-
addLiveRoom(room) {
|
|
74
|
-
this.room.add(room);
|
|
75
|
-
}
|
|
76
|
-
/** 打开房间 */
|
|
77
|
-
openRoom(roomKey) {
|
|
78
|
-
this.room.open(roomKey);
|
|
79
|
-
}
|
|
80
|
-
/** 关闭房间 */
|
|
81
|
-
closeRoom(roomKey) {
|
|
82
|
-
this.room.close(roomKey);
|
|
83
|
-
}
|
|
84
|
-
/** 打开所有房间 */
|
|
85
|
-
openAllRooms() {
|
|
86
|
-
this.room.keyList.forEach((key) => {
|
|
87
|
-
this.room.open(key);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/** 关闭所有房间 */
|
|
91
|
-
closeAllRooms() {
|
|
92
|
-
this.room.keyList.forEach((key) => {
|
|
93
|
-
this.room.close(key);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
/** 更新房间信息 */
|
|
97
|
-
updateRoomInfo(roomKey) {
|
|
98
|
-
this.room.update(roomKey);
|
|
99
|
-
}
|
|
100
36
|
/** 重写事件监听 */
|
|
101
37
|
on(eventName, listener) {
|
|
102
38
|
super.on(eventName, listener);
|
|
@@ -105,7 +41,9 @@ class FloatingLive extends events_1.EventEmitter {
|
|
|
105
41
|
if (!this.regEventMap.has(this.plugin.currentPlugin)) {
|
|
106
42
|
this.regEventMap.set(this.plugin.currentPlugin, []);
|
|
107
43
|
}
|
|
108
|
-
this.regEventMap
|
|
44
|
+
this.regEventMap
|
|
45
|
+
.get(this.plugin.currentPlugin)
|
|
46
|
+
?.push([eventName, listener]);
|
|
109
47
|
}
|
|
110
48
|
return this;
|
|
111
49
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModAuth = void 0;
|
|
4
|
+
const Reglist_1 = require("../abstract/Reglist");
|
|
5
|
+
class ModAuth {
|
|
6
|
+
constructor(main) {
|
|
7
|
+
this.options = new Reglist_1.Reglist(main, "auth.options");
|
|
8
|
+
this.main = main;
|
|
9
|
+
}
|
|
10
|
+
set(name, auth) {
|
|
11
|
+
return this.main.rooms.setAuth(name, auth);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ModAuth = ModAuth;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Message } from "../types/message";
|
|
2
|
+
import { FloatingLive } from "..";
|
|
3
|
+
import { Reglist } from "../abstract/Reglist";
|
|
4
|
+
export declare class ModMessage {
|
|
5
|
+
main: FloatingLive;
|
|
6
|
+
handler: Reglist<(msg: Message.All) => void>;
|
|
7
|
+
constructor(main: FloatingLive);
|
|
8
|
+
handle(msg: Message.All): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModMessage = void 0;
|
|
4
|
+
const Reglist_1 = require("../abstract/Reglist");
|
|
5
|
+
class ModMessage {
|
|
6
|
+
constructor(main) {
|
|
7
|
+
this.main = main;
|
|
8
|
+
this.handler = new Reglist_1.Reglist(main, "message.handler");
|
|
9
|
+
}
|
|
10
|
+
handle(msg) { }
|
|
11
|
+
}
|
|
12
|
+
exports.ModMessage = ModMessage;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FloatingLive } from "..";
|
|
2
2
|
import { FloatingLivePlugin } from "../types/plugin";
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class ModPlugin<T extends FloatingLive> {
|
|
4
4
|
private current;
|
|
5
5
|
/** 插件列表 */
|
|
6
6
|
private list;
|
|
@@ -16,11 +16,7 @@ export declare class PluginHandler<T extends FloatingLive> {
|
|
|
16
16
|
[key: string]: any;
|
|
17
17
|
} | undefined;
|
|
18
18
|
/** 注册插件 */
|
|
19
|
-
register(
|
|
20
|
-
[key: string]: any;
|
|
21
|
-
}): void | {
|
|
22
|
-
[key: string]: any;
|
|
23
|
-
};
|
|
19
|
+
register(plugin: FloatingLivePlugin<T>): void | object;
|
|
24
20
|
/** 移除插件 */
|
|
25
21
|
unregister(name: string): void;
|
|
26
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
3
|
+
exports.ModPlugin = void 0;
|
|
4
|
+
class ModPlugin {
|
|
5
5
|
constructor(main) {
|
|
6
6
|
this.current = null;
|
|
7
7
|
/** 插件列表 */
|
|
@@ -27,27 +27,28 @@ class PluginHandler {
|
|
|
27
27
|
return this.list.get(name);
|
|
28
28
|
}
|
|
29
29
|
/** 注册插件 */
|
|
30
|
-
register(
|
|
30
|
+
register(plugin) {
|
|
31
|
+
// 执行插件函数
|
|
32
|
+
let pluginObject = plugin();
|
|
33
|
+
const name = pluginObject.name;
|
|
31
34
|
if (this.list.has(name)) {
|
|
32
|
-
this.main.emit("
|
|
35
|
+
this.main.emit("plugin:duplicate", name);
|
|
33
36
|
return;
|
|
34
37
|
}
|
|
35
38
|
this.current = name;
|
|
36
|
-
// 执行插件函数并获取插件操作对象
|
|
37
|
-
let pluginObject = plugin();
|
|
38
39
|
// 如果插件register函数无法调用,则无法注册插件
|
|
39
|
-
if (typeof pluginObject.register !=
|
|
40
|
-
this.main.emit("
|
|
40
|
+
if (typeof pluginObject.register != "function") {
|
|
41
|
+
this.main.emit("plugin:invalid", name);
|
|
41
42
|
this.current = null;
|
|
42
43
|
return;
|
|
43
44
|
}
|
|
44
|
-
let pluginExpose = pluginObject.register(this.main
|
|
45
|
+
let pluginExpose = pluginObject.register(this.main);
|
|
45
46
|
this.list.set(name, pluginExpose || {});
|
|
46
47
|
// 执行钩子函数
|
|
47
|
-
this.helper.pluginAddHandler.getList().forEach(handler => {
|
|
48
|
+
this.helper.pluginAddHandler.getList().forEach((handler) => {
|
|
48
49
|
handler(name);
|
|
49
50
|
});
|
|
50
|
-
this.main.emit("
|
|
51
|
+
this.main.emit("plugin:add", name);
|
|
51
52
|
this.current = null;
|
|
52
53
|
return pluginExpose;
|
|
53
54
|
}
|
|
@@ -55,28 +56,29 @@ class PluginHandler {
|
|
|
55
56
|
unregister(name) {
|
|
56
57
|
// 检测插件是否存在
|
|
57
58
|
if (!this.list.has(name)) {
|
|
58
|
-
this.main.emit("
|
|
59
|
+
this.main.emit("plugin:unexist", name);
|
|
59
60
|
return;
|
|
60
61
|
}
|
|
61
62
|
// 获取该插件的销毁函数
|
|
62
|
-
let
|
|
63
|
+
let destroyFunc = this.helper.pluginDestory
|
|
64
|
+
.getIdByPlugin(name)
|
|
65
|
+
.map((id) => this.helper.pluginDestory.get(id));
|
|
63
66
|
// 从列表中移除插件
|
|
64
67
|
this.list.delete(name);
|
|
65
68
|
// 移除helper注册
|
|
66
|
-
this.helper.roomGenerator.unregister(name);
|
|
67
69
|
this.helper.messageHandler.unregister(name);
|
|
68
70
|
this.helper.pluginAddHandler.unregister(name);
|
|
69
71
|
this.helper.pluginRemoveHandler.unregister(name);
|
|
70
72
|
this.helper.pluginDestory.unregister(name);
|
|
71
73
|
// 执行钩子函数
|
|
72
|
-
this.helper.pluginRemoveHandler.getList().forEach(handler => {
|
|
74
|
+
this.helper.pluginRemoveHandler.getList().forEach((handler) => {
|
|
73
75
|
handler(name);
|
|
74
76
|
});
|
|
75
77
|
// 执行销毁函数
|
|
76
|
-
|
|
78
|
+
destroyFunc.forEach((handler) => {
|
|
77
79
|
handler?.();
|
|
78
80
|
});
|
|
79
|
-
this.main.emit("
|
|
81
|
+
this.main.emit("plugin:remove", name);
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
|
-
exports.
|
|
84
|
+
exports.ModPlugin = ModPlugin;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Reglist } from "../abstract/Reglist";
|
|
2
|
+
import { LiveRoom } from "../abstract/LiveRoom";
|
|
3
|
+
import { FloatingLive } from "..";
|
|
4
|
+
/** 直播间监听实例控制器 */
|
|
5
|
+
export declare class ModRooms {
|
|
6
|
+
readonly main: FloatingLive;
|
|
7
|
+
private roomMap;
|
|
8
|
+
private auths;
|
|
9
|
+
private configs;
|
|
10
|
+
generator: Reglist<(id: string | number, open?: boolean, config?: object) => LiveRoom>;
|
|
11
|
+
constructor(main: FloatingLive);
|
|
12
|
+
/** 设置登录凭据 */
|
|
13
|
+
setAuth(platform: string, auth: string): void;
|
|
14
|
+
/** 设置房间配置 */
|
|
15
|
+
setConfig(platform: string, config: any): void;
|
|
16
|
+
/** 生成房间 */
|
|
17
|
+
generate(platform: string, id: string | number, open?: boolean): LiveRoom | undefined;
|
|
18
|
+
/** 添加房间监听实例 */
|
|
19
|
+
addRoom(room: LiveRoom, open?: boolean): void;
|
|
20
|
+
/** 添加房间 */
|
|
21
|
+
add(platform: string, id: number, open: boolean): void;
|
|
22
|
+
/** 移除房间 */
|
|
23
|
+
remove(roomKey: string): void;
|
|
24
|
+
/** 获取房间 */
|
|
25
|
+
get(roomKey: string): LiveRoom | undefined;
|
|
26
|
+
/** 获取房间信息 */
|
|
27
|
+
info(roomKey: string): import("../types").RoomInfo | undefined;
|
|
28
|
+
/** 更新房间信息 */
|
|
29
|
+
update(roomKey: string): void;
|
|
30
|
+
/** 获取roomKey列表 */
|
|
31
|
+
get keys(): Array<string>;
|
|
32
|
+
/** 打开房间连接 */
|
|
33
|
+
open(roomKey: string): void;
|
|
34
|
+
/** 关闭房间连接 */
|
|
35
|
+
close(roomKey: string): void;
|
|
36
|
+
}
|
|
@@ -1,30 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ModRooms = void 0;
|
|
4
|
+
const Reglist_1 = require("../abstract/Reglist");
|
|
4
5
|
/** 直播间监听实例控制器 */
|
|
5
|
-
class
|
|
6
|
+
class ModRooms {
|
|
6
7
|
constructor(main) {
|
|
7
8
|
this.roomMap = new Map();
|
|
9
|
+
this.auths = new Map();
|
|
10
|
+
this.configs = new Map();
|
|
8
11
|
this.main = main;
|
|
12
|
+
this.generator = new Reglist_1.Reglist(this.main, "rooms.generator");
|
|
9
13
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/** 设置登录凭据 */
|
|
15
|
+
setAuth(platform, auth) {
|
|
16
|
+
this.auths.set(platform, auth);
|
|
17
|
+
}
|
|
18
|
+
/** 设置房间配置 */
|
|
19
|
+
setConfig(platform, config) {
|
|
20
|
+
this.configs.set(platform, config);
|
|
21
|
+
}
|
|
22
|
+
/** 生成房间 */
|
|
23
|
+
generate(platform, id, open) {
|
|
24
|
+
platform = platform.toLowerCase();
|
|
25
|
+
const config = this.configs.get(platform) || {};
|
|
26
|
+
const auth = this.auths.get(platform);
|
|
27
|
+
let platformGenerator = this.generator.get(platform);
|
|
16
28
|
if (platformGenerator) {
|
|
17
|
-
return platformGenerator(id, open);
|
|
29
|
+
return platformGenerator(id, open, { auth, ...config });
|
|
18
30
|
}
|
|
19
31
|
else {
|
|
20
|
-
this.main.emit("
|
|
32
|
+
this.main.emit("room:unknown_platform", platform);
|
|
21
33
|
}
|
|
22
34
|
}
|
|
23
|
-
/**
|
|
24
|
-
|
|
35
|
+
/** 添加房间监听实例 */
|
|
36
|
+
addRoom(room, open) {
|
|
25
37
|
let key = room.key;
|
|
26
38
|
if (this.roomMap.has(key)) {
|
|
27
|
-
this.main.emit("
|
|
39
|
+
this.main.emit("room:exist", key);
|
|
28
40
|
return;
|
|
29
41
|
}
|
|
30
42
|
this.roomMap.set(key, room);
|
|
@@ -34,59 +46,64 @@ class RoomController {
|
|
|
34
46
|
this.main.helper.messageHandler.getList().forEach((handler) => {
|
|
35
47
|
handler(data);
|
|
36
48
|
});
|
|
37
|
-
this.main.emit("
|
|
49
|
+
this.main.emit("live:message", data);
|
|
38
50
|
});
|
|
39
51
|
// 直播消息源数据
|
|
40
|
-
room.on("
|
|
41
|
-
this.main.emit("
|
|
52
|
+
room.on("raw", (data, { platform, room }) => {
|
|
53
|
+
this.main.emit("live:raw", data, { platform, room });
|
|
42
54
|
});
|
|
43
55
|
// 连接到直播间
|
|
44
56
|
room.on("connect", () => {
|
|
45
|
-
this.main.emit("
|
|
57
|
+
this.main.emit("room:connect", key);
|
|
46
58
|
});
|
|
47
59
|
// 与直播间的连接已断开
|
|
48
60
|
room.on("disconnect", () => {
|
|
49
|
-
this.main.emit("
|
|
61
|
+
this.main.emit("room:disconnect", key);
|
|
50
62
|
});
|
|
51
63
|
// 获取房间信息
|
|
52
64
|
room.on("info", () => {
|
|
53
|
-
this.main.emit("
|
|
65
|
+
this.main.emit("room:info", key, room.info);
|
|
54
66
|
});
|
|
55
67
|
// 直播展示信息更改
|
|
56
68
|
room.on("detail", (data) => {
|
|
57
|
-
this.main.emit("
|
|
69
|
+
this.main.emit("room:detail", key, data);
|
|
58
70
|
});
|
|
59
71
|
// 直播状态更改
|
|
60
72
|
room.on("status", (status, { id, timestamp }) => {
|
|
61
|
-
this.main.emit("
|
|
73
|
+
this.main.emit("room:status", key, status, { id, timestamp });
|
|
62
74
|
});
|
|
63
75
|
// 统计数据更新
|
|
64
76
|
room.on("stats", (data) => {
|
|
65
|
-
this.main.emit("
|
|
77
|
+
this.main.emit("room:stats", key, data);
|
|
66
78
|
});
|
|
67
79
|
// 房间被打开
|
|
68
80
|
room.on("open", () => {
|
|
69
|
-
this.main.emit("
|
|
81
|
+
this.main.emit("room:open", key, room.info);
|
|
70
82
|
});
|
|
71
83
|
// 房间被关闭
|
|
72
84
|
room.on("close", () => {
|
|
73
|
-
this.main.emit("
|
|
85
|
+
this.main.emit("room:close", key, room.info);
|
|
74
86
|
});
|
|
75
87
|
if (open) {
|
|
76
88
|
room.open();
|
|
77
89
|
}
|
|
78
|
-
this.main.emit("
|
|
90
|
+
this.main.emit("room:add", key, room.info);
|
|
91
|
+
}
|
|
92
|
+
/** 添加房间 */
|
|
93
|
+
add(platform, id, open) {
|
|
94
|
+
const room = this.generate(platform, id, open);
|
|
95
|
+
room && this.addRoom(room);
|
|
79
96
|
}
|
|
80
97
|
/** 移除房间 */
|
|
81
98
|
remove(roomKey) {
|
|
82
99
|
if (!this.roomMap.has(roomKey)) {
|
|
83
|
-
this.main.emit("
|
|
100
|
+
this.main.emit("room:unexist", roomKey);
|
|
84
101
|
return;
|
|
85
102
|
}
|
|
86
103
|
let room = this.roomMap.get(roomKey);
|
|
87
104
|
this.roomMap.delete(roomKey); // 从表中删除房间
|
|
88
105
|
room?.removeAllListeners(); // 移除房间监听实例
|
|
89
|
-
this.main.emit("
|
|
106
|
+
this.main.emit("room:remove", roomKey);
|
|
90
107
|
}
|
|
91
108
|
/** 获取房间 */
|
|
92
109
|
get(roomKey) {
|
|
@@ -103,16 +120,18 @@ class RoomController {
|
|
|
103
120
|
room && room.getInfo();
|
|
104
121
|
}
|
|
105
122
|
/** 获取roomKey列表 */
|
|
106
|
-
get
|
|
123
|
+
get keys() {
|
|
107
124
|
return [...this.roomMap.keys()];
|
|
108
125
|
}
|
|
126
|
+
/** 打开房间连接 */
|
|
109
127
|
open(roomKey) {
|
|
110
128
|
let room = this.roomMap.get(roomKey);
|
|
111
|
-
room?.available && !room.
|
|
129
|
+
room?.available && !room.opened && room.open();
|
|
112
130
|
}
|
|
131
|
+
/** 关闭房间连接 */
|
|
113
132
|
close(roomKey) {
|
|
114
133
|
let room = this.roomMap.get(roomKey);
|
|
115
|
-
room?.
|
|
134
|
+
room?.opened && room.close();
|
|
116
135
|
}
|
|
117
136
|
}
|
|
118
|
-
exports.
|
|
137
|
+
exports.ModRooms = ModRooms;
|
package/src/types/index.d.ts
CHANGED
package/src/types/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./message
|
|
18
|
-
__exportStar(require("./message/MessageData"), exports);
|
|
17
|
+
__exportStar(require("./message"), exports);
|
|
19
18
|
__exportStar(require("./plugin"), exports);
|
|
20
19
|
__exportStar(require("./room"), exports);
|