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
@@ -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 bilibiliLive_1 = __importDefault(require("./bilibiliLive"));
6
- module.exports = (ctx) => {
7
- ctx.helper.roomGenerator.register("bilibili", (id, open) => {
8
- return new bilibiliLive_1.default(Number(id), open);
9
- });
6
+ module.exports = () => {
7
+ return {
8
+ register: (ctx) => {
9
+ ctx.helper.roomGenerator.register("bilibili", (id, open) => {
10
+ return new bilibiliLive_1.default(Number(id), open);
11
+ });
12
+ }
13
+ };
10
14
  };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chatPrint = void 0;
4
+ const enum_1 = require("../../src/enum");
4
5
  class chatPrint {
5
6
  constructor(main) {
6
7
  this.main = main;
@@ -14,8 +15,8 @@ class chatPrint {
14
15
  let name = `${"\x1b[33m"}${user.name}`; // 用户名
15
16
  let medal = user.medal ? `${"\x1b[32m"}[${user.medal.name}(${user.medal.level})] ` : ""; // 粉丝牌
16
17
  let membership = user.membership ? `${"\x1b[36m"}[${this.getPriviliegeName(message.platform, user.membership)}]` : ""; // 特权粉丝
17
- let identity = user.identity ? `${"\x1b[95m"}[${{ admin: "房管", anchor: "主播" }[user.identity]}]` : ""; // 房管
18
- return `${medal}${membership}${identity}${name}${"\x1b[0m"}`; //[粉丝牌(等级)] [特权][房管]用户名
18
+ let admin = user.admin ? `${"\x1b[95m"}[${{ [enum_1.UserAdmin.admin]: "房管", [enum_1.UserAdmin.anchor]: "主播" }[user.admin]}]` : ""; // 房管
19
+ return `${medal}${membership}${admin}${name}${"\x1b[0m"}`; //[粉丝牌(等级)] [特权][房管]用户名
19
20
  }
20
21
  /** 获取特权粉丝名称 */
21
22
  getPriviliegeName(platform, level) {
@@ -80,7 +81,7 @@ class chatPrint {
80
81
  }
81
82
  case "block": {
82
83
  let user = this.getUserInfo(message);
83
- let operator = message.info.operator.identity ? { admin: "房管", anchor: "主播" }[message.info.operator.identity] : "管理员";
84
+ let operator = message.info.operator.admin ? { [enum_1.UserAdmin.admin]: "房管", [enum_1.UserAdmin.anchor]: "主播" }[message.info.operator.admin] : "管理员";
84
85
  console.log(`${user} 已被${operator}禁言`);
85
86
  break;
86
87
  }
@@ -1,4 +1,6 @@
1
1
  import { FloatingLive } from "../../src";
2
2
  import { chatPrint } from "./chatPrint";
3
- declare const _default: (ctx: FloatingLive) => chatPrint;
3
+ declare const _default: () => {
4
+ register: (ctx: FloatingLive) => chatPrint;
5
+ };
4
6
  export = _default;
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  const chatPrint_1 = require("./chatPrint");
3
- module.exports = (ctx) => {
4
- return new chatPrint_1.chatPrint(ctx);
3
+ module.exports = () => {
4
+ return {
5
+ register: (ctx) => {
6
+ return new chatPrint_1.chatPrint(ctx);
7
+ }
8
+ };
5
9
  };
@@ -1,3 +1,5 @@
1
1
  import { FloatingLive } from "../../src";
2
- declare const _default: (ctx: FloatingLive) => void;
2
+ declare const _default: () => {
3
+ register: (ctx: FloatingLive) => void;
4
+ };
3
5
  export = _default;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- module.exports = (ctx) => {
2
+ const initEventConsole = (ctx) => {
3
3
  ctx.on("start", () => {
4
4
  console.log(`[controller]记录已开始: ${ctx.timestamp}`);
5
5
  });
@@ -49,3 +49,8 @@ module.exports = (ctx) => {
49
49
  console.log(`[plugin]插件名称重复: ${name}`);
50
50
  });
51
51
  };
52
+ module.exports = () => {
53
+ return {
54
+ register: initEventConsole
55
+ };
56
+ };
@@ -1,4 +1,8 @@
1
1
  import { FloatingLive } from "../../src";
2
- import msgSave from "../msgSave/msgSave";
3
- export declare const messageSave: (ctx: FloatingLive) => msgSave;
4
- export declare const messageSaveOrigin: (ctx: FloatingLive) => msgSave;
2
+ import MsgSave from "../msgSave/msgSave";
3
+ export declare const messageSave: () => {
4
+ register: (ctx: FloatingLive) => MsgSave;
5
+ };
6
+ export declare const messageSaveOrigin: () => {
7
+ register: (ctx: FloatingLive) => MsgSave;
8
+ };
@@ -5,27 +5,82 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.messageSaveOrigin = exports.messageSave = void 0;
7
7
  const msgSave_1 = __importDefault(require("../msgSave/msgSave"));
8
- const messageSave = (ctx) => {
9
- let saveMessage = new msgSave_1.default(ctx, "live_message", `./save/undefined.txt`, ctx.started);
10
- ctx.on("start", () => {
11
- let startDate = new Date(ctx.timestamp);
12
- let fileId = `${startDate.getFullYear()}${(startDate.getMonth() + 1).toString().padStart(2, '0')}${startDate.getDate().toString().padStart(2, '0')}_${startDate.getHours().toString().padStart(2, '0')}${startDate.getMinutes().toString().padStart(2, '0')}${startDate.getSeconds().toString().padStart(2, '0')}-${String(ctx.room.keyList[0]).replace(":", "-")}`;
13
- saveMessage.changeFile(`./save/${fileId}.txt`);
14
- saveMessage.start();
15
- });
16
- ctx.on("end", () => { saveMessage.pause(); });
17
- return saveMessage;
8
+ const messageSave = () => {
9
+ return {
10
+ register: (ctx) => {
11
+ const saveMessage = new msgSave_1.default(ctx, {
12
+ filePath: `./save`,
13
+ sliceByStatus: true,
14
+ });
15
+ // 直播状态改变时,更新保存信息
16
+ ctx.on("room_status", (roomKey, status, { timestamp }) => {
17
+ const { platform, id } = ctx.room.get(roomKey).info;
18
+ saveMessage.setSaveInfo({
19
+ platform,
20
+ room: id,
21
+ status,
22
+ timestamp,
23
+ statusChanged: true
24
+ });
25
+ });
26
+ // 打开直播间时,设置保存信息
27
+ ctx.on("room_open", (roomKey, roomInfo) => {
28
+ const { platform, id, status } = roomInfo;
29
+ saveMessage.setSaveInfo({
30
+ platform,
31
+ room: id,
32
+ status,
33
+ timestamp: Date.now(),
34
+ statusChanged: false
35
+ });
36
+ });
37
+ // 关闭直播间时,移除保存信息
38
+ ctx.on("room_close", (roomKey, roomInfo) => {
39
+ saveMessage.removeSaveInfo(roomKey);
40
+ });
41
+ ctx.on("live_message", (msg) => {
42
+ saveMessage.write(msg, msg);
43
+ });
44
+ ctx.on("start", () => {
45
+ saveMessage.start();
46
+ });
47
+ ctx.on("end", () => { saveMessage.pause(); });
48
+ return saveMessage;
49
+ }
50
+ };
18
51
  };
19
52
  exports.messageSave = messageSave;
20
- const messageSaveOrigin = (ctx) => {
21
- let saveOrigin = new msgSave_1.default(ctx, "live_origin", `./save/undefined-origin.txt`, ctx.started);
22
- ctx.on("start", () => {
23
- let startDate = new Date(ctx.timestamp);
24
- let fileId = `${startDate.getFullYear()}${(startDate.getMonth() + 1).toString().padStart(2, '0')}${startDate.getDate().toString().padStart(2, '0')}_${startDate.getHours().toString().padStart(2, '0')}${startDate.getMinutes().toString().padStart(2, '0')}${startDate.getSeconds().toString().padStart(2, '0')}-${String(ctx.room.keyList[0]).replace(":", "-")}`;
25
- saveOrigin.changeFile(`./save/${fileId}-origin.txt`);
26
- saveOrigin.start();
27
- });
28
- ctx.on("end", () => { saveOrigin.pause(); });
29
- return saveOrigin;
53
+ const messageSaveOrigin = () => {
54
+ return {
55
+ register: (ctx) => {
56
+ const saveOrigin = new msgSave_1.default(ctx, {
57
+ filePath: `./save`,
58
+ suffix: `.origin`,
59
+ });
60
+ // 打开直播间时,设置保存信息
61
+ ctx.on("room_open", (roomKey, roomInfo) => {
62
+ const { platform, id, status } = roomInfo;
63
+ saveOrigin.setSaveInfo({
64
+ platform,
65
+ room: id,
66
+ status,
67
+ timestamp: Date.now(),
68
+ statusChanged: false
69
+ });
70
+ });
71
+ // 关闭直播间时,移除保存信息
72
+ ctx.on("room_close", (roomKey, roomInfo) => {
73
+ saveOrigin.removeSaveInfo(roomKey);
74
+ });
75
+ ctx.on("live_origin", (msg, { platform, room }) => {
76
+ saveOrigin.write(msg, { platform, room });
77
+ });
78
+ ctx.on("start", () => {
79
+ saveOrigin.start();
80
+ });
81
+ ctx.on("end", () => { saveOrigin.pause(); });
82
+ return saveOrigin;
83
+ }
84
+ };
30
85
  };
31
86
  exports.messageSaveOrigin = messageSaveOrigin;
@@ -1,22 +1,83 @@
1
+ import { RoomStatus } from './../../src/enum';
1
2
  import { FloatingLive } from "../..";
2
- declare class msgSave {
3
+ interface SaveInfoConfig {
4
+ platform: string;
5
+ room: string | number;
6
+ status: RoomStatus;
7
+ timestamp: number;
8
+ statusChanged: boolean;
9
+ }
10
+ declare class SaveInfo implements SaveInfoConfig {
11
+ /** 文件id */
12
+ get fileId(): string;
13
+ /** 平台 */
14
+ platform: string;
15
+ /** 房间号 */
16
+ room: string | number;
17
+ /** 时间戳 */
18
+ timestamp: number;
19
+ /** 状态 */
20
+ status: RoomStatus;
21
+ /** 文件是否存在 */
22
+ exist: boolean;
23
+ /** 记录状态是否已更改 */
24
+ statusChanged: boolean;
25
+ /** 按状态分文件 */
26
+ sliceByStatus: boolean;
27
+ /** 消息记录数 */
28
+ count: number;
29
+ /** 总消息记录数 */
30
+ totalCount: number;
31
+ /** 按消息记录数分文件 */
32
+ sliceByCount: number;
33
+ /** 分块id */
34
+ part: number;
35
+ constructor({ platform, room, status, timestamp, statusChanged, sliceByStatus, sliceByCount }: SaveInfoConfig & {
36
+ sliceByStatus?: boolean;
37
+ sliceByCount?: number;
38
+ });
39
+ /** 分块 */
40
+ slice(): void;
41
+ }
42
+ declare class MsgSave {
3
43
  /** 主模块 */
4
44
  main: FloatingLive;
5
- file: string;
6
- config: object;
7
- type: string;
45
+ /** 文件路径 */
46
+ path: string;
47
+ /** 前缀 */
48
+ prefix: string;
49
+ /** 后缀 */
50
+ suffix: string;
51
+ /** 按状态分文件 */
52
+ sliceByStatus: boolean;
53
+ sliceByCount: number;
8
54
  paused: boolean;
9
- listener: (msg: any) => void;
10
- constructor(main: FloatingLive, type: string, file: string, open?: boolean, config?: {
11
- encoding: string;
12
- flag: string;
55
+ /** 列表 */
56
+ list: Map<string, SaveInfo>;
57
+ constructor(main: FloatingLive, { filePath, prefix, suffix, open, sliceByStatus, sliceByCount }: {
58
+ filePath: string;
59
+ prefix?: string;
60
+ suffix?: string;
61
+ open?: boolean;
62
+ sliceByStatus?: boolean;
63
+ sliceByCount?: number;
13
64
  });
14
- write(message: any): void;
65
+ write(message: any, { platform, room }: {
66
+ platform: string;
67
+ room: string | number;
68
+ }): void;
15
69
  start(): void;
16
70
  pause(): void;
17
- /** 更改路径 */
18
- changeFile(file: string): void;
19
- /** 销毁实例 */
20
- destory(): void;
71
+ /** 设置保存信息 */
72
+ setSaveInfo({ platform, room, status, timestamp, statusChanged }: SaveInfoConfig): void;
73
+ /** 创建保存信息,用于记录信息可能不存在的情况 */
74
+ createSaveInfo({ platform, room }: {
75
+ platform: string;
76
+ room: string | number;
77
+ }): SaveInfo;
78
+ /** 创建记录文件 */
79
+ createFile(roomKey: string): void;
80
+ /** 移除记录信息 */
81
+ removeSaveInfo(roomKey: string): void;
21
82
  }
22
- export default msgSave;
83
+ export default MsgSave;
@@ -3,25 +3,88 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const enum_1 = require("./../../src/enum");
6
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
7
- class msgSave {
8
- constructor(main, type, file, open = true, config = { encoding: "utf8", flag: "a" }) {
8
+ const path_1 = __importDefault(require("path"));
9
+ function getTimeStr(timestamp) {
10
+ let startDate = new Date(timestamp);
11
+ return `${startDate.getFullYear()}${(startDate.getMonth() + 1).toString().padStart(2, '0')}${startDate.getDate().toString().padStart(2, '0')}_${startDate.getHours().toString().padStart(2, '0')}${startDate.getMinutes().toString().padStart(2, '0')}${startDate.getSeconds().toString().padStart(2, '0')}`;
12
+ }
13
+ /** 获取当次记录状态
14
+ * S=直播开始 L=直播中 E=直播结束 O=未开播
15
+ */
16
+ function getRecordStatus(status, statusChanged) {
17
+ if (status == enum_1.RoomStatus.live) {
18
+ /** 已开播 */
19
+ return statusChanged ? "S" : "L";
20
+ }
21
+ else {
22
+ /** 未开播 */
23
+ return statusChanged ? "E" : "O";
24
+ }
25
+ }
26
+ class SaveInfo {
27
+ constructor({ platform, room, status, timestamp, statusChanged, sliceByStatus = false, sliceByCount = 0 }) {
28
+ /** 文件是否存在 */
29
+ this.exist = false;
30
+ /** 记录状态是否已更改 */
31
+ this.statusChanged = false;
32
+ /** 消息记录数 */
33
+ this.count = 0;
34
+ /** 总消息记录数 */
35
+ this.totalCount = 0;
36
+ this.platform = platform;
37
+ this.room = room;
38
+ this.status = status;
39
+ this.timestamp = timestamp;
40
+ this.statusChanged = statusChanged;
41
+ this.sliceByStatus = sliceByStatus;
42
+ this.sliceByCount = sliceByCount;
43
+ this.part = sliceByCount && 1;
44
+ }
45
+ /** 文件id */
46
+ get fileId() {
47
+ return `${this.platform}_${this.room}-${getTimeStr(this.timestamp || 0)}${this.sliceByStatus ? getRecordStatus(this.status, this.statusChanged) : ""}${this.part ? `.${this.part}` : ""}`;
48
+ }
49
+ /** 分块 */
50
+ slice() {
51
+ this.exist = false;
52
+ this.count = 0;
53
+ this.part += 1;
54
+ }
55
+ }
56
+ class MsgSave {
57
+ constructor(main, { filePath, prefix = "", suffix = "", open = true, sliceByStatus = false, sliceByCount = 0 }) {
58
+ /** 列表 */
59
+ this.list = new Map();
9
60
  this.paused = !open;
10
61
  this.main = main;
11
- this.file = file;
12
- this.config = config;
13
- this.type = type;
14
- this.listener = (msg) => { if (!this.paused)
15
- this.write(msg); };
16
- this.main.on(this.type, this.listener);
17
- }
18
- write(message) {
19
- fs_extra_1.default.ensureFileSync(this.file);
20
- fs_extra_1.default.writeFile(this.file, JSON.stringify(message) + ",", this.config, (err) => {
62
+ this.path = filePath;
63
+ this.prefix = prefix;
64
+ this.suffix = suffix;
65
+ this.sliceByStatus = sliceByStatus;
66
+ this.sliceByCount = sliceByCount;
67
+ }
68
+ write(message, { platform, room }) {
69
+ if (this.paused)
70
+ return;
71
+ const roomKey = `${platform}:${room}`;
72
+ // 获取保存信息,若信息不存在,则设置一个信息
73
+ const saveInfo = this.list.get(roomKey) || this.createSaveInfo({ platform, room });
74
+ // 若文件不存在,则创建一个有record_info信息的.floatrec文件
75
+ if (!saveInfo.exist)
76
+ this.createFile(roomKey);
77
+ const file = path_1.default.join(this.path, `${this.prefix}${saveInfo.fileId}${this.suffix}.floatrec`);
78
+ fs_extra_1.default.writeFile(file, JSON.stringify(message) + ",", { encoding: "utf8", flag: "a" }, (err) => {
21
79
  if (err)
22
80
  throw err;
23
81
  // console.log('写入成功');
24
82
  });
83
+ // 保存信息递增
84
+ saveInfo.count += 1;
85
+ // 若单文件保存信息已达最大值,则切分到下一个文件
86
+ if (saveInfo.sliceByCount && saveInfo.sliceByCount <= saveInfo.count)
87
+ saveInfo.slice();
25
88
  }
26
89
  start() {
27
90
  this.paused = false;
@@ -29,13 +92,61 @@ class msgSave {
29
92
  pause() {
30
93
  this.paused = true;
31
94
  }
32
- /** 更改路径 */
33
- changeFile(file) {
34
- this.file = file;
95
+ /** 设置保存信息 */
96
+ setSaveInfo({ platform, room, status, timestamp, statusChanged }) {
97
+ const saveInfo = new SaveInfo({
98
+ platform,
99
+ room,
100
+ status,
101
+ timestamp,
102
+ statusChanged,
103
+ sliceByStatus: this.sliceByStatus,
104
+ sliceByCount: this.sliceByCount,
105
+ });
106
+ const roomKey = `${platform}:${room}`;
107
+ if (this.list.get(roomKey)?.fileId == saveInfo.fileId)
108
+ return;
109
+ this.list.set(roomKey, saveInfo);
110
+ }
111
+ /** 创建保存信息,用于记录信息可能不存在的情况 */
112
+ createSaveInfo({ platform, room }) {
113
+ const { status, timestamp } = this.main.room.get(`${platform}:${room}`)?.info || { status: enum_1.RoomStatus.off, timestamp: 0 };
114
+ const saveInfoConfig = {
115
+ platform,
116
+ room, status,
117
+ timestamp,
118
+ statusChanged: false,
119
+ sliceByStatus: this.sliceByStatus,
120
+ sliceByCount: this.sliceByCount,
121
+ };
122
+ this.setSaveInfo(saveInfoConfig);
123
+ return this.list.get(`${platform}:${room}`);
124
+ }
125
+ /** 创建记录文件 */
126
+ createFile(roomKey) {
127
+ const saveInfo = this.list.get(roomKey);
128
+ const file = path_1.default.join(this.path, `${this.prefix}${saveInfo.fileId}${this.suffix}.floatrec`);
129
+ // 如果文件已存在,则将文件标记为已存在,否则创建一个文件并写入record_info信息
130
+ if (fs_extra_1.default.existsSync(file)) {
131
+ saveInfo.exist = true;
132
+ return;
133
+ }
134
+ fs_extra_1.default.ensureFileSync(file);
135
+ const message = {
136
+ type: "record_info",
137
+ platform: saveInfo.platform,
138
+ room: saveInfo.room,
139
+ timestamp: saveInfo.timestamp,
140
+ statusChanged: saveInfo.statusChanged,
141
+ index: saveInfo.totalCount,
142
+ part: saveInfo.part,
143
+ roomInfo: this.main.room.get(roomKey)?.info,
144
+ };
145
+ fs_extra_1.default.writeFileSync(file, JSON.stringify(message) + ",", { encoding: "utf8", flag: "a" });
35
146
  }
36
- /** 销毁实例 */
37
- destory() {
38
- this.main.removeListener(this.type, this.listener);
147
+ /** 移除记录信息 */
148
+ removeSaveInfo(roomKey) {
149
+ this.list.delete(roomKey);
39
150
  }
40
151
  }
41
- exports.default = msgSave;
152
+ exports.default = MsgSave;
package/src/enum.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ /** 直播间状态 */
2
+ export declare enum RoomStatus {
3
+ /** 未开播 */
4
+ off = 0,
5
+ /** 正在直播 */
6
+ live = 1,
7
+ /** 正在轮播 */
8
+ round = 2,
9
+ /** 被封禁 */
10
+ banned = -1
11
+ }
12
+ /** 图片大小 */
13
+ export declare enum ImageSize {
14
+ /** 自定义大小 */
15
+ custom = 0,
16
+ /** 小表情(文字行高) */
17
+ small = 1,
18
+ /** 大表情 */
19
+ large = 2
20
+ }
21
+ /** 弹幕模式 */
22
+ export declare enum DanmakuMode {
23
+ left = 1,
24
+ bottom = 4,
25
+ top = 5,
26
+ right = 6
27
+ }
28
+ /** 管理等级 */
29
+ export declare enum UserAdmin {
30
+ /** 房管 */
31
+ admin = 1,
32
+ /** 主播 */
33
+ anchor = 2
34
+ }
package/src/enum.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserAdmin = exports.DanmakuMode = exports.ImageSize = exports.RoomStatus = void 0;
4
+ /** 直播间状态 */
5
+ var RoomStatus;
6
+ (function (RoomStatus) {
7
+ /** 未开播 */
8
+ RoomStatus[RoomStatus["off"] = 0] = "off";
9
+ /** 正在直播 */
10
+ RoomStatus[RoomStatus["live"] = 1] = "live";
11
+ /** 正在轮播 */
12
+ RoomStatus[RoomStatus["round"] = 2] = "round";
13
+ /** 被封禁 */
14
+ RoomStatus[RoomStatus["banned"] = -1] = "banned";
15
+ })(RoomStatus = exports.RoomStatus || (exports.RoomStatus = {}));
16
+ /** 图片大小 */
17
+ var ImageSize;
18
+ (function (ImageSize) {
19
+ /** 自定义大小 */
20
+ ImageSize[ImageSize["custom"] = 0] = "custom";
21
+ /** 小表情(文字行高) */
22
+ ImageSize[ImageSize["small"] = 1] = "small";
23
+ /** 大表情 */
24
+ ImageSize[ImageSize["large"] = 2] = "large";
25
+ })(ImageSize = exports.ImageSize || (exports.ImageSize = {}));
26
+ /** 弹幕模式 */
27
+ var DanmakuMode;
28
+ (function (DanmakuMode) {
29
+ DanmakuMode[DanmakuMode["left"] = 1] = "left";
30
+ DanmakuMode[DanmakuMode["bottom"] = 4] = "bottom";
31
+ DanmakuMode[DanmakuMode["top"] = 5] = "top";
32
+ DanmakuMode[DanmakuMode["right"] = 6] = "right";
33
+ })(DanmakuMode = exports.DanmakuMode || (exports.DanmakuMode = {}));
34
+ /** 管理等级 */
35
+ var UserAdmin;
36
+ (function (UserAdmin) {
37
+ /** 房管 */
38
+ UserAdmin[UserAdmin["admin"] = 1] = "admin";
39
+ /** 主播 */
40
+ UserAdmin[UserAdmin["anchor"] = 2] = "anchor";
41
+ })(UserAdmin = exports.UserAdmin || (exports.UserAdmin = {}));
package/src/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { EventEmitter } from "events";
3
3
  import { Reglist } from "./lib/Reglist";
4
4
  import { LiveRoom } from "./lib/LiveRoom";
5
- import { MessageData } from "./types/message/MessageData";
5
+ import { MessageData } from "./types";
6
6
  import { PluginHandler } from "./module/Plugin";
7
7
  import { RoomController } from "./module/Room";
8
8
  export declare class FloatingLive extends EventEmitter {
@@ -23,7 +23,7 @@ export declare class FloatingLive extends EventEmitter {
23
23
  pluginRemoveHandler: Reglist<(name: string) => void>;
24
24
  };
25
25
  /** 插件事件注册表 */
26
- private pluginEventMap;
26
+ private regEventMap;
27
27
  /** 状态 */
28
28
  private status;
29
29
  get started(): boolean;
@@ -39,7 +39,7 @@ export declare class FloatingLive extends EventEmitter {
39
39
  addRoom({ platform, id }: {
40
40
  platform: string;
41
41
  id: string | number;
42
- }, open?: boolean): void;
42
+ }, open?: boolean, config?: {}): void;
43
43
  /** 移除房间 */
44
44
  removeRoom(roomKey: string): void;
45
45
  /** 添加房间实例 */
package/src/index.js CHANGED
@@ -9,7 +9,7 @@ class FloatingLive extends events_1.EventEmitter {
9
9
  constructor() {
10
10
  super();
11
11
  /** 插件事件注册表 */
12
- this.pluginEventMap = new Map();
12
+ this.regEventMap = new Map();
13
13
  /** 状态 */
14
14
  this.status = {
15
15
  started: false,
@@ -34,11 +34,13 @@ class FloatingLive extends events_1.EventEmitter {
34
34
  }
35
35
  /** 初始化 */
36
36
  init() {
37
+ // 监听到有房间打开,则开始记录
37
38
  this.on("room_open", () => {
38
39
  this.started || this.start();
39
40
  });
41
+ // 设置在插件卸载时移除由插件注册的事件
40
42
  this.helper.pluginRemoveHandler.register("removePluginEvent", (name) => {
41
- this.pluginEventMap.get(name)?.forEach(([eventName, listener]) => {
43
+ this.regEventMap.get(name)?.forEach(([eventName, listener]) => {
42
44
  this.removeListener(eventName, listener);
43
45
  });
44
46
  });
@@ -46,7 +48,7 @@ class FloatingLive extends events_1.EventEmitter {
46
48
  /** 开始 */
47
49
  start() {
48
50
  this.status.started = true;
49
- this.status.timestamp = new Date().valueOf();
51
+ this.status.timestamp = Date.now();
50
52
  this.emit("start", this.timestamp);
51
53
  }
52
54
  /** 结束 */
@@ -57,7 +59,7 @@ class FloatingLive extends events_1.EventEmitter {
57
59
  this.status.timestamp = 0;
58
60
  }
59
61
  /** 添加房间 */
60
- addRoom({ platform, id }, open) {
62
+ addRoom({ platform, id }, open, config) {
61
63
  let generated = this.room.generate({ platform, id }, open);
62
64
  if (generated) {
63
65
  this.room.add(generated);
@@ -100,10 +102,10 @@ class FloatingLive extends events_1.EventEmitter {
100
102
  super.on(eventName, listener);
101
103
  // 检测是否为插件添加事件,并添加进事件列表
102
104
  if (this.plugin.currentPlugin) {
103
- if (!this.pluginEventMap.has(this.plugin.currentPlugin)) {
104
- this.pluginEventMap.set(this.plugin.currentPlugin, []);
105
+ if (!this.regEventMap.has(this.plugin.currentPlugin)) {
106
+ this.regEventMap.set(this.plugin.currentPlugin, []);
105
107
  }
106
- this.pluginEventMap.get(this.plugin.currentPlugin)?.push([eventName, listener]);
108
+ this.regEventMap.get(this.plugin.currentPlugin)?.push([eventName, listener]);
107
109
  }
108
110
  return this;
109
111
  }