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.
@@ -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", { name, options })
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;
@@ -3,7 +3,7 @@ import { FloatingLive } from "../live";
3
3
  import { RoomInfo } from "../types";
4
4
  /** 直播间监听实例控制器 */
5
5
  export declare class ModRoom {
6
- private list;
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(roomKey: string): void;
14
+ remove(key: string): void;
15
15
  /** 获取房间 */
16
- get(roomKey: string): LiveRoom | undefined;
17
- has(roomKey: string): boolean;
16
+ get(key: string): LiveRoom | undefined;
17
+ has(key: string): boolean;
18
18
  /** 获取房间信息 */
19
- info(roomKey: string): RoomInfo | undefined;
19
+ info(key: string): RoomInfo | undefined;
20
20
  /** 更新房间信息 */
21
- update(roomKey: string): void;
22
- /** 获取roomKey列表 */
21
+ update(key: string): void;
22
+ /** 获取房间key列表 */
23
23
  get keys(): Array<string>;
24
+ /** 获取房间列表 */
25
+ getList(): Array<LiveRoom>;
24
26
  /** 打开房间连接 */
25
- open(roomKey: string): void;
27
+ open(key: string): void;
26
28
  /** 关闭房间连接 */
27
- close(roomKey: string): void;
29
+ close(key: string): void;
28
30
  /** 更改某个房间的顺序 */
29
- move(roomKey: string, position: number): void;
31
+ move(key: string, position: number): void;
30
32
  /** 获取快照 */
31
33
  getSnapshot(): RoomInfo[];
32
34
  }
@@ -4,7 +4,7 @@ exports.ModRoom = void 0;
4
4
  /** 直播间监听实例控制器 */
5
5
  class ModRoom {
6
6
  constructor(main) {
7
- this.list = new Map();
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.list.has(key)) {
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.list.set(key, room);
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", data);
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(roomKey) {
101
- let room = this.list.get(roomKey);
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.list.delete(roomKey); // 从表中删除房间
109
+ this.map.delete(key); // 从表中删除房间
109
110
  room?.removeAllListeners(); // 移除房间监听实例
110
- this.main.emit("room:remove", roomKey);
111
+ this.main.emit("room:remove", key);
111
112
  }
112
113
  /** 获取房间 */
113
- get(roomKey) {
114
- return this.list.get(roomKey);
114
+ get(key) {
115
+ return this.map.get(key);
115
116
  }
116
- has(roomKey) {
117
- return this.list.has(roomKey);
117
+ has(key) {
118
+ return this.map.has(key);
118
119
  }
119
120
  /** 获取房间信息 */
120
- info(roomKey) {
121
- let room = this.list.get(roomKey);
121
+ info(key) {
122
+ let room = this.map.get(key);
122
123
  return room ? room.info : undefined;
123
124
  }
124
125
  /** 更新房间信息 */
125
- update(roomKey) {
126
- let room = this.list.get(roomKey);
126
+ update(key) {
127
+ let room = this.map.get(key);
127
128
  room && room.getInfo();
128
129
  }
129
- /** 获取roomKey列表 */
130
+ /** 获取房间key列表 */
130
131
  get keys() {
131
- return [...this.list.keys()];
132
+ return [...this.map.keys()];
133
+ }
134
+ /** 获取房间列表 */
135
+ getList() {
136
+ return [...this.map.values()];
132
137
  }
133
138
  /** 打开房间连接 */
134
- open(roomKey) {
135
- let room = this.list.get(roomKey);
139
+ open(key) {
140
+ let room = this.map.get(key);
136
141
  room?.available && !room.opened && room.open();
137
142
  }
138
143
  /** 关闭房间连接 */
139
- close(roomKey) {
140
- let room = this.list.get(roomKey);
144
+ close(key) {
145
+ let room = this.map.get(key);
141
146
  room?.opened && room.close();
142
147
  }
143
148
  /** 更改某个房间的顺序 */
144
- move(roomKey, position) {
145
- const arr = [...this.list];
146
- const index = arr.findIndex(([key]) => key == roomKey);
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.list = new Map(arr);
152
- this.main.emit("room:move", roomKey, position);
156
+ this.map = new Map(arr);
157
+ this.main.emit("room:move", key, position);
153
158
  }
154
159
  /** 获取快照 */
155
160
  getSnapshot() {
156
- return [...this.list.values()].map((room) => room.info);
161
+ return this.getList().map((room) => room.info);
157
162
  }
158
163
  }
159
164
  exports.ModRoom = ModRoom;
@@ -19,7 +19,6 @@ class ModValue {
19
19
  unregister(name) {
20
20
  this.list.delete(name);
21
21
  this.main.emit("value:remove", name);
22
- this.main.emit("value:change", name, undefined);
23
22
  }
24
23
  /** 获取值 */
25
24
  get(name) {
@@ -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", { name, options })
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;
@@ -1,7 +1,7 @@
1
1
  /** 直播间监听实例控制器 */
2
2
  export class ModRoom {
3
3
  constructor(main) {
4
- this.list = new Map();
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.list.has(key)) {
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.list.set(key, room);
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", data);
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(roomKey) {
98
- let room = this.list.get(roomKey);
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.list.delete(roomKey); // 从表中删除房间
106
+ this.map.delete(key); // 从表中删除房间
106
107
  room?.removeAllListeners(); // 移除房间监听实例
107
- this.main.emit("room:remove", roomKey);
108
+ this.main.emit("room:remove", key);
108
109
  }
109
110
  /** 获取房间 */
110
- get(roomKey) {
111
- return this.list.get(roomKey);
111
+ get(key) {
112
+ return this.map.get(key);
112
113
  }
113
- has(roomKey) {
114
- return this.list.has(roomKey);
114
+ has(key) {
115
+ return this.map.has(key);
115
116
  }
116
117
  /** 获取房间信息 */
117
- info(roomKey) {
118
- let room = this.list.get(roomKey);
118
+ info(key) {
119
+ let room = this.map.get(key);
119
120
  return room ? room.info : undefined;
120
121
  }
121
122
  /** 更新房间信息 */
122
- update(roomKey) {
123
- let room = this.list.get(roomKey);
123
+ update(key) {
124
+ let room = this.map.get(key);
124
125
  room && room.getInfo();
125
126
  }
126
- /** 获取roomKey列表 */
127
+ /** 获取房间key列表 */
127
128
  get keys() {
128
- return [...this.list.keys()];
129
+ return [...this.map.keys()];
130
+ }
131
+ /** 获取房间列表 */
132
+ getList() {
133
+ return [...this.map.values()];
129
134
  }
130
135
  /** 打开房间连接 */
131
- open(roomKey) {
132
- let room = this.list.get(roomKey);
136
+ open(key) {
137
+ let room = this.map.get(key);
133
138
  room?.available && !room.opened && room.open();
134
139
  }
135
140
  /** 关闭房间连接 */
136
- close(roomKey) {
137
- let room = this.list.get(roomKey);
141
+ close(key) {
142
+ let room = this.map.get(key);
138
143
  room?.opened && room.close();
139
144
  }
140
145
  /** 更改某个房间的顺序 */
141
- move(roomKey, position) {
142
- const arr = [...this.list];
143
- const index = arr.findIndex(([key]) => key == roomKey);
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.list = new Map(arr);
149
- this.main.emit("room:move", roomKey, position);
153
+ this.map = new Map(arr);
154
+ this.main.emit("room:move", key, position);
150
155
  }
151
156
  /** 获取快照 */
152
157
  getSnapshot() {
153
- return [...this.list.values()].map((room) => room.info);
158
+ return this.getList().map((room) => room.info);
154
159
  }
155
160
  }
@@ -16,7 +16,6 @@ export class ModValue {
16
16
  unregister(name) {
17
17
  this.list.delete(name);
18
18
  this.main.emit("value:remove", name);
19
- this.main.emit("value:change", name, undefined);
20
19
  }
21
20
  /** 获取值 */
22
21
  get(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.15.9",
3
+ "version": "0.15.11",
4
4
  "type": "commonjs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",