floating-live 0.15.0 → 0.15.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/live.js +3 -1
- package/dist/module/hook.d.ts +1 -1
- package/dist/module/plugin.d.ts +1 -4
- package/dist/module/plugin.js +13 -11
- package/dist/module/room.js +2 -2
- package/dist/module/value.d.ts +3 -3
- package/dist/types/events.d.ts +1 -0
- package/dist/types/hook.d.ts +8 -2
- package/dist/types/plugin.d.ts +2 -2
- package/package.json +4 -3
package/dist/live.js
CHANGED
|
@@ -25,7 +25,9 @@ class FloatingLive extends events_1.EventEmitter {
|
|
|
25
25
|
return super.on(eventName, listener);
|
|
26
26
|
}
|
|
27
27
|
emit(eventName, ...args) {
|
|
28
|
-
|
|
28
|
+
const emit = super.emit(eventName, ...args);
|
|
29
|
+
super.emit("event", eventName, ...args);
|
|
30
|
+
return emit;
|
|
29
31
|
}
|
|
30
32
|
throw(err) {
|
|
31
33
|
this.emit("error", err);
|
package/dist/module/hook.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FloatingLive } from "../live";
|
|
2
2
|
import { FloatingHookMap } from "../types/hook";
|
|
3
|
-
export
|
|
3
|
+
export type HookFunction<T> = (ctx: T) => boolean | void | Promise<boolean | void>;
|
|
4
4
|
export declare class ModHook {
|
|
5
5
|
private list;
|
|
6
6
|
protected readonly main: FloatingLive;
|
package/dist/module/plugin.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { FloatingLive } from "../live";
|
|
2
2
|
import { PluginConstructor } from "../types/plugin";
|
|
3
3
|
export declare class ModPlugin {
|
|
4
|
-
private current;
|
|
5
4
|
/** 插件列表 */
|
|
6
5
|
private list;
|
|
7
6
|
protected readonly main: FloatingLive;
|
|
8
7
|
constructor(main: FloatingLive);
|
|
9
|
-
/** 获取当前安装插件 */
|
|
10
|
-
get currentPlugin(): string | null;
|
|
11
8
|
/** 注册插件 */
|
|
12
|
-
register(pluginFunc: PluginConstructor, options?: any): void;
|
|
9
|
+
register(pluginFunc: PluginConstructor, options?: any): Promise<void> | undefined;
|
|
13
10
|
/** 移除插件 */
|
|
14
11
|
unregister(name: string): void;
|
|
15
12
|
/** 获取插件实例 */
|
package/dist/module/plugin.js
CHANGED
|
@@ -3,15 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ModPlugin = void 0;
|
|
4
4
|
class ModPlugin {
|
|
5
5
|
constructor(main) {
|
|
6
|
-
this.current = null;
|
|
7
6
|
/** 插件列表 */
|
|
8
7
|
this.list = new Map();
|
|
9
8
|
this.main = main;
|
|
10
9
|
}
|
|
11
|
-
/** 获取当前安装插件 */
|
|
12
|
-
get currentPlugin() {
|
|
13
|
-
return this.current;
|
|
14
|
-
}
|
|
15
10
|
/** 注册插件 */
|
|
16
11
|
register(pluginFunc, options) {
|
|
17
12
|
const name = pluginFunc.pluginName;
|
|
@@ -29,11 +24,18 @@ class ModPlugin {
|
|
|
29
24
|
}));
|
|
30
25
|
return;
|
|
31
26
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
return this.main.hook
|
|
28
|
+
.call("plugin.register", { name, options })
|
|
29
|
+
.then((res) => {
|
|
30
|
+
if (!res)
|
|
31
|
+
return;
|
|
32
|
+
// 执行插件函数
|
|
33
|
+
const plugin = new pluginFunc(this.main, options);
|
|
34
|
+
this.list.set(name, plugin);
|
|
35
|
+
// 调用插件的register钩子
|
|
36
|
+
plugin.register?.(this.main, options);
|
|
37
|
+
this.main.emit("plugin:add", name);
|
|
38
|
+
});
|
|
37
39
|
}
|
|
38
40
|
/** 移除插件 */
|
|
39
41
|
unregister(name) {
|
|
@@ -46,7 +48,7 @@ class ModPlugin {
|
|
|
46
48
|
}));
|
|
47
49
|
return;
|
|
48
50
|
}
|
|
49
|
-
//
|
|
51
|
+
// 调用该插件的destroy钩子
|
|
50
52
|
plugin.destroy?.();
|
|
51
53
|
// 从列表中移除插件
|
|
52
54
|
this.list.delete(name);
|
package/dist/module/room.js
CHANGED
|
@@ -27,7 +27,7 @@ class ModRoom {
|
|
|
27
27
|
// 添加监听事件
|
|
28
28
|
// 直播消息
|
|
29
29
|
room.on("message", (data) => {
|
|
30
|
-
this.main.hook.call("message", data).then((res) => {
|
|
30
|
+
this.main.hook.call("message", { message: data }).then((res) => {
|
|
31
31
|
res && this.main.emit("live:message", data);
|
|
32
32
|
});
|
|
33
33
|
});
|
|
@@ -84,7 +84,7 @@ class ModRoom {
|
|
|
84
84
|
add(platform, id, options) {
|
|
85
85
|
const opt = typeof options == "boolean" ? { open: options } : options;
|
|
86
86
|
const ctx = { platform, id, options: opt || {} };
|
|
87
|
-
this.main.hook.call("add", ctx).then((res) => {
|
|
87
|
+
this.main.hook.call("room.add", ctx).then((res) => {
|
|
88
88
|
if (!res)
|
|
89
89
|
return;
|
|
90
90
|
const room = this.main.call(`${platform}.room.create`, id, opt);
|
package/dist/module/value.d.ts
CHANGED
|
@@ -9,13 +9,13 @@ export declare class ModValue {
|
|
|
9
9
|
protected readonly main: FloatingLive;
|
|
10
10
|
constructor(main: FloatingLive);
|
|
11
11
|
/** 注册值 */
|
|
12
|
-
register<T>(name:
|
|
12
|
+
register<T extends keyof FloatingValueMap>(name: T, config: ValueConfig<FloatingValueMap[T]>): void;
|
|
13
13
|
/** 取消注册 */
|
|
14
14
|
unregister(name: string): void;
|
|
15
15
|
/** 获取值 */
|
|
16
|
-
get(name:
|
|
16
|
+
get<T extends keyof FloatingValueMap>(name: T): any;
|
|
17
17
|
/** 设置值 */
|
|
18
|
-
set(name:
|
|
18
|
+
set<T extends keyof FloatingValueMap>(name: T, value: FloatingValueMap[T]): boolean;
|
|
19
19
|
/** 获取注册的所有值 */
|
|
20
20
|
getSnapshot(): Record<string, any>;
|
|
21
21
|
emit<T extends keyof FloatingValueMap>(name: T, value: FloatingValueMap[T]): void;
|
package/dist/types/events.d.ts
CHANGED
|
@@ -33,5 +33,6 @@ export interface FloatingEventMap {
|
|
|
33
33
|
"value:remove": (name: string) => void;
|
|
34
34
|
"value:change": (name: string, value: any) => void;
|
|
35
35
|
[name: `change:${string}`]: (value: any) => void;
|
|
36
|
+
event: (eventName: string, ...args: any[]) => void;
|
|
36
37
|
error: (err: Error) => void;
|
|
37
38
|
}
|
package/dist/types/hook.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { Message } from "./message";
|
|
2
2
|
export interface FloatingHookMap {
|
|
3
|
-
message:
|
|
4
|
-
|
|
3
|
+
message: {
|
|
4
|
+
message: Message.All;
|
|
5
|
+
};
|
|
6
|
+
"room.add": {
|
|
5
7
|
platform: string;
|
|
6
8
|
id: string | number;
|
|
7
9
|
options: Record<string, any>;
|
|
8
10
|
};
|
|
11
|
+
"plugin.register": {
|
|
12
|
+
name: string;
|
|
13
|
+
options: Record<string, any>;
|
|
14
|
+
};
|
|
9
15
|
}
|
package/dist/types/plugin.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { FloatingLive } from "../live";
|
|
2
2
|
/** 插件模块, 加载时调用 */
|
|
3
|
-
export
|
|
3
|
+
export type FloatingLivePlugin<C extends object = object> = () => {
|
|
4
4
|
/** 插件名称 */
|
|
5
5
|
name: string;
|
|
6
6
|
register: (ctx: FloatingLive, options?: C) => void;
|
|
7
7
|
destroy?: (ctx: FloatingLive) => void;
|
|
8
8
|
};
|
|
9
9
|
export interface IPlugin {
|
|
10
|
-
|
|
10
|
+
register?(ctx: FloatingLive, options: any): void;
|
|
11
11
|
destroy?(): void;
|
|
12
12
|
}
|
|
13
13
|
export interface PluginConstructor {
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "floating-live",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"author": "Minteea",
|
|
8
|
-
"license": "
|
|
8
|
+
"license": "MIT",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"test": "npm run clear && ts-node demo/demo.ts",
|
|
35
35
|
"build-test": "npm run build && node demo/demo.js",
|
|
36
36
|
"build": "npm run clear && npm run tsc",
|
|
37
|
-
"
|
|
37
|
+
"prepack": "npm run build",
|
|
38
|
+
"postpack": "npm run clear"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"rimraf": "^3.0.2",
|