floating-live 0.15.10 → 0.16.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +14 -10
  2. package/dist/FloatingLive.d.ts +6 -0
  3. package/dist/FloatingLive.js +8 -0
  4. package/dist/app.d.ts +46 -0
  5. package/dist/app.js +126 -0
  6. package/dist/command/index.d.ts +1 -0
  7. package/dist/command/index.js +1 -0
  8. package/dist/command/manager.d.ts +23 -0
  9. package/dist/command/manager.js +46 -0
  10. package/dist/command/types.d.ts +25 -0
  11. package/{esm/types/command.js → dist/command/types.js} +1 -1
  12. package/dist/error/index.d.ts +11 -0
  13. package/dist/error/index.js +9 -0
  14. package/dist/error/types.d.ts +6 -0
  15. package/{esm/types/error.js → dist/error/types.js} +1 -1
  16. package/dist/event/index.d.ts +1 -0
  17. package/dist/event/index.js +1 -0
  18. package/dist/event/manager.d.ts +9 -0
  19. package/dist/event/manager.js +17 -0
  20. package/dist/event/types.d.ts +42 -0
  21. package/{esm/types/events.js → dist/event/types.js} +1 -1
  22. package/dist/hook/index.d.ts +1 -0
  23. package/dist/hook/index.js +1 -0
  24. package/dist/hook/manager.d.ts +25 -0
  25. package/dist/hook/manager.js +79 -0
  26. package/dist/hook/types.d.ts +22 -0
  27. package/{esm/types/hook.js → dist/hook/types.js} +1 -1
  28. package/dist/index.d.ts +8 -5
  29. package/dist/index.js +8 -23
  30. package/dist/{types → live}/message.d.ts +185 -248
  31. package/{esm/types → dist/live}/message.js +1 -1
  32. package/dist/live/messageInfo.d.ts +93 -0
  33. package/dist/live/messageInfo.js +28 -0
  34. package/dist/live/platform.d.ts +40 -0
  35. package/dist/live/platform.js +1 -0
  36. package/dist/live/room.d.ts +150 -0
  37. package/dist/live/room.js +120 -0
  38. package/dist/plugin/context/CommonPluginContext.d.ts +45 -0
  39. package/dist/plugin/context/CommonPluginContext.js +273 -0
  40. package/dist/plugin/context/SafePluginContext.d.ts +34 -0
  41. package/dist/plugin/context/SafePluginContext.js +91 -0
  42. package/dist/plugin/index.d.ts +8 -0
  43. package/dist/plugin/index.js +5 -0
  44. package/dist/plugin/manager.d.ts +31 -0
  45. package/dist/plugin/manager.js +93 -0
  46. package/dist/plugin/types.d.ts +73 -0
  47. package/dist/plugin/types.js +1 -0
  48. package/dist/plugins/room/index.d.ts +116 -0
  49. package/dist/plugins/room/index.js +172 -0
  50. package/dist/utils/EventEmitter.d.ts +6 -0
  51. package/dist/utils/EventEmitter.js +26 -0
  52. package/dist/utils/index.d.ts +2 -0
  53. package/dist/utils/index.js +4 -0
  54. package/dist/value/index.d.ts +1 -0
  55. package/dist/value/index.js +1 -0
  56. package/dist/value/manager.d.ts +24 -0
  57. package/dist/value/manager.js +63 -0
  58. package/dist/value/types.d.ts +19 -0
  59. package/dist/value/types.js +1 -0
  60. package/package.json +9 -40
  61. package/src/source.md +29 -0
  62. package/tsconfig.tsbuildinfo +1 -0
  63. package/dist/core/LiveRoom.d.ts +0 -44
  64. package/dist/core/LiveRoom.js +0 -81
  65. package/dist/core/index.d.ts +0 -1
  66. package/dist/core/index.js +0 -17
  67. package/dist/core/plugin.d.ts +0 -17
  68. package/dist/core/plugin.js +0 -28
  69. package/dist/enums.d.ts +0 -51
  70. package/dist/enums.js +0 -59
  71. package/dist/live.d.ts +0 -39
  72. package/dist/live.js +0 -51
  73. package/dist/module/command.d.ts +0 -18
  74. package/dist/module/command.js +0 -42
  75. package/dist/module/hook.d.ts +0 -15
  76. package/dist/module/hook.js +0 -51
  77. package/dist/module/manifest.d.ts +0 -15
  78. package/dist/module/manifest.js +0 -44
  79. package/dist/module/plugin.d.ts +0 -16
  80. package/dist/module/plugin.js +0 -84
  81. package/dist/module/room.d.ts +0 -32
  82. package/dist/module/room.js +0 -159
  83. package/dist/module/value.d.ts +0 -26
  84. package/dist/module/value.js +0 -60
  85. package/dist/types/command.d.ts +0 -23
  86. package/dist/types/command.js +0 -2
  87. package/dist/types/error.d.ts +0 -10
  88. package/dist/types/error.js +0 -2
  89. package/dist/types/events.d.ts +0 -41
  90. package/dist/types/events.js +0 -2
  91. package/dist/types/hook.d.ts +0 -15
  92. package/dist/types/hook.js +0 -2
  93. package/dist/types/index.d.ts +0 -9
  94. package/dist/types/index.js +0 -25
  95. package/dist/types/manifest.d.ts +0 -4
  96. package/dist/types/manifest.js +0 -2
  97. package/dist/types/message.js +0 -2
  98. package/dist/types/plugin.d.ts +0 -13
  99. package/dist/types/plugin.js +0 -2
  100. package/dist/types/room.d.ts +0 -98
  101. package/dist/types/room.js +0 -2
  102. package/dist/types/value.d.ts +0 -2
  103. package/dist/types/value.js +0 -2
  104. package/dist/utils.d.ts +0 -2
  105. package/dist/utils.js +0 -21
  106. package/esm/core/LiveRoom.js +0 -77
  107. package/esm/core/index.js +0 -1
  108. package/esm/core/plugin.js +0 -24
  109. package/esm/enums.js +0 -56
  110. package/esm/index.js +0 -5
  111. package/esm/live.js +0 -47
  112. package/esm/module/command.js +0 -38
  113. package/esm/module/hook.js +0 -47
  114. package/esm/module/manifest.js +0 -40
  115. package/esm/module/plugin.js +0 -80
  116. package/esm/module/room.js +0 -155
  117. package/esm/module/value.js +0 -56
  118. package/esm/types/index.js +0 -9
  119. package/esm/types/manifest.js +0 -1
  120. package/esm/types/plugin.js +0 -1
  121. package/esm/types/room.js +0 -1
  122. package/esm/types/value.js +0 -1
  123. package/esm/utils.js +0 -17
@@ -0,0 +1,63 @@
1
+ import { bindCommand } from "../utils";
2
+ export class ValueManager {
3
+ constructor(app) {
4
+ this.list = new Map();
5
+ this.app = app;
6
+ app.registerCommand("get", bindCommand(this.get, this));
7
+ app.registerCommand("set", bindCommand(this.set, this));
8
+ }
9
+ /** 注册值 */
10
+ register(name, { get, set, pluginName }) {
11
+ this.list.set(name, { get, set, pluginName });
12
+ this.app.emit("value:register", { name, value: get() }, { source: `plugin:${pluginName}` });
13
+ }
14
+ /** 取消注册 */
15
+ unregister(name) {
16
+ this.list.delete(name);
17
+ this.app.emit("value:unregister", { name });
18
+ }
19
+ /** 获取值 */
20
+ get(name, options) {
21
+ const item = this.list.get(name);
22
+ if (!item)
23
+ throw {};
24
+ return item.get(options);
25
+ }
26
+ /** 获取值(不存在则返回undefined) */
27
+ getNullable(name, options) {
28
+ return this.list.get(name)?.get(options);
29
+ }
30
+ /** 设置值 */
31
+ set(name, value, options) {
32
+ const valueItem = this.list.get(name);
33
+ if (valueItem?.set) {
34
+ valueItem?.set(value, options);
35
+ return true;
36
+ }
37
+ else {
38
+ return false;
39
+ }
40
+ }
41
+ /** 检测值是否存在 */
42
+ has(name) {
43
+ return this.list.has(name);
44
+ }
45
+ emit(name, value) {
46
+ this.app.emit(`change:${name}`, value);
47
+ this.app.emit("value:change", { name, value });
48
+ }
49
+ watch(name, listener) {
50
+ this.app.on(`change:${name}`, listener);
51
+ }
52
+ unwatch(name, listener) {
53
+ this.app.off(`change:${name}`, listener);
54
+ }
55
+ /** 获取注册的所有值 */
56
+ getData() {
57
+ const map = {};
58
+ this.list.forEach((config, name) => {
59
+ map[name] = config.get();
60
+ });
61
+ return map;
62
+ }
63
+ }
@@ -0,0 +1,19 @@
1
+ export interface ValueOptions<T> {
2
+ pluginName?: string;
3
+ get: () => T;
4
+ set?: (value: T) => void;
5
+ }
6
+ export interface ValueContext<T> {
7
+ emit: (value: T) => void;
8
+ }
9
+ export interface ValueItem<T> {
10
+ pluginName?: string;
11
+ get: (options?: ValueAccessOptions) => T;
12
+ set?: (value: T, options?: ValueAccessOptions) => void;
13
+ }
14
+ export interface ValueAccessOptions {
15
+ pluginName?: string;
16
+ }
17
+ export interface AppValueMap {
18
+ "": undefined;
19
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,53 +1,22 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.15.10",
4
- "type": "commonjs",
3
+ "version": "0.16.0-alpha.0",
4
+ "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "author": "Minteea",
8
8
  "license": "MIT",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "require": "./dist/index.js",
13
- "import": "./esm/index.js"
14
- },
15
- "./core": {
16
- "types": "./dist/core/index.d.ts",
17
- "require": "./dist/core/index.js",
18
- "import": "./esm/core/index.js"
19
- },
20
- "./types": {
21
- "types": "./dist/types/index.d.ts",
22
- "require": "./dist/types/index.js",
23
- "import": "./esm/types/index.js"
24
- },
25
- "./enums": {
26
- "types": "./dist/enums.d.ts",
27
- "require": "./dist/enums.js",
28
- "import": "./esm/enums.js"
29
- },
30
- "./utils": {
31
- "types": "./dist/utils.d.ts",
32
- "require": "./dist/utils.js",
33
- "import": "./esm/utils.js"
34
- }
9
+ "devDependencies": {
10
+ "@types/node": "^22.8.2",
11
+ "typescript": "^5.6.3",
12
+ "rimraf": "^3.0.2",
13
+ "ts-node": "^10.9.1"
35
14
  },
36
15
  "scripts": {
37
16
  "tsc": "tsc -b",
38
- "clear": "rimraf dist esm",
39
- "test": "npm run clear && ts-node demo/demo.ts",
40
- "build-test": "npm run build && node demo/demo.js",
41
- "build": "npm run clear && tsc -b && tsc --project tsconfig.esm.json",
17
+ "clear": "rimraf dist",
18
+ "build": "npm run clear && tsc -b",
42
19
  "prepack": "npm run build",
43
20
  "postpack": "npm run clear"
44
- },
45
- "devDependencies": {
46
- "rimraf": "^3.0.2",
47
- "ts-node": "^10.9.1",
48
- "typescript": "^4.8.4"
49
- },
50
- "peerDependencies": {
51
- "events": "^3.3.0"
52
21
  }
53
22
  }
package/src/source.md ADDED
@@ -0,0 +1,29 @@
1
+ ##### 插件来源(source 字段)
2
+
3
+ - managerName
4
+ - "plugin:{pluginName}" (插件调用)
5
+ - "" (app.emit())
6
+
7
+ ##### 客户端/服务端来源(client.name 字段)
8
+
9
+ - "electron" (electron 客户端)
10
+ - "web:{clinetId}" (网络客户端)
11
+ - "server" (服务端)
12
+ - "" (自身环境内)
13
+
14
+ #### 机制
15
+
16
+ - from server/node = source: "plugin:foo"
17
+ - to server/node = source: "plugin:foo" client: ""
18
+ - to client/browser = source: "plugin:foo" client: "server"
19
+ - to client/electron = source: "plugin:foo" client: "server"
20
+ - from client/browser = source: "plugin:foo"
21
+ - to client/browser = source: "plugin:foo" client: ""
22
+ - to server/node = source: "plugin:foo" client: "browser:10000001"
23
+
24
+ ctx.callWithOptions(name, options, ...args)
25
+ ctx.emitWithOptions(name, detail, options)
26
+
27
+ ctx.on()
28
+
29
+ client.emit()
@@ -0,0 +1 @@
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/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"}
@@ -1,44 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from "events";
3
- import { ConnectStatus, RoomStatus } from "../enums";
4
- import { RoomDetail, RoomInfo, RoomStatsInfo } from "../types";
5
- import { Message, UserInfo } from "../types/message";
6
- export declare abstract class LiveRoom extends EventEmitter implements RoomInfo {
7
- constructor();
8
- /** 平台 */
9
- abstract readonly platform: string;
10
- /** 房间id */
11
- abstract readonly id: string | number;
12
- /** 房间详情 */
13
- abstract detail: RoomDetail;
14
- /** 统计信息 */
15
- stats?: RoomStatsInfo;
16
- /** 主播信息 */
17
- abstract anchor: UserInfo;
18
- /** 直播状态 */
19
- status: RoomStatus;
20
- /** 时间戳 */
21
- timestamp: number;
22
- /** 当前直播id */
23
- liveId?: string;
24
- /** 房间是否打开 */
25
- opened: boolean;
26
- /** 是否连接上房间 */
27
- connection: ConnectStatus;
28
- /** 房间是否可用 */
29
- abstract available: boolean;
30
- /** 打开连接 */
31
- abstract open(): void;
32
- /** 关闭连接 */
33
- abstract close(): void;
34
- /** 从服务器获取信息 */
35
- abstract getInfo(): Promise<void>;
36
- /** 销毁事件 */
37
- protected onDestroy?(): void;
38
- /** 销毁 */
39
- destroy(): void;
40
- protected emitMessage(msg: Message.All): void;
41
- protected emitRaw(msg: any): void;
42
- get info(): RoomInfo;
43
- get key(): string;
44
- }
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LiveRoom = void 0;
4
- const events_1 = require("events");
5
- const enums_1 = require("../enums");
6
- class LiveRoom extends events_1.EventEmitter {
7
- constructor() {
8
- super();
9
- /** 直播状态 */
10
- this.status = enums_1.RoomStatus.off;
11
- /** 时间戳 */
12
- this.timestamp = 0;
13
- /** 房间是否打开 */
14
- this.opened = false;
15
- /** 是否连接上房间 */
16
- this.connection = enums_1.ConnectStatus.off;
17
- }
18
- /** 销毁 */
19
- destroy() {
20
- this.close();
21
- this.removeAllListeners();
22
- this.onDestroy?.();
23
- }
24
- // 发送消息
25
- emitMessage(msg) {
26
- // 其他消息 => 先更改状态再发送消息
27
- // 直播结束消息 => 先发送消息再更改状态
28
- switch (msg.type) {
29
- case "live_start":
30
- this.status = enums_1.RoomStatus.live;
31
- this.timestamp = msg.timestamp;
32
- this.emit("status", enums_1.RoomStatus.live, {
33
- timestamp: msg.timestamp,
34
- id: msg.info.id,
35
- });
36
- break;
37
- case "live_detail":
38
- this.detail = Object.assign(this.detail, msg.info);
39
- this.emit("detail", msg.info);
40
- break;
41
- case "live_stats":
42
- this.stats = Object.assign(this.stats, msg.info);
43
- this.emit("stats", msg.info);
44
- break;
45
- case "live_end":
46
- case "live_cut":
47
- this.status = msg.status || enums_1.RoomStatus.off;
48
- this.timestamp = msg.timestamp;
49
- this.emit("message", msg);
50
- this.emit("status", msg.status || enums_1.RoomStatus.off, {
51
- timestamp: msg.timestamp,
52
- });
53
- return;
54
- }
55
- this.emit("message", msg);
56
- }
57
- // 发送源消息
58
- emitRaw(msg) {
59
- this.emit("raw", msg, { platform: this.platform, room: this.id });
60
- }
61
- get info() {
62
- return {
63
- platform: this.platform,
64
- id: this.id,
65
- detail: this.detail,
66
- stats: this.stats,
67
- anchor: this.anchor,
68
- timestamp: this.timestamp,
69
- status: this.status,
70
- liveId: this.liveId,
71
- available: this.available,
72
- opened: this.opened,
73
- connection: this.connection,
74
- key: this.key,
75
- };
76
- }
77
- get key() {
78
- return `${this.platform}:${this.id}`;
79
- }
80
- }
81
- exports.LiveRoom = LiveRoom;
@@ -1 +0,0 @@
1
- export * from "./LiveRoom";
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./LiveRoom"), exports);
@@ -1,17 +0,0 @@
1
- import { FloatingLive } from "../live";
2
- import { FloatingEventMap } from "../types/events";
3
- export declare abstract class BasePlugin {
4
- static pluginName: string;
5
- protected main: FloatingLive;
6
- private registerList;
7
- constructor(main: FloatingLive);
8
- /** 插件监听事件 */
9
- on<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): void;
10
- /** 插件一次性监听事件 */
11
- once<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): void;
12
- /** 插件移除监听事件 */
13
- off<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): void;
14
- /** 插件发送事件 */
15
- emit<T extends keyof FloatingEventMap>(eventName: T, ...args: Parameters<FloatingEventMap[T]>): void;
16
- abstract destroy(): void;
17
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BasePlugin = void 0;
4
- class BasePlugin {
5
- constructor(main) {
6
- this.registerList = [];
7
- this.main = main;
8
- }
9
- /** 插件监听事件 */
10
- on(eventName, listener) {
11
- this.main.on(eventName, listener);
12
- this.registerList.push(["event", eventName, listener]);
13
- }
14
- /** 插件一次性监听事件 */
15
- once(eventName, listener) {
16
- this.main.once(eventName, listener);
17
- this.registerList.push(["event", eventName, listener]);
18
- }
19
- /** 插件移除监听事件 */
20
- off(eventName, listener) {
21
- this.main.off(eventName, listener);
22
- }
23
- /** 插件发送事件 */
24
- emit(eventName, ...args) {
25
- this.main.emit(eventName, ...args);
26
- }
27
- }
28
- exports.BasePlugin = BasePlugin;
package/dist/enums.d.ts DELETED
@@ -1,51 +0,0 @@
1
- /** 直播间状态 */
2
- export declare enum RoomStatus {
3
- /** 未开播 */
4
- off = 0,
5
- /** 正在直播 */
6
- live = 1,
7
- /** 正在轮播 */
8
- round = 2,
9
- /** 被封禁 */
10
- banned = -1,
11
- /** 已上锁 */
12
- locked = -2
13
- }
14
- /** 直播间状态 */
15
- export declare enum ConnectStatus {
16
- /** 未连接 */
17
- off = 0,
18
- /** 连接中 */
19
- connecting = 1,
20
- /** 连接到服务器 */
21
- connected = 2,
22
- /** 连接到房间 */
23
- entered = 3,
24
- /** 连接失败或断开 */
25
- disconnected = -1
26
- }
27
- /** 图片大小 */
28
- export declare enum ImageSize {
29
- /** 自定义大小 */
30
- custom = 0,
31
- /** 小表情(文字行高) */
32
- small = 1,
33
- /** 大表情 */
34
- large = 2
35
- }
36
- /** 弹幕模式 */
37
- export declare enum DanmakuMode {
38
- left = 1,
39
- bottom = 4,
40
- top = 5,
41
- right = 6
42
- }
43
- /** 用户类型 */
44
- export declare enum UserType {
45
- /** 普通观众 */
46
- normal = 0,
47
- /** 房管 */
48
- admin = 1,
49
- /** 主播 */
50
- anchor = 2
51
- }
package/dist/enums.js DELETED
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UserType = exports.DanmakuMode = exports.ImageSize = exports.ConnectStatus = exports.RoomStatus = void 0;
4
- /** 直播间状态 */
5
- var RoomStatus;
6
- (function (RoomStatus) {
7
- /** 未开播 */
8
- RoomStatus[RoomStatus["off"] = 0] = "off";
9
- /** 正在直播 */
10
- RoomStatus[RoomStatus["live"] = 1] = "live";
11
- /** 正在轮播 */
12
- RoomStatus[RoomStatus["round"] = 2] = "round";
13
- /** 被封禁 */
14
- RoomStatus[RoomStatus["banned"] = -1] = "banned";
15
- /** 已上锁 */
16
- RoomStatus[RoomStatus["locked"] = -2] = "locked";
17
- })(RoomStatus = exports.RoomStatus || (exports.RoomStatus = {}));
18
- /** 直播间状态 */
19
- var ConnectStatus;
20
- (function (ConnectStatus) {
21
- /** 未连接 */
22
- ConnectStatus[ConnectStatus["off"] = 0] = "off";
23
- /** 连接中 */
24
- ConnectStatus[ConnectStatus["connecting"] = 1] = "connecting";
25
- /** 连接到服务器 */
26
- ConnectStatus[ConnectStatus["connected"] = 2] = "connected";
27
- /** 连接到房间 */
28
- ConnectStatus[ConnectStatus["entered"] = 3] = "entered";
29
- /** 连接失败或断开 */
30
- ConnectStatus[ConnectStatus["disconnected"] = -1] = "disconnected";
31
- })(ConnectStatus = exports.ConnectStatus || (exports.ConnectStatus = {}));
32
- /** 图片大小 */
33
- var ImageSize;
34
- (function (ImageSize) {
35
- /** 自定义大小 */
36
- ImageSize[ImageSize["custom"] = 0] = "custom";
37
- /** 小表情(文字行高) */
38
- ImageSize[ImageSize["small"] = 1] = "small";
39
- /** 大表情 */
40
- ImageSize[ImageSize["large"] = 2] = "large";
41
- })(ImageSize = exports.ImageSize || (exports.ImageSize = {}));
42
- /** 弹幕模式 */
43
- var DanmakuMode;
44
- (function (DanmakuMode) {
45
- DanmakuMode[DanmakuMode["left"] = 1] = "left";
46
- DanmakuMode[DanmakuMode["bottom"] = 4] = "bottom";
47
- DanmakuMode[DanmakuMode["top"] = 5] = "top";
48
- DanmakuMode[DanmakuMode["right"] = 6] = "right";
49
- })(DanmakuMode = exports.DanmakuMode || (exports.DanmakuMode = {}));
50
- /** 用户类型 */
51
- var UserType;
52
- (function (UserType) {
53
- /** 普通观众 */
54
- UserType[UserType["normal"] = 0] = "normal";
55
- /** 房管 */
56
- UserType[UserType["admin"] = 1] = "admin";
57
- /** 主播 */
58
- UserType[UserType["anchor"] = 2] = "anchor";
59
- })(UserType = exports.UserType || (exports.UserType = {}));
package/dist/live.d.ts DELETED
@@ -1,39 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from "events";
3
- import { ModPlugin } from "./module/plugin";
4
- import { ModRoom } from "./module/room";
5
- import { ModManifest } from "./module/manifest";
6
- import { ModCommand } from "./module/command";
7
- import { ModValue } from "./module/value";
8
- import { ModHook } from "./module/hook";
9
- import { FloatingEventMap } from "./types/events";
10
- import { ErrorOptions, FloatingCommandMap } from "./types";
11
- export declare class FloatingLive extends EventEmitter {
12
- /** 房间控制模块 */
13
- room: ModRoom;
14
- /** 插件处理模块 */
15
- plugin: ModPlugin;
16
- /** 命令模块 */
17
- command: ModCommand;
18
- /** Manifest模块 */
19
- manifest: ModManifest;
20
- /** 数值模块 */
21
- value: ModValue;
22
- /** 钩子模块 */
23
- hook: ModHook;
24
- constructor();
25
- call<T extends keyof FloatingCommandMap>(name: T, ...args: Parameters<FloatingCommandMap[T]>): ReturnType<FloatingCommandMap[T]>;
26
- on<T extends keyof FloatingEventMap>(eventName: T, listener: FloatingEventMap[T]): this;
27
- emit<T extends keyof FloatingEventMap>(eventName: T, ...args: Parameters<FloatingEventMap[T]>): boolean;
28
- /** 抛出错误 */
29
- throw(err: Error, options?: ErrorOptions): void;
30
- throw(options: ErrorOptions): void;
31
- getSnapshot(): {
32
- room: import("./types").RoomInfo[];
33
- value: Record<string, any>;
34
- manifest: Record<string, Record<string, any>>;
35
- command: string[];
36
- hook: Record<string, number>;
37
- plugin: string[];
38
- };
39
- }
package/dist/live.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FloatingLive = void 0;
4
- const events_1 = require("events");
5
- const plugin_1 = require("./module/plugin");
6
- const room_1 = require("./module/room");
7
- const manifest_1 = require("./module/manifest");
8
- const command_1 = require("./module/command");
9
- const value_1 = require("./module/value");
10
- const hook_1 = require("./module/hook");
11
- class FloatingLive extends events_1.EventEmitter {
12
- constructor() {
13
- super();
14
- this.command = new command_1.ModCommand(this);
15
- this.manifest = new manifest_1.ModManifest(this);
16
- this.plugin = new plugin_1.ModPlugin(this);
17
- this.room = new room_1.ModRoom(this);
18
- this.value = new value_1.ModValue(this);
19
- this.hook = new hook_1.ModHook(this);
20
- }
21
- call(name, ...args) {
22
- return this.command.call(name, ...args);
23
- }
24
- on(eventName, listener) {
25
- return super.on(eventName, listener);
26
- }
27
- emit(eventName, ...args) {
28
- const emit = super.emit(eventName, ...args);
29
- super.emit("event", eventName, ...args);
30
- return emit;
31
- }
32
- throw(err, options) {
33
- if (err instanceof Error) {
34
- throw Object.assign(err, options);
35
- }
36
- else {
37
- throw Object.assign(new Error(), err);
38
- }
39
- }
40
- getSnapshot() {
41
- return {
42
- room: this.room.getSnapshot(),
43
- value: this.value.getSnapshot(),
44
- manifest: this.manifest.getSnapshot(),
45
- command: this.command.getSnapshot(),
46
- hook: this.hook.getSnapshot(),
47
- plugin: this.plugin.getSnapshot(),
48
- };
49
- }
50
- }
51
- exports.FloatingLive = FloatingLive;
@@ -1,18 +0,0 @@
1
- import { FloatingLive } from "../live";
2
- import { FloatingCommandMap } from "../types";
3
- export declare class ModCommand {
4
- /** 功能列表 */
5
- private readonly list;
6
- protected readonly main: FloatingLive;
7
- constructor(main: FloatingLive);
8
- /** 注册命令 */
9
- register<T extends keyof FloatingCommandMap>(name: T, func: FloatingCommandMap[T]): void;
10
- /** 取消注册命令 */
11
- unregister(name: string): void;
12
- /** 调用命令 */
13
- call<T extends keyof FloatingCommandMap>(name: T, ...args: Parameters<FloatingCommandMap[T]>): any;
14
- /** 检测命令是否存在 */
15
- has<T extends keyof FloatingCommandMap>(name: T): boolean;
16
- /** 获取快照 */
17
- getSnapshot(): string[];
18
- }
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModCommand = void 0;
4
- class ModCommand {
5
- constructor(main) {
6
- /** 功能列表 */
7
- this.list = new Map();
8
- this.main = main;
9
- }
10
- /** 注册命令 */
11
- register(name, func) {
12
- this.list.set(name, func);
13
- this.main.emit("command:add", name);
14
- }
15
- /** 取消注册命令 */
16
- unregister(name) {
17
- this.list.delete(name);
18
- this.main.emit("command:remove", name);
19
- }
20
- /** 调用命令 */
21
- call(name, ...args) {
22
- const command = this.list.get(name);
23
- if (!command) {
24
- this.main.throw({
25
- message: "命令不存在",
26
- id: "command:call_unexist",
27
- });
28
- }
29
- else {
30
- return command(...args);
31
- }
32
- }
33
- /** 检测命令是否存在 */
34
- has(name) {
35
- return this.list.has(name);
36
- }
37
- /** 获取快照 */
38
- getSnapshot() {
39
- return [...this.list].map(([key]) => key);
40
- }
41
- }
42
- exports.ModCommand = ModCommand;
@@ -1,15 +0,0 @@
1
- import { FloatingLive } from "../live";
2
- import { FloatingHookMap } from "../types/hook";
3
- export type HookFunction<T> = (ctx: T) => boolean | void | Promise<boolean | void>;
4
- export declare class ModHook {
5
- private list;
6
- protected readonly main: FloatingLive;
7
- constructor(main: FloatingLive);
8
- /** 注册钩子函数 */
9
- register<T extends keyof FloatingHookMap>(name: T, func: HookFunction<FloatingHookMap[T]>): void;
10
- /** 取消注册钩子函数 */
11
- unregister<T extends keyof FloatingHookMap>(name: T, func: HookFunction<FloatingHookMap[T]>): void;
12
- /** 调用钩子函数 */
13
- call<T extends keyof FloatingHookMap>(name: T, ctx: FloatingHookMap[T]): Promise<boolean>;
14
- getSnapshot(): Record<string, number>;
15
- }