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,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 {
@@ -1,4 +1,6 @@
1
- import { RoomBaseInfo, RoomStatsInfo, RoomStatus } from "../../lib/LiveRoom";
1
+ import { RoomInfo } from './../../lib/LiveRoom';
2
+ import { DanmakuMode, RoomStatus, UserAdmin } from '../../enum';
3
+ import { RoomViewInfo, RoomStatsInfo } from "../../lib/LiveRoom";
2
4
  import { UserInfo, GiftInfo, ImageInfo } from "./AttributeInfo";
3
5
  declare type MessageBase = {
4
6
  /** 平台名称 */
@@ -7,8 +9,8 @@ declare type MessageBase = {
7
9
  room: number | string;
8
10
  /** 信息类型 */
9
11
  type: string;
10
- /** 记录时间 */
11
- record_time: number;
12
+ /** 时间戳 */
13
+ timestamp: number;
12
14
  /** 其他属性 */
13
15
  [attr: string]: any;
14
16
  };
@@ -31,14 +33,12 @@ export declare type MessageChat = MessageBase & {
31
33
  info: {
32
34
  /** 用户信息 */
33
35
  user: UserInfo;
34
- /** 日期时间戳 */
35
- timestamp: number;
36
36
  /** 文本内容 */
37
37
  content: string;
38
38
  /** 文字颜色 */
39
39
  color?: number | string;
40
40
  /** 弹幕模式 */
41
- mode?: number | string;
41
+ mode?: DanmakuMode;
42
42
  /** 文字大小 */
43
43
  size?: number | string;
44
44
  /** 图片信息 */
@@ -57,8 +57,6 @@ export declare type MessageGift = MessageBase & {
57
57
  info: {
58
58
  /** 用户信息 */
59
59
  user: UserInfo;
60
- /** 日期时间戳 */
61
- timestamp: number;
62
60
  /** 礼物信息 */
63
61
  gift: GiftInfo;
64
62
  };
@@ -69,8 +67,6 @@ export declare type MessageInteract = MessageBase & {
69
67
  info: {
70
68
  /** 用户信息 */
71
69
  user: UserInfo;
72
- /** 日期时间戳 */
73
- timestamp: number;
74
70
  /** 信息标签 */
75
71
  tag?: string | boolean;
76
72
  };
@@ -81,8 +77,6 @@ export declare type MessageMembership = MessageBase & {
81
77
  info: {
82
78
  /** 用户信息 */
83
79
  user: UserInfo;
84
- /** 日期时间戳 */
85
- timestamp: number;
86
80
  /** 礼物信息 */
87
81
  gift: GiftInfo;
88
82
  /** 开通vip名称 */
@@ -101,8 +95,6 @@ export declare type MessageSuperchat = MessageBase & {
101
95
  id?: string;
102
96
  /** 用户信息 */
103
97
  user: UserInfo;
104
- /** 日期时间戳 */
105
- timestamp: number;
106
98
  /** 文本内容 */
107
99
  content: string;
108
100
  /** 文字颜色 */
@@ -119,11 +111,9 @@ export declare type MessageBlock = MessageBase & {
119
111
  info: {
120
112
  /** 用户信息 */
121
113
  user: UserInfo;
122
- /** 日期时间戳 */
123
- timestamp?: number;
124
114
  /** 操作者 */
125
115
  operator: UserInfo | {
126
- identity: null | "admin" | "anchor";
116
+ admin: null | UserAdmin;
127
117
  };
128
118
  };
129
119
  };
@@ -131,8 +121,8 @@ export declare type MessageBlock = MessageBase & {
131
121
  export declare type MessageLiveStart = MessageBase & {
132
122
  type: "live_start";
133
123
  info: {
134
- /** 开播时间 */
135
- timestamp: number;
124
+ /** 直播id */
125
+ id: string;
136
126
  };
137
127
  };
138
128
  /** 直播切断消息 */
@@ -143,15 +133,21 @@ export declare type MessageLiveCut = MessageBase & {
143
133
  message: string;
144
134
  };
145
135
  };
136
+ /** 获取房间信息 */
137
+ export interface MessageRoomInfo extends MessageBase {
138
+ type: "room_info";
139
+ /** 数据信息 */
140
+ info: RoomInfo;
141
+ }
146
142
  /** 直播数据更新 */
147
143
  export declare type MessageLiveStats = MessageBase & {
148
144
  type: "live_stats";
149
145
  info: RoomStatsInfo;
150
146
  };
151
- /** 直播信息更新 */
152
- export declare type MessageLiveChange = MessageBase & {
153
- type: "live_change";
154
- info: RoomBaseInfo;
147
+ /** 直播展示信息更新 */
148
+ export declare type MessageLiveView = MessageBase & {
149
+ type: "live_view";
150
+ info: RoomViewInfo;
155
151
  };
156
152
  /** 直播结束 */
157
153
  export declare type MessageLiveEnd = MessageBase & {
@@ -161,7 +157,7 @@ export declare type MessageLiveEnd = MessageBase & {
161
157
  status: RoomStatus;
162
158
  };
163
159
  };
164
- declare type AllMessageType = MessageChat | MessageGift | MessageInteract | MessageMembership | MessageSuperchat | MessageBlock | MessageLiveStart | MessageLiveEnd | MessageLiveCut | MessageLiveChange | MessageLiveStats;
160
+ declare type AllMessageType = MessageChat | MessageGift | MessageInteract | MessageMembership | MessageSuperchat | MessageBlock | MessageLiveStart | MessageLiveEnd | MessageLiveCut | MessageLiveView | MessageLiveStats;
165
161
  export declare type MessageData<T extends AllMessageType["type"] = AllMessageType["type"]> = AllMessageType & {
166
162
  type: T;
167
163
  };
@@ -0,0 +1,9 @@
1
+ import { FloatingLive } from "..";
2
+ /** 插件模块, 加载时调用 */
3
+ export declare type FloatingLivePlugin<T extends FloatingLive> = () => {
4
+ register: (ctx: T, config?: {
5
+ [key: string]: any;
6
+ }) => {
7
+ [key: string]: any;
8
+ } | void;
9
+ };
@@ -36,3 +36,5 @@ export interface PlatformInfo {
36
36
  }>;
37
37
  };
38
38
  }
39
+ export interface RoomConfig {
40
+ }
@@ -1,5 +0,0 @@
1
- import { FloatingLive } from "../..";
2
- /** 插件模块, 加载时调用 */
3
- export declare type FloatingLivePlugin<T extends FloatingLive = FloatingLive> = (ctx: T) => {
4
- [key: string]: any;
5
- } | void;
File without changes
File without changes