floating-live 0.15.0-beta.2 → 0.15.0-beta.4

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.
package/dist/enums.d.ts CHANGED
@@ -7,7 +7,9 @@ export declare enum RoomStatus {
7
7
  /** 正在轮播 */
8
8
  round = 2,
9
9
  /** 被封禁 */
10
- banned = -1
10
+ banned = -1,
11
+ /** 已上锁 */
12
+ locked = -2
11
13
  }
12
14
  /** 图片大小 */
13
15
  export declare enum ImageSize {
package/dist/enums.js CHANGED
@@ -12,6 +12,8 @@ var RoomStatus;
12
12
  RoomStatus[RoomStatus["round"] = 2] = "round";
13
13
  /** 被封禁 */
14
14
  RoomStatus[RoomStatus["banned"] = -1] = "banned";
15
+ /** 已上锁 */
16
+ RoomStatus[RoomStatus["locked"] = -2] = "locked";
15
17
  })(RoomStatus = exports.RoomStatus || (exports.RoomStatus = {}));
16
18
  /** 图片大小 */
17
19
  var ImageSize;
package/dist/live.d.ts CHANGED
@@ -7,6 +7,7 @@ import ModCommand from "./module/command";
7
7
  import { ModValues } from "./module/values";
8
8
  import { ModHook } from "./module/hook";
9
9
  import { FloatingEventMap } from "./types/events";
10
+ import { FloatingCommandMap } from "./types";
10
11
  export declare class FloatingLive extends EventEmitter {
11
12
  /** 房间控制模块 */
12
13
  room: ModRoom;
@@ -18,11 +19,17 @@ export declare class FloatingLive extends EventEmitter {
18
19
  store: ModStore;
19
20
  /** 数值模块 */
20
21
  values: ModValues;
21
- /** 数值模块 */
22
+ /** 钩子模块 */
22
23
  hook: ModHook;
23
24
  constructor();
24
- call(name: string, ...args: any[]): any;
25
+ call<T extends keyof FloatingCommandMap>(name: T, ...args: Parameters<FloatingCommandMap[T]>): ReturnType<FloatingCommandMap[T]>;
25
26
  on<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): this;
26
- emit<T extends keyof FloatingEventMap>(eventName: T, ...args: any[]): boolean;
27
+ emit<T extends keyof FloatingEventMap>(eventName: T, ...args: Parameters<FloatingEventMap[T]>): boolean;
27
28
  throw(err: Error): void;
29
+ snapshot(): {
30
+ room: import("./types").RoomInfo[];
31
+ values: Record<string, any>;
32
+ store: Record<string, Record<string, any>>;
33
+ command: string[];
34
+ };
28
35
  }
package/dist/live.js CHANGED
@@ -33,5 +33,13 @@ class FloatingLive extends events_1.EventEmitter {
33
33
  throw(err) {
34
34
  this.emit("error", err);
35
35
  }
36
+ snapshot() {
37
+ return {
38
+ room: this.room.snapshot(),
39
+ values: this.values.snapshot(),
40
+ store: this.store.snapshot(),
41
+ command: this.command.snapshot(),
42
+ };
43
+ }
36
44
  }
37
45
  exports.FloatingLive = FloatingLive;
@@ -1,15 +1,16 @@
1
1
  import { FloatingLive } from "../live";
2
- declare type CommandFunction = (...args: any[]) => any;
2
+ import { FloatingCommandMap } from "../types";
3
3
  export default class ModCommand {
4
4
  /** 功能列表 */
5
5
  private readonly list;
6
6
  protected readonly main: FloatingLive;
7
7
  constructor(main: FloatingLive);
8
8
  /** 注册命令 */
9
- register(name: string, func: CommandFunction): void;
9
+ register<T extends keyof FloatingCommandMap>(name: T, func: FloatingCommandMap[T]): void;
10
10
  /** 取消注册命令 */
11
11
  unregister(name: string): void;
12
12
  /** 调用命令 */
13
- call(name: string, ...args: any[]): any;
13
+ call<T extends keyof FloatingCommandMap>(name: T, ...args: Parameters<FloatingCommandMap[T]>): any;
14
+ /** 获取快照 */
15
+ snapshot(): string[];
14
16
  }
15
- export {};
@@ -20,5 +20,9 @@ class ModCommand {
20
20
  call(name, ...args) {
21
21
  return this.list.get(name)?.(...args);
22
22
  }
23
+ /** 获取快照 */
24
+ snapshot() {
25
+ return [...this.list].map(([key]) => key);
26
+ }
23
27
  }
24
28
  exports.default = ModCommand;
@@ -1,13 +1,14 @@
1
1
  import { FloatingLive } from "../live";
2
+ import { FloatingHookMap } from "../types/hook";
2
3
  export declare type HookFunction<T> = (ctx: T) => boolean | void | Promise<boolean | void>;
3
4
  export declare class ModHook {
4
5
  private list;
5
6
  protected readonly main: FloatingLive;
6
7
  constructor(main: FloatingLive);
7
8
  /** 注册钩子函数 */
8
- register<T>(name: string, func: HookFunction<T>): void;
9
+ register<T extends keyof FloatingHookMap>(name: T, func: HookFunction<FloatingHookMap[T]>): void;
9
10
  /** 取消注册钩子函数 */
10
- unregister(name: string, func: HookFunction<any>): void;
11
+ unregister<T extends keyof FloatingHookMap>(name: T, func: HookFunction<FloatingHookMap[T]>): void;
11
12
  /** 调用钩子函数 */
12
- call<T>(name: string, ctx: T): Promise<boolean>;
13
+ call<T extends keyof FloatingHookMap>(name: T, ctx: FloatingHookMap[T]): Promise<boolean>;
13
14
  }
@@ -24,4 +24,8 @@ export declare class ModRoom {
24
24
  open(roomKey: string): void;
25
25
  /** 关闭房间连接 */
26
26
  close(roomKey: string): void;
27
+ /** 更改某个房间的顺序 */
28
+ move(roomKey: string, position: number): void;
29
+ /** 获取快照 */
30
+ snapshot(): RoomInfo[];
27
31
  }
@@ -77,7 +77,7 @@ class ModRoom {
77
77
  if (typeof config == "boolean") {
78
78
  config = { open: config };
79
79
  }
80
- const room = this.main.call(platform, id, config);
80
+ const room = this.main.call(`room.create.${platform}`, id, config);
81
81
  room && this.addRoom(room);
82
82
  }
83
83
  /** 移除房间 */
@@ -121,5 +121,19 @@ class ModRoom {
121
121
  let room = this.list.get(roomKey);
122
122
  room?.opened && room.close();
123
123
  }
124
+ /** 更改某个房间的顺序 */
125
+ move(roomKey, position) {
126
+ const arr = [...this.list];
127
+ const index = arr.findIndex(([key]) => key == roomKey);
128
+ if (index == -1)
129
+ return;
130
+ const [item] = arr.splice(index, 1);
131
+ arr.splice(position, 0, item);
132
+ this.list = new Map(arr);
133
+ }
134
+ /** 获取快照 */
135
+ snapshot() {
136
+ return [...this.list].map(([key, room]) => room.info);
137
+ }
124
138
  }
125
139
  exports.ModRoom = ModRoom;
@@ -1,14 +1,15 @@
1
1
  import { FloatingLive } from "../live";
2
+ import { FloatingStoreMap } from "../types/store";
2
3
  export declare class ModStore {
3
4
  private list;
4
5
  protected readonly main: FloatingLive;
5
6
  constructor(main: FloatingLive);
6
- /** 注册钩子函数 */
7
- register<T>(name: string, id: string, value: T): void;
8
- /** 取消注册钩子函数 */
9
- unregister(name: string, id: string): void;
7
+ /** 注册store */
8
+ register<T extends keyof FloatingStoreMap>(name: T, id: string, value: FloatingStoreMap[T]): void;
9
+ /** 取消注册store */
10
+ unregister<T extends keyof FloatingStoreMap>(name: T, id: string): void;
10
11
  /** 获取值 */
11
12
  get(name: string): Map<string, any> | undefined;
12
- /** 获取注册的所有值 */
13
- getMap(): Record<string, Record<string, any>>;
13
+ /** 获取快照 */
14
+ snapshot(): Record<string, Record<string, any>>;
14
15
  }
@@ -6,7 +6,7 @@ class ModStore {
6
6
  this.list = new Map();
7
7
  this.main = main;
8
8
  }
9
- /** 注册钩子函数 */
9
+ /** 注册store */
10
10
  register(name, id, value) {
11
11
  let store = this.list.get(name);
12
12
  if (!store) {
@@ -14,20 +14,22 @@ class ModStore {
14
14
  this.list.set(name, store);
15
15
  }
16
16
  store.set(id, value);
17
+ this.main.emit("store:add", name, id, value);
17
18
  }
18
- /** 取消注册钩子函数 */
19
+ /** 取消注册store */
19
20
  unregister(name, id) {
20
21
  let store = this.list.get(name);
21
22
  if (store) {
22
23
  store.delete(id);
24
+ this.main.emit("store:remove", name, id);
23
25
  }
24
26
  }
25
27
  /** 获取值 */
26
28
  get(name) {
27
29
  return this.list.get(name);
28
30
  }
29
- /** 获取注册的所有值 */
30
- getMap() {
31
+ /** 获取快照 */
32
+ snapshot() {
31
33
  const map = {};
32
34
  this.list.forEach((store, name) => {
33
35
  const part = {};
@@ -1,4 +1,5 @@
1
1
  import { FloatingLive } from "../live";
2
+ import { FloatingValueMap } from "../types/values";
2
3
  interface ValueConfig<T> {
3
4
  get: () => T;
4
5
  set?: (value: T) => void;
@@ -16,6 +17,9 @@ export declare class ModValues {
16
17
  /** 设置值 */
17
18
  set(name: string, value: any): boolean;
18
19
  /** 获取注册的所有值 */
19
- getMap(): Record<string, any>;
20
+ snapshot(): Record<string, any>;
21
+ emit<T extends keyof FloatingValueMap>(name: T, value: FloatingValueMap[T]): void;
22
+ watch<T extends keyof FloatingValueMap>(name: T, listener: (value: FloatingValueMap[T]) => void): void;
23
+ unwatch<T extends keyof FloatingValueMap>(name: T, listener: (value: FloatingValueMap[T]) => void): void;
20
24
  }
21
25
  export {};
@@ -30,12 +30,22 @@ class ModValues {
30
30
  }
31
31
  }
32
32
  /** 获取注册的所有值 */
33
- getMap() {
33
+ snapshot() {
34
34
  const map = {};
35
35
  this.list.forEach((config, name) => {
36
36
  map[name] = config.get();
37
37
  });
38
38
  return map;
39
39
  }
40
+ emit(name, value) {
41
+ this.main.emit("values:change", name, value);
42
+ this.main.emit(`change:${name}`, value);
43
+ }
44
+ watch(name, listener) {
45
+ this.main.on(`change:${name}`, listener);
46
+ }
47
+ unwatch(name, listener) {
48
+ this.main.off(`change:${name}`, listener);
49
+ }
40
50
  }
41
51
  exports.ModValues = ModValues;
@@ -0,0 +1,9 @@
1
+ import { LiveRoom } from "../core";
2
+ export interface FloatingCommandMap {
3
+ add: (platform: string, id: number, config?: boolean | Record<string, any>) => void;
4
+ remove: (key: string) => void;
5
+ open: (key: string) => void;
6
+ close: (key: string) => void;
7
+ update: (key: string) => void;
8
+ [name: `room.create.${string}`]: (id: string | number, config?: Record<string, any>) => LiveRoom;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,7 +3,10 @@ import { Message } from "./message";
3
3
  import { RoomDetail, RoomInfo, RoomStatsInfo } from "./room";
4
4
  export interface FloatingEventMap {
5
5
  "live:message": (msg: Message.All) => void;
6
- "live:raw": (data: any) => void;
6
+ "live:raw": (data: any, { platform, room }: {
7
+ platform: string;
8
+ room: string | number;
9
+ }) => void;
7
10
  "room:connect": (key: string) => void;
8
11
  "room:disconnect": (key: string) => void;
9
12
  "room:info": (key: string, info: RoomInfo) => void;
@@ -17,10 +20,15 @@ export interface FloatingEventMap {
17
20
  "room:open": (key: string, info: RoomInfo) => void;
18
21
  "room:close": (key: string, info: RoomInfo) => void;
19
22
  "room:add": (key: string, info: RoomInfo) => void;
20
- "room:remove": (key: string, info: RoomInfo) => void;
23
+ "room:remove": (key: string) => void;
21
24
  "plugin:add": (name: string) => void;
22
25
  "plugin:remove": (name: string) => void;
23
26
  "command:add": (name: string) => void;
24
27
  "command:remove": (name: string) => void;
28
+ "store:add": (name: string, id: string, value: any) => void;
29
+ "store:remove": (name: string, id: string) => void;
30
+ "values:register": (name: string) => void;
31
+ "values:change": (name: string, value: any) => void;
32
+ [name: `change:${string}`]: (value: any) => void;
25
33
  error: (err: Error) => void;
26
34
  }
@@ -0,0 +1,5 @@
1
+ import { Message } from "./message";
2
+ export interface FloatingHookMap {
3
+ message: Message.All;
4
+ add: Record<string, any>;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,5 @@
1
1
  export * from "./message";
2
2
  export * from "./plugin";
3
3
  export * from "./room";
4
+ export * from "./command";
5
+ export * from "./events";
@@ -17,3 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./message"), exports);
18
18
  __exportStar(require("./plugin"), exports);
19
19
  __exportStar(require("./room"), exports);
20
+ __exportStar(require("./command"), exports);
21
+ __exportStar(require("./events"), exports);
@@ -16,9 +16,9 @@ export declare namespace Message {
16
16
  /** 其他属性 */
17
17
  [attr: string]: any;
18
18
  }
19
- /** 文本聊天消息 */
20
- interface Chat extends Base {
21
- type: "chat";
19
+ /** 聊天消息 */
20
+ interface Comment extends Base {
21
+ type: "comment";
22
22
  info: {
23
23
  /** 用户信息 */
24
24
  user: UserInfo;
@@ -140,7 +140,43 @@ export declare namespace Message {
140
140
  type: "live_detail";
141
141
  info: RoomDetail;
142
142
  }
143
- type All = Chat | Gift | Interact | Membership | Superchat | Block | LiveStart | LiveEnd | LiveCut | LiveDetail | LiveStats;
143
+ interface Lottery extends Base {
144
+ type: "lottery";
145
+ info: {
146
+ id: number;
147
+ award: GiftInfo;
148
+ };
149
+ }
150
+ interface LotteryResult extends Base {
151
+ type: "lottery_result";
152
+ info: {
153
+ id: number;
154
+ award: GiftInfo;
155
+ result: UserInfo[];
156
+ };
157
+ }
158
+ interface Redpacket extends Base {
159
+ type: "redpacket";
160
+ info: {
161
+ id: number;
162
+ gifts?: GiftInfo[];
163
+ value?: number;
164
+ currency?: string | number;
165
+ };
166
+ }
167
+ interface RedpacketResult extends Base {
168
+ type: "redpacket_result";
169
+ info: {
170
+ id: number;
171
+ result: {
172
+ user: UserInfo;
173
+ gift?: GiftInfo;
174
+ value?: number;
175
+ currency?: string | number;
176
+ }[];
177
+ };
178
+ }
179
+ type All = Comment | Gift | Interact | Membership | Superchat | Block | LiveStart | LiveEnd | LiveCut | LiveDetail | LiveStats | Lottery | LotteryResult | Redpacket | RedpacketResult;
144
180
  }
145
181
  /** 用户信息 */
146
182
  export interface UserInfo {
@@ -200,11 +236,13 @@ export interface GiftInfo {
200
236
  /** 礼物连击id */
201
237
  comboId?: string;
202
238
  /** 人民币价值 */
203
- cny?: number;
239
+ money?: number;
204
240
  /** 行为 */
205
241
  action?: string;
206
242
  /** 随机礼物信息 */
207
243
  blindGift?: GiftInfo;
208
244
  /** 图片信息 */
209
245
  image?: string;
246
+ /** 单位 */
247
+ unit?: string;
210
248
  }
@@ -59,10 +59,8 @@ export interface RoomStatsInfo {
59
59
  export interface PlatformInfo {
60
60
  /** 平台名称 */
61
61
  name: string;
62
- /** 平台id */
63
- id: string;
64
62
  /** 平台vip信息 */
65
- vip: {
63
+ vip?: {
66
64
  /** 平台vip对应id */
67
65
  id: string;
68
66
  /** 平台vip名称 */
@@ -71,7 +69,7 @@ export interface PlatformInfo {
71
69
  level?: string[];
72
70
  };
73
71
  /** 粉丝vip信息 */
74
- membership: {
72
+ membership?: {
75
73
  /** 粉丝vip对应id */
76
74
  id: string;
77
75
  /** 粉丝vip名称 */
@@ -80,16 +78,19 @@ export interface PlatformInfo {
80
78
  level?: string[];
81
79
  };
82
80
  /** 礼物信息 */
83
- gift: {
81
+ gift?: {
82
+ /** 默认送出礼物行为 */
84
83
  action: string;
85
84
  };
85
+ /** 统计信息 */
86
+ stats?: Record<string, string>;
86
87
  /** 货币信息 */
87
- currency: Record<string, {
88
+ currency?: Record<string, {
88
89
  /** 货币名称 */
89
90
  name: string;
90
91
  /** 1货币面值等值value (1面值/1数值) */
91
- face: number;
92
- /** 1人民币等值value (1.00CNY/1数值) (若为0则为免费货币) */
93
- cny?: number;
92
+ ratio: number;
93
+ /** 1单位消费金额等值value (1.00CNY/1数值) (若为0则为免费货币) */
94
+ money?: number;
94
95
  }>;
95
96
  }
@@ -0,0 +1,4 @@
1
+ import { PlatformInfo } from "./room";
2
+ export interface FloatingStoreMap {
3
+ platform: PlatformInfo;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export interface FloatingValueMap {
2
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.15.0-beta.2",
3
+ "version": "0.15.0-beta.4",
4
4
  "type": "commonjs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",