floating-live 0.10.2 → 0.11.1
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/index.d.ts +2 -4
- package/index.js +2 -4
- package/package.json +2 -2
- package/plugin/acfun/acfunLive.d.ts +7 -4
- package/plugin/acfun/acfunLive.js +57 -28
- package/plugin/acfun/index.d.ts +3 -1
- package/plugin/acfun/index.js +8 -4
- package/plugin/bilibili/bilibiliLive.d.ts +11 -6
- package/plugin/bilibili/bilibiliLive.js +95 -67
- package/plugin/bilibili/index.d.ts +4 -2
- package/plugin/bilibili/index.js +8 -4
- package/plugin/chatPrint/chatPrint.d.ts +2 -2
- package/plugin/chatPrint/chatPrint.js +4 -3
- package/plugin/chatPrint/index.d.ts +4 -2
- package/plugin/chatPrint/index.js +6 -2
- package/plugin/consoleEvent/index.d.ts +4 -2
- package/plugin/consoleEvent/index.js +6 -1
- package/plugin/msgSave/index.d.ts +8 -4
- package/plugin/msgSave/index.js +76 -21
- package/plugin/msgSave/msgSave.d.ts +75 -14
- package/plugin/msgSave/msgSave.js +130 -19
- package/src/enum.d.ts +34 -0
- package/src/enum.js +41 -0
- package/src/index.d.ts +3 -3
- package/src/index.js +9 -7
- package/src/lib/LiveRoom.d.ts +10 -9
- package/src/lib/LiveRoom.js +28 -27
- package/src/module/Command.d.ts +2 -1
- package/src/module/Command.js +3 -3
- package/src/module/Plugin.d.ts +4 -2
- package/src/module/Plugin.js +12 -4
- package/src/module/Room.js +7 -7
- package/src/types/index.d.ts +4 -0
- package/src/types/index.js +20 -0
- package/src/types/message/AttributeInfo.d.ts +5 -4
- package/src/types/message/MessageData.d.ts +20 -24
- package/src/types/plugin.d.ts +9 -0
- package/src/types/{room/PlatformInfo.d.ts → room.d.ts} +2 -0
- package/src/types/plugin/Plugin.d.ts +0 -5
- /package/src/types/{plugin/Plugin.js → plugin.js} +0 -0
- /package/src/types/{room/PlatformInfo.js → room.js} +0 -0
|
@@ -1,22 +1,83 @@
|
|
|
1
|
+
import { RoomStatus } from '../..';
|
|
1
2
|
import { FloatingLive } from "../..";
|
|
2
|
-
|
|
3
|
+
interface SaveInfoConfig {
|
|
4
|
+
platform: string;
|
|
5
|
+
room: string | number;
|
|
6
|
+
status: RoomStatus;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
statusChanged: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare class SaveInfo implements SaveInfoConfig {
|
|
11
|
+
/** 文件id */
|
|
12
|
+
get fileId(): string;
|
|
13
|
+
/** 平台 */
|
|
14
|
+
platform: string;
|
|
15
|
+
/** 房间号 */
|
|
16
|
+
room: string | number;
|
|
17
|
+
/** 时间戳 */
|
|
18
|
+
timestamp: number;
|
|
19
|
+
/** 状态 */
|
|
20
|
+
status: RoomStatus;
|
|
21
|
+
/** 文件是否存在 */
|
|
22
|
+
exist: boolean;
|
|
23
|
+
/** 记录状态是否已更改 */
|
|
24
|
+
statusChanged: boolean;
|
|
25
|
+
/** 按状态分文件 */
|
|
26
|
+
sliceByStatus: boolean;
|
|
27
|
+
/** 消息记录数 */
|
|
28
|
+
count: number;
|
|
29
|
+
/** 总消息记录数 */
|
|
30
|
+
totalCount: number;
|
|
31
|
+
/** 按消息记录数分文件 */
|
|
32
|
+
sliceByCount: number;
|
|
33
|
+
/** 分块id */
|
|
34
|
+
part: number;
|
|
35
|
+
constructor({ platform, room, status, timestamp, statusChanged, sliceByStatus, sliceByCount }: SaveInfoConfig & {
|
|
36
|
+
sliceByStatus?: boolean;
|
|
37
|
+
sliceByCount?: number;
|
|
38
|
+
});
|
|
39
|
+
/** 分块 */
|
|
40
|
+
slice(): void;
|
|
41
|
+
}
|
|
42
|
+
declare class MsgSave {
|
|
3
43
|
/** 主模块 */
|
|
4
44
|
main: FloatingLive;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
45
|
+
/** 文件路径 */
|
|
46
|
+
path: string;
|
|
47
|
+
/** 前缀 */
|
|
48
|
+
prefix: string;
|
|
49
|
+
/** 后缀 */
|
|
50
|
+
suffix: string;
|
|
51
|
+
/** 按状态分文件 */
|
|
52
|
+
sliceByStatus: boolean;
|
|
53
|
+
sliceByCount: number;
|
|
8
54
|
paused: boolean;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
55
|
+
/** 列表 */
|
|
56
|
+
list: Map<string, SaveInfo>;
|
|
57
|
+
constructor(main: FloatingLive, { filePath, prefix, suffix, open, sliceByStatus, sliceByCount }: {
|
|
58
|
+
filePath: string;
|
|
59
|
+
prefix?: string;
|
|
60
|
+
suffix?: string;
|
|
61
|
+
open?: boolean;
|
|
62
|
+
sliceByStatus?: boolean;
|
|
63
|
+
sliceByCount?: number;
|
|
13
64
|
});
|
|
14
|
-
write(message: any
|
|
65
|
+
write(message: any, { platform, room }: {
|
|
66
|
+
platform: string;
|
|
67
|
+
room: string | number;
|
|
68
|
+
}): void;
|
|
15
69
|
start(): void;
|
|
16
70
|
pause(): void;
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
|
|
71
|
+
/** 设置保存信息 */
|
|
72
|
+
setSaveInfo({ platform, room, status, timestamp, statusChanged }: SaveInfoConfig): void;
|
|
73
|
+
/** 创建保存信息,用于记录信息可能不存在的情况 */
|
|
74
|
+
createSaveInfo({ platform, room }: {
|
|
75
|
+
platform: string;
|
|
76
|
+
room: string | number;
|
|
77
|
+
}): SaveInfo;
|
|
78
|
+
/** 创建记录文件 */
|
|
79
|
+
createFile(roomKey: string): void;
|
|
80
|
+
/** 移除记录信息 */
|
|
81
|
+
removeSaveInfo(roomKey: string): void;
|
|
21
82
|
}
|
|
22
|
-
export default
|
|
83
|
+
export default MsgSave;
|
|
@@ -3,25 +3,88 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const __1 = require("../..");
|
|
6
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
function getTimeStr(timestamp) {
|
|
10
|
+
let startDate = new Date(timestamp);
|
|
11
|
+
return `${startDate.getFullYear()}${(startDate.getMonth() + 1).toString().padStart(2, '0')}${startDate.getDate().toString().padStart(2, '0')}_${startDate.getHours().toString().padStart(2, '0')}${startDate.getMinutes().toString().padStart(2, '0')}${startDate.getSeconds().toString().padStart(2, '0')}`;
|
|
12
|
+
}
|
|
13
|
+
/** 获取当次记录状态
|
|
14
|
+
* S=直播开始 L=直播中 E=直播结束 O=未开播
|
|
15
|
+
*/
|
|
16
|
+
function getRecordStatus(status, statusChanged) {
|
|
17
|
+
if (status == __1.RoomStatus.live) {
|
|
18
|
+
/** 已开播 */
|
|
19
|
+
return statusChanged ? "S" : "L";
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
/** 未开播 */
|
|
23
|
+
return statusChanged ? "E" : "O";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class SaveInfo {
|
|
27
|
+
constructor({ platform, room, status, timestamp, statusChanged, sliceByStatus = false, sliceByCount = 0 }) {
|
|
28
|
+
/** 文件是否存在 */
|
|
29
|
+
this.exist = false;
|
|
30
|
+
/** 记录状态是否已更改 */
|
|
31
|
+
this.statusChanged = false;
|
|
32
|
+
/** 消息记录数 */
|
|
33
|
+
this.count = 0;
|
|
34
|
+
/** 总消息记录数 */
|
|
35
|
+
this.totalCount = 0;
|
|
36
|
+
this.platform = platform;
|
|
37
|
+
this.room = room;
|
|
38
|
+
this.status = status;
|
|
39
|
+
this.timestamp = timestamp;
|
|
40
|
+
this.statusChanged = statusChanged;
|
|
41
|
+
this.sliceByStatus = sliceByStatus;
|
|
42
|
+
this.sliceByCount = sliceByCount;
|
|
43
|
+
this.part = sliceByCount && 1;
|
|
44
|
+
}
|
|
45
|
+
/** 文件id */
|
|
46
|
+
get fileId() {
|
|
47
|
+
return `${this.platform}_${this.room}-${getTimeStr(this.timestamp || 0)}${this.sliceByStatus ? getRecordStatus(this.status, this.statusChanged) : ""}${this.part ? `.${this.part}` : ""}`;
|
|
48
|
+
}
|
|
49
|
+
/** 分块 */
|
|
50
|
+
slice() {
|
|
51
|
+
this.exist = false;
|
|
52
|
+
this.count = 0;
|
|
53
|
+
this.part += 1;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class MsgSave {
|
|
57
|
+
constructor(main, { filePath, prefix = "", suffix = "", open = true, sliceByStatus = false, sliceByCount = 0 }) {
|
|
58
|
+
/** 列表 */
|
|
59
|
+
this.list = new Map();
|
|
9
60
|
this.paused = !open;
|
|
10
61
|
this.main = main;
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
62
|
+
this.path = filePath;
|
|
63
|
+
this.prefix = prefix;
|
|
64
|
+
this.suffix = suffix;
|
|
65
|
+
this.sliceByStatus = sliceByStatus;
|
|
66
|
+
this.sliceByCount = sliceByCount;
|
|
67
|
+
}
|
|
68
|
+
write(message, { platform, room }) {
|
|
69
|
+
if (this.paused)
|
|
70
|
+
return;
|
|
71
|
+
const roomKey = `${platform}:${room}`;
|
|
72
|
+
// 获取保存信息,若信息不存在,则设置一个信息
|
|
73
|
+
const saveInfo = this.list.get(roomKey) || this.createSaveInfo({ platform, room });
|
|
74
|
+
// 若文件不存在,则创建一个有record_info信息的.floatrec文件
|
|
75
|
+
if (!saveInfo.exist)
|
|
76
|
+
this.createFile(roomKey);
|
|
77
|
+
const file = path_1.default.join(this.path, `${this.prefix}${saveInfo.fileId}${this.suffix}.floatrec`);
|
|
78
|
+
fs_extra_1.default.writeFile(file, JSON.stringify(message) + ",", { encoding: "utf8", flag: "a" }, (err) => {
|
|
21
79
|
if (err)
|
|
22
80
|
throw err;
|
|
23
81
|
// console.log('写入成功');
|
|
24
82
|
});
|
|
83
|
+
// 保存信息递增
|
|
84
|
+
saveInfo.count += 1;
|
|
85
|
+
// 若单文件保存信息已达最大值,则切分到下一个文件
|
|
86
|
+
if (saveInfo.sliceByCount && saveInfo.sliceByCount <= saveInfo.count)
|
|
87
|
+
saveInfo.slice();
|
|
25
88
|
}
|
|
26
89
|
start() {
|
|
27
90
|
this.paused = false;
|
|
@@ -29,13 +92,61 @@ class msgSave {
|
|
|
29
92
|
pause() {
|
|
30
93
|
this.paused = true;
|
|
31
94
|
}
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
95
|
+
/** 设置保存信息 */
|
|
96
|
+
setSaveInfo({ platform, room, status, timestamp, statusChanged }) {
|
|
97
|
+
const saveInfo = new SaveInfo({
|
|
98
|
+
platform,
|
|
99
|
+
room,
|
|
100
|
+
status,
|
|
101
|
+
timestamp,
|
|
102
|
+
statusChanged,
|
|
103
|
+
sliceByStatus: this.sliceByStatus,
|
|
104
|
+
sliceByCount: this.sliceByCount,
|
|
105
|
+
});
|
|
106
|
+
const roomKey = `${platform}:${room}`;
|
|
107
|
+
if (this.list.get(roomKey)?.fileId == saveInfo.fileId)
|
|
108
|
+
return;
|
|
109
|
+
this.list.set(roomKey, saveInfo);
|
|
110
|
+
}
|
|
111
|
+
/** 创建保存信息,用于记录信息可能不存在的情况 */
|
|
112
|
+
createSaveInfo({ platform, room }) {
|
|
113
|
+
const { status, timestamp } = this.main.room.get(`${platform}:${room}`)?.info || { status: __1.RoomStatus.off, timestamp: 0 };
|
|
114
|
+
const saveInfoConfig = {
|
|
115
|
+
platform,
|
|
116
|
+
room, status,
|
|
117
|
+
timestamp,
|
|
118
|
+
statusChanged: false,
|
|
119
|
+
sliceByStatus: this.sliceByStatus,
|
|
120
|
+
sliceByCount: this.sliceByCount,
|
|
121
|
+
};
|
|
122
|
+
this.setSaveInfo(saveInfoConfig);
|
|
123
|
+
return this.list.get(`${platform}:${room}`);
|
|
124
|
+
}
|
|
125
|
+
/** 创建记录文件 */
|
|
126
|
+
createFile(roomKey) {
|
|
127
|
+
const saveInfo = this.list.get(roomKey);
|
|
128
|
+
const file = path_1.default.join(this.path, `${this.prefix}${saveInfo.fileId}${this.suffix}.floatrec`);
|
|
129
|
+
// 如果文件已存在,则将文件标记为已存在,否则创建一个文件并写入record_info信息
|
|
130
|
+
if (fs_extra_1.default.existsSync(file)) {
|
|
131
|
+
saveInfo.exist = true;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
fs_extra_1.default.ensureFileSync(file);
|
|
135
|
+
const message = {
|
|
136
|
+
type: "record_info",
|
|
137
|
+
platform: saveInfo.platform,
|
|
138
|
+
room: saveInfo.room,
|
|
139
|
+
timestamp: saveInfo.timestamp,
|
|
140
|
+
statusChanged: saveInfo.statusChanged,
|
|
141
|
+
index: saveInfo.totalCount,
|
|
142
|
+
part: saveInfo.part,
|
|
143
|
+
roomInfo: this.main.room.get(roomKey)?.info,
|
|
144
|
+
};
|
|
145
|
+
fs_extra_1.default.writeFileSync(file, JSON.stringify(message) + ",", { encoding: "utf8", flag: "a" });
|
|
35
146
|
}
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
this.
|
|
147
|
+
/** 移除记录信息 */
|
|
148
|
+
removeSaveInfo(roomKey) {
|
|
149
|
+
this.list.delete(roomKey);
|
|
39
150
|
}
|
|
40
151
|
}
|
|
41
|
-
exports.default =
|
|
152
|
+
exports.default = MsgSave;
|
package/src/enum.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** 直播间状态 */
|
|
2
|
+
export declare enum RoomStatus {
|
|
3
|
+
/** 未开播 */
|
|
4
|
+
off = 0,
|
|
5
|
+
/** 正在直播 */
|
|
6
|
+
live = 1,
|
|
7
|
+
/** 正在轮播 */
|
|
8
|
+
round = 2,
|
|
9
|
+
/** 被封禁 */
|
|
10
|
+
banned = -1
|
|
11
|
+
}
|
|
12
|
+
/** 图片大小 */
|
|
13
|
+
export declare enum ImageSize {
|
|
14
|
+
/** 自定义大小 */
|
|
15
|
+
custom = 0,
|
|
16
|
+
/** 小表情(文字行高) */
|
|
17
|
+
small = 1,
|
|
18
|
+
/** 大表情 */
|
|
19
|
+
large = 2
|
|
20
|
+
}
|
|
21
|
+
/** 弹幕模式 */
|
|
22
|
+
export declare enum DanmakuMode {
|
|
23
|
+
left = 1,
|
|
24
|
+
bottom = 4,
|
|
25
|
+
top = 5,
|
|
26
|
+
right = 6
|
|
27
|
+
}
|
|
28
|
+
/** 管理等级 */
|
|
29
|
+
export declare enum UserAdmin {
|
|
30
|
+
/** 房管 */
|
|
31
|
+
admin = 1,
|
|
32
|
+
/** 主播 */
|
|
33
|
+
anchor = 2
|
|
34
|
+
}
|
package/src/enum.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserAdmin = exports.DanmakuMode = exports.ImageSize = exports.RoomStatus = void 0;
|
|
4
|
+
/** 直播间状态 */
|
|
5
|
+
var RoomStatus;
|
|
6
|
+
(function (RoomStatus) {
|
|
7
|
+
/** 未开播 */
|
|
8
|
+
RoomStatus[RoomStatus["off"] = 0] = "off";
|
|
9
|
+
/** 正在直播 */
|
|
10
|
+
RoomStatus[RoomStatus["live"] = 1] = "live";
|
|
11
|
+
/** 正在轮播 */
|
|
12
|
+
RoomStatus[RoomStatus["round"] = 2] = "round";
|
|
13
|
+
/** 被封禁 */
|
|
14
|
+
RoomStatus[RoomStatus["banned"] = -1] = "banned";
|
|
15
|
+
})(RoomStatus = exports.RoomStatus || (exports.RoomStatus = {}));
|
|
16
|
+
/** 图片大小 */
|
|
17
|
+
var ImageSize;
|
|
18
|
+
(function (ImageSize) {
|
|
19
|
+
/** 自定义大小 */
|
|
20
|
+
ImageSize[ImageSize["custom"] = 0] = "custom";
|
|
21
|
+
/** 小表情(文字行高) */
|
|
22
|
+
ImageSize[ImageSize["small"] = 1] = "small";
|
|
23
|
+
/** 大表情 */
|
|
24
|
+
ImageSize[ImageSize["large"] = 2] = "large";
|
|
25
|
+
})(ImageSize = exports.ImageSize || (exports.ImageSize = {}));
|
|
26
|
+
/** 弹幕模式 */
|
|
27
|
+
var DanmakuMode;
|
|
28
|
+
(function (DanmakuMode) {
|
|
29
|
+
DanmakuMode[DanmakuMode["left"] = 1] = "left";
|
|
30
|
+
DanmakuMode[DanmakuMode["bottom"] = 4] = "bottom";
|
|
31
|
+
DanmakuMode[DanmakuMode["top"] = 5] = "top";
|
|
32
|
+
DanmakuMode[DanmakuMode["right"] = 6] = "right";
|
|
33
|
+
})(DanmakuMode = exports.DanmakuMode || (exports.DanmakuMode = {}));
|
|
34
|
+
/** 管理等级 */
|
|
35
|
+
var UserAdmin;
|
|
36
|
+
(function (UserAdmin) {
|
|
37
|
+
/** 房管 */
|
|
38
|
+
UserAdmin[UserAdmin["admin"] = 1] = "admin";
|
|
39
|
+
/** 主播 */
|
|
40
|
+
UserAdmin[UserAdmin["anchor"] = 2] = "anchor";
|
|
41
|
+
})(UserAdmin = exports.UserAdmin || (exports.UserAdmin = {}));
|
package/src/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
3
|
import { Reglist } from "./lib/Reglist";
|
|
4
4
|
import { LiveRoom } from "./lib/LiveRoom";
|
|
5
|
-
import { MessageData } from "./types
|
|
5
|
+
import { MessageData } from "./types";
|
|
6
6
|
import { PluginHandler } from "./module/Plugin";
|
|
7
7
|
import { RoomController } from "./module/Room";
|
|
8
8
|
export declare class FloatingLive extends EventEmitter {
|
|
@@ -23,7 +23,7 @@ export declare class FloatingLive extends EventEmitter {
|
|
|
23
23
|
pluginRemoveHandler: Reglist<(name: string) => void>;
|
|
24
24
|
};
|
|
25
25
|
/** 插件事件注册表 */
|
|
26
|
-
private
|
|
26
|
+
private regEventMap;
|
|
27
27
|
/** 状态 */
|
|
28
28
|
private status;
|
|
29
29
|
get started(): boolean;
|
|
@@ -39,7 +39,7 @@ export declare class FloatingLive extends EventEmitter {
|
|
|
39
39
|
addRoom({ platform, id }: {
|
|
40
40
|
platform: string;
|
|
41
41
|
id: string | number;
|
|
42
|
-
}, open?: boolean): void;
|
|
42
|
+
}, open?: boolean, config?: {}): void;
|
|
43
43
|
/** 移除房间 */
|
|
44
44
|
removeRoom(roomKey: string): void;
|
|
45
45
|
/** 添加房间实例 */
|
package/src/index.js
CHANGED
|
@@ -9,7 +9,7 @@ class FloatingLive extends events_1.EventEmitter {
|
|
|
9
9
|
constructor() {
|
|
10
10
|
super();
|
|
11
11
|
/** 插件事件注册表 */
|
|
12
|
-
this.
|
|
12
|
+
this.regEventMap = new Map();
|
|
13
13
|
/** 状态 */
|
|
14
14
|
this.status = {
|
|
15
15
|
started: false,
|
|
@@ -34,11 +34,13 @@ class FloatingLive extends events_1.EventEmitter {
|
|
|
34
34
|
}
|
|
35
35
|
/** 初始化 */
|
|
36
36
|
init() {
|
|
37
|
+
// 监听到有房间打开,则开始记录
|
|
37
38
|
this.on("room_open", () => {
|
|
38
39
|
this.started || this.start();
|
|
39
40
|
});
|
|
41
|
+
// 设置在插件卸载时移除由插件注册的事件
|
|
40
42
|
this.helper.pluginRemoveHandler.register("removePluginEvent", (name) => {
|
|
41
|
-
this.
|
|
43
|
+
this.regEventMap.get(name)?.forEach(([eventName, listener]) => {
|
|
42
44
|
this.removeListener(eventName, listener);
|
|
43
45
|
});
|
|
44
46
|
});
|
|
@@ -46,7 +48,7 @@ class FloatingLive extends events_1.EventEmitter {
|
|
|
46
48
|
/** 开始 */
|
|
47
49
|
start() {
|
|
48
50
|
this.status.started = true;
|
|
49
|
-
this.status.timestamp =
|
|
51
|
+
this.status.timestamp = Date.now();
|
|
50
52
|
this.emit("start", this.timestamp);
|
|
51
53
|
}
|
|
52
54
|
/** 结束 */
|
|
@@ -57,7 +59,7 @@ class FloatingLive extends events_1.EventEmitter {
|
|
|
57
59
|
this.status.timestamp = 0;
|
|
58
60
|
}
|
|
59
61
|
/** 添加房间 */
|
|
60
|
-
addRoom({ platform, id }, open) {
|
|
62
|
+
addRoom({ platform, id }, open, config) {
|
|
61
63
|
let generated = this.room.generate({ platform, id }, open);
|
|
62
64
|
if (generated) {
|
|
63
65
|
this.room.add(generated);
|
|
@@ -100,10 +102,10 @@ class FloatingLive extends events_1.EventEmitter {
|
|
|
100
102
|
super.on(eventName, listener);
|
|
101
103
|
// 检测是否为插件添加事件,并添加进事件列表
|
|
102
104
|
if (this.plugin.currentPlugin) {
|
|
103
|
-
if (!this.
|
|
104
|
-
this.
|
|
105
|
+
if (!this.regEventMap.has(this.plugin.currentPlugin)) {
|
|
106
|
+
this.regEventMap.set(this.plugin.currentPlugin, []);
|
|
105
107
|
}
|
|
106
|
-
this.
|
|
108
|
+
this.regEventMap.get(this.plugin.currentPlugin)?.push([eventName, listener]);
|
|
107
109
|
}
|
|
108
110
|
return this;
|
|
109
111
|
}
|
package/src/lib/LiveRoom.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
|
-
import {
|
|
4
|
-
import { MessageData } from "
|
|
3
|
+
import { RoomStatus } from "../enum";
|
|
4
|
+
import { MessageData, UserInfo } from "../../src/types";
|
|
5
5
|
export interface RoomInfo {
|
|
6
6
|
/** 平台id */
|
|
7
7
|
platform: string;
|
|
@@ -10,13 +10,15 @@ export interface RoomInfo {
|
|
|
10
10
|
/** 房间key */
|
|
11
11
|
key: string;
|
|
12
12
|
/** 基本信息 */
|
|
13
|
-
|
|
13
|
+
view: RoomViewInfo;
|
|
14
14
|
/** 统计信息 */
|
|
15
15
|
stats?: RoomStatsInfo;
|
|
16
16
|
/** 主播信息 */
|
|
17
17
|
anchor: UserInfo;
|
|
18
18
|
/** 时间戳 */
|
|
19
19
|
timestamp: number;
|
|
20
|
+
/** 当前直播id */
|
|
21
|
+
liveId?: string;
|
|
20
22
|
/** 直播状态 */
|
|
21
23
|
status: RoomStatus;
|
|
22
24
|
/** 直播间是否可用 */
|
|
@@ -26,8 +28,8 @@ export interface RoomInfo {
|
|
|
26
28
|
/** 是否连接到房间 */
|
|
27
29
|
connected: boolean;
|
|
28
30
|
}
|
|
29
|
-
/**
|
|
30
|
-
export declare type
|
|
31
|
+
/** 房间展示信息 */
|
|
32
|
+
export declare type RoomViewInfo = {
|
|
31
33
|
/** 直播标题 */
|
|
32
34
|
title?: string;
|
|
33
35
|
/** 分区 */
|
|
@@ -46,8 +48,6 @@ export declare type RoomStatsInfo = {
|
|
|
46
48
|
/** 人气值 */
|
|
47
49
|
popularity?: number;
|
|
48
50
|
};
|
|
49
|
-
/** 房间状态 */
|
|
50
|
-
export declare type RoomStatus = "live" | "off" | "round" | "banned";
|
|
51
51
|
export declare abstract class LiveRoom extends EventEmitter implements RoomInfo {
|
|
52
52
|
constructor();
|
|
53
53
|
/** 平台 */
|
|
@@ -55,7 +55,7 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
|
|
|
55
55
|
/** 房间id */
|
|
56
56
|
abstract readonly id: string | number;
|
|
57
57
|
/** 基本信息 */
|
|
58
|
-
abstract
|
|
58
|
+
abstract view: RoomViewInfo;
|
|
59
59
|
/** 统计信息 */
|
|
60
60
|
stats?: RoomStatsInfo;
|
|
61
61
|
/** 主播信息 */
|
|
@@ -64,6 +64,8 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
|
|
|
64
64
|
status: RoomStatus;
|
|
65
65
|
/** 时间戳 */
|
|
66
66
|
timestamp: number;
|
|
67
|
+
/** 当前直播id */
|
|
68
|
+
liveId?: string;
|
|
67
69
|
/** 房间是否打开 */
|
|
68
70
|
opening: boolean;
|
|
69
71
|
/** 房间是否可用 */
|
|
@@ -84,5 +86,4 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
|
|
|
84
86
|
protected emitOrigin(msg: any): void;
|
|
85
87
|
get info(): RoomInfo;
|
|
86
88
|
get key(): string;
|
|
87
|
-
private msgCheck;
|
|
88
89
|
}
|
package/src/lib/LiveRoom.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiveRoom = void 0;
|
|
4
4
|
const events_1 = require("events");
|
|
5
|
+
const enum_1 = require("../enum");
|
|
5
6
|
class LiveRoom extends events_1.EventEmitter {
|
|
6
7
|
constructor() {
|
|
7
8
|
super();
|
|
8
9
|
/** 直播状态 */
|
|
9
|
-
this.status =
|
|
10
|
+
this.status = enum_1.RoomStatus.off;
|
|
10
11
|
/** 时间戳 */
|
|
11
12
|
this.timestamp = 0;
|
|
12
13
|
/** 房间是否打开 */
|
|
@@ -20,22 +21,45 @@ class LiveRoom extends events_1.EventEmitter {
|
|
|
20
21
|
}
|
|
21
22
|
// 发送消息
|
|
22
23
|
emitMsg(msg) {
|
|
23
|
-
|
|
24
|
+
// 其他消息 => 先更改状态再发送消息
|
|
25
|
+
// 直播结束消息 => 先发送消息再更改状态
|
|
26
|
+
switch (msg.type) {
|
|
27
|
+
case "live_start":
|
|
28
|
+
this.status = enum_1.RoomStatus.live;
|
|
29
|
+
this.timestamp = msg.timestamp;
|
|
30
|
+
this.emit("status", enum_1.RoomStatus.live, { timestamp: msg.timestamp, id: msg.info.id });
|
|
31
|
+
break;
|
|
32
|
+
case "live_view":
|
|
33
|
+
this.view = Object.assign(this.view, msg.info);
|
|
34
|
+
this.emit("view", msg.info);
|
|
35
|
+
break;
|
|
36
|
+
case "live_stats":
|
|
37
|
+
this.stats = Object.assign(this.stats, msg.info);
|
|
38
|
+
break;
|
|
39
|
+
case "live_end":
|
|
40
|
+
case "live_cut":
|
|
41
|
+
this.emit("msg", msg);
|
|
42
|
+
this.status = msg.status || enum_1.RoomStatus.off;
|
|
43
|
+
this.timestamp = msg.timestamp;
|
|
44
|
+
this.emit("status", msg.status || enum_1.RoomStatus.off, { timestamp: msg.timestamp });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
24
47
|
this.emit("msg", msg);
|
|
25
48
|
}
|
|
26
49
|
// 发送源消息
|
|
27
50
|
emitOrigin(msg) {
|
|
28
|
-
this.emit("origin", msg);
|
|
51
|
+
this.emit("origin", msg, { platform: this.platform, room: this.id });
|
|
29
52
|
}
|
|
30
53
|
get info() {
|
|
31
54
|
return {
|
|
32
55
|
platform: this.platform,
|
|
33
56
|
id: this.id,
|
|
34
|
-
|
|
57
|
+
view: this.view,
|
|
35
58
|
stats: this.stats,
|
|
36
59
|
anchor: this.anchor,
|
|
37
60
|
timestamp: this.timestamp,
|
|
38
61
|
status: this.status,
|
|
62
|
+
liveId: this.liveId,
|
|
39
63
|
available: this.available,
|
|
40
64
|
opening: this.opening,
|
|
41
65
|
connected: this.connected,
|
|
@@ -45,28 +69,5 @@ class LiveRoom extends events_1.EventEmitter {
|
|
|
45
69
|
get key() {
|
|
46
70
|
return `${this.platform}:${this.id}`;
|
|
47
71
|
}
|
|
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
|
}
|
|
72
73
|
exports.LiveRoom = LiveRoom;
|
package/src/module/Command.d.ts
CHANGED
package/src/module/Command.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
class Command {
|
|
3
|
+
const Reglist_1 = require("../lib/Reglist");
|
|
4
|
+
class Command extends Reglist_1.Reglist {
|
|
5
5
|
}
|
|
6
|
-
exports.
|
|
6
|
+
exports.default = Command;
|
package/src/module/Plugin.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FloatingLive } from "..";
|
|
2
|
+
import { FloatingLivePlugin } from "../types/plugin";
|
|
2
3
|
export declare class PluginHandler<T extends FloatingLive> {
|
|
3
4
|
private current;
|
|
5
|
+
/** 插件列表 */
|
|
4
6
|
private list;
|
|
5
7
|
private pluginEvent;
|
|
6
8
|
private main;
|
|
@@ -14,9 +16,9 @@ export declare class PluginHandler<T extends FloatingLive> {
|
|
|
14
16
|
[key: string]: any;
|
|
15
17
|
} | undefined;
|
|
16
18
|
/** 注册插件 */
|
|
17
|
-
register(name: string,
|
|
19
|
+
register(name: string, plugin: FloatingLivePlugin<T>, config?: {
|
|
18
20
|
[key: string]: any;
|
|
19
|
-
}
|
|
21
|
+
}): void | {
|
|
20
22
|
[key: string]: any;
|
|
21
23
|
};
|
|
22
24
|
/** 移除插件 */
|
package/src/module/Plugin.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.PluginHandler = void 0;
|
|
|
4
4
|
class PluginHandler {
|
|
5
5
|
constructor(main) {
|
|
6
6
|
this.current = null;
|
|
7
|
+
/** 插件列表 */
|
|
7
8
|
this.list = new Map();
|
|
8
9
|
this.pluginEvent = new Map();
|
|
9
10
|
this.main = main;
|
|
@@ -26,22 +27,29 @@ class PluginHandler {
|
|
|
26
27
|
return this.list.get(name);
|
|
27
28
|
}
|
|
28
29
|
/** 注册插件 */
|
|
29
|
-
register(name,
|
|
30
|
+
register(name, plugin, config) {
|
|
30
31
|
if (this.list.has(name)) {
|
|
31
32
|
this.main.emit("plugin_duplicate", name);
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
35
|
this.current = name;
|
|
35
36
|
// 执行插件函数并获取插件操作对象
|
|
36
|
-
let pluginObject =
|
|
37
|
-
|
|
37
|
+
let pluginObject = plugin();
|
|
38
|
+
// 如果插件register函数无法调用,则无法注册插件
|
|
39
|
+
if (typeof pluginObject.register != 'function') {
|
|
40
|
+
this.main.emit("plugin_invalid", name);
|
|
41
|
+
this.current = null;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let pluginExpose = pluginObject.register(this.main, config);
|
|
45
|
+
this.list.set(name, pluginExpose || {});
|
|
38
46
|
// 执行钩子函数
|
|
39
47
|
this.helper.pluginAddHandler.getList().forEach(handler => {
|
|
40
48
|
handler(name);
|
|
41
49
|
});
|
|
42
50
|
this.main.emit("plugin_add", name);
|
|
43
51
|
this.current = null;
|
|
44
|
-
return
|
|
52
|
+
return pluginExpose;
|
|
45
53
|
}
|
|
46
54
|
/** 移除插件 */
|
|
47
55
|
unregister(name) {
|