@floating-live/bilibili 0.17.0-alpha.3 → 0.17.0-alpha.4

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/LICENSE CHANGED
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ import { bilibili } from "./proto";
2
+ export declare const decode_INTERACT_WORD_V2: (pb: string) => bilibili.live.xuserreward.v1.InteractWord;
3
+ export declare const decode_ONLINE_RANK_V3: (pb: string) => bilibili.live.rankdb.v1.GoldRankBroadcast;
@@ -0,0 +1,17 @@
1
+ import { bilibili } from "./proto";
2
+ export const decode_INTERACT_WORD_V2 = (pb) => {
3
+ return bilibili.live.xuserreward.v1.InteractWord.decode(base64ToUint8Array(pb));
4
+ };
5
+ export const decode_ONLINE_RANK_V3 = (pb) => {
6
+ return bilibili.live.rankdb.v1.GoldRankBroadcast.decode(base64ToUint8Array(pb));
7
+ };
8
+ function base64ToUint8Array(base64String) {
9
+ let padding = "=".repeat((4 - (base64String.length % 4)) % 4);
10
+ let base64 = (base64String + padding).replace(/\-/g, "+").replace(/_/g, "/");
11
+ let rawData = atob(base64);
12
+ let outputArray = new Uint8Array(rawData.length);
13
+ for (var i = 0; i < rawData.length; ++i) {
14
+ outputArray[i] = rawData.charCodeAt(i);
15
+ }
16
+ return outputArray;
17
+ }
package/dist/parser.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { LiveMessage, LiveRoomData } from "floating-live";
2
2
  import { BilibiliRoomData, RoomBaseInfo } from "./types.js";
3
3
  import { DataXliveGetInfoByRoom, MessageData } from "bilibili-live-danmaku";
4
- /** 转换bilibili直播弹幕为floating通用格式 */
4
+ /** 转换bilibili直播弹幕为floalive通用格式 */
5
5
  export declare function parseMessage(data: MessageData.All, room?: BilibiliRoomData): LiveMessage.All | undefined;
6
- /** 转换bilibili直播间信息为floating通用格式 */
6
+ /** 转换bilibili直播间信息为floalive通用格式 */
7
7
  export declare function parseGetInfoByRoom(data: DataXliveGetInfoByRoom): BilibiliRoomData;
8
- /** 转换bilibili直播间信息为floating通用格式 */
8
+ /** 转换bilibili直播间信息为floalive通用格式 */
9
9
  export declare function parseRoomBaseInfo(data: RoomBaseInfo): BilibiliRoomData;
10
10
  export declare function mergeLiveRoomData<T extends LiveRoomData>(...list: Partial<T>[]): T;
package/dist/parser.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { UserType, ImageSize, LiveRoomStatus, } from "floating-live";
2
+ import { decode_INTERACT_WORD_V2 } from "./decoder.js";
2
3
  // utils
3
- const generateId = (m) => `${m.platform}:${m.roomId}-${m.type}:${m.userId}@${Date.now()}`;
4
+ /** @deprecated Use generateIdByTimestamp or generateIdByValue instead */
5
+ const generateId = (m) => `${m.platform}:${m.roomId}-${m.type}:${m.userId}~${Date.now()}`;
6
+ const generateIdByTimestamp = (m) => `${m.platform}:${m.roomId}-${m.type}:${m.userId}@${m.timestamp}`;
7
+ const generateIdByValue = (m, id) => `${m.platform}:${m.roomId}-${m.type}:${m.userId}@${id}`;
4
8
  // 获取当前时间戳,以替代无法从数据中获取时间戳的情况,精度为1s
5
9
  function getDateTimestamp() {
6
10
  return Math.floor(Date.now() / 1000) * 1000;
@@ -8,15 +12,16 @@ function getDateTimestamp() {
8
12
  const parsingFunction = {
9
13
  DANMU_MSG: (msg, room) => {
10
14
  const { info, msg_id } = msg;
11
- let content = info[1];
12
- let mode = info[0][1];
13
- let color = info[0][3];
14
- let uname = info[2][1];
15
- let uid = info[2][0];
16
- let timestamp = info[0][4];
17
- let guard_level = info[7]; // 舰长级别
18
- let extra = JSON.parse(info[0][15].extra);
19
- let medal = info[3][0] != null
15
+ const content = info[1];
16
+ const mode = info[0][1];
17
+ const color = info[0][3];
18
+ const uname = info[2][1];
19
+ const uid = info[2][0];
20
+ const timestamp = info[0][4];
21
+ const guard_level = info[7]; // 舰长级别
22
+ const emote = info[0][12] ? info[0][13] : undefined;
23
+ const extra = JSON.parse(info[0][15].extra);
24
+ const medal = info[3]?.[0] != null
20
25
  ? {
21
26
  level: info[3][0],
22
27
  name: info[3][1],
@@ -50,17 +55,17 @@ const parsingFunction = {
50
55
  userId: uid,
51
56
  type: "comment",
52
57
  timestamp: timestamp,
53
- id: msg_id,
54
- info: {
58
+ id: "",
59
+ data: {
55
60
  color: color,
56
61
  mode: mode,
57
62
  content: content,
58
- image: info[0][12]
63
+ image: emote
59
64
  ? {
60
65
  name: content,
61
- id: info[0][13].emoticon_unique,
62
- url: info[0][13].url,
63
- size: info[0][13].width == info[0][13].height
66
+ id: emote.emoticon_unique,
67
+ url: emote.url,
68
+ size: emote.width == emote.height
64
69
  ? ImageSize.large
65
70
  : ImageSize.small,
66
71
  }
@@ -76,54 +81,12 @@ const parsingFunction = {
76
81
  },
77
82
  },
78
83
  };
79
- danmaku.id ?? (danmaku.id = generateId(danmaku));
84
+ danmaku.id = generateIdByTimestamp(danmaku);
80
85
  return danmaku;
81
86
  },
82
- // /** @deprecated */
83
- // INTERACT_WORD: (msg: MessageData.INTERACT_WORD, room) => {
84
- // const { data, msg_id, send_time } = msg;
85
- // let type: "entry" | "follow" | "share";
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: LiveMessage.Interact = {
100
- // platform: "bilibili",
101
- // roomId: room?.id || 0,
102
- // userId: data.uid,
103
- // type: type,
104
- // id: msg_id!,
105
- // timestamp: send_time || Math.floor(data.trigger_time / 1000000),
106
- // info: {
107
- // user: {
108
- // name: data.uname,
109
- // id: data.uid,
110
- // medal: data.fans_medal?.medal_level
111
- // ? {
112
- // level: data.fans_medal.medal_level,
113
- // name: data.fans_medal.medal_name,
114
- // id: data.fans_medal.target_id,
115
- // membership: data.fans_medal.guard_level,
116
- // }
117
- // : null,
118
- // },
119
- // },
120
- // };
121
- // interact.id ??= generateId(interact);
122
- // return interact;
123
- // },
124
87
  INTERACT_WORD_V2: (msg, room) => {
125
- const { decoded, msg_id, send_time } = msg;
126
- const data = decoded;
88
+ const pb = msg.data.pb;
89
+ const data = decode_INTERACT_WORD_V2(pb);
127
90
  let type;
128
91
  switch (Number(data.msgType)) {
129
92
  case 1:
@@ -143,9 +106,9 @@ const parsingFunction = {
143
106
  roomId: room?.id || 0,
144
107
  userId: Number(data.uid),
145
108
  type: type,
146
- id: msg_id,
147
- timestamp: send_time || Math.floor(Number(data.triggerTime || 0) / 1000000),
148
- info: {
109
+ id: "",
110
+ timestamp: Math.floor(Number(data.triggerTime || 0) / 1000000),
111
+ data: {
149
112
  user: {
150
113
  name: data.uname,
151
114
  id: Number(data.uid),
@@ -161,19 +124,19 @@ const parsingFunction = {
161
124
  },
162
125
  },
163
126
  };
164
- interact.id ?? (interact.id = generateId(interact));
127
+ interact.id ?? (interact.id = generateIdByTimestamp(interact));
165
128
  return interact;
166
129
  },
167
130
  LIKE_INFO_V3_CLICK: (msg, room) => {
168
- const { data, msg_id, send_time } = msg;
131
+ const { data } = msg;
169
132
  let like = {
170
133
  platform: "bilibili",
171
134
  roomId: room?.id || 0,
172
135
  userId: data.uid,
173
136
  type: "like",
174
- id: msg_id,
175
- timestamp: send_time || getDateTimestamp(),
176
- info: {
137
+ id: "",
138
+ timestamp: getDateTimestamp(),
139
+ data: {
177
140
  user: {
178
141
  name: data.uname,
179
142
  id: data.uid,
@@ -193,24 +156,25 @@ const parsingFunction = {
193
156
  return like;
194
157
  },
195
158
  SEND_GIFT: (msg, room) => {
196
- const { data, msg_id, send_time } = msg;
159
+ const { data } = msg;
160
+ const medal = data.medal_info;
197
161
  let gift = {
198
162
  platform: "bilibili",
199
163
  roomId: room?.id || 0,
200
164
  userId: data.uid,
201
165
  type: "gift",
202
- id: msg_id || data.combo_send?.combo_id,
203
- timestamp: send_time || data.timestamp * 1000,
204
- info: {
166
+ id: "",
167
+ timestamp: data.timestamp * 1000,
168
+ data: {
205
169
  user: {
206
170
  name: data.uname,
207
171
  id: data.uid,
208
- medal: data.fans_medal && data.fans_medal.medal_level
172
+ medal: medal && medal.medal_level
209
173
  ? {
210
- level: data.fans_medal.medal_level,
211
- name: data.fans_medal.medal_name,
212
- id: data.fans_medal.target_id,
213
- membership: data.fans_medal.guard_level,
174
+ level: medal.medal_level,
175
+ name: medal.medal_name,
176
+ id: medal.target_id,
177
+ membership: medal.guard_level,
214
178
  }
215
179
  : null,
216
180
  membership: data.guard_level,
@@ -221,9 +185,10 @@ const parsingFunction = {
221
185
  name: data.giftName,
222
186
  id: data.giftId,
223
187
  num: data.num,
224
- value: data.coin_type == "gold" ? data.total_coin / 100 : data.total_coin,
188
+ value: data.total_coin,
225
189
  valueType: data.coin_type,
226
- valueName: data.coin_type == "gold" ? "电池" : "银瓜子",
190
+ coins: data.coin_type == "gold" ? data.total_coin / 100 : data.total_coin,
191
+ coinName: data.coin_type == "gold" ? "电池" : "银瓜子",
227
192
  price: data.coin_type == "gold" ? data.total_coin / 1000 : 0,
228
193
  currency: "CNY",
229
194
  action: data.action,
@@ -231,19 +196,21 @@ const parsingFunction = {
231
196
  },
232
197
  },
233
198
  };
234
- gift.id ?? (gift.id = generateId(gift));
199
+ gift.id ?? (gift.id = generateIdByValue(gift, data.rnd));
235
200
  return gift;
236
201
  },
202
+ /** @deprecated Use USER_TOAST_MSG_V2 instead */
237
203
  USER_TOAST_MSG: (msg, room) => {
238
- const { data, msg_id, send_time } = msg;
204
+ return undefined;
205
+ const { data } = msg;
239
206
  let gift = {
240
207
  platform: "bilibili",
241
208
  roomId: room?.id || 0,
242
209
  userId: data.uid,
243
210
  type: "membership",
244
- id: msg_id,
245
- timestamp: send_time || data.start_time * 1000,
246
- info: {
211
+ id: "",
212
+ timestamp: data.start_time * 1000,
213
+ data: {
247
214
  user: {
248
215
  // avatar: "",
249
216
  name: data.username,
@@ -253,9 +220,10 @@ const parsingFunction = {
253
220
  name: data.role_name,
254
221
  id: data.gift_id,
255
222
  num: data.num,
256
- value: data.price / 100,
223
+ value: data.price,
257
224
  valueType: "gold",
258
- valueName: "电池",
225
+ coins: data.price / 100,
226
+ coinName: "电池",
259
227
  price: data.price / 1000,
260
228
  currency: "CNY",
261
229
  unit: data.unit == "年" ? "year" : data.unit == "天" ? "day" : "month",
@@ -271,51 +239,57 @@ const parsingFunction = {
271
239
  gift.id ?? (gift.id = generateId(gift));
272
240
  return gift;
273
241
  },
274
- // /** @deprecated */
275
- // GUARD_BUY: (msg: MessageData.GUARD_BUY, room) => {
276
- // const { data, msg_id, send_time } = msg;
277
- // let gift: LiveMessage.Membership = {
278
- // platform: "bilibili",
279
- // roomId: room?.id || 0,
280
- // userId: data.uid,
281
- // type: "membership",
282
- // id: msg_id!,
283
- // timestamp: send_time || data.start_time * 1000,
284
- // info: {
285
- // user: {
286
- // name: data.username,
287
- // id: data.uid,
288
- // },
289
- // gift: {
290
- // name: data.gift_name,
291
- // id: data.gift_id,
292
- // num: data.num,
293
- // value: data.price / 100,
294
- // valueType: "gold",
295
- // valueName: "电池",
296
- // price: data.price / 1000,
297
- // currency: "CNY",
298
- // unit: "month",
299
- // },
300
- // name: data.gift_name,
301
- // level: data.guard_level,
302
- // duration: data.num * 30 * 24 * 3600_000,
303
- // },
304
- // };
305
- // gift.id ??= generateId(gift);
306
- // return gift;
307
- // },
242
+ USER_TOAST_MSG_V2: (msg, room) => {
243
+ const { data } = msg;
244
+ const user = data.sender_uinfo;
245
+ const num = data.pay_info.num;
246
+ let gift = {
247
+ platform: "bilibili",
248
+ roomId: room?.id || 0,
249
+ userId: user.uid,
250
+ type: "membership",
251
+ id: "",
252
+ timestamp: data.guard_info.start_time * 1000,
253
+ data: {
254
+ user: {
255
+ // avatar: "",
256
+ name: user.base.name,
257
+ id: user.uid,
258
+ },
259
+ gift: {
260
+ name: data.guard_info.role_name,
261
+ id: data.gift_info.gift_id,
262
+ num: num,
263
+ value: data.pay_info.price,
264
+ valueType: "gold",
265
+ coins: data.pay_info.price / 100,
266
+ coinName: "电池",
267
+ price: data.pay_info.price / 1000,
268
+ currency: "CNY",
269
+ unit: data.pay_info.unit == "年" ? "year" : data.pay_info.unit == "天" ? "day" : "month",
270
+ },
271
+ name: data.guard_info.role_name,
272
+ level: data.guard_info.guard_level,
273
+ duration: num *
274
+ (data.pay_info.unit == "年" ? 365 : data.pay_info.unit == "天" ? 1 : 30) *
275
+ 24 *
276
+ 3600000,
277
+ },
278
+ };
279
+ gift.id ?? (gift.id = generateIdByValue(gift, data.pay_info.payflow_id));
280
+ return gift;
281
+ },
308
282
  SUPER_CHAT_MESSAGE: (msg, room) => {
309
- const { data, msg_id, send_time } = msg;
283
+ const { data } = msg;
310
284
  let sc = {
311
285
  platform: "bilibili",
312
286
  roomId: room?.id || 0,
313
287
  userId: data.uid,
314
288
  type: "superchat",
315
- id: msg_id,
316
- timestamp: send_time || data.ts * 1000,
317
- info: {
318
- id: data.id,
289
+ id: "",
290
+ timestamp: data.ts * 1000,
291
+ data: {
292
+ token: data.token,
319
293
  user: {
320
294
  name: data.user_info.uname,
321
295
  id: data.uid,
@@ -337,27 +311,28 @@ const parsingFunction = {
337
311
  id: data.gift.gift_id,
338
312
  name: data.gift.gift_name,
339
313
  num: data.gift.num,
340
- value: data.price * 10,
314
+ value: data.price * 1000,
341
315
  valueType: "gold",
342
- valueName: "电池",
316
+ coins: data.price * 10,
317
+ coinName: "电池",
343
318
  price: data.price,
344
319
  currency: "CNY",
345
320
  },
346
321
  },
347
322
  };
348
- sc.id ?? (sc.id = generateId(sc));
323
+ sc.id ?? (sc.id = generateIdByValue(sc, data.token));
349
324
  return sc;
350
325
  },
351
326
  WATCHED_CHANGE: (msg, room) => {
352
- const { data, msg_id, send_time } = msg;
327
+ const { data } = msg;
353
328
  const stats = {
354
329
  platform: "bilibili",
355
330
  roomId: room?.id || 0,
356
331
  userId: 0,
357
332
  type: "live_stats",
358
- id: msg_id,
359
- timestamp: send_time || getDateTimestamp(),
360
- info: {
333
+ id: "",
334
+ timestamp: getDateTimestamp(),
335
+ data: {
361
336
  view: data.num,
362
337
  },
363
338
  };
@@ -365,23 +340,40 @@ const parsingFunction = {
365
340
  return stats;
366
341
  },
367
342
  LIKE_INFO_V3_UPDATE: (msg, room) => {
368
- const { data, msg_id, send_time } = msg;
343
+ const { data } = msg;
369
344
  const stats = {
370
345
  platform: "bilibili",
371
346
  roomId: room?.id || 0,
372
347
  userId: 0,
373
348
  type: "live_stats",
374
- id: msg_id,
375
- timestamp: send_time || getDateTimestamp(),
376
- info: {
349
+ id: "",
350
+ timestamp: getDateTimestamp(),
351
+ data: {
377
352
  like: data.click_count,
378
353
  },
379
354
  };
380
355
  stats.id ?? (stats.id = generateId(stats));
381
356
  return stats;
382
357
  },
358
+ ROOM_REAL_TIME_MESSAGE_UPDATE: (msg, room) => {
359
+ const { data } = msg;
360
+ const stats = {
361
+ platform: "bilibili",
362
+ roomId: room?.id || 0,
363
+ userId: 0,
364
+ type: "live_stats",
365
+ id: "",
366
+ timestamp: getDateTimestamp(),
367
+ data: {
368
+ fans: data.fans,
369
+ clubFans: data.fans_club
370
+ },
371
+ };
372
+ stats.id ?? (stats.id = generateId(stats));
373
+ return stats;
374
+ },
383
375
  ONLINE_RANK_COUNT: (msg, room) => {
384
- const { data, msg_id, send_time } = msg;
376
+ const { data } = msg;
385
377
  if (data.online_count == null)
386
378
  return;
387
379
  const stats = {
@@ -389,9 +381,9 @@ const parsingFunction = {
389
381
  roomId: room?.id || 0,
390
382
  userId: 0,
391
383
  type: "live_stats",
392
- id: msg_id,
393
- timestamp: send_time || getDateTimestamp(),
394
- info: {
384
+ id: "",
385
+ timestamp: getDateTimestamp(),
386
+ data: {
395
387
  online: data.online_count,
396
388
  },
397
389
  };
@@ -399,15 +391,16 @@ const parsingFunction = {
399
391
  return stats;
400
392
  },
401
393
  ROOM_BLOCK_MSG: (msg, room) => {
402
- const { data, msg_id, send_time } = msg;
394
+ const { data } = msg;
403
395
  const block = {
404
396
  platform: "bilibili",
405
397
  roomId: room?.id || 0,
406
398
  userId: data.uid,
407
399
  type: "block",
408
- id: msg_id,
409
- timestamp: send_time || getDateTimestamp(),
410
- info: {
400
+ id: "",
401
+ timestamp: getDateTimestamp(),
402
+ // expired: data.block_expired ? data.block_expired * 1000 : undefined,
403
+ data: {
411
404
  user: {
412
405
  id: data.uid,
413
406
  name: data.uname,
@@ -421,7 +414,6 @@ const parsingFunction = {
421
414
  return block;
422
415
  },
423
416
  LIVE: (msg, room) => {
424
- const { msg_id, send_time } = msg;
425
417
  // 直播间开播
426
418
  if (msg.live_time) {
427
419
  let live = {
@@ -429,59 +421,59 @@ const parsingFunction = {
429
421
  roomId: room?.id || 0,
430
422
  userId: 0,
431
423
  type: "live_start",
432
- id: msg_id,
433
- timestamp: send_time || msg.live_time * 1000,
434
- info: {
424
+ id: "",
425
+ timestamp: msg.live_time * 1000,
426
+ data: {
435
427
  id: msg.live_key.toString(),
436
428
  },
437
429
  };
438
- live.id ?? (live.id = generateId(live));
430
+ live.id ?? (live.id = generateIdByValue(live, live.data.id));
439
431
  return live;
440
432
  }
441
433
  },
442
434
  CUT_OFF: (msg, room) => {
443
- const { msg_id, send_time } = msg;
444
435
  // 直播间被切断
445
436
  let cut = {
446
437
  platform: "bilibili",
447
438
  roomId: room?.id || 0,
448
439
  userId: 0,
449
440
  type: "live_cut",
450
- id: msg_id,
451
- timestamp: send_time || getDateTimestamp(),
452
- info: {
441
+ id: "",
442
+ timestamp: getDateTimestamp(),
443
+ data: {
453
444
  message: msg.msg,
445
+ status: LiveRoomStatus.off,
454
446
  },
455
447
  };
456
448
  cut.id ?? (cut.id = generateId(cut));
457
449
  return cut;
458
450
  },
459
451
  PREPARING: (msg, room) => {
460
- const { msg_id, send_time } = msg;
452
+ const { send_time } = msg;
461
453
  let off = {
462
454
  platform: "bilibili",
463
455
  roomId: room?.id || 0,
464
456
  userId: 0,
465
457
  type: "live_end",
466
- id: msg_id,
458
+ id: "",
467
459
  timestamp: send_time || getDateTimestamp(),
468
- info: {
460
+ data: {
469
461
  status: msg.round ? LiveRoomStatus.round : LiveRoomStatus.off,
470
462
  },
471
463
  };
472
- off.id ?? (off.id = generateId(off));
464
+ off.id ?? (off.id = generateIdByTimestamp(off));
473
465
  return off;
474
466
  },
475
467
  ROOM_CHANGE: (msg, room) => {
476
- const { data, msg_id, send_time } = msg;
468
+ const { data } = msg;
477
469
  let change = {
478
470
  platform: "bilibili",
479
471
  roomId: room?.id || 0,
480
472
  userId: 0,
481
473
  type: "live_detail",
482
- id: msg_id,
483
- timestamp: send_time || getDateTimestamp(),
484
- info: {
474
+ id: "",
475
+ timestamp: getDateTimestamp(),
476
+ data: {
485
477
  title: data.title,
486
478
  area: [data.parent_area_name, data.area_name],
487
479
  },
@@ -489,8 +481,8 @@ const parsingFunction = {
489
481
  change.id ?? (change.id = generateId(change));
490
482
  return change;
491
483
  },
492
- // ANCHOR_LOT_START: (msg: MessageData.ANCHOR_LOT_START, room) => {
493
- // const { data, msg_id, send_time } = msg;
484
+ // ANCHOR_LOT_START: (msg: BilibiliInternal.WebSocket.Prod.ANCHOR_LOT_START, room) => {
485
+ // const { data } = msg;
494
486
  // let m: LiveMessage.Lottery = {
495
487
  // platform: "bilibili",
496
488
  // roomId: room?.id || 0,
@@ -498,7 +490,7 @@ const parsingFunction = {
498
490
  // type: "lottery",
499
491
  // timestamp: send_time || data.current_time * 1000,
500
492
  // id: msg_id!,
501
- // info: {
493
+ // data: {
502
494
  // id: data.id,
503
495
  // award: {
504
496
  // name: data.award_name,
@@ -513,19 +505,21 @@ const parsingFunction = {
513
505
  // return m;
514
506
  // },
515
507
  };
516
- /** 转换bilibili直播弹幕为floating通用格式 */
508
+ /** 转换bilibili直播弹幕为floalive通用格式 */
517
509
  export function parseMessage(data, room) {
518
510
  return parsingFunction[data.cmd]?.(data, room);
519
511
  }
520
- /** 转换bilibili直播间信息为floating通用格式 */
512
+ /** 转换bilibili直播间信息为floalive通用格式 */
521
513
  export function parseGetInfoByRoom(data) {
522
514
  const { room_info, anchor_info, like_info_v3, watched_show, } = data;
523
515
  return {
524
516
  platform: "bilibili",
517
+ service: "bilibili",
525
518
  id: room_info.room_id,
526
519
  roomId: room_info.room_id,
527
520
  shortId: room_info.short_id,
528
521
  key: `bilibili:${room_info.room_id}`,
522
+ pending: false,
529
523
  detail: {
530
524
  title: room_info.title,
531
525
  area: [room_info.parent_area_name, room_info.area_name],
@@ -552,18 +546,18 @@ export function parseGetInfoByRoom(data) {
552
546
  opened: false,
553
547
  connectionStatus: 0,
554
548
  valid: true,
555
- service: "",
556
- serviceId: "bilibili",
557
549
  };
558
550
  }
559
- /** 转换bilibili直播间信息为floating通用格式 */
551
+ /** 转换bilibili直播间信息为floalive通用格式 */
560
552
  export function parseRoomBaseInfo(data) {
561
553
  return {
562
554
  platform: "bilibili",
555
+ service: "bilibili",
563
556
  id: data.room_id,
564
557
  roomId: data.room_id,
565
558
  shortId: data.short_id,
566
559
  key: `bilibili:${data.room_id}`,
560
+ pending: false,
567
561
  detail: {
568
562
  title: data.title,
569
563
  area: [data.parent_area_name, data.area_name],
@@ -586,8 +580,6 @@ export function parseRoomBaseInfo(data) {
586
580
  opened: false,
587
581
  connectionStatus: 0,
588
582
  valid: true,
589
- service: "",
590
- serviceId: "bilibili",
591
583
  };
592
584
  }
593
585
  export function mergeLiveRoomData(...list) {
package/dist/plugin.js CHANGED
@@ -43,7 +43,7 @@ export class PluginBilibili extends BasePlugin {
43
43
  ...options,
44
44
  });
45
45
  });
46
- ctx.registerCommand("bilibili.room.data", async (e, id) => {
46
+ ctx.registerCommand("bilibili.room.info", async (e, id) => {
47
47
  return await fetchLiveRoomData(this.apiClient, parseInt(id.toString()));
48
48
  });
49
49
  ctx.registerCommand("bilibili.credentials.check", async (e, credentials) => {
package/dist/room.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BilibiliRoomData, ConnectTokens } from "./types.js";
2
- import { LiveWS } from "bilibili-live-danmaku";
2
+ import { LiveWS } from "@laplace.live/ws";
3
3
  import { UserInfo, LiveRoomStatsInfo, LiveRoomDetailInfo, LiveRoom } from "floating-live";
4
4
  /** 配置项 */
5
5
  export interface RoomOptions {
@@ -36,6 +36,8 @@ export declare class RoomBilibili extends LiveRoom implements BilibiliRoomData {
36
36
  #private;
37
37
  /** 平台id */
38
38
  readonly platform: string;
39
+ /** 服务id */
40
+ readonly service: string;
39
41
  /** 直播间号 */
40
42
  readonly id: number;
41
43
  /** 直播间room_id */
package/dist/room.js CHANGED
@@ -10,9 +10,10 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
12
  var _RoomBilibili_tokens, _RoomBilibili_apiClient;
13
- import { LiveWS, parseLiveConfig } from "bilibili-live-danmaku";
13
+ import { LiveWS } from "@laplace.live/ws";
14
14
  import { parseGetInfoByRoom, parseMessage, parseRoomBaseInfo } from "./parser.js";
15
15
  import { LiveConnectionStatus, LiveRoom, LiveRoomOpenStatus, } from "floating-live";
16
+ import { parseLiveConfig } from "bilibili-live-danmaku";
16
17
  import { BilibiliApiClientEx } from "./utils/request.js";
17
18
  const symbolAbortController = Symbol("abortController");
18
19
  export class RoomBilibili extends LiveRoom {
@@ -28,6 +29,8 @@ export class RoomBilibili extends LiveRoom {
28
29
  super();
29
30
  /** 平台id */
30
31
  this.platform = "bilibili";
32
+ /** 服务id */
33
+ this.service = "bilibili";
31
34
  /** 直播间room_id */
32
35
  this.roomId = 0;
33
36
  /** 直播间短房号 */
@@ -272,7 +275,7 @@ export class RoomBilibili extends LiveRoom {
272
275
  uid: __classPrivateFieldGet(this, _RoomBilibili_tokens, "f")?.uid,
273
276
  buvid: __classPrivateFieldGet(this, _RoomBilibili_tokens, "f")?.buvid,
274
277
  key: __classPrivateFieldGet(this, _RoomBilibili_tokens, "f")?.key,
275
- decodeProtobuf: true,
278
+ // decodeProtobuf: true,
276
279
  });
277
280
  const controller = new AbortController();
278
281
  const signal = controller.signal;
@@ -291,11 +294,11 @@ export class RoomBilibili extends LiveRoom {
291
294
  this.safeReconnect();
292
295
  }
293
296
  }, { signal });
294
- client.addEventListener("CONNECT_SUCCESS", () => {
297
+ client.addEventListener("live", () => {
295
298
  // 连接到直播间
296
299
  this.emitConnention(LiveConnectionStatus.entered);
297
300
  }, { signal });
298
- client.addEventListener("MESSAGE", ({ data }) => {
301
+ client.addEventListener("msg", ({ data }) => {
299
302
  const m = parseMessage(data, this);
300
303
  m && this.emitMessage(m);
301
304
  this.emitRaw(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floating-live/bilibili",
3
- "version": "0.17.0-alpha.3",
3
+ "version": "0.17.0-alpha.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,6 +20,8 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@floating-live/cookies": "^0.1.0",
23
+ "@laplace.live/internal": "^1.3.42",
24
+ "@laplace.live/ws": "^8.1.1",
23
25
  "bilibili-live-danmaku": "^0.7.16",
24
26
  "md5": "^2.3.0"
25
27
  },
@@ -34,11 +36,11 @@
34
36
  "vite": "^8.0.11"
35
37
  },
36
38
  "peerDependencies": {
37
- "floating-live": "0.17.0-alpha.5"
39
+ "floating-live": "0.17.0-alpha.15"
38
40
  },
39
41
  "files": [
40
42
  "dist",
41
43
  "plugin.json"
42
44
  ],
43
- "gitHead": "eb7c02f5dba6b6abc223b747cdf391942ae9e734"
45
+ "gitHead": "2693172ffac76bae4a3ff6e6faa13b8324e71421"
44
46
  }
package/plugin.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "bilibili",
3
3
  "role": "platform/bilibili",
4
4
  "author": "FloatingLive",
5
- "version": "0.17.0-alpha.3",
5
+ "version": "0.17.0-alpha.4",
6
6
  "description": "Bilibili plugin for FloatingLive",
7
7
  "main": "plugin.js"
8
8
  }