floating-live 0.14.11 → 0.15.0-beta.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.
Files changed (64) hide show
  1. package/LICENSE +5 -670
  2. package/{src/abstract → dist/core}/LiveRoom.d.ts +1 -1
  3. package/{src/abstract → dist/core}/LiveRoom.js +6 -6
  4. package/{src/abstract → dist/core}/Reglist.d.ts +1 -1
  5. package/dist/core/index.d.ts +2 -0
  6. package/dist/core/index.js +18 -0
  7. package/dist/index.d.ts +6 -0
  8. package/{index.js → dist/index.js} +7 -7
  9. package/{src → dist}/module/ModAuth.d.ts +2 -2
  10. package/{src → dist}/module/ModAuth.js +1 -1
  11. package/{src → dist}/module/ModCommand.d.ts +2 -2
  12. package/{src → dist}/module/ModCommand.js +1 -1
  13. package/{src → dist}/module/ModMessage.d.ts +2 -2
  14. package/{src → dist}/module/ModMessage.js +1 -1
  15. package/{src → dist}/module/ModPlugin.d.ts +1 -1
  16. package/{src → dist}/module/ModRoom.d.ts +3 -3
  17. package/{src → dist}/module/ModRoom.js +1 -1
  18. package/{src → dist}/module/ModState.d.ts +2 -2
  19. package/{src → dist}/module/ModState.js +1 -1
  20. package/{src → dist}/types/message.d.ts +2 -2
  21. package/{src → dist}/types/plugin.d.ts +1 -1
  22. package/{src → dist}/types/room.d.ts +1 -1
  23. package/package.json +26 -5
  24. package/index.d.ts +0 -6
  25. package/plugin/acfun/acfunLive.d.ts +0 -74
  26. package/plugin/acfun/acfunLive.js +0 -279
  27. package/plugin/acfun/index.d.ts +0 -3
  28. package/plugin/acfun/index.js +0 -16
  29. package/plugin/bilibili/index.d.ts +0 -6
  30. package/plugin/bilibili/index.js +0 -45
  31. package/plugin/bilibili/parser.d.ts +0 -6
  32. package/plugin/bilibili/parser.js +0 -397
  33. package/plugin/bilibili/room.d.ts +0 -77
  34. package/plugin/bilibili/room.js +0 -261
  35. package/plugin/bilibili/types.d.ts +0 -424
  36. package/plugin/bilibili/types.js +0 -2
  37. package/plugin/bilibili/utils.d.ts +0 -17
  38. package/plugin/bilibili/utils.js +0 -137
  39. package/plugin/chatPrint/chatPrint.d.ts +0 -20
  40. package/plugin/chatPrint/chatPrint.js +0 -116
  41. package/plugin/chatPrint/index.d.ts +0 -7
  42. package/plugin/chatPrint/index.js +0 -10
  43. package/plugin/consoleEvent/index.d.ts +0 -6
  44. package/plugin/consoleEvent/index.js +0 -51
  45. package/plugin/msgSave/index.d.ts +0 -10
  46. package/plugin/msgSave/index.js +0 -81
  47. package/plugin/msgSave/msgSave.d.ts +0 -83
  48. package/plugin/msgSave/msgSave.js +0 -168
  49. package/test/type/bilibili_getInfoByRoom.d.ts +0 -492
  50. /package/{src/abstract → dist/core}/Reglist.js +0 -0
  51. /package/{src/enum.d.ts → dist/enums.d.ts} +0 -0
  52. /package/{src/enum.js → dist/enums.js} +0 -0
  53. /package/{src/index.d.ts → dist/live.d.ts} +0 -0
  54. /package/{src/index.js → dist/live.js} +0 -0
  55. /package/{src → dist}/module/ModPlugin.js +0 -0
  56. /package/{src → dist}/types/auth.d.ts +0 -0
  57. /package/{src → dist}/types/auth.js +0 -0
  58. /package/{src → dist}/types/index.d.ts +0 -0
  59. /package/{src → dist}/types/index.js +0 -0
  60. /package/{src → dist}/types/message.js +0 -0
  61. /package/{src → dist}/types/plugin.js +0 -0
  62. /package/{src → dist}/types/room.js +0 -0
  63. /package/{src → dist}/utils.d.ts +0 -0
  64. /package/{src → dist}/utils.js +0 -0
@@ -1,6 +0,0 @@
1
- import { FloatingLive } from "../..";
2
- declare const bilibili: () => {
3
- name: string;
4
- register: (ctx: FloatingLive) => void;
5
- };
6
- export = bilibili;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- const room_1 = __importDefault(require("./room"));
6
- const utils_1 = require("./utils");
7
- const bilibili = () => {
8
- return {
9
- name: "bilibili",
10
- register: (ctx) => {
11
- ctx.room.generator.register("bilibili", (id, open, config) => {
12
- return new room_1.default(Number(id), open, config);
13
- });
14
- ctx.auth.options.register("bilibili", authConfig);
15
- ctx.command.register("auth.bilibili", async (auth) => {
16
- const uid = await (0, utils_1.getLoginUid)(auth);
17
- ctx.auth.status["bilibili"] = uid;
18
- ctx.auth.set("bilibili", auth);
19
- ctx.emit("auth:update", "bilibili", uid);
20
- });
21
- ctx.command.register("auth.bilibili.qrcode.get", () => {
22
- return (0, utils_1.generateLoginQRcode)();
23
- });
24
- ctx.command.register("auth.bilibili.qrcode.check", async (key) => {
25
- const [code, auth] = await (0, utils_1.checkLoginQRcode)(key);
26
- if (auth) {
27
- const { SESSDATA, DedeUserID } = (0, utils_1.parseCookieString)(auth);
28
- ctx.auth.status["bilibili"] = DedeUserID;
29
- ctx.auth.set("bilibili", `SESSDATA=${SESSDATA}`);
30
- ctx.emit("auth:update", "bilibili", DedeUserID);
31
- }
32
- return [code, auth];
33
- });
34
- },
35
- };
36
- };
37
- const authConfig = {
38
- auth: {
39
- type: "cookie",
40
- },
41
- qrcode: {
42
- type: "url",
43
- },
44
- };
45
- module.exports = bilibili;
@@ -1,6 +0,0 @@
1
- import { Message } from "../../src/types";
2
- import { RoomInfo } from "./../../src/types/room";
3
- import { RawInfo, RawMessage } from "./types";
4
- /** 转换bilibili直播弹幕为floating通用格式 */
5
- export declare function parseMessage(data: RawMessage.All, room?: RoomInfo): Message.All | undefined;
6
- export declare function parseInfo(data: RawInfo): RoomInfo;
@@ -1,397 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseInfo = exports.parseMessage = void 0;
4
- const enum_1 = require("../../src/enum");
5
- const utils_1 = require("../../src/utils");
6
- // utils
7
- // 获取当前时间戳,以替代无法从数据中获取时间戳的情况,精度为1s
8
- function getDateTimestamp() {
9
- return Math.floor(Date.now() / 1000) * 1000;
10
- }
11
- const parseFunction = {
12
- DANMU_MSG: (msg, room) => {
13
- const { info, msg_id } = msg;
14
- let content = info[1];
15
- let mode = info[0][1];
16
- let color = info[0][3];
17
- let uname = info[2][1];
18
- let uid = info[2][0];
19
- let timestamp = info[0][4];
20
- let guard_level = info[7]; // 舰长级别
21
- let extra = JSON.parse(info[0][15].extra);
22
- let medal = info[3][0] != null
23
- ? {
24
- level: info[3][0],
25
- name: info[3][1],
26
- // user: info[3][2],
27
- id: info[3][12],
28
- membership: info[3][10] || 0,
29
- }
30
- : null;
31
- let identity = 0;
32
- let emoticon = undefined;
33
- if (extra.emots) {
34
- emoticon = {};
35
- for (let key in extra.emots) {
36
- let emotItem = extra.emots[key];
37
- emoticon[key] = {
38
- id: emotItem.emoticon_unique,
39
- url: emotItem.url,
40
- name: emotItem.emoji,
41
- };
42
- }
43
- }
44
- if (info[2][2]) {
45
- identity = enum_1.UserType.admin;
46
- }
47
- else if (uid === room?.anchor.id) {
48
- identity = enum_1.UserType.anchor;
49
- }
50
- let danmaku = {
51
- platform: "bilibili",
52
- room: room?.id || 0,
53
- type: "chat",
54
- timestamp: timestamp,
55
- id: msg_id,
56
- info: {
57
- color: color,
58
- mode: mode,
59
- content: content,
60
- image: info[0][12]
61
- ? {
62
- name: content,
63
- id: info[0][13].emoticon_unique,
64
- url: info[0][13].url,
65
- size: info[0][13].width == info[0][13].height
66
- ? enum_1.ImageSize.large
67
- : enum_1.ImageSize.small,
68
- }
69
- : undefined,
70
- emoticon: emoticon,
71
- user: {
72
- name: uname,
73
- id: uid,
74
- medal: medal,
75
- membership: guard_level,
76
- type: identity,
77
- },
78
- },
79
- };
80
- danmaku.id ?? (danmaku.id = (0, utils_1.generateId)(danmaku));
81
- return danmaku;
82
- },
83
- INTERACT_WORD: (msg, room) => {
84
- const { data, msg_id, send_time } = msg;
85
- let type;
86
- switch (data.msg_type) {
87
- case 1:
88
- type = "entry"; // 进入直播间
89
- break;
90
- case 2:
91
- type = "follow"; // 关注直播间
92
- break;
93
- case 3:
94
- type = "share"; // 分享直播间
95
- break;
96
- default:
97
- return;
98
- }
99
- let interact = {
100
- platform: "bilibili",
101
- room: room?.id || 0,
102
- type: type,
103
- id: msg_id,
104
- timestamp: send_time || Math.floor(data.trigger_time / 1000000),
105
- info: {
106
- user: {
107
- name: data.uname,
108
- id: data.uid,
109
- medal: data.fans_medal?.medal_level
110
- ? {
111
- level: data.fans_medal.medal_level,
112
- name: data.fans_medal.medal_name,
113
- id: data.fans_medal.target_id,
114
- membership: data.fans_medal.guard_level,
115
- }
116
- : null,
117
- },
118
- },
119
- };
120
- interact.id ?? (interact.id = (0, utils_1.generateId)(interact));
121
- return interact;
122
- },
123
- SEND_GIFT: (msg, room) => {
124
- const { data, msg_id, send_time } = msg;
125
- let gift = {
126
- platform: "bilibili",
127
- room: room?.id || 0,
128
- type: "gift",
129
- id: msg_id || data.combo_id,
130
- timestamp: send_time || data.timestamp * 1000,
131
- info: {
132
- user: {
133
- name: data.uname,
134
- id: data.uid,
135
- medal: data.fans_medal && data.fans_medal.medal_level
136
- ? {
137
- level: data.fans_medal.medal_level,
138
- name: data.fans_medal.medal_name,
139
- id: data.fans_medal.target_id,
140
- membership: data.fans_medal.guard_level,
141
- }
142
- : null,
143
- membership: data.guard_level,
144
- avatar: data.face,
145
- },
146
- gift: {
147
- name: data.giftName,
148
- id: data.giftId,
149
- num: data.num,
150
- value: data.total_coin,
151
- currency: data.coin_type,
152
- action: data.action,
153
- comboId: data.batch_combo_id,
154
- },
155
- },
156
- };
157
- gift.id ?? (gift.id = (0, utils_1.generateId)(gift));
158
- return gift;
159
- },
160
- GUARD_BUY: (msg, room) => {
161
- const { data, msg_id, send_time } = msg;
162
- let gift = {
163
- platform: "bilibili",
164
- room: room?.id || 0,
165
- type: "membership",
166
- id: msg_id,
167
- timestamp: send_time || data.start_time * 1000,
168
- info: {
169
- user: {
170
- name: data.username,
171
- id: data.uid,
172
- membership: data.guard_level,
173
- },
174
- gift: {
175
- name: data.gift_name,
176
- id: data.gift_id,
177
- num: data.num,
178
- value: data.price,
179
- currency: "gold",
180
- },
181
- name: data.gift_name,
182
- level: data.guard_level,
183
- duration: data.num * 30,
184
- },
185
- };
186
- gift.id ?? (gift.id = (0, utils_1.generateId)(gift));
187
- return gift;
188
- },
189
- SUPER_CHAT_MESSAGE: (msg, room) => {
190
- const { data, msg_id, send_time } = msg;
191
- let sc = {
192
- platform: "bilibili",
193
- room: room?.id || 0,
194
- type: "superchat",
195
- id: msg_id,
196
- timestamp: send_time || data.ts * 1000,
197
- info: {
198
- id: data.id,
199
- user: {
200
- name: data.user_info.uname,
201
- id: data.uid,
202
- avatar: data.user_info.face,
203
- medal: data.medal_info && data.medal_info.medal_level
204
- ? {
205
- level: data.medal_info.medal_level,
206
- name: data.medal_info.medal_name,
207
- id: data.medal_info.target_id,
208
- membership: data.medal_info.guard_level,
209
- }
210
- : null,
211
- membership: data.user_info.guard_level,
212
- },
213
- content: data.message,
214
- color: data.background_bottom_color,
215
- duration: data.time * 1000,
216
- gift: {
217
- id: data.gift.gift_id,
218
- name: data.gift.gift_name,
219
- num: data.gift.num,
220
- value: data.price * 1000,
221
- currency: "gold",
222
- },
223
- },
224
- };
225
- sc.id ?? (sc.id = (0, utils_1.generateId)(sc));
226
- return sc;
227
- },
228
- WATCHED_CHANGE: (msg, room) => {
229
- const { data, msg_id, send_time } = msg;
230
- const stats = {
231
- platform: "bilibili",
232
- room: room?.id || 0,
233
- type: "live_stats",
234
- id: msg_id,
235
- timestamp: send_time || getDateTimestamp(),
236
- info: {
237
- view: data.num,
238
- },
239
- };
240
- stats.id ?? (stats.id = (0, utils_1.generateId)(stats));
241
- return stats;
242
- },
243
- LIKE_INFO_V3_UPDATE: (msg, room) => {
244
- const { data, msg_id, send_time } = msg;
245
- const stats = {
246
- platform: "bilibili",
247
- room: room?.id || 0,
248
- type: "live_stats",
249
- id: msg_id,
250
- timestamp: send_time || getDateTimestamp(),
251
- info: {
252
- like: data.click_count,
253
- },
254
- };
255
- stats.id ?? (stats.id = (0, utils_1.generateId)(stats));
256
- return stats;
257
- },
258
- ONLINE_RANK_COUNT: (msg, room) => {
259
- const { data, msg_id, send_time } = msg;
260
- if (data.online_count == null)
261
- return;
262
- const stats = {
263
- platform: "bilibili",
264
- room: room?.id || 0,
265
- type: "live_stats",
266
- id: msg_id,
267
- timestamp: send_time || getDateTimestamp(),
268
- info: {
269
- online: data.online_count,
270
- },
271
- };
272
- stats.id ?? (stats.id = (0, utils_1.generateId)(stats));
273
- return stats;
274
- },
275
- ROOM_BLOCK_MSG: (msg, room) => {
276
- const { data, msg_id, send_time } = msg;
277
- const block = {
278
- platform: "bilibili",
279
- room: room?.id || 0,
280
- type: "block",
281
- id: msg_id,
282
- timestamp: send_time || getDateTimestamp(),
283
- info: {
284
- user: {
285
- id: data.uid,
286
- name: data.uname,
287
- },
288
- operator: {
289
- type: data.operator == 2 ? enum_1.UserType.anchor : enum_1.UserType.admin,
290
- },
291
- },
292
- };
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;
298
- // 直播间开播
299
- if (msg.live_time) {
300
- let live = {
301
- platform: "bilibili",
302
- room: room?.id || 0,
303
- type: "live_start",
304
- id: msg_id,
305
- timestamp: send_time || msg.live_time * 1000,
306
- info: {
307
- id: msg.live_key.toString(),
308
- },
309
- };
310
- live.id ?? (live.id = (0, utils_1.generateId)(live));
311
- return live;
312
- }
313
- },
314
- CUT_OFF: (msg, room) => {
315
- const { msg_id, send_time } = msg;
316
- // 直播间被切断
317
- let cut = {
318
- platform: "bilibili",
319
- room: room?.id || 0,
320
- type: "live_cut",
321
- id: msg_id,
322
- timestamp: send_time || getDateTimestamp(),
323
- info: {
324
- message: msg.msg,
325
- },
326
- };
327
- cut.id ?? (cut.id = (0, utils_1.generateId)(cut));
328
- return cut;
329
- },
330
- PREPARING: (msg, room) => {
331
- const { msg_id, send_time } = msg;
332
- let off = {
333
- platform: "bilibili",
334
- room: room?.id || 0,
335
- type: "live_end",
336
- id: msg_id,
337
- timestamp: send_time || getDateTimestamp(),
338
- info: {
339
- status: msg.round ? enum_1.RoomStatus.round : enum_1.RoomStatus.off,
340
- },
341
- };
342
- off.id ?? (off.id = (0, utils_1.generateId)(off));
343
- return off;
344
- },
345
- ROOM_CHANGE: (msg, room) => {
346
- const { data, msg_id, send_time } = msg;
347
- let change = {
348
- platform: "bilibili",
349
- room: room?.id || 0,
350
- type: "live_detail",
351
- id: msg_id,
352
- timestamp: send_time || getDateTimestamp(),
353
- info: {
354
- title: data.title,
355
- area: [data.parent_area_name, data.area_name],
356
- },
357
- };
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
- };
396
- }
397
- exports.parseInfo = parseInfo;
@@ -1,77 +0,0 @@
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;