floating-live 0.8.7 → 0.10.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 (56) hide show
  1. package/README.md +6 -4
  2. package/index.d.ts +7 -2
  3. package/index.js +23 -4
  4. package/package.json +1 -1
  5. package/plugin/acfun/acfunLive.d.ts +24 -30
  6. package/plugin/acfun/acfunLive.js +38 -51
  7. package/plugin/acfun/index.d.ts +1 -1
  8. package/plugin/acfun/index.js +1 -3
  9. package/plugin/bilibili/bilibiliLive.d.ts +7 -15
  10. package/plugin/bilibili/bilibiliLive.js +86 -117
  11. package/plugin/bilibili/index.d.ts +1 -1
  12. package/plugin/bilibili/index.js +1 -3
  13. package/plugin/chatPrint/chatPrint.d.ts +6 -7
  14. package/plugin/chatPrint/chatPrint.js +12 -18
  15. package/plugin/chatPrint/index.d.ts +2 -2
  16. package/plugin/chatPrint/index.js +2 -5
  17. package/plugin/consoleEvent/index.d.ts +1 -1
  18. package/plugin/consoleEvent/index.js +14 -2
  19. package/plugin/msgSave/index.d.ts +1 -1
  20. package/plugin/msgSave/index.js +6 -6
  21. package/plugin/msgSave/msgSave.d.ts +3 -3
  22. package/src/index.d.ts +51 -25
  23. package/src/index.js +98 -41
  24. package/src/lib/LiveRoom.d.ts +88 -0
  25. package/src/lib/LiveRoom.js +72 -0
  26. package/src/lib/{Registerable.d.ts → Reglist.d.ts} +6 -8
  27. package/src/lib/{Registerable.js → Reglist.js} +13 -19
  28. package/src/module/Command.d.ts +2 -0
  29. package/src/{types/room/RoomInfo.js → module/Command.js} +4 -0
  30. package/src/module/Plugin.d.ts +24 -0
  31. package/src/module/Plugin.js +74 -0
  32. package/src/{controller → module}/Room.d.ts +7 -13
  33. package/src/{controller → module}/Room.js +24 -16
  34. package/src/types/message/AttributeInfo.d.ts +8 -6
  35. package/src/types/message/MessageData.d.ts +132 -44
  36. package/src/types/plugin/Plugin.d.ts +4 -2
  37. package/src/types/room/PlatformInfo.d.ts +1 -1
  38. package/plugin/chat/ChatCommand.d.ts +0 -9
  39. package/plugin/chat/ChatCommand.js +0 -39
  40. package/plugin/chat/ChatFilter.d.ts +0 -9
  41. package/plugin/chat/ChatFilter.js +0 -44
  42. package/plugin/chat/chatProcessor.d.ts +0 -12
  43. package/plugin/chat/chatProcessor.js +0 -24
  44. package/src/controller/Message.d.ts +0 -9
  45. package/src/controller/Message.js +0 -15
  46. package/src/controller/index.d.ts +0 -39
  47. package/src/controller/index.js +0 -74
  48. package/src/types/message/MessageInfo.d.ts +0 -123
  49. package/src/types/message/MessageInfo.js +0 -2
  50. package/src/types/room/LiveInfo.d.ts +0 -24
  51. package/src/types/room/LiveInfo.js +0 -2
  52. package/src/types/room/LiveRoom.d.ts +0 -20
  53. package/src/types/room/LiveRoom.js +0 -2
  54. package/src/types/room/RoomInfo.d.ts +0 -16
  55. package/src/utils/getRoomInfo.d.ts +0 -4
  56. package/src/utils/getRoomInfo.js +0 -25
package/README.md CHANGED
@@ -7,6 +7,8 @@
7
7
 
8
8
  注意:当前项目未进入正式版本阶段,程序结构及导出数据结构可能随时改动,**非常不建议用于正式项目中**。
9
9
 
10
+ GUI版本:[Minteea/floating-live-gui](https://github.com/Minteea/floating-live-gui)
11
+
10
12
  ## 使用方法
11
13
  ### npm安装
12
14
  ```
@@ -14,18 +16,18 @@ npm install floating-live
14
16
  ```
15
17
  ``` javascript
16
18
  // 导入FloatingLive
17
- const FloatingLive = require("floating-live")
19
+ const { FloatingLive } = require("floating-live")
18
20
  // 导入bilibili房间生成插件
19
21
  const bilibili = require("floating-live/plugin/bilibili")
20
22
 
21
23
  // 创建一个FloatingLive实例
22
24
  const live = new FloatingLive()
23
25
  // 注册插件
24
- live.registerPlugin("bilibili", bilibili)
26
+ live.plugin.register("bilibili", bilibili)
25
27
  // 添加房间
26
- live.controller.addRoom({platform: "bilibili", id: 6})
28
+ live.addRoom({platform: "bilibili", id: 6})
27
29
  // 打开
28
- live.controller.start()
30
+ live.start()
29
31
  ```
30
32
 
31
33
  ### 拆包即用模式
package/index.d.ts CHANGED
@@ -1,2 +1,7 @@
1
- import FloatingLiving from "./src";
2
- export = FloatingLiving;
1
+ export { FloatingLive } from "./src";
2
+ export * from "./src/types/message/AttributeInfo";
3
+ export * from "./src/types/message/MessageData";
4
+ export * from "./src/types/plugin/Plugin";
5
+ export * from "./src/types/room/PlatformInfo";
6
+ export * from "./src/lib/LiveRoom";
7
+ export * from "./src/lib/Reglist";
package/index.js CHANGED
@@ -1,6 +1,25 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4
15
  };
5
- const src_1 = __importDefault(require("./src"));
6
- module.exports = src_1.default;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.FloatingLive = void 0;
18
+ var src_1 = require("./src");
19
+ Object.defineProperty(exports, "FloatingLive", { enumerable: true, get: function () { return src_1.FloatingLive; } });
20
+ __exportStar(require("./src/types/message/AttributeInfo"), exports);
21
+ __exportStar(require("./src/types/message/MessageData"), exports);
22
+ __exportStar(require("./src/types/plugin/Plugin"), exports);
23
+ __exportStar(require("./src/types/room/PlatformInfo"), exports);
24
+ __exportStar(require("./src/lib/LiveRoom"), exports);
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.8.7",
3
+ "version": "0.10.0",
4
4
  "type": "commonjs",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,23 +1,34 @@
1
- /// <reference types="node" />
2
1
  import { MedalInfo, UserInfo } from "../../src/types/message/AttributeInfo";
3
- import LiveRoom from "../../src/types/room/LiveRoom";
4
2
  import AcClient from "acfun-live-danmaku/client";
5
- import { EventEmitter } from "events";
6
- import { LiveInfo } from "../../src/types/room/LiveInfo";
7
- import { MessageType } from "../../src/types/message/MessageData";
8
- declare class acfunLive extends EventEmitter implements LiveRoom {
3
+ import { LiveRoom, RoomBaseInfo } from "../../src/lib/LiveRoom";
4
+ declare type ZtLiveUserInfo = {
5
+ userIdentity: {
6
+ managerType?: number;
7
+ };
8
+ badge?: string;
9
+ nickname: string;
10
+ userId: string;
11
+ avatar: [
12
+ {
13
+ url: string;
14
+ }
15
+ ];
16
+ };
17
+ declare class acfunLive extends LiveRoom {
9
18
  /** 平台id */
10
19
  readonly platform: string;
11
20
  /** 房间id */
12
21
  readonly id: number;
13
22
  /** 直播信息 */
14
- live: LiveInfo;
23
+ base: RoomBaseInfo;
15
24
  /** 主播信息 */
16
25
  anchor: UserInfo;
17
26
  /** 直播间弹幕api模块 */
18
27
  client: AcClient | null;
19
28
  /** 是否为打开状态 */
20
29
  opening: boolean;
30
+ /** 是否连接上服务器 */
31
+ connected: boolean;
21
32
  private wsInit;
22
33
  /** 直播间是否可用 */
23
34
  get available(): boolean;
@@ -30,47 +41,30 @@ declare class acfunLive extends EventEmitter implements LiveRoom {
30
41
  close(): void;
31
42
  destory(): void;
32
43
  /** 根据守护徽章字符串获取粉丝牌信息 */
33
- getMedal(badge: string): MedalInfo | null;
44
+ getMedal(badge?: string): MedalInfo | null;
45
+ getUser(user: ZtLiveUserInfo): UserInfo;
34
46
  /** 文本信息(Comment) */
35
47
  msg_Comment(data: {
36
48
  sendTimeMs: string;
37
- userInfo: {
38
- userIdentity: any;
39
- badge: string;
40
- nickname: any;
41
- userId: string;
42
- };
49
+ userInfo: ZtLiveUserInfo;
43
50
  content: any;
44
51
  }): void;
45
52
  /** 礼物信息(Gift) */
46
53
  msg_Gift(data: {
47
54
  sendTimeMs: string;
48
- user: {
49
- userIdentity: any;
50
- badge: string;
51
- nickname: any;
52
- userId: string;
53
- };
55
+ user: ZtLiveUserInfo;
54
56
  giftName: any;
55
57
  giftId: string;
56
- count: any;
58
+ count: number;
57
59
  value: string;
58
60
  }): void;
59
61
  /** 互动信息 */
60
62
  msg_Interact(data: {
61
63
  sendTimeMs: string;
62
- userInfo: {
63
- userIdentity: any;
64
- badge: string;
65
- nickname: any;
66
- userId: string;
67
- };
64
+ userInfo: ZtLiveUserInfo;
68
65
  }, type: "entry" | "like" | "follow" | "share" | "join"): void;
69
66
  msg_LiveClosed(): void;
70
67
  msg_LiveBanned(): void;
71
68
  msg_DisplayInfo(data: any): void;
72
- emitMsg(data: MessageType): void;
73
- emitOrigin(data: any): void;
74
- emitChange(data: Partial<LiveInfo>): void;
75
69
  }
76
70
  export default acfunLive;
@@ -4,25 +4,21 @@ 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 events_1 = require("events");
8
7
  const axios_1 = __importDefault(require("axios"));
9
- class acfunLive extends events_1.EventEmitter {
8
+ const LiveRoom_1 = require("../../src/lib/LiveRoom");
9
+ class acfunLive extends LiveRoom_1.LiveRoom {
10
10
  constructor(id, open = false) {
11
11
  super();
12
12
  /** 平台id */
13
13
  this.platform = "acfun";
14
14
  /** 直播信息 */
15
- this.live = {
15
+ this.base = {
16
16
  /** 直播标题 */
17
17
  title: "",
18
18
  /** 分区 */
19
19
  area: [],
20
20
  /** 封面 */
21
21
  cover: "",
22
- /** 直播状态 */
23
- status: "off",
24
- /** 开始直播时间 */
25
- start_time: 0
26
22
  };
27
23
  /** 主播信息 */
28
24
  this.anchor = { name: "", id: 0 };
@@ -30,6 +26,8 @@ class acfunLive extends events_1.EventEmitter {
30
26
  this.client = null;
31
27
  /** 是否为打开状态 */
32
28
  this.opening = false;
29
+ /** 是否连接上服务器 */
30
+ this.connected = false;
33
31
  this.wsInit = false;
34
32
  this.platform = "acfun";
35
33
  this.id = id; // 直播间号
@@ -49,10 +47,10 @@ class acfunLive extends events_1.EventEmitter {
49
47
  if (!this.client) {
50
48
  this.client = await (0, acfun_live_danmaku_1.default)(this.id) || null;
51
49
  if (this.client) {
52
- this.live.status = "live";
53
- this.live.start_time = this.client.liveStartTime;
54
- this.live.title = this.client.caption; // bug
55
- this.live.cover = `https://tx2.a.kwimgs.com/bs2/ztlc/cover_${this.client.liveId}_raw.jpg`;
50
+ this.status = "live";
51
+ this.timestamp = this.client.liveStartTime;
52
+ this.base.title = this.client.caption; // bug
53
+ this.base.cover = `https://tx2.a.kwimgs.com/bs2/ztlc/cover_${this.client.liveId}_raw.jpg`;
56
54
  }
57
55
  await axios_1.default
58
56
  .get(`https://live.acfun.cn/rest/pc-direct/user/userInfo?userId=${this.id}`)
@@ -87,7 +85,7 @@ class acfunLive extends events_1.EventEmitter {
87
85
  let client = this.client;
88
86
  client.on("EnterRoomAck", () => {
89
87
  console.log("[acfun-live-danmaku] 已连接AcFun直播间");
90
- this.live.status = "live";
88
+ this.status = "live";
91
89
  });
92
90
  client.on("RecentComment", (comments) => {
93
91
  //当前弹幕列表
@@ -131,20 +129,32 @@ class acfunLive extends events_1.EventEmitter {
131
129
  return null;
132
130
  }
133
131
  }
132
+ getUser(user) {
133
+ let identity = null;
134
+ if (user.userIdentity?.managerType == 1) {
135
+ identity = "admin";
136
+ }
137
+ else if (parseInt(user.userId) == this.anchor.id) {
138
+ identity = "anchor";
139
+ }
140
+ return {
141
+ name: user.nickname,
142
+ id: parseInt(user.userId),
143
+ medal: this.getMedal(user.badge),
144
+ avatar: user.avatar[0].url,
145
+ identity: identity
146
+ };
147
+ }
134
148
  /** 文本信息(Comment) */
135
149
  msg_Comment(data) {
136
150
  let danmaku = {
137
151
  platform: "acfun",
138
152
  room: this.id,
139
- local_timestamp: new Date().valueOf(),
140
- type: "text",
153
+ record_time: new Date().valueOf(),
154
+ type: "chat",
141
155
  info: {
142
- text: data.content,
143
- user: {
144
- name: data.userInfo.nickname,
145
- id: parseInt(data.userInfo.userId),
146
- medal: this.getMedal(data.userInfo.badge),
147
- },
156
+ content: data.content,
157
+ user: this.getUser(data.userInfo),
148
158
  timestamp: parseInt(data.sendTimeMs),
149
159
  },
150
160
  };
@@ -156,18 +166,14 @@ class acfunLive extends events_1.EventEmitter {
156
166
  platform: "acfun",
157
167
  room: this.id,
158
168
  type: "gift",
159
- local_timestamp: new Date().valueOf(),
169
+ record_time: new Date().valueOf(),
160
170
  info: {
161
- user: {
162
- name: data.user.nickname,
163
- id: parseInt(data.user.userId),
164
- medal: this.getMedal(data.user.badge),
165
- },
171
+ user: this.getUser(data.user),
166
172
  gift: {
167
173
  name: data.giftName,
168
174
  id: parseInt(data.giftId),
169
175
  num: data.count,
170
- currency: "coin",
176
+ currency: data.giftId == "1" ? "banana" : "coin",
171
177
  value: parseInt(data.value), // 总价值
172
178
  },
173
179
  timestamp: parseInt(data.sendTimeMs),
@@ -181,13 +187,9 @@ class acfunLive extends events_1.EventEmitter {
181
187
  platform: "acfun",
182
188
  room: this.id,
183
189
  type: type,
184
- local_timestamp: new Date().valueOf(),
190
+ record_time: new Date().valueOf(),
185
191
  info: {
186
- user: {
187
- name: data.userInfo.nickname,
188
- id: parseInt(data.userInfo.userId),
189
- medal: this.getMedal(data.userInfo.badge),
190
- },
192
+ user: this.getUser(data.userInfo),
191
193
  timestamp: parseInt(data.sendTimeMs),
192
194
  },
193
195
  };
@@ -198,13 +200,12 @@ class acfunLive extends events_1.EventEmitter {
198
200
  platform: "acfun",
199
201
  room: this.id,
200
202
  type: "live_end",
201
- local_timestamp: new Date().valueOf(),
203
+ record_time: new Date().valueOf(),
202
204
  info: {
203
205
  status: "off"
204
206
  }
205
207
  };
206
208
  this.client = null;
207
- this.emit("change", { status: "off" });
208
209
  this.emitMsg(off);
209
210
  }
210
211
  msg_LiveBanned() {
@@ -212,30 +213,16 @@ class acfunLive extends events_1.EventEmitter {
212
213
  platform: "acfun",
213
214
  room: this.id,
214
215
  type: "live_cut",
215
- local_timestamp: new Date().valueOf(),
216
+ record_time: new Date().valueOf(),
216
217
  info: {
217
218
  message: ""
218
219
  }
219
220
  };
220
221
  this.client = null;
221
- this.emit("change", { status: "off" });
222
222
  this.emitMsg(cut);
223
223
  }
224
224
  msg_DisplayInfo(data) {
225
- // this.toData(msg)
226
- }
227
- emitMsg(data) {
228
- // 一般消息
229
- this.emit("msg", data);
230
- }
231
- emitOrigin(data) {
232
- // 源消息
233
- this.emit("origin", data);
234
- }
235
- emitChange(data) {
236
- this.live = Object.assign(this.live, data);
237
- // 直播信息
238
- this.emit("change", data);
225
+ //
239
226
  }
240
227
  }
241
228
  exports.default = acfunLive;
@@ -1,3 +1,3 @@
1
- import FloatingLive from "../../src/index";
1
+ import { FloatingLive } from "../../src/index";
2
2
  declare const _default: (ctx: FloatingLive) => void;
3
3
  export = _default;
@@ -5,8 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  const acfunLive_1 = __importDefault(require("./acfunLive"));
6
6
  module.exports = (ctx) => {
7
7
  ctx.helper.roomGenerator.register("acfun", (id, open) => {
8
- let key = `acfun:${Number(id)}`;
9
- let room = new acfunLive_1.default(Number(id), open);
10
- return { key, room };
8
+ return new acfunLive_1.default(Number(id), open);
11
9
  });
12
10
  };
@@ -1,10 +1,7 @@
1
- /// <reference types="node" />
2
1
  import { UserInfo } from "../../src/types/message/AttributeInfo";
3
2
  import { KeepLiveWS } from "bilibili-live-ws";
4
- import { EventEmitter } from "events";
5
- import LiveRoom from "../../src/types/room/LiveRoom";
6
- import { LiveInfo } from "../../src/types/room/LiveInfo";
7
- declare class bilibiliLive extends EventEmitter implements LiveRoom {
3
+ import { LiveRoom, RoomBaseInfo } from "../../src/lib/LiveRoom";
4
+ declare class bilibiliLive extends LiveRoom {
8
5
  /** 平台id */
9
6
  readonly platform: string;
10
7
  /** 直播间号 */
@@ -12,16 +9,15 @@ declare class bilibiliLive extends EventEmitter implements LiveRoom {
12
9
  /** 直播间room_id */
13
10
  roomid: number;
14
11
  /** 直播信息 */
15
- live: LiveInfo;
16
- cover: string;
12
+ base: RoomBaseInfo;
13
+ /** 房间是否可用 */
14
+ available: boolean;
15
+ /** 是否连接上房间 */
16
+ connected: boolean;
17
17
  /** 主播信息 */
18
18
  anchor: UserInfo;
19
- /** 直播间是否可用 */
20
- available: boolean;
21
19
  /** 直播间弹幕api模块 */
22
20
  client: KeepLiveWS | null;
23
- /** 是否为持续监听状态 */
24
- opening: boolean;
25
21
  /** 断线重连间隔 */
26
22
  connectInterval: number;
27
23
  constructor(id: number, // 房间id
@@ -36,10 +32,6 @@ declare class bilibiliLive extends EventEmitter implements LiveRoom {
36
32
  /** 连接直播服务端 */
37
33
  createWS(): Promise<void>;
38
34
  close(): void;
39
- destory(): void;
40
- emitMsg(data: any): void;
41
- emitOrigin(data: any): void;
42
- emitChange(data: Partial<LiveInfo>): void;
43
35
  getDanmakuMode(n: number): string;
44
36
  /** 获取弹幕消息 */
45
37
  msg_DANMU_MSG(msg: any): void;