floating-live 0.16.0-alpha.1 → 0.16.0-alpha.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/FloatingLive.d.ts +18 -0
- package/dist/FloatingLive.js +36 -1
- package/dist/app.d.ts +14 -7
- package/dist/app.js +31 -8
- package/dist/live/messageInfo.d.ts +20 -17
- package/dist/live/messageInfo.js +16 -20
- package/dist/live/room.d.ts +23 -17
- package/dist/live/room.js +15 -17
- package/dist/plugin/context/CommonPluginContext.d.ts +10 -7
- package/dist/plugin/context/CommonPluginContext.js +36 -13
- package/dist/plugin/context/CorePluginContext.d.ts +8 -0
- package/dist/plugin/context/CorePluginContext.js +25 -0
- package/dist/plugin/context/SafePluginContext.d.ts +2 -2
- package/dist/plugin/manager.d.ts +4 -2
- package/dist/plugin/manager.js +75 -7
- package/dist/plugin/types.d.ts +34 -9
- package/dist/plugins/room/index.d.ts +20 -4
- package/dist/plugins/room/index.js +18 -3
- package/dist/utils/EventEmitter.d.ts +2 -2
- package/dist/utils/EventEmitter.js +4 -4
- package/dist/utils/types.d.ts +1 -0
- package/dist/utils/types.js +1 -0
- package/dist/value/manager.d.ts +2 -2
- package/dist/value/manager.js +5 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +0 -1
package/dist/FloatingLive.d.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
|
+
import { LiveRoom } from ".";
|
|
1
2
|
import { App } from "./app";
|
|
2
3
|
import { Room } from "./plugins/room";
|
|
3
4
|
export declare class FloatingLive extends App {
|
|
4
5
|
room: Room;
|
|
5
6
|
constructor();
|
|
7
|
+
/** 添加房间 */
|
|
8
|
+
add(platform: string, id: number, options?: boolean | Record<string, any>): Promise<void>;
|
|
9
|
+
/** 移除房间 */
|
|
10
|
+
remove(key: string): void;
|
|
11
|
+
/** 获取房间 */
|
|
12
|
+
get(key: string): LiveRoom | undefined;
|
|
13
|
+
has(key: string): boolean;
|
|
14
|
+
/** 获取房间信息 */
|
|
15
|
+
data(key: string): import("./live").LiveRoomData | undefined;
|
|
16
|
+
/** 更新房间信息 */
|
|
17
|
+
update(key: string): void;
|
|
18
|
+
/** 打开房间连接 */
|
|
19
|
+
open(key: string): void;
|
|
20
|
+
/** 关闭房间连接 */
|
|
21
|
+
close(key: string): void;
|
|
22
|
+
/** 获取房间列表 */
|
|
23
|
+
getList(): LiveRoom[];
|
|
6
24
|
}
|
package/dist/FloatingLive.js
CHANGED
|
@@ -3,6 +3,41 @@ import { Room } from "./plugins/room";
|
|
|
3
3
|
export class FloatingLive extends App {
|
|
4
4
|
constructor() {
|
|
5
5
|
super();
|
|
6
|
-
this.room =
|
|
6
|
+
this.room = this.registerSync(Room, { core: true });
|
|
7
|
+
}
|
|
8
|
+
/** 添加房间 */
|
|
9
|
+
add(platform, id, options) {
|
|
10
|
+
return this.room.add(platform, id, options);
|
|
11
|
+
}
|
|
12
|
+
/** 移除房间 */
|
|
13
|
+
remove(key) {
|
|
14
|
+
return this.room.remove(key);
|
|
15
|
+
}
|
|
16
|
+
/** 获取房间 */
|
|
17
|
+
get(key) {
|
|
18
|
+
return this.room.get(key);
|
|
19
|
+
}
|
|
20
|
+
has(key) {
|
|
21
|
+
return this.room.has(key);
|
|
22
|
+
}
|
|
23
|
+
/** 获取房间信息 */
|
|
24
|
+
data(key) {
|
|
25
|
+
return this.room.data(key);
|
|
26
|
+
}
|
|
27
|
+
/** 更新房间信息 */
|
|
28
|
+
update(key) {
|
|
29
|
+
return this.room.update(key);
|
|
30
|
+
}
|
|
31
|
+
/** 打开房间连接 */
|
|
32
|
+
open(key) {
|
|
33
|
+
return this.room.open(key);
|
|
34
|
+
}
|
|
35
|
+
/** 关闭房间连接 */
|
|
36
|
+
close(key) {
|
|
37
|
+
return this.room.close(key);
|
|
38
|
+
}
|
|
39
|
+
/** 获取房间列表 */
|
|
40
|
+
getList() {
|
|
41
|
+
return this.room.getList();
|
|
7
42
|
}
|
|
8
43
|
}
|
package/dist/app.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { CommandOptions, CommandCallOptions, AppCommandMap, CommandFunction } fr
|
|
|
2
2
|
import { AppError } from "./error";
|
|
3
3
|
import { AppEventDetailMap, AppEventEmitOptions, AppEventListener } from "./event";
|
|
4
4
|
import { AppHookMap, HookCallOptions, HookContext, HookFunction, HookUseOptions } from "./hook";
|
|
5
|
-
import { PluginContext,
|
|
5
|
+
import { AppPluginExposesMap, PluginConstructor, PluginContext, PluginInitOptions, PluginItem } from "./plugin";
|
|
6
6
|
import { CustomEventEmitter } from "./utils/EventEmitter";
|
|
7
7
|
import { AppValueMap, ValueOptions } from "./value";
|
|
8
8
|
export declare class App extends CustomEventEmitter implements PluginContext {
|
|
@@ -10,37 +10,44 @@ export declare class App extends CustomEventEmitter implements PluginContext {
|
|
|
10
10
|
private pluginManager;
|
|
11
11
|
private commandManager;
|
|
12
12
|
private valueManager;
|
|
13
|
+
private abortController;
|
|
13
14
|
constructor();
|
|
14
|
-
on<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]
|
|
15
|
-
once<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]
|
|
15
|
+
on<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]>, signal?: AbortSignal): void;
|
|
16
|
+
once<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]>, signal?: AbortSignal): void;
|
|
16
17
|
off<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]>): void;
|
|
17
18
|
emit<K extends keyof AppEventDetailMap>(type: K, detail: AppEventDetailMap[K], options?: AppEventEmitOptions & EventInit): void;
|
|
18
19
|
/** 发送错误 */
|
|
19
20
|
throw(err?: Error): void;
|
|
20
21
|
error(id: string, detail?: Record<string, any>): AppError;
|
|
21
22
|
/** 注册插件 */
|
|
22
|
-
register(plugin:
|
|
23
|
+
register<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions): Promise<P>;
|
|
24
|
+
/** 同步注册插件 */
|
|
25
|
+
registerSync<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions): P;
|
|
23
26
|
/** 取消注册插件 */
|
|
24
27
|
unregister(pluginName: string): void;
|
|
25
28
|
getPlugin(pluginName: string): void;
|
|
26
|
-
whenRegister(pluginName:
|
|
29
|
+
whenRegister<K extends keyof AppPluginExposesMap>(pluginName: K, callback: (exposes: AppPluginExposesMap[K]) => (() => void) | void): void;
|
|
30
|
+
whenRegister(pluginName: string, callback: () => (() => void) | void): void;
|
|
27
31
|
getPluginExposes(pluginName: string): any;
|
|
28
32
|
hasPlugin(pluginName: string): boolean;
|
|
29
33
|
registerCommand<T extends keyof AppCommandMap>(name: T, func: CommandFunction<AppCommandMap[T]>, options?: CommandOptions): void;
|
|
30
34
|
unregisterCommand(name: string): void;
|
|
35
|
+
hasCommand(name: string): boolean;
|
|
31
36
|
call<T extends keyof AppCommandMap>(name: T, ...args: Parameters<AppCommandMap[T]>): ReturnType<AppCommandMap[T]>;
|
|
32
37
|
callWithOptions<T extends keyof AppCommandMap>(name: T, options: CommandCallOptions, ...args: Parameters<AppCommandMap[T]>): ReturnType<AppCommandMap[T]>;
|
|
33
38
|
useHook<T extends keyof AppHookMap>(name: T, func: HookFunction<AppHookMap[T]>, options?: HookUseOptions): void;
|
|
34
39
|
unuseHook<T extends keyof AppHookMap>(name: T, func: HookFunction<AppHookMap[T]>): void;
|
|
35
40
|
callHook<T extends keyof AppHookMap>(name: T, ctx: AppHookMap[T], options?: HookCallOptions): Promise<HookContext<AppHookMap[T]>>;
|
|
36
41
|
callHookSync<T extends keyof AppHookMap>(name: T, ctx: AppHookMap[T], options?: HookCallOptions): HookContext<AppHookMap[T]>;
|
|
37
|
-
registerValue<K extends keyof AppValueMap>(name: K, options: ValueOptions<AppValueMap[K]>):
|
|
42
|
+
registerValue<K extends keyof AppValueMap>(name: K, options: ValueOptions<AppValueMap[K]>): import("./value").ValueContext<AppValueMap[K]>;
|
|
38
43
|
unregisterValue(name: string): void;
|
|
39
44
|
watch<K extends keyof AppValueMap>(name: K, watcher: (value: AppValueMap[K]) => void): void;
|
|
40
45
|
unwatch<K extends keyof AppValueMap>(name: K, watcher: (value: AppValueMap[K]) => void): void;
|
|
46
|
+
hasValue(name: string): boolean;
|
|
41
47
|
getValue<K extends keyof AppValueMap>(name: K): AppValueMap[K];
|
|
42
48
|
setValue(name: string, value: any): void;
|
|
43
49
|
destroy(): void;
|
|
44
50
|
/** 拓展值 */
|
|
45
|
-
define(): void;
|
|
51
|
+
define(key: string, value: ((...args: any[]) => any) | PropertyDescriptor): void;
|
|
52
|
+
get signal(): AbortSignal;
|
|
46
53
|
}
|
package/dist/app.js
CHANGED
|
@@ -7,16 +7,17 @@ import { ValueManager } from "./value/manager";
|
|
|
7
7
|
export class App extends CustomEventEmitter {
|
|
8
8
|
constructor() {
|
|
9
9
|
super();
|
|
10
|
+
this.abortController = new AbortController();
|
|
10
11
|
this.hookManager = new HookManager(this);
|
|
11
12
|
this.pluginManager = new PluginManager(this);
|
|
12
13
|
this.commandManager = new CommandManager(this);
|
|
13
14
|
this.valueManager = new ValueManager(this);
|
|
14
15
|
}
|
|
15
|
-
on(type, listener) {
|
|
16
|
-
super.on(type, listener);
|
|
16
|
+
on(type, listener, signal = this.signal) {
|
|
17
|
+
super.on(type, listener, signal);
|
|
17
18
|
}
|
|
18
|
-
once(type, listener) {
|
|
19
|
-
super.once(type, listener);
|
|
19
|
+
once(type, listener, signal = this.signal) {
|
|
20
|
+
super.once(type, listener, signal);
|
|
20
21
|
}
|
|
21
22
|
off(type, listener) {
|
|
22
23
|
super.off(type, listener);
|
|
@@ -36,7 +37,11 @@ export class App extends CustomEventEmitter {
|
|
|
36
37
|
//--- 插件机制 ---//
|
|
37
38
|
/** 注册插件 */
|
|
38
39
|
register(plugin, options) {
|
|
39
|
-
this.pluginManager.register(plugin, options);
|
|
40
|
+
return this.pluginManager.register(plugin, options);
|
|
41
|
+
}
|
|
42
|
+
/** 同步注册插件 */
|
|
43
|
+
registerSync(plugin, options) {
|
|
44
|
+
return this.pluginManager.registerSync(plugin, options);
|
|
40
45
|
}
|
|
41
46
|
/** 取消注册插件 */
|
|
42
47
|
unregister(pluginName) {
|
|
@@ -81,6 +86,9 @@ export class App extends CustomEventEmitter {
|
|
|
81
86
|
unregisterCommand(name) {
|
|
82
87
|
this.commandManager.unregister(name);
|
|
83
88
|
}
|
|
89
|
+
hasCommand(name) {
|
|
90
|
+
return this.commandManager.has(name);
|
|
91
|
+
}
|
|
84
92
|
call(name, ...args) {
|
|
85
93
|
return this.commandManager.call(name, ...args);
|
|
86
94
|
}
|
|
@@ -102,7 +110,7 @@ export class App extends CustomEventEmitter {
|
|
|
102
110
|
}
|
|
103
111
|
//--- 值机制 ---//
|
|
104
112
|
registerValue(name, options) {
|
|
105
|
-
this.valueManager.register(name, options);
|
|
113
|
+
return this.valueManager.register(name, options);
|
|
106
114
|
}
|
|
107
115
|
unregisterValue(name) {
|
|
108
116
|
this.valueManager.unregister(name);
|
|
@@ -113,14 +121,29 @@ export class App extends CustomEventEmitter {
|
|
|
113
121
|
unwatch(name, watcher) {
|
|
114
122
|
this.valueManager.unwatch(name, watcher);
|
|
115
123
|
}
|
|
124
|
+
hasValue(name) {
|
|
125
|
+
return this.valueManager.has(name);
|
|
126
|
+
}
|
|
116
127
|
getValue(name) {
|
|
117
128
|
return this.valueManager.get(name);
|
|
118
129
|
}
|
|
119
130
|
setValue(name, value) {
|
|
120
131
|
this.valueManager.set(name, value);
|
|
121
132
|
}
|
|
122
|
-
destroy() {
|
|
133
|
+
destroy() {
|
|
134
|
+
this.abortController.abort();
|
|
135
|
+
}
|
|
123
136
|
//--- 其他 ---//
|
|
124
137
|
/** 拓展值 */
|
|
125
|
-
define() {
|
|
138
|
+
define(key, value) {
|
|
139
|
+
if (typeof value == "function") {
|
|
140
|
+
Object.defineProperty(this, key, { value });
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
Object.defineProperty(this, key, value);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
get signal() {
|
|
147
|
+
return this.abortController.signal;
|
|
148
|
+
}
|
|
126
149
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EnumValue } from "../utils/types";
|
|
1
2
|
/** 用户信息 */
|
|
2
3
|
export interface UserInfo {
|
|
3
4
|
/** 用户名 */
|
|
@@ -66,28 +67,30 @@ export interface GiftInfo {
|
|
|
66
67
|
/** 单位 */
|
|
67
68
|
unit?: string;
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
-
export declare enum ImageSize {
|
|
70
|
+
export declare const ImageSize: {
|
|
71
71
|
/** 自定义大小 */
|
|
72
|
-
custom
|
|
72
|
+
readonly custom: 0;
|
|
73
73
|
/** 小表情(文字行高) */
|
|
74
|
-
small
|
|
74
|
+
readonly small: 1;
|
|
75
75
|
/** 大表情 */
|
|
76
|
-
large
|
|
77
|
-
}
|
|
76
|
+
readonly large: 2;
|
|
77
|
+
};
|
|
78
|
+
export type ImageSize = EnumValue<typeof ImageSize>;
|
|
78
79
|
/** 弹幕模式 */
|
|
79
|
-
export declare
|
|
80
|
-
left
|
|
81
|
-
bottom
|
|
82
|
-
top
|
|
83
|
-
right
|
|
84
|
-
}
|
|
80
|
+
export declare const DanmakuMode: {
|
|
81
|
+
readonly left: 1;
|
|
82
|
+
readonly bottom: 4;
|
|
83
|
+
readonly top: 5;
|
|
84
|
+
readonly right: 6;
|
|
85
|
+
};
|
|
86
|
+
export type DanmakuMode = EnumValue<typeof DanmakuMode>;
|
|
85
87
|
/** 用户类型 */
|
|
86
|
-
export declare
|
|
88
|
+
export declare const UserType: {
|
|
87
89
|
/** 普通观众 */
|
|
88
|
-
normal
|
|
90
|
+
readonly normal: 0;
|
|
89
91
|
/** 房管 */
|
|
90
|
-
admin
|
|
92
|
+
readonly admin: 1;
|
|
91
93
|
/** 主播 */
|
|
92
|
-
anchor
|
|
93
|
-
}
|
|
94
|
+
readonly anchor: 2;
|
|
95
|
+
};
|
|
96
|
+
export type UserType = EnumValue<typeof UserType>;
|
package/dist/live/messageInfo.js
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
export var ImageSize;
|
|
3
|
-
(function (ImageSize) {
|
|
1
|
+
export const ImageSize = {
|
|
4
2
|
/** 自定义大小 */
|
|
5
|
-
|
|
3
|
+
custom: 0,
|
|
6
4
|
/** 小表情(文字行高) */
|
|
7
|
-
|
|
5
|
+
small: 1,
|
|
8
6
|
/** 大表情 */
|
|
9
|
-
|
|
10
|
-
}
|
|
7
|
+
large: 2,
|
|
8
|
+
};
|
|
11
9
|
/** 弹幕模式 */
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})(DanmakuMode || (DanmakuMode = {}));
|
|
10
|
+
export const DanmakuMode = {
|
|
11
|
+
left: 1,
|
|
12
|
+
bottom: 4,
|
|
13
|
+
top: 5,
|
|
14
|
+
right: 6,
|
|
15
|
+
};
|
|
19
16
|
/** 用户类型 */
|
|
20
|
-
export
|
|
21
|
-
(function (UserType) {
|
|
17
|
+
export const UserType = {
|
|
22
18
|
/** 普通观众 */
|
|
23
|
-
|
|
19
|
+
normal: 0,
|
|
24
20
|
/** 房管 */
|
|
25
|
-
|
|
21
|
+
admin: 1,
|
|
26
22
|
/** 主播 */
|
|
27
|
-
|
|
28
|
-
}
|
|
23
|
+
anchor: 2,
|
|
24
|
+
};
|
package/dist/live/room.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CustomEventEmitter } from "../utils/EventEmitter";
|
|
2
|
+
import { EnumValue } from "../utils/types";
|
|
2
3
|
import { LiveMessage } from "./message";
|
|
3
4
|
import { UserInfo } from "./messageInfo";
|
|
4
5
|
export declare abstract class LiveRoom extends CustomEventEmitter implements LiveRoomData {
|
|
@@ -21,7 +22,7 @@ export declare abstract class LiveRoom extends CustomEventEmitter implements Liv
|
|
|
21
22
|
liveId?: string;
|
|
22
23
|
/** 房间是否打开 */
|
|
23
24
|
opened: boolean;
|
|
24
|
-
/**
|
|
25
|
+
/** 房间连接状态 */
|
|
25
26
|
connection: LiveConnectionStatus;
|
|
26
27
|
/** 房间是否可用 */
|
|
27
28
|
abstract available: boolean;
|
|
@@ -95,43 +96,47 @@ export interface LiveRoomStatsInfo {
|
|
|
95
96
|
popularity?: number;
|
|
96
97
|
}
|
|
97
98
|
/** 直播间状态 */
|
|
98
|
-
export declare
|
|
99
|
+
export declare const LiveRoomStatus: {
|
|
99
100
|
/** 未开播 */
|
|
100
|
-
off
|
|
101
|
+
readonly off: 0;
|
|
101
102
|
/** 正在直播 */
|
|
102
|
-
live
|
|
103
|
+
readonly live: 1;
|
|
103
104
|
/** 正在轮播 */
|
|
104
|
-
round
|
|
105
|
+
readonly round: 2;
|
|
105
106
|
/** 被封禁 */
|
|
106
|
-
banned
|
|
107
|
+
readonly banned: -1;
|
|
107
108
|
/** 已上锁 */
|
|
108
|
-
locked
|
|
109
|
-
}
|
|
109
|
+
readonly locked: -2;
|
|
110
|
+
};
|
|
111
|
+
export type LiveRoomStatus = EnumValue<typeof LiveRoomStatus>;
|
|
110
112
|
/** 直播间状态 */
|
|
111
|
-
export declare
|
|
113
|
+
export declare const LiveConnectionStatus: {
|
|
112
114
|
/** 未连接 */
|
|
113
|
-
off
|
|
115
|
+
off: number;
|
|
114
116
|
/** 连接中 */
|
|
115
|
-
connecting
|
|
117
|
+
connecting: number;
|
|
116
118
|
/** 连接到服务器 */
|
|
117
|
-
connected
|
|
119
|
+
connected: number;
|
|
118
120
|
/** 连接到房间 */
|
|
119
|
-
entered
|
|
121
|
+
entered: number;
|
|
120
122
|
/** 连接失败或断开 */
|
|
121
|
-
disconnected
|
|
122
|
-
}
|
|
123
|
+
disconnected: number;
|
|
124
|
+
};
|
|
125
|
+
export type LiveConnectionStatus = EnumValue<typeof LiveConnectionStatus>;
|
|
123
126
|
export interface LiveRoomEventMap {
|
|
124
127
|
status: {
|
|
125
128
|
status: LiveRoomStatus;
|
|
126
129
|
timestamp: number;
|
|
127
130
|
liveId?: string | number;
|
|
128
131
|
};
|
|
129
|
-
update: {
|
|
132
|
+
update: {
|
|
133
|
+
room: LiveRoomData;
|
|
134
|
+
};
|
|
130
135
|
detail: {
|
|
131
136
|
detail: Partial<LiveRoomDetailInfo>;
|
|
132
137
|
};
|
|
133
138
|
stats: {
|
|
134
|
-
stats: LiveRoomStatsInfo
|
|
139
|
+
stats: Partial<LiveRoomStatsInfo>;
|
|
135
140
|
};
|
|
136
141
|
message: {
|
|
137
142
|
message: LiveMessage.All;
|
|
@@ -141,6 +146,7 @@ export interface LiveRoomEventMap {
|
|
|
141
146
|
roomId: string | number;
|
|
142
147
|
data: any;
|
|
143
148
|
};
|
|
149
|
+
init: {};
|
|
144
150
|
connecting: {};
|
|
145
151
|
connected: {};
|
|
146
152
|
disconnect: {};
|
package/dist/live/room.js
CHANGED
|
@@ -8,7 +8,7 @@ export class LiveRoom extends CustomEventEmitter {
|
|
|
8
8
|
this.timestamp = 0;
|
|
9
9
|
/** 房间是否打开 */
|
|
10
10
|
this.opened = false;
|
|
11
|
-
/**
|
|
11
|
+
/** 房间连接状态 */
|
|
12
12
|
this.connection = LiveConnectionStatus.off;
|
|
13
13
|
}
|
|
14
14
|
/** 销毁 */
|
|
@@ -91,30 +91,28 @@ export class LiveRoom extends CustomEventEmitter {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
/** 直播间状态 */
|
|
94
|
-
export
|
|
95
|
-
(function (LiveRoomStatus) {
|
|
94
|
+
export const LiveRoomStatus = {
|
|
96
95
|
/** 未开播 */
|
|
97
|
-
|
|
96
|
+
off: 0,
|
|
98
97
|
/** 正在直播 */
|
|
99
|
-
|
|
98
|
+
live: 1,
|
|
100
99
|
/** 正在轮播 */
|
|
101
|
-
|
|
100
|
+
round: 2,
|
|
102
101
|
/** 被封禁 */
|
|
103
|
-
|
|
102
|
+
banned: -1,
|
|
104
103
|
/** 已上锁 */
|
|
105
|
-
|
|
106
|
-
}
|
|
104
|
+
locked: -2,
|
|
105
|
+
};
|
|
107
106
|
/** 直播间状态 */
|
|
108
|
-
export
|
|
109
|
-
(function (LiveConnectionStatus) {
|
|
107
|
+
export const LiveConnectionStatus = {
|
|
110
108
|
/** 未连接 */
|
|
111
|
-
|
|
109
|
+
off: 0,
|
|
112
110
|
/** 连接中 */
|
|
113
|
-
|
|
111
|
+
connecting: 1,
|
|
114
112
|
/** 连接到服务器 */
|
|
115
|
-
|
|
113
|
+
connected: 2,
|
|
116
114
|
/** 连接到房间 */
|
|
117
|
-
|
|
115
|
+
entered: 3,
|
|
118
116
|
/** 连接失败或断开 */
|
|
119
|
-
|
|
120
|
-
}
|
|
117
|
+
disconnected: -1,
|
|
118
|
+
};
|
|
@@ -3,8 +3,8 @@ import type { CommandOptions, CommandCallOptions, CommandFunction, AppCommandMap
|
|
|
3
3
|
import { AppError, ErrorOptions } from "../../error";
|
|
4
4
|
import { AppEventListener, AppEventEmitOptions, AppEventDetailMap } from "../../event";
|
|
5
5
|
import { HookUseOptions, HookCallOptions, AppHookMap, HookFunction, HookContext } from "../../hook";
|
|
6
|
-
import { AppValueMap, ValueOptions } from "../../value";
|
|
7
|
-
import type { PluginContext, PluginConstructor,
|
|
6
|
+
import { AppValueMap, ValueContext, ValueOptions } from "../../value";
|
|
7
|
+
import type { PluginContext, PluginConstructor, PluginInitOptions, AppPluginExposesMap, PluginItem } from "../types";
|
|
8
8
|
export declare class CommonPluginContext implements PluginContext {
|
|
9
9
|
#private;
|
|
10
10
|
get safe(): boolean;
|
|
@@ -18,15 +18,16 @@ export declare class CommonPluginContext implements PluginContext {
|
|
|
18
18
|
*/
|
|
19
19
|
throw(err: AppError): void;
|
|
20
20
|
error(id: string, options: ErrorOptions): AppError;
|
|
21
|
-
register(plugin: PluginConstructor
|
|
21
|
+
register<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions): Promise<P>;
|
|
22
22
|
unregister(pluginName: string): void;
|
|
23
|
-
getPluginExposes<
|
|
24
|
-
whenRegister
|
|
23
|
+
getPluginExposes<K extends keyof AppPluginExposesMap>(pluginName: K): AppPluginExposesMap[K];
|
|
24
|
+
whenRegister(pluginName: string, callback: (exposes: any) => (() => void) | void): void;
|
|
25
25
|
hasPlugin(pluginName: string): boolean;
|
|
26
|
-
registerValue<K extends keyof AppValueMap>(name: K, options: ValueOptions<AppValueMap[K]>):
|
|
26
|
+
registerValue<K extends keyof AppValueMap>(name: K, options: ValueOptions<AppValueMap[K]>): ValueContext<AppValueMap[K]>;
|
|
27
27
|
unregisterValue(name: string): void;
|
|
28
28
|
registerCommand<T extends keyof AppCommandMap>(name: T, func: CommandFunction<AppCommandMap[T]>, options?: CommandOptions): void;
|
|
29
29
|
unregisterCommand(name: string): void;
|
|
30
|
+
hasCommand(name: string): boolean;
|
|
30
31
|
on<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]>): void;
|
|
31
32
|
once<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]>): void;
|
|
32
33
|
off<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]>): void;
|
|
@@ -39,7 +40,9 @@ export declare class CommonPluginContext implements PluginContext {
|
|
|
39
40
|
callHookSync<T extends keyof AppHookMap>(name: T, ctx: AppHookMap[T], options?: HookCallOptions): HookContext<AppHookMap[T]>;
|
|
40
41
|
watch<K extends keyof AppValueMap>(name: K, watcher: (value: AppValueMap[K]) => void): void;
|
|
41
42
|
unwatch<K extends keyof AppValueMap>(name: K, watcher: (value: AppValueMap[K]) => void): void;
|
|
42
|
-
|
|
43
|
+
hasValue<K extends keyof AppValueMap>(name: K): boolean;
|
|
44
|
+
getValue<K extends keyof AppValueMap>(name: K): AppValueMap[K];
|
|
43
45
|
setValue<K extends keyof AppValueMap>(name: K, value: AppValueMap[K]): void;
|
|
44
46
|
destroy(): void;
|
|
47
|
+
get signal(): AbortSignal;
|
|
45
48
|
}
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _CommonPluginContext_app, _CommonPluginContext_registered;
|
|
12
|
+
var _CommonPluginContext_app, _CommonPluginContext_abortController, _CommonPluginContext_registered;
|
|
13
13
|
import { AppError } from "../../error";
|
|
14
14
|
class ListMap extends Map {
|
|
15
15
|
addItem(key, value) {
|
|
@@ -35,6 +35,8 @@ export class CommonPluginContext {
|
|
|
35
35
|
constructor(app, pluginName) {
|
|
36
36
|
/** 主程序,插件不可访问 */
|
|
37
37
|
_CommonPluginContext_app.set(this, void 0);
|
|
38
|
+
/** AbortController,插件不可访问 */
|
|
39
|
+
_CommonPluginContext_abortController.set(this, new AbortController());
|
|
38
40
|
_CommonPluginContext_registered.set(this, {
|
|
39
41
|
plugins: new Set(),
|
|
40
42
|
values: new Set(),
|
|
@@ -58,11 +60,12 @@ export class CommonPluginContext {
|
|
|
58
60
|
}
|
|
59
61
|
register(plugin, options) {
|
|
60
62
|
try {
|
|
61
|
-
__classPrivateFieldGet(this, _CommonPluginContext_app, "f").register(plugin, options);
|
|
63
|
+
const p = __classPrivateFieldGet(this, _CommonPluginContext_app, "f").register(plugin, options);
|
|
62
64
|
__classPrivateFieldGet(this, _CommonPluginContext_registered, "f").plugins.add(plugin.name);
|
|
65
|
+
return p;
|
|
63
66
|
}
|
|
64
67
|
catch (err) {
|
|
65
|
-
this.throw(err);
|
|
68
|
+
throw this.throw(err);
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
unregister(pluginName) {
|
|
@@ -105,11 +108,12 @@ export class CommonPluginContext {
|
|
|
105
108
|
}
|
|
106
109
|
registerValue(name, options) {
|
|
107
110
|
try {
|
|
108
|
-
__classPrivateFieldGet(this, _CommonPluginContext_app, "f").registerValue(name, options);
|
|
111
|
+
const ctx = __classPrivateFieldGet(this, _CommonPluginContext_app, "f").registerValue(name, options);
|
|
109
112
|
__classPrivateFieldGet(this, _CommonPluginContext_registered, "f").values.add(name);
|
|
113
|
+
return ctx;
|
|
110
114
|
}
|
|
111
115
|
catch (err) {
|
|
112
|
-
this.throw(err);
|
|
116
|
+
throw this.throw(err);
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
unregisterValue(name) {
|
|
@@ -139,6 +143,14 @@ export class CommonPluginContext {
|
|
|
139
143
|
this.throw(err);
|
|
140
144
|
}
|
|
141
145
|
}
|
|
146
|
+
hasCommand(name) {
|
|
147
|
+
try {
|
|
148
|
+
return __classPrivateFieldGet(this, _CommonPluginContext_app, "f").hasCommand(name);
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
throw this.throw(err);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
142
154
|
on(type, listener) {
|
|
143
155
|
try {
|
|
144
156
|
__classPrivateFieldGet(this, _CommonPluginContext_app, "f").on(type, listener);
|
|
@@ -234,7 +246,7 @@ export class CommonPluginContext {
|
|
|
234
246
|
__classPrivateFieldGet(this, _CommonPluginContext_app, "f").watch(name, watcher);
|
|
235
247
|
}
|
|
236
248
|
catch (err) {
|
|
237
|
-
this.throw(err);
|
|
249
|
+
throw this.throw(err);
|
|
238
250
|
}
|
|
239
251
|
}
|
|
240
252
|
unwatch(name, watcher) {
|
|
@@ -242,7 +254,15 @@ export class CommonPluginContext {
|
|
|
242
254
|
__classPrivateFieldGet(this, _CommonPluginContext_app, "f").unwatch(name, watcher);
|
|
243
255
|
}
|
|
244
256
|
catch (err) {
|
|
245
|
-
this.throw(err);
|
|
257
|
+
throw this.throw(err);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
hasValue(name) {
|
|
261
|
+
try {
|
|
262
|
+
return __classPrivateFieldGet(this, _CommonPluginContext_app, "f").hasValue(name);
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
throw this.throw(err);
|
|
246
266
|
}
|
|
247
267
|
}
|
|
248
268
|
getValue(name) {
|
|
@@ -250,24 +270,27 @@ export class CommonPluginContext {
|
|
|
250
270
|
return __classPrivateFieldGet(this, _CommonPluginContext_app, "f").getValue(name);
|
|
251
271
|
}
|
|
252
272
|
catch (err) {
|
|
253
|
-
this.throw(err);
|
|
273
|
+
throw this.throw(err);
|
|
254
274
|
}
|
|
255
275
|
}
|
|
256
276
|
setValue(name, value) {
|
|
257
277
|
try {
|
|
258
|
-
__classPrivateFieldGet(this, _CommonPluginContext_app, "f").setValue(name, value);
|
|
278
|
+
return __classPrivateFieldGet(this, _CommonPluginContext_app, "f").setValue(name, value);
|
|
259
279
|
}
|
|
260
280
|
catch (err) {
|
|
261
|
-
this.throw(err);
|
|
281
|
+
throw this.throw(err);
|
|
262
282
|
}
|
|
263
283
|
}
|
|
264
284
|
destroy() {
|
|
265
|
-
const { plugins,
|
|
285
|
+
const { plugins, values, hooks, commands } = __classPrivateFieldGet(this, _CommonPluginContext_registered, "f");
|
|
266
286
|
plugins.forEach((pluginName) => __classPrivateFieldGet(this, _CommonPluginContext_app, "f").unregister(pluginName));
|
|
267
|
-
events.forEach((listenerList, eventName) => listenerList.forEach((listener) => __classPrivateFieldGet(this, _CommonPluginContext_app, "f").off(eventName, listener)));
|
|
268
287
|
hooks.forEach((hookList, name) => hookList.forEach((hookFunc) => __classPrivateFieldGet(this, _CommonPluginContext_app, "f").off(name, hookFunc)));
|
|
269
288
|
commands.forEach((name) => __classPrivateFieldGet(this, _CommonPluginContext_app, "f").unregisterCommand(name));
|
|
270
289
|
values.forEach((name) => __classPrivateFieldGet(this, _CommonPluginContext_app, "f").unregisterValue(name));
|
|
290
|
+
__classPrivateFieldGet(this, _CommonPluginContext_abortController, "f").abort();
|
|
291
|
+
}
|
|
292
|
+
get signal() {
|
|
293
|
+
return __classPrivateFieldGet(this, _CommonPluginContext_abortController, "f").signal;
|
|
271
294
|
}
|
|
272
295
|
}
|
|
273
|
-
_CommonPluginContext_app = new WeakMap(), _CommonPluginContext_registered = new WeakMap();
|
|
296
|
+
_CommonPluginContext_app = new WeakMap(), _CommonPluginContext_abortController = new WeakMap(), _CommonPluginContext_registered = new WeakMap();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { App } from "../..";
|
|
2
|
+
import { CommonPluginContext } from "./CommonPluginContext";
|
|
3
|
+
/** 核心插件,具有对程序的访问权限 */
|
|
4
|
+
export declare class CorePluginContext extends CommonPluginContext {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(app: App, pluginName: string);
|
|
7
|
+
get app(): App;
|
|
8
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _CorePluginContext_app;
|
|
13
|
+
import { CommonPluginContext } from "./CommonPluginContext";
|
|
14
|
+
/** 核心插件,具有对程序的访问权限 */
|
|
15
|
+
export class CorePluginContext extends CommonPluginContext {
|
|
16
|
+
constructor(app, pluginName) {
|
|
17
|
+
super(app, pluginName);
|
|
18
|
+
_CorePluginContext_app.set(this, void 0);
|
|
19
|
+
__classPrivateFieldSet(this, _CorePluginContext_app, app, "f");
|
|
20
|
+
}
|
|
21
|
+
get app() {
|
|
22
|
+
return __classPrivateFieldGet(this, _CorePluginContext_app, "f");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
_CorePluginContext_app = new WeakMap();
|
|
@@ -2,7 +2,7 @@ import { App } from "../../app";
|
|
|
2
2
|
import { AppCommandMap, CommandCallOptions, CommandFunction, CommandOptions } from "../../command";
|
|
3
3
|
import { AppEventDetailMap, AppEventEmitOptions } from "../../event";
|
|
4
4
|
import { AppHookMap, HookCallOptions, HookContext, HookFunction, HookUseOptions } from "../../hook";
|
|
5
|
-
import { PluginConstructor,
|
|
5
|
+
import { PluginConstructor, PluginItem, PluginInitOptions } from "../types";
|
|
6
6
|
import { CommonPluginContext } from "./CommonPluginContext";
|
|
7
7
|
export interface PluginPermissions {
|
|
8
8
|
"plugin.register"?: boolean;
|
|
@@ -22,7 +22,7 @@ export declare class SafePluginContext extends CommonPluginContext {
|
|
|
22
22
|
permissions: PluginPermissions;
|
|
23
23
|
});
|
|
24
24
|
private throwNotPermitted;
|
|
25
|
-
register(plugin: PluginConstructor
|
|
25
|
+
register<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions): Promise<P>;
|
|
26
26
|
unregister(pluginName: string): void;
|
|
27
27
|
emit<K extends keyof AppEventDetailMap>(type: K, detail: AppEventDetailMap[K], options?: AppEventEmitOptions & EventInit): void;
|
|
28
28
|
call<T extends keyof AppCommandMap>(name: T, ...args: Parameters<AppCommandMap[T]>): ReturnType<AppCommandMap[T]>;
|
package/dist/plugin/manager.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { App } from "../app";
|
|
2
2
|
import { AppError, ErrorOptions } from "../error";
|
|
3
|
-
import { PluginItem, PluginConstructor, PluginContext } from "./types";
|
|
3
|
+
import { PluginItem, PluginConstructor, PluginContext, PluginRegisterOptions } from "./types";
|
|
4
4
|
export interface PluginErrorOptions extends ErrorOptions {
|
|
5
5
|
pluginName: string;
|
|
6
6
|
}
|
|
@@ -12,14 +12,16 @@ export interface PluginData<T> {
|
|
|
12
12
|
plugin: PluginItem;
|
|
13
13
|
context: PluginContext;
|
|
14
14
|
exposes?: T;
|
|
15
|
+
core?: boolean;
|
|
15
16
|
}
|
|
16
17
|
export declare class PluginManager {
|
|
17
18
|
/** 插件列表 */
|
|
18
19
|
private list;
|
|
19
20
|
protected readonly app: App;
|
|
20
21
|
constructor(app: App);
|
|
22
|
+
registerSync<P extends PluginItem>(pluginConstructor: PluginConstructor<P>, options?: Record<string, any>, { context, core }?: PluginRegisterOptions): P;
|
|
21
23
|
/** 注册插件 */
|
|
22
|
-
register(pluginConstructor: PluginConstructor
|
|
24
|
+
register<P extends PluginItem>(pluginConstructor: PluginConstructor<P>, options?: Record<string, any>, { context, core }?: PluginRegisterOptions): Promise<P>;
|
|
23
25
|
/** 移除插件 */
|
|
24
26
|
unregister(pluginName: string): Promise<void>;
|
|
25
27
|
/** 获取插件实例 */
|
package/dist/plugin/manager.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CommonPluginContext } from "./context/CommonPluginContext";
|
|
2
2
|
import { AppError } from "../error";
|
|
3
|
+
import { CorePluginContext } from "./context/CorePluginContext";
|
|
3
4
|
export class PluginError extends AppError {
|
|
4
5
|
constructor(id, options) {
|
|
5
6
|
super(id, options);
|
|
@@ -12,8 +13,57 @@ export class PluginManager {
|
|
|
12
13
|
this.list = new Map();
|
|
13
14
|
this.app = app;
|
|
14
15
|
}
|
|
16
|
+
registerSync(pluginConstructor, options = {}, { context, core } = {}) {
|
|
17
|
+
const pluginName = pluginConstructor.pluginName;
|
|
18
|
+
if (!pluginName) {
|
|
19
|
+
throw new PluginError("plugin:register_id_missing", {
|
|
20
|
+
message: "插件注册失败",
|
|
21
|
+
cause: "插件缺少pluginName字段",
|
|
22
|
+
pluginName: "",
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (this.list.has(pluginName)) {
|
|
26
|
+
throw new PluginError("plugin:register_id_duplicate", {
|
|
27
|
+
message: `插件注册失败: ${pluginName}`,
|
|
28
|
+
cause: "已存在相同id的插件",
|
|
29
|
+
pluginName,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const registerCtx = { pluginName, options };
|
|
33
|
+
const pluginCtx = context || new CorePluginContext(this.app, pluginName);
|
|
34
|
+
try {
|
|
35
|
+
const ctx = this.app.callHookSync("plugin.register", registerCtx);
|
|
36
|
+
if (ctx.defaultPrevented)
|
|
37
|
+
throw new PluginError("plugin:register_hook_prevented", {
|
|
38
|
+
message: `插件注册失败: ${pluginName}`,
|
|
39
|
+
cause: "插件注册被钩子函数阻止",
|
|
40
|
+
pluginName,
|
|
41
|
+
});
|
|
42
|
+
// 执行插件函数
|
|
43
|
+
const plugin = new pluginConstructor(pluginCtx, registerCtx.options || {});
|
|
44
|
+
// 调用插件的init钩子
|
|
45
|
+
plugin.init?.(pluginCtx, registerCtx.options || {});
|
|
46
|
+
// 调用插件的expose钩子
|
|
47
|
+
const exposes = plugin.expose?.(pluginCtx);
|
|
48
|
+
this.list.set(pluginName, {
|
|
49
|
+
plugin,
|
|
50
|
+
context: pluginCtx,
|
|
51
|
+
exposes,
|
|
52
|
+
core,
|
|
53
|
+
});
|
|
54
|
+
this.app.emit("plugin:register", { pluginName });
|
|
55
|
+
return plugin;
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
throw new PluginError("plugin:register_fail", {
|
|
59
|
+
message: `插件注册失败: ${pluginName}`,
|
|
60
|
+
cause: err,
|
|
61
|
+
pluginName,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
15
65
|
/** 注册插件 */
|
|
16
|
-
async register(pluginConstructor, options = {}) {
|
|
66
|
+
async register(pluginConstructor, options = {}, { context, core } = {}) {
|
|
17
67
|
const pluginName = pluginConstructor.pluginName;
|
|
18
68
|
if (!pluginName) {
|
|
19
69
|
throw new PluginError("plugin:register_id_missing", {
|
|
@@ -30,17 +80,28 @@ export class PluginManager {
|
|
|
30
80
|
});
|
|
31
81
|
}
|
|
32
82
|
const registerCtx = { pluginName, options };
|
|
33
|
-
const pluginCtx = new CommonPluginContext(this.app, pluginName);
|
|
83
|
+
const pluginCtx = context || new CommonPluginContext(this.app, pluginName);
|
|
34
84
|
return await this.app
|
|
35
85
|
.callHook("plugin.register", registerCtx)
|
|
36
86
|
.then(async (ctx) => {
|
|
37
87
|
if (ctx.defaultPrevented)
|
|
38
|
-
|
|
88
|
+
throw new PluginError("plugin:register_hook_prevented", {
|
|
89
|
+
message: `插件注册失败: ${pluginName}`,
|
|
90
|
+
cause: "插件注册被钩子函数阻止",
|
|
91
|
+
pluginName,
|
|
92
|
+
});
|
|
39
93
|
// 执行插件函数
|
|
40
94
|
const plugin = new pluginConstructor(pluginCtx, registerCtx.options || {});
|
|
41
|
-
// 调用插件的
|
|
42
|
-
await plugin.
|
|
43
|
-
|
|
95
|
+
// 调用插件的init钩子
|
|
96
|
+
await plugin.init?.(pluginCtx, registerCtx.options || {});
|
|
97
|
+
// 调用插件的expose钩子
|
|
98
|
+
const exposes = await plugin.expose?.(pluginCtx);
|
|
99
|
+
this.list.set(pluginName, {
|
|
100
|
+
plugin,
|
|
101
|
+
context: pluginCtx,
|
|
102
|
+
exposes,
|
|
103
|
+
core,
|
|
104
|
+
});
|
|
44
105
|
this.app.emit("plugin:register", { pluginName });
|
|
45
106
|
return plugin;
|
|
46
107
|
})
|
|
@@ -64,7 +125,14 @@ export class PluginManager {
|
|
|
64
125
|
});
|
|
65
126
|
}
|
|
66
127
|
else {
|
|
67
|
-
const { plugin, context } = pluginData;
|
|
128
|
+
const { plugin, context, core } = pluginData;
|
|
129
|
+
if (core) {
|
|
130
|
+
throw new PluginError("plugin:unregister_core", {
|
|
131
|
+
message: `插件移除失败: ${pluginName}`,
|
|
132
|
+
cause: "无法移除核心插件",
|
|
133
|
+
pluginName,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
68
136
|
// 调用插件和上下文的destroy钩子
|
|
69
137
|
plugin.destroy?.(context);
|
|
70
138
|
context.destroy();
|
package/dist/plugin/types.d.ts
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
|
+
import { App } from "../app";
|
|
1
2
|
import { CommandOptions, CommandCallOptions, AppCommandMap, CommandFunction } from "../command";
|
|
2
3
|
import { AppError, ErrorOptions } from "../error";
|
|
3
4
|
import { AppEventListener, AppEventEmitOptions, AppEventDetailMap } from "../event";
|
|
4
5
|
import { AppHookMap, HookCallOptions, HookContext, HookFunction, HookUseOptions } from "../hook";
|
|
5
|
-
import { AppValueMap, ValueOptions } from "../value";
|
|
6
|
+
import { AppValueMap, ValueContext, ValueOptions } from "../value";
|
|
6
7
|
/** 插件对象 */
|
|
7
8
|
export interface PluginItem {
|
|
8
9
|
pluginName: string;
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
/** 初始化插件 */
|
|
11
|
+
init?(ctx: PluginContext, options?: Record<string, any>): void | Promise<void>;
|
|
12
|
+
/** 插件销毁 */
|
|
13
|
+
destroy?(ctx: PluginContext): void | Promise<void>;
|
|
14
|
+
/** 插件暴露 */
|
|
15
|
+
expose?(ctx: PluginContext): any;
|
|
11
16
|
}
|
|
12
17
|
/** 插件构造器 */
|
|
13
|
-
export interface PluginConstructor {
|
|
18
|
+
export interface PluginConstructor<P extends PluginItem> {
|
|
14
19
|
pluginName: string;
|
|
15
|
-
new (ctx: PluginContext, options: any):
|
|
20
|
+
new (ctx: PluginContext, options: any): P;
|
|
21
|
+
}
|
|
22
|
+
/** 插件初始化选项 */
|
|
23
|
+
export interface PluginInitOptions {
|
|
16
24
|
}
|
|
17
25
|
/** 插件注册选项 */
|
|
18
26
|
export interface PluginRegisterOptions {
|
|
27
|
+
/** 提供的插件上下文 */
|
|
28
|
+
context?: PluginContext;
|
|
29
|
+
/** 核心插件,不可解除注册 */
|
|
30
|
+
core?: boolean;
|
|
19
31
|
}
|
|
20
32
|
/** 插件上下文 */
|
|
21
33
|
export interface PluginContext {
|
|
34
|
+
/** 安全插件上下文 */
|
|
35
|
+
safe?: boolean;
|
|
36
|
+
/** App实例,仅在核心插件上下文提供 */
|
|
37
|
+
app?: App;
|
|
22
38
|
/** 监听事件 */
|
|
23
39
|
on<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]>): void;
|
|
24
40
|
/** 单次监听事件 */
|
|
@@ -32,19 +48,22 @@ export interface PluginContext {
|
|
|
32
48
|
/** 生成错误 */
|
|
33
49
|
error(id: string, options: ErrorOptions): AppError;
|
|
34
50
|
/** 注册插件 */
|
|
35
|
-
register(plugin: PluginConstructor
|
|
51
|
+
register<P extends PluginItem>(plugin: PluginConstructor<P>, options?: PluginInitOptions): Promise<P>;
|
|
36
52
|
/** 取消注册插件 */
|
|
37
53
|
unregister(pluginName: string): void;
|
|
38
54
|
/** 获取插件暴露对象 */
|
|
39
|
-
getPluginExposes<
|
|
55
|
+
getPluginExposes<K extends keyof AppPluginExposesMap>(pluginName: K): AppPluginExposesMap[K];
|
|
40
56
|
/** 等待plugin注册 */
|
|
41
|
-
whenRegister(pluginName:
|
|
57
|
+
whenRegister<K extends keyof AppPluginExposesMap>(pluginName: K, callback: (exposes: AppPluginExposesMap[K]) => (() => void) | void): void;
|
|
58
|
+
whenRegister(pluginName: string, callback: () => (() => void) | void): void;
|
|
42
59
|
/** 是否存在插件 */
|
|
43
60
|
hasPlugin(pluginName: string): boolean;
|
|
44
61
|
/** 注册指令 */
|
|
45
62
|
registerCommand<T extends keyof AppCommandMap>(name: T, func: CommandFunction<AppCommandMap[T]>, options?: CommandOptions): void;
|
|
46
63
|
/** 取消注册指令 */
|
|
47
64
|
unregisterCommand(name: string): void;
|
|
65
|
+
/** 检测值是否存在 */
|
|
66
|
+
hasCommand(name: string): boolean;
|
|
48
67
|
/** 调用指令 */
|
|
49
68
|
call<T extends keyof AppCommandMap>(name: T, ...args: Parameters<AppCommandMap[T]>): ReturnType<AppCommandMap[T]>;
|
|
50
69
|
/** 调用指令(可配置) */
|
|
@@ -58,16 +77,22 @@ export interface PluginContext {
|
|
|
58
77
|
/** 调用同步钩子 */
|
|
59
78
|
callHookSync<T extends keyof AppHookMap>(name: T, ctx: AppHookMap[T], options?: HookCallOptions): HookContext<AppHookMap[T]>;
|
|
60
79
|
/** 注册值 */
|
|
61
|
-
registerValue<K extends keyof AppValueMap>(name: K, options: ValueOptions<AppValueMap[K]>):
|
|
80
|
+
registerValue<K extends keyof AppValueMap>(name: K, options: ValueOptions<AppValueMap[K]>): ValueContext<AppValueMap[K]>;
|
|
62
81
|
/** 取消注册值 */
|
|
63
82
|
unregisterValue(name: string): void;
|
|
64
83
|
/** 监听值 */
|
|
65
84
|
watch<K extends keyof AppValueMap>(name: K, watcher: (value: AppValueMap[K]) => void): void;
|
|
66
85
|
/** 取消监听值 */
|
|
67
86
|
unwatch<K extends keyof AppValueMap>(name: K, watcher: (value: AppValueMap[K]) => void): void;
|
|
87
|
+
/** 值是否存在 */
|
|
88
|
+
hasValue(name: string): boolean;
|
|
68
89
|
/** 获取值 */
|
|
69
90
|
getValue<K extends keyof AppValueMap>(name: K): AppValueMap[K];
|
|
70
91
|
/** 设置值 */
|
|
71
92
|
setValue<K extends keyof AppValueMap>(name: K, value: AppValueMap[K]): void;
|
|
72
93
|
destroy(): void;
|
|
94
|
+
get signal(): AbortSignal;
|
|
95
|
+
}
|
|
96
|
+
export interface AppPluginExposesMap {
|
|
97
|
+
"": {};
|
|
73
98
|
}
|
|
@@ -2,6 +2,17 @@ import { LiveMessage } from "../../live/message";
|
|
|
2
2
|
import { LiveRoom, LiveRoomDetailInfo, LiveRoomData, LiveRoomStatsInfo, LiveRoomStatus } from "../../live/room";
|
|
3
3
|
import { BasePlugin } from "../../plugin";
|
|
4
4
|
import { PluginContext } from "../../plugin/types";
|
|
5
|
+
interface PluginExposes {
|
|
6
|
+
add(platform: string, id: number, options?: boolean | Record<string, any>): void;
|
|
7
|
+
remove(key: string): void;
|
|
8
|
+
get(key: string): LiveRoom | undefined;
|
|
9
|
+
has(key: string): boolean;
|
|
10
|
+
data(key: string): LiveRoomData | undefined;
|
|
11
|
+
update(key: string): void;
|
|
12
|
+
open(key: string): void;
|
|
13
|
+
close(key: string): void;
|
|
14
|
+
getList(): LiveRoom[];
|
|
15
|
+
}
|
|
5
16
|
declare module "../.." {
|
|
6
17
|
interface AppCommandMap {
|
|
7
18
|
add: (platform: string, id: number, options?: boolean | Record<string, any>) => void;
|
|
@@ -12,6 +23,7 @@ declare module "../.." {
|
|
|
12
23
|
update: (key: string) => void;
|
|
13
24
|
"room.snapshot": () => LiveRoomData[];
|
|
14
25
|
[name: `${string}.room.create`]: (id: string | number, options: Record<string, any>) => LiveRoom | Promise<LiveRoom>;
|
|
26
|
+
[name: `${string}.room.data`]: (id: string | number) => LiveRoomData | Promise<LiveRoomData>;
|
|
15
27
|
}
|
|
16
28
|
interface AppEventDetailMap {
|
|
17
29
|
"live:message": {
|
|
@@ -82,12 +94,16 @@ declare module "../.." {
|
|
|
82
94
|
options: Record<string, any>;
|
|
83
95
|
};
|
|
84
96
|
}
|
|
97
|
+
interface AppPluginExposesMap {
|
|
98
|
+
room: PluginExposes;
|
|
99
|
+
}
|
|
85
100
|
}
|
|
86
101
|
export declare class Room extends BasePlugin {
|
|
87
102
|
static pluginName: string;
|
|
88
103
|
private map;
|
|
89
104
|
private symbolRoomEventHandlers;
|
|
90
|
-
|
|
105
|
+
init(ctx: PluginContext): void;
|
|
106
|
+
expose(): PluginExposes;
|
|
91
107
|
/** 添加房间监听实例 */
|
|
92
108
|
attachRoom(room: LiveRoom, open?: boolean): void;
|
|
93
109
|
/** 添加房间 */
|
|
@@ -98,13 +114,13 @@ export declare class Room extends BasePlugin {
|
|
|
98
114
|
get(key: string): LiveRoom | undefined;
|
|
99
115
|
has(key: string): boolean;
|
|
100
116
|
/** 获取房间信息 */
|
|
101
|
-
|
|
117
|
+
data(key: string): LiveRoomData | undefined;
|
|
102
118
|
/** 更新房间信息 */
|
|
103
119
|
update(key: string): void;
|
|
104
120
|
/** 获取房间key列表 */
|
|
105
|
-
get keys():
|
|
121
|
+
get keys(): string[];
|
|
106
122
|
/** 获取房间列表 */
|
|
107
|
-
getList():
|
|
123
|
+
getList(): LiveRoom[];
|
|
108
124
|
/** 打开房间连接 */
|
|
109
125
|
open(key: string): void;
|
|
110
126
|
/** 关闭房间连接 */
|
|
@@ -2,10 +2,12 @@ import { AppError } from "../../error";
|
|
|
2
2
|
import { BasePlugin } from "../../plugin";
|
|
3
3
|
import { bindCommand } from "../../utils";
|
|
4
4
|
export class Room extends BasePlugin {
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
7
|
this.map = new Map();
|
|
8
8
|
this.symbolRoomEventHandlers = Symbol("room.roomEventHandlers");
|
|
9
|
+
}
|
|
10
|
+
init(ctx) {
|
|
9
11
|
ctx.registerCommand("add", bindCommand(this.add, this));
|
|
10
12
|
ctx.registerCommand("remove", bindCommand(this.remove, this));
|
|
11
13
|
ctx.registerCommand("open", bindCommand(this.open, this));
|
|
@@ -13,6 +15,19 @@ export class Room extends BasePlugin {
|
|
|
13
15
|
ctx.registerCommand("update", bindCommand(this.update, this));
|
|
14
16
|
ctx.registerCommand("room.snapshot", bindCommand(this.getSnapshot, this));
|
|
15
17
|
}
|
|
18
|
+
expose() {
|
|
19
|
+
return {
|
|
20
|
+
add: this.add.bind(this),
|
|
21
|
+
remove: this.remove.bind(this),
|
|
22
|
+
get: this.get.bind(this),
|
|
23
|
+
has: this.has.bind(this),
|
|
24
|
+
data: this.data.bind(this),
|
|
25
|
+
update: this.update.bind(this),
|
|
26
|
+
open: this.open.bind(this),
|
|
27
|
+
close: this.close.bind(this),
|
|
28
|
+
getList: this.getList.bind(this),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
16
31
|
/** 添加房间监听实例 */
|
|
17
32
|
attachRoom(room, open) {
|
|
18
33
|
let key = room.key;
|
|
@@ -125,7 +140,7 @@ export class Room extends BasePlugin {
|
|
|
125
140
|
return this.map.has(key);
|
|
126
141
|
}
|
|
127
142
|
/** 获取房间信息 */
|
|
128
|
-
|
|
143
|
+
data(key) {
|
|
129
144
|
let room = this.map.get(key);
|
|
130
145
|
return room ? room.toData() : undefined;
|
|
131
146
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare class CustomEventEmitter extends EventTarget {
|
|
2
|
-
on(type: string, listener: (e: any) => void): void;
|
|
3
|
-
once(type: string, listener: (e: any) => void): void;
|
|
2
|
+
on(type: string, listener: (e: any) => void, signal?: AbortSignal): void;
|
|
3
|
+
once(type: string, listener: (e: any) => void, signal?: AbortSignal): void;
|
|
4
4
|
off(type: string, listener: (e: any) => void): void;
|
|
5
5
|
emit(type: string, detail: any, options?: EventInit): void;
|
|
6
6
|
}
|
|
@@ -10,11 +10,11 @@ function getListenerCallback(listener) {
|
|
|
10
10
|
return newItem;
|
|
11
11
|
}
|
|
12
12
|
export class CustomEventEmitter extends EventTarget {
|
|
13
|
-
on(type, listener) {
|
|
14
|
-
this.addEventListener(type, getListenerCallback(listener));
|
|
13
|
+
on(type, listener, signal) {
|
|
14
|
+
this.addEventListener(type, getListenerCallback(listener), { signal });
|
|
15
15
|
}
|
|
16
|
-
once(type, listener) {
|
|
17
|
-
this.addEventListener(type, getListenerCallback(listener), { once: true });
|
|
16
|
+
once(type, listener, signal) {
|
|
17
|
+
this.addEventListener(type, getListenerCallback(listener), { once: true, signal });
|
|
18
18
|
}
|
|
19
19
|
off(type, listener) {
|
|
20
20
|
this.removeEventListener(type, getListenerCallback(listener));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type EnumValue<T> = T[keyof T];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/value/manager.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { App } from "../app";
|
|
2
|
-
import { ValueAccessOptions, ValueOptions } from "./types";
|
|
2
|
+
import { ValueAccessOptions, ValueContext, ValueOptions } from "./types";
|
|
3
3
|
export declare class ValueManager {
|
|
4
4
|
private list;
|
|
5
5
|
protected readonly app: App;
|
|
6
6
|
constructor(app: App);
|
|
7
7
|
/** 注册值 */
|
|
8
|
-
register<T>(name: string, { get, set, pluginName }: ValueOptions<T>):
|
|
8
|
+
register<T>(name: string, { get, set, pluginName }: ValueOptions<T>): ValueContext<T>;
|
|
9
9
|
/** 取消注册 */
|
|
10
10
|
unregister(name: string): void;
|
|
11
11
|
/** 获取值 */
|
package/dist/value/manager.js
CHANGED
|
@@ -10,6 +10,11 @@ export class ValueManager {
|
|
|
10
10
|
register(name, { get, set, pluginName }) {
|
|
11
11
|
this.list.set(name, { get, set, pluginName });
|
|
12
12
|
this.app.emit("value:register", { name, value: get() }, { source: `plugin:${pluginName}` });
|
|
13
|
+
return {
|
|
14
|
+
emit: (v) => {
|
|
15
|
+
this.emit(name, v);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
13
18
|
}
|
|
14
19
|
/** 取消注册 */
|
|
15
20
|
unregister(name) {
|
package/package.json
CHANGED
package/tsconfig.tsbuildinfo
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["./src/floatinglive.ts","./src/app.ts","./src/index.ts","./src/command/index.ts","./src/command/manager.ts","./src/command/types.ts","./src/error/index.ts","./src/error/types.ts","./src/event/index.ts","./src/event/manager.ts","./src/event/types.ts","./src/hook/index.ts","./src/hook/manager.ts","./src/hook/types.ts","./src/live/index.ts","./src/live/message.ts","./src/live/messageinfo.ts","./src/live/platform.ts","./src/live/room.ts","./src/plugin/index.ts","./src/plugin/manager.ts","./src/plugin/types.ts","./src/plugin/context/commonplugincontext.ts","./src/plugin/context/safeplugincontext.ts","./src/plugins/room/index.ts","./src/utils/eventemitter.ts","./src/utils/index.ts","./src/value/index.ts","./src/value/manager.ts","./src/value/types.ts"],"version":"5.6.3"}
|