floating-live 0.10.2 → 0.11.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 (40) hide show
  1. package/index.d.ts +2 -2
  2. package/index.js +2 -2
  3. package/package.json +2 -2
  4. package/plugin/acfun/acfunLive.d.ts +6 -3
  5. package/plugin/acfun/acfunLive.js +55 -26
  6. package/plugin/acfun/index.d.ts +3 -1
  7. package/plugin/acfun/index.js +8 -4
  8. package/plugin/bilibili/bilibiliLive.d.ts +10 -5
  9. package/plugin/bilibili/bilibiliLive.js +93 -65
  10. package/plugin/bilibili/index.d.ts +3 -1
  11. package/plugin/bilibili/index.js +8 -4
  12. package/plugin/chatPrint/chatPrint.js +4 -3
  13. package/plugin/chatPrint/index.d.ts +3 -1
  14. package/plugin/chatPrint/index.js +6 -2
  15. package/plugin/consoleEvent/index.d.ts +3 -1
  16. package/plugin/consoleEvent/index.js +6 -1
  17. package/plugin/msgSave/index.d.ts +7 -3
  18. package/plugin/msgSave/index.js +75 -20
  19. package/plugin/msgSave/msgSave.d.ts +75 -14
  20. package/plugin/msgSave/msgSave.js +130 -19
  21. package/src/enum.d.ts +34 -0
  22. package/src/enum.js +41 -0
  23. package/src/index.d.ts +3 -3
  24. package/src/index.js +9 -7
  25. package/src/lib/LiveRoom.d.ts +10 -9
  26. package/src/lib/LiveRoom.js +28 -27
  27. package/src/module/Command.d.ts +2 -1
  28. package/src/module/Command.js +3 -3
  29. package/src/module/Plugin.d.ts +4 -2
  30. package/src/module/Plugin.js +12 -4
  31. package/src/module/Room.js +7 -7
  32. package/src/types/index.d.ts +4 -0
  33. package/src/types/index.js +20 -0
  34. package/src/types/message/AttributeInfo.d.ts +5 -4
  35. package/src/types/message/MessageData.d.ts +20 -24
  36. package/src/types/plugin.d.ts +9 -0
  37. package/src/types/{room/PlatformInfo.d.ts → room.d.ts} +2 -0
  38. package/src/types/plugin/Plugin.d.ts +0 -5
  39. /package/src/types/{plugin/Plugin.js → plugin.js} +0 -0
  40. /package/src/types/{room/PlatformInfo.js → room.js} +0 -0
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { FloatingLive } from "./src";
2
2
  export * from "./src/types/message/AttributeInfo";
3
3
  export * from "./src/types/message/MessageData";
4
- export * from "./src/types/plugin/Plugin";
5
- export * from "./src/types/room/PlatformInfo";
4
+ export * from "./src/types/plugin";
5
+ export * from "./src/types/room";
6
6
  export * from "./src/lib/LiveRoom";
7
7
  export * from "./src/lib/Reglist";
package/index.js CHANGED
@@ -19,7 +19,7 @@ var src_1 = require("./src");
19
19
  Object.defineProperty(exports, "FloatingLive", { enumerable: true, get: function () { return src_1.FloatingLive; } });
20
20
  __exportStar(require("./src/types/message/AttributeInfo"), exports);
21
21
  __exportStar(require("./src/types/message/MessageData"), exports);
22
- __exportStar(require("./src/types/plugin/Plugin"), exports);
23
- __exportStar(require("./src/types/room/PlatformInfo"), exports);
22
+ __exportStar(require("./src/types/plugin"), exports);
23
+ __exportStar(require("./src/types/room"), exports);
24
24
  __exportStar(require("./src/lib/LiveRoom"), exports);
25
25
  __exportStar(require("./src/lib/Reglist"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.10.2",
3
+ "version": "0.11.0",
4
4
  "type": "commonjs",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "acfun-live-danmaku": "^0.6.1",
19
- "axios": "^1.2.3",
19
+ "axios": "^1.4.0",
20
20
  "bilibili-live-ws": "^6.0.3",
21
21
  "fs-extra": "^11.1.0"
22
22
  },
@@ -1,6 +1,6 @@
1
1
  import { MedalInfo, UserInfo } from "../../src/types/message/AttributeInfo";
2
2
  import AcClient from "acfun-live-danmaku/client";
3
- import { LiveRoom, RoomBaseInfo } from "../../src/lib/LiveRoom";
3
+ import { LiveRoom, RoomStatsInfo, RoomViewInfo } from "../../src/lib/LiveRoom";
4
4
  declare type ZtLiveUserInfo = {
5
5
  userIdentity: {
6
6
  managerType?: number;
@@ -19,8 +19,10 @@ declare class acfunLive extends LiveRoom {
19
19
  readonly platform: string;
20
20
  /** 房间id */
21
21
  readonly id: number;
22
- /** 直播信息 */
23
- base: RoomBaseInfo;
22
+ /** 直播展示信息 */
23
+ view: RoomViewInfo;
24
+ /** 直播数据信息 */
25
+ stats: RoomStatsInfo;
24
26
  /** 主播信息 */
25
27
  anchor: UserInfo;
26
28
  /** 直播间弹幕api模块 */
@@ -38,6 +40,7 @@ declare class acfunLive extends LiveRoom {
38
40
  open(): Promise<void>;
39
41
  /** 初始化直播服务端监听 */
40
42
  private initWS;
43
+ /** 关闭直播间监听 */
41
44
  close(): void;
42
45
  destory(): void;
43
46
  /** 根据守护徽章字符串获取粉丝牌信息 */
@@ -4,15 +4,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const acfun_live_danmaku_1 = __importDefault(require("acfun-live-danmaku"));
7
- const axios_1 = __importDefault(require("axios"));
8
7
  const LiveRoom_1 = require("../../src/lib/LiveRoom");
8
+ const enum_1 = require("../../src/enum");
9
+ // 获取当前时间戳,以替代无法从数据中获取时间戳的情况,精度为1s
10
+ function getDateTimestamp() {
11
+ return Math.floor(Date.now() / 1000) * 1000;
12
+ }
13
+ function stringToNumber(num) {
14
+ if (num.slice(-1) == "万") {
15
+ return Math.round(parseFloat(num) * 10000);
16
+ }
17
+ else {
18
+ return parseFloat(num);
19
+ }
20
+ }
9
21
  class acfunLive extends LiveRoom_1.LiveRoom {
10
22
  constructor(id, open = false) {
11
23
  super();
12
24
  /** 平台id */
13
25
  this.platform = "acfun";
14
- /** 直播信息 */
15
- this.base = {
26
+ /** 直播展示信息 */
27
+ this.view = {
16
28
  /** 直播标题 */
17
29
  title: "",
18
30
  /** 分区 */
@@ -20,6 +32,13 @@ class acfunLive extends LiveRoom_1.LiveRoom {
20
32
  /** 封面 */
21
33
  cover: "",
22
34
  };
35
+ /** 直播数据信息 */
36
+ this.stats = {
37
+ /** 点赞数 */
38
+ like: 0,
39
+ /** 在线观看数 */
40
+ online: 0,
41
+ };
23
42
  /** 主播信息 */
24
43
  this.anchor = { name: "", id: 0 };
25
44
  /** 直播间弹幕api模块 */
@@ -46,22 +65,24 @@ class acfunLive extends LiveRoom_1.LiveRoom {
46
65
  if (!this.client) {
47
66
  this.client = await (0, acfun_live_danmaku_1.default)(this.id) || null;
48
67
  if (this.client) {
49
- this.status = "live";
68
+ this.status = enum_1.RoomStatus.live;
50
69
  this.timestamp = this.client.liveStartTime;
51
- this.base.title = this.client.caption; // bug
52
- this.base.cover = `https://tx2.a.kwimgs.com/bs2/ztlc/cover_${this.client.liveId}_raw.jpg`;
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`;
53
72
  }
54
- await axios_1.default
55
- .get(`https://live.acfun.cn/rest/pc-direct/user/userInfo?userId=${this.id}`)
73
+ await fetch(`https://live.acfun.cn/rest/pc-direct/user/userInfo?userId=${this.id}`, {
74
+ method: "GET"
75
+ })
76
+ .then((response) => response.json())
56
77
  .then((res) => {
57
- let profile = res.data.profile;
58
- this.anchor.avatar = profile.headUrl;
59
- this.anchor.name = profile.name;
78
+ let { headUrl, name } = res.profile;
79
+ this.anchor.avatar = headUrl;
80
+ this.anchor.name = name;
81
+ this.emit("info");
60
82
  })
61
83
  .catch((error) => {
62
84
  console.error(error);
63
85
  });
64
- this.emit("info");
65
86
  }
66
87
  // 暂不能在连接房间后更新信息
67
88
  }
@@ -84,7 +105,7 @@ class acfunLive extends LiveRoom_1.LiveRoom {
84
105
  let client = this.client;
85
106
  client.on("EnterRoomAck", () => {
86
107
  console.log("[acfun-live-danmaku] 已连接AcFun直播间");
87
- this.status = "live";
108
+ this.status = enum_1.RoomStatus.live;
88
109
  });
89
110
  client.on("RecentComment", (comments) => {
90
111
  //当前弹幕列表
@@ -102,6 +123,7 @@ class acfunLive extends LiveRoom_1.LiveRoom {
102
123
  client.on("LiveBanned", (end) => { this.msg_LiveBanned(); });
103
124
  this.wsInit = true;
104
125
  }
126
+ /** 关闭直播间监听 */
105
127
  close() {
106
128
  if (!this.opening)
107
129
  return;
@@ -131,17 +153,17 @@ class acfunLive extends LiveRoom_1.LiveRoom {
131
153
  getUser(user) {
132
154
  let identity = null;
133
155
  if (user.userIdentity?.managerType == 1) {
134
- identity = "admin";
156
+ identity = enum_1.UserAdmin.admin;
135
157
  }
136
158
  else if (parseInt(user.userId) == this.anchor.id) {
137
- identity = "anchor";
159
+ identity = enum_1.UserAdmin.anchor;
138
160
  }
139
161
  return {
140
162
  name: user.nickname,
141
163
  id: parseInt(user.userId),
142
164
  medal: this.getMedal(user.badge),
143
165
  avatar: user.avatar[0].url,
144
- identity: identity
166
+ admin: identity
145
167
  };
146
168
  }
147
169
  /** 文本信息(Comment) */
@@ -149,12 +171,11 @@ class acfunLive extends LiveRoom_1.LiveRoom {
149
171
  let danmaku = {
150
172
  platform: "acfun",
151
173
  room: this.id,
152
- record_time: new Date().valueOf(),
174
+ timestamp: parseInt(data.sendTimeMs),
153
175
  type: "chat",
154
176
  info: {
155
177
  content: data.content,
156
178
  user: this.getUser(data.userInfo),
157
- timestamp: parseInt(data.sendTimeMs),
158
179
  },
159
180
  };
160
181
  this.emitMsg(danmaku);
@@ -165,7 +186,7 @@ class acfunLive extends LiveRoom_1.LiveRoom {
165
186
  platform: "acfun",
166
187
  room: this.id,
167
188
  type: "gift",
168
- record_time: new Date().valueOf(),
189
+ timestamp: parseInt(data.sendTimeMs),
169
190
  info: {
170
191
  user: this.getUser(data.user),
171
192
  gift: {
@@ -175,7 +196,6 @@ class acfunLive extends LiveRoom_1.LiveRoom {
175
196
  currency: data.giftId == "1" ? "banana" : "coin",
176
197
  value: parseInt(data.value), // 总价值
177
198
  },
178
- timestamp: parseInt(data.sendTimeMs),
179
199
  },
180
200
  };
181
201
  this.emitMsg(gift);
@@ -186,10 +206,9 @@ class acfunLive extends LiveRoom_1.LiveRoom {
186
206
  platform: "acfun",
187
207
  room: this.id,
188
208
  type: type,
189
- record_time: new Date().valueOf(),
209
+ timestamp: parseInt(data.sendTimeMs),
190
210
  info: {
191
211
  user: this.getUser(data.userInfo),
192
- timestamp: parseInt(data.sendTimeMs),
193
212
  },
194
213
  };
195
214
  this.emitMsg(like);
@@ -199,9 +218,9 @@ class acfunLive extends LiveRoom_1.LiveRoom {
199
218
  platform: "acfun",
200
219
  room: this.id,
201
220
  type: "live_end",
202
- record_time: new Date().valueOf(),
221
+ timestamp: getDateTimestamp(),
203
222
  info: {
204
- status: "off"
223
+ status: enum_1.RoomStatus.off
205
224
  }
206
225
  };
207
226
  this.client = null;
@@ -212,7 +231,7 @@ class acfunLive extends LiveRoom_1.LiveRoom {
212
231
  platform: "acfun",
213
232
  room: this.id,
214
233
  type: "live_cut",
215
- record_time: new Date().valueOf(),
234
+ timestamp: getDateTimestamp(),
216
235
  info: {
217
236
  message: ""
218
237
  }
@@ -221,7 +240,17 @@ class acfunLive extends LiveRoom_1.LiveRoom {
221
240
  this.emitMsg(cut);
222
241
  }
223
242
  msg_DisplayInfo(data) {
224
- //
243
+ let stats = {
244
+ platform: "acfun",
245
+ room: this.id,
246
+ type: "live_stats",
247
+ timestamp: getDateTimestamp(),
248
+ info: {
249
+ like: stringToNumber(data.likeCount),
250
+ online: stringToNumber(data.watchingCount),
251
+ }
252
+ };
253
+ this.emitMsg(stats);
225
254
  }
226
255
  }
227
256
  exports.default = acfunLive;
@@ -1,3 +1,5 @@
1
1
  import { FloatingLive } from "../../src/index";
2
- declare const _default: (ctx: FloatingLive) => void;
2
+ declare const _default: () => {
3
+ register: (ctx: FloatingLive) => void;
4
+ };
3
5
  export = _default;
@@ -3,8 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  const acfunLive_1 = __importDefault(require("./acfunLive"));
6
- module.exports = (ctx) => {
7
- ctx.helper.roomGenerator.register("acfun", (id, open) => {
8
- return new acfunLive_1.default(Number(id), open);
9
- });
6
+ module.exports = () => {
7
+ return {
8
+ register: (ctx) => {
9
+ ctx.helper.roomGenerator.register("acfun", (id, open) => {
10
+ return new acfunLive_1.default(Number(id), open);
11
+ });
12
+ }
13
+ };
10
14
  };
@@ -1,6 +1,6 @@
1
1
  import { UserInfo } from "../../src/types/message/AttributeInfo";
2
2
  import { KeepLiveWS } from "bilibili-live-ws";
3
- import { LiveRoom, RoomBaseInfo } from "../../src/lib/LiveRoom";
3
+ import { LiveRoom, RoomStatsInfo, RoomViewInfo } from "../../src/lib/LiveRoom";
4
4
  declare class bilibiliLive extends LiveRoom {
5
5
  /** 平台id */
6
6
  readonly platform: string;
@@ -8,8 +8,9 @@ declare class bilibiliLive extends LiveRoom {
8
8
  readonly id: number;
9
9
  /** 直播间room_id */
10
10
  roomid: number;
11
- /** 直播信息 */
12
- base: RoomBaseInfo;
11
+ /** 展示信息 */
12
+ view: RoomViewInfo;
13
+ stats: RoomStatsInfo;
13
14
  /** 房间是否可用 */
14
15
  available: boolean;
15
16
  /** 是否连接上房间 */
@@ -26,13 +27,13 @@ declare class bilibiliLive extends LiveRoom {
26
27
  connectInterval: number;
27
28
  });
28
29
  /** 获取房间信息 */
29
- getInfo(): Promise<void>;
30
+ getInfo(refresh?: boolean): Promise<void>;
30
31
  /** 开启直播间监听 */
31
32
  open(): Promise<void>;
32
33
  /** 连接直播服务端 */
33
34
  createWS(): Promise<void>;
35
+ /** 关闭直播间监听 */
34
36
  close(): void;
35
- getDanmakuMode(n: number): string;
36
37
  /** 获取弹幕消息 */
37
38
  msg_DANMU_MSG(msg: any): void;
38
39
  /** 获取互动消息 */
@@ -43,6 +44,10 @@ declare class bilibiliLive extends LiveRoom {
43
44
  msg_GUARD_BUY(msg: any): void;
44
45
  /** 获取醒目留言消息 */
45
46
  msg_SUPER_CHAT_MESSAGE(msg: any): void;
47
+ /** 观看数变化 */
48
+ msg_WATCHED_CHANGE(msg: any): void;
49
+ /** 点赞数变化 */
50
+ msg_LIKE_INFO_V3_UPDATE(msg: any): void;
46
51
  msg_ROOM_BLOCK_MSG(msg: any): void;
47
52
  msg_LIVE(msg: any): void;
48
53
  msg_CUT_OFF(msg: any): void;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const enum_1 = require("./../../src/enum");
6
4
  const bilibili_live_ws_1 = require("bilibili-live-ws");
7
- const axios_1 = __importDefault(require("axios"));
8
5
  const LiveRoom_1 = require("../../src/lib/LiveRoom");
6
+ // utils
7
+ // 获取当前时间戳,以替代无法从数据中获取时间戳的情况,精度为1s
8
+ function getDateTimestamp() {
9
+ return Math.floor(Date.now() / 1000) * 1000;
10
+ }
9
11
  class bilibiliLive extends LiveRoom_1.LiveRoom {
10
12
  constructor(id, // 房间id
11
13
  open = false, // 生成房间后是否打开
@@ -15,8 +17,8 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
15
17
  this.platform = "bilibili";
16
18
  /** 直播间room_id */
17
19
  this.roomid = 0;
18
- /** 直播信息 */
19
- this.base = {
20
+ /** 展示信息 */
21
+ this.view = {
20
22
  /** 直播标题 */
21
23
  title: "",
22
24
  /** 分区 */
@@ -24,6 +26,12 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
24
26
  /** 封面url */
25
27
  cover: "",
26
28
  };
29
+ this.stats = {
30
+ /** 观看数 */
31
+ watch: 0,
32
+ /** 点赞数 */
33
+ like: 0,
34
+ };
27
35
  /** 房间是否可用 */
28
36
  this.available = false;
29
37
  /** 是否连接上房间 */
@@ -42,20 +50,23 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
42
50
  }
43
51
  }
44
52
  /** 获取房间信息 */
45
- async getInfo() {
46
- await axios_1.default
47
- .get(`https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=${this.id}`) // 获取直播间信息
53
+ async getInfo(refresh) {
54
+ await fetch(`https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=${this.id}`, {
55
+ method: "GET"
56
+ }) // 获取直播间信息
57
+ .then((response) => response.json())
48
58
  .then((res) => {
49
- let data = res.data.data;
50
- this.roomid = data.room_info.room_id;
51
- this.status = data.room_info.live_status == 1 ? "live" : "off";
52
- this.timestamp = this.status == "live" ? data.room_info.live_start_time * 1000 : 0;
53
- this.base.title = data.room_info.title;
54
- this.base.area = [data.room_info.parent_area_name, data.room_info.area_name];
55
- this.base.cover = data.room_info.cover;
56
- this.anchor.id = data.room_info.uid;
57
- this.anchor.name = data.anchor_info.base_info.uname;
58
- this.anchor.avatar = data.anchor_info.base_info.face;
59
+ const { room_info, anchor_info } = res.data;
60
+ this.roomid = room_info.room_id;
61
+ this.status = room_info.live_status == 1 ? enum_1.RoomStatus.live : enum_1.RoomStatus.off;
62
+ this.timestamp = this.status == enum_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;
66
+ this.anchor.id = room_info.uid;
67
+ this.anchor.name = anchor_info.base_info.uname;
68
+ this.anchor.avatar = anchor_info.base_info.face;
69
+ this.liveId = room_info.live_id_str;
59
70
  this.available = true;
60
71
  console.log("[bilibiliLive] 已获取房间信息");
61
72
  this.emit("info", this.info);
@@ -66,9 +77,12 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
66
77
  }
67
78
  /** 开启直播间监听 */
68
79
  async open() {
69
- await this.getInfo();
70
- // 如果直播间监听已打开或直播间不可用,则返回
71
- if (this.opening || !this.available)
80
+ // 如果直播间监听已打开,则返回
81
+ if (this.opening)
82
+ return;
83
+ await this.getInfo(true);
84
+ // 如果直播间不可用,则返回
85
+ if (!this.available)
72
86
  return;
73
87
  this.opening = true;
74
88
  this.createWS();
@@ -107,7 +121,10 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
107
121
  client.on("PREPARING", this.msg_PREPARING.bind(this));
108
122
  client.on("LIVE", this.msg_LIVE.bind(this));
109
123
  client.on("ROOM_CHANGE", this.msg_ROOM_CHANGE.bind(this));
124
+ client.on("WATCHED_CHANGE", this.msg_WATCHED_CHANGE.bind(this));
125
+ client.on("LIKE_INFO_V3_UPDATE", this.msg_LIKE_INFO_V3_UPDATE.bind(this));
110
126
  }
127
+ /** 关闭直播间监听 */
111
128
  close() {
112
129
  if (!this.opening)
113
130
  return;
@@ -115,22 +132,10 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
115
132
  this.client?.close();
116
133
  this.emit("close");
117
134
  }
118
- getDanmakuMode(n) {
119
- switch (n) {
120
- case 1:
121
- return "left";
122
- case 4:
123
- return "bottom";
124
- case 5:
125
- return "top";
126
- default:
127
- return "left";
128
- }
129
- }
130
135
  /** 获取弹幕消息 */
131
136
  msg_DANMU_MSG(msg) {
132
137
  let content = msg.info[1];
133
- let mode = this.getDanmakuMode(msg.info[0][1]);
138
+ let mode = msg.info[0][1];
134
139
  let color = msg.info[0][3];
135
140
  let uname = msg.info[2][1];
136
141
  let uid = msg.info[2][0];
@@ -158,18 +163,17 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
158
163
  }
159
164
  }
160
165
  if (msg.info[2][2]) {
161
- identity = "admin";
166
+ identity = enum_1.UserAdmin.admin;
162
167
  }
163
168
  else if (uid == this.anchor.id) {
164
- identity = "anchor";
169
+ identity = enum_1.UserAdmin.anchor;
165
170
  }
166
171
  let danmaku = {
167
172
  platform: "bilibili",
168
173
  room: this.id,
169
174
  type: "chat",
170
- record_time: new Date().valueOf(),
175
+ timestamp: timestamp,
171
176
  info: {
172
- timestamp: timestamp,
173
177
  color: color,
174
178
  mode: mode,
175
179
  content: content,
@@ -177,7 +181,7 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
177
181
  name: content,
178
182
  id: msg.info[0][13].emoticon_unique,
179
183
  url: msg.info[0][13].url,
180
- height: msg.info[0][13].height / 3,
184
+ size: msg.info[0][13].width == msg.info[0][13].height ? enum_1.ImageSize.large : enum_1.ImageSize.small,
181
185
  } : undefined,
182
186
  emoticon: emoticon,
183
187
  user: {
@@ -185,7 +189,7 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
185
189
  id: uid,
186
190
  medal: medal,
187
191
  membership: guard_level,
188
- identity: identity,
192
+ admin: identity,
189
193
  }
190
194
  }
191
195
  };
@@ -193,7 +197,7 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
193
197
  }
194
198
  /** 获取互动消息 */
195
199
  msg_INTERACT_WORD(msg) {
196
- let data = msg.data;
200
+ const data = msg.data;
197
201
  let type;
198
202
  switch (data.msg_type) {
199
203
  case 1:
@@ -212,13 +216,12 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
212
216
  platform: "bilibili",
213
217
  room: this.id,
214
218
  type: type,
215
- record_time: new Date().valueOf(),
219
+ timestamp: Math.floor(data.trigger_time / 1000000),
216
220
  info: {
217
- timestamp: Math.floor(data.trigger_time / 1000000),
218
221
  user: {
219
222
  name: data.uname,
220
223
  id: data.uid,
221
- medal: (data.fans_medal && data.fans_medal.medal_level) ? {
224
+ medal: (data.fans_medal?.medal_level) ? {
222
225
  level: data.fans_medal.medal_level,
223
226
  name: data.fans_medal.medal_name,
224
227
  id: data.fans_medal.target_id,
@@ -231,14 +234,13 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
231
234
  }
232
235
  /** 获取礼物消息 */
233
236
  msg_SEND_GIFT(msg) {
234
- let data = msg.data;
237
+ const data = msg.data;
235
238
  let gift = {
236
239
  platform: "bilibili",
237
240
  room: this.id,
238
241
  type: "gift",
239
- record_time: new Date().valueOf(),
242
+ timestamp: data.timestamp * 1000,
240
243
  info: {
241
- timestamp: data.timestamp * 1000,
242
244
  user: {
243
245
  name: data.uname,
244
246
  id: data.uid,
@@ -266,14 +268,13 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
266
268
  }
267
269
  /** 获取舰长开通消息 */
268
270
  msg_GUARD_BUY(msg) {
269
- let data = msg.data;
271
+ const data = msg.data;
270
272
  let gift = {
271
273
  platform: "bilibili",
272
274
  room: this.id,
273
275
  type: "membership",
274
- record_time: new Date().valueOf(),
276
+ timestamp: data.start_time * 1000,
275
277
  info: {
276
- timestamp: data.start_time * 1000,
277
278
  user: {
278
279
  name: data.username,
279
280
  id: data.uid,
@@ -295,15 +296,14 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
295
296
  }
296
297
  /** 获取醒目留言消息 */
297
298
  msg_SUPER_CHAT_MESSAGE(msg) {
298
- let data = msg.data;
299
+ const data = msg.data;
299
300
  let sc = {
300
301
  platform: "bilibili",
301
302
  room: this.id,
302
303
  type: "superchat",
303
- record_time: new Date().valueOf(),
304
+ timestamp: data.ts * 1000,
304
305
  info: {
305
306
  id: data.id,
306
- timestamp: data.ts * 1000,
307
307
  user: {
308
308
  name: data.user_info.uname,
309
309
  id: data.uid,
@@ -330,21 +330,49 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
330
330
  };
331
331
  this.emitMsg(sc);
332
332
  }
333
+ /** 观看数变化 */
334
+ msg_WATCHED_CHANGE(msg) {
335
+ const data = msg.data;
336
+ const stats = {
337
+ platform: "bilibili",
338
+ room: this.id,
339
+ type: "live_stats",
340
+ timestamp: getDateTimestamp(),
341
+ info: {
342
+ watch: data.num
343
+ },
344
+ };
345
+ this.emitMsg(stats);
346
+ }
347
+ /** 点赞数变化 */
348
+ msg_LIKE_INFO_V3_UPDATE(msg) {
349
+ const data = msg.data;
350
+ const stats = {
351
+ platform: "bilibili",
352
+ room: this.id,
353
+ type: "live_stats",
354
+ timestamp: getDateTimestamp(),
355
+ info: {
356
+ like: data.click_count
357
+ },
358
+ };
359
+ this.emitMsg(stats);
360
+ }
333
361
  msg_ROOM_BLOCK_MSG(msg) {
334
362
  // 禁言
335
- let data = msg.data;
336
- let block = {
363
+ const data = msg.data;
364
+ const block = {
337
365
  platform: "bilibili",
338
366
  room: this.id,
339
367
  type: "block",
340
- record_time: new Date().valueOf(),
368
+ timestamp: getDateTimestamp(),
341
369
  info: {
342
370
  user: {
343
371
  id: data.uid,
344
372
  name: data.uname
345
373
  },
346
374
  operator: {
347
- identity: data.operator == 2 ? "anchor" : "admin"
375
+ admin: data.operator == 2 ? enum_1.UserAdmin.anchor : enum_1.UserAdmin.admin
348
376
  }
349
377
  },
350
378
  };
@@ -357,9 +385,9 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
357
385
  platform: "bilibili",
358
386
  room: this.id,
359
387
  type: "live_start",
360
- record_time: new Date().valueOf(),
388
+ timestamp: msg.live_time * 1000,
361
389
  info: {
362
- timestamp: msg.live_time * 1000,
390
+ id: msg.live_key.toString(),
363
391
  },
364
392
  };
365
393
  this.emitMsg(live);
@@ -371,7 +399,7 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
371
399
  platform: "bilibili",
372
400
  room: this.id,
373
401
  type: "live_cut",
374
- record_time: new Date().valueOf(),
402
+ timestamp: getDateTimestamp(),
375
403
  info: {
376
404
  message: msg.msg,
377
405
  },
@@ -383,9 +411,9 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
383
411
  platform: "bilibili",
384
412
  room: this.id,
385
413
  type: "live_end",
386
- record_time: new Date().valueOf(),
414
+ timestamp: getDateTimestamp(),
387
415
  info: {
388
- status: msg.round ? "round" : "off"
416
+ status: msg.round ? enum_1.RoomStatus.round : enum_1.RoomStatus.off
389
417
  }
390
418
  };
391
419
  this.emitMsg(off);
@@ -394,8 +422,8 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
394
422
  let change = {
395
423
  platform: "bilibili",
396
424
  room: this.id,
397
- type: "live_change",
398
- record_time: new Date().valueOf(),
425
+ type: "live_view",
426
+ timestamp: Date.now(),
399
427
  info: {
400
428
  title: msg.data.title,
401
429
  area: [msg.data.parent_area_name, msg.data.area_name]