floating-live 0.10.1 → 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 +56 -27
  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.1",
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
  //当前弹幕列表
@@ -96,12 +117,13 @@ class acfunLive extends LiveRoom_1.LiveRoom {
96
117
  client.on("Gift", (gift) => { this.msg_Gift(gift); });
97
118
  client.on("UserEnterRoom", (entry) => { this.msg_Interact(entry, "entry"); });
98
119
  client.on("Like", (like) => { this.msg_Interact(like, "like"); });
99
- client.on("JoinClub", (join) => { this.msg_Interact(join, "join"); });
120
+ // client.on("JoinClub", (join: any) => { this.msg_Interact(join, "join"); });
100
121
  client.on("DisplayInfo", (info) => { this.msg_DisplayInfo(info); });
101
122
  client.on("LiveClosed", (end) => { this.msg_LiveClosed(); });
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;