@floating-live/bilibili 0.17.0-alpha.2 → 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,36 +156,39 @@ 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_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,
217
181
  avatar: data.face,
218
182
  },
219
183
  gift: {
184
+ image: data.gift_info.img_basic,
220
185
  name: data.giftName,
221
186
  id: data.giftId,
222
187
  num: data.num,
223
- value: data.coin_type == "gold" ? data.total_coin / 100 : data.total_coin,
188
+ value: data.total_coin,
224
189
  valueType: data.coin_type,
225
- valueName: data.coin_type == "gold" ? "电池" : "银瓜子",
190
+ coins: data.coin_type == "gold" ? data.total_coin / 100 : data.total_coin,
191
+ coinName: data.coin_type == "gold" ? "电池" : "银瓜子",
226
192
  price: data.coin_type == "gold" ? data.total_coin / 1000 : 0,
227
193
  currency: "CNY",
228
194
  action: data.action,
@@ -230,20 +196,23 @@ const parsingFunction = {
230
196
  },
231
197
  },
232
198
  };
233
- gift.id ?? (gift.id = generateId(gift));
199
+ gift.id ?? (gift.id = generateIdByValue(gift, data.rnd));
234
200
  return gift;
235
201
  },
202
+ /** @deprecated Use USER_TOAST_MSG_V2 instead */
236
203
  USER_TOAST_MSG: (msg, room) => {
237
- const { data, msg_id, send_time } = msg;
204
+ return undefined;
205
+ const { data } = msg;
238
206
  let gift = {
239
207
  platform: "bilibili",
240
208
  roomId: room?.id || 0,
241
209
  userId: data.uid,
242
210
  type: "membership",
243
- id: msg_id,
244
- timestamp: send_time || data.start_time * 1000,
245
- info: {
211
+ id: "",
212
+ timestamp: data.start_time * 1000,
213
+ data: {
246
214
  user: {
215
+ // avatar: "",
247
216
  name: data.username,
248
217
  id: data.uid,
249
218
  },
@@ -251,9 +220,10 @@ const parsingFunction = {
251
220
  name: data.role_name,
252
221
  id: data.gift_id,
253
222
  num: data.num,
254
- value: data.price / 100,
223
+ value: data.price,
255
224
  valueType: "gold",
256
- valueName: "电池",
225
+ coins: data.price / 100,
226
+ coinName: "电池",
257
227
  price: data.price / 1000,
258
228
  currency: "CNY",
259
229
  unit: data.unit == "年" ? "year" : data.unit == "天" ? "day" : "month",
@@ -269,51 +239,57 @@ const parsingFunction = {
269
239
  gift.id ?? (gift.id = generateId(gift));
270
240
  return gift;
271
241
  },
272
- // /** @deprecated */
273
- // GUARD_BUY: (msg: MessageData.GUARD_BUY, room) => {
274
- // const { data, msg_id, send_time } = msg;
275
- // let gift: LiveMessage.Membership = {
276
- // platform: "bilibili",
277
- // roomId: room?.id || 0,
278
- // userId: data.uid,
279
- // type: "membership",
280
- // id: msg_id!,
281
- // timestamp: send_time || data.start_time * 1000,
282
- // info: {
283
- // user: {
284
- // name: data.username,
285
- // id: data.uid,
286
- // },
287
- // gift: {
288
- // name: data.gift_name,
289
- // id: data.gift_id,
290
- // num: data.num,
291
- // value: data.price / 100,
292
- // valueType: "gold",
293
- // valueName: "电池",
294
- // price: data.price / 1000,
295
- // currency: "CNY",
296
- // unit: "month",
297
- // },
298
- // name: data.gift_name,
299
- // level: data.guard_level,
300
- // duration: data.num * 30 * 24 * 3600_000,
301
- // },
302
- // };
303
- // gift.id ??= generateId(gift);
304
- // return gift;
305
- // },
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
+ },
306
282
  SUPER_CHAT_MESSAGE: (msg, room) => {
307
- const { data, msg_id, send_time } = msg;
283
+ const { data } = msg;
308
284
  let sc = {
309
285
  platform: "bilibili",
310
286
  roomId: room?.id || 0,
311
287
  userId: data.uid,
312
288
  type: "superchat",
313
- id: msg_id,
314
- timestamp: send_time || data.ts * 1000,
315
- info: {
316
- id: data.id,
289
+ id: "",
290
+ timestamp: data.ts * 1000,
291
+ data: {
292
+ token: data.token,
317
293
  user: {
318
294
  name: data.user_info.uname,
319
295
  id: data.uid,
@@ -335,27 +311,28 @@ const parsingFunction = {
335
311
  id: data.gift.gift_id,
336
312
  name: data.gift.gift_name,
337
313
  num: data.gift.num,
338
- value: data.price * 10,
314
+ value: data.price * 1000,
339
315
  valueType: "gold",
340
- valueName: "电池",
316
+ coins: data.price * 10,
317
+ coinName: "电池",
341
318
  price: data.price,
342
319
  currency: "CNY",
343
320
  },
344
321
  },
345
322
  };
346
- sc.id ?? (sc.id = generateId(sc));
323
+ sc.id ?? (sc.id = generateIdByValue(sc, data.token));
347
324
  return sc;
348
325
  },
349
326
  WATCHED_CHANGE: (msg, room) => {
350
- const { data, msg_id, send_time } = msg;
327
+ const { data } = msg;
351
328
  const stats = {
352
329
  platform: "bilibili",
353
330
  roomId: room?.id || 0,
354
331
  userId: 0,
355
332
  type: "live_stats",
356
- id: msg_id,
357
- timestamp: send_time || getDateTimestamp(),
358
- info: {
333
+ id: "",
334
+ timestamp: getDateTimestamp(),
335
+ data: {
359
336
  view: data.num,
360
337
  },
361
338
  };
@@ -363,23 +340,40 @@ const parsingFunction = {
363
340
  return stats;
364
341
  },
365
342
  LIKE_INFO_V3_UPDATE: (msg, room) => {
366
- const { data, msg_id, send_time } = msg;
343
+ const { data } = msg;
367
344
  const stats = {
368
345
  platform: "bilibili",
369
346
  roomId: room?.id || 0,
370
347
  userId: 0,
371
348
  type: "live_stats",
372
- id: msg_id,
373
- timestamp: send_time || getDateTimestamp(),
374
- info: {
349
+ id: "",
350
+ timestamp: getDateTimestamp(),
351
+ data: {
375
352
  like: data.click_count,
376
353
  },
377
354
  };
378
355
  stats.id ?? (stats.id = generateId(stats));
379
356
  return stats;
380
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
+ },
381
375
  ONLINE_RANK_COUNT: (msg, room) => {
382
- const { data, msg_id, send_time } = msg;
376
+ const { data } = msg;
383
377
  if (data.online_count == null)
384
378
  return;
385
379
  const stats = {
@@ -387,9 +381,9 @@ const parsingFunction = {
387
381
  roomId: room?.id || 0,
388
382
  userId: 0,
389
383
  type: "live_stats",
390
- id: msg_id,
391
- timestamp: send_time || getDateTimestamp(),
392
- info: {
384
+ id: "",
385
+ timestamp: getDateTimestamp(),
386
+ data: {
393
387
  online: data.online_count,
394
388
  },
395
389
  };
@@ -397,15 +391,16 @@ const parsingFunction = {
397
391
  return stats;
398
392
  },
399
393
  ROOM_BLOCK_MSG: (msg, room) => {
400
- const { data, msg_id, send_time } = msg;
394
+ const { data } = msg;
401
395
  const block = {
402
396
  platform: "bilibili",
403
397
  roomId: room?.id || 0,
404
398
  userId: data.uid,
405
399
  type: "block",
406
- id: msg_id,
407
- timestamp: send_time || getDateTimestamp(),
408
- info: {
400
+ id: "",
401
+ timestamp: getDateTimestamp(),
402
+ // expired: data.block_expired ? data.block_expired * 1000 : undefined,
403
+ data: {
409
404
  user: {
410
405
  id: data.uid,
411
406
  name: data.uname,
@@ -419,7 +414,6 @@ const parsingFunction = {
419
414
  return block;
420
415
  },
421
416
  LIVE: (msg, room) => {
422
- const { msg_id, send_time } = msg;
423
417
  // 直播间开播
424
418
  if (msg.live_time) {
425
419
  let live = {
@@ -427,59 +421,59 @@ const parsingFunction = {
427
421
  roomId: room?.id || 0,
428
422
  userId: 0,
429
423
  type: "live_start",
430
- id: msg_id,
431
- timestamp: send_time || msg.live_time * 1000,
432
- info: {
424
+ id: "",
425
+ timestamp: msg.live_time * 1000,
426
+ data: {
433
427
  id: msg.live_key.toString(),
434
428
  },
435
429
  };
436
- live.id ?? (live.id = generateId(live));
430
+ live.id ?? (live.id = generateIdByValue(live, live.data.id));
437
431
  return live;
438
432
  }
439
433
  },
440
434
  CUT_OFF: (msg, room) => {
441
- const { msg_id, send_time } = msg;
442
435
  // 直播间被切断
443
436
  let cut = {
444
437
  platform: "bilibili",
445
438
  roomId: room?.id || 0,
446
439
  userId: 0,
447
440
  type: "live_cut",
448
- id: msg_id,
449
- timestamp: send_time || getDateTimestamp(),
450
- info: {
441
+ id: "",
442
+ timestamp: getDateTimestamp(),
443
+ data: {
451
444
  message: msg.msg,
445
+ status: LiveRoomStatus.off,
452
446
  },
453
447
  };
454
448
  cut.id ?? (cut.id = generateId(cut));
455
449
  return cut;
456
450
  },
457
451
  PREPARING: (msg, room) => {
458
- const { msg_id, send_time } = msg;
452
+ const { send_time } = msg;
459
453
  let off = {
460
454
  platform: "bilibili",
461
455
  roomId: room?.id || 0,
462
456
  userId: 0,
463
457
  type: "live_end",
464
- id: msg_id,
458
+ id: "",
465
459
  timestamp: send_time || getDateTimestamp(),
466
- info: {
460
+ data: {
467
461
  status: msg.round ? LiveRoomStatus.round : LiveRoomStatus.off,
468
462
  },
469
463
  };
470
- off.id ?? (off.id = generateId(off));
464
+ off.id ?? (off.id = generateIdByTimestamp(off));
471
465
  return off;
472
466
  },
473
467
  ROOM_CHANGE: (msg, room) => {
474
- const { data, msg_id, send_time } = msg;
468
+ const { data } = msg;
475
469
  let change = {
476
470
  platform: "bilibili",
477
471
  roomId: room?.id || 0,
478
472
  userId: 0,
479
473
  type: "live_detail",
480
- id: msg_id,
481
- timestamp: send_time || getDateTimestamp(),
482
- info: {
474
+ id: "",
475
+ timestamp: getDateTimestamp(),
476
+ data: {
483
477
  title: data.title,
484
478
  area: [data.parent_area_name, data.area_name],
485
479
  },
@@ -487,8 +481,8 @@ const parsingFunction = {
487
481
  change.id ?? (change.id = generateId(change));
488
482
  return change;
489
483
  },
490
- // ANCHOR_LOT_START: (msg: MessageData.ANCHOR_LOT_START, room) => {
491
- // const { data, msg_id, send_time } = msg;
484
+ // ANCHOR_LOT_START: (msg: BilibiliInternal.WebSocket.Prod.ANCHOR_LOT_START, room) => {
485
+ // const { data } = msg;
492
486
  // let m: LiveMessage.Lottery = {
493
487
  // platform: "bilibili",
494
488
  // roomId: room?.id || 0,
@@ -496,7 +490,7 @@ const parsingFunction = {
496
490
  // type: "lottery",
497
491
  // timestamp: send_time || data.current_time * 1000,
498
492
  // id: msg_id!,
499
- // info: {
493
+ // data: {
500
494
  // id: data.id,
501
495
  // award: {
502
496
  // name: data.award_name,
@@ -511,19 +505,21 @@ const parsingFunction = {
511
505
  // return m;
512
506
  // },
513
507
  };
514
- /** 转换bilibili直播弹幕为floating通用格式 */
508
+ /** 转换bilibili直播弹幕为floalive通用格式 */
515
509
  export function parseMessage(data, room) {
516
510
  return parsingFunction[data.cmd]?.(data, room);
517
511
  }
518
- /** 转换bilibili直播间信息为floating通用格式 */
512
+ /** 转换bilibili直播间信息为floalive通用格式 */
519
513
  export function parseGetInfoByRoom(data) {
520
514
  const { room_info, anchor_info, like_info_v3, watched_show, } = data;
521
515
  return {
522
516
  platform: "bilibili",
517
+ service: "bilibili",
523
518
  id: room_info.room_id,
524
519
  roomId: room_info.room_id,
525
520
  shortId: room_info.short_id,
526
521
  key: `bilibili:${room_info.room_id}`,
522
+ pending: false,
527
523
  detail: {
528
524
  title: room_info.title,
529
525
  area: [room_info.parent_area_name, room_info.area_name],
@@ -550,18 +546,18 @@ export function parseGetInfoByRoom(data) {
550
546
  opened: false,
551
547
  connectionStatus: 0,
552
548
  valid: true,
553
- service: "",
554
- serviceId: "bilibili",
555
549
  };
556
550
  }
557
- /** 转换bilibili直播间信息为floating通用格式 */
551
+ /** 转换bilibili直播间信息为floalive通用格式 */
558
552
  export function parseRoomBaseInfo(data) {
559
553
  return {
560
554
  platform: "bilibili",
555
+ service: "bilibili",
561
556
  id: data.room_id,
562
557
  roomId: data.room_id,
563
558
  shortId: data.short_id,
564
559
  key: `bilibili:${data.room_id}`,
560
+ pending: false,
565
561
  detail: {
566
562
  title: data.title,
567
563
  area: [data.parent_area_name, data.area_name],
@@ -584,8 +580,6 @@ export function parseRoomBaseInfo(data) {
584
580
  opened: false,
585
581
  connectionStatus: 0,
586
582
  valid: true,
587
- service: "",
588
- serviceId: "bilibili",
589
583
  };
590
584
  }
591
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,6 +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,
278
+ // decodeProtobuf: true,
275
279
  });
276
280
  const controller = new AbortController();
277
281
  const signal = controller.signal;
@@ -290,11 +294,11 @@ export class RoomBilibili extends LiveRoom {
290
294
  this.safeReconnect();
291
295
  }
292
296
  }, { signal });
293
- client.addEventListener("CONNECT_SUCCESS", () => {
297
+ client.addEventListener("live", () => {
294
298
  // 连接到直播间
295
299
  this.emitConnention(LiveConnectionStatus.entered);
296
300
  }, { signal });
297
- client.addEventListener("MESSAGE", ({ data }) => {
301
+ client.addEventListener("msg", ({ data }) => {
298
302
  const m = parseMessage(data, this);
299
303
  m && this.emitMessage(m);
300
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.2",
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,7 +20,9 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@floating-live/cookies": "^0.1.0",
23
- "bilibili-live-danmaku": "^0.7.15",
23
+ "@laplace.live/internal": "^1.3.42",
24
+ "@laplace.live/ws": "^8.1.1",
25
+ "bilibili-live-danmaku": "^0.7.16",
24
26
  "md5": "^2.3.0"
25
27
  },
26
28
  "devDependencies": {
@@ -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": "f5691cd51e7dd93aebc1b5a1c499644ee21c80e2"
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.2",
5
+ "version": "0.17.0-alpha.4",
6
6
  "description": "Bilibili plugin for FloatingLive",
7
7
  "main": "plugin.js"
8
8
  }