floating-live 0.16.4 → 0.16.6

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.
@@ -1,8 +1,10 @@
1
1
  import { LiveRoom } from "./index.js";
2
2
  import { App } from "./app.js";
3
3
  import { Room } from "./plugins/room/index.js";
4
+ import { Platform } from "./plugins/platform/index.js";
4
5
  export declare class FloatingLive extends App {
5
6
  room: Room;
7
+ platform: Platform;
6
8
  constructor();
7
9
  /** 添加房间 */
8
10
  add(platform: string, id: number, options?: boolean | Record<string, any>): Promise<void>;
@@ -1,9 +1,11 @@
1
1
  import { App } from "./app.js";
2
2
  import { Room } from "./plugins/room/index.js";
3
+ import { Platform } from "./plugins/platform/index.js";
3
4
  export class FloatingLive extends App {
4
5
  constructor() {
5
6
  super();
6
7
  this.room = this.registerSync(Room, { core: true });
8
+ this.platform = this.registerSync(Platform, { core: true });
7
9
  }
8
10
  /** 添加房间 */
9
11
  add(platform, id, options) {
@@ -82,7 +82,7 @@ export declare namespace LiveMessage {
82
82
  type: "superchat";
83
83
  info: {
84
84
  /** 留言id */
85
- id: string;
85
+ id: string | number;
86
86
  /** 用户信息 */
87
87
  user: UserInfo;
88
88
  /** 文本内容 */
@@ -145,24 +145,36 @@ export declare namespace LiveMessage {
145
145
  interface Lottery extends Base {
146
146
  type: "lottery";
147
147
  info: {
148
- id: number;
149
- award: GiftInfo;
148
+ title: string;
149
+ role: "user" | "anchor";
150
+ user?: UserInfo;
151
+ gift?: GiftInfo;
152
+ id: string | number;
153
+ award?: GiftInfo | GiftInfo[];
154
+ value?: number;
155
+ valueType?: string | number;
156
+ price?: number;
157
+ currency?: string;
150
158
  };
151
159
  }
152
160
  /** 主播抽奖结果 */
153
161
  interface LotteryResult extends Base {
154
162
  type: "lottery_result";
155
163
  info: {
156
- id: number;
157
- award: GiftInfo;
158
- result: UserInfo[];
164
+ title: string;
165
+ role: "user" | "anchor";
166
+ id: string | number;
167
+ result: {
168
+ user: UserInfo;
169
+ award: GiftInfo | GiftInfo[];
170
+ }[];
159
171
  };
160
172
  }
161
173
  /** 发送红包 */
162
174
  interface Redpacket extends Base {
163
175
  type: "redpacket";
164
176
  info: {
165
- id: number;
177
+ id: string | number;
166
178
  gifts?: GiftInfo[];
167
179
  value?: number;
168
180
  currency?: string | number;
@@ -172,7 +184,7 @@ export declare namespace LiveMessage {
172
184
  interface RedpacketResult extends Base {
173
185
  type: "redpacket_result";
174
186
  info: {
175
- id: number;
187
+ id: string | number;
176
188
  result: {
177
189
  user: UserInfo;
178
190
  gift?: GiftInfo;
@@ -181,5 +193,5 @@ export declare namespace LiveMessage {
181
193
  }[];
182
194
  };
183
195
  }
184
- type All = Comment | Gift | Interact | Membership | Superchat | Block | LiveStart | LiveEnd | LiveCut | LiveDetail | LiveStats | Lottery | LotteryResult | Redpacket | RedpacketResult;
196
+ type All = Comment | Gift | Interact | Membership | Superchat | Block | LiveStart | LiveEnd | LiveCut | LiveDetail | LiveStats | Lottery | LotteryResult;
185
197
  }
@@ -3,7 +3,7 @@ import type { PluginItem, PluginContext } from "./types.js";
3
3
  export type * from "./types.js";
4
4
  export declare class BasePlugin implements PluginItem {
5
5
  static pluginName: string;
6
- pluginName: string;
6
+ get pluginName(): string;
7
7
  ctx: PluginContext;
8
8
  readonly Error: typeof AppError;
9
9
  readonly throw: (err?: Error) => void;
@@ -1,5 +1,8 @@
1
1
  import { AppError } from "../error/index.js";
2
2
  export class BasePlugin {
3
+ get pluginName() {
4
+ return this.constructor.pluginName;
5
+ }
3
6
  constructor(ctx, options) {
4
7
  this.Error = AppError;
5
8
  this.ctx = ctx;
@@ -6,7 +6,10 @@ import { AppHookMap, HookCallOptions, HookContext, HookFunction, HookUseOptions
6
6
  import { AppValueMap, ValueContext, ValueOptions } from "../value/index.js";
7
7
  /** 插件对象 */
8
8
  export interface PluginItem {
9
+ /** 插件名称 */
9
10
  pluginName: string;
11
+ /** 插件作用 */
12
+ role?: string;
10
13
  /** 初始化插件 */
11
14
  init?(ctx: PluginContext, options?: Record<string, any>): void | Promise<void>;
12
15
  /** 插件销毁 */
@@ -0,0 +1,50 @@
1
+ import { BasePlugin, LivePlatformInfo } from "../../index.js";
2
+ interface PluginExposes {
3
+ register(name: string, info: LivePlatformInfo, signal: AbortSignal): void;
4
+ get(name: string): LivePlatformInfo | undefined;
5
+ toSnapshot(): {
6
+ name: string;
7
+ }[];
8
+ }
9
+ declare module "../../index.js" {
10
+ interface AppPluginExposesMap {
11
+ platform: PluginExposes;
12
+ }
13
+ interface AppEventDetailMap {
14
+ "platform:register": {
15
+ name: string;
16
+ info: LivePlatformInfo;
17
+ };
18
+ "platform:unregister": {
19
+ name: string;
20
+ };
21
+ }
22
+ interface AppCommandMap {
23
+ "platform.snapshot": () => {
24
+ name: string;
25
+ info: LivePlatformInfo;
26
+ }[];
27
+ }
28
+ interface AppSnapshotMap {
29
+ platform: {
30
+ name: string;
31
+ info: LivePlatformInfo;
32
+ }[];
33
+ }
34
+ }
35
+ export declare class Platform extends BasePlugin {
36
+ static pluginName: string;
37
+ private list;
38
+ /** 注册直播平台信息 */
39
+ register(name: string, info: LivePlatformInfo, signal?: AbortSignal): void;
40
+ /** 解除注册直播平台信息 */
41
+ unregister(name: string): void;
42
+ /** 获取直播平台信息 */
43
+ get(name: string): LivePlatformInfo | undefined;
44
+ expose(): PluginExposes;
45
+ toSnapshot(): {
46
+ name: string;
47
+ info: LivePlatformInfo;
48
+ }[];
49
+ }
50
+ export default Platform;
@@ -0,0 +1,48 @@
1
+ import { BasePlugin } from "../../index.js";
2
+ export class Platform extends BasePlugin {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.list = new Map();
6
+ }
7
+ /** 注册直播平台信息 */
8
+ register(name, info, signal) {
9
+ if (this.list.has(name)) {
10
+ throw new this.Error("platform:register_duplicated", {
11
+ message: "平台信息重复注册",
12
+ });
13
+ }
14
+ this.list.set(name, info);
15
+ if (signal) {
16
+ signal.addEventListener("abort", () => {
17
+ this.unregister(name);
18
+ }, { once: true });
19
+ }
20
+ }
21
+ /** 解除注册直播平台信息 */
22
+ unregister(name) {
23
+ if (!this.list.has(name)) {
24
+ throw new this.Error("platform:unregister_unexisted", {
25
+ message: "无法解除不存在的平台信息注册",
26
+ });
27
+ }
28
+ this.list.delete(name);
29
+ }
30
+ /** 获取直播平台信息 */
31
+ get(name) {
32
+ return this.list.get(name);
33
+ }
34
+ expose() {
35
+ return {
36
+ register: (name, info, signal) => {
37
+ this.register(name, info, signal);
38
+ },
39
+ get: (name) => this.get(name),
40
+ toSnapshot: () => this.toSnapshot(),
41
+ };
42
+ }
43
+ toSnapshot() {
44
+ return [...this.list].map(([name, info]) => ({ name, info }));
45
+ }
46
+ }
47
+ Platform.pluginName = "platform";
48
+ export default Platform;
@@ -30,8 +30,11 @@ declare module "../../index.js" {
30
30
  message: LiveMessage.All;
31
31
  };
32
32
  "live:raw": {
33
+ /** 平台 */
33
34
  platform: string;
34
35
  roomId: string | number;
36
+ /** 服务来源 */
37
+ service?: string;
35
38
  data: any;
36
39
  };
37
40
  "room:connecting": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.16.4",
3
+ "version": "0.16.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",