floating-live 0.15.0-beta.1 → 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.
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/core/plugin.d.ts +17 -0
- package/dist/core/plugin.js +28 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/live.d.ts +17 -16
- package/dist/live.js +19 -36
- package/dist/module/command.d.ts +15 -0
- package/dist/module/command.js +24 -0
- package/dist/module/hook.d.ts +13 -0
- package/dist/module/hook.js +44 -0
- package/dist/module/plugin.d.ts +15 -0
- package/dist/module/{ModPlugin.js → plugin.js} +19 -25
- package/dist/module/{ModRoom.d.ts → room.d.ts} +2 -10
- package/dist/module/{ModRoom.js → room.js} +35 -65
- package/dist/module/store.d.ts +14 -0
- package/dist/module/store.js +42 -0
- package/dist/module/values.d.ts +21 -0
- package/dist/module/values.js +41 -0
- package/dist/types/events.d.ts +26 -0
- package/dist/types/events.js +2 -0
- package/dist/types/plugin.d.ts +9 -2
- package/dist/types/room.d.ts +10 -0
- package/package.json +1 -1
- package/dist/core/Reglist.d.ts +0 -29
- package/dist/core/Reglist.js +0 -69
- package/dist/module/ModCommand.d.ts +0 -9
- package/dist/module/ModCommand.js +0 -19
- package/dist/module/ModMessage.d.ts +0 -9
- package/dist/module/ModMessage.js +0 -16
- package/dist/module/ModPlugin.d.ts +0 -20
- package/dist/module/ModState.d.ts +0 -12
- package/dist/module/ModState.js +0 -29
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -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
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,27 +1,28 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
|
-
import { ModPlugin } from "./module/
|
|
4
|
-
import { ModRoom } from "./module/
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
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";
|
|
8
10
|
export declare class FloatingLive extends EventEmitter {
|
|
9
11
|
/** 房间控制模块 */
|
|
10
12
|
room: ModRoom;
|
|
11
|
-
/** 消息处理模块 */
|
|
12
|
-
message: ModMessage;
|
|
13
13
|
/** 插件处理模块 */
|
|
14
|
-
plugin: ModPlugin
|
|
14
|
+
plugin: ModPlugin;
|
|
15
15
|
/** 命令模块 */
|
|
16
16
|
command: ModCommand;
|
|
17
17
|
/** 状态模块 */
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
|
|
18
|
+
store: ModStore;
|
|
19
|
+
/** 数值模块 */
|
|
20
|
+
values: ModValues;
|
|
21
|
+
/** 数值模块 */
|
|
22
|
+
hook: ModHook;
|
|
21
23
|
constructor();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
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;
|
|
27
28
|
}
|
package/dist/live.js
CHANGED
|
@@ -5,50 +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
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
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");
|
|
13
14
|
class FloatingLive extends events_1.EventEmitter {
|
|
14
15
|
constructor() {
|
|
15
16
|
super();
|
|
16
|
-
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.message = new ModMessage_1.ModMessage(this);
|
|
23
|
-
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);
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// 设置在插件卸载时移除由插件注册的事件
|
|
28
|
-
this.on("plugin:remove", (name) => {
|
|
29
|
-
this.regEventMap.get(name)?.forEach(([eventName, listener]) => {
|
|
30
|
-
this.removeListener(eventName, listener);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
24
|
+
call(name, ...args) {
|
|
25
|
+
return this.command.call(name, ...args);
|
|
33
26
|
}
|
|
34
|
-
/** 重写事件监听 */
|
|
35
27
|
on(eventName, listener) {
|
|
36
|
-
super.on(eventName, listener);
|
|
37
|
-
// 检测是否为插件添加事件,并添加进事件列表
|
|
38
|
-
if (this.plugin.currentPlugin) {
|
|
39
|
-
if (!this.regEventMap.has(this.plugin.currentPlugin)) {
|
|
40
|
-
this.regEventMap.set(this.plugin.currentPlugin, []);
|
|
41
|
-
}
|
|
42
|
-
this.regEventMap
|
|
43
|
-
.get(this.plugin.currentPlugin)
|
|
44
|
-
?.push([eventName, listener]);
|
|
45
|
-
}
|
|
46
|
-
return this;
|
|
28
|
+
return super.on(eventName, listener);
|
|
47
29
|
}
|
|
48
30
|
emit(eventName, ...args) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
31
|
+
return super.emit(eventName, ...args);
|
|
32
|
+
}
|
|
33
|
+
throw(err) {
|
|
34
|
+
this.emit("error", err);
|
|
52
35
|
}
|
|
53
36
|
}
|
|
54
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,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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.
|
|
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.
|
|
43
|
+
this.main.throw(Object.assign(new Error("插件不存在"), {
|
|
44
|
+
from: "plugin",
|
|
45
|
+
signal: "plugin_unexist",
|
|
46
|
+
}));
|
|
53
47
|
return;
|
|
54
48
|
}
|
|
55
49
|
// 获取该插件的销毁函数
|
|
@@ -1,23 +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
|
-
setConfig(platform: string, config: any): void;
|
|
15
|
-
/** 生成房间 */
|
|
16
|
-
generate(platform: string, id: string | number, open?: boolean): LiveRoom | undefined;
|
|
17
9
|
/** 添加房间监听实例 */
|
|
18
10
|
addRoom(room: LiveRoom, open?: boolean): void;
|
|
19
11
|
/** 添加房间 */
|
|
20
|
-
add(platform: string, id: number,
|
|
12
|
+
add(platform: string, id: number, config?: boolean | Record<string, any>): void;
|
|
21
13
|
/** 移除房间 */
|
|
22
14
|
remove(roomKey: string): void;
|
|
23
15
|
/** 获取房间 */
|
|
@@ -1,70 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ModRoom = void 0;
|
|
4
|
-
const Reglist_1 = require("../core/Reglist");
|
|
5
4
|
/** 直播间监听实例控制器 */
|
|
6
5
|
class ModRoom {
|
|
7
6
|
constructor(main) {
|
|
8
|
-
this.
|
|
9
|
-
this.auths = new Map();
|
|
10
|
-
this.configs = new Map();
|
|
7
|
+
this.list = new Map();
|
|
11
8
|
this.main = main;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return { list };
|
|
19
|
-
});
|
|
20
|
-
this.main.command.batchRegister({
|
|
21
|
-
add: (platform, id, open) => {
|
|
22
|
-
this.add(platform, id, open);
|
|
23
|
-
},
|
|
24
|
-
remove: (key) => {
|
|
25
|
-
this.remove(key);
|
|
26
|
-
},
|
|
27
|
-
open: (key) => {
|
|
28
|
-
this.open(key);
|
|
29
|
-
},
|
|
30
|
-
close: (key) => {
|
|
31
|
-
this.close(key);
|
|
32
|
-
},
|
|
33
|
-
update: (key) => {
|
|
34
|
-
this.update(key);
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
/** 设置房间配置 */
|
|
39
|
-
setConfig(platform, config) {
|
|
40
|
-
this.configs.set(platform, config);
|
|
41
|
-
}
|
|
42
|
-
/** 生成房间 */
|
|
43
|
-
generate(platform, id, open) {
|
|
44
|
-
platform = platform.toLowerCase();
|
|
45
|
-
const config = this.configs.get(platform) || {};
|
|
46
|
-
const auth = this.auths.get(platform);
|
|
47
|
-
let platformGenerator = this.generator.get(platform);
|
|
48
|
-
if (platformGenerator) {
|
|
49
|
-
return platformGenerator(id, open, { auth, ...config });
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
this.main.emit("room:unknown_platform", platform);
|
|
53
|
-
}
|
|
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));
|
|
54
15
|
}
|
|
55
16
|
/** 添加房间监听实例 */
|
|
56
17
|
addRoom(room, open) {
|
|
57
18
|
let key = room.key;
|
|
58
|
-
if (this.
|
|
59
|
-
this.main.
|
|
19
|
+
if (this.list.has(key)) {
|
|
20
|
+
this.main.throw(Object.assign(new Error("房间已存在"), {
|
|
21
|
+
from: "room",
|
|
22
|
+
signal: "room_exist",
|
|
23
|
+
}));
|
|
60
24
|
return;
|
|
61
25
|
}
|
|
62
|
-
this.
|
|
26
|
+
this.list.set(key, room);
|
|
63
27
|
// 添加监听事件
|
|
64
28
|
// 直播消息
|
|
65
29
|
room.on("msg", (data) => {
|
|
66
|
-
this.main.
|
|
67
|
-
|
|
30
|
+
this.main.hook.call("message", data).then((res) => {
|
|
31
|
+
res && this.main.emit("live:message", data);
|
|
32
|
+
});
|
|
68
33
|
});
|
|
69
34
|
// 直播消息源数据
|
|
70
35
|
room.on("raw", (data, { platform, room }) => {
|
|
@@ -88,7 +53,7 @@ class ModRoom {
|
|
|
88
53
|
});
|
|
89
54
|
// 直播状态更改
|
|
90
55
|
room.on("status", (status, { id, timestamp }) => {
|
|
91
|
-
this.main.emit("room:status", key, status,
|
|
56
|
+
this.main.emit("room:status", key, { status, id, timestamp });
|
|
92
57
|
});
|
|
93
58
|
// 统计数据更新
|
|
94
59
|
room.on("stats", (data) => {
|
|
@@ -108,47 +73,52 @@ class ModRoom {
|
|
|
108
73
|
this.main.emit("room:add", key, room.info);
|
|
109
74
|
}
|
|
110
75
|
/** 添加房间 */
|
|
111
|
-
add(platform, id,
|
|
112
|
-
|
|
76
|
+
add(platform, id, config) {
|
|
77
|
+
if (typeof config == "boolean") {
|
|
78
|
+
config = { open: config };
|
|
79
|
+
}
|
|
80
|
+
const room = this.main.call(platform, id, config);
|
|
113
81
|
room && this.addRoom(room);
|
|
114
82
|
}
|
|
115
83
|
/** 移除房间 */
|
|
116
84
|
remove(roomKey) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
+
}));
|
|
120
91
|
}
|
|
121
|
-
|
|
122
|
-
this.roomMap.delete(roomKey); // 从表中删除房间
|
|
92
|
+
this.list.delete(roomKey); // 从表中删除房间
|
|
123
93
|
room?.removeAllListeners(); // 移除房间监听实例
|
|
124
94
|
this.main.emit("room:remove", roomKey);
|
|
125
95
|
}
|
|
126
96
|
/** 获取房间 */
|
|
127
97
|
get(roomKey) {
|
|
128
|
-
return this.
|
|
98
|
+
return this.list.get(roomKey);
|
|
129
99
|
}
|
|
130
100
|
/** 获取房间信息 */
|
|
131
101
|
info(roomKey) {
|
|
132
|
-
let room = this.
|
|
102
|
+
let room = this.list.get(roomKey);
|
|
133
103
|
return room ? room.info : undefined;
|
|
134
104
|
}
|
|
135
105
|
/** 更新房间信息 */
|
|
136
106
|
update(roomKey) {
|
|
137
|
-
let room = this.
|
|
107
|
+
let room = this.list.get(roomKey);
|
|
138
108
|
room && room.getInfo();
|
|
139
109
|
}
|
|
140
110
|
/** 获取roomKey列表 */
|
|
141
111
|
get keys() {
|
|
142
|
-
return [...this.
|
|
112
|
+
return [...this.list.keys()];
|
|
143
113
|
}
|
|
144
114
|
/** 打开房间连接 */
|
|
145
115
|
open(roomKey) {
|
|
146
|
-
let room = this.
|
|
116
|
+
let room = this.list.get(roomKey);
|
|
147
117
|
room?.available && !room.opened && room.open();
|
|
148
118
|
}
|
|
149
119
|
/** 关闭房间连接 */
|
|
150
120
|
close(roomKey) {
|
|
151
|
-
let room = this.
|
|
121
|
+
let room = this.list.get(roomKey);
|
|
152
122
|
room?.opened && room.close();
|
|
153
123
|
}
|
|
154
124
|
}
|
|
@@ -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;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FloatingLive } from "../live";
|
|
2
|
+
interface ValueConfig<T> {
|
|
3
|
+
get: () => T;
|
|
4
|
+
set?: (value: T) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare class ModValues {
|
|
7
|
+
private list;
|
|
8
|
+
protected readonly main: FloatingLive;
|
|
9
|
+
constructor(main: FloatingLive);
|
|
10
|
+
/** 注册值 */
|
|
11
|
+
register<T>(name: string, config: ValueConfig<T>): void;
|
|
12
|
+
/** 取消注册 */
|
|
13
|
+
unregister(name: string): void;
|
|
14
|
+
/** 获取值 */
|
|
15
|
+
get(name: string): any;
|
|
16
|
+
/** 设置值 */
|
|
17
|
+
set(name: string, value: any): boolean;
|
|
18
|
+
/** 获取注册的所有值 */
|
|
19
|
+
getMap(): Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModValues = void 0;
|
|
4
|
+
class ModValues {
|
|
5
|
+
constructor(main) {
|
|
6
|
+
this.list = new Map();
|
|
7
|
+
this.main = main;
|
|
8
|
+
}
|
|
9
|
+
/** 注册值 */
|
|
10
|
+
register(name, config) {
|
|
11
|
+
this.list.set(name, config);
|
|
12
|
+
}
|
|
13
|
+
/** 取消注册 */
|
|
14
|
+
unregister(name) {
|
|
15
|
+
this.list.delete(name);
|
|
16
|
+
}
|
|
17
|
+
/** 获取值 */
|
|
18
|
+
get(name) {
|
|
19
|
+
return this.list.get(name)?.get();
|
|
20
|
+
}
|
|
21
|
+
/** 设置值 */
|
|
22
|
+
set(name, value) {
|
|
23
|
+
const valueConfig = this.list.get(name);
|
|
24
|
+
if (valueConfig?.set) {
|
|
25
|
+
valueConfig?.set(value);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** 获取注册的所有值 */
|
|
33
|
+
getMap() {
|
|
34
|
+
const map = {};
|
|
35
|
+
this.list.forEach((config, name) => {
|
|
36
|
+
map[name] = config.get();
|
|
37
|
+
});
|
|
38
|
+
return map;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.ModValues = ModValues;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { RoomStatus } from "../enums";
|
|
2
|
+
import { Message } from "./message";
|
|
3
|
+
import { RoomDetail, RoomInfo, RoomStatsInfo } from "./room";
|
|
4
|
+
export interface FloatingEventMap {
|
|
5
|
+
"live:message": (msg: Message.All) => void;
|
|
6
|
+
"live:raw": (data: any) => void;
|
|
7
|
+
"room:connect": (key: string) => void;
|
|
8
|
+
"room:disconnect": (key: string) => void;
|
|
9
|
+
"room:info": (key: string, info: RoomInfo) => void;
|
|
10
|
+
"room:detail": (key: string, info: RoomDetail) => void;
|
|
11
|
+
"room:status": (key: string, info: {
|
|
12
|
+
status: RoomStatus;
|
|
13
|
+
id?: string;
|
|
14
|
+
timestamp?: number;
|
|
15
|
+
}) => void;
|
|
16
|
+
"room:stats": (key: string, info: RoomStatsInfo) => void;
|
|
17
|
+
"room:open": (key: string, info: RoomInfo) => void;
|
|
18
|
+
"room:close": (key: string, info: RoomInfo) => void;
|
|
19
|
+
"room:add": (key: string, info: RoomInfo) => void;
|
|
20
|
+
"room:remove": (key: string, info: RoomInfo) => void;
|
|
21
|
+
"plugin:add": (name: string) => void;
|
|
22
|
+
"plugin:remove": (name: string) => void;
|
|
23
|
+
"command:add": (name: string) => void;
|
|
24
|
+
"command:remove": (name: string) => void;
|
|
25
|
+
error: (err: Error) => void;
|
|
26
|
+
}
|
package/dist/types/plugin.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { FloatingLive } from "../live";
|
|
2
2
|
/** 插件模块, 加载时调用 */
|
|
3
|
-
export declare type FloatingLivePlugin<C extends object = object
|
|
3
|
+
export declare type FloatingLivePlugin<C extends object = object> = () => {
|
|
4
4
|
/** 插件名称 */
|
|
5
5
|
name: string;
|
|
6
|
-
register: (ctx: FloatingLive, config?: C) =>
|
|
6
|
+
register: (ctx: FloatingLive, config?: C) => void;
|
|
7
7
|
destroy?: (ctx: FloatingLive) => void;
|
|
8
8
|
};
|
|
9
|
+
export interface IPlugin {
|
|
10
|
+
destroy: () => void;
|
|
11
|
+
}
|
|
12
|
+
export interface PluginConstructor {
|
|
13
|
+
pluginName: string;
|
|
14
|
+
new (ctx: FloatingLive, config: any): IPlugin;
|
|
15
|
+
}
|
package/dist/types/room.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { RoomStatus } from "../enums";
|
|
2
2
|
import { UserInfo } from "./message";
|
|
3
|
+
/** 房间配置 */
|
|
4
|
+
export interface RoomConfig {
|
|
5
|
+
/** 添加后是否打开房间 */
|
|
6
|
+
open?: boolean;
|
|
7
|
+
/** 口令 */
|
|
8
|
+
tokens?: Record<string, number>;
|
|
9
|
+
/** 凭据 */
|
|
10
|
+
credentials?: string;
|
|
11
|
+
}
|
|
12
|
+
/** 房间信息 */
|
|
3
13
|
export interface RoomInfo {
|
|
4
14
|
/** 平台id */
|
|
5
15
|
platform: string;
|
package/package.json
CHANGED
package/dist/core/Reglist.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { FloatingLive } from "../live";
|
|
2
|
-
/** 插件可注册对象模块 */
|
|
3
|
-
export declare class Reglist<T> {
|
|
4
|
-
/** 功能列表 */
|
|
5
|
-
private readonly list;
|
|
6
|
-
/** 插件与功能名称绑定表 */
|
|
7
|
-
private readonly pluginIdMap;
|
|
8
|
-
private readonly name;
|
|
9
|
-
protected readonly main: FloatingLive;
|
|
10
|
-
constructor(main: FloatingLive, name: string);
|
|
11
|
-
/** 注册一个对象 */
|
|
12
|
-
register(id: string, item: T): void;
|
|
13
|
-
/** 取消某一插件在该模块中的注册 */
|
|
14
|
-
unregister(pluginName: string): void;
|
|
15
|
-
/** 获取名称 */
|
|
16
|
-
getName(): string;
|
|
17
|
-
/** 根据id获取注册对象 */
|
|
18
|
-
get(id: string): T | undefined;
|
|
19
|
-
/** 检查注册对象是否存在 */
|
|
20
|
-
has(id: string): boolean;
|
|
21
|
-
/** 获取注册对象列表 */
|
|
22
|
-
getList(): T[];
|
|
23
|
-
/** 遍历 */
|
|
24
|
-
forEach(callbackfn: (value: T, key: string) => void): void;
|
|
25
|
-
/** 获取注册id列表 */
|
|
26
|
-
getIdList(): string[];
|
|
27
|
-
/** 获取注册id列表 */
|
|
28
|
-
getIdByPlugin(name: string): string[];
|
|
29
|
-
}
|
package/dist/core/Reglist.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Reglist = void 0;
|
|
4
|
-
/** 插件可注册对象模块 */
|
|
5
|
-
class Reglist {
|
|
6
|
-
constructor(main, name) {
|
|
7
|
-
this.main = main;
|
|
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 (this.main.plugin.currentPlugin) {
|
|
23
|
-
if (this.pluginIdMap.has(this.main.plugin.currentPlugin)) {
|
|
24
|
-
this.pluginIdMap.get(this.main.plugin.currentPlugin)?.push(id);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
this.pluginIdMap.set(this.main.plugin.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
|
-
has(id) {
|
|
50
|
-
return this.list.has(id);
|
|
51
|
-
}
|
|
52
|
-
/** 获取注册对象列表 */
|
|
53
|
-
getList() {
|
|
54
|
-
return [...this.list.values()];
|
|
55
|
-
}
|
|
56
|
-
/** 遍历 */
|
|
57
|
-
forEach(callbackfn) {
|
|
58
|
-
this.list.forEach(callbackfn);
|
|
59
|
-
}
|
|
60
|
-
/** 获取注册id列表 */
|
|
61
|
-
getIdList() {
|
|
62
|
-
return [...this.list.keys()];
|
|
63
|
-
}
|
|
64
|
-
/** 获取注册id列表 */
|
|
65
|
-
getIdByPlugin(name) {
|
|
66
|
-
return [...(this.pluginIdMap.get(name) || [])];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.Reglist = Reglist;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { FloatingLive } from "../live";
|
|
2
|
-
import { Reglist } from "../core/Reglist";
|
|
3
|
-
export default class ModCommand extends Reglist<(...args: any[]) => any> {
|
|
4
|
-
constructor(main: FloatingLive);
|
|
5
|
-
/** 批量注册命令 */
|
|
6
|
-
batchRegister(list: Record<string, (...args: any) => any>): void;
|
|
7
|
-
/** 执行命令 */
|
|
8
|
-
execute(name: string, ...args: any[]): any;
|
|
9
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Reglist_1 = require("../core/Reglist");
|
|
4
|
-
class ModCommand extends Reglist_1.Reglist {
|
|
5
|
-
constructor(main) {
|
|
6
|
-
super(main, "command");
|
|
7
|
-
}
|
|
8
|
-
/** 批量注册命令 */
|
|
9
|
-
batchRegister(list) {
|
|
10
|
-
for (const key in list) {
|
|
11
|
-
this.register(key, list[key]);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/** 执行命令 */
|
|
15
|
-
execute(name, ...args) {
|
|
16
|
-
return this.get(name)?.(...args);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.default = ModCommand;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Message } from "../types/message";
|
|
2
|
-
import { FloatingLive } from "../live";
|
|
3
|
-
import { Reglist } from "../core/Reglist";
|
|
4
|
-
export declare class ModMessage {
|
|
5
|
-
main: FloatingLive;
|
|
6
|
-
handler: Reglist<(msg: Message.All) => void>;
|
|
7
|
-
constructor(main: FloatingLive);
|
|
8
|
-
handle(msg: Message.All): void;
|
|
9
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModMessage = void 0;
|
|
4
|
-
const Reglist_1 = require("../core/Reglist");
|
|
5
|
-
class ModMessage {
|
|
6
|
-
constructor(main) {
|
|
7
|
-
this.main = main;
|
|
8
|
-
this.handler = new Reglist_1.Reglist(main, "message.handler");
|
|
9
|
-
}
|
|
10
|
-
handle(msg) {
|
|
11
|
-
this.handler.getList().forEach((handler) => {
|
|
12
|
-
handler(msg);
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.ModMessage = ModMessage;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { FloatingLive } from "../live";
|
|
2
|
-
import { FloatingLivePlugin } from "../types/plugin";
|
|
3
|
-
export declare class ModPlugin<T extends FloatingLive> {
|
|
4
|
-
private current;
|
|
5
|
-
/** 插件列表 */
|
|
6
|
-
private list;
|
|
7
|
-
private pluginEvent;
|
|
8
|
-
private main;
|
|
9
|
-
private exports;
|
|
10
|
-
constructor(main: T);
|
|
11
|
-
/** 获取当前安装插件 */
|
|
12
|
-
get currentPlugin(): string | null;
|
|
13
|
-
addPluginEvent(eventName: string, listener: (...args: any[]) => void): void;
|
|
14
|
-
/** 访问插件操作对象 */
|
|
15
|
-
access(name: string): object | undefined;
|
|
16
|
-
/** 注册插件 */
|
|
17
|
-
register<C extends object, E extends void | object>(pluginFunc: FloatingLivePlugin<C, E>, pluginConfig?: C): {} | undefined;
|
|
18
|
-
/** 移除插件 */
|
|
19
|
-
unregister(name: string): void;
|
|
20
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { FloatingLive } from "../live";
|
|
2
|
-
import { Reglist } from "../core/Reglist";
|
|
3
|
-
export declare class ModState extends Reglist<() => object> {
|
|
4
|
-
constructor(main: FloatingLive);
|
|
5
|
-
generate(): Record<string, any>;
|
|
6
|
-
/** 设置一个值 */
|
|
7
|
-
set(name: string, value: any): void;
|
|
8
|
-
/** 在数组中添加一个值 */
|
|
9
|
-
arrayPush(name: string, value: any): void;
|
|
10
|
-
/** 在数组中移除一个值 */
|
|
11
|
-
arrayRemove(name: string, key: string, val: string): void;
|
|
12
|
-
}
|
package/dist/module/ModState.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModState = void 0;
|
|
4
|
-
const Reglist_1 = require("../core/Reglist");
|
|
5
|
-
class ModState extends Reglist_1.Reglist {
|
|
6
|
-
constructor(main) {
|
|
7
|
-
super(main, "state");
|
|
8
|
-
}
|
|
9
|
-
generate() {
|
|
10
|
-
const state = {};
|
|
11
|
-
this.forEach((gen, key) => {
|
|
12
|
-
state[key] = gen();
|
|
13
|
-
});
|
|
14
|
-
return state;
|
|
15
|
-
}
|
|
16
|
-
/** 设置一个值 */
|
|
17
|
-
set(name, value) {
|
|
18
|
-
this.main.emit("state:set", name, value);
|
|
19
|
-
}
|
|
20
|
-
/** 在数组中添加一个值 */
|
|
21
|
-
arrayPush(name, value) {
|
|
22
|
-
this.main.emit("state:array_push", name, value);
|
|
23
|
-
}
|
|
24
|
-
/** 在数组中移除一个值 */
|
|
25
|
-
arrayRemove(name, key, val) {
|
|
26
|
-
this.main.emit("state:array_remove", name, key, val);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.ModState = ModState;
|