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
@@ -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
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from "events";
3
- import { UserInfo } from "../types/message/AttributeInfo";
4
- import { MessageData } from "../types/message/MessageData";
3
+ import { RoomStatus } from "../enum";
4
+ import { MessageData, UserInfo } from "../../src/types";
5
5
  export interface RoomInfo {
6
6
  /** 平台id */
7
7
  platform: string;
@@ -10,13 +10,15 @@ export interface RoomInfo {
10
10
  /** 房间key */
11
11
  key: string;
12
12
  /** 基本信息 */
13
- base: RoomBaseInfo;
13
+ view: RoomViewInfo;
14
14
  /** 统计信息 */
15
15
  stats?: RoomStatsInfo;
16
16
  /** 主播信息 */
17
17
  anchor: UserInfo;
18
18
  /** 时间戳 */
19
19
  timestamp: number;
20
+ /** 当前直播id */
21
+ liveId?: string;
20
22
  /** 直播状态 */
21
23
  status: RoomStatus;
22
24
  /** 直播间是否可用 */
@@ -26,8 +28,8 @@ export interface RoomInfo {
26
28
  /** 是否连接到房间 */
27
29
  connected: boolean;
28
30
  }
29
- /** 房间基本信息 */
30
- export declare type RoomBaseInfo = {
31
+ /** 房间展示信息 */
32
+ export declare type RoomViewInfo = {
31
33
  /** 直播标题 */
32
34
  title?: string;
33
35
  /** 分区 */
@@ -46,8 +48,6 @@ export declare type RoomStatsInfo = {
46
48
  /** 人气值 */
47
49
  popularity?: number;
48
50
  };
49
- /** 房间状态 */
50
- export declare type RoomStatus = "live" | "off" | "round" | "banned";
51
51
  export declare abstract class LiveRoom extends EventEmitter implements RoomInfo {
52
52
  constructor();
53
53
  /** 平台 */
@@ -55,7 +55,7 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
55
55
  /** 房间id */
56
56
  abstract readonly id: string | number;
57
57
  /** 基本信息 */
58
- abstract base: RoomBaseInfo;
58
+ abstract view: RoomViewInfo;
59
59
  /** 统计信息 */
60
60
  stats?: RoomStatsInfo;
61
61
  /** 主播信息 */
@@ -64,6 +64,8 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
64
64
  status: RoomStatus;
65
65
  /** 时间戳 */
66
66
  timestamp: number;
67
+ /** 当前直播id */
68
+ liveId?: string;
67
69
  /** 房间是否打开 */
68
70
  opening: boolean;
69
71
  /** 房间是否可用 */
@@ -84,5 +86,4 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
84
86
  protected emitOrigin(msg: any): void;
85
87
  get info(): RoomInfo;
86
88
  get key(): string;
87
- private msgCheck;
88
89
  }
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LiveRoom = void 0;
4
4
  const events_1 = require("events");
5
+ const enum_1 = require("../enum");
5
6
  class LiveRoom extends events_1.EventEmitter {
6
7
  constructor() {
7
8
  super();
8
9
  /** 直播状态 */
9
- this.status = "off";
10
+ this.status = enum_1.RoomStatus.off;
10
11
  /** 时间戳 */
11
12
  this.timestamp = 0;
12
13
  /** 房间是否打开 */
@@ -20,22 +21,45 @@ class LiveRoom extends events_1.EventEmitter {
20
21
  }
21
22
  // 发送消息
22
23
  emitMsg(msg) {
23
- this.msgCheck(msg);
24
+ // 其他消息 => 先更改状态再发送消息
25
+ // 直播结束消息 => 先发送消息再更改状态
26
+ switch (msg.type) {
27
+ case "live_start":
28
+ this.status = enum_1.RoomStatus.live;
29
+ this.timestamp = msg.timestamp;
30
+ this.emit("status", enum_1.RoomStatus.live, { timestamp: msg.timestamp, id: msg.info.id });
31
+ break;
32
+ case "live_view":
33
+ this.view = Object.assign(this.view, msg.info);
34
+ this.emit("view", msg.info);
35
+ break;
36
+ case "live_stats":
37
+ this.stats = Object.assign(this.stats, msg.info);
38
+ break;
39
+ case "live_end":
40
+ case "live_cut":
41
+ this.emit("msg", msg);
42
+ this.status = msg.status || enum_1.RoomStatus.off;
43
+ this.timestamp = msg.timestamp;
44
+ this.emit("status", msg.status || enum_1.RoomStatus.off, { timestamp: msg.timestamp });
45
+ return;
46
+ }
24
47
  this.emit("msg", msg);
25
48
  }
26
49
  // 发送源消息
27
50
  emitOrigin(msg) {
28
- this.emit("origin", msg);
51
+ this.emit("origin", msg, { platform: this.platform, room: this.id });
29
52
  }
30
53
  get info() {
31
54
  return {
32
55
  platform: this.platform,
33
56
  id: this.id,
34
- base: this.base,
57
+ view: this.view,
35
58
  stats: this.stats,
36
59
  anchor: this.anchor,
37
60
  timestamp: this.timestamp,
38
61
  status: this.status,
62
+ liveId: this.liveId,
39
63
  available: this.available,
40
64
  opening: this.opening,
41
65
  connected: this.connected,
@@ -45,28 +69,5 @@ class LiveRoom extends events_1.EventEmitter {
45
69
  get key() {
46
70
  return `${this.platform}:${this.id}`;
47
71
  }
48
- // 检测特定消息
49
- msgCheck(msg) {
50
- switch (msg.type) {
51
- case "live_start":
52
- this.status = "live";
53
- this.timestamp = msg.info.timestamp || msg.record_time;
54
- this.emit("status", "live", msg.info.timestamp);
55
- break;
56
- case "live_end":
57
- case "live_cut":
58
- this.status = msg.status || "off";
59
- this.timestamp = msg.timestamp || msg.record_time;
60
- this.emit("status", msg.status || "off", msg.timestamp || msg.record_time);
61
- break;
62
- case "live_change":
63
- this.base = Object.assign(this.base, msg.info);
64
- this.emit("change", msg.info);
65
- break;
66
- case "live_stats":
67
- this.stats = Object.assign(this.stats, msg.info);
68
- break;
69
- }
70
- }
71
72
  }
72
73
  exports.LiveRoom = LiveRoom;
@@ -1,2 +1,3 @@
1
- export declare class Command {
1
+ import { Reglist } from "../lib/Reglist";
2
+ export default class Command extends Reglist<(e: any, ...args: any) => void> {
2
3
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Command = void 0;
4
- class Command {
3
+ const Reglist_1 = require("../lib/Reglist");
4
+ class Command extends Reglist_1.Reglist {
5
5
  }
6
- exports.Command = Command;
6
+ exports.default = Command;
@@ -1,6 +1,8 @@
1
1
  import { FloatingLive } from "..";
2
+ import { FloatingLivePlugin } from "../types/plugin";
2
3
  export declare class PluginHandler<T extends FloatingLive> {
3
4
  private current;
5
+ /** 插件列表 */
4
6
  private list;
5
7
  private pluginEvent;
6
8
  private main;
@@ -14,9 +16,9 @@ export declare class PluginHandler<T extends FloatingLive> {
14
16
  [key: string]: any;
15
17
  } | undefined;
16
18
  /** 注册插件 */
17
- register(name: string, pluginFunc: (main: T) => {
19
+ register(name: string, plugin: FloatingLivePlugin<T>, config?: {
18
20
  [key: string]: any;
19
- } | void): void | {
21
+ }): void | {
20
22
  [key: string]: any;
21
23
  };
22
24
  /** 移除插件 */
@@ -4,6 +4,7 @@ exports.PluginHandler = void 0;
4
4
  class PluginHandler {
5
5
  constructor(main) {
6
6
  this.current = null;
7
+ /** 插件列表 */
7
8
  this.list = new Map();
8
9
  this.pluginEvent = new Map();
9
10
  this.main = main;
@@ -26,22 +27,29 @@ class PluginHandler {
26
27
  return this.list.get(name);
27
28
  }
28
29
  /** 注册插件 */
29
- register(name, pluginFunc) {
30
+ register(name, plugin, config) {
30
31
  if (this.list.has(name)) {
31
32
  this.main.emit("plugin_duplicate", name);
32
33
  return;
33
34
  }
34
35
  this.current = name;
35
36
  // 执行插件函数并获取插件操作对象
36
- let pluginObject = pluginFunc(this.main);
37
- this.list.set(name, pluginObject || {});
37
+ let pluginObject = plugin();
38
+ // 如果插件register函数无法调用,则无法注册插件
39
+ if (typeof pluginObject.register != 'function') {
40
+ this.main.emit("plugin_invalid", name);
41
+ this.current = null;
42
+ return;
43
+ }
44
+ let pluginExpose = pluginObject.register(this.main, config);
45
+ this.list.set(name, pluginExpose || {});
38
46
  // 执行钩子函数
39
47
  this.helper.pluginAddHandler.getList().forEach(handler => {
40
48
  handler(name);
41
49
  });
42
50
  this.main.emit("plugin_add", name);
43
51
  this.current = null;
44
- return pluginObject;
52
+ return pluginExpose;
45
53
  }
46
54
  /** 移除插件 */
47
55
  unregister(name) {
@@ -37,8 +37,8 @@ class RoomController {
37
37
  this.main.emit("live_message", data);
38
38
  });
39
39
  // 直播消息源数据
40
- room.on("origin", (data) => {
41
- this.main.emit("live_origin", data);
40
+ room.on("origin", (data, { platform, room }) => {
41
+ this.main.emit("live_origin", data, { platform, room });
42
42
  });
43
43
  // 连接到直播间
44
44
  room.on("connect", () => {
@@ -52,13 +52,13 @@ class RoomController {
52
52
  room.on("info", () => {
53
53
  this.main.emit("room_info", key, room.info);
54
54
  });
55
- // 直播信息更改
56
- room.on("change", (data) => {
57
- this.main.emit("room_change", key, data);
55
+ // 直播展示信息更改
56
+ room.on("view", (data) => {
57
+ this.main.emit("room_view", key, data);
58
58
  });
59
59
  // 直播状态更改
60
- room.on("status", (status, timestamp) => {
61
- this.main.emit("room_status", key, status, timestamp);
60
+ room.on("status", (status, { id, timestamp }) => {
61
+ this.main.emit("room_status", key, status, { id, timestamp });
62
62
  });
63
63
  // 统计数据更新
64
64
  room.on("stats", (data) => {
@@ -0,0 +1,4 @@
1
+ export * from "./message/AttributeInfo";
2
+ export * from "./message/MessageData";
3
+ export * from "./plugin";
4
+ export * from "./room";
@@ -0,0 +1,20 @@
1
+ "use strict";
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);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./message/AttributeInfo"), exports);
18
+ __exportStar(require("./message/MessageData"), exports);
19
+ __exportStar(require("./plugin"), exports);
20
+ __exportStar(require("./room"), exports);
@@ -1,3 +1,4 @@
1
+ import { ImageSize, UserAdmin } from "../../enum";
1
2
  /** 用户信息 */
2
3
  export interface UserInfo {
3
4
  /** 用户名 */
@@ -8,8 +9,8 @@ export interface UserInfo {
8
9
  avatar?: string;
9
10
  /** 粉丝勋章 */
10
11
  medal?: MedalInfo | null;
11
- /** 身份 */
12
- identity?: "anchor" | "admin" | null;
12
+ /** 管理等级 */
13
+ admin?: UserAdmin | null;
13
14
  /** 粉丝vip等级 */
14
15
  membership?: boolean | number;
15
16
  /** vip等级 */
@@ -36,8 +37,8 @@ export interface ImageInfo {
36
37
  id?: string | number;
37
38
  /** 图像url */
38
39
  url?: string;
39
- /** 图像高度 */
40
- height?: number;
40
+ /** 图像尺寸 */
41
+ size?: ImageSize;
41
42
  }
42
43
  /** 礼物信息 */
43
44
  export interface GiftInfo {