floating-live 0.11.2 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export * from "./src/types";
3
3
  export * from "./src/enum";
4
4
  export * from "./src/lib/LiveRoom";
5
5
  export * from "./src/lib/Reglist";
6
+ export * from "./src/tool";
package/index.js CHANGED
@@ -21,3 +21,4 @@ __exportStar(require("./src/types"), exports);
21
21
  __exportStar(require("./src/enum"), exports);
22
22
  __exportStar(require("./src/lib/LiveRoom"), exports);
23
23
  __exportStar(require("./src/lib/Reglist"), exports);
24
+ __exportStar(require("./src/tool"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "type": "commonjs",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "acfun-live-danmaku": "^0.6.1",
19
19
  "axios": "^1.4.0",
20
- "bilibili-live-ws": "^6.0.3",
20
+ "bilibili-live-ws": "^6.3.1",
21
21
  "fs-extra": "^11.1.0"
22
22
  },
23
23
  "devDependencies": {
@@ -1,6 +1,7 @@
1
+ import { RoomDetail } from './../../src/lib/LiveRoom';
1
2
  import { MedalInfo, UserInfo } from "../..";
2
3
  import AcClient from "acfun-live-danmaku/client";
3
- import { LiveRoom, RoomStatsInfo, RoomViewInfo } from "../..";
4
+ import { LiveRoom, RoomStatsInfo } from "../..";
4
5
  declare type ZtLiveUserInfo = {
5
6
  userIdentity: {
6
7
  managerType?: number;
@@ -20,7 +21,7 @@ declare class acfunLive extends LiveRoom {
20
21
  /** 房间id */
21
22
  readonly id: number;
22
23
  /** 直播展示信息 */
23
- view: RoomViewInfo;
24
+ detail: RoomDetail;
24
25
  /** 直播数据信息 */
25
26
  stats: RoomStatsInfo;
26
27
  /** 主播信息 */
@@ -24,7 +24,7 @@ class acfunLive extends __1.LiveRoom {
24
24
  /** 平台id */
25
25
  this.platform = "acfun";
26
26
  /** 直播展示信息 */
27
- this.view = {
27
+ this.detail = {
28
28
  /** 直播标题 */
29
29
  title: "",
30
30
  /** 分区 */
@@ -60,18 +60,17 @@ class acfunLive extends __1.LiveRoom {
60
60
  get available() {
61
61
  return Boolean(this.client);
62
62
  }
63
- ;
64
63
  async getInfo() {
65
64
  if (!this.client) {
66
- this.client = await (0, acfun_live_danmaku_1.default)(this.id) || null;
65
+ this.client = (await (0, acfun_live_danmaku_1.default)(this.id)) || null;
67
66
  if (this.client) {
68
67
  this.status = __2.RoomStatus.live;
69
68
  this.timestamp = this.client.liveStartTime;
70
- this.view.title = this.client.caption; // bug
71
- this.view.cover = `https://tx2.a.kwimgs.com/bs2/ztlc/cover_${this.client.liveId}_raw.jpg`;
69
+ this.detail.title = this.client.caption; // bug
70
+ this.detail.cover = `https://tx2.a.kwimgs.com/bs2/ztlc/cover_${this.client.liveId}_raw.jpg`;
72
71
  }
73
72
  await fetch(`https://live.acfun.cn/rest/pc-direct/user/userInfo?userId=${this.id}`, {
74
- method: "GET"
73
+ method: "GET",
75
74
  })
76
75
  .then((response) => response.json())
77
76
  .then((res) => {
@@ -114,13 +113,26 @@ class acfunLive extends __1.LiveRoom {
114
113
  //收到的弹幕
115
114
  this.msg_Comment(danmaku);
116
115
  });
117
- client.on("Gift", (gift) => { this.msg_Gift(gift); });
118
- client.on("UserEnterRoom", (entry) => { this.msg_Interact(entry, "entry"); });
119
- client.on("Like", (like) => { this.msg_Interact(like, "like"); });
120
- // client.on("JoinClub", (join: any) => { this.msg_Interact(join, "join"); });
121
- client.on("DisplayInfo", (info) => { this.msg_DisplayInfo(info); });
122
- client.on("LiveClosed", (end) => { this.msg_LiveClosed(); });
123
- client.on("LiveBanned", (end) => { this.msg_LiveBanned(); });
116
+ client.on("Gift", (msg) => {
117
+ this.msg_Gift(msg);
118
+ });
119
+ client.on("UserEnterRoom", (msg) => {
120
+ this.msg_Interact(msg, "entry");
121
+ });
122
+ client.on("Like", (msg) => {
123
+ this.msg_Interact(msg, "like");
124
+ });
125
+ // client.on("UserFollowAuthor", (join: any) => { this.msg_Interact(msg, "follow"); });
126
+ // client.on("JoinClub", (msg: any) => { this.msg_Interact(msg, "join"); });
127
+ client.on("DisplayInfo", (msg) => {
128
+ this.msg_DisplayInfo(msg);
129
+ });
130
+ client.on("LiveClosed", (msg) => {
131
+ this.msg_LiveClosed();
132
+ });
133
+ client.on("LiveBanned", (msg) => {
134
+ this.msg_LiveBanned();
135
+ });
124
136
  this.wsInit = true;
125
137
  }
126
138
  /** 关闭直播间监听 */
@@ -135,7 +147,6 @@ class acfunLive extends __1.LiveRoom {
135
147
  this.close();
136
148
  this.removeAllListeners();
137
149
  }
138
- ;
139
150
  /** 根据守护徽章字符串获取粉丝牌信息 */
140
151
  getMedal(badge) {
141
152
  if (badge) {
@@ -163,32 +174,36 @@ class acfunLive extends __1.LiveRoom {
163
174
  id: parseInt(user.userId),
164
175
  medal: this.getMedal(user.badge),
165
176
  avatar: user.avatar[0].url,
166
- admin: identity
177
+ admin: identity,
167
178
  };
168
179
  }
169
180
  /** 文本信息(Comment) */
170
181
  msg_Comment(data) {
171
- let danmaku = {
182
+ const userInfo = this.getUser(data.userInfo);
183
+ let m = {
172
184
  platform: "acfun",
173
185
  room: this.id,
186
+ id: `${userInfo.id}-${data.sendTimeMs}`,
174
187
  timestamp: parseInt(data.sendTimeMs),
175
188
  type: "chat",
176
189
  info: {
177
190
  content: data.content,
178
- user: this.getUser(data.userInfo),
191
+ user: userInfo,
179
192
  },
180
193
  };
181
- this.emitMsg(danmaku);
194
+ this.emitMsg(m);
182
195
  }
183
196
  /** 礼物信息(Gift) */
184
197
  msg_Gift(data) {
185
- let gift = {
198
+ const userInfo = this.getUser(data.user);
199
+ let m = {
186
200
  platform: "acfun",
187
201
  room: this.id,
188
202
  type: "gift",
203
+ id: `${userInfo.id}-${data.sendTimeMs}`,
189
204
  timestamp: parseInt(data.sendTimeMs),
190
205
  info: {
191
- user: this.getUser(data.user),
206
+ user: userInfo,
192
207
  gift: {
193
208
  name: data.giftName,
194
209
  id: parseInt(data.giftId),
@@ -198,59 +213,67 @@ class acfunLive extends __1.LiveRoom {
198
213
  },
199
214
  },
200
215
  };
201
- this.emitMsg(gift);
216
+ this.emitMsg(m);
202
217
  }
203
218
  /** 互动信息 */
204
219
  msg_Interact(data, type) {
205
- let like = {
220
+ const userInfo = this.getUser(data.userInfo);
221
+ let m = {
206
222
  platform: "acfun",
207
223
  room: this.id,
208
224
  type: type,
225
+ id: `${userInfo.id}-${data.sendTimeMs}`,
209
226
  timestamp: parseInt(data.sendTimeMs),
210
227
  info: {
211
- user: this.getUser(data.userInfo),
228
+ user: userInfo,
212
229
  },
213
230
  };
214
- this.emitMsg(like);
231
+ this.emitMsg(m);
215
232
  }
216
233
  msg_LiveClosed() {
217
- let off = {
234
+ const timestamp = getDateTimestamp();
235
+ let m = {
218
236
  platform: "acfun",
219
237
  room: this.id,
220
238
  type: "live_end",
221
- timestamp: getDateTimestamp(),
239
+ id: `${timestamp}`,
240
+ timestamp: timestamp,
222
241
  info: {
223
- status: __2.RoomStatus.off
224
- }
242
+ status: __2.RoomStatus.off,
243
+ },
225
244
  };
226
245
  this.client = null;
227
- this.emitMsg(off);
246
+ this.emitMsg(m);
228
247
  }
229
248
  msg_LiveBanned() {
230
- let cut = {
249
+ const timestamp = getDateTimestamp();
250
+ let m = {
231
251
  platform: "acfun",
232
252
  room: this.id,
233
253
  type: "live_cut",
234
- timestamp: getDateTimestamp(),
254
+ id: `${timestamp}`,
255
+ timestamp: timestamp,
235
256
  info: {
236
- message: ""
237
- }
257
+ message: "",
258
+ },
238
259
  };
239
260
  this.client = null;
240
- this.emitMsg(cut);
261
+ this.emitMsg(m);
241
262
  }
242
263
  msg_DisplayInfo(data) {
243
- let stats = {
264
+ const timestamp = getDateTimestamp();
265
+ let m = {
244
266
  platform: "acfun",
245
267
  room: this.id,
246
268
  type: "live_stats",
247
- timestamp: getDateTimestamp(),
269
+ id: `${timestamp}`,
270
+ timestamp: timestamp,
248
271
  info: {
249
272
  like: stringToNumber(data.likeCount),
250
273
  online: stringToNumber(data.watchingCount),
251
- }
274
+ },
252
275
  };
253
- this.emitMsg(stats);
276
+ this.emitMsg(m);
254
277
  }
255
278
  }
256
279
  exports.default = acfunLive;
@@ -1,6 +1,6 @@
1
1
  import { UserInfo } from "../..";
2
2
  import { KeepLiveWS } from "bilibili-live-ws";
3
- import { LiveRoom, RoomStatsInfo, RoomViewInfo } from "../..";
3
+ import { LiveRoom, RoomStatsInfo, RoomDetail } from "../..";
4
4
  declare class bilibiliLive extends LiveRoom {
5
5
  /** 平台id */
6
6
  readonly platform: string;
@@ -8,8 +8,8 @@ declare class bilibiliLive extends LiveRoom {
8
8
  readonly id: number;
9
9
  /** 直播间room_id */
10
10
  roomid: number;
11
- /** 展示信息 */
12
- view: RoomViewInfo;
11
+ /** 房间信息 */
12
+ detail: RoomDetail;
13
13
  stats: RoomStatsInfo;
14
14
  /** 房间是否可用 */
15
15
  available: boolean;
@@ -27,7 +27,7 @@ declare class bilibiliLive extends LiveRoom {
27
27
  connectInterval: number;
28
28
  });
29
29
  /** 获取房间信息 */
30
- getInfo(refresh?: boolean): Promise<void>;
30
+ getInfo(): Promise<void>;
31
31
  /** 开启直播间监听 */
32
32
  open(): Promise<void>;
33
33
  /** 连接直播服务端 */
@@ -48,6 +48,7 @@ declare class bilibiliLive extends LiveRoom {
48
48
  msg_WATCHED_CHANGE(msg: any): void;
49
49
  /** 点赞数变化 */
50
50
  msg_LIKE_INFO_V3_UPDATE(msg: any): void;
51
+ msg_ONLINE_RANK_COUNT(msg: any): void;
51
52
  msg_ROOM_BLOCK_MSG(msg: any): void;
52
53
  msg_LIVE(msg: any): void;
53
54
  msg_CUT_OFF(msg: any): void;
@@ -8,6 +8,16 @@ const __2 = require("../..");
8
8
  function getDateTimestamp() {
9
9
  return Math.floor(Date.now() / 1000) * 1000;
10
10
  }
11
+ function getRoomStatus(s) {
12
+ switch (s) {
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
+ }
11
21
  class bilibiliLive extends __2.LiveRoom {
12
22
  constructor(id, // 房间id
13
23
  open = false, // 生成房间后是否打开
@@ -17,8 +27,8 @@ class bilibiliLive extends __2.LiveRoom {
17
27
  this.platform = "bilibili";
18
28
  /** 直播间room_id */
19
29
  this.roomid = 0;
20
- /** 展示信息 */
21
- this.view = {
30
+ /** 房间信息 */
31
+ this.detail = {
22
32
  /** 直播标题 */
23
33
  title: "",
24
34
  /** 分区 */
@@ -50,19 +60,24 @@ class bilibiliLive extends __2.LiveRoom {
50
60
  }
51
61
  }
52
62
  /** 获取房间信息 */
53
- async getInfo(refresh) {
63
+ async getInfo() {
54
64
  await fetch(`https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=${this.id}`, {
55
- method: "GET"
65
+ method: "GET",
56
66
  }) // 获取直播间信息
57
67
  .then((response) => response.json())
58
68
  .then((res) => {
59
69
  const { room_info, anchor_info, like_info_v3, watched_show } = res.data;
60
70
  this.roomid = room_info.room_id;
61
- this.status = room_info.live_status == 1 ? __1.RoomStatus.live : __1.RoomStatus.off;
62
- this.timestamp = this.status == __1.RoomStatus.live ? room_info.live_start_time * 1000 : refresh ? Date.now() : this.timestamp;
63
- this.view.title = room_info.title;
64
- this.view.area = [room_info.parent_area_name, room_info.area_name];
65
- this.view.cover = room_info.cover;
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;
66
81
  this.stats.watch = watched_show.num;
67
82
  this.stats.like = like_info_v3.total_likes;
68
83
  this.anchor.id = room_info.uid;
@@ -82,7 +97,7 @@ class bilibiliLive extends __2.LiveRoom {
82
97
  // 如果直播间监听已打开,则返回
83
98
  if (this.opening)
84
99
  return;
85
- await this.getInfo(true);
100
+ await this.getInfo();
86
101
  // 如果直播间不可用,则返回
87
102
  if (!this.available)
88
103
  return;
@@ -94,7 +109,7 @@ class bilibiliLive extends __2.LiveRoom {
94
109
  async createWS() {
95
110
  // 与Websocket服务器连接
96
111
  console.log("[bilibili-live-ws] 开始连接bilibili直播服务器");
97
- this.client = new bilibili_live_ws_1.KeepLiveWS(this.roomid);
112
+ this.client = new bilibili_live_ws_1.KeepLiveWS(this.roomid, { uid: this.anchor.id });
98
113
  let client = this.client;
99
114
  client.interval = this.connectInterval;
100
115
  client.on("open", () => {
@@ -125,6 +140,7 @@ class bilibiliLive extends __2.LiveRoom {
125
140
  client.on("ROOM_CHANGE", this.msg_ROOM_CHANGE.bind(this));
126
141
  client.on("WATCHED_CHANGE", this.msg_WATCHED_CHANGE.bind(this));
127
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));
128
144
  }
129
145
  /** 关闭直播间监听 */
130
146
  close() {
@@ -136,21 +152,24 @@ class bilibiliLive extends __2.LiveRoom {
136
152
  }
137
153
  /** 获取弹幕消息 */
138
154
  msg_DANMU_MSG(msg) {
139
- let content = msg.info[1];
140
- let mode = msg.info[0][1];
141
- let color = msg.info[0][3];
142
- let uname = msg.info[2][1];
143
- let uid = msg.info[2][0];
144
- let timestamp = msg.info[0][4];
145
- let guard_level = msg.info[7]; // 舰长级别
146
- let extra = JSON.parse(msg.info[0][15].extra);
147
- let medal = (msg.info[3].length) ? {
148
- level: msg.info[3][0],
149
- name: msg.info[3][1],
150
- // user: msg.info[3][2],
151
- id: msg.info[3][12],
152
- membership: msg.info[3][10] || 0,
153
- } : null;
155
+ const { info, msg_id } = msg;
156
+ let content = info[1];
157
+ let mode = info[0][1];
158
+ let color = info[0][3];
159
+ let uname = info[2][1];
160
+ let uid = info[2][0];
161
+ let timestamp = info[0][4];
162
+ let guard_level = info[7]; // 舰长级别
163
+ let extra = JSON.parse(info[0][15].extra);
164
+ let medal = info[3].length
165
+ ? {
166
+ level: info[3][0],
167
+ name: info[3][1],
168
+ // user: info[3][2],
169
+ id: info[3][12],
170
+ membership: info[3][10] || 0,
171
+ }
172
+ : null;
154
173
  let identity = null;
155
174
  let emoticon = undefined;
156
175
  if (extra.emots) {
@@ -164,7 +183,7 @@ class bilibiliLive extends __2.LiveRoom {
164
183
  };
165
184
  }
166
185
  }
167
- if (msg.info[2][2]) {
186
+ if (info[2][2]) {
168
187
  identity = __1.UserAdmin.admin;
169
188
  }
170
189
  else if (uid == this.anchor.id) {
@@ -175,16 +194,21 @@ class bilibiliLive extends __2.LiveRoom {
175
194
  room: this.id,
176
195
  type: "chat",
177
196
  timestamp: timestamp,
197
+ id: msg_id,
178
198
  info: {
179
199
  color: color,
180
200
  mode: mode,
181
201
  content: content,
182
- image: msg.info[0][12] ? {
183
- name: content,
184
- id: msg.info[0][13].emoticon_unique,
185
- url: msg.info[0][13].url,
186
- size: msg.info[0][13].width == msg.info[0][13].height ? __1.ImageSize.large : __1.ImageSize.small,
187
- } : undefined,
202
+ image: info[0][12]
203
+ ? {
204
+ name: content,
205
+ id: info[0][13].emoticon_unique,
206
+ url: info[0][13].url,
207
+ size: info[0][13].width == info[0][13].height
208
+ ? __1.ImageSize.large
209
+ : __1.ImageSize.small,
210
+ }
211
+ : undefined,
188
212
  emoticon: emoticon,
189
213
  user: {
190
214
  name: uname,
@@ -192,14 +216,14 @@ class bilibiliLive extends __2.LiveRoom {
192
216
  medal: medal,
193
217
  membership: guard_level,
194
218
  admin: identity,
195
- }
196
- }
219
+ },
220
+ },
197
221
  };
198
222
  this.emitMsg(danmaku);
199
223
  }
200
224
  /** 获取互动消息 */
201
225
  msg_INTERACT_WORD(msg) {
202
- const data = msg.data;
226
+ const { data, msg_id, send_time } = msg;
203
227
  let type;
204
228
  switch (data.msg_type) {
205
229
  case 1:
@@ -218,42 +242,48 @@ class bilibiliLive extends __2.LiveRoom {
218
242
  platform: "bilibili",
219
243
  room: this.id,
220
244
  type: type,
221
- timestamp: Math.floor(data.trigger_time / 1000000),
245
+ id: msg_id,
246
+ timestamp: send_time,
222
247
  info: {
223
248
  user: {
224
249
  name: data.uname,
225
250
  id: data.uid,
226
- medal: (data.fans_medal?.medal_level) ? {
227
- level: data.fans_medal.medal_level,
228
- name: data.fans_medal.medal_name,
229
- id: data.fans_medal.target_id,
230
- membership: data.fans_medal.guard_level,
231
- } : null
232
- }
251
+ medal: data.fans_medal?.medal_level
252
+ ? {
253
+ level: data.fans_medal.medal_level,
254
+ name: data.fans_medal.medal_name,
255
+ id: data.fans_medal.target_id,
256
+ membership: data.fans_medal.guard_level,
257
+ }
258
+ : null,
259
+ },
233
260
  },
234
261
  };
235
262
  this.emitMsg(interact);
236
263
  }
237
264
  /** 获取礼物消息 */
238
265
  msg_SEND_GIFT(msg) {
239
- const data = msg.data;
266
+ const { data, msg_id, send_time } = msg;
240
267
  let gift = {
241
268
  platform: "bilibili",
242
269
  room: this.id,
243
270
  type: "gift",
244
- timestamp: data.timestamp * 1000,
271
+ id: msg_id,
272
+ timestamp: send_time,
245
273
  info: {
246
274
  user: {
247
275
  name: data.uname,
248
276
  id: data.uid,
249
- medal: (data.fans_medal && data.fans_medal.medal_level) ? {
250
- level: data.fans_medal.medal_level,
251
- name: data.fans_medal.medal_name,
252
- id: data.fans_medal.target_id,
253
- membership: data.fans_medal.guard_level,
254
- } : null,
277
+ medal: data.fans_medal && data.fans_medal.medal_level
278
+ ? {
279
+ level: data.fans_medal.medal_level,
280
+ name: data.fans_medal.medal_name,
281
+ id: data.fans_medal.target_id,
282
+ membership: data.fans_medal.guard_level,
283
+ }
284
+ : null,
255
285
  membership: data.guard_level,
256
- avatar: data.face
286
+ avatar: data.face,
257
287
  },
258
288
  gift: {
259
289
  name: data.giftName,
@@ -262,20 +292,21 @@ class bilibiliLive extends __2.LiveRoom {
262
292
  value: data.total_coin,
263
293
  currency: data.coin_type,
264
294
  action: data.action,
265
- combo_id: data.batch_combo_id,
266
- }
295
+ comboId: data.batch_combo_id,
296
+ },
267
297
  },
268
298
  };
269
299
  this.emitMsg(gift);
270
300
  }
271
301
  /** 获取舰长开通消息 */
272
302
  msg_GUARD_BUY(msg) {
273
- const data = msg.data;
303
+ const { data, msg_id, send_time } = msg;
274
304
  let gift = {
275
305
  platform: "bilibili",
276
306
  room: this.id,
277
307
  type: "membership",
278
- timestamp: data.start_time * 1000,
308
+ id: msg_id,
309
+ timestamp: send_time,
279
310
  info: {
280
311
  user: {
281
312
  name: data.username,
@@ -298,24 +329,27 @@ class bilibiliLive extends __2.LiveRoom {
298
329
  }
299
330
  /** 获取醒目留言消息 */
300
331
  msg_SUPER_CHAT_MESSAGE(msg) {
301
- const data = msg.data;
332
+ const { data, msg_id, send_time } = msg;
302
333
  let sc = {
303
334
  platform: "bilibili",
304
335
  room: this.id,
305
336
  type: "superchat",
306
- timestamp: data.ts * 1000,
337
+ id: msg_id,
338
+ timestamp: send_time,
307
339
  info: {
308
340
  id: data.id,
309
341
  user: {
310
342
  name: data.user_info.uname,
311
343
  id: data.uid,
312
344
  avatar: data.user_info.face,
313
- medal: (data.medal_info && data.medal_info.medal_level) ? {
314
- level: data.medal_info.medal_level,
315
- name: data.medal_info.medal_name,
316
- id: data.medal_info.target_id,
317
- membership: data.medal_info.guard_level,
318
- } : null,
345
+ medal: data.medal_info && data.medal_info.medal_level
346
+ ? {
347
+ level: data.medal_info.medal_level,
348
+ name: data.medal_info.medal_name,
349
+ id: data.medal_info.target_id,
350
+ membership: data.medal_info.guard_level,
351
+ }
352
+ : null,
319
353
  membership: data.user_info.guard_level,
320
354
  },
321
355
  content: data.message,
@@ -327,67 +361,86 @@ class bilibiliLive extends __2.LiveRoom {
327
361
  num: data.gift.num,
328
362
  value: data.price * 1000,
329
363
  currency: "gold",
330
- }
364
+ },
331
365
  },
332
366
  };
333
367
  this.emitMsg(sc);
334
368
  }
335
369
  /** 观看数变化 */
336
370
  msg_WATCHED_CHANGE(msg) {
337
- const data = msg.data;
371
+ const { data, msg_id, send_time } = msg;
338
372
  const stats = {
339
373
  platform: "bilibili",
340
374
  room: this.id,
341
375
  type: "live_stats",
342
- timestamp: getDateTimestamp(),
376
+ id: msg_id,
377
+ timestamp: send_time,
343
378
  info: {
344
- watch: data.num
379
+ watch: data.num,
345
380
  },
346
381
  };
347
382
  this.emitMsg(stats);
348
383
  }
349
384
  /** 点赞数变化 */
350
385
  msg_LIKE_INFO_V3_UPDATE(msg) {
351
- const data = msg.data;
386
+ const { data, msg_id, send_time } = msg;
387
+ const stats = {
388
+ platform: "bilibili",
389
+ room: this.id,
390
+ type: "live_stats",
391
+ id: msg_id,
392
+ timestamp: send_time,
393
+ info: {
394
+ like: data.click_count,
395
+ },
396
+ };
397
+ this.emitMsg(stats);
398
+ }
399
+ msg_ONLINE_RANK_COUNT(msg) {
400
+ const { data, msg_id, send_time } = msg;
352
401
  const stats = {
353
402
  platform: "bilibili",
354
403
  room: this.id,
355
404
  type: "live_stats",
356
- timestamp: getDateTimestamp(),
405
+ id: msg_id,
406
+ timestamp: send_time,
357
407
  info: {
358
- like: data.click_count
408
+ online: data.count,
359
409
  },
360
410
  };
361
411
  this.emitMsg(stats);
362
412
  }
363
413
  msg_ROOM_BLOCK_MSG(msg) {
364
414
  // 禁言
365
- const data = msg.data;
415
+ const { data, msg_id, send_time } = msg;
366
416
  const block = {
367
417
  platform: "bilibili",
368
418
  room: this.id,
369
419
  type: "block",
370
- timestamp: getDateTimestamp(),
420
+ id: msg_id,
421
+ timestamp: send_time,
371
422
  info: {
372
423
  user: {
373
424
  id: data.uid,
374
- name: data.uname
425
+ name: data.uname,
375
426
  },
376
427
  operator: {
377
- admin: data.operator == 2 ? __1.UserAdmin.anchor : __1.UserAdmin.admin
378
- }
428
+ admin: data.operator == 2 ? __1.UserAdmin.anchor : __1.UserAdmin.admin,
429
+ },
379
430
  },
380
431
  };
381
432
  this.emitMsg(block);
382
433
  }
383
434
  msg_LIVE(msg) {
435
+ const { data, msg_id, send_time } = msg;
384
436
  // 直播间开播
385
437
  if (msg.live_time) {
386
438
  let live = {
387
439
  platform: "bilibili",
388
440
  room: this.id,
389
441
  type: "live_start",
390
- timestamp: msg.live_time * 1000,
442
+ id: msg_id,
443
+ timestamp: send_time,
391
444
  info: {
392
445
  id: msg.live_key.toString(),
393
446
  },
@@ -396,12 +449,14 @@ class bilibiliLive extends __2.LiveRoom {
396
449
  }
397
450
  }
398
451
  msg_CUT_OFF(msg) {
452
+ const { msg_id, send_time } = msg;
399
453
  // 直播间被切断
400
454
  let cut = {
401
455
  platform: "bilibili",
402
456
  room: this.id,
403
457
  type: "live_cut",
404
- timestamp: getDateTimestamp(),
458
+ id: msg_id,
459
+ timestamp: send_time,
405
460
  info: {
406
461
  message: msg.msg,
407
462
  },
@@ -409,27 +464,31 @@ class bilibiliLive extends __2.LiveRoom {
409
464
  this.emitMsg(cut);
410
465
  }
411
466
  msg_PREPARING(msg) {
467
+ const { msg_id, send_time } = msg;
412
468
  let off = {
413
469
  platform: "bilibili",
414
470
  room: this.id,
415
471
  type: "live_end",
416
- timestamp: getDateTimestamp(),
472
+ id: msg_id,
473
+ timestamp: send_time,
417
474
  info: {
418
- status: msg.round ? __1.RoomStatus.round : __1.RoomStatus.off
419
- }
475
+ status: msg.round ? __1.RoomStatus.round : __1.RoomStatus.off,
476
+ },
420
477
  };
421
478
  this.emitMsg(off);
422
479
  }
423
480
  msg_ROOM_CHANGE(msg) {
481
+ const { data, msg_id, send_time } = msg;
424
482
  let change = {
425
483
  platform: "bilibili",
426
484
  room: this.id,
427
- type: "live_view",
428
- timestamp: Date.now(),
485
+ type: "live_detail",
486
+ id: msg_id,
487
+ timestamp: send_time,
429
488
  info: {
430
- title: msg.data.title,
431
- area: [msg.data.parent_area_name, msg.data.area_name]
432
- }
489
+ title: data.title,
490
+ area: [data.parent_area_name, data.area_name],
491
+ },
433
492
  };
434
493
  this.emitMsg(change);
435
494
  }
@@ -10,7 +10,7 @@ export interface RoomInfo {
10
10
  /** 房间key */
11
11
  key: string;
12
12
  /** 基本信息 */
13
- view: RoomViewInfo;
13
+ detail: RoomDetail;
14
14
  /** 统计信息 */
15
15
  stats?: RoomStatsInfo;
16
16
  /** 主播信息 */
@@ -29,7 +29,7 @@ export interface RoomInfo {
29
29
  connected: boolean;
30
30
  }
31
31
  /** 房间展示信息 */
32
- export declare type RoomViewInfo = {
32
+ export declare type RoomDetail = {
33
33
  /** 直播标题 */
34
34
  title?: string;
35
35
  /** 分区 */
@@ -54,8 +54,8 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
54
54
  abstract readonly platform: string;
55
55
  /** 房间id */
56
56
  abstract readonly id: string | number;
57
- /** 基本信息 */
58
- abstract view: RoomViewInfo;
57
+ /** 房间详情 */
58
+ abstract detail: RoomDetail;
59
59
  /** 统计信息 */
60
60
  stats?: RoomStatsInfo;
61
61
  /** 主播信息 */
@@ -29,9 +29,9 @@ class LiveRoom extends events_1.EventEmitter {
29
29
  this.timestamp = msg.timestamp;
30
30
  this.emit("status", enum_1.RoomStatus.live, { timestamp: msg.timestamp, id: msg.info.id });
31
31
  break;
32
- case "live_view":
33
- this.view = Object.assign(this.view, msg.info);
34
- this.emit("view", msg.info);
32
+ case "live_detail":
33
+ this.detail = Object.assign(this.detail, msg.info);
34
+ this.emit("detail", msg.info);
35
35
  break;
36
36
  case "live_stats":
37
37
  this.stats = Object.assign(this.stats, msg.info);
@@ -55,7 +55,7 @@ class LiveRoom extends events_1.EventEmitter {
55
55
  return {
56
56
  platform: this.platform,
57
57
  id: this.id,
58
- view: this.view,
58
+ detail: this.detail,
59
59
  stats: this.stats,
60
60
  anchor: this.anchor,
61
61
  timestamp: this.timestamp,
@@ -53,8 +53,8 @@ class RoomController {
53
53
  this.main.emit("room_info", key, room.info);
54
54
  });
55
55
  // 直播展示信息更改
56
- room.on("view", (data) => {
57
- this.main.emit("room_view", key, data);
56
+ room.on("detail", (data) => {
57
+ this.main.emit("room_detail", key, data);
58
58
  });
59
59
  // 直播状态更改
60
60
  room.on("status", (status, { id, timestamp }) => {
package/src/tool.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { MessageData } from './types/message/MessageData';
2
+ export declare function generateKey(msg: MessageData): string;
package/src/tool.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateKey = void 0;
4
+ function generateKey(msg) {
5
+ switch (msg.type) {
6
+ case "gift":
7
+ return `gift:${msg.info.gift.comboId || `${msg.info.user.id}-${msg.timestamp}`}`;
8
+ case "superchat":
9
+ return `superchat:${msg.info.id}`;
10
+ case "membership":
11
+ return `membership:${msg.info.user.id}-${msg.info.level || 0}-${msg.timestamp}`;
12
+ default:
13
+ if (/^live_/.test(msg.type)) {
14
+ return `${msg.type}:${msg.platform}:${msg.room}-${msg.timestamp}`;
15
+ }
16
+ else {
17
+ return `${msg.type}:${msg.info.user?.id || 0}-${msg.timestamp}`;
18
+ }
19
+ }
20
+ }
21
+ exports.generateKey = generateKey;
@@ -55,13 +55,13 @@ export interface GiftInfo {
55
55
  /** 礼物连击数 */
56
56
  combo?: string;
57
57
  /** 礼物连击id */
58
- combo_id?: string;
58
+ comboId?: string;
59
59
  /** 人民币价值 */
60
60
  cny?: number;
61
61
  /** 行为 */
62
62
  action?: string;
63
63
  /** 随机礼物信息 */
64
- blind_gift?: GiftInfo;
64
+ blindGift?: GiftInfo;
65
65
  /** 图片信息 */
66
66
  image?: string;
67
67
  }
@@ -1,6 +1,6 @@
1
- import { RoomInfo } from './../../lib/LiveRoom';
2
- import { DanmakuMode, RoomStatus, UserAdmin } from '../../enum';
3
- import { RoomViewInfo, RoomStatsInfo } from "../../lib/LiveRoom";
1
+ import { RoomInfo } from "./../../lib/LiveRoom";
2
+ import { DanmakuMode, RoomStatus, UserAdmin } from "../../enum";
3
+ import { RoomDetail, RoomStatsInfo } from "../../lib/LiveRoom";
4
4
  import { UserInfo, GiftInfo, ImageInfo } from "./AttributeInfo";
5
5
  declare type MessageBase = {
6
6
  /** 平台名称 */
@@ -11,6 +11,8 @@ declare type MessageBase = {
11
11
  type: string;
12
12
  /** 时间戳 */
13
13
  timestamp: number;
14
+ /** 消息id */
15
+ id: string;
14
16
  /** 其他属性 */
15
17
  [attr: string]: any;
16
18
  };
@@ -28,7 +30,7 @@ export declare type MessageExt<T extends MessageInterface, E extends {
28
30
  info: E;
29
31
  };
30
32
  /** 文本聊天消息 */
31
- export declare type MessageChat = MessageBase & {
33
+ export interface MessageChat extends MessageBase {
32
34
  type: "chat";
33
35
  info: {
34
36
  /** 用户信息 */
@@ -50,9 +52,9 @@ export declare type MessageChat = MessageBase & {
50
52
  /** 标签信息 */
51
53
  tag?: string;
52
54
  };
53
- };
55
+ }
54
56
  /** 礼物消息 */
55
- export declare type MessageGift = MessageBase & {
57
+ export interface MessageGift extends MessageBase {
56
58
  type: "gift";
57
59
  info: {
58
60
  /** 用户信息 */
@@ -60,9 +62,9 @@ export declare type MessageGift = MessageBase & {
60
62
  /** 礼物信息 */
61
63
  gift: GiftInfo;
62
64
  };
63
- };
65
+ }
64
66
  /** 互动消息(进入直播间、点赞、关注、分享、加入粉丝团) */
65
- export declare type MessageInteract = MessageBase & {
67
+ export interface MessageInteract extends MessageBase {
66
68
  type: "entry" | "like" | "follow" | "share" | "join";
67
69
  info: {
68
70
  /** 用户信息 */
@@ -70,9 +72,9 @@ export declare type MessageInteract = MessageBase & {
70
72
  /** 信息标签 */
71
73
  tag?: string | boolean;
72
74
  };
73
- };
75
+ }
74
76
  /** 粉丝vip开通消息 */
75
- export declare type MessageMembership = MessageBase & {
77
+ export interface MessageMembership extends MessageBase {
76
78
  type: "membership";
77
79
  info: {
78
80
  /** 用户信息 */
@@ -86,13 +88,13 @@ export declare type MessageMembership = MessageBase & {
86
88
  /** 持续时间(天数) */
87
89
  duration: number;
88
90
  };
89
- };
91
+ }
90
92
  /** 粉丝vip开通消息 */
91
- export declare type MessageSuperchat = MessageBase & {
93
+ export interface MessageSuperchat extends MessageBase {
92
94
  type: "superchat";
93
95
  info: {
94
96
  /** 留言id */
95
- id?: string;
97
+ id: string;
96
98
  /** 用户信息 */
97
99
  user: UserInfo;
98
100
  /** 文本内容 */
@@ -104,9 +106,9 @@ export declare type MessageSuperchat = MessageBase & {
104
106
  /** (SC)持续时间 */
105
107
  duration: number;
106
108
  };
107
- };
109
+ }
108
110
  /** 禁言消息 */
109
- export declare type MessageBlock = MessageBase & {
111
+ export interface MessageBlock extends MessageBase {
110
112
  type: "block";
111
113
  info: {
112
114
  /** 用户信息 */
@@ -116,23 +118,23 @@ export declare type MessageBlock = MessageBase & {
116
118
  admin: null | UserAdmin;
117
119
  };
118
120
  };
119
- };
121
+ }
120
122
  /** 直播开播消息 */
121
- export declare type MessageLiveStart = MessageBase & {
123
+ export interface MessageLiveStart extends MessageBase {
122
124
  type: "live_start";
123
125
  info: {
124
126
  /** 直播id */
125
127
  id: string;
126
128
  };
127
- };
129
+ }
128
130
  /** 直播切断消息 */
129
- export declare type MessageLiveCut = MessageBase & {
131
+ export interface MessageLiveCut extends MessageBase {
130
132
  type: "live_cut";
131
133
  info: {
132
134
  /** 切断消息 */
133
135
  message: string;
134
136
  };
135
- };
137
+ }
136
138
  /** 获取房间信息 */
137
139
  export interface MessageRoomInfo extends MessageBase {
138
140
  type: "room_info";
@@ -140,24 +142,24 @@ export interface MessageRoomInfo extends MessageBase {
140
142
  info: RoomInfo;
141
143
  }
142
144
  /** 直播数据更新 */
143
- export declare type MessageLiveStats = MessageBase & {
145
+ export interface MessageLiveStats extends MessageBase {
144
146
  type: "live_stats";
145
147
  info: RoomStatsInfo;
146
- };
148
+ }
147
149
  /** 直播展示信息更新 */
148
- export declare type MessageLiveView = MessageBase & {
149
- type: "live_view";
150
- info: RoomViewInfo;
151
- };
150
+ export interface MessageLiveDetail extends MessageBase {
151
+ type: "live_detail";
152
+ info: RoomDetail;
153
+ }
152
154
  /** 直播结束 */
153
- export declare type MessageLiveEnd = MessageBase & {
155
+ export interface MessageLiveEnd extends MessageBase {
154
156
  type: "live_end";
155
157
  info: {
156
158
  /** 直播状态 */
157
159
  status: RoomStatus;
158
160
  };
159
- };
160
- declare type AllMessageType = MessageChat | MessageGift | MessageInteract | MessageMembership | MessageSuperchat | MessageBlock | MessageLiveStart | MessageLiveEnd | MessageLiveCut | MessageLiveView | MessageLiveStats;
161
+ }
162
+ declare type AllMessageType = MessageChat | MessageGift | MessageInteract | MessageMembership | MessageSuperchat | MessageBlock | MessageLiveStart | MessageLiveEnd | MessageLiveCut | MessageLiveDetail | MessageLiveStats;
161
163
  export declare type MessageData<T extends AllMessageType["type"] = AllMessageType["type"]> = AllMessageType & {
162
164
  type: T;
163
165
  };