floating-live 0.12.1 → 0.14.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 +2 -2
- package/index.js +2 -2
- package/package.json +4 -2
- package/plugin/acfun/acfunLive.d.ts +3 -3
- package/plugin/acfun/acfunLive.js +6 -6
- 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} +117 -230
- 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 +3 -3
- 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/{lib → abstract}/Reglist.d.ts +2 -0
- package/src/{lib → abstract}/Reglist.js +4 -0
- package/src/index.d.ts +17 -46
- package/src/index.js +24 -81
- package/src/module/ModAuth.d.ts +8 -0
- package/src/module/ModAuth.js +28 -0
- package/src/module/ModCommand.d.ts +9 -0
- package/src/module/ModCommand.js +19 -0
- package/src/module/ModMessage.d.ts +9 -0
- package/src/module/ModMessage.js +16 -0
- package/src/module/{Plugin.d.ts → ModPlugin.d.ts} +5 -11
- package/src/module/ModPlugin.js +63 -0
- package/src/module/ModRooms.d.ts +37 -0
- package/src/module/ModRooms.js +159 -0
- package/src/module/ModState.d.ts +6 -0
- package/src/module/ModState.js +17 -0
- 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 -2
- 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/Plugin.js +0 -82
- package/src/module/Room.d.ts +0 -26
- package/src/module/Room.js +0 -118
- package/src/types/message/AttributeInfo.d.ts +0 -67
- package/src/types/message/MessageData.d.ts +0 -167
- /package/{src/types/message/AttributeInfo.js → plugin/bilibili/types.js} +0 -0
- /package/src/types/{message/MessageData.js → message.js} +0 -0
|
@@ -1,157 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
exports.parseInfo = exports.parseMessage = void 0;
|
|
4
|
+
const enum_1 = require("../../src/enum");
|
|
5
|
+
const utils_1 = require("../../src/utils");
|
|
6
6
|
// utils
|
|
7
7
|
// 获取当前时间戳,以替代无法从数据中获取时间戳的情况,精度为1s
|
|
8
8
|
function getDateTimestamp() {
|
|
9
9
|
return Math.floor(Date.now() / 1000) * 1000;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
case 1:
|
|
14
|
-
return __1.RoomStatus.live;
|
|
15
|
-
case 2:
|
|
16
|
-
return __1.RoomStatus.round;
|
|
17
|
-
default:
|
|
18
|
-
return __1.RoomStatus.off;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
class bilibiliLive extends __2.LiveRoom {
|
|
22
|
-
constructor(id, // 房间id
|
|
23
|
-
open = false, // 生成房间后是否打开
|
|
24
|
-
config) {
|
|
25
|
-
super();
|
|
26
|
-
/** 平台id */
|
|
27
|
-
this.platform = "bilibili";
|
|
28
|
-
/** 直播间room_id */
|
|
29
|
-
this.roomid = 0;
|
|
30
|
-
/** 房间信息 */
|
|
31
|
-
this.detail = {
|
|
32
|
-
/** 直播标题 */
|
|
33
|
-
title: "",
|
|
34
|
-
/** 分区 */
|
|
35
|
-
area: [],
|
|
36
|
-
/** 封面url */
|
|
37
|
-
cover: "",
|
|
38
|
-
};
|
|
39
|
-
this.stats = {
|
|
40
|
-
/** 观看数 */
|
|
41
|
-
watch: 0,
|
|
42
|
-
/** 点赞数 */
|
|
43
|
-
like: 0,
|
|
44
|
-
};
|
|
45
|
-
/** 房间是否可用 */
|
|
46
|
-
this.available = false;
|
|
47
|
-
/** 是否连接上房间 */
|
|
48
|
-
this.connected = false;
|
|
49
|
-
/** 主播信息 */
|
|
50
|
-
this.anchor = { name: "", id: 0 };
|
|
51
|
-
/** 直播间弹幕api模块 */
|
|
52
|
-
this.client = null;
|
|
53
|
-
this.id = id; // 直播间号
|
|
54
|
-
this.connectInterval = config?.connectInterval || 100;
|
|
55
|
-
if (open) {
|
|
56
|
-
this.open();
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
this.getInfo();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/** 获取房间信息 */
|
|
63
|
-
async getInfo() {
|
|
64
|
-
await fetch(`https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=${this.id}`, {
|
|
65
|
-
method: "GET",
|
|
66
|
-
}) // 获取直播间信息
|
|
67
|
-
.then((response) => response.json())
|
|
68
|
-
.then((res) => {
|
|
69
|
-
const { room_info, anchor_info, like_info_v3, watched_show } = res.data;
|
|
70
|
-
this.roomid = room_info.room_id;
|
|
71
|
-
this.status = room_info.lock_status
|
|
72
|
-
? __1.RoomStatus.banned
|
|
73
|
-
: getRoomStatus(room_info.live_status);
|
|
74
|
-
this.timestamp =
|
|
75
|
-
this.status == __1.RoomStatus.live
|
|
76
|
-
? room_info.live_start_time * 1000
|
|
77
|
-
: this.timestamp;
|
|
78
|
-
this.detail.title = room_info.title;
|
|
79
|
-
this.detail.area = [room_info.parent_area_name, room_info.area_name];
|
|
80
|
-
this.detail.cover = room_info.cover;
|
|
81
|
-
this.stats.watch = watched_show.num;
|
|
82
|
-
this.stats.like = like_info_v3.total_likes;
|
|
83
|
-
this.anchor.id = room_info.uid;
|
|
84
|
-
this.anchor.name = anchor_info.base_info.uname;
|
|
85
|
-
this.anchor.avatar = anchor_info.base_info.face;
|
|
86
|
-
this.liveId = room_info.live_id_str;
|
|
87
|
-
this.available = true;
|
|
88
|
-
console.log("[bilibiliLive] 已获取房间信息");
|
|
89
|
-
this.emit("info", this.info);
|
|
90
|
-
})
|
|
91
|
-
.catch((error) => {
|
|
92
|
-
console.error(error);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
/** 开启直播间监听 */
|
|
96
|
-
async open() {
|
|
97
|
-
// 如果直播间监听已打开,则返回
|
|
98
|
-
if (this.opening)
|
|
99
|
-
return;
|
|
100
|
-
await this.getInfo();
|
|
101
|
-
// 如果直播间不可用,则返回
|
|
102
|
-
if (!this.available)
|
|
103
|
-
return;
|
|
104
|
-
this.opening = true;
|
|
105
|
-
this.createWS();
|
|
106
|
-
this.emit("open");
|
|
107
|
-
}
|
|
108
|
-
/** 连接直播服务端 */
|
|
109
|
-
async createWS() {
|
|
110
|
-
// 与Websocket服务器连接
|
|
111
|
-
console.log("[bilibili-live-ws] 开始连接bilibili直播服务器");
|
|
112
|
-
this.client = new bilibili_live_ws_1.KeepLiveWS(this.roomid, { uid: this.anchor.id });
|
|
113
|
-
let client = this.client;
|
|
114
|
-
client.interval = this.connectInterval;
|
|
115
|
-
client.on("open", () => {
|
|
116
|
-
console.log("[bilibili-live-ws] 已连接bilibili直播服务器");
|
|
117
|
-
this.emit("connect");
|
|
118
|
-
});
|
|
119
|
-
client.on("close", () => {
|
|
120
|
-
console.log("[bilibili-live-ws] 与bilibili直播服务器的连接已关闭");
|
|
121
|
-
this.emit("disconnect");
|
|
122
|
-
});
|
|
123
|
-
client.on("live", () => {
|
|
124
|
-
console.log("[bilibili-live-ws] 目标房间连接成功");
|
|
125
|
-
});
|
|
126
|
-
client.on("msg", (data) => {
|
|
127
|
-
this.emitOrigin(data);
|
|
128
|
-
});
|
|
129
|
-
client.on("DANMU_MSG", this.msg_DANMU_MSG.bind(this));
|
|
130
|
-
//client.on("ENTRY_EFFECT", this.msg_ENTRY_EFFECT.bind(this));
|
|
131
|
-
client.on("INTERACT_WORD", this.msg_INTERACT_WORD.bind(this));
|
|
132
|
-
client.on("SEND_GIFT", this.msg_SEND_GIFT.bind(this));
|
|
133
|
-
client.on("GUARD_BUY", this.msg_GUARD_BUY.bind(this));
|
|
134
|
-
//client.on('COMBO_SEND', this.msg_COMBO_SEND.bind(this))
|
|
135
|
-
client.on("ROOM_BLOCK_MSG", this.msg_ROOM_BLOCK_MSG.bind(this));
|
|
136
|
-
client.on("SUPER_CHAT_MESSAGE", this.msg_SUPER_CHAT_MESSAGE.bind(this));
|
|
137
|
-
client.on("CUT_OFF", this.msg_CUT_OFF.bind(this));
|
|
138
|
-
client.on("PREPARING", this.msg_PREPARING.bind(this));
|
|
139
|
-
client.on("LIVE", this.msg_LIVE.bind(this));
|
|
140
|
-
client.on("ROOM_CHANGE", this.msg_ROOM_CHANGE.bind(this));
|
|
141
|
-
client.on("WATCHED_CHANGE", this.msg_WATCHED_CHANGE.bind(this));
|
|
142
|
-
client.on("LIKE_INFO_V3_UPDATE", this.msg_LIKE_INFO_V3_UPDATE.bind(this));
|
|
143
|
-
client.on("ONLINE_RANK_COUNT", this.msg_ONLINE_RANK_COUNT.bind(this));
|
|
144
|
-
}
|
|
145
|
-
/** 关闭直播间监听 */
|
|
146
|
-
close() {
|
|
147
|
-
if (!this.opening)
|
|
148
|
-
return;
|
|
149
|
-
this.opening = false;
|
|
150
|
-
this.client?.close();
|
|
151
|
-
this.emit("close");
|
|
152
|
-
}
|
|
153
|
-
/** 获取弹幕消息 */
|
|
154
|
-
msg_DANMU_MSG(msg) {
|
|
11
|
+
const parseFunction = {
|
|
12
|
+
DANMU_MSG: (msg, room) => {
|
|
155
13
|
const { info, msg_id } = msg;
|
|
156
14
|
let content = info[1];
|
|
157
15
|
let mode = info[0][1];
|
|
@@ -161,7 +19,7 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
161
19
|
let timestamp = info[0][4];
|
|
162
20
|
let guard_level = info[7]; // 舰长级别
|
|
163
21
|
let extra = JSON.parse(info[0][15].extra);
|
|
164
|
-
let medal = info[3]
|
|
22
|
+
let medal = info[3][0] != null
|
|
165
23
|
? {
|
|
166
24
|
level: info[3][0],
|
|
167
25
|
name: info[3][1],
|
|
@@ -184,14 +42,14 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
184
42
|
}
|
|
185
43
|
}
|
|
186
44
|
if (info[2][2]) {
|
|
187
|
-
identity =
|
|
45
|
+
identity = enum_1.UserType.admin;
|
|
188
46
|
}
|
|
189
|
-
else if (uid
|
|
190
|
-
identity =
|
|
47
|
+
else if (uid === room?.anchor.id) {
|
|
48
|
+
identity = enum_1.UserType.anchor;
|
|
191
49
|
}
|
|
192
50
|
let danmaku = {
|
|
193
51
|
platform: "bilibili",
|
|
194
|
-
room:
|
|
52
|
+
room: room?.id || 0,
|
|
195
53
|
type: "chat",
|
|
196
54
|
timestamp: timestamp,
|
|
197
55
|
id: msg_id,
|
|
@@ -205,8 +63,8 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
205
63
|
id: info[0][13].emoticon_unique,
|
|
206
64
|
url: info[0][13].url,
|
|
207
65
|
size: info[0][13].width == info[0][13].height
|
|
208
|
-
?
|
|
209
|
-
:
|
|
66
|
+
? enum_1.ImageSize.large
|
|
67
|
+
: enum_1.ImageSize.small,
|
|
210
68
|
}
|
|
211
69
|
: undefined,
|
|
212
70
|
emoticon: emoticon,
|
|
@@ -219,11 +77,10 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
219
77
|
},
|
|
220
78
|
},
|
|
221
79
|
};
|
|
222
|
-
danmaku.id ?? (danmaku.id = (0,
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
msg_INTERACT_WORD(msg) {
|
|
80
|
+
danmaku.id ?? (danmaku.id = (0, utils_1.generateId)(danmaku));
|
|
81
|
+
return danmaku;
|
|
82
|
+
},
|
|
83
|
+
INTERACT_WORD: (msg, room) => {
|
|
227
84
|
const { data, msg_id, send_time } = msg;
|
|
228
85
|
let type;
|
|
229
86
|
switch (data.msg_type) {
|
|
@@ -241,7 +98,7 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
241
98
|
}
|
|
242
99
|
let interact = {
|
|
243
100
|
platform: "bilibili",
|
|
244
|
-
room:
|
|
101
|
+
room: room?.id || 0,
|
|
245
102
|
type: type,
|
|
246
103
|
id: msg_id,
|
|
247
104
|
timestamp: send_time || Math.floor(data.trigger_time / 1000000),
|
|
@@ -260,15 +117,14 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
260
117
|
},
|
|
261
118
|
},
|
|
262
119
|
};
|
|
263
|
-
interact.id ?? (interact.id = (0,
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
msg_SEND_GIFT(msg) {
|
|
120
|
+
interact.id ?? (interact.id = (0, utils_1.generateId)(interact));
|
|
121
|
+
return interact;
|
|
122
|
+
},
|
|
123
|
+
SEND_GIFT: (msg, room) => {
|
|
268
124
|
const { data, msg_id, send_time } = msg;
|
|
269
125
|
let gift = {
|
|
270
126
|
platform: "bilibili",
|
|
271
|
-
room:
|
|
127
|
+
room: room?.id || 0,
|
|
272
128
|
type: "gift",
|
|
273
129
|
id: msg_id || data.combo_id,
|
|
274
130
|
timestamp: send_time || data.timestamp * 1000,
|
|
@@ -298,15 +154,14 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
298
154
|
},
|
|
299
155
|
},
|
|
300
156
|
};
|
|
301
|
-
gift.id ?? (gift.id = (0,
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
msg_GUARD_BUY(msg) {
|
|
157
|
+
gift.id ?? (gift.id = (0, utils_1.generateId)(gift));
|
|
158
|
+
return gift;
|
|
159
|
+
},
|
|
160
|
+
GUARD_BUY: (msg, room) => {
|
|
306
161
|
const { data, msg_id, send_time } = msg;
|
|
307
162
|
let gift = {
|
|
308
163
|
platform: "bilibili",
|
|
309
|
-
room:
|
|
164
|
+
room: room?.id || 0,
|
|
310
165
|
type: "membership",
|
|
311
166
|
id: msg_id,
|
|
312
167
|
timestamp: send_time || data.start_time * 1000,
|
|
@@ -328,15 +183,14 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
328
183
|
duration: data.num * 30,
|
|
329
184
|
},
|
|
330
185
|
};
|
|
331
|
-
gift.id ?? (gift.id = (0,
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
msg_SUPER_CHAT_MESSAGE(msg) {
|
|
186
|
+
gift.id ?? (gift.id = (0, utils_1.generateId)(gift));
|
|
187
|
+
return gift;
|
|
188
|
+
},
|
|
189
|
+
SUPER_CHAT_MESSAGE: (msg, room) => {
|
|
336
190
|
const { data, msg_id, send_time } = msg;
|
|
337
191
|
let sc = {
|
|
338
192
|
platform: "bilibili",
|
|
339
|
-
room:
|
|
193
|
+
room: room?.id || 0,
|
|
340
194
|
type: "superchat",
|
|
341
195
|
id: msg_id,
|
|
342
196
|
timestamp: send_time || data.ts * 1000,
|
|
@@ -368,31 +222,29 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
368
222
|
},
|
|
369
223
|
},
|
|
370
224
|
};
|
|
371
|
-
sc.id ?? (sc.id = (0,
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
msg_WATCHED_CHANGE(msg) {
|
|
225
|
+
sc.id ?? (sc.id = (0, utils_1.generateId)(sc));
|
|
226
|
+
return sc;
|
|
227
|
+
},
|
|
228
|
+
WATCHED_CHANGE: (msg, room) => {
|
|
376
229
|
const { data, msg_id, send_time } = msg;
|
|
377
230
|
const stats = {
|
|
378
231
|
platform: "bilibili",
|
|
379
|
-
room:
|
|
232
|
+
room: room?.id || 0,
|
|
380
233
|
type: "live_stats",
|
|
381
234
|
id: msg_id,
|
|
382
235
|
timestamp: send_time || getDateTimestamp(),
|
|
383
236
|
info: {
|
|
384
|
-
|
|
237
|
+
view: data.num,
|
|
385
238
|
},
|
|
386
239
|
};
|
|
387
|
-
stats.id ?? (stats.id = (0,
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
msg_LIKE_INFO_V3_UPDATE(msg) {
|
|
240
|
+
stats.id ?? (stats.id = (0, utils_1.generateId)(stats));
|
|
241
|
+
return stats;
|
|
242
|
+
},
|
|
243
|
+
LIKE_INFO_V3_UPDATE: (msg, room) => {
|
|
392
244
|
const { data, msg_id, send_time } = msg;
|
|
393
245
|
const stats = {
|
|
394
246
|
platform: "bilibili",
|
|
395
|
-
room:
|
|
247
|
+
room: room?.id || 0,
|
|
396
248
|
type: "live_stats",
|
|
397
249
|
id: msg_id,
|
|
398
250
|
timestamp: send_time || getDateTimestamp(),
|
|
@@ -400,14 +252,16 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
400
252
|
like: data.click_count,
|
|
401
253
|
},
|
|
402
254
|
};
|
|
403
|
-
stats.id ?? (stats.id = (0,
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
|
|
255
|
+
stats.id ?? (stats.id = (0, utils_1.generateId)(stats));
|
|
256
|
+
return stats;
|
|
257
|
+
},
|
|
258
|
+
ONLINE_RANK_COUNT: (msg, room) => {
|
|
407
259
|
const { data, msg_id, send_time } = msg;
|
|
260
|
+
if (data.online_count == null)
|
|
261
|
+
return;
|
|
408
262
|
const stats = {
|
|
409
263
|
platform: "bilibili",
|
|
410
|
-
room:
|
|
264
|
+
room: room?.id || 0,
|
|
411
265
|
type: "live_stats",
|
|
412
266
|
id: msg_id,
|
|
413
267
|
timestamp: send_time || getDateTimestamp(),
|
|
@@ -415,16 +269,14 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
415
269
|
online: data.online_count,
|
|
416
270
|
},
|
|
417
271
|
};
|
|
418
|
-
stats.id ?? (stats.id = (0,
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
msg_ROOM_BLOCK_MSG(msg) {
|
|
423
|
-
// 禁言
|
|
272
|
+
stats.id ?? (stats.id = (0, utils_1.generateId)(stats));
|
|
273
|
+
return stats;
|
|
274
|
+
},
|
|
275
|
+
ROOM_BLOCK_MSG: (msg, room) => {
|
|
424
276
|
const { data, msg_id, send_time } = msg;
|
|
425
277
|
const block = {
|
|
426
278
|
platform: "bilibili",
|
|
427
|
-
room:
|
|
279
|
+
room: room?.id || 0,
|
|
428
280
|
type: "block",
|
|
429
281
|
id: msg_id,
|
|
430
282
|
timestamp: send_time || getDateTimestamp(),
|
|
@@ -434,20 +286,20 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
434
286
|
name: data.uname,
|
|
435
287
|
},
|
|
436
288
|
operator: {
|
|
437
|
-
type: data.operator == 2 ?
|
|
289
|
+
type: data.operator == 2 ? enum_1.UserType.anchor : enum_1.UserType.admin,
|
|
438
290
|
},
|
|
439
291
|
},
|
|
440
292
|
};
|
|
441
|
-
block.id ?? (block.id = (0,
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
const {
|
|
293
|
+
block.id ?? (block.id = (0, utils_1.generateId)(block));
|
|
294
|
+
return block;
|
|
295
|
+
},
|
|
296
|
+
LIVE: (msg, room) => {
|
|
297
|
+
const { msg_id, send_time } = msg;
|
|
446
298
|
// 直播间开播
|
|
447
299
|
if (msg.live_time) {
|
|
448
300
|
let live = {
|
|
449
301
|
platform: "bilibili",
|
|
450
|
-
room:
|
|
302
|
+
room: room?.id || 0,
|
|
451
303
|
type: "live_start",
|
|
452
304
|
id: msg_id,
|
|
453
305
|
timestamp: send_time || msg.live_time * 1000,
|
|
@@ -455,16 +307,16 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
455
307
|
id: msg.live_key.toString(),
|
|
456
308
|
},
|
|
457
309
|
};
|
|
458
|
-
live.id ?? (live.id = (0,
|
|
459
|
-
|
|
310
|
+
live.id ?? (live.id = (0, utils_1.generateId)(live));
|
|
311
|
+
return live;
|
|
460
312
|
}
|
|
461
|
-
}
|
|
462
|
-
|
|
313
|
+
},
|
|
314
|
+
CUT_OFF: (msg, room) => {
|
|
463
315
|
const { msg_id, send_time } = msg;
|
|
464
316
|
// 直播间被切断
|
|
465
317
|
let cut = {
|
|
466
318
|
platform: "bilibili",
|
|
467
|
-
room:
|
|
319
|
+
room: room?.id || 0,
|
|
468
320
|
type: "live_cut",
|
|
469
321
|
id: msg_id,
|
|
470
322
|
timestamp: send_time || getDateTimestamp(),
|
|
@@ -472,29 +324,29 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
472
324
|
message: msg.msg,
|
|
473
325
|
},
|
|
474
326
|
};
|
|
475
|
-
cut.id ?? (cut.id = (0,
|
|
476
|
-
|
|
477
|
-
}
|
|
478
|
-
|
|
327
|
+
cut.id ?? (cut.id = (0, utils_1.generateId)(cut));
|
|
328
|
+
return cut;
|
|
329
|
+
},
|
|
330
|
+
PREPARING: (msg, room) => {
|
|
479
331
|
const { msg_id, send_time } = msg;
|
|
480
332
|
let off = {
|
|
481
333
|
platform: "bilibili",
|
|
482
|
-
room:
|
|
334
|
+
room: room?.id || 0,
|
|
483
335
|
type: "live_end",
|
|
484
336
|
id: msg_id,
|
|
485
337
|
timestamp: send_time || getDateTimestamp(),
|
|
486
338
|
info: {
|
|
487
|
-
status: msg.round ?
|
|
339
|
+
status: msg.round ? enum_1.RoomStatus.round : enum_1.RoomStatus.off,
|
|
488
340
|
},
|
|
489
341
|
};
|
|
490
|
-
off.id ?? (off.id = (0,
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
|
|
342
|
+
off.id ?? (off.id = (0, utils_1.generateId)(off));
|
|
343
|
+
return off;
|
|
344
|
+
},
|
|
345
|
+
ROOM_CHANGE: (msg, room) => {
|
|
494
346
|
const { data, msg_id, send_time } = msg;
|
|
495
347
|
let change = {
|
|
496
348
|
platform: "bilibili",
|
|
497
|
-
room:
|
|
349
|
+
room: room?.id || 0,
|
|
498
350
|
type: "live_detail",
|
|
499
351
|
id: msg_id,
|
|
500
352
|
timestamp: send_time || getDateTimestamp(),
|
|
@@ -503,8 +355,43 @@ class bilibiliLive extends __2.LiveRoom {
|
|
|
503
355
|
area: [data.parent_area_name, data.area_name],
|
|
504
356
|
},
|
|
505
357
|
};
|
|
506
|
-
change.id ?? (change.id = (0,
|
|
507
|
-
|
|
508
|
-
}
|
|
358
|
+
change.id ?? (change.id = (0, utils_1.generateId)(change));
|
|
359
|
+
return change;
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
/** 转换bilibili直播弹幕为floating通用格式 */
|
|
363
|
+
function parseMessage(data, room) {
|
|
364
|
+
return parseFunction[data.cmd](data, room);
|
|
365
|
+
}
|
|
366
|
+
exports.parseMessage = parseMessage;
|
|
367
|
+
function parseInfo(data) {
|
|
368
|
+
const { room_info, anchor_info, like_info_v3, watched_show } = data;
|
|
369
|
+
return {
|
|
370
|
+
platform: "bilibili",
|
|
371
|
+
id: room_info.room_id,
|
|
372
|
+
key: `bilibili:${room_info.room_id}`,
|
|
373
|
+
detail: {
|
|
374
|
+
title: room_info.title,
|
|
375
|
+
area: [room_info.parent_area_name, room_info.area_name],
|
|
376
|
+
cover: room_info.cover,
|
|
377
|
+
},
|
|
378
|
+
anchor: {
|
|
379
|
+
id: room_info.uid,
|
|
380
|
+
name: anchor_info.base_info.uname,
|
|
381
|
+
avatar: anchor_info.base_info.face,
|
|
382
|
+
},
|
|
383
|
+
stats: {
|
|
384
|
+
view: watched_show.num,
|
|
385
|
+
like: like_info_v3.total_likes,
|
|
386
|
+
},
|
|
387
|
+
liveId: room_info.live_id_str,
|
|
388
|
+
available: true,
|
|
389
|
+
status: room_info.lock_status ? enum_1.RoomStatus.banned : room_info.live_status,
|
|
390
|
+
timestamp: room_info.live_status == enum_1.RoomStatus.live
|
|
391
|
+
? room_info.live_start_time * 1000
|
|
392
|
+
: 0,
|
|
393
|
+
opened: false,
|
|
394
|
+
connected: false,
|
|
395
|
+
};
|
|
509
396
|
}
|
|
510
|
-
exports.
|
|
397
|
+
exports.parseInfo = parseInfo;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { UserInfo } from "../..";
|
|
2
|
+
import { KeepLiveWS } from "bilibili-live-ws";
|
|
3
|
+
import { RoomStatsInfo, RoomDetail } from "../..";
|
|
4
|
+
import { RawMessage } from "./types";
|
|
5
|
+
import { LiveRoom } from "../../src/abstract/LiveRoom";
|
|
6
|
+
declare class RoomBilibili extends LiveRoom {
|
|
7
|
+
#private;
|
|
8
|
+
/** 平台id */
|
|
9
|
+
readonly platform: string;
|
|
10
|
+
/** 直播间号 */
|
|
11
|
+
readonly id: number;
|
|
12
|
+
/** 直播间room_id */
|
|
13
|
+
roomid: number;
|
|
14
|
+
/** 房间信息 */
|
|
15
|
+
detail: RoomDetail;
|
|
16
|
+
stats: RoomStatsInfo;
|
|
17
|
+
/** 房间是否可用 */
|
|
18
|
+
available: boolean;
|
|
19
|
+
/** 是否连接上房间 */
|
|
20
|
+
connected: boolean;
|
|
21
|
+
/** 主播信息 */
|
|
22
|
+
anchor: UserInfo;
|
|
23
|
+
/** 直播间弹幕api模块 */
|
|
24
|
+
client: KeepLiveWS | null;
|
|
25
|
+
/** 断线重连间隔 */
|
|
26
|
+
connectInterval: number;
|
|
27
|
+
private userId;
|
|
28
|
+
private buvid;
|
|
29
|
+
private token;
|
|
30
|
+
/** 是否处于正在打开的状态 */
|
|
31
|
+
private opening;
|
|
32
|
+
constructor(
|
|
33
|
+
/** 房间id */
|
|
34
|
+
id: number,
|
|
35
|
+
/** 生成房间后是否打开 */
|
|
36
|
+
open?: boolean,
|
|
37
|
+
/** 配置项 */
|
|
38
|
+
config?: {
|
|
39
|
+
/** 登录凭据 */
|
|
40
|
+
auth?: string;
|
|
41
|
+
/** 断线重连间隔(默认值为100ms) */
|
|
42
|
+
connectInterval?: number;
|
|
43
|
+
});
|
|
44
|
+
/** 获取房间信息 */
|
|
45
|
+
getInfo(): Promise<void>;
|
|
46
|
+
/** 开启直播间监听 */
|
|
47
|
+
open(): Promise<void>;
|
|
48
|
+
/** 设置登录凭据 */
|
|
49
|
+
setAuth(auth: string): void;
|
|
50
|
+
/** 初始化登录凭据 */
|
|
51
|
+
private initAuth;
|
|
52
|
+
/** 连接直播服务端 */
|
|
53
|
+
createWS(): void;
|
|
54
|
+
/** 关闭直播间监听 */
|
|
55
|
+
close(): void;
|
|
56
|
+
/** 获取弹幕消息 */
|
|
57
|
+
msg_DANMU_MSG(msg: RawMessage.DANMU_MSG): void;
|
|
58
|
+
/** 获取互动消息 */
|
|
59
|
+
msg_INTERACT_WORD(msg: RawMessage.INTERACT_WORD): void;
|
|
60
|
+
/** 获取礼物消息 */
|
|
61
|
+
msg_SEND_GIFT(msg: RawMessage.SEND_GIFT): void;
|
|
62
|
+
/** 获取舰长开通消息 */
|
|
63
|
+
msg_GUARD_BUY(msg: RawMessage.GUARD_BUY): void;
|
|
64
|
+
/** 获取醒目留言消息 */
|
|
65
|
+
msg_SUPER_CHAT_MESSAGE(msg: RawMessage.SUPER_CHAT_MESSAGE): void;
|
|
66
|
+
/** 观看数变化 */
|
|
67
|
+
msg_WATCHED_CHANGE(msg: RawMessage.WATCHED_CHANGE): void;
|
|
68
|
+
/** 点赞数变化 */
|
|
69
|
+
msg_LIKE_INFO_V3_UPDATE(msg: RawMessage.LIKE_INFO_V3_UPDATE): void;
|
|
70
|
+
msg_ONLINE_RANK_COUNT(msg: RawMessage.ONLINE_RANK_COUNT): void;
|
|
71
|
+
msg_ROOM_BLOCK_MSG(msg: RawMessage.ROOM_BLOCK_MSG): void;
|
|
72
|
+
msg_LIVE(msg: RawMessage.LIVE): void;
|
|
73
|
+
msg_CUT_OFF(msg: RawMessage.CUT_OFF): void;
|
|
74
|
+
msg_PREPARING(msg: RawMessage.PREPARING): void;
|
|
75
|
+
msg_ROOM_CHANGE(msg: RawMessage.ROOM_CHANGE): void;
|
|
76
|
+
}
|
|
77
|
+
export default RoomBilibili;
|