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

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 (42) hide show
  1. package/README.md +3 -34
  2. package/dist/core/LiveRoom.d.ts +0 -2
  3. package/dist/core/index.d.ts +0 -1
  4. package/dist/core/index.js +0 -1
  5. package/dist/core/plugin.d.ts +17 -0
  6. package/dist/core/plugin.js +28 -0
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.js +0 -1
  9. package/dist/live.d.ts +17 -19
  10. package/dist/live.js +19 -38
  11. package/dist/module/command.d.ts +15 -0
  12. package/dist/module/command.js +24 -0
  13. package/dist/module/hook.d.ts +13 -0
  14. package/dist/module/hook.js +44 -0
  15. package/dist/module/plugin.d.ts +15 -0
  16. package/dist/module/{ModPlugin.js → plugin.js} +19 -25
  17. package/dist/module/{ModRoom.d.ts → room.d.ts} +2 -12
  18. package/dist/module/room.js +125 -0
  19. package/dist/module/store.d.ts +14 -0
  20. package/dist/module/store.js +42 -0
  21. package/dist/module/values.d.ts +21 -0
  22. package/dist/module/values.js +41 -0
  23. package/dist/types/events.d.ts +26 -0
  24. package/dist/types/index.d.ts +0 -1
  25. package/dist/types/index.js +0 -1
  26. package/dist/types/plugin.d.ts +9 -2
  27. package/dist/types/room.d.ts +10 -0
  28. package/package.json +8 -15
  29. package/dist/core/Reglist.d.ts +0 -29
  30. package/dist/core/Reglist.js +0 -69
  31. package/dist/module/ModAuth.d.ts +0 -10
  32. package/dist/module/ModAuth.js +0 -35
  33. package/dist/module/ModCommand.d.ts +0 -9
  34. package/dist/module/ModCommand.js +0 -19
  35. package/dist/module/ModMessage.d.ts +0 -9
  36. package/dist/module/ModMessage.js +0 -16
  37. package/dist/module/ModPlugin.d.ts +0 -20
  38. package/dist/module/ModRoom.js +0 -164
  39. package/dist/module/ModState.d.ts +0 -12
  40. package/dist/module/ModState.js +0 -29
  41. package/dist/types/auth.d.ts +0 -19
  42. /package/dist/types/{auth.js → events.js} +0 -0
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Floating Live
2
2
  一个用于处理和保存直播弹幕的Node.js小工具,开箱即用。
3
3
 
4
+ 本体无弹幕获取功能,需要配合[floating-live-danmaku](https://github.com/Minteea/floating-live-danmaku)中的弹幕获取插件使用。
5
+
4
6
  目前支持bilibili和AcFun的直播弹幕,不同平台的弹幕会转换为同一种格式便于保存。
5
7
 
6
8
  项目仍在开发中,功能尚未完善,目前除了记录保存直播弹幕外暂时没有别的用处啦,敬请期待。
@@ -18,7 +20,7 @@ npm install floating-live
18
20
  // 导入FloatingLive
19
21
  const { FloatingLive } = require("floating-live")
20
22
  // 导入bilibili房间生成插件
21
- const bilibili = require("floating-live/plugin/bilibili")
23
+ const bilibili = require("@floating-live/bilibili/plugin")
22
24
 
23
25
  // 创建一个FloatingLive实例
24
26
  const live = new FloatingLive()
@@ -28,36 +30,3 @@ live.plugin.register(bilibili)
28
30
  // 添加房间并自动打开
29
31
  live.room.add("bilibili", 6, true)
30
32
  ```
31
-
32
- ### 拆包即用模式
33
- * 下载并安装 `Node.js` ,建议下载最新LTS版本(如果已经安装可跳过这一步)。
34
- * 下载该项目的zip压缩包,解压,并在项目根目录下新建一个名为 `save` 的文件夹。
35
- * 在项目根目录的控制台输入下列命令,安装所有依赖包。
36
- ```
37
- npm install
38
- ```
39
- #### 运行Demo文件
40
- * 打开demo/demo.ts
41
- ``` typescript
42
- // ...
43
- const config = {
44
- rooms: [
45
- {
46
- platform: "bilibili", // 直播平台
47
- id: 2064239, // 直播间号
48
- },
49
- ],
50
- };
51
- // ...
52
- ```
53
- * 根据需要修改直播平台和直播间号,目前支持的 `platform` 值有:`acfun`、`bilibili`(注意是小写),也可以通过自定义插件添加直播平台
54
- * 在项目根目录的控制台输入下列命令:
55
- ```
56
- npm run test
57
- ```
58
- 即可接收来自平台的直播弹幕。
59
-
60
- ## 感谢
61
- ### 使用开源库
62
- * [simon300000/bilibili-live-ws](https://github.com/simon300000/bilibili-live-ws/)
63
- * [ACFUN-FOSS/ac-danmu](https://github.com/ACFUN-FOSS/ac-danmu.js)
@@ -33,8 +33,6 @@ export declare abstract class LiveRoom extends EventEmitter implements RoomInfo
33
33
  abstract close(): void;
34
34
  /** 从服务器获取信息 */
35
35
  abstract getInfo(): Promise<void>;
36
- /** 设置用户凭据 */
37
- setAuth?(auth: string): void;
38
36
  /** 销毁事件 */
39
37
  protected onDestory?(): void;
40
38
  /** 销毁 */
@@ -1,2 +1 @@
1
1
  export * from "./LiveRoom";
2
- export * from "./Reglist";
@@ -15,4 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./LiveRoom"), exports);
18
- __exportStar(require("./Reglist"), exports);
@@ -0,0 +1,17 @@
1
+ import { FloatingLive } from "../live";
2
+ import { FloatingEventMap } from "../types/events";
3
+ export declare abstract class BasePlugin {
4
+ static pluginName: string;
5
+ protected main: FloatingLive;
6
+ private registerList;
7
+ constructor(main: FloatingLive);
8
+ /** 插件监听事件 */
9
+ on<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): void;
10
+ /** 插件一次性监听事件 */
11
+ once<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): void;
12
+ /** 插件移除监听事件 */
13
+ off<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): void;
14
+ /** 插件发送事件 */
15
+ emit<T extends keyof FloatingEventMap>(eventName: T, ...args: Parameters<FloatingEventMap[T]>): void;
16
+ abstract destroy(): void;
17
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasePlugin = void 0;
4
+ class BasePlugin {
5
+ constructor(main) {
6
+ this.registerList = [];
7
+ this.main = main;
8
+ }
9
+ /** 插件监听事件 */
10
+ on(eventName, listener) {
11
+ this.main.on(eventName, listener);
12
+ this.registerList.push(["event", eventName, listener]);
13
+ }
14
+ /** 插件一次性监听事件 */
15
+ once(eventName, listener) {
16
+ this.main.once(eventName, listener);
17
+ this.registerList.push(["event", eventName, listener]);
18
+ }
19
+ /** 插件移除监听事件 */
20
+ off(eventName, listener) {
21
+ this.main.off(eventName, listener);
22
+ }
23
+ /** 插件发送事件 */
24
+ emit(eventName, ...args) {
25
+ this.main.emit(eventName, ...args);
26
+ }
27
+ }
28
+ exports.BasePlugin = BasePlugin;
package/dist/index.d.ts CHANGED
@@ -2,5 +2,4 @@ export { FloatingLive } from "./live";
2
2
  export * from "./types";
3
3
  export * from "./enums";
4
4
  export * from "./core/LiveRoom";
5
- export * from "./core/Reglist";
6
5
  export * from "./utils";
package/dist/index.js CHANGED
@@ -20,5 +20,4 @@ Object.defineProperty(exports, "FloatingLive", { enumerable: true, get: function
20
20
  __exportStar(require("./types"), exports);
21
21
  __exportStar(require("./enums"), exports);
22
22
  __exportStar(require("./core/LiveRoom"), exports);
23
- __exportStar(require("./core/Reglist"), exports);
24
23
  __exportStar(require("./utils"), exports);
package/dist/live.d.ts CHANGED
@@ -1,30 +1,28 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from "events";
3
- import { ModPlugin } from "./module/ModPlugin";
4
- import { ModRoom } from "./module/ModRoom";
5
- import { ModAuth } from "./module/ModAuth";
6
- import { ModMessage } from "./module/ModMessage";
7
- import { ModState } from "./module/ModState";
8
- import ModCommand from "./module/ModCommand";
3
+ import { ModPlugin } from "./module/plugin";
4
+ import { ModRoom } from "./module/room";
5
+ import { ModStore } from "./module/store";
6
+ import ModCommand from "./module/command";
7
+ import { ModValues } from "./module/values";
8
+ import { ModHook } from "./module/hook";
9
+ import { FloatingEventMap } from "./types/events";
9
10
  export declare class FloatingLive extends EventEmitter {
10
11
  /** 房间控制模块 */
11
12
  room: ModRoom;
12
- /** 消息处理模块 */
13
- message: ModMessage;
14
- /** 用户登录凭据模块 */
15
- auth: ModAuth;
16
13
  /** 插件处理模块 */
17
- plugin: ModPlugin<this>;
14
+ plugin: ModPlugin;
18
15
  /** 命令模块 */
19
16
  command: ModCommand;
20
17
  /** 状态模块 */
21
- state: ModState;
22
- /** 插件事件注册表 */
23
- private regEventMap;
18
+ store: ModStore;
19
+ /** 数值模块 */
20
+ values: ModValues;
21
+ /** 数值模块 */
22
+ hook: ModHook;
24
23
  constructor();
25
- /** 初始化 */
26
- private init;
27
- /** 重写事件监听 */
28
- on(eventName: string, listener: (...args: any[]) => void): this;
29
- emit(eventName: string | symbol, ...args: any[]): boolean;
24
+ call(name: string, ...args: any[]): any;
25
+ on<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): this;
26
+ emit<T extends keyof FloatingEventMap>(eventName: T, ...args: any[]): boolean;
27
+ throw(err: Error): void;
30
28
  }
package/dist/live.js CHANGED
@@ -5,52 +5,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FloatingLive = void 0;
7
7
  const events_1 = require("events");
8
- const ModPlugin_1 = require("./module/ModPlugin");
9
- const ModRoom_1 = require("./module/ModRoom");
10
- const ModAuth_1 = require("./module/ModAuth");
11
- const ModMessage_1 = require("./module/ModMessage");
12
- const ModState_1 = require("./module/ModState");
13
- const ModCommand_1 = __importDefault(require("./module/ModCommand"));
8
+ const plugin_1 = require("./module/plugin");
9
+ const room_1 = require("./module/room");
10
+ const store_1 = require("./module/store");
11
+ const command_1 = __importDefault(require("./module/command"));
12
+ const values_1 = require("./module/values");
13
+ const hook_1 = require("./module/hook");
14
14
  class FloatingLive extends events_1.EventEmitter {
15
15
  constructor() {
16
16
  super();
17
- /** 插件事件注册表 */
18
- this.regEventMap = new Map();
19
- this.command = new ModCommand_1.default(this);
20
- this.state = new ModState_1.ModState(this);
21
- this.plugin = new ModPlugin_1.ModPlugin(this);
22
- this.room = new ModRoom_1.ModRoom(this);
23
- this.message = new ModMessage_1.ModMessage(this);
24
- this.auth = new ModAuth_1.ModAuth(this);
25
- this.init();
17
+ this.command = new command_1.default(this);
18
+ this.store = new store_1.ModStore(this);
19
+ this.plugin = new plugin_1.ModPlugin(this);
20
+ this.room = new room_1.ModRoom(this);
21
+ this.values = new values_1.ModValues(this);
22
+ this.hook = new hook_1.ModHook(this);
26
23
  }
27
- /** 初始化 */
28
- init() {
29
- // 设置在插件卸载时移除由插件注册的事件
30
- this.on("plugin:remove", (name) => {
31
- this.regEventMap.get(name)?.forEach(([eventName, listener]) => {
32
- this.removeListener(eventName, listener);
33
- });
34
- });
24
+ call(name, ...args) {
25
+ return this.command.call(name, ...args);
35
26
  }
36
- /** 重写事件监听 */
37
27
  on(eventName, listener) {
38
- super.on(eventName, listener);
39
- // 检测是否为插件添加事件,并添加进事件列表
40
- if (this.plugin.currentPlugin) {
41
- if (!this.regEventMap.has(this.plugin.currentPlugin)) {
42
- this.regEventMap.set(this.plugin.currentPlugin, []);
43
- }
44
- this.regEventMap
45
- .get(this.plugin.currentPlugin)
46
- ?.push([eventName, listener]);
47
- }
48
- return this;
28
+ return super.on(eventName, listener);
49
29
  }
50
30
  emit(eventName, ...args) {
51
- const result = super.emit(eventName, ...args);
52
- super.emit("event", eventName, ...args);
53
- return result;
31
+ return super.emit(eventName, ...args);
32
+ }
33
+ throw(err) {
34
+ this.emit("error", err);
54
35
  }
55
36
  }
56
37
  exports.FloatingLive = FloatingLive;
@@ -0,0 +1,15 @@
1
+ import { FloatingLive } from "../live";
2
+ declare type CommandFunction = (...args: any[]) => any;
3
+ export default class ModCommand {
4
+ /** 功能列表 */
5
+ private readonly list;
6
+ protected readonly main: FloatingLive;
7
+ constructor(main: FloatingLive);
8
+ /** 注册命令 */
9
+ register(name: string, func: CommandFunction): void;
10
+ /** 取消注册命令 */
11
+ unregister(name: string): void;
12
+ /** 调用命令 */
13
+ call(name: string, ...args: any[]): any;
14
+ }
15
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ModCommand {
4
+ constructor(main) {
5
+ /** 功能列表 */
6
+ this.list = new Map();
7
+ this.main = main;
8
+ }
9
+ /** 注册命令 */
10
+ register(name, func) {
11
+ this.list.set(name, func);
12
+ this.main.emit("command:add", name);
13
+ }
14
+ /** 取消注册命令 */
15
+ unregister(name) {
16
+ this.list.delete(name);
17
+ this.main.emit("command:remove", name);
18
+ }
19
+ /** 调用命令 */
20
+ call(name, ...args) {
21
+ return this.list.get(name)?.(...args);
22
+ }
23
+ }
24
+ exports.default = ModCommand;
@@ -0,0 +1,13 @@
1
+ import { FloatingLive } from "../live";
2
+ export declare type HookFunction<T> = (ctx: T) => boolean | void | Promise<boolean | void>;
3
+ export declare class ModHook {
4
+ private list;
5
+ protected readonly main: FloatingLive;
6
+ constructor(main: FloatingLive);
7
+ /** 注册钩子函数 */
8
+ register<T>(name: string, func: HookFunction<T>): void;
9
+ /** 取消注册钩子函数 */
10
+ unregister(name: string, func: HookFunction<any>): void;
11
+ /** 调用钩子函数 */
12
+ call<T>(name: string, ctx: T): Promise<boolean>;
13
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModHook = void 0;
4
+ class ModHook {
5
+ constructor(main) {
6
+ this.list = new Map();
7
+ this.main = main;
8
+ }
9
+ /** 注册钩子函数 */
10
+ register(name, func) {
11
+ let hooks = this.list.get(name);
12
+ if (!hooks) {
13
+ hooks = [];
14
+ this.list.set(name, hooks);
15
+ }
16
+ hooks.push(func);
17
+ }
18
+ /** 取消注册钩子函数 */
19
+ unregister(name, func) {
20
+ let hooks = this.list.get(name);
21
+ if (hooks) {
22
+ const index = hooks.indexOf(func);
23
+ index > -1 && hooks.splice(index, 1);
24
+ }
25
+ }
26
+ /** 调用钩子函数 */
27
+ async call(name, ctx) {
28
+ const hooks = this.list.get(name);
29
+ if (!hooks) {
30
+ return true;
31
+ }
32
+ for (const func of hooks) {
33
+ const result = await func(ctx);
34
+ if (result == true) {
35
+ return true;
36
+ }
37
+ else if (result == false) {
38
+ return false;
39
+ }
40
+ }
41
+ return false;
42
+ }
43
+ }
44
+ exports.ModHook = ModHook;
@@ -0,0 +1,15 @@
1
+ import { FloatingLive } from "../live";
2
+ import { PluginConstructor } from "../types/plugin";
3
+ export declare class ModPlugin {
4
+ private current;
5
+ /** 插件列表 */
6
+ private list;
7
+ protected readonly main: FloatingLive;
8
+ constructor(main: FloatingLive);
9
+ /** 获取当前安装插件 */
10
+ get currentPlugin(): string | null;
11
+ /** 注册插件 */
12
+ register(pluginFunc: PluginConstructor, config?: any): void;
13
+ /** 移除插件 */
14
+ unregister(name: string): void;
15
+ }
@@ -6,50 +6,44 @@ class ModPlugin {
6
6
  this.current = null;
7
7
  /** 插件列表 */
8
8
  this.list = new Map();
9
- this.pluginEvent = new Map();
10
- this.exports = new Map();
11
9
  this.main = main;
12
10
  }
13
11
  /** 获取当前安装插件 */
14
12
  get currentPlugin() {
15
13
  return this.current;
16
14
  }
17
- addPluginEvent(eventName, listener) {
18
- if (this.currentPlugin) {
19
- if (!this.pluginEvent.has(this.currentPlugin)) {
20
- this.pluginEvent.set(this.currentPlugin, []);
21
- }
22
- this.pluginEvent.get(this.currentPlugin)?.push([eventName, listener]);
23
- }
24
- }
25
- /** 访问插件操作对象 */
26
- access(name) {
27
- return this.exports.get(name);
28
- }
29
15
  /** 注册插件 */
30
- register(pluginFunc, pluginConfig) {
31
- // 执行插件函数
32
- const plugin = pluginFunc();
33
- const name = plugin.name;
16
+ register(pluginFunc, config) {
17
+ const name = pluginFunc.name;
18
+ if (!name) {
19
+ this.main.throw(Object.assign(new TypeError("缺少插件id"), {
20
+ from: "plugin",
21
+ signal: "plugin_id_missing",
22
+ }));
23
+ return;
24
+ }
34
25
  if (this.list.has(name)) {
35
- this.main.emit("plugin:duplicate", name);
26
+ this.main.throw(Object.assign(new Error("插件id重复"), {
27
+ from: "plugin",
28
+ signal: "plugin_id_duplicate",
29
+ }));
36
30
  return;
37
31
  }
32
+ // 执行插件函数
33
+ const plugin = new pluginFunc(this.main, config);
38
34
  this.list.set(name, plugin);
39
- this.current = name;
40
- // 调用register函数,并保存获取值
41
- let pluginExpose = plugin.register?.(this.main, pluginConfig) || {};
42
- this.exports.set(name, pluginExpose);
43
35
  this.main.emit("plugin:add", name);
44
36
  this.current = null;
45
- return pluginExpose;
46
37
  }
47
38
  /** 移除插件 */
48
39
  unregister(name) {
49
40
  const plugin = this.list.get(name);
50
41
  // 检测插件是否存在
51
42
  if (!plugin) {
52
- this.main.emit("plugin:unexist", name);
43
+ this.main.throw(Object.assign(new Error("插件不存在"), {
44
+ from: "plugin",
45
+ signal: "plugin_unexist",
46
+ }));
53
47
  return;
54
48
  }
55
49
  // 获取该插件的销毁函数
@@ -1,25 +1,15 @@
1
- import { Reglist } from "../core/Reglist";
2
1
  import { LiveRoom } from "../core/LiveRoom";
3
2
  import { FloatingLive } from "../live";
4
3
  import { RoomInfo } from "../types";
5
4
  /** 直播间监听实例控制器 */
6
5
  export declare class ModRoom {
6
+ private list;
7
7
  readonly main: FloatingLive;
8
- private roomMap;
9
- private auths;
10
- private configs;
11
- generator: Reglist<(id: string | number, open?: boolean, config?: object) => LiveRoom>;
12
8
  constructor(main: FloatingLive);
13
- /** 设置登录凭据 */
14
- setAuth(platform: string, auth: string): void;
15
- /** 设置房间配置 */
16
- setConfig(platform: string, config: any): void;
17
- /** 生成房间 */
18
- generate(platform: string, id: string | number, open?: boolean): LiveRoom | undefined;
19
9
  /** 添加房间监听实例 */
20
10
  addRoom(room: LiveRoom, open?: boolean): void;
21
11
  /** 添加房间 */
22
- add(platform: string, id: number, open: boolean): void;
12
+ add(platform: string, id: number, config?: boolean | Record<string, any>): void;
23
13
  /** 移除房间 */
24
14
  remove(roomKey: string): void;
25
15
  /** 获取房间 */
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModRoom = void 0;
4
+ /** 直播间监听实例控制器 */
5
+ class ModRoom {
6
+ constructor(main) {
7
+ this.list = new Map();
8
+ this.main = main;
9
+ const { command } = main;
10
+ command.register("add", this.add.bind(this));
11
+ command.register("remove", this.remove.bind(this));
12
+ command.register("open", this.open.bind(this));
13
+ command.register("close", this.close.bind(this));
14
+ command.register("update", this.update.bind(this));
15
+ }
16
+ /** 添加房间监听实例 */
17
+ addRoom(room, open) {
18
+ let key = room.key;
19
+ if (this.list.has(key)) {
20
+ this.main.throw(Object.assign(new Error("房间已存在"), {
21
+ from: "room",
22
+ signal: "room_exist",
23
+ }));
24
+ return;
25
+ }
26
+ this.list.set(key, room);
27
+ // 添加监听事件
28
+ // 直播消息
29
+ room.on("msg", (data) => {
30
+ this.main.hook.call("message", data).then((res) => {
31
+ res && this.main.emit("live:message", data);
32
+ });
33
+ });
34
+ // 直播消息源数据
35
+ room.on("raw", (data, { platform, room }) => {
36
+ this.main.emit("live:raw", data, { platform, room });
37
+ });
38
+ // 连接到直播间
39
+ room.on("connect", () => {
40
+ this.main.emit("room:connect", key);
41
+ });
42
+ // 与直播间的连接已断开
43
+ room.on("disconnect", () => {
44
+ this.main.emit("room:disconnect", key);
45
+ });
46
+ // 获取房间信息
47
+ room.on("info", () => {
48
+ this.main.emit("room:info", key, room.info);
49
+ });
50
+ // 直播展示信息更改
51
+ room.on("detail", (data) => {
52
+ this.main.emit("room:detail", key, data);
53
+ });
54
+ // 直播状态更改
55
+ room.on("status", (status, { id, timestamp }) => {
56
+ this.main.emit("room:status", key, { status, id, timestamp });
57
+ });
58
+ // 统计数据更新
59
+ room.on("stats", (data) => {
60
+ this.main.emit("room:stats", key, data);
61
+ });
62
+ // 房间被打开
63
+ room.on("open", () => {
64
+ this.main.emit("room:open", key, room.info);
65
+ });
66
+ // 房间被关闭
67
+ room.on("close", () => {
68
+ this.main.emit("room:close", key, room.info);
69
+ });
70
+ if (open) {
71
+ room.open();
72
+ }
73
+ this.main.emit("room:add", key, room.info);
74
+ }
75
+ /** 添加房间 */
76
+ add(platform, id, config) {
77
+ if (typeof config == "boolean") {
78
+ config = { open: config };
79
+ }
80
+ const room = this.main.call(platform, id, config);
81
+ room && this.addRoom(room);
82
+ }
83
+ /** 移除房间 */
84
+ remove(roomKey) {
85
+ let room = this.list.get(roomKey);
86
+ if (!room) {
87
+ this.main.throw(Object.assign(new Error("房间不存在"), {
88
+ from: "room",
89
+ signal: "room_unexist",
90
+ }));
91
+ }
92
+ this.list.delete(roomKey); // 从表中删除房间
93
+ room?.removeAllListeners(); // 移除房间监听实例
94
+ this.main.emit("room:remove", roomKey);
95
+ }
96
+ /** 获取房间 */
97
+ get(roomKey) {
98
+ return this.list.get(roomKey);
99
+ }
100
+ /** 获取房间信息 */
101
+ info(roomKey) {
102
+ let room = this.list.get(roomKey);
103
+ return room ? room.info : undefined;
104
+ }
105
+ /** 更新房间信息 */
106
+ update(roomKey) {
107
+ let room = this.list.get(roomKey);
108
+ room && room.getInfo();
109
+ }
110
+ /** 获取roomKey列表 */
111
+ get keys() {
112
+ return [...this.list.keys()];
113
+ }
114
+ /** 打开房间连接 */
115
+ open(roomKey) {
116
+ let room = this.list.get(roomKey);
117
+ room?.available && !room.opened && room.open();
118
+ }
119
+ /** 关闭房间连接 */
120
+ close(roomKey) {
121
+ let room = this.list.get(roomKey);
122
+ room?.opened && room.close();
123
+ }
124
+ }
125
+ exports.ModRoom = ModRoom;
@@ -0,0 +1,14 @@
1
+ import { FloatingLive } from "../live";
2
+ export declare class ModStore {
3
+ private list;
4
+ protected readonly main: FloatingLive;
5
+ constructor(main: FloatingLive);
6
+ /** 注册钩子函数 */
7
+ register<T>(name: string, id: string, value: T): void;
8
+ /** 取消注册钩子函数 */
9
+ unregister(name: string, id: string): void;
10
+ /** 获取值 */
11
+ get(name: string): Map<string, any> | undefined;
12
+ /** 获取注册的所有值 */
13
+ getMap(): Record<string, Record<string, any>>;
14
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModStore = void 0;
4
+ class ModStore {
5
+ constructor(main) {
6
+ this.list = new Map();
7
+ this.main = main;
8
+ }
9
+ /** 注册钩子函数 */
10
+ register(name, id, value) {
11
+ let store = this.list.get(name);
12
+ if (!store) {
13
+ store = new Map();
14
+ this.list.set(name, store);
15
+ }
16
+ store.set(id, value);
17
+ }
18
+ /** 取消注册钩子函数 */
19
+ unregister(name, id) {
20
+ let store = this.list.get(name);
21
+ if (store) {
22
+ store.delete(id);
23
+ }
24
+ }
25
+ /** 获取值 */
26
+ get(name) {
27
+ return this.list.get(name);
28
+ }
29
+ /** 获取注册的所有值 */
30
+ getMap() {
31
+ const map = {};
32
+ this.list.forEach((store, name) => {
33
+ const part = {};
34
+ map[name] = part;
35
+ store.forEach((value, id) => {
36
+ part[id] = value;
37
+ });
38
+ });
39
+ return map;
40
+ }
41
+ }
42
+ exports.ModStore = ModStore;