floating-live 0.15.6 → 0.15.8
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.d.ts +3 -2
- package/dist/live.js +2 -1
- package/dist/module/hook.d.ts +1 -0
- package/dist/module/hook.js +7 -0
- package/dist/module/plugin.d.ts +3 -1
- package/dist/module/plugin.js +25 -4
- package/dist/module/room.d.ts +2 -1
- package/dist/module/room.js +5 -1
- package/dist/module/value.d.ts +3 -2
- package/dist/module/value.js +15 -7
- package/dist/types/command.d.ts +12 -0
- package/dist/types/error.d.ts +2 -0
- package/dist/types/events.d.ts +3 -0
- package/esm/live.js +2 -1
- package/esm/module/hook.js +7 -0
- package/esm/module/plugin.js +25 -4
- package/esm/module/room.js +5 -1
- package/esm/module/value.js +15 -7
- package/package.json +1 -1
package/dist/live.d.ts
CHANGED
|
@@ -29,10 +29,11 @@ export declare class FloatingLive extends EventEmitter {
|
|
|
29
29
|
throw(err: Error, options?: ErrorOptions): void;
|
|
30
30
|
throw(options: ErrorOptions): void;
|
|
31
31
|
getSnapshot(): {
|
|
32
|
-
room: import("./
|
|
32
|
+
room: import("./core").LiveRoom[];
|
|
33
33
|
value: Record<string, any>;
|
|
34
34
|
manifest: Record<string, Record<string, any>>;
|
|
35
35
|
command: string[];
|
|
36
|
-
hook: Record<string,
|
|
36
|
+
hook: Record<string, number>;
|
|
37
|
+
plugin: string[];
|
|
37
38
|
};
|
|
38
39
|
}
|
package/dist/live.js
CHANGED
|
@@ -43,7 +43,8 @@ class FloatingLive extends events_1.EventEmitter {
|
|
|
43
43
|
value: this.value.getSnapshot(),
|
|
44
44
|
manifest: this.manifest.getSnapshot(),
|
|
45
45
|
command: this.command.getSnapshot(),
|
|
46
|
-
hook: this.
|
|
46
|
+
hook: this.hook.getSnapshot(),
|
|
47
|
+
plugin: this.plugin.getSnapshot(),
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
}
|
package/dist/module/hook.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export declare class ModHook {
|
|
|
11
11
|
unregister<T extends keyof FloatingHookMap>(name: T, func: HookFunction<FloatingHookMap[T]>): void;
|
|
12
12
|
/** 调用钩子函数 */
|
|
13
13
|
call<T extends keyof FloatingHookMap>(name: T, ctx: FloatingHookMap[T]): Promise<boolean>;
|
|
14
|
+
getSnapshot(): Record<string, number>;
|
|
14
15
|
}
|
package/dist/module/hook.js
CHANGED
package/dist/module/plugin.d.ts
CHANGED
|
@@ -6,9 +6,11 @@ export declare class ModPlugin {
|
|
|
6
6
|
protected readonly main: FloatingLive;
|
|
7
7
|
constructor(main: FloatingLive);
|
|
8
8
|
/** 注册插件 */
|
|
9
|
-
register(pluginFunc: PluginConstructor, options?: Record<string, any>): Promise<PluginItem | undefined>;
|
|
9
|
+
register(pluginFunc: PluginConstructor, options?: Record<string, any>): Promise<void | PluginItem | undefined>;
|
|
10
10
|
/** 移除插件 */
|
|
11
11
|
unregister(name: string): Promise<void>;
|
|
12
12
|
/** 获取插件实例 */
|
|
13
13
|
get(name: string): PluginItem | undefined;
|
|
14
|
+
has(name: string): boolean;
|
|
15
|
+
getSnapshot(): string[];
|
|
14
16
|
}
|
package/dist/module/plugin.js
CHANGED
|
@@ -12,14 +12,17 @@ class ModPlugin {
|
|
|
12
12
|
const name = pluginFunc.pluginName;
|
|
13
13
|
if (!name) {
|
|
14
14
|
this.main.throw({
|
|
15
|
-
message: "
|
|
15
|
+
message: "添加插件失败",
|
|
16
|
+
reason: "缺少插件id",
|
|
16
17
|
id: "plugin:register_id_missing",
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
20
|
if (this.list.has(name)) {
|
|
20
21
|
this.main.throw({
|
|
21
|
-
message:
|
|
22
|
+
message: `添加插件失败: ${name}`,
|
|
23
|
+
reason: "已存在相同id的插件",
|
|
22
24
|
id: "plugin:register_id_duplicate",
|
|
25
|
+
pluginName: name,
|
|
23
26
|
});
|
|
24
27
|
}
|
|
25
28
|
return await this.main.hook
|
|
@@ -29,11 +32,21 @@ class ModPlugin {
|
|
|
29
32
|
return;
|
|
30
33
|
// 执行插件函数
|
|
31
34
|
const plugin = new pluginFunc(this.main, options);
|
|
32
|
-
this.list.set(name, plugin);
|
|
33
35
|
// 调用插件的register钩子
|
|
34
36
|
await plugin.register?.(this.main, options);
|
|
37
|
+
this.list.set(name, plugin);
|
|
35
38
|
this.main.emit("plugin:add", name);
|
|
36
39
|
return plugin;
|
|
40
|
+
})
|
|
41
|
+
.catch((err) => {
|
|
42
|
+
this.main.throw({
|
|
43
|
+
message: `添加插件失败: ${name}`,
|
|
44
|
+
reason: err?.message && err?.reason
|
|
45
|
+
? `${err.message}: ${err.reason}`
|
|
46
|
+
: err?.message || err?.reason,
|
|
47
|
+
id: "plugin:register_fail",
|
|
48
|
+
pluginName: name,
|
|
49
|
+
});
|
|
37
50
|
});
|
|
38
51
|
}
|
|
39
52
|
/** 移除插件 */
|
|
@@ -42,8 +55,10 @@ class ModPlugin {
|
|
|
42
55
|
// 检测插件是否存在
|
|
43
56
|
if (!plugin) {
|
|
44
57
|
this.main.throw({
|
|
45
|
-
message:
|
|
58
|
+
message: `移除插件失败: ${name}`,
|
|
59
|
+
reason: "插件不存在",
|
|
46
60
|
id: "plugin:unregister_unexist",
|
|
61
|
+
pluginName: name,
|
|
47
62
|
});
|
|
48
63
|
}
|
|
49
64
|
else {
|
|
@@ -59,5 +74,11 @@ class ModPlugin {
|
|
|
59
74
|
get(name) {
|
|
60
75
|
return this.list.get(name);
|
|
61
76
|
}
|
|
77
|
+
has(name) {
|
|
78
|
+
return this.list.has(name);
|
|
79
|
+
}
|
|
80
|
+
getSnapshot() {
|
|
81
|
+
return [...this.list.keys()];
|
|
82
|
+
}
|
|
62
83
|
}
|
|
63
84
|
exports.ModPlugin = ModPlugin;
|
package/dist/module/room.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class ModRoom {
|
|
|
14
14
|
remove(roomKey: string): void;
|
|
15
15
|
/** 获取房间 */
|
|
16
16
|
get(roomKey: string): LiveRoom | undefined;
|
|
17
|
+
has(roomKey: string): boolean;
|
|
17
18
|
/** 获取房间信息 */
|
|
18
19
|
info(roomKey: string): RoomInfo | undefined;
|
|
19
20
|
/** 更新房间信息 */
|
|
@@ -27,5 +28,5 @@ export declare class ModRoom {
|
|
|
27
28
|
/** 更改某个房间的顺序 */
|
|
28
29
|
move(roomKey: string, position: number): void;
|
|
29
30
|
/** 获取快照 */
|
|
30
|
-
getSnapshot():
|
|
31
|
+
getSnapshot(): LiveRoom[];
|
|
31
32
|
}
|
package/dist/module/room.js
CHANGED
|
@@ -113,6 +113,9 @@ class ModRoom {
|
|
|
113
113
|
get(roomKey) {
|
|
114
114
|
return this.list.get(roomKey);
|
|
115
115
|
}
|
|
116
|
+
has(roomKey) {
|
|
117
|
+
return this.list.has(roomKey);
|
|
118
|
+
}
|
|
116
119
|
/** 获取房间信息 */
|
|
117
120
|
info(roomKey) {
|
|
118
121
|
let room = this.list.get(roomKey);
|
|
@@ -146,10 +149,11 @@ class ModRoom {
|
|
|
146
149
|
const [item] = arr.splice(index, 1);
|
|
147
150
|
arr.splice(position, 0, item);
|
|
148
151
|
this.list = new Map(arr);
|
|
152
|
+
this.main.emit("room:move", roomKey, position);
|
|
149
153
|
}
|
|
150
154
|
/** 获取快照 */
|
|
151
155
|
getSnapshot() {
|
|
152
|
-
return [...this.list
|
|
156
|
+
return [...this.list.values()];
|
|
153
157
|
}
|
|
154
158
|
}
|
|
155
159
|
exports.ModRoom = ModRoom;
|
package/dist/module/value.d.ts
CHANGED
|
@@ -16,10 +16,11 @@ export declare class ModValue {
|
|
|
16
16
|
get<T extends keyof FloatingValueMap>(name: T): any;
|
|
17
17
|
/** 设置值 */
|
|
18
18
|
set<T extends keyof FloatingValueMap>(name: T, value: FloatingValueMap[T]): boolean;
|
|
19
|
-
|
|
20
|
-
getSnapshot(): Record<string, any>;
|
|
19
|
+
has(name: string): boolean;
|
|
21
20
|
emit<T extends keyof FloatingValueMap>(name: T, value: FloatingValueMap[T]): void;
|
|
22
21
|
watch<T extends keyof FloatingValueMap>(name: T, listener: (value: FloatingValueMap[T]) => void): void;
|
|
23
22
|
unwatch<T extends keyof FloatingValueMap>(name: T, listener: (value: FloatingValueMap[T]) => void): void;
|
|
23
|
+
/** 获取注册的所有值 */
|
|
24
|
+
getSnapshot(): Record<string, any>;
|
|
24
25
|
}
|
|
25
26
|
export {};
|
package/dist/module/value.js
CHANGED
|
@@ -5,16 +5,21 @@ class ModValue {
|
|
|
5
5
|
constructor(main) {
|
|
6
6
|
this.list = new Map();
|
|
7
7
|
this.main = main;
|
|
8
|
+
const { command } = main;
|
|
9
|
+
command.register("get", this.get.bind(this));
|
|
10
|
+
command.register("set", this.set.bind(this));
|
|
8
11
|
}
|
|
9
12
|
/** 注册值 */
|
|
10
13
|
register(name, config) {
|
|
11
14
|
this.list.set(name, config);
|
|
12
15
|
this.main.emit("value:add", name);
|
|
16
|
+
this.main.emit("value:change", name, config.get());
|
|
13
17
|
}
|
|
14
18
|
/** 取消注册 */
|
|
15
19
|
unregister(name) {
|
|
16
20
|
this.list.delete(name);
|
|
17
21
|
this.main.emit("value:remove", name);
|
|
22
|
+
this.main.emit("value:change", name, undefined);
|
|
18
23
|
}
|
|
19
24
|
/** 获取值 */
|
|
20
25
|
get(name) {
|
|
@@ -31,13 +36,8 @@ class ModValue {
|
|
|
31
36
|
return false;
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const map = {};
|
|
37
|
-
this.list.forEach((config, name) => {
|
|
38
|
-
map[name] = config.get();
|
|
39
|
-
});
|
|
40
|
-
return map;
|
|
39
|
+
has(name) {
|
|
40
|
+
return this.list.has(name);
|
|
41
41
|
}
|
|
42
42
|
emit(name, value) {
|
|
43
43
|
this.main.emit(`change:${name}`, value);
|
|
@@ -49,5 +49,13 @@ class ModValue {
|
|
|
49
49
|
unwatch(name, listener) {
|
|
50
50
|
this.main.off(`change:${name}`, listener);
|
|
51
51
|
}
|
|
52
|
+
/** 获取注册的所有值 */
|
|
53
|
+
getSnapshot() {
|
|
54
|
+
const map = {};
|
|
55
|
+
this.list.forEach((config, name) => {
|
|
56
|
+
map[name] = config.get();
|
|
57
|
+
});
|
|
58
|
+
return map;
|
|
59
|
+
}
|
|
52
60
|
}
|
|
53
61
|
exports.ModValue = ModValue;
|
package/dist/types/command.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { LiveRoom } from "../core";
|
|
2
2
|
import { RoomInfo } from "./room";
|
|
3
|
+
import { FloatingValueMap } from "./value";
|
|
3
4
|
export interface FloatingCommandMap {
|
|
5
|
+
/** 添加房间 */
|
|
4
6
|
add: (platform: string, id: number, options?: boolean | Record<string, any>) => void;
|
|
7
|
+
/** 移除房间 */
|
|
5
8
|
remove: (key: string) => void;
|
|
9
|
+
/** 打开房间 */
|
|
6
10
|
open: (key: string) => void;
|
|
11
|
+
/** 关闭房间 */
|
|
7
12
|
close: (key: string) => void;
|
|
13
|
+
/** 更新房间信息 */
|
|
8
14
|
update: (key: string) => void;
|
|
15
|
+
/** 创建房间 */
|
|
9
16
|
[name: `${string}.room.create`]: (id: string | number, options?: Record<string, any>) => Promise<LiveRoom> | LiveRoom;
|
|
17
|
+
/** 获取房间信息 */
|
|
10
18
|
[name: `${string}.room.info`]: (id: string | number) => Promise<RoomInfo>;
|
|
19
|
+
/** 获取值 */
|
|
20
|
+
get: <N extends keyof FloatingValueMap>(name: N) => FloatingValueMap[N];
|
|
21
|
+
/** 设置值 */
|
|
22
|
+
set: <N extends keyof FloatingValueMap>(name: N, value: FloatingValueMap[N]) => boolean;
|
|
11
23
|
}
|
package/dist/types/error.d.ts
CHANGED
package/dist/types/events.d.ts
CHANGED
|
@@ -23,12 +23,15 @@ export interface FloatingEventMap {
|
|
|
23
23
|
"room:close": (key: string, info: RoomInfo) => void;
|
|
24
24
|
"room:add": (key: string, info: RoomInfo) => void;
|
|
25
25
|
"room:remove": (key: string) => void;
|
|
26
|
+
"room:move": (key: string, position: number) => void;
|
|
26
27
|
"plugin:add": (name: string) => void;
|
|
27
28
|
"plugin:remove": (name: string) => void;
|
|
28
29
|
"command:add": (name: string) => void;
|
|
29
30
|
"command:remove": (name: string) => void;
|
|
30
31
|
"manifest:add": (name: string, id: string, value: any) => void;
|
|
31
32
|
"manifest:remove": (name: string, id: string) => void;
|
|
33
|
+
"hook:add": (name: string) => void;
|
|
34
|
+
"hook:remove": (name: string) => void;
|
|
32
35
|
"value:add": (name: string) => void;
|
|
33
36
|
"value:remove": (name: string) => void;
|
|
34
37
|
"value:change": (name: string, value: any) => void;
|
package/esm/live.js
CHANGED
|
@@ -40,7 +40,8 @@ export class FloatingLive extends EventEmitter {
|
|
|
40
40
|
value: this.value.getSnapshot(),
|
|
41
41
|
manifest: this.manifest.getSnapshot(),
|
|
42
42
|
command: this.command.getSnapshot(),
|
|
43
|
-
hook: this.
|
|
43
|
+
hook: this.hook.getSnapshot(),
|
|
44
|
+
plugin: this.plugin.getSnapshot(),
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
}
|
package/esm/module/hook.js
CHANGED
package/esm/module/plugin.js
CHANGED
|
@@ -9,14 +9,17 @@ export class ModPlugin {
|
|
|
9
9
|
const name = pluginFunc.pluginName;
|
|
10
10
|
if (!name) {
|
|
11
11
|
this.main.throw({
|
|
12
|
-
message: "
|
|
12
|
+
message: "添加插件失败",
|
|
13
|
+
reason: "缺少插件id",
|
|
13
14
|
id: "plugin:register_id_missing",
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
17
|
if (this.list.has(name)) {
|
|
17
18
|
this.main.throw({
|
|
18
|
-
message:
|
|
19
|
+
message: `添加插件失败: ${name}`,
|
|
20
|
+
reason: "已存在相同id的插件",
|
|
19
21
|
id: "plugin:register_id_duplicate",
|
|
22
|
+
pluginName: name,
|
|
20
23
|
});
|
|
21
24
|
}
|
|
22
25
|
return await this.main.hook
|
|
@@ -26,11 +29,21 @@ export class ModPlugin {
|
|
|
26
29
|
return;
|
|
27
30
|
// 执行插件函数
|
|
28
31
|
const plugin = new pluginFunc(this.main, options);
|
|
29
|
-
this.list.set(name, plugin);
|
|
30
32
|
// 调用插件的register钩子
|
|
31
33
|
await plugin.register?.(this.main, options);
|
|
34
|
+
this.list.set(name, plugin);
|
|
32
35
|
this.main.emit("plugin:add", name);
|
|
33
36
|
return plugin;
|
|
37
|
+
})
|
|
38
|
+
.catch((err) => {
|
|
39
|
+
this.main.throw({
|
|
40
|
+
message: `添加插件失败: ${name}`,
|
|
41
|
+
reason: err?.message && err?.reason
|
|
42
|
+
? `${err.message}: ${err.reason}`
|
|
43
|
+
: err?.message || err?.reason,
|
|
44
|
+
id: "plugin:register_fail",
|
|
45
|
+
pluginName: name,
|
|
46
|
+
});
|
|
34
47
|
});
|
|
35
48
|
}
|
|
36
49
|
/** 移除插件 */
|
|
@@ -39,8 +52,10 @@ export class ModPlugin {
|
|
|
39
52
|
// 检测插件是否存在
|
|
40
53
|
if (!plugin) {
|
|
41
54
|
this.main.throw({
|
|
42
|
-
message:
|
|
55
|
+
message: `移除插件失败: ${name}`,
|
|
56
|
+
reason: "插件不存在",
|
|
43
57
|
id: "plugin:unregister_unexist",
|
|
58
|
+
pluginName: name,
|
|
44
59
|
});
|
|
45
60
|
}
|
|
46
61
|
else {
|
|
@@ -56,4 +71,10 @@ export class ModPlugin {
|
|
|
56
71
|
get(name) {
|
|
57
72
|
return this.list.get(name);
|
|
58
73
|
}
|
|
74
|
+
has(name) {
|
|
75
|
+
return this.list.has(name);
|
|
76
|
+
}
|
|
77
|
+
getSnapshot() {
|
|
78
|
+
return [...this.list.keys()];
|
|
79
|
+
}
|
|
59
80
|
}
|
package/esm/module/room.js
CHANGED
|
@@ -110,6 +110,9 @@ export class ModRoom {
|
|
|
110
110
|
get(roomKey) {
|
|
111
111
|
return this.list.get(roomKey);
|
|
112
112
|
}
|
|
113
|
+
has(roomKey) {
|
|
114
|
+
return this.list.has(roomKey);
|
|
115
|
+
}
|
|
113
116
|
/** 获取房间信息 */
|
|
114
117
|
info(roomKey) {
|
|
115
118
|
let room = this.list.get(roomKey);
|
|
@@ -143,9 +146,10 @@ export class ModRoom {
|
|
|
143
146
|
const [item] = arr.splice(index, 1);
|
|
144
147
|
arr.splice(position, 0, item);
|
|
145
148
|
this.list = new Map(arr);
|
|
149
|
+
this.main.emit("room:move", roomKey, position);
|
|
146
150
|
}
|
|
147
151
|
/** 获取快照 */
|
|
148
152
|
getSnapshot() {
|
|
149
|
-
return [...this.list
|
|
153
|
+
return [...this.list.values()];
|
|
150
154
|
}
|
|
151
155
|
}
|
package/esm/module/value.js
CHANGED
|
@@ -2,16 +2,21 @@ export class ModValue {
|
|
|
2
2
|
constructor(main) {
|
|
3
3
|
this.list = new Map();
|
|
4
4
|
this.main = main;
|
|
5
|
+
const { command } = main;
|
|
6
|
+
command.register("get", this.get.bind(this));
|
|
7
|
+
command.register("set", this.set.bind(this));
|
|
5
8
|
}
|
|
6
9
|
/** 注册值 */
|
|
7
10
|
register(name, config) {
|
|
8
11
|
this.list.set(name, config);
|
|
9
12
|
this.main.emit("value:add", name);
|
|
13
|
+
this.main.emit("value:change", name, config.get());
|
|
10
14
|
}
|
|
11
15
|
/** 取消注册 */
|
|
12
16
|
unregister(name) {
|
|
13
17
|
this.list.delete(name);
|
|
14
18
|
this.main.emit("value:remove", name);
|
|
19
|
+
this.main.emit("value:change", name, undefined);
|
|
15
20
|
}
|
|
16
21
|
/** 获取值 */
|
|
17
22
|
get(name) {
|
|
@@ -28,13 +33,8 @@ export class ModValue {
|
|
|
28
33
|
return false;
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const map = {};
|
|
34
|
-
this.list.forEach((config, name) => {
|
|
35
|
-
map[name] = config.get();
|
|
36
|
-
});
|
|
37
|
-
return map;
|
|
36
|
+
has(name) {
|
|
37
|
+
return this.list.has(name);
|
|
38
38
|
}
|
|
39
39
|
emit(name, value) {
|
|
40
40
|
this.main.emit(`change:${name}`, value);
|
|
@@ -46,4 +46,12 @@ export class ModValue {
|
|
|
46
46
|
unwatch(name, listener) {
|
|
47
47
|
this.main.off(`change:${name}`, listener);
|
|
48
48
|
}
|
|
49
|
+
/** 获取注册的所有值 */
|
|
50
|
+
getSnapshot() {
|
|
51
|
+
const map = {};
|
|
52
|
+
this.list.forEach((config, name) => {
|
|
53
|
+
map[name] = config.get();
|
|
54
|
+
});
|
|
55
|
+
return map;
|
|
56
|
+
}
|
|
49
57
|
}
|