floating-live 0.16.0-alpha.1 → 0.16.0-alpha.10

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/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, PluginRegisterOptions } from "./plugin";
5
+ import { AppPluginExposesMap, PluginContext, PluginInitOptions } 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,24 +10,27 @@ 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]>): void;
15
- once<K extends keyof AppEventDetailMap>(type: K, listener: AppEventListener<AppEventDetailMap[K]>): void;
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: any, options?: PluginRegisterOptions): void;
23
+ register(plugin: any, options?: PluginInitOptions): void;
23
24
  /** 取消注册插件 */
24
25
  unregister(pluginName: string): void;
25
26
  getPlugin(pluginName: string): void;
26
- whenRegister(pluginName: string, callback: (exposes: any) => (() => void) | undefined): void;
27
+ whenRegister<K extends keyof AppPluginExposesMap>(pluginName: K, callback: (exposes: AppPluginExposesMap[K]) => (() => void) | void): void;
28
+ whenRegister(pluginName: string, callback: () => (() => void) | void): void;
27
29
  getPluginExposes(pluginName: string): any;
28
30
  hasPlugin(pluginName: string): boolean;
29
31
  registerCommand<T extends keyof AppCommandMap>(name: T, func: CommandFunction<AppCommandMap[T]>, options?: CommandOptions): void;
30
32
  unregisterCommand(name: string): void;
33
+ hasCommand(name: string): boolean;
31
34
  call<T extends keyof AppCommandMap>(name: T, ...args: Parameters<AppCommandMap[T]>): ReturnType<AppCommandMap[T]>;
32
35
  callWithOptions<T extends keyof AppCommandMap>(name: T, options: CommandCallOptions, ...args: Parameters<AppCommandMap[T]>): ReturnType<AppCommandMap[T]>;
33
36
  useHook<T extends keyof AppHookMap>(name: T, func: HookFunction<AppHookMap[T]>, options?: HookUseOptions): void;
@@ -38,9 +41,11 @@ export declare class App extends CustomEventEmitter implements PluginContext {
38
41
  unregisterValue(name: string): void;
39
42
  watch<K extends keyof AppValueMap>(name: K, watcher: (value: AppValueMap[K]) => void): void;
40
43
  unwatch<K extends keyof AppValueMap>(name: K, watcher: (value: AppValueMap[K]) => void): void;
44
+ hasValue(name: string): boolean;
41
45
  getValue<K extends keyof AppValueMap>(name: K): AppValueMap[K];
42
46
  setValue(name: string, value: any): void;
43
47
  destroy(): void;
44
48
  /** 拓展值 */
45
49
  define(): void;
50
+ get signal(): AbortSignal;
46
51
  }
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);
@@ -81,6 +82,9 @@ export class App extends CustomEventEmitter {
81
82
  unregisterCommand(name) {
82
83
  this.commandManager.unregister(name);
83
84
  }
85
+ hasCommand(name) {
86
+ return this.commandManager.has(name);
87
+ }
84
88
  call(name, ...args) {
85
89
  return this.commandManager.call(name, ...args);
86
90
  }
@@ -113,14 +117,22 @@ export class App extends CustomEventEmitter {
113
117
  unwatch(name, watcher) {
114
118
  this.valueManager.unwatch(name, watcher);
115
119
  }
120
+ hasValue(name) {
121
+ return this.valueManager.has(name);
122
+ }
116
123
  getValue(name) {
117
124
  return this.valueManager.get(name);
118
125
  }
119
126
  setValue(name, value) {
120
127
  this.valueManager.set(name, value);
121
128
  }
122
- destroy() { }
129
+ destroy() {
130
+ this.abortController.abort();
131
+ }
123
132
  //--- 其他 ---//
124
133
  /** 拓展值 */
125
134
  define() { }
135
+ get signal() {
136
+ return this.abortController.signal;
137
+ }
126
138
  }
@@ -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 = 0,
72
+ readonly custom: 0;
73
73
  /** 小表情(文字行高) */
74
- small = 1,
74
+ readonly small: 1;
75
75
  /** 大表情 */
76
- large = 2
77
- }
76
+ readonly large: 2;
77
+ };
78
+ export type ImageSize = EnumValue<typeof ImageSize>;
78
79
  /** 弹幕模式 */
79
- export declare enum DanmakuMode {
80
- left = 1,
81
- bottom = 4,
82
- top = 5,
83
- right = 6
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 enum UserType {
88
+ export declare const UserType: {
87
89
  /** 普通观众 */
88
- normal = 0,
90
+ readonly normal: 0;
89
91
  /** 房管 */
90
- admin = 1,
92
+ readonly admin: 1;
91
93
  /** 主播 */
92
- anchor = 2
93
- }
94
+ readonly anchor: 2;
95
+ };
96
+ export type UserType = EnumValue<typeof UserType>;
@@ -1,28 +1,24 @@
1
- /** 图片大小 */
2
- export var ImageSize;
3
- (function (ImageSize) {
1
+ export const ImageSize = {
4
2
  /** 自定义大小 */
5
- ImageSize[ImageSize["custom"] = 0] = "custom";
3
+ custom: 0,
6
4
  /** 小表情(文字行高) */
7
- ImageSize[ImageSize["small"] = 1] = "small";
5
+ small: 1,
8
6
  /** 大表情 */
9
- ImageSize[ImageSize["large"] = 2] = "large";
10
- })(ImageSize || (ImageSize = {}));
7
+ large: 2,
8
+ };
11
9
  /** 弹幕模式 */
12
- export var DanmakuMode;
13
- (function (DanmakuMode) {
14
- DanmakuMode[DanmakuMode["left"] = 1] = "left";
15
- DanmakuMode[DanmakuMode["bottom"] = 4] = "bottom";
16
- DanmakuMode[DanmakuMode["top"] = 5] = "top";
17
- DanmakuMode[DanmakuMode["right"] = 6] = "right";
18
- })(DanmakuMode || (DanmakuMode = {}));
10
+ export const DanmakuMode = {
11
+ left: 1,
12
+ bottom: 4,
13
+ top: 5,
14
+ right: 6,
15
+ };
19
16
  /** 用户类型 */
20
- export var UserType;
21
- (function (UserType) {
17
+ export const UserType = {
22
18
  /** 普通观众 */
23
- UserType[UserType["normal"] = 0] = "normal";
19
+ normal: 0,
24
20
  /** 房管 */
25
- UserType[UserType["admin"] = 1] = "admin";
21
+ admin: 1,
26
22
  /** 主播 */
27
- UserType[UserType["anchor"] = 2] = "anchor";
28
- })(UserType || (UserType = {}));
23
+ anchor: 2,
24
+ };
@@ -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 enum LiveRoomStatus {
99
+ export declare const LiveRoomStatus: {
99
100
  /** 未开播 */
100
- off = 0,
101
+ readonly off: 0;
101
102
  /** 正在直播 */
102
- live = 1,
103
+ readonly live: 1;
103
104
  /** 正在轮播 */
104
- round = 2,
105
+ readonly round: 2;
105
106
  /** 被封禁 */
106
- banned = -1,
107
+ readonly banned: -1;
107
108
  /** 已上锁 */
108
- locked = -2
109
- }
109
+ readonly locked: -2;
110
+ };
111
+ export type LiveRoomStatus = EnumValue<typeof LiveRoomStatus>;
110
112
  /** 直播间状态 */
111
- export declare enum LiveConnectionStatus {
113
+ export declare const LiveConnectionStatus: {
112
114
  /** 未连接 */
113
- off = 0,
115
+ off: number;
114
116
  /** 连接中 */
115
- connecting = 1,
117
+ connecting: number;
116
118
  /** 连接到服务器 */
117
- connected = 2,
119
+ connected: number;
118
120
  /** 连接到房间 */
119
- entered = 3,
121
+ entered: number;
120
122
  /** 连接失败或断开 */
121
- disconnected = -1
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 var LiveRoomStatus;
95
- (function (LiveRoomStatus) {
94
+ export const LiveRoomStatus = {
96
95
  /** 未开播 */
97
- LiveRoomStatus[LiveRoomStatus["off"] = 0] = "off";
96
+ off: 0,
98
97
  /** 正在直播 */
99
- LiveRoomStatus[LiveRoomStatus["live"] = 1] = "live";
98
+ live: 1,
100
99
  /** 正在轮播 */
101
- LiveRoomStatus[LiveRoomStatus["round"] = 2] = "round";
100
+ round: 2,
102
101
  /** 被封禁 */
103
- LiveRoomStatus[LiveRoomStatus["banned"] = -1] = "banned";
102
+ banned: -1,
104
103
  /** 已上锁 */
105
- LiveRoomStatus[LiveRoomStatus["locked"] = -2] = "locked";
106
- })(LiveRoomStatus || (LiveRoomStatus = {}));
104
+ locked: -2,
105
+ };
107
106
  /** 直播间状态 */
108
- export var LiveConnectionStatus;
109
- (function (LiveConnectionStatus) {
107
+ export const LiveConnectionStatus = {
110
108
  /** 未连接 */
111
- LiveConnectionStatus[LiveConnectionStatus["off"] = 0] = "off";
109
+ off: 0,
112
110
  /** 连接中 */
113
- LiveConnectionStatus[LiveConnectionStatus["connecting"] = 1] = "connecting";
111
+ connecting: 1,
114
112
  /** 连接到服务器 */
115
- LiveConnectionStatus[LiveConnectionStatus["connected"] = 2] = "connected";
113
+ connected: 2,
116
114
  /** 连接到房间 */
117
- LiveConnectionStatus[LiveConnectionStatus["entered"] = 3] = "entered";
115
+ entered: 3,
118
116
  /** 连接失败或断开 */
119
- LiveConnectionStatus[LiveConnectionStatus["disconnected"] = -1] = "disconnected";
120
- })(LiveConnectionStatus || (LiveConnectionStatus = {}));
117
+ disconnected: -1,
118
+ };
@@ -4,7 +4,7 @@ import { AppError, ErrorOptions } from "../../error";
4
4
  import { AppEventListener, AppEventEmitOptions, AppEventDetailMap } from "../../event";
5
5
  import { HookUseOptions, HookCallOptions, AppHookMap, HookFunction, HookContext } from "../../hook";
6
6
  import { AppValueMap, ValueOptions } from "../../value";
7
- import type { PluginContext, PluginConstructor, PluginRegisterOptions } from "../types";
7
+ import type { PluginContext, PluginConstructor, PluginInitOptions, AppPluginExposesMap } 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, options?: PluginRegisterOptions): void;
21
+ register(plugin: PluginConstructor, options?: PluginInitOptions): void;
22
22
  unregister(pluginName: string): void;
23
- getPluginExposes<T>(pluginName: string): T;
24
- whenRegister<T>(pluginName: string, callback: (exposes: any) => (() => void) | undefined): (() => void) | void;
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
26
  registerValue<K extends keyof AppValueMap>(name: K, options: ValueOptions<AppValueMap[K]>): void;
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
- getValue<K extends keyof AppValueMap>(name: K): undefined;
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(),
@@ -139,6 +141,14 @@ export class CommonPluginContext {
139
141
  this.throw(err);
140
142
  }
141
143
  }
144
+ hasCommand(name) {
145
+ try {
146
+ return __classPrivateFieldGet(this, _CommonPluginContext_app, "f").hasCommand(name);
147
+ }
148
+ catch (err) {
149
+ throw this.throw(err);
150
+ }
151
+ }
142
152
  on(type, listener) {
143
153
  try {
144
154
  __classPrivateFieldGet(this, _CommonPluginContext_app, "f").on(type, listener);
@@ -234,7 +244,7 @@ export class CommonPluginContext {
234
244
  __classPrivateFieldGet(this, _CommonPluginContext_app, "f").watch(name, watcher);
235
245
  }
236
246
  catch (err) {
237
- this.throw(err);
247
+ throw this.throw(err);
238
248
  }
239
249
  }
240
250
  unwatch(name, watcher) {
@@ -242,7 +252,15 @@ export class CommonPluginContext {
242
252
  __classPrivateFieldGet(this, _CommonPluginContext_app, "f").unwatch(name, watcher);
243
253
  }
244
254
  catch (err) {
245
- this.throw(err);
255
+ throw this.throw(err);
256
+ }
257
+ }
258
+ hasValue(name) {
259
+ try {
260
+ return __classPrivateFieldGet(this, _CommonPluginContext_app, "f").hasValue(name);
261
+ }
262
+ catch (err) {
263
+ throw this.throw(err);
246
264
  }
247
265
  }
248
266
  getValue(name) {
@@ -250,24 +268,27 @@ export class CommonPluginContext {
250
268
  return __classPrivateFieldGet(this, _CommonPluginContext_app, "f").getValue(name);
251
269
  }
252
270
  catch (err) {
253
- this.throw(err);
271
+ throw this.throw(err);
254
272
  }
255
273
  }
256
274
  setValue(name, value) {
257
275
  try {
258
- __classPrivateFieldGet(this, _CommonPluginContext_app, "f").setValue(name, value);
276
+ return __classPrivateFieldGet(this, _CommonPluginContext_app, "f").setValue(name, value);
259
277
  }
260
278
  catch (err) {
261
- this.throw(err);
279
+ throw this.throw(err);
262
280
  }
263
281
  }
264
282
  destroy() {
265
- const { plugins, events, values, hooks, commands } = __classPrivateFieldGet(this, _CommonPluginContext_registered, "f");
283
+ const { plugins, values, hooks, commands } = __classPrivateFieldGet(this, _CommonPluginContext_registered, "f");
266
284
  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
285
  hooks.forEach((hookList, name) => hookList.forEach((hookFunc) => __classPrivateFieldGet(this, _CommonPluginContext_app, "f").off(name, hookFunc)));
269
286
  commands.forEach((name) => __classPrivateFieldGet(this, _CommonPluginContext_app, "f").unregisterCommand(name));
270
287
  values.forEach((name) => __classPrivateFieldGet(this, _CommonPluginContext_app, "f").unregisterValue(name));
288
+ __classPrivateFieldGet(this, _CommonPluginContext_abortController, "f").abort();
289
+ }
290
+ get signal() {
291
+ return __classPrivateFieldGet(this, _CommonPluginContext_abortController, "f").signal;
271
292
  }
272
293
  }
273
- _CommonPluginContext_app = new WeakMap(), _CommonPluginContext_registered = new WeakMap();
294
+ _CommonPluginContext_app = new WeakMap(), _CommonPluginContext_abortController = new WeakMap(), _CommonPluginContext_registered = 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, PluginRegisterOptions } from "../types";
5
+ import { PluginConstructor, 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, options?: PluginRegisterOptions): void;
25
+ register(plugin: PluginConstructor, options?: PluginInitOptions): void;
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]>;
@@ -38,9 +38,11 @@ export class PluginManager {
38
38
  return;
39
39
  // 执行插件函数
40
40
  const plugin = new pluginConstructor(pluginCtx, registerCtx.options || {});
41
- // 调用插件的register钩子
42
- await plugin.register?.(pluginCtx, registerCtx.options || {});
43
- this.list.set(pluginName, { plugin, context: pluginCtx });
41
+ // 调用插件的init钩子
42
+ await plugin.init?.(pluginCtx, registerCtx.options || {});
43
+ // 调用插件的expose钩子
44
+ const exposes = await plugin.expose?.(pluginCtx);
45
+ this.list.set(pluginName, { plugin, context: pluginCtx, exposes });
44
46
  this.app.emit("plugin:register", { pluginName });
45
47
  return plugin;
46
48
  })
@@ -6,16 +6,17 @@ import { AppValueMap, ValueOptions } from "../value";
6
6
  /** 插件对象 */
7
7
  export interface PluginItem {
8
8
  pluginName: string;
9
- register?(ctx: PluginContext, options?: Record<string, any>): void;
10
- destroy?(ctx: PluginContext): void;
9
+ init?(ctx: PluginContext, options?: Record<string, any>): void | Promise<void>;
10
+ destroy?(ctx: PluginContext): void | Promise<void>;
11
+ expose?(ctx: PluginContext): any;
11
12
  }
12
13
  /** 插件构造器 */
13
14
  export interface PluginConstructor {
14
15
  pluginName: string;
15
16
  new (ctx: PluginContext, options: any): PluginItem;
16
17
  }
17
- /** 插件注册选项 */
18
- export interface PluginRegisterOptions {
18
+ /** 插件初始化选项 */
19
+ export interface PluginInitOptions {
19
20
  }
20
21
  /** 插件上下文 */
21
22
  export interface PluginContext {
@@ -32,19 +33,22 @@ export interface PluginContext {
32
33
  /** 生成错误 */
33
34
  error(id: string, options: ErrorOptions): AppError;
34
35
  /** 注册插件 */
35
- register(plugin: PluginConstructor, options?: PluginRegisterOptions): void;
36
+ register(plugin: PluginConstructor, options?: PluginInitOptions): void;
36
37
  /** 取消注册插件 */
37
38
  unregister(pluginName: string): void;
38
39
  /** 获取插件暴露对象 */
39
- getPluginExposes<T>(pluginName: string): T;
40
+ getPluginExposes<K extends keyof AppPluginExposesMap>(pluginName: K): AppPluginExposesMap[K];
40
41
  /** 等待plugin注册 */
41
- whenRegister(pluginName: string, callback: (exposes: any) => (() => void) | void): void;
42
+ whenRegister<K extends keyof AppPluginExposesMap>(pluginName: K, callback: (exposes: AppPluginExposesMap[K]) => (() => void) | void): void;
43
+ whenRegister(pluginName: string, callback: () => (() => void) | void): void;
42
44
  /** 是否存在插件 */
43
45
  hasPlugin(pluginName: string): boolean;
44
46
  /** 注册指令 */
45
47
  registerCommand<T extends keyof AppCommandMap>(name: T, func: CommandFunction<AppCommandMap[T]>, options?: CommandOptions): void;
46
48
  /** 取消注册指令 */
47
49
  unregisterCommand(name: string): void;
50
+ /** 检测值是否存在 */
51
+ hasCommand(name: string): boolean;
48
52
  /** 调用指令 */
49
53
  call<T extends keyof AppCommandMap>(name: T, ...args: Parameters<AppCommandMap[T]>): ReturnType<AppCommandMap[T]>;
50
54
  /** 调用指令(可配置) */
@@ -65,9 +69,15 @@ export interface PluginContext {
65
69
  watch<K extends keyof AppValueMap>(name: K, watcher: (value: AppValueMap[K]) => void): void;
66
70
  /** 取消监听值 */
67
71
  unwatch<K extends keyof AppValueMap>(name: K, watcher: (value: AppValueMap[K]) => void): void;
72
+ /** 值是否存在 */
73
+ hasValue(name: string): boolean;
68
74
  /** 获取值 */
69
75
  getValue<K extends keyof AppValueMap>(name: K): AppValueMap[K];
70
76
  /** 设置值 */
71
77
  setValue<K extends keyof AppValueMap>(name: K, value: AppValueMap[K]): void;
72
78
  destroy(): void;
79
+ get signal(): AbortSignal;
80
+ }
81
+ export interface AppPluginExposesMap {
82
+ "": {};
73
83
  }
@@ -12,6 +12,7 @@ declare module "../.." {
12
12
  update: (key: string) => void;
13
13
  "room.snapshot": () => LiveRoomData[];
14
14
  [name: `${string}.room.create`]: (id: string | number, options: Record<string, any>) => LiveRoom | Promise<LiveRoom>;
15
+ [name: `${string}.room.data`]: (id: string | number) => LiveRoomData | Promise<LiveRoomData>;
15
16
  }
16
17
  interface AppEventDetailMap {
17
18
  "live:message": {
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.16.0-alpha.1",
3
+ "version": "0.16.0-alpha.10",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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"}