floating-live 0.14.11 → 0.15.0-beta.1

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 (65) hide show
  1. package/LICENSE +5 -670
  2. package/README.md +3 -34
  3. package/{src/abstract → dist/core}/LiveRoom.d.ts +1 -3
  4. package/{src/abstract → dist/core}/LiveRoom.js +6 -6
  5. package/{src/abstract → dist/core}/Reglist.d.ts +1 -1
  6. package/dist/core/index.d.ts +2 -0
  7. package/dist/core/index.js +18 -0
  8. package/dist/index.d.ts +6 -0
  9. package/{index.js → dist/index.js} +7 -7
  10. package/{src/index.d.ts → dist/live.d.ts} +0 -3
  11. package/{src/index.js → dist/live.js} +0 -2
  12. package/{src → dist}/module/ModCommand.d.ts +2 -2
  13. package/{src → dist}/module/ModCommand.js +1 -1
  14. package/{src → dist}/module/ModMessage.d.ts +2 -2
  15. package/{src → dist}/module/ModMessage.js +1 -1
  16. package/{src → dist}/module/ModPlugin.d.ts +1 -1
  17. package/{src → dist}/module/ModRoom.d.ts +3 -5
  18. package/{src → dist}/module/ModRoom.js +1 -10
  19. package/{src → dist}/module/ModState.d.ts +2 -2
  20. package/{src → dist}/module/ModState.js +1 -1
  21. package/{src → dist}/types/index.d.ts +0 -1
  22. package/{src → dist}/types/index.js +0 -1
  23. package/{src → dist}/types/message.d.ts +2 -2
  24. package/{src → dist}/types/plugin.d.ts +1 -1
  25. package/{src → dist}/types/room.d.ts +1 -1
  26. package/package.json +29 -15
  27. package/index.d.ts +0 -6
  28. package/plugin/acfun/acfunLive.d.ts +0 -74
  29. package/plugin/acfun/acfunLive.js +0 -279
  30. package/plugin/acfun/index.d.ts +0 -3
  31. package/plugin/acfun/index.js +0 -16
  32. package/plugin/bilibili/index.d.ts +0 -6
  33. package/plugin/bilibili/index.js +0 -45
  34. package/plugin/bilibili/parser.d.ts +0 -6
  35. package/plugin/bilibili/parser.js +0 -397
  36. package/plugin/bilibili/room.d.ts +0 -77
  37. package/plugin/bilibili/room.js +0 -261
  38. package/plugin/bilibili/types.d.ts +0 -424
  39. package/plugin/bilibili/types.js +0 -2
  40. package/plugin/bilibili/utils.d.ts +0 -17
  41. package/plugin/bilibili/utils.js +0 -137
  42. package/plugin/chatPrint/chatPrint.d.ts +0 -20
  43. package/plugin/chatPrint/chatPrint.js +0 -116
  44. package/plugin/chatPrint/index.d.ts +0 -7
  45. package/plugin/chatPrint/index.js +0 -10
  46. package/plugin/consoleEvent/index.d.ts +0 -6
  47. package/plugin/consoleEvent/index.js +0 -51
  48. package/plugin/msgSave/index.d.ts +0 -10
  49. package/plugin/msgSave/index.js +0 -81
  50. package/plugin/msgSave/msgSave.d.ts +0 -83
  51. package/plugin/msgSave/msgSave.js +0 -168
  52. package/src/module/ModAuth.d.ts +0 -10
  53. package/src/module/ModAuth.js +0 -35
  54. package/src/types/auth.d.ts +0 -19
  55. package/src/types/auth.js +0 -2
  56. package/test/type/bilibili_getInfoByRoom.d.ts +0 -492
  57. /package/{src/abstract → dist/core}/Reglist.js +0 -0
  58. /package/{src/enum.d.ts → dist/enums.d.ts} +0 -0
  59. /package/{src/enum.js → dist/enums.js} +0 -0
  60. /package/{src → dist}/module/ModPlugin.js +0 -0
  61. /package/{src → dist}/types/message.js +0 -0
  62. /package/{src → dist}/types/plugin.js +0 -0
  63. /package/{src → dist}/types/room.js +0 -0
  64. /package/{src → dist}/utils.d.ts +0 -0
  65. /package/{src → dist}/utils.js +0 -0
@@ -1,279 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const acfun_live_danmaku_1 = __importDefault(require("acfun-live-danmaku"));
7
- const __1 = require("../..");
8
- const __2 = require("../..");
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
- }
21
- class acfunLive extends __1.LiveRoom {
22
- constructor(id, open = false) {
23
- super();
24
- /** 平台id */
25
- this.platform = "acfun";
26
- /** 直播展示信息 */
27
- this.detail = {
28
- /** 直播标题 */
29
- title: "",
30
- /** 分区 */
31
- area: [],
32
- /** 封面 */
33
- cover: "",
34
- };
35
- /** 直播数据信息 */
36
- this.stats = {
37
- /** 点赞数 */
38
- like: 0,
39
- /** 在线观看数 */
40
- online: 0,
41
- };
42
- /** 主播信息 */
43
- this.anchor = { name: "", id: 0 };
44
- /** 直播间弹幕api模块 */
45
- this.client = null;
46
- /** 是否为打开状态 */
47
- this.opened = false;
48
- /** 是否连接上服务器 */
49
- this.connected = false;
50
- this.wsInit = false;
51
- this.platform = "acfun";
52
- this.id = id; // 直播间号
53
- this.anchor.id = id; // 主播uid
54
- this.getInfo().then(() => {
55
- if (open)
56
- this.open();
57
- });
58
- }
59
- /** 直播间是否可用 */
60
- get available() {
61
- return Boolean(this.client);
62
- }
63
- async getInfo() {
64
- if (!this.client) {
65
- this.client = (await (0, acfun_live_danmaku_1.default)(this.id)) || null;
66
- if (this.client) {
67
- this.status = __2.RoomStatus.live;
68
- this.timestamp = this.client.liveStartTime;
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`;
71
- }
72
- await fetch(`https://live.acfun.cn/rest/pc-direct/user/userInfo?userId=${this.id}`, {
73
- method: "GET",
74
- })
75
- .then((response) => response.json())
76
- .then((res) => {
77
- let { headUrl, name } = res.profile;
78
- this.anchor.avatar = headUrl;
79
- this.anchor.name = name;
80
- this.emit("info", this.info);
81
- })
82
- .catch((error) => {
83
- this.emit("info_error", error);
84
- });
85
- }
86
- // 暂不能在连接房间后更新信息
87
- }
88
- /** 开启直播间监听 */
89
- async open() {
90
- if (this.opened || !this.available)
91
- return;
92
- if (!this.wsInit) {
93
- this.initWS();
94
- }
95
- //启动websocket连接
96
- this.opened = true;
97
- this.client.wsStart();
98
- this.emit("open");
99
- }
100
- /** 初始化直播服务端监听 */
101
- async initWS() {
102
- if (!this.client)
103
- return;
104
- let client = this.client;
105
- client.on("EnterRoomAck", () => {
106
- console.log("[acfun-live-danmaku] 已连接AcFun直播间");
107
- this.status = __2.RoomStatus.live;
108
- });
109
- client.on("RecentComment", (comments) => {
110
- //当前弹幕列表
111
- });
112
- client.on("Comment", (danmaku) => {
113
- //收到的弹幕
114
- this.msg_Comment(danmaku);
115
- });
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
- });
136
- this.wsInit = true;
137
- }
138
- /** 关闭直播间监听 */
139
- close() {
140
- if (!this.opened)
141
- return;
142
- this.opened = false;
143
- this.client?.wsClose();
144
- this.emit("close");
145
- }
146
- destroy() {
147
- this.close();
148
- this.removeAllListeners();
149
- }
150
- /** 根据守护徽章字符串获取粉丝牌信息 */
151
- getMedal(badge) {
152
- if (badge) {
153
- let medalInfo = JSON.parse(badge).medalInfo;
154
- return {
155
- name: medalInfo.clubName,
156
- id: medalInfo.uperId,
157
- level: medalInfo.level,
158
- };
159
- }
160
- else {
161
- return null;
162
- }
163
- }
164
- getUser(user) {
165
- let identity = 0;
166
- if (user.userIdentity?.managerType == 1) {
167
- identity = __2.UserType.admin;
168
- }
169
- else if (parseInt(user.userId) == this.anchor.id) {
170
- identity = __2.UserType.anchor;
171
- }
172
- return {
173
- name: user.nickname,
174
- id: parseInt(user.userId),
175
- medal: this.getMedal(user.badge),
176
- avatar: user.avatar[0].url,
177
- type: identity,
178
- };
179
- }
180
- /** 文本信息(Comment) */
181
- msg_Comment(data) {
182
- const userInfo = this.getUser(data.userInfo);
183
- let m = {
184
- platform: "acfun",
185
- room: this.id,
186
- id: `${userInfo.id}-${data.sendTimeMs}`,
187
- timestamp: parseInt(data.sendTimeMs),
188
- type: "chat",
189
- info: {
190
- content: data.content,
191
- user: userInfo,
192
- },
193
- };
194
- this.emitMsg(m);
195
- }
196
- /** 礼物信息(Gift) */
197
- msg_Gift(data) {
198
- const userInfo = this.getUser(data.user);
199
- let m = {
200
- platform: "acfun",
201
- room: this.id,
202
- type: "gift",
203
- id: `${userInfo.id}-${data.sendTimeMs}`,
204
- timestamp: parseInt(data.sendTimeMs),
205
- info: {
206
- user: userInfo,
207
- gift: {
208
- name: data.giftName,
209
- id: parseInt(data.giftId),
210
- num: data.count,
211
- currency: data.giftId == "1" ? "banana" : "coin",
212
- value: parseInt(data.value), // 总价值
213
- },
214
- },
215
- };
216
- this.emitMsg(m);
217
- }
218
- /** 互动信息 */
219
- msg_Interact(data, type) {
220
- const userInfo = this.getUser(data.userInfo);
221
- let m = {
222
- platform: "acfun",
223
- room: this.id,
224
- type: type,
225
- id: `${userInfo.id}-${data.sendTimeMs}`,
226
- timestamp: parseInt(data.sendTimeMs),
227
- info: {
228
- user: userInfo,
229
- },
230
- };
231
- this.emitMsg(m);
232
- }
233
- msg_LiveClosed() {
234
- const timestamp = getDateTimestamp();
235
- let m = {
236
- platform: "acfun",
237
- room: this.id,
238
- type: "live_end",
239
- id: `${timestamp}`,
240
- timestamp: timestamp,
241
- info: {
242
- status: __2.RoomStatus.off,
243
- },
244
- };
245
- this.client = null;
246
- this.emitMsg(m);
247
- }
248
- msg_LiveBanned() {
249
- const timestamp = getDateTimestamp();
250
- let m = {
251
- platform: "acfun",
252
- room: this.id,
253
- type: "live_cut",
254
- id: `${timestamp}`,
255
- timestamp: timestamp,
256
- info: {
257
- message: "",
258
- },
259
- };
260
- this.client = null;
261
- this.emitMsg(m);
262
- }
263
- msg_DisplayInfo(data) {
264
- const timestamp = getDateTimestamp();
265
- let m = {
266
- platform: "acfun",
267
- room: this.id,
268
- type: "live_stats",
269
- id: `${timestamp}`,
270
- timestamp: timestamp,
271
- info: {
272
- like: stringToNumber(data.likeCount),
273
- online: stringToNumber(data.watchingCount),
274
- },
275
- };
276
- this.emitMsg(m);
277
- }
278
- }
279
- exports.default = acfunLive;
@@ -1,3 +0,0 @@
1
- import { FloatingLivePlugin } from "../../src/types";
2
- declare const acfun: FloatingLivePlugin;
3
- export = acfun;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- const acfunLive_1 = __importDefault(require("./acfunLive"));
6
- const acfun = () => {
7
- return {
8
- name: "acfun",
9
- register: (ctx) => {
10
- ctx.room.generator.register("acfun", (id, open) => {
11
- return new acfunLive_1.default(Number(id), open);
12
- });
13
- },
14
- };
15
- };
16
- module.exports = acfun;
@@ -1,6 +0,0 @@
1
- import { FloatingLive } from "../..";
2
- declare const bilibili: () => {
3
- name: string;
4
- register: (ctx: FloatingLive) => void;
5
- };
6
- export = bilibili;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- const room_1 = __importDefault(require("./room"));
6
- const utils_1 = require("./utils");
7
- const bilibili = () => {
8
- return {
9
- name: "bilibili",
10
- register: (ctx) => {
11
- ctx.room.generator.register("bilibili", (id, open, config) => {
12
- return new room_1.default(Number(id), open, config);
13
- });
14
- ctx.auth.options.register("bilibili", authConfig);
15
- ctx.command.register("auth.bilibili", async (auth) => {
16
- const uid = await (0, utils_1.getLoginUid)(auth);
17
- ctx.auth.status["bilibili"] = uid;
18
- ctx.auth.set("bilibili", auth);
19
- ctx.emit("auth:update", "bilibili", uid);
20
- });
21
- ctx.command.register("auth.bilibili.qrcode.get", () => {
22
- return (0, utils_1.generateLoginQRcode)();
23
- });
24
- ctx.command.register("auth.bilibili.qrcode.check", async (key) => {
25
- const [code, auth] = await (0, utils_1.checkLoginQRcode)(key);
26
- if (auth) {
27
- const { SESSDATA, DedeUserID } = (0, utils_1.parseCookieString)(auth);
28
- ctx.auth.status["bilibili"] = DedeUserID;
29
- ctx.auth.set("bilibili", `SESSDATA=${SESSDATA}`);
30
- ctx.emit("auth:update", "bilibili", DedeUserID);
31
- }
32
- return [code, auth];
33
- });
34
- },
35
- };
36
- };
37
- const authConfig = {
38
- auth: {
39
- type: "cookie",
40
- },
41
- qrcode: {
42
- type: "url",
43
- },
44
- };
45
- module.exports = bilibili;
@@ -1,6 +0,0 @@
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;