floating-live 0.15.11 → 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 -85
  81. package/dist/module/room.d.ts +0 -34
  82. package/dist/module/room.js +0 -164
  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 -81
  116. package/esm/module/room.js +0 -160
  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
@@ -1,160 +0,0 @@
1
- /** 直播间监听实例控制器 */
2
- export class ModRoom {
3
- constructor(main) {
4
- this.map = new Map();
5
- this.main = main;
6
- const { command } = main;
7
- command.register("add", this.add.bind(this));
8
- command.register("remove", this.remove.bind(this));
9
- command.register("open", this.open.bind(this));
10
- command.register("close", this.close.bind(this));
11
- command.register("update", this.update.bind(this));
12
- }
13
- /** 添加房间监听实例 */
14
- addRoom(room, open) {
15
- let key = room.key;
16
- if (this.map.has(key)) {
17
- this.main.throw({
18
- message: "房间已存在",
19
- id: "room:add_exist",
20
- });
21
- return;
22
- }
23
- this.map.set(key, room);
24
- // 添加监听事件
25
- // 直播消息
26
- room.on("message", (data) => {
27
- const ctx = { message: data };
28
- this.main.hook.call("message", { message: data }).then((res) => {
29
- res && this.main.emit("live:message", ctx.message);
30
- });
31
- });
32
- // 直播消息源数据
33
- room.on("raw", (data, { platform, room }) => {
34
- this.main.emit("live:raw", data, { platform, room });
35
- });
36
- // 正在连接服务器
37
- room.on("connecting", () => {
38
- this.main.emit("room:connecting", key);
39
- });
40
- // 连接到服务器
41
- room.on("connected", () => {
42
- this.main.emit("room:connected", key);
43
- });
44
- // 与服务器的连接已断开
45
- room.on("disconnect", () => {
46
- this.main.emit("room:disconnect", key);
47
- });
48
- // 连接到直播间
49
- room.on("enter", () => {
50
- this.main.emit("room:enter", key);
51
- });
52
- // 获取房间信息
53
- room.on("info", () => {
54
- this.main.emit("room:info", key, room.info);
55
- });
56
- // 直播展示信息更改
57
- room.on("detail", (data) => {
58
- this.main.emit("room:detail", key, data);
59
- });
60
- // 直播状态更改
61
- room.on("status", (status, { id, timestamp }) => {
62
- this.main.emit("room:status", key, { status, id, timestamp });
63
- });
64
- // 统计数据更新
65
- room.on("stats", (data) => {
66
- this.main.emit("room:stats", key, data);
67
- });
68
- // 房间被打开
69
- room.on("open", () => {
70
- this.main.emit("room:open", key, room.info);
71
- });
72
- // 房间被关闭
73
- room.on("close", () => {
74
- this.main.emit("room:close", key, room.info);
75
- });
76
- if (open) {
77
- room.open();
78
- }
79
- this.main.emit("room:add", key, room.info);
80
- }
81
- /** 添加房间 */
82
- async add(platform, id, options) {
83
- const opt = typeof options == "boolean" ? { open: options } : options || {};
84
- const ctx = { platform, id, options: opt };
85
- const res = await this.main.hook.call("room.add", ctx);
86
- if (!res) {
87
- this.main.throw({ message: "无法添加房间", id: "room:add_fail" });
88
- }
89
- const room = await this.main.call(`${platform}.room.create`, id, opt);
90
- if (!room) {
91
- this.main.throw({ message: "无法创建房间", id: "room:create_fail" });
92
- }
93
- else {
94
- this.addRoom(room);
95
- }
96
- }
97
- /** 移除房间 */
98
- remove(key) {
99
- let room = this.map.get(key);
100
- if (!room) {
101
- this.main.throw({
102
- message: "房间不存在",
103
- id: "room:remove_unexist",
104
- });
105
- }
106
- this.map.delete(key); // 从表中删除房间
107
- room?.removeAllListeners(); // 移除房间监听实例
108
- this.main.emit("room:remove", key);
109
- }
110
- /** 获取房间 */
111
- get(key) {
112
- return this.map.get(key);
113
- }
114
- has(key) {
115
- return this.map.has(key);
116
- }
117
- /** 获取房间信息 */
118
- info(key) {
119
- let room = this.map.get(key);
120
- return room ? room.info : undefined;
121
- }
122
- /** 更新房间信息 */
123
- update(key) {
124
- let room = this.map.get(key);
125
- room && room.getInfo();
126
- }
127
- /** 获取房间key列表 */
128
- get keys() {
129
- return [...this.map.keys()];
130
- }
131
- /** 获取房间列表 */
132
- getList() {
133
- return [...this.map.values()];
134
- }
135
- /** 打开房间连接 */
136
- open(key) {
137
- let room = this.map.get(key);
138
- room?.available && !room.opened && room.open();
139
- }
140
- /** 关闭房间连接 */
141
- close(key) {
142
- let room = this.map.get(key);
143
- room?.opened && room.close();
144
- }
145
- /** 更改某个房间的顺序 */
146
- move(key, position) {
147
- const arr = [...this.map];
148
- const index = arr.findIndex(([k]) => k == key);
149
- if (index == -1)
150
- return;
151
- const [item] = arr.splice(index, 1);
152
- arr.splice(position, 0, item);
153
- this.map = new Map(arr);
154
- this.main.emit("room:move", key, position);
155
- }
156
- /** 获取快照 */
157
- getSnapshot() {
158
- return this.getList().map((room) => room.info);
159
- }
160
- }
@@ -1,56 +0,0 @@
1
- export class ModValue {
2
- constructor(main) {
3
- this.list = new Map();
4
- this.main = main;
5
- const { command } = main;
6
- command.register("get", this.get.bind(this));
7
- command.register("set", this.set.bind(this));
8
- }
9
- /** 注册值 */
10
- register(name, config) {
11
- this.list.set(name, config);
12
- this.main.emit("value:add", name);
13
- this.main.emit("value:change", name, config.get());
14
- }
15
- /** 取消注册 */
16
- unregister(name) {
17
- this.list.delete(name);
18
- this.main.emit("value:remove", name);
19
- }
20
- /** 获取值 */
21
- get(name) {
22
- return this.list.get(name)?.get();
23
- }
24
- /** 设置值 */
25
- set(name, value) {
26
- const valueConfig = this.list.get(name);
27
- if (valueConfig?.set) {
28
- valueConfig?.set(value);
29
- return true;
30
- }
31
- else {
32
- return false;
33
- }
34
- }
35
- has(name) {
36
- return this.list.has(name);
37
- }
38
- emit(name, value) {
39
- this.main.emit(`change:${name}`, value);
40
- this.main.emit("value:change", name, value);
41
- }
42
- watch(name, listener) {
43
- this.main.on(`change:${name}`, listener);
44
- }
45
- unwatch(name, listener) {
46
- this.main.off(`change:${name}`, listener);
47
- }
48
- /** 获取注册的所有值 */
49
- getSnapshot() {
50
- const map = {};
51
- this.list.forEach((config, name) => {
52
- map[name] = config.get();
53
- });
54
- return map;
55
- }
56
- }
@@ -1,9 +0,0 @@
1
- export * from "./message";
2
- export * from "./plugin";
3
- export * from "./room";
4
- export * from "./command";
5
- export * from "./events";
6
- export * from "./manifest";
7
- export * from "./hook";
8
- export * from "./value";
9
- export * from "./error";
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
package/esm/types/room.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
package/esm/utils.js DELETED
@@ -1,17 +0,0 @@
1
- export function generateId(msg) {
2
- switch (msg.type) {
3
- case "gift":
4
- return `gift:${msg.info.user.id}-${msg.timestamp}`;
5
- case "superchat":
6
- return `superchat:${msg.info.id}`;
7
- case "membership":
8
- return `membership:${msg.info.user.id}-${msg.info.level || 0}-${msg.timestamp}`;
9
- default:
10
- if (/^live_/.test(msg.type)) {
11
- return `${msg.type}:${msg.platform}:${msg.room}-${msg.timestamp}`;
12
- }
13
- else {
14
- return `${msg.type}:${msg.info.user?.id || 0}-${msg.timestamp}`;
15
- }
16
- }
17
- }