floating-live 0.10.1 → 0.11.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/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +2 -2
- package/plugin/acfun/acfunLive.d.ts +6 -3
- package/plugin/acfun/acfunLive.js +56 -27
- package/plugin/acfun/index.d.ts +3 -1
- package/plugin/acfun/index.js +8 -4
- package/plugin/bilibili/bilibiliLive.d.ts +10 -5
- package/plugin/bilibili/bilibiliLive.js +93 -65
- package/plugin/bilibili/index.d.ts +3 -1
- package/plugin/bilibili/index.js +8 -4
- package/plugin/chatPrint/chatPrint.js +4 -3
- package/plugin/chatPrint/index.d.ts +3 -1
- package/plugin/chatPrint/index.js +6 -2
- package/plugin/consoleEvent/index.d.ts +3 -1
- package/plugin/consoleEvent/index.js +6 -1
- package/plugin/msgSave/index.d.ts +7 -3
- package/plugin/msgSave/index.js +75 -20
- 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,11 +1,13 @@
|
|
|
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
|
+
const enum_1 = require("./../../src/enum");
|
|
6
4
|
const bilibili_live_ws_1 = require("bilibili-live-ws");
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
5
|
const LiveRoom_1 = require("../../src/lib/LiveRoom");
|
|
6
|
+
// utils
|
|
7
|
+
// 获取当前时间戳,以替代无法从数据中获取时间戳的情况,精度为1s
|
|
8
|
+
function getDateTimestamp() {
|
|
9
|
+
return Math.floor(Date.now() / 1000) * 1000;
|
|
10
|
+
}
|
|
9
11
|
class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
10
12
|
constructor(id, // 房间id
|
|
11
13
|
open = false, // 生成房间后是否打开
|
|
@@ -15,8 +17,8 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
15
17
|
this.platform = "bilibili";
|
|
16
18
|
/** 直播间room_id */
|
|
17
19
|
this.roomid = 0;
|
|
18
|
-
/**
|
|
19
|
-
this.
|
|
20
|
+
/** 展示信息 */
|
|
21
|
+
this.view = {
|
|
20
22
|
/** 直播标题 */
|
|
21
23
|
title: "",
|
|
22
24
|
/** 分区 */
|
|
@@ -24,6 +26,12 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
24
26
|
/** 封面url */
|
|
25
27
|
cover: "",
|
|
26
28
|
};
|
|
29
|
+
this.stats = {
|
|
30
|
+
/** 观看数 */
|
|
31
|
+
watch: 0,
|
|
32
|
+
/** 点赞数 */
|
|
33
|
+
like: 0,
|
|
34
|
+
};
|
|
27
35
|
/** 房间是否可用 */
|
|
28
36
|
this.available = false;
|
|
29
37
|
/** 是否连接上房间 */
|
|
@@ -42,20 +50,23 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
/** 获取房间信息 */
|
|
45
|
-
async getInfo() {
|
|
46
|
-
await
|
|
47
|
-
|
|
53
|
+
async getInfo(refresh) {
|
|
54
|
+
await fetch(`https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=${this.id}`, {
|
|
55
|
+
method: "GET"
|
|
56
|
+
}) // 获取直播间信息
|
|
57
|
+
.then((response) => response.json())
|
|
48
58
|
.then((res) => {
|
|
49
|
-
|
|
50
|
-
this.roomid =
|
|
51
|
-
this.status =
|
|
52
|
-
this.timestamp = this.status ==
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.anchor.id =
|
|
57
|
-
this.anchor.name =
|
|
58
|
-
this.anchor.avatar =
|
|
59
|
+
const { room_info, anchor_info } = res.data;
|
|
60
|
+
this.roomid = room_info.room_id;
|
|
61
|
+
this.status = room_info.live_status == 1 ? enum_1.RoomStatus.live : enum_1.RoomStatus.off;
|
|
62
|
+
this.timestamp = this.status == enum_1.RoomStatus.live ? room_info.live_start_time * 1000 : refresh ? Date.now() : this.timestamp;
|
|
63
|
+
this.view.title = room_info.title;
|
|
64
|
+
this.view.area = [room_info.parent_area_name, room_info.area_name];
|
|
65
|
+
this.view.cover = room_info.cover;
|
|
66
|
+
this.anchor.id = room_info.uid;
|
|
67
|
+
this.anchor.name = anchor_info.base_info.uname;
|
|
68
|
+
this.anchor.avatar = anchor_info.base_info.face;
|
|
69
|
+
this.liveId = room_info.live_id_str;
|
|
59
70
|
this.available = true;
|
|
60
71
|
console.log("[bilibiliLive] 已获取房间信息");
|
|
61
72
|
this.emit("info", this.info);
|
|
@@ -66,9 +77,12 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
66
77
|
}
|
|
67
78
|
/** 开启直播间监听 */
|
|
68
79
|
async open() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
// 如果直播间监听已打开,则返回
|
|
81
|
+
if (this.opening)
|
|
82
|
+
return;
|
|
83
|
+
await this.getInfo(true);
|
|
84
|
+
// 如果直播间不可用,则返回
|
|
85
|
+
if (!this.available)
|
|
72
86
|
return;
|
|
73
87
|
this.opening = true;
|
|
74
88
|
this.createWS();
|
|
@@ -107,7 +121,10 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
107
121
|
client.on("PREPARING", this.msg_PREPARING.bind(this));
|
|
108
122
|
client.on("LIVE", this.msg_LIVE.bind(this));
|
|
109
123
|
client.on("ROOM_CHANGE", this.msg_ROOM_CHANGE.bind(this));
|
|
124
|
+
client.on("WATCHED_CHANGE", this.msg_WATCHED_CHANGE.bind(this));
|
|
125
|
+
client.on("LIKE_INFO_V3_UPDATE", this.msg_LIKE_INFO_V3_UPDATE.bind(this));
|
|
110
126
|
}
|
|
127
|
+
/** 关闭直播间监听 */
|
|
111
128
|
close() {
|
|
112
129
|
if (!this.opening)
|
|
113
130
|
return;
|
|
@@ -115,22 +132,10 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
115
132
|
this.client?.close();
|
|
116
133
|
this.emit("close");
|
|
117
134
|
}
|
|
118
|
-
getDanmakuMode(n) {
|
|
119
|
-
switch (n) {
|
|
120
|
-
case 1:
|
|
121
|
-
return "left";
|
|
122
|
-
case 4:
|
|
123
|
-
return "bottom";
|
|
124
|
-
case 5:
|
|
125
|
-
return "top";
|
|
126
|
-
default:
|
|
127
|
-
return "left";
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
135
|
/** 获取弹幕消息 */
|
|
131
136
|
msg_DANMU_MSG(msg) {
|
|
132
137
|
let content = msg.info[1];
|
|
133
|
-
let mode =
|
|
138
|
+
let mode = msg.info[0][1];
|
|
134
139
|
let color = msg.info[0][3];
|
|
135
140
|
let uname = msg.info[2][1];
|
|
136
141
|
let uid = msg.info[2][0];
|
|
@@ -158,18 +163,17 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
165
|
if (msg.info[2][2]) {
|
|
161
|
-
identity =
|
|
166
|
+
identity = enum_1.UserAdmin.admin;
|
|
162
167
|
}
|
|
163
168
|
else if (uid == this.anchor.id) {
|
|
164
|
-
identity =
|
|
169
|
+
identity = enum_1.UserAdmin.anchor;
|
|
165
170
|
}
|
|
166
171
|
let danmaku = {
|
|
167
172
|
platform: "bilibili",
|
|
168
173
|
room: this.id,
|
|
169
174
|
type: "chat",
|
|
170
|
-
|
|
175
|
+
timestamp: timestamp,
|
|
171
176
|
info: {
|
|
172
|
-
timestamp: timestamp,
|
|
173
177
|
color: color,
|
|
174
178
|
mode: mode,
|
|
175
179
|
content: content,
|
|
@@ -177,7 +181,7 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
177
181
|
name: content,
|
|
178
182
|
id: msg.info[0][13].emoticon_unique,
|
|
179
183
|
url: msg.info[0][13].url,
|
|
180
|
-
|
|
184
|
+
size: msg.info[0][13].width == msg.info[0][13].height ? enum_1.ImageSize.large : enum_1.ImageSize.small,
|
|
181
185
|
} : undefined,
|
|
182
186
|
emoticon: emoticon,
|
|
183
187
|
user: {
|
|
@@ -185,7 +189,7 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
185
189
|
id: uid,
|
|
186
190
|
medal: medal,
|
|
187
191
|
membership: guard_level,
|
|
188
|
-
|
|
192
|
+
admin: identity,
|
|
189
193
|
}
|
|
190
194
|
}
|
|
191
195
|
};
|
|
@@ -193,7 +197,7 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
193
197
|
}
|
|
194
198
|
/** 获取互动消息 */
|
|
195
199
|
msg_INTERACT_WORD(msg) {
|
|
196
|
-
|
|
200
|
+
const data = msg.data;
|
|
197
201
|
let type;
|
|
198
202
|
switch (data.msg_type) {
|
|
199
203
|
case 1:
|
|
@@ -212,13 +216,12 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
212
216
|
platform: "bilibili",
|
|
213
217
|
room: this.id,
|
|
214
218
|
type: type,
|
|
215
|
-
|
|
219
|
+
timestamp: Math.floor(data.trigger_time / 1000000),
|
|
216
220
|
info: {
|
|
217
|
-
timestamp: Math.floor(data.trigger_time / 1000000),
|
|
218
221
|
user: {
|
|
219
222
|
name: data.uname,
|
|
220
223
|
id: data.uid,
|
|
221
|
-
medal: (data.fans_medal
|
|
224
|
+
medal: (data.fans_medal?.medal_level) ? {
|
|
222
225
|
level: data.fans_medal.medal_level,
|
|
223
226
|
name: data.fans_medal.medal_name,
|
|
224
227
|
id: data.fans_medal.target_id,
|
|
@@ -231,14 +234,13 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
231
234
|
}
|
|
232
235
|
/** 获取礼物消息 */
|
|
233
236
|
msg_SEND_GIFT(msg) {
|
|
234
|
-
|
|
237
|
+
const data = msg.data;
|
|
235
238
|
let gift = {
|
|
236
239
|
platform: "bilibili",
|
|
237
240
|
room: this.id,
|
|
238
241
|
type: "gift",
|
|
239
|
-
|
|
242
|
+
timestamp: data.timestamp * 1000,
|
|
240
243
|
info: {
|
|
241
|
-
timestamp: data.timestamp * 1000,
|
|
242
244
|
user: {
|
|
243
245
|
name: data.uname,
|
|
244
246
|
id: data.uid,
|
|
@@ -266,14 +268,13 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
266
268
|
}
|
|
267
269
|
/** 获取舰长开通消息 */
|
|
268
270
|
msg_GUARD_BUY(msg) {
|
|
269
|
-
|
|
271
|
+
const data = msg.data;
|
|
270
272
|
let gift = {
|
|
271
273
|
platform: "bilibili",
|
|
272
274
|
room: this.id,
|
|
273
275
|
type: "membership",
|
|
274
|
-
|
|
276
|
+
timestamp: data.start_time * 1000,
|
|
275
277
|
info: {
|
|
276
|
-
timestamp: data.start_time * 1000,
|
|
277
278
|
user: {
|
|
278
279
|
name: data.username,
|
|
279
280
|
id: data.uid,
|
|
@@ -295,15 +296,14 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
295
296
|
}
|
|
296
297
|
/** 获取醒目留言消息 */
|
|
297
298
|
msg_SUPER_CHAT_MESSAGE(msg) {
|
|
298
|
-
|
|
299
|
+
const data = msg.data;
|
|
299
300
|
let sc = {
|
|
300
301
|
platform: "bilibili",
|
|
301
302
|
room: this.id,
|
|
302
303
|
type: "superchat",
|
|
303
|
-
|
|
304
|
+
timestamp: data.ts * 1000,
|
|
304
305
|
info: {
|
|
305
306
|
id: data.id,
|
|
306
|
-
timestamp: data.ts * 1000,
|
|
307
307
|
user: {
|
|
308
308
|
name: data.user_info.uname,
|
|
309
309
|
id: data.uid,
|
|
@@ -330,21 +330,49 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
330
330
|
};
|
|
331
331
|
this.emitMsg(sc);
|
|
332
332
|
}
|
|
333
|
+
/** 观看数变化 */
|
|
334
|
+
msg_WATCHED_CHANGE(msg) {
|
|
335
|
+
const data = msg.data;
|
|
336
|
+
const stats = {
|
|
337
|
+
platform: "bilibili",
|
|
338
|
+
room: this.id,
|
|
339
|
+
type: "live_stats",
|
|
340
|
+
timestamp: getDateTimestamp(),
|
|
341
|
+
info: {
|
|
342
|
+
watch: data.num
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
this.emitMsg(stats);
|
|
346
|
+
}
|
|
347
|
+
/** 点赞数变化 */
|
|
348
|
+
msg_LIKE_INFO_V3_UPDATE(msg) {
|
|
349
|
+
const data = msg.data;
|
|
350
|
+
const stats = {
|
|
351
|
+
platform: "bilibili",
|
|
352
|
+
room: this.id,
|
|
353
|
+
type: "live_stats",
|
|
354
|
+
timestamp: getDateTimestamp(),
|
|
355
|
+
info: {
|
|
356
|
+
like: data.click_count
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
this.emitMsg(stats);
|
|
360
|
+
}
|
|
333
361
|
msg_ROOM_BLOCK_MSG(msg) {
|
|
334
362
|
// 禁言
|
|
335
|
-
|
|
336
|
-
|
|
363
|
+
const data = msg.data;
|
|
364
|
+
const block = {
|
|
337
365
|
platform: "bilibili",
|
|
338
366
|
room: this.id,
|
|
339
367
|
type: "block",
|
|
340
|
-
|
|
368
|
+
timestamp: getDateTimestamp(),
|
|
341
369
|
info: {
|
|
342
370
|
user: {
|
|
343
371
|
id: data.uid,
|
|
344
372
|
name: data.uname
|
|
345
373
|
},
|
|
346
374
|
operator: {
|
|
347
|
-
|
|
375
|
+
admin: data.operator == 2 ? enum_1.UserAdmin.anchor : enum_1.UserAdmin.admin
|
|
348
376
|
}
|
|
349
377
|
},
|
|
350
378
|
};
|
|
@@ -357,9 +385,9 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
357
385
|
platform: "bilibili",
|
|
358
386
|
room: this.id,
|
|
359
387
|
type: "live_start",
|
|
360
|
-
|
|
388
|
+
timestamp: msg.live_time * 1000,
|
|
361
389
|
info: {
|
|
362
|
-
|
|
390
|
+
id: msg.live_key.toString(),
|
|
363
391
|
},
|
|
364
392
|
};
|
|
365
393
|
this.emitMsg(live);
|
|
@@ -371,7 +399,7 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
371
399
|
platform: "bilibili",
|
|
372
400
|
room: this.id,
|
|
373
401
|
type: "live_cut",
|
|
374
|
-
|
|
402
|
+
timestamp: getDateTimestamp(),
|
|
375
403
|
info: {
|
|
376
404
|
message: msg.msg,
|
|
377
405
|
},
|
|
@@ -383,9 +411,9 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
383
411
|
platform: "bilibili",
|
|
384
412
|
room: this.id,
|
|
385
413
|
type: "live_end",
|
|
386
|
-
|
|
414
|
+
timestamp: getDateTimestamp(),
|
|
387
415
|
info: {
|
|
388
|
-
status: msg.round ?
|
|
416
|
+
status: msg.round ? enum_1.RoomStatus.round : enum_1.RoomStatus.off
|
|
389
417
|
}
|
|
390
418
|
};
|
|
391
419
|
this.emitMsg(off);
|
|
@@ -394,8 +422,8 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
394
422
|
let change = {
|
|
395
423
|
platform: "bilibili",
|
|
396
424
|
room: this.id,
|
|
397
|
-
type: "
|
|
398
|
-
|
|
425
|
+
type: "live_view",
|
|
426
|
+
timestamp: Date.now(),
|
|
399
427
|
info: {
|
|
400
428
|
title: msg.data.title,
|
|
401
429
|
area: [msg.data.parent_area_name, msg.data.area_name]
|
package/plugin/bilibili/index.js
CHANGED
|
@@ -3,8 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
const bilibiliLive_1 = __importDefault(require("./bilibiliLive"));
|
|
6
|
-
module.exports = (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
module.exports = () => {
|
|
7
|
+
return {
|
|
8
|
+
register: (ctx) => {
|
|
9
|
+
ctx.helper.roomGenerator.register("bilibili", (id, open) => {
|
|
10
|
+
return new bilibiliLive_1.default(Number(id), open);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
};
|
|
10
14
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.chatPrint = void 0;
|
|
4
|
+
const enum_1 = require("../../src/enum");
|
|
4
5
|
class chatPrint {
|
|
5
6
|
constructor(main) {
|
|
6
7
|
this.main = main;
|
|
@@ -14,8 +15,8 @@ class chatPrint {
|
|
|
14
15
|
let name = `${"\x1b[33m"}${user.name}`; // 用户名
|
|
15
16
|
let medal = user.medal ? `${"\x1b[32m"}[${user.medal.name}(${user.medal.level})] ` : ""; // 粉丝牌
|
|
16
17
|
let membership = user.membership ? `${"\x1b[36m"}[${this.getPriviliegeName(message.platform, user.membership)}]` : ""; // 特权粉丝
|
|
17
|
-
let
|
|
18
|
-
return `${medal}${membership}${
|
|
18
|
+
let admin = user.admin ? `${"\x1b[95m"}[${{ [enum_1.UserAdmin.admin]: "房管", [enum_1.UserAdmin.anchor]: "主播" }[user.admin]}]` : ""; // 房管
|
|
19
|
+
return `${medal}${membership}${admin}${name}${"\x1b[0m"}`; //[粉丝牌(等级)] [特权][房管]用户名
|
|
19
20
|
}
|
|
20
21
|
/** 获取特权粉丝名称 */
|
|
21
22
|
getPriviliegeName(platform, level) {
|
|
@@ -80,7 +81,7 @@ class chatPrint {
|
|
|
80
81
|
}
|
|
81
82
|
case "block": {
|
|
82
83
|
let user = this.getUserInfo(message);
|
|
83
|
-
let operator = message.info.operator.
|
|
84
|
+
let operator = message.info.operator.admin ? { [enum_1.UserAdmin.admin]: "房管", [enum_1.UserAdmin.anchor]: "主播" }[message.info.operator.admin] : "管理员";
|
|
84
85
|
console.log(`${user} 已被${operator}禁言`);
|
|
85
86
|
break;
|
|
86
87
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
const initEventConsole = (ctx) => {
|
|
3
3
|
ctx.on("start", () => {
|
|
4
4
|
console.log(`[controller]记录已开始: ${ctx.timestamp}`);
|
|
5
5
|
});
|
|
@@ -49,3 +49,8 @@ module.exports = (ctx) => {
|
|
|
49
49
|
console.log(`[plugin]插件名称重复: ${name}`);
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
|
+
module.exports = () => {
|
|
53
|
+
return {
|
|
54
|
+
register: initEventConsole
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { FloatingLive } from "../../src";
|
|
2
|
-
import
|
|
3
|
-
export declare const messageSave: (
|
|
4
|
-
|
|
2
|
+
import MsgSave from "../msgSave/msgSave";
|
|
3
|
+
export declare const messageSave: () => {
|
|
4
|
+
register: (ctx: FloatingLive) => MsgSave;
|
|
5
|
+
};
|
|
6
|
+
export declare const messageSaveOrigin: () => {
|
|
7
|
+
register: (ctx: FloatingLive) => MsgSave;
|
|
8
|
+
};
|
package/plugin/msgSave/index.js
CHANGED
|
@@ -5,27 +5,82 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.messageSaveOrigin = exports.messageSave = void 0;
|
|
7
7
|
const msgSave_1 = __importDefault(require("../msgSave/msgSave"));
|
|
8
|
-
const messageSave = (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
const messageSave = () => {
|
|
9
|
+
return {
|
|
10
|
+
register: (ctx) => {
|
|
11
|
+
const saveMessage = new msgSave_1.default(ctx, {
|
|
12
|
+
filePath: `./save`,
|
|
13
|
+
sliceByStatus: true,
|
|
14
|
+
});
|
|
15
|
+
// 直播状态改变时,更新保存信息
|
|
16
|
+
ctx.on("room_status", (roomKey, status, { timestamp }) => {
|
|
17
|
+
const { platform, id } = ctx.room.get(roomKey).info;
|
|
18
|
+
saveMessage.setSaveInfo({
|
|
19
|
+
platform,
|
|
20
|
+
room: id,
|
|
21
|
+
status,
|
|
22
|
+
timestamp,
|
|
23
|
+
statusChanged: true
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
// 打开直播间时,设置保存信息
|
|
27
|
+
ctx.on("room_open", (roomKey, roomInfo) => {
|
|
28
|
+
const { platform, id, status } = roomInfo;
|
|
29
|
+
saveMessage.setSaveInfo({
|
|
30
|
+
platform,
|
|
31
|
+
room: id,
|
|
32
|
+
status,
|
|
33
|
+
timestamp: Date.now(),
|
|
34
|
+
statusChanged: false
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
// 关闭直播间时,移除保存信息
|
|
38
|
+
ctx.on("room_close", (roomKey, roomInfo) => {
|
|
39
|
+
saveMessage.removeSaveInfo(roomKey);
|
|
40
|
+
});
|
|
41
|
+
ctx.on("live_message", (msg) => {
|
|
42
|
+
saveMessage.write(msg, msg);
|
|
43
|
+
});
|
|
44
|
+
ctx.on("start", () => {
|
|
45
|
+
saveMessage.start();
|
|
46
|
+
});
|
|
47
|
+
ctx.on("end", () => { saveMessage.pause(); });
|
|
48
|
+
return saveMessage;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
18
51
|
};
|
|
19
52
|
exports.messageSave = messageSave;
|
|
20
|
-
const messageSaveOrigin = (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
53
|
+
const messageSaveOrigin = () => {
|
|
54
|
+
return {
|
|
55
|
+
register: (ctx) => {
|
|
56
|
+
const saveOrigin = new msgSave_1.default(ctx, {
|
|
57
|
+
filePath: `./save`,
|
|
58
|
+
suffix: `.origin`,
|
|
59
|
+
});
|
|
60
|
+
// 打开直播间时,设置保存信息
|
|
61
|
+
ctx.on("room_open", (roomKey, roomInfo) => {
|
|
62
|
+
const { platform, id, status } = roomInfo;
|
|
63
|
+
saveOrigin.setSaveInfo({
|
|
64
|
+
platform,
|
|
65
|
+
room: id,
|
|
66
|
+
status,
|
|
67
|
+
timestamp: Date.now(),
|
|
68
|
+
statusChanged: false
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
// 关闭直播间时,移除保存信息
|
|
72
|
+
ctx.on("room_close", (roomKey, roomInfo) => {
|
|
73
|
+
saveOrigin.removeSaveInfo(roomKey);
|
|
74
|
+
});
|
|
75
|
+
ctx.on("live_origin", (msg, { platform, room }) => {
|
|
76
|
+
saveOrigin.write(msg, { platform, room });
|
|
77
|
+
});
|
|
78
|
+
ctx.on("start", () => {
|
|
79
|
+
saveOrigin.start();
|
|
80
|
+
});
|
|
81
|
+
ctx.on("end", () => { saveOrigin.pause(); });
|
|
82
|
+
return saveOrigin;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
30
85
|
};
|
|
31
86
|
exports.messageSaveOrigin = messageSaveOrigin;
|
|
@@ -1,22 +1,83 @@
|
|
|
1
|
+
import { RoomStatus } from './../../src/enum';
|
|
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;
|