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