floating-live 0.12.0 → 0.13.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 (63) hide show
  1. package/README.md +7 -8
  2. package/index.d.ts +3 -3
  3. package/index.js +3 -3
  4. package/package.json +4 -2
  5. package/plugin/acfun/acfunLive.d.ts +3 -3
  6. package/plugin/acfun/acfunLive.js +10 -10
  7. package/plugin/acfun/index.d.ts +1 -0
  8. package/plugin/acfun/index.js +3 -2
  9. package/plugin/bilibili/index.d.ts +1 -0
  10. package/plugin/bilibili/index.js +17 -4
  11. package/plugin/bilibili/parser.d.ts +6 -0
  12. package/plugin/bilibili/{bilibiliLive.js → parser.js} +132 -231
  13. package/plugin/bilibili/room.d.ts +77 -0
  14. package/plugin/bilibili/room.js +261 -0
  15. package/plugin/bilibili/types.d.ts +424 -0
  16. package/plugin/bilibili/utils.d.ts +16 -0
  17. package/plugin/bilibili/utils.js +140 -0
  18. package/plugin/chatPrint/chatPrint.d.ts +2 -2
  19. package/plugin/chatPrint/chatPrint.js +16 -6
  20. package/plugin/chatPrint/index.d.ts +1 -0
  21. package/plugin/chatPrint/index.js +2 -1
  22. package/plugin/consoleEvent/index.d.ts +1 -0
  23. package/plugin/consoleEvent/index.js +16 -21
  24. package/plugin/msgSave/index.d.ts +3 -1
  25. package/plugin/msgSave/index.js +25 -30
  26. package/plugin/msgSave/msgSave.d.ts +5 -5
  27. package/plugin/msgSave/msgSave.js +25 -9
  28. package/src/abstract/LiveRoom.d.ts +44 -0
  29. package/src/{lib → abstract}/LiveRoom.js +12 -7
  30. package/src/enum.d.ts +4 -2
  31. package/src/enum.js +9 -7
  32. package/src/index.d.ts +13 -37
  33. package/src/index.js +12 -74
  34. package/src/module/ModAuth.d.ts +8 -0
  35. package/src/module/ModAuth.js +14 -0
  36. package/src/module/ModCommand.d.ts +3 -0
  37. package/src/module/ModCommand.js +6 -0
  38. package/src/module/ModMessage.d.ts +9 -0
  39. package/src/module/ModMessage.js +12 -0
  40. package/src/module/{Plugin.d.ts → ModPlugin.d.ts} +2 -6
  41. package/src/module/{Plugin.js → ModPlugin.js} +20 -18
  42. package/src/module/ModRooms.d.ts +36 -0
  43. package/src/module/{Room.js → ModRooms.js} +50 -31
  44. package/src/types/index.d.ts +1 -2
  45. package/src/types/index.js +1 -2
  46. package/src/types/message.d.ts +210 -0
  47. package/src/types/plugin.d.ts +4 -5
  48. package/src/types/room.d.ts +48 -2
  49. package/src/utils.d.ts +2 -0
  50. package/src/{tool.js → utils.js} +4 -4
  51. package/test/type/bilibili_getInfoByRoom.d.ts +492 -0
  52. package/plugin/bilibili/bilibiliLive.d.ts +0 -58
  53. package/src/lib/LiveRoom.d.ts +0 -89
  54. package/src/module/Command.d.ts +0 -3
  55. package/src/module/Command.js +0 -6
  56. package/src/module/Room.d.ts +0 -26
  57. package/src/tool.d.ts +0 -2
  58. package/src/types/message/AttributeInfo.d.ts +0 -67
  59. package/src/types/message/MessageData.d.ts +0 -166
  60. /package/{src/types/message/AttributeInfo.js → plugin/bilibili/types.js} +0 -0
  61. /package/src/{lib → abstract}/Reglist.d.ts +0 -0
  62. /package/src/{lib → abstract}/Reglist.js +0 -0
  63. /package/src/types/{message/MessageData.js → message.js} +0 -0
package/README.md CHANGED
@@ -23,11 +23,10 @@ const bilibili = require("floating-live/plugin/bilibili")
23
23
  // 创建一个FloatingLive实例
24
24
  const live = new FloatingLive()
25
25
  // 注册插件
26
- live.plugin.register("bilibili", bilibili)
27
- // 添加房间
28
- live.addRoom({platform: "bilibili", id: 6})
29
- // 打开
30
- live.start()
26
+ live.plugin.register(bilibili)
27
+
28
+ // 添加房间并自动打开
29
+ live.rooms.add("bilibili", 6, true)
31
30
  ```
32
31
 
33
32
  ### 拆包即用模式
@@ -59,6 +58,6 @@ live.start()
59
58
  即可接收来自平台的直播弹幕。
60
59
 
61
60
  ## 感谢
62
- ### 开源库
63
- * [simon300000/bilibili-live-ws](https://github.com/simon300000/bilibili-live-ws/):与bilibili直播建立Websocket连接并解码数据包
64
- * [ACFUN-FOSS/ac-danmu](https://github.com/ACFUN-FOSS/ac-danmu.js):与AcFun直播建立Websocket连接并解码数据包
61
+ ### 使用开源库
62
+ * [simon300000/bilibili-live-ws](https://github.com/simon300000/bilibili-live-ws/)
63
+ * [ACFUN-FOSS/ac-danmu](https://github.com/ACFUN-FOSS/ac-danmu.js)
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { FloatingLive } from "./src";
2
2
  export * from "./src/types";
3
3
  export * from "./src/enum";
4
- export * from "./src/lib/LiveRoom";
5
- export * from "./src/lib/Reglist";
6
- export * from "./src/tool";
4
+ export * from "./src/abstract/LiveRoom";
5
+ export * from "./src/abstract/Reglist";
6
+ export * from "./src/utils";
package/index.js CHANGED
@@ -19,6 +19,6 @@ 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"), exports);
21
21
  __exportStar(require("./src/enum"), exports);
22
- __exportStar(require("./src/lib/LiveRoom"), exports);
23
- __exportStar(require("./src/lib/Reglist"), exports);
24
- __exportStar(require("./src/tool"), exports);
22
+ __exportStar(require("./src/abstract/LiveRoom"), exports);
23
+ __exportStar(require("./src/abstract/Reglist"), exports);
24
+ __exportStar(require("./src/utils"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "type": "commonjs",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -15,10 +15,12 @@
15
15
  "prepare": "npm run build"
16
16
  },
17
17
  "dependencies": {
18
+ "@types/qrcode": "^1.5.2",
18
19
  "acfun-live-danmaku": "^0.6.1",
19
20
  "axios": "^1.4.0",
20
21
  "bilibili-live-ws": "^6.3.1",
21
- "fs-extra": "^11.1.0"
22
+ "fs-extra": "^11.1.0",
23
+ "qrcode": "^1.5.3"
22
24
  },
23
25
  "devDependencies": {
24
26
  "@types/fs-extra": "^9.0.13",
@@ -1,4 +1,4 @@
1
- import { RoomDetail } from './../../src/lib/LiveRoom';
1
+ import { RoomDetail } from "../..";
2
2
  import { MedalInfo, UserInfo } from "../..";
3
3
  import AcClient from "acfun-live-danmaku/client";
4
4
  import { LiveRoom, RoomStatsInfo } from "../..";
@@ -29,7 +29,7 @@ declare class acfunLive extends LiveRoom {
29
29
  /** 直播间弹幕api模块 */
30
30
  client: AcClient | null;
31
31
  /** 是否为打开状态 */
32
- opening: boolean;
32
+ opened: boolean;
33
33
  /** 是否连接上服务器 */
34
34
  connected: boolean;
35
35
  private wsInit;
@@ -43,7 +43,7 @@ declare class acfunLive extends LiveRoom {
43
43
  private initWS;
44
44
  /** 关闭直播间监听 */
45
45
  close(): void;
46
- destory(): void;
46
+ destroy(): void;
47
47
  /** 根据守护徽章字符串获取粉丝牌信息 */
48
48
  getMedal(badge?: string): MedalInfo | null;
49
49
  getUser(user: ZtLiveUserInfo): UserInfo;
@@ -44,7 +44,7 @@ class acfunLive extends __1.LiveRoom {
44
44
  /** 直播间弹幕api模块 */
45
45
  this.client = null;
46
46
  /** 是否为打开状态 */
47
- this.opening = false;
47
+ this.opened = false;
48
48
  /** 是否连接上服务器 */
49
49
  this.connected = false;
50
50
  this.wsInit = false;
@@ -87,13 +87,13 @@ class acfunLive extends __1.LiveRoom {
87
87
  }
88
88
  /** 开启直播间监听 */
89
89
  async open() {
90
- if (this.opening || !this.available)
90
+ if (this.opened || !this.available)
91
91
  return;
92
92
  if (!this.wsInit) {
93
93
  this.initWS();
94
94
  }
95
95
  //启动websocket连接
96
- this.opening = true;
96
+ this.opened = true;
97
97
  this.client.wsStart();
98
98
  this.emit("open");
99
99
  }
@@ -137,13 +137,13 @@ class acfunLive extends __1.LiveRoom {
137
137
  }
138
138
  /** 关闭直播间监听 */
139
139
  close() {
140
- if (!this.opening)
140
+ if (!this.opened)
141
141
  return;
142
- this.opening = false;
142
+ this.opened = false;
143
143
  this.client?.wsClose();
144
144
  this.emit("close");
145
145
  }
146
- destory() {
146
+ destroy() {
147
147
  this.close();
148
148
  this.removeAllListeners();
149
149
  }
@@ -162,19 +162,19 @@ class acfunLive extends __1.LiveRoom {
162
162
  }
163
163
  }
164
164
  getUser(user) {
165
- let identity = null;
165
+ let identity = 0;
166
166
  if (user.userIdentity?.managerType == 1) {
167
- identity = __2.UserAdmin.admin;
167
+ identity = __2.UserType.admin;
168
168
  }
169
169
  else if (parseInt(user.userId) == this.anchor.id) {
170
- identity = __2.UserAdmin.anchor;
170
+ identity = __2.UserType.anchor;
171
171
  }
172
172
  return {
173
173
  name: user.nickname,
174
174
  id: parseInt(user.userId),
175
175
  medal: this.getMedal(user.badge),
176
176
  avatar: user.avatar[0].url,
177
- admin: identity,
177
+ type: identity,
178
178
  };
179
179
  }
180
180
  /** 文本信息(Comment) */
@@ -1,5 +1,6 @@
1
1
  import { FloatingLive } from "../../src/index";
2
2
  declare const _default: () => {
3
+ name: string;
3
4
  register: (ctx: FloatingLive) => void;
4
5
  };
5
6
  export = _default;
@@ -5,10 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  const acfunLive_1 = __importDefault(require("./acfunLive"));
6
6
  module.exports = () => {
7
7
  return {
8
+ name: "acfun",
8
9
  register: (ctx) => {
9
- ctx.helper.roomGenerator.register("acfun", (id, open) => {
10
+ ctx.rooms.generator.register("acfun", (id, open) => {
10
11
  return new acfunLive_1.default(Number(id), open);
11
12
  });
12
- }
13
+ },
13
14
  };
14
15
  };
@@ -1,5 +1,6 @@
1
1
  import { FloatingLive } from "../..";
2
2
  declare const _default: () => {
3
+ name: string;
3
4
  register: (ctx: FloatingLive) => void;
4
5
  };
5
6
  export = _default;
@@ -2,13 +2,26 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- const bilibiliLive_1 = __importDefault(require("./bilibiliLive"));
5
+ const room_1 = __importDefault(require("./room"));
6
+ const authConfig = {
7
+ warn: "由于b站弹幕接口限制,在未登录账号的情况下,返回的弹幕用户名会变为星号且无法获取到uid。\n详见(github:simon300000/bilibili-live-ws#397)[https://github.com/simon300000/bilibili-live-ws/issues/397]",
8
+ auth: {
9
+ placeholder: "此处粘贴cookie",
10
+ info: "请在登录后的b站页面中获取cookie并粘贴在输入框内,至少包含SESSDATA字段。",
11
+ },
12
+ qrcode: {
13
+ generate: () => { },
14
+ },
15
+ // verify: { name: "key", type: "string" },
16
+ };
6
17
  module.exports = () => {
7
18
  return {
19
+ name: "bilibili",
8
20
  register: (ctx) => {
9
- ctx.helper.roomGenerator.register("bilibili", (id, open) => {
10
- return new bilibiliLive_1.default(Number(id), open);
21
+ ctx.rooms.generator.register("bilibili", (id, open, config) => {
22
+ return new room_1.default(Number(id), open, config);
11
23
  });
12
- }
24
+ ctx.auth;
25
+ },
13
26
  };
14
27
  };
@@ -0,0 +1,6 @@
1
+ import { Message } from "../../src/types";
2
+ import { RoomInfo } from "./../../src/types/room";
3
+ import { RawInfo, RawMessage } from "./types";
4
+ /** 转换bilibili直播弹幕为floating通用格式 */
5
+ export declare function parseMessage(data: RawMessage.All, room?: RoomInfo): Message.All | undefined;
6
+ export declare function parseInfo(data: RawInfo): RoomInfo;