floating-live 0.15.10 → 0.16.0-alpha.0
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/README.md +14 -10
- package/dist/FloatingLive.d.ts +6 -0
- package/dist/FloatingLive.js +8 -0
- package/dist/app.d.ts +46 -0
- package/dist/app.js +126 -0
- package/dist/command/index.d.ts +1 -0
- package/dist/command/index.js +1 -0
- package/dist/command/manager.d.ts +23 -0
- package/dist/command/manager.js +46 -0
- package/dist/command/types.d.ts +25 -0
- package/{esm/types/command.js → dist/command/types.js} +1 -1
- package/dist/error/index.d.ts +11 -0
- package/dist/error/index.js +9 -0
- package/dist/error/types.d.ts +6 -0
- package/{esm/types/error.js → dist/error/types.js} +1 -1
- package/dist/event/index.d.ts +1 -0
- package/dist/event/index.js +1 -0
- package/dist/event/manager.d.ts +9 -0
- package/dist/event/manager.js +17 -0
- package/dist/event/types.d.ts +42 -0
- package/{esm/types/events.js → dist/event/types.js} +1 -1
- package/dist/hook/index.d.ts +1 -0
- package/dist/hook/index.js +1 -0
- package/dist/hook/manager.d.ts +25 -0
- package/dist/hook/manager.js +79 -0
- package/dist/hook/types.d.ts +22 -0
- package/{esm/types/hook.js → dist/hook/types.js} +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.js +8 -23
- package/dist/{types → live}/message.d.ts +185 -248
- package/{esm/types → dist/live}/message.js +1 -1
- package/dist/live/messageInfo.d.ts +93 -0
- package/dist/live/messageInfo.js +28 -0
- package/dist/live/platform.d.ts +40 -0
- package/dist/live/platform.js +1 -0
- package/dist/live/room.d.ts +150 -0
- package/dist/live/room.js +120 -0
- package/dist/plugin/context/CommonPluginContext.d.ts +45 -0
- package/dist/plugin/context/CommonPluginContext.js +273 -0
- package/dist/plugin/context/SafePluginContext.d.ts +34 -0
- package/dist/plugin/context/SafePluginContext.js +91 -0
- package/dist/plugin/index.d.ts +8 -0
- package/dist/plugin/index.js +5 -0
- package/dist/plugin/manager.d.ts +31 -0
- package/dist/plugin/manager.js +93 -0
- package/dist/plugin/types.d.ts +73 -0
- package/dist/plugin/types.js +1 -0
- package/dist/plugins/room/index.d.ts +116 -0
- package/dist/plugins/room/index.js +172 -0
- package/dist/utils/EventEmitter.d.ts +6 -0
- package/dist/utils/EventEmitter.js +26 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +4 -0
- package/dist/value/index.d.ts +1 -0
- package/dist/value/index.js +1 -0
- package/dist/value/manager.d.ts +24 -0
- package/dist/value/manager.js +63 -0
- package/dist/value/types.d.ts +19 -0
- package/dist/value/types.js +1 -0
- package/package.json +9 -40
- package/src/source.md +29 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/core/LiveRoom.d.ts +0 -44
- package/dist/core/LiveRoom.js +0 -81
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -17
- package/dist/core/plugin.d.ts +0 -17
- package/dist/core/plugin.js +0 -28
- package/dist/enums.d.ts +0 -51
- package/dist/enums.js +0 -59
- package/dist/live.d.ts +0 -39
- package/dist/live.js +0 -51
- package/dist/module/command.d.ts +0 -18
- package/dist/module/command.js +0 -42
- package/dist/module/hook.d.ts +0 -15
- package/dist/module/hook.js +0 -51
- package/dist/module/manifest.d.ts +0 -15
- package/dist/module/manifest.js +0 -44
- package/dist/module/plugin.d.ts +0 -16
- package/dist/module/plugin.js +0 -84
- package/dist/module/room.d.ts +0 -32
- package/dist/module/room.js +0 -159
- package/dist/module/value.d.ts +0 -26
- package/dist/module/value.js +0 -60
- package/dist/types/command.d.ts +0 -23
- package/dist/types/command.js +0 -2
- package/dist/types/error.d.ts +0 -10
- package/dist/types/error.js +0 -2
- package/dist/types/events.d.ts +0 -41
- package/dist/types/events.js +0 -2
- package/dist/types/hook.d.ts +0 -15
- package/dist/types/hook.js +0 -2
- package/dist/types/index.d.ts +0 -9
- package/dist/types/index.js +0 -25
- package/dist/types/manifest.d.ts +0 -4
- package/dist/types/manifest.js +0 -2
- package/dist/types/message.js +0 -2
- package/dist/types/plugin.d.ts +0 -13
- package/dist/types/plugin.js +0 -2
- package/dist/types/room.d.ts +0 -98
- package/dist/types/room.js +0 -2
- package/dist/types/value.d.ts +0 -2
- package/dist/types/value.js +0 -2
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +0 -21
- package/esm/core/LiveRoom.js +0 -77
- package/esm/core/index.js +0 -1
- package/esm/core/plugin.js +0 -24
- package/esm/enums.js +0 -56
- package/esm/index.js +0 -5
- package/esm/live.js +0 -47
- package/esm/module/command.js +0 -38
- package/esm/module/hook.js +0 -47
- package/esm/module/manifest.js +0 -40
- package/esm/module/plugin.js +0 -80
- package/esm/module/room.js +0 -155
- package/esm/module/value.js +0 -56
- package/esm/types/index.js +0 -9
- package/esm/types/manifest.js +0 -1
- package/esm/types/plugin.js +0 -1
- package/esm/types/room.js +0 -1
- package/esm/types/value.js +0 -1
- package/esm/utils.js +0 -17
package/dist/module/hook.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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 true;
|
|
42
|
-
}
|
|
43
|
-
getSnapshot() {
|
|
44
|
-
const map = {};
|
|
45
|
-
this.list.forEach((fnList, name) => {
|
|
46
|
-
map[name] = fnList.length;
|
|
47
|
-
});
|
|
48
|
-
return map;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.ModHook = ModHook;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { FloatingLive } from "../live";
|
|
2
|
-
import { FloatingManifestMap } from "../types/manifest";
|
|
3
|
-
export declare class ModManifest {
|
|
4
|
-
private list;
|
|
5
|
-
protected readonly main: FloatingLive;
|
|
6
|
-
constructor(main: FloatingLive);
|
|
7
|
-
/** 注册manifest */
|
|
8
|
-
register<T extends keyof FloatingManifestMap>(name: T, id: string, value: FloatingManifestMap[T]): void;
|
|
9
|
-
/** 取消注册manifest */
|
|
10
|
-
unregister<T extends keyof FloatingManifestMap>(name: T, id: string): void;
|
|
11
|
-
/** 获取值 */
|
|
12
|
-
get(name: string): Map<string, any> | undefined;
|
|
13
|
-
/** 获取快照 */
|
|
14
|
-
getSnapshot(): Record<string, Record<string, any>>;
|
|
15
|
-
}
|
package/dist/module/manifest.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModManifest = void 0;
|
|
4
|
-
class ModManifest {
|
|
5
|
-
constructor(main) {
|
|
6
|
-
this.list = new Map();
|
|
7
|
-
this.main = main;
|
|
8
|
-
}
|
|
9
|
-
/** 注册manifest */
|
|
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
|
-
this.main.emit("manifest:add", name, id, value);
|
|
18
|
-
}
|
|
19
|
-
/** 取消注册manifest */
|
|
20
|
-
unregister(name, id) {
|
|
21
|
-
let store = this.list.get(name);
|
|
22
|
-
if (store) {
|
|
23
|
-
store.delete(id);
|
|
24
|
-
this.main.emit("manifest:remove", name, id);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/** 获取值 */
|
|
28
|
-
get(name) {
|
|
29
|
-
return this.list.get(name);
|
|
30
|
-
}
|
|
31
|
-
/** 获取快照 */
|
|
32
|
-
getSnapshot() {
|
|
33
|
-
const map = {};
|
|
34
|
-
this.list.forEach((store, name) => {
|
|
35
|
-
const part = {};
|
|
36
|
-
map[name] = part;
|
|
37
|
-
store.forEach((value, id) => {
|
|
38
|
-
part[id] = value;
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
return map;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.ModManifest = ModManifest;
|
package/dist/module/plugin.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FloatingLive } from "../live";
|
|
2
|
-
import { PluginItem, PluginConstructor } from "../types/plugin";
|
|
3
|
-
export declare class ModPlugin {
|
|
4
|
-
/** 插件列表 */
|
|
5
|
-
private list;
|
|
6
|
-
protected readonly main: FloatingLive;
|
|
7
|
-
constructor(main: FloatingLive);
|
|
8
|
-
/** 注册插件 */
|
|
9
|
-
register(pluginFunc: PluginConstructor, options?: Record<string, any>): Promise<void | PluginItem | undefined>;
|
|
10
|
-
/** 移除插件 */
|
|
11
|
-
unregister(name: string): Promise<void>;
|
|
12
|
-
/** 获取插件实例 */
|
|
13
|
-
get(name: string): PluginItem | undefined;
|
|
14
|
-
has(name: string): boolean;
|
|
15
|
-
getSnapshot(): string[];
|
|
16
|
-
}
|
package/dist/module/plugin.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModPlugin = void 0;
|
|
4
|
-
class ModPlugin {
|
|
5
|
-
constructor(main) {
|
|
6
|
-
/** 插件列表 */
|
|
7
|
-
this.list = new Map();
|
|
8
|
-
this.main = main;
|
|
9
|
-
}
|
|
10
|
-
/** 注册插件 */
|
|
11
|
-
async register(pluginFunc, options = {}) {
|
|
12
|
-
const name = pluginFunc.pluginName;
|
|
13
|
-
if (!name) {
|
|
14
|
-
this.main.throw({
|
|
15
|
-
message: "添加插件失败",
|
|
16
|
-
reason: "缺少插件id",
|
|
17
|
-
id: "plugin:register_id_missing",
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
if (this.list.has(name)) {
|
|
21
|
-
this.main.throw({
|
|
22
|
-
message: `添加插件失败: ${name}`,
|
|
23
|
-
reason: "已存在相同id的插件",
|
|
24
|
-
id: "plugin:register_id_duplicate",
|
|
25
|
-
pluginName: name,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return await this.main.hook
|
|
29
|
-
.call("plugin.register", { name, options })
|
|
30
|
-
.then(async (res) => {
|
|
31
|
-
if (!res)
|
|
32
|
-
return;
|
|
33
|
-
// 执行插件函数
|
|
34
|
-
const plugin = new pluginFunc(this.main, options);
|
|
35
|
-
// 调用插件的register钩子
|
|
36
|
-
await plugin.register?.(this.main, options);
|
|
37
|
-
this.list.set(name, plugin);
|
|
38
|
-
this.main.emit("plugin:add", name);
|
|
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
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/** 移除插件 */
|
|
53
|
-
async unregister(name) {
|
|
54
|
-
const plugin = this.list.get(name);
|
|
55
|
-
// 检测插件是否存在
|
|
56
|
-
if (!plugin) {
|
|
57
|
-
this.main.throw({
|
|
58
|
-
message: `移除插件失败: ${name}`,
|
|
59
|
-
reason: "插件不存在",
|
|
60
|
-
id: "plugin:unregister_unexist",
|
|
61
|
-
pluginName: name,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
// 调用该插件的destroy钩子
|
|
66
|
-
await plugin.destroy?.();
|
|
67
|
-
// 从列表中移除插件
|
|
68
|
-
this.list.delete(name);
|
|
69
|
-
// 移除插件注册
|
|
70
|
-
this.main.emit("plugin:remove", name);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/** 获取插件实例 */
|
|
74
|
-
get(name) {
|
|
75
|
-
return this.list.get(name);
|
|
76
|
-
}
|
|
77
|
-
has(name) {
|
|
78
|
-
return this.list.has(name);
|
|
79
|
-
}
|
|
80
|
-
getSnapshot() {
|
|
81
|
-
return [...this.list.keys()];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.ModPlugin = ModPlugin;
|
package/dist/module/room.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { LiveRoom } from "../core/LiveRoom";
|
|
2
|
-
import { FloatingLive } from "../live";
|
|
3
|
-
import { RoomInfo } from "../types";
|
|
4
|
-
/** 直播间监听实例控制器 */
|
|
5
|
-
export declare class ModRoom {
|
|
6
|
-
private list;
|
|
7
|
-
readonly main: FloatingLive;
|
|
8
|
-
constructor(main: FloatingLive);
|
|
9
|
-
/** 添加房间监听实例 */
|
|
10
|
-
addRoom(room: LiveRoom, open?: boolean): void;
|
|
11
|
-
/** 添加房间 */
|
|
12
|
-
add(platform: string, id: number, options?: boolean | Record<string, any>): Promise<void>;
|
|
13
|
-
/** 移除房间 */
|
|
14
|
-
remove(roomKey: string): void;
|
|
15
|
-
/** 获取房间 */
|
|
16
|
-
get(roomKey: string): LiveRoom | undefined;
|
|
17
|
-
has(roomKey: string): boolean;
|
|
18
|
-
/** 获取房间信息 */
|
|
19
|
-
info(roomKey: string): RoomInfo | undefined;
|
|
20
|
-
/** 更新房间信息 */
|
|
21
|
-
update(roomKey: string): void;
|
|
22
|
-
/** 获取roomKey列表 */
|
|
23
|
-
get keys(): Array<string>;
|
|
24
|
-
/** 打开房间连接 */
|
|
25
|
-
open(roomKey: string): void;
|
|
26
|
-
/** 关闭房间连接 */
|
|
27
|
-
close(roomKey: string): void;
|
|
28
|
-
/** 更改某个房间的顺序 */
|
|
29
|
-
move(roomKey: string, position: number): void;
|
|
30
|
-
/** 获取快照 */
|
|
31
|
-
getSnapshot(): RoomInfo[];
|
|
32
|
-
}
|
package/dist/module/room.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
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({
|
|
21
|
-
message: "房间已存在",
|
|
22
|
-
id: "room:add_exist",
|
|
23
|
-
});
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
this.list.set(key, room);
|
|
27
|
-
// 添加监听事件
|
|
28
|
-
// 直播消息
|
|
29
|
-
room.on("message", (data) => {
|
|
30
|
-
this.main.hook.call("message", { 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("connecting", () => {
|
|
40
|
-
this.main.emit("room:connecting", key);
|
|
41
|
-
});
|
|
42
|
-
// 连接到服务器
|
|
43
|
-
room.on("connected", () => {
|
|
44
|
-
this.main.emit("room:connected", key);
|
|
45
|
-
});
|
|
46
|
-
// 与服务器的连接已断开
|
|
47
|
-
room.on("disconnect", () => {
|
|
48
|
-
this.main.emit("room:disconnect", key);
|
|
49
|
-
});
|
|
50
|
-
// 连接到直播间
|
|
51
|
-
room.on("enter", () => {
|
|
52
|
-
this.main.emit("room:enter", key);
|
|
53
|
-
});
|
|
54
|
-
// 获取房间信息
|
|
55
|
-
room.on("info", () => {
|
|
56
|
-
this.main.emit("room:info", key, room.info);
|
|
57
|
-
});
|
|
58
|
-
// 直播展示信息更改
|
|
59
|
-
room.on("detail", (data) => {
|
|
60
|
-
this.main.emit("room:detail", key, data);
|
|
61
|
-
});
|
|
62
|
-
// 直播状态更改
|
|
63
|
-
room.on("status", (status, { id, timestamp }) => {
|
|
64
|
-
this.main.emit("room:status", key, { status, id, timestamp });
|
|
65
|
-
});
|
|
66
|
-
// 统计数据更新
|
|
67
|
-
room.on("stats", (data) => {
|
|
68
|
-
this.main.emit("room:stats", key, data);
|
|
69
|
-
});
|
|
70
|
-
// 房间被打开
|
|
71
|
-
room.on("open", () => {
|
|
72
|
-
this.main.emit("room:open", key, room.info);
|
|
73
|
-
});
|
|
74
|
-
// 房间被关闭
|
|
75
|
-
room.on("close", () => {
|
|
76
|
-
this.main.emit("room:close", key, room.info);
|
|
77
|
-
});
|
|
78
|
-
if (open) {
|
|
79
|
-
room.open();
|
|
80
|
-
}
|
|
81
|
-
this.main.emit("room:add", key, room.info);
|
|
82
|
-
}
|
|
83
|
-
/** 添加房间 */
|
|
84
|
-
async add(platform, id, options) {
|
|
85
|
-
const opt = typeof options == "boolean" ? { open: options } : options || {};
|
|
86
|
-
const ctx = { platform, id, options: opt };
|
|
87
|
-
const res = await this.main.hook.call("room.add", ctx);
|
|
88
|
-
if (!res) {
|
|
89
|
-
this.main.throw({ message: "无法添加房间", id: "room:add_fail" });
|
|
90
|
-
}
|
|
91
|
-
const room = await this.main.call(`${platform}.room.create`, id, opt);
|
|
92
|
-
if (!room) {
|
|
93
|
-
this.main.throw({ message: "无法创建房间", id: "room:create_fail" });
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
this.addRoom(room);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/** 移除房间 */
|
|
100
|
-
remove(roomKey) {
|
|
101
|
-
let room = this.list.get(roomKey);
|
|
102
|
-
if (!room) {
|
|
103
|
-
this.main.throw({
|
|
104
|
-
message: "房间不存在",
|
|
105
|
-
id: "room:remove_unexist",
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
this.list.delete(roomKey); // 从表中删除房间
|
|
109
|
-
room?.removeAllListeners(); // 移除房间监听实例
|
|
110
|
-
this.main.emit("room:remove", roomKey);
|
|
111
|
-
}
|
|
112
|
-
/** 获取房间 */
|
|
113
|
-
get(roomKey) {
|
|
114
|
-
return this.list.get(roomKey);
|
|
115
|
-
}
|
|
116
|
-
has(roomKey) {
|
|
117
|
-
return this.list.has(roomKey);
|
|
118
|
-
}
|
|
119
|
-
/** 获取房间信息 */
|
|
120
|
-
info(roomKey) {
|
|
121
|
-
let room = this.list.get(roomKey);
|
|
122
|
-
return room ? room.info : undefined;
|
|
123
|
-
}
|
|
124
|
-
/** 更新房间信息 */
|
|
125
|
-
update(roomKey) {
|
|
126
|
-
let room = this.list.get(roomKey);
|
|
127
|
-
room && room.getInfo();
|
|
128
|
-
}
|
|
129
|
-
/** 获取roomKey列表 */
|
|
130
|
-
get keys() {
|
|
131
|
-
return [...this.list.keys()];
|
|
132
|
-
}
|
|
133
|
-
/** 打开房间连接 */
|
|
134
|
-
open(roomKey) {
|
|
135
|
-
let room = this.list.get(roomKey);
|
|
136
|
-
room?.available && !room.opened && room.open();
|
|
137
|
-
}
|
|
138
|
-
/** 关闭房间连接 */
|
|
139
|
-
close(roomKey) {
|
|
140
|
-
let room = this.list.get(roomKey);
|
|
141
|
-
room?.opened && room.close();
|
|
142
|
-
}
|
|
143
|
-
/** 更改某个房间的顺序 */
|
|
144
|
-
move(roomKey, position) {
|
|
145
|
-
const arr = [...this.list];
|
|
146
|
-
const index = arr.findIndex(([key]) => key == roomKey);
|
|
147
|
-
if (index == -1)
|
|
148
|
-
return;
|
|
149
|
-
const [item] = arr.splice(index, 1);
|
|
150
|
-
arr.splice(position, 0, item);
|
|
151
|
-
this.list = new Map(arr);
|
|
152
|
-
this.main.emit("room:move", roomKey, position);
|
|
153
|
-
}
|
|
154
|
-
/** 获取快照 */
|
|
155
|
-
getSnapshot() {
|
|
156
|
-
return [...this.list.values()].map((room) => room.info);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
exports.ModRoom = ModRoom;
|
package/dist/module/value.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { FloatingLive } from "../live";
|
|
2
|
-
import { FloatingValueMap } from "../types/value";
|
|
3
|
-
interface ValueConfig<T> {
|
|
4
|
-
get: () => T;
|
|
5
|
-
set?: (value: T) => void;
|
|
6
|
-
}
|
|
7
|
-
export declare class ModValue {
|
|
8
|
-
private list;
|
|
9
|
-
protected readonly main: FloatingLive;
|
|
10
|
-
constructor(main: FloatingLive);
|
|
11
|
-
/** 注册值 */
|
|
12
|
-
register<T extends keyof FloatingValueMap>(name: T, config: ValueConfig<FloatingValueMap[T]>): void;
|
|
13
|
-
/** 取消注册 */
|
|
14
|
-
unregister(name: string): void;
|
|
15
|
-
/** 获取值 */
|
|
16
|
-
get<T extends keyof FloatingValueMap>(name: T): any;
|
|
17
|
-
/** 设置值 */
|
|
18
|
-
set<T extends keyof FloatingValueMap>(name: T, value: FloatingValueMap[T]): boolean;
|
|
19
|
-
has(name: string): boolean;
|
|
20
|
-
emit<T extends keyof FloatingValueMap>(name: T, value: FloatingValueMap[T]): void;
|
|
21
|
-
watch<T extends keyof FloatingValueMap>(name: T, listener: (value: FloatingValueMap[T]) => void): void;
|
|
22
|
-
unwatch<T extends keyof FloatingValueMap>(name: T, listener: (value: FloatingValueMap[T]) => void): void;
|
|
23
|
-
/** 获取注册的所有值 */
|
|
24
|
-
getSnapshot(): Record<string, any>;
|
|
25
|
-
}
|
|
26
|
-
export {};
|
package/dist/module/value.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModValue = void 0;
|
|
4
|
-
class ModValue {
|
|
5
|
-
constructor(main) {
|
|
6
|
-
this.list = new Map();
|
|
7
|
-
this.main = main;
|
|
8
|
-
const { command } = main;
|
|
9
|
-
command.register("get", this.get.bind(this));
|
|
10
|
-
command.register("set", this.set.bind(this));
|
|
11
|
-
}
|
|
12
|
-
/** 注册值 */
|
|
13
|
-
register(name, config) {
|
|
14
|
-
this.list.set(name, config);
|
|
15
|
-
this.main.emit("value:add", name);
|
|
16
|
-
this.main.emit("value:change", name, config.get());
|
|
17
|
-
}
|
|
18
|
-
/** 取消注册 */
|
|
19
|
-
unregister(name) {
|
|
20
|
-
this.list.delete(name);
|
|
21
|
-
this.main.emit("value:remove", name);
|
|
22
|
-
}
|
|
23
|
-
/** 获取值 */
|
|
24
|
-
get(name) {
|
|
25
|
-
return this.list.get(name)?.get();
|
|
26
|
-
}
|
|
27
|
-
/** 设置值 */
|
|
28
|
-
set(name, value) {
|
|
29
|
-
const valueConfig = this.list.get(name);
|
|
30
|
-
if (valueConfig?.set) {
|
|
31
|
-
valueConfig?.set(value);
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
has(name) {
|
|
39
|
-
return this.list.has(name);
|
|
40
|
-
}
|
|
41
|
-
emit(name, value) {
|
|
42
|
-
this.main.emit(`change:${name}`, value);
|
|
43
|
-
this.main.emit("value:change", name, value);
|
|
44
|
-
}
|
|
45
|
-
watch(name, listener) {
|
|
46
|
-
this.main.on(`change:${name}`, listener);
|
|
47
|
-
}
|
|
48
|
-
unwatch(name, listener) {
|
|
49
|
-
this.main.off(`change:${name}`, listener);
|
|
50
|
-
}
|
|
51
|
-
/** 获取注册的所有值 */
|
|
52
|
-
getSnapshot() {
|
|
53
|
-
const map = {};
|
|
54
|
-
this.list.forEach((config, name) => {
|
|
55
|
-
map[name] = config.get();
|
|
56
|
-
});
|
|
57
|
-
return map;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.ModValue = ModValue;
|
package/dist/types/command.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { LiveRoom } from "../core";
|
|
2
|
-
import { RoomInfo } from "./room";
|
|
3
|
-
import { FloatingValueMap } from "./value";
|
|
4
|
-
export interface FloatingCommandMap {
|
|
5
|
-
/** 添加房间 */
|
|
6
|
-
add: (platform: string, id: number, options?: boolean | Record<string, any>) => void;
|
|
7
|
-
/** 移除房间 */
|
|
8
|
-
remove: (key: string) => void;
|
|
9
|
-
/** 打开房间 */
|
|
10
|
-
open: (key: string) => void;
|
|
11
|
-
/** 关闭房间 */
|
|
12
|
-
close: (key: string) => void;
|
|
13
|
-
/** 更新房间信息 */
|
|
14
|
-
update: (key: string) => void;
|
|
15
|
-
/** 创建房间 */
|
|
16
|
-
[name: `${string}.room.create`]: (id: string | number, options?: Record<string, any>) => Promise<LiveRoom> | LiveRoom;
|
|
17
|
-
/** 获取房间信息 */
|
|
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;
|
|
23
|
-
}
|
package/dist/types/command.js
DELETED
package/dist/types/error.d.ts
DELETED
package/dist/types/error.js
DELETED
package/dist/types/events.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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, { platform, room }: {
|
|
7
|
-
platform: string;
|
|
8
|
-
room: string | number;
|
|
9
|
-
}) => void;
|
|
10
|
-
"room:connecting": (key: string) => void;
|
|
11
|
-
"room:connected": (key: string) => void;
|
|
12
|
-
"room:enter": (key: string) => void;
|
|
13
|
-
"room:disconnect": (key: string) => void;
|
|
14
|
-
"room:info": (key: string, info: RoomInfo) => void;
|
|
15
|
-
"room:detail": (key: string, info: RoomDetail) => void;
|
|
16
|
-
"room:status": (key: string, info: {
|
|
17
|
-
status: RoomStatus;
|
|
18
|
-
id?: string;
|
|
19
|
-
timestamp?: number;
|
|
20
|
-
}) => void;
|
|
21
|
-
"room:stats": (key: string, info: RoomStatsInfo) => void;
|
|
22
|
-
"room:open": (key: string, info: RoomInfo) => void;
|
|
23
|
-
"room:close": (key: string, info: RoomInfo) => void;
|
|
24
|
-
"room:add": (key: string, info: RoomInfo) => void;
|
|
25
|
-
"room:remove": (key: string) => void;
|
|
26
|
-
"room:move": (key: string, position: number) => void;
|
|
27
|
-
"plugin:add": (name: string) => void;
|
|
28
|
-
"plugin:remove": (name: string) => void;
|
|
29
|
-
"command:add": (name: string) => void;
|
|
30
|
-
"command:remove": (name: string) => void;
|
|
31
|
-
"manifest:add": (name: string, id: string, value: any) => void;
|
|
32
|
-
"manifest:remove": (name: string, id: string) => void;
|
|
33
|
-
"hook:add": (name: string) => void;
|
|
34
|
-
"hook:remove": (name: string) => void;
|
|
35
|
-
"value:add": (name: string) => void;
|
|
36
|
-
"value:remove": (name: string) => void;
|
|
37
|
-
"value:change": (name: string, value: any) => void;
|
|
38
|
-
[name: `change:${string}`]: (value: any) => void;
|
|
39
|
-
event: (eventName: string, ...args: any[]) => void;
|
|
40
|
-
error: (err: Error) => void;
|
|
41
|
-
}
|
package/dist/types/events.js
DELETED
package/dist/types/hook.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Message } from "./message";
|
|
2
|
-
export interface FloatingHookMap {
|
|
3
|
-
message: {
|
|
4
|
-
message: Message.All;
|
|
5
|
-
};
|
|
6
|
-
"room.add": {
|
|
7
|
-
platform: string;
|
|
8
|
-
id: string | number;
|
|
9
|
-
options: Record<string, any>;
|
|
10
|
-
};
|
|
11
|
-
"plugin.register": {
|
|
12
|
-
name: string;
|
|
13
|
-
options: Record<string, any>;
|
|
14
|
-
};
|
|
15
|
-
}
|
package/dist/types/hook.js
DELETED
package/dist/types/index.d.ts
DELETED
package/dist/types/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./message"), exports);
|
|
18
|
-
__exportStar(require("./plugin"), exports);
|
|
19
|
-
__exportStar(require("./room"), exports);
|
|
20
|
-
__exportStar(require("./command"), exports);
|
|
21
|
-
__exportStar(require("./events"), exports);
|
|
22
|
-
__exportStar(require("./manifest"), exports);
|
|
23
|
-
__exportStar(require("./hook"), exports);
|
|
24
|
-
__exportStar(require("./value"), exports);
|
|
25
|
-
__exportStar(require("./error"), exports);
|
package/dist/types/manifest.d.ts
DELETED
package/dist/types/manifest.js
DELETED
package/dist/types/message.js
DELETED
package/dist/types/plugin.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FloatingLive } from "../live";
|
|
2
|
-
/** 插件对象 */
|
|
3
|
-
export interface PluginItem {
|
|
4
|
-
pluginName?: string;
|
|
5
|
-
register?(ctx: FloatingLive, options: any): void | Promise<void>;
|
|
6
|
-
destroy?(): void | Promise<void>;
|
|
7
|
-
[name: string]: any;
|
|
8
|
-
}
|
|
9
|
-
/** 插件构造器 */
|
|
10
|
-
export interface PluginConstructor {
|
|
11
|
-
pluginName: string;
|
|
12
|
-
new (ctx: FloatingLive, options: any): PluginItem;
|
|
13
|
-
}
|
package/dist/types/plugin.js
DELETED