floating-live 0.8.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 (57) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +62 -0
  3. package/index.d.ts +2 -0
  4. package/index.js +6 -0
  5. package/package.json +29 -0
  6. package/plugin/acfun/acfunLive.d.ts +74 -0
  7. package/plugin/acfun/acfunLive.js +236 -0
  8. package/plugin/acfun/index.d.ts +3 -0
  9. package/plugin/acfun/index.js +12 -0
  10. package/plugin/bilibili/bilibiliLive.d.ts +58 -0
  11. package/plugin/bilibili/bilibiliLive.js +421 -0
  12. package/plugin/bilibili/index.d.ts +3 -0
  13. package/plugin/bilibili/index.js +12 -0
  14. package/plugin/chat/ChatCommand.d.ts +9 -0
  15. package/plugin/chat/ChatCommand.js +39 -0
  16. package/plugin/chat/ChatFilter.d.ts +9 -0
  17. package/plugin/chat/ChatFilter.js +44 -0
  18. package/plugin/chat/chatProcessor.d.ts +12 -0
  19. package/plugin/chat/chatProcessor.js +24 -0
  20. package/plugin/chatPrint/chatPrint.d.ts +21 -0
  21. package/plugin/chatPrint/chatPrint.js +111 -0
  22. package/plugin/chatPrint/index.d.ts +4 -0
  23. package/plugin/chatPrint/index.js +8 -0
  24. package/plugin/consoleEvent/index.d.ts +3 -0
  25. package/plugin/consoleEvent/index.js +39 -0
  26. package/plugin/msgSave/index.d.ts +4 -0
  27. package/plugin/msgSave/index.js +31 -0
  28. package/plugin/msgSave/msgSave.d.ts +22 -0
  29. package/plugin/msgSave/msgSave.js +40 -0
  30. package/src/controller/Message.d.ts +9 -0
  31. package/src/controller/Message.js +15 -0
  32. package/src/controller/Room.d.ts +32 -0
  33. package/src/controller/Room.js +110 -0
  34. package/src/controller/index.d.ts +39 -0
  35. package/src/controller/index.js +74 -0
  36. package/src/index.d.ts +33 -0
  37. package/src/index.js +50 -0
  38. package/src/lib/Registerable.d.ts +27 -0
  39. package/src/lib/Registerable.js +67 -0
  40. package/src/types/message/AttributeInfo.d.ts +64 -0
  41. package/src/types/message/AttributeInfo.js +2 -0
  42. package/src/types/message/MessageData.d.ts +80 -0
  43. package/src/types/message/MessageData.js +2 -0
  44. package/src/types/message/MessageInfo.d.ts +123 -0
  45. package/src/types/message/MessageInfo.js +2 -0
  46. package/src/types/plugin/Plugin.d.ts +3 -0
  47. package/src/types/plugin/Plugin.js +2 -0
  48. package/src/types/room/LiveInfo.d.ts +24 -0
  49. package/src/types/room/LiveInfo.js +2 -0
  50. package/src/types/room/LiveRoom.d.ts +20 -0
  51. package/src/types/room/LiveRoom.js +2 -0
  52. package/src/types/room/PlatformInfo.d.ts +38 -0
  53. package/src/types/room/PlatformInfo.js +2 -0
  54. package/src/types/room/RoomInfo.d.ts +16 -0
  55. package/src/types/room/RoomInfo.js +2 -0
  56. package/src/utils/getRoomInfo.d.ts +4 -0
  57. package/src/utils/getRoomInfo.js +25 -0
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ // Plugin System modified from PicGo
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getCurrentPluginName = exports.setCurrentPluginName = exports.Registerable = void 0;
5
+ /** 插件可注册对象模块 */
6
+ class Registerable {
7
+ constructor(name) {
8
+ this.name = name;
9
+ this.list = new Map();
10
+ this.pluginIdMap = new Map();
11
+ }
12
+ /** 注册一个对象 */
13
+ register(id, item) {
14
+ // 如果组件缺少id, 或者id与已安装插件重复, 则报错
15
+ if (!id)
16
+ throw new TypeError("id is required!");
17
+ if (this.list.has(id))
18
+ throw new TypeError(`${this.name} duplicate id: ${id}!`);
19
+ // 将组件添加至列表中
20
+ this.list.set(id, item);
21
+ // 将插件名称与注册id关联
22
+ if (Registerable.currentPlugin) {
23
+ if (this.pluginIdMap.has(Registerable.currentPlugin)) {
24
+ this.pluginIdMap.get(Registerable.currentPlugin)?.push(id);
25
+ }
26
+ else {
27
+ this.pluginIdMap.set(Registerable.currentPlugin, [id]);
28
+ }
29
+ }
30
+ }
31
+ /** 取消某一插件在该模块中的注册 */
32
+ unregister(pluginName) {
33
+ if (this.pluginIdMap.has(pluginName)) {
34
+ const handlerList = this.pluginIdMap.get(pluginName);
35
+ handlerList?.forEach((plugin) => {
36
+ this.list.delete(plugin);
37
+ });
38
+ }
39
+ }
40
+ /** 获取名称 */
41
+ getName() {
42
+ return this.name;
43
+ }
44
+ /** 根据id获取注册对象 */
45
+ get(id) {
46
+ return this.list.get(id);
47
+ }
48
+ /** 获取注册对象列表 */
49
+ getList() {
50
+ return [...this.list.values()];
51
+ }
52
+ /** 获取注册id列表 */
53
+ getIdList() {
54
+ return [...this.list.keys()];
55
+ }
56
+ }
57
+ exports.Registerable = Registerable;
58
+ /** 设置当前安装插件名称 */
59
+ const setCurrentPluginName = (name = null) => {
60
+ Registerable.currentPlugin = name;
61
+ };
62
+ exports.setCurrentPluginName = setCurrentPluginName;
63
+ /** 获取当前安装插件名称 */
64
+ const getCurrentPluginName = () => {
65
+ return Registerable.currentPlugin;
66
+ };
67
+ exports.getCurrentPluginName = getCurrentPluginName;
@@ -0,0 +1,64 @@
1
+ /** 用户信息 */
2
+ export interface UserInfo {
3
+ /** 用户名 */
4
+ name: string;
5
+ /** 用户id */
6
+ id: number;
7
+ /** 头像url */
8
+ avatar?: string;
9
+ /** 粉丝勋章 */
10
+ medal?: MedalInfo | null;
11
+ /** 房管等级(1为主播, 2为管理员) */
12
+ admin?: number;
13
+ /** 粉丝vip等级 */
14
+ privilege?: boolean | number;
15
+ /** vip等级 */
16
+ vip?: boolean | number;
17
+ /** 用户等级 */
18
+ level?: number;
19
+ }
20
+ /** 粉丝牌信息 */
21
+ export interface MedalInfo {
22
+ /** 粉丝牌名称 */
23
+ name: string;
24
+ /** 粉丝牌id */
25
+ id: number;
26
+ /** 粉丝牌等级 */
27
+ level?: number;
28
+ /** 粉丝vip等级 */
29
+ privilege?: number;
30
+ }
31
+ /** 图像信息 */
32
+ export interface ImageInfo {
33
+ /** 图像名称 */
34
+ name?: string;
35
+ /** 图像id */
36
+ id?: string | number;
37
+ /** 图像url */
38
+ url?: string;
39
+ /** 图像尺寸 */
40
+ size?: [number, number];
41
+ }
42
+ /** 礼物信息 */
43
+ export interface GiftInfo {
44
+ /** 礼物名称 */
45
+ name: string;
46
+ /** 礼物id */
47
+ id: number | string;
48
+ /** 礼物数量 */
49
+ num: number;
50
+ /** 总价值 */
51
+ value: number;
52
+ /** 平台货币 */
53
+ currency: string;
54
+ /** 礼物连击数 */
55
+ combo?: string;
56
+ /** 礼物连击id */
57
+ combo_id?: string;
58
+ /** 人民币价值 */
59
+ cny?: number;
60
+ /** 行为 */
61
+ action?: string;
62
+ /** 随机礼物信息 */
63
+ blind_gift?: GiftInfo;
64
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,80 @@
1
+ import { MessageInfo, MsgInfoBlock, MsgInfoGift, MsgInfoImage, MsgInfoInteract, MsgInfoPrivilege, MsgInfoSuperchat, MsgInfoText } from "./MessageInfo";
2
+ import { LiveStats } from "../room/LiveInfo";
3
+ export interface MessageData {
4
+ /** 平台名称 */
5
+ platform: string;
6
+ /** 房间号 */
7
+ room: number | string;
8
+ /** 信息类型 */
9
+ type: string;
10
+ /** 数据信息 */
11
+ info: MessageInfo;
12
+ /** 本地时间戳 */
13
+ local_timestamp?: number;
14
+ /** 其他属性 */
15
+ [attr: string]: any;
16
+ }
17
+ export interface MessageText extends MessageData {
18
+ type: "text";
19
+ info: MsgInfoText;
20
+ }
21
+ /** 图片聊天消息 */
22
+ export interface MessageImage extends MessageData {
23
+ type: "image";
24
+ info: MsgInfoImage;
25
+ }
26
+ /** 礼物消息 */
27
+ export interface MessageGift extends MessageData {
28
+ type: "gift";
29
+ info: MsgInfoGift;
30
+ }
31
+ /** 互动消息(进入直播间、点赞、关注、分享、加入粉丝团) */
32
+ export interface MessageInteract extends MessageData {
33
+ type: "entry" | "like" | "follow" | "share" | "join";
34
+ info: MsgInfoInteract;
35
+ }
36
+ /** 粉丝vip开通消息 */
37
+ export interface MessagePrivilege extends MessageData {
38
+ type: "privilege";
39
+ info: MsgInfoPrivilege;
40
+ }
41
+ /** 粉丝vip开通消息 */
42
+ export interface MessageSuperchat extends MessageData {
43
+ type: "superchat";
44
+ info: MsgInfoSuperchat;
45
+ }
46
+ /** 禁言消息 */
47
+ export interface MessageBlock extends MessageData {
48
+ type: "block";
49
+ info: MsgInfoBlock;
50
+ }
51
+ /** 直播开播消息 */
52
+ export interface MessageLiveStart extends MessageData {
53
+ type: "live_start";
54
+ info: {
55
+ /** 开播时间 */
56
+ start_time: number;
57
+ };
58
+ }
59
+ /** 直播切断消息 */
60
+ export interface MessageLiveCut extends MessageData {
61
+ type: "live_cut";
62
+ info: {
63
+ /** 切断消息 */
64
+ message: string;
65
+ };
66
+ }
67
+ /** 直播数据更新 */
68
+ export interface MessageLiveStats extends MessageData {
69
+ type: "live_stats";
70
+ info: LiveStats;
71
+ }
72
+ /** 直播结束 */
73
+ export interface MessageLiveEnd extends MessageData {
74
+ type: "live_end";
75
+ info: {
76
+ /** 直播状态 */
77
+ status: "live" | "off" | "round" | "banned";
78
+ };
79
+ }
80
+ export declare type MessageType = MessageText | MessageImage | MessageGift | MessageInteract | MessagePrivilege | MessageSuperchat | MessageBlock | MessageLiveStart | MessageLiveCut | MessageLiveStats | MessageLiveEnd;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,123 @@
1
+ import { UserInfo, ImageInfo, GiftInfo } from "./AttributeInfo";
2
+ /** 聊天板信息 */
3
+ export interface MessageInfo {
4
+ /** 消息id */
5
+ msg_id?: string;
6
+ /** id */
7
+ id?: string;
8
+ /** 用户信息 */
9
+ user?: UserInfo;
10
+ /** 日期时间戳 */
11
+ timestamp?: number;
12
+ /** 文本内容 */
13
+ text?: string;
14
+ /** 文字颜色 */
15
+ color?: number | string;
16
+ /** 弹幕模式 */
17
+ mode?: number | string;
18
+ /** 文字大小 */
19
+ size?: number | string;
20
+ /** 图片信息 */
21
+ image?: ImageInfo;
22
+ /** 礼物信息 */
23
+ gift?: GiftInfo;
24
+ /** (SC)持续时间 */
25
+ duration?: number;
26
+ /** 其他属性 */
27
+ [attr: string]: any;
28
+ }
29
+ /** 文字聊天信息 */
30
+ export interface MsgInfoText {
31
+ /** 用户信息 */
32
+ user: UserInfo;
33
+ /** 日期时间戳 */
34
+ timestamp: number;
35
+ /** 文本内容 */
36
+ text: string;
37
+ /** 文字颜色 */
38
+ color?: number | string;
39
+ /** 弹幕模式 */
40
+ mode?: number | string;
41
+ /** 文字大小 */
42
+ size?: number | string;
43
+ /** 信息标签 */
44
+ tag?: string | boolean;
45
+ }
46
+ /** 图片聊天信息 */
47
+ export interface MsgInfoImage {
48
+ /** 用户信息 */
49
+ user: UserInfo;
50
+ /** 日期时间戳 */
51
+ timestamp: number;
52
+ /** 弹幕模式 */
53
+ mode?: number | string;
54
+ /** 文字大小 */
55
+ size?: number | string;
56
+ /** 图片信息 */
57
+ image: ImageInfo;
58
+ /** 信息标签 */
59
+ tag?: string | boolean;
60
+ }
61
+ /** 礼物信息 */
62
+ export interface MsgInfoGift {
63
+ /** 用户信息 */
64
+ user: UserInfo;
65
+ /** 日期时间戳 */
66
+ timestamp: number;
67
+ /** 礼物信息 */
68
+ gift: GiftInfo;
69
+ }
70
+ /** 互动信息 */
71
+ export interface MsgInfoInteract {
72
+ /** 用户信息 */
73
+ user: UserInfo;
74
+ /** 日期时间戳 */
75
+ timestamp: number;
76
+ /** 信息标签 */
77
+ tag?: string | boolean;
78
+ }
79
+ /** 粉丝付费会员开通信息 */
80
+ export interface MsgInfoPrivilege {
81
+ /** 用户信息 */
82
+ user: UserInfo;
83
+ /** 日期时间戳 */
84
+ timestamp: number;
85
+ /** 礼物信息 */
86
+ gift: GiftInfo;
87
+ /** 开通vip名称 */
88
+ name: string;
89
+ /** 开通vip等级 */
90
+ level?: number;
91
+ /** 持续时间(天数) */
92
+ duration: number;
93
+ /** 续费类型(0为非续费开通, 1为续费, 2为自动续费) */
94
+ renew?: 0 | 1 | 2;
95
+ }
96
+ /** 付费留言信息 */
97
+ export interface MsgInfoSuperchat {
98
+ /** 留言id */
99
+ id?: string;
100
+ /** 用户信息 */
101
+ user: UserInfo;
102
+ /** 日期时间戳 */
103
+ timestamp: number;
104
+ /** 文本内容 */
105
+ text: string;
106
+ /** 文字颜色 */
107
+ color?: number | string;
108
+ /** 礼物信息 */
109
+ gift: GiftInfo;
110
+ /** (SC)持续时间 */
111
+ duration: number;
112
+ }
113
+ /** 禁言信息 */
114
+ export interface MsgInfoBlock {
115
+ /** 用户信息 */
116
+ user: UserInfo;
117
+ /** 日期时间戳 */
118
+ timestamp?: number;
119
+ /** 操作者 */
120
+ operator: UserInfo | {
121
+ admin: number;
122
+ };
123
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import FloatingLive from "../..";
2
+ /** 插件模块, 加载时调用 */
3
+ export declare type FLivePlugin<T = void> = (ctx: FloatingLive) => T;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,24 @@
1
+ /** 直播信息 */
2
+ export interface LiveInfo {
3
+ /** 直播标题 */
4
+ title: string;
5
+ /** 分区 */
6
+ area?: string[];
7
+ /** 封面url */
8
+ cover?: string;
9
+ /** 直播状态(直播/关播/轮播/封禁) */
10
+ status: "live" | "off" | "round" | "banned";
11
+ /** 开始直播时间 */
12
+ start_time: number;
13
+ }
14
+ /** 直播统计信息 */
15
+ export interface LiveStats {
16
+ /** 在线人数 */
17
+ online?: number;
18
+ /** 已观看人数 */
19
+ watched?: number;
20
+ /** 点赞数 */
21
+ like?: number;
22
+ /** 人气值 */
23
+ popularity?: number;
24
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ import RoomInfo from "./RoomInfo";
2
+ interface LiveRoom extends RoomInfo {
3
+ /** 直播平台 */
4
+ readonly platform: string;
5
+ /** 房间id */
6
+ readonly id: number;
7
+ /** 打开连接 */
8
+ open: () => void;
9
+ /** 关闭连接 */
10
+ close: () => void;
11
+ /** 销毁 */
12
+ destory: () => void;
13
+ /** 从服务器获取信息 */
14
+ getInfo: () => void;
15
+ /** 事件监听 */
16
+ on: (eventName: string | symbol, listener: (...args: any[]) => void) => this;
17
+ /** 移除事件监听 */
18
+ removeAllListeners: () => void;
19
+ }
20
+ export default LiveRoom;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,38 @@
1
+ export interface PlatformInfo {
2
+ /** 平台名称 */
3
+ name: string;
4
+ /** 平台id */
5
+ id: string;
6
+ /** 平台vip信息 */
7
+ vip: {
8
+ /** 平台vip对应id */
9
+ id: string;
10
+ /** 平台vip名称 */
11
+ name: string;
12
+ /** 平台vip等级名称 */
13
+ level?: string[];
14
+ };
15
+ /** 粉丝vip信息 */
16
+ privilege: {
17
+ /** 粉丝vip对应id */
18
+ id: string;
19
+ /** 粉丝vip名称 */
20
+ name: string;
21
+ /** 粉丝vip等级名称 */
22
+ level?: string;
23
+ };
24
+ /** 礼物信息 */
25
+ gift: {
26
+ /** 货币 */
27
+ currency: Array<{
28
+ /** 货币id */
29
+ id: string;
30
+ /** 货币名称 */
31
+ name: string;
32
+ /** 1货币面值等值value (1面值/1数值) */
33
+ face: number;
34
+ /** 1人民币等值value (1.00CNY/1数值) (若为0则为免费货币) */
35
+ cny?: number;
36
+ }>;
37
+ };
38
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import { LiveInfo } from "./LiveInfo";
2
+ import { UserInfo } from "../message/AttributeInfo";
3
+ export default interface RoomInfo {
4
+ /** 平台id */
5
+ platform: string;
6
+ /** 房间id */
7
+ id: number;
8
+ /** 直播信息 */
9
+ live: LiveInfo;
10
+ /** 主播信息 */
11
+ anchor: UserInfo;
12
+ /** 直播间是否可用 */
13
+ available: boolean;
14
+ /** 房间是否打开 */
15
+ opening: boolean;
16
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import LiveRoom from "../types/room/LiveRoom";
2
+ import RoomInfo from "../types/room/RoomInfo";
3
+ /** 从房间中获取房间信息 */
4
+ export default function getRoomInfo(liveroom: LiveRoom): RoomInfo;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /** 从房间中获取房间信息 */
4
+ function getRoomInfo(liveroom) {
5
+ let { platform, id, live: { title, cover, area, status, start_time, }, anchor, available, opening, } = liveroom;
6
+ return {
7
+ platform,
8
+ id,
9
+ live: {
10
+ title,
11
+ cover,
12
+ area: area ? [...area] : undefined,
13
+ status,
14
+ start_time,
15
+ },
16
+ anchor: {
17
+ name: anchor.name,
18
+ id: anchor.id,
19
+ avatar: anchor.avatar
20
+ },
21
+ available,
22
+ opening,
23
+ };
24
+ }
25
+ exports.default = getRoomInfo;