floating-live 0.15.9 → 0.15.11
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/module/plugin.js +4 -3
- package/dist/module/room.d.ts +12 -10
- package/dist/module/room.js +33 -28
- package/dist/module/value.js +0 -1
- package/esm/module/plugin.js +4 -3
- package/esm/module/room.js +33 -28
- package/esm/module/value.js +0 -1
- package/package.json +1 -1
package/dist/module/plugin.js
CHANGED
|
@@ -25,15 +25,16 @@ class ModPlugin {
|
|
|
25
25
|
pluginName: name,
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
+
const ctx = { name, options };
|
|
28
29
|
return await this.main.hook
|
|
29
|
-
.call("plugin.register",
|
|
30
|
+
.call("plugin.register", ctx)
|
|
30
31
|
.then(async (res) => {
|
|
31
32
|
if (!res)
|
|
32
33
|
return;
|
|
33
34
|
// 执行插件函数
|
|
34
|
-
const plugin = new pluginFunc(this.main, options);
|
|
35
|
+
const plugin = new pluginFunc(this.main, ctx.options || {});
|
|
35
36
|
// 调用插件的register钩子
|
|
36
|
-
await plugin.register?.(this.main, options);
|
|
37
|
+
await plugin.register?.(this.main, ctx.options || {});
|
|
37
38
|
this.list.set(name, plugin);
|
|
38
39
|
this.main.emit("plugin:add", name);
|
|
39
40
|
return plugin;
|
package/dist/module/room.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { FloatingLive } from "../live";
|
|
|
3
3
|
import { RoomInfo } from "../types";
|
|
4
4
|
/** 直播间监听实例控制器 */
|
|
5
5
|
export declare class ModRoom {
|
|
6
|
-
private
|
|
6
|
+
private map;
|
|
7
7
|
readonly main: FloatingLive;
|
|
8
8
|
constructor(main: FloatingLive);
|
|
9
9
|
/** 添加房间监听实例 */
|
|
@@ -11,22 +11,24 @@ export declare class ModRoom {
|
|
|
11
11
|
/** 添加房间 */
|
|
12
12
|
add(platform: string, id: number, options?: boolean | Record<string, any>): Promise<void>;
|
|
13
13
|
/** 移除房间 */
|
|
14
|
-
remove(
|
|
14
|
+
remove(key: string): void;
|
|
15
15
|
/** 获取房间 */
|
|
16
|
-
get(
|
|
17
|
-
has(
|
|
16
|
+
get(key: string): LiveRoom | undefined;
|
|
17
|
+
has(key: string): boolean;
|
|
18
18
|
/** 获取房间信息 */
|
|
19
|
-
info(
|
|
19
|
+
info(key: string): RoomInfo | undefined;
|
|
20
20
|
/** 更新房间信息 */
|
|
21
|
-
update(
|
|
22
|
-
/**
|
|
21
|
+
update(key: string): void;
|
|
22
|
+
/** 获取房间key列表 */
|
|
23
23
|
get keys(): Array<string>;
|
|
24
|
+
/** 获取房间列表 */
|
|
25
|
+
getList(): Array<LiveRoom>;
|
|
24
26
|
/** 打开房间连接 */
|
|
25
|
-
open(
|
|
27
|
+
open(key: string): void;
|
|
26
28
|
/** 关闭房间连接 */
|
|
27
|
-
close(
|
|
29
|
+
close(key: string): void;
|
|
28
30
|
/** 更改某个房间的顺序 */
|
|
29
|
-
move(
|
|
31
|
+
move(key: string, position: number): void;
|
|
30
32
|
/** 获取快照 */
|
|
31
33
|
getSnapshot(): RoomInfo[];
|
|
32
34
|
}
|
package/dist/module/room.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.ModRoom = void 0;
|
|
|
4
4
|
/** 直播间监听实例控制器 */
|
|
5
5
|
class ModRoom {
|
|
6
6
|
constructor(main) {
|
|
7
|
-
this.
|
|
7
|
+
this.map = new Map();
|
|
8
8
|
this.main = main;
|
|
9
9
|
const { command } = main;
|
|
10
10
|
command.register("add", this.add.bind(this));
|
|
@@ -16,19 +16,20 @@ class ModRoom {
|
|
|
16
16
|
/** 添加房间监听实例 */
|
|
17
17
|
addRoom(room, open) {
|
|
18
18
|
let key = room.key;
|
|
19
|
-
if (this.
|
|
19
|
+
if (this.map.has(key)) {
|
|
20
20
|
this.main.throw({
|
|
21
21
|
message: "房间已存在",
|
|
22
22
|
id: "room:add_exist",
|
|
23
23
|
});
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
this.
|
|
26
|
+
this.map.set(key, room);
|
|
27
27
|
// 添加监听事件
|
|
28
28
|
// 直播消息
|
|
29
29
|
room.on("message", (data) => {
|
|
30
|
+
const ctx = { message: data };
|
|
30
31
|
this.main.hook.call("message", { message: data }).then((res) => {
|
|
31
|
-
res && this.main.emit("live:message",
|
|
32
|
+
res && this.main.emit("live:message", ctx.message);
|
|
32
33
|
});
|
|
33
34
|
});
|
|
34
35
|
// 直播消息源数据
|
|
@@ -97,63 +98,67 @@ class ModRoom {
|
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
/** 移除房间 */
|
|
100
|
-
remove(
|
|
101
|
-
let room = this.
|
|
101
|
+
remove(key) {
|
|
102
|
+
let room = this.map.get(key);
|
|
102
103
|
if (!room) {
|
|
103
104
|
this.main.throw({
|
|
104
105
|
message: "房间不存在",
|
|
105
106
|
id: "room:remove_unexist",
|
|
106
107
|
});
|
|
107
108
|
}
|
|
108
|
-
this.
|
|
109
|
+
this.map.delete(key); // 从表中删除房间
|
|
109
110
|
room?.removeAllListeners(); // 移除房间监听实例
|
|
110
|
-
this.main.emit("room:remove",
|
|
111
|
+
this.main.emit("room:remove", key);
|
|
111
112
|
}
|
|
112
113
|
/** 获取房间 */
|
|
113
|
-
get(
|
|
114
|
-
return this.
|
|
114
|
+
get(key) {
|
|
115
|
+
return this.map.get(key);
|
|
115
116
|
}
|
|
116
|
-
has(
|
|
117
|
-
return this.
|
|
117
|
+
has(key) {
|
|
118
|
+
return this.map.has(key);
|
|
118
119
|
}
|
|
119
120
|
/** 获取房间信息 */
|
|
120
|
-
info(
|
|
121
|
-
let room = this.
|
|
121
|
+
info(key) {
|
|
122
|
+
let room = this.map.get(key);
|
|
122
123
|
return room ? room.info : undefined;
|
|
123
124
|
}
|
|
124
125
|
/** 更新房间信息 */
|
|
125
|
-
update(
|
|
126
|
-
let room = this.
|
|
126
|
+
update(key) {
|
|
127
|
+
let room = this.map.get(key);
|
|
127
128
|
room && room.getInfo();
|
|
128
129
|
}
|
|
129
|
-
/**
|
|
130
|
+
/** 获取房间key列表 */
|
|
130
131
|
get keys() {
|
|
131
|
-
return [...this.
|
|
132
|
+
return [...this.map.keys()];
|
|
133
|
+
}
|
|
134
|
+
/** 获取房间列表 */
|
|
135
|
+
getList() {
|
|
136
|
+
return [...this.map.values()];
|
|
132
137
|
}
|
|
133
138
|
/** 打开房间连接 */
|
|
134
|
-
open(
|
|
135
|
-
let room = this.
|
|
139
|
+
open(key) {
|
|
140
|
+
let room = this.map.get(key);
|
|
136
141
|
room?.available && !room.opened && room.open();
|
|
137
142
|
}
|
|
138
143
|
/** 关闭房间连接 */
|
|
139
|
-
close(
|
|
140
|
-
let room = this.
|
|
144
|
+
close(key) {
|
|
145
|
+
let room = this.map.get(key);
|
|
141
146
|
room?.opened && room.close();
|
|
142
147
|
}
|
|
143
148
|
/** 更改某个房间的顺序 */
|
|
144
|
-
move(
|
|
145
|
-
const arr = [...this.
|
|
146
|
-
const index = arr.findIndex(([
|
|
149
|
+
move(key, position) {
|
|
150
|
+
const arr = [...this.map];
|
|
151
|
+
const index = arr.findIndex(([k]) => k == key);
|
|
147
152
|
if (index == -1)
|
|
148
153
|
return;
|
|
149
154
|
const [item] = arr.splice(index, 1);
|
|
150
155
|
arr.splice(position, 0, item);
|
|
151
|
-
this.
|
|
152
|
-
this.main.emit("room:move",
|
|
156
|
+
this.map = new Map(arr);
|
|
157
|
+
this.main.emit("room:move", key, position);
|
|
153
158
|
}
|
|
154
159
|
/** 获取快照 */
|
|
155
160
|
getSnapshot() {
|
|
156
|
-
return
|
|
161
|
+
return this.getList().map((room) => room.info);
|
|
157
162
|
}
|
|
158
163
|
}
|
|
159
164
|
exports.ModRoom = ModRoom;
|
package/dist/module/value.js
CHANGED
package/esm/module/plugin.js
CHANGED
|
@@ -22,15 +22,16 @@ export class ModPlugin {
|
|
|
22
22
|
pluginName: name,
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
const ctx = { name, options };
|
|
25
26
|
return await this.main.hook
|
|
26
|
-
.call("plugin.register",
|
|
27
|
+
.call("plugin.register", ctx)
|
|
27
28
|
.then(async (res) => {
|
|
28
29
|
if (!res)
|
|
29
30
|
return;
|
|
30
31
|
// 执行插件函数
|
|
31
|
-
const plugin = new pluginFunc(this.main, options);
|
|
32
|
+
const plugin = new pluginFunc(this.main, ctx.options || {});
|
|
32
33
|
// 调用插件的register钩子
|
|
33
|
-
await plugin.register?.(this.main, options);
|
|
34
|
+
await plugin.register?.(this.main, ctx.options || {});
|
|
34
35
|
this.list.set(name, plugin);
|
|
35
36
|
this.main.emit("plugin:add", name);
|
|
36
37
|
return plugin;
|
package/esm/module/room.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** 直播间监听实例控制器 */
|
|
2
2
|
export class ModRoom {
|
|
3
3
|
constructor(main) {
|
|
4
|
-
this.
|
|
4
|
+
this.map = new Map();
|
|
5
5
|
this.main = main;
|
|
6
6
|
const { command } = main;
|
|
7
7
|
command.register("add", this.add.bind(this));
|
|
@@ -13,19 +13,20 @@ export class ModRoom {
|
|
|
13
13
|
/** 添加房间监听实例 */
|
|
14
14
|
addRoom(room, open) {
|
|
15
15
|
let key = room.key;
|
|
16
|
-
if (this.
|
|
16
|
+
if (this.map.has(key)) {
|
|
17
17
|
this.main.throw({
|
|
18
18
|
message: "房间已存在",
|
|
19
19
|
id: "room:add_exist",
|
|
20
20
|
});
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
this.
|
|
23
|
+
this.map.set(key, room);
|
|
24
24
|
// 添加监听事件
|
|
25
25
|
// 直播消息
|
|
26
26
|
room.on("message", (data) => {
|
|
27
|
+
const ctx = { message: data };
|
|
27
28
|
this.main.hook.call("message", { message: data }).then((res) => {
|
|
28
|
-
res && this.main.emit("live:message",
|
|
29
|
+
res && this.main.emit("live:message", ctx.message);
|
|
29
30
|
});
|
|
30
31
|
});
|
|
31
32
|
// 直播消息源数据
|
|
@@ -94,62 +95,66 @@ export class ModRoom {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
/** 移除房间 */
|
|
97
|
-
remove(
|
|
98
|
-
let room = this.
|
|
98
|
+
remove(key) {
|
|
99
|
+
let room = this.map.get(key);
|
|
99
100
|
if (!room) {
|
|
100
101
|
this.main.throw({
|
|
101
102
|
message: "房间不存在",
|
|
102
103
|
id: "room:remove_unexist",
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
|
-
this.
|
|
106
|
+
this.map.delete(key); // 从表中删除房间
|
|
106
107
|
room?.removeAllListeners(); // 移除房间监听实例
|
|
107
|
-
this.main.emit("room:remove",
|
|
108
|
+
this.main.emit("room:remove", key);
|
|
108
109
|
}
|
|
109
110
|
/** 获取房间 */
|
|
110
|
-
get(
|
|
111
|
-
return this.
|
|
111
|
+
get(key) {
|
|
112
|
+
return this.map.get(key);
|
|
112
113
|
}
|
|
113
|
-
has(
|
|
114
|
-
return this.
|
|
114
|
+
has(key) {
|
|
115
|
+
return this.map.has(key);
|
|
115
116
|
}
|
|
116
117
|
/** 获取房间信息 */
|
|
117
|
-
info(
|
|
118
|
-
let room = this.
|
|
118
|
+
info(key) {
|
|
119
|
+
let room = this.map.get(key);
|
|
119
120
|
return room ? room.info : undefined;
|
|
120
121
|
}
|
|
121
122
|
/** 更新房间信息 */
|
|
122
|
-
update(
|
|
123
|
-
let room = this.
|
|
123
|
+
update(key) {
|
|
124
|
+
let room = this.map.get(key);
|
|
124
125
|
room && room.getInfo();
|
|
125
126
|
}
|
|
126
|
-
/**
|
|
127
|
+
/** 获取房间key列表 */
|
|
127
128
|
get keys() {
|
|
128
|
-
return [...this.
|
|
129
|
+
return [...this.map.keys()];
|
|
130
|
+
}
|
|
131
|
+
/** 获取房间列表 */
|
|
132
|
+
getList() {
|
|
133
|
+
return [...this.map.values()];
|
|
129
134
|
}
|
|
130
135
|
/** 打开房间连接 */
|
|
131
|
-
open(
|
|
132
|
-
let room = this.
|
|
136
|
+
open(key) {
|
|
137
|
+
let room = this.map.get(key);
|
|
133
138
|
room?.available && !room.opened && room.open();
|
|
134
139
|
}
|
|
135
140
|
/** 关闭房间连接 */
|
|
136
|
-
close(
|
|
137
|
-
let room = this.
|
|
141
|
+
close(key) {
|
|
142
|
+
let room = this.map.get(key);
|
|
138
143
|
room?.opened && room.close();
|
|
139
144
|
}
|
|
140
145
|
/** 更改某个房间的顺序 */
|
|
141
|
-
move(
|
|
142
|
-
const arr = [...this.
|
|
143
|
-
const index = arr.findIndex(([
|
|
146
|
+
move(key, position) {
|
|
147
|
+
const arr = [...this.map];
|
|
148
|
+
const index = arr.findIndex(([k]) => k == key);
|
|
144
149
|
if (index == -1)
|
|
145
150
|
return;
|
|
146
151
|
const [item] = arr.splice(index, 1);
|
|
147
152
|
arr.splice(position, 0, item);
|
|
148
|
-
this.
|
|
149
|
-
this.main.emit("room:move",
|
|
153
|
+
this.map = new Map(arr);
|
|
154
|
+
this.main.emit("room:move", key, position);
|
|
150
155
|
}
|
|
151
156
|
/** 获取快照 */
|
|
152
157
|
getSnapshot() {
|
|
153
|
-
return
|
|
158
|
+
return this.getList().map((room) => room.info);
|
|
154
159
|
}
|
|
155
160
|
}
|
package/esm/module/value.js
CHANGED