floating-live 0.16.0-alpha.11 → 0.16.0-alpha.13
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/live/room.d.ts +31 -7
- package/dist/live/room.js +3 -13
- package/dist/plugins/room/index.d.ts +2 -2
- package/dist/plugins/room/index.js +9 -11
- package/package.json +1 -1
package/dist/live/room.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { CustomEventEmitter } from "../utils/EventEmitter";
|
|
|
2
2
|
import { EnumValue } from "../utils/types";
|
|
3
3
|
import { LiveMessage } from "./message";
|
|
4
4
|
import { UserInfo } from "./messageInfo";
|
|
5
|
+
/** 直播间客户端API */
|
|
5
6
|
export declare abstract class LiveRoom extends CustomEventEmitter implements LiveRoomData {
|
|
6
7
|
constructor();
|
|
7
8
|
/** 平台 */
|
|
@@ -25,25 +26,31 @@ export declare abstract class LiveRoom extends CustomEventEmitter implements Liv
|
|
|
25
26
|
/** 房间连接状态 */
|
|
26
27
|
connection: LiveConnectionStatus;
|
|
27
28
|
/** 房间是否可用 */
|
|
28
|
-
|
|
29
|
+
available: boolean;
|
|
29
30
|
/** 打开连接 */
|
|
30
31
|
abstract open(): void;
|
|
31
32
|
/** 关闭连接 */
|
|
32
33
|
abstract close(): void;
|
|
33
|
-
/**
|
|
34
|
-
abstract
|
|
35
|
-
/**
|
|
36
|
-
|
|
34
|
+
/** 更新房间数据 */
|
|
35
|
+
abstract update(): Promise<LiveRoomData>;
|
|
36
|
+
/** 从服务器获取房间数据 */
|
|
37
|
+
abstract fetchData?(): Promise<LiveRoomData>;
|
|
38
|
+
/** 设置房间数据 */
|
|
39
|
+
abstract setData?(data: LiveRoomData): LiveRoomData;
|
|
37
40
|
/** 销毁 */
|
|
38
41
|
destroy(): void;
|
|
42
|
+
/** 销毁事件 */
|
|
43
|
+
protected onDestroy?: () => void;
|
|
39
44
|
protected emitMessage(msg: LiveMessage.All): void;
|
|
40
45
|
/** 发送源消息 */
|
|
41
46
|
protected emitRaw(msg: any): void;
|
|
42
47
|
/** 获取数据 */
|
|
43
48
|
toData(): LiveRoomData;
|
|
44
49
|
get key(): string;
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
}
|
|
51
|
+
export interface LiveRoom {
|
|
52
|
+
on<K extends keyof LiveRoomEventMap>(type: K, listener: (e: LiveRoomEventMap[K]) => void, signal?: AbortSignal): void;
|
|
53
|
+
once<K extends keyof LiveRoomEventMap>(type: K, listener: (e: LiveRoomEventMap[K]) => void, signal?: AbortSignal): void;
|
|
47
54
|
off<K extends keyof LiveRoomEventMap>(type: K, listener: (e: LiveRoomEventMap[K]) => void): void;
|
|
48
55
|
emit<K extends keyof LiveRoomEventMap>(type: LiveRoomEventMap[K] extends Record<string, never> ? K : never): void;
|
|
49
56
|
emit<K extends keyof LiveRoomEventMap>(type: K, detail: LiveRoomEventMap[K]): void;
|
|
@@ -124,33 +131,50 @@ export declare const LiveConnectionStatus: {
|
|
|
124
131
|
};
|
|
125
132
|
export type LiveConnectionStatus = EnumValue<typeof LiveConnectionStatus>;
|
|
126
133
|
export interface LiveRoomEventMap {
|
|
134
|
+
/** */
|
|
127
135
|
status: {
|
|
128
136
|
status: LiveRoomStatus;
|
|
129
137
|
timestamp: number;
|
|
130
138
|
liveId?: string | number;
|
|
131
139
|
};
|
|
140
|
+
/** 房间数据更新 */
|
|
132
141
|
update: {
|
|
133
142
|
room: LiveRoomData;
|
|
134
143
|
};
|
|
144
|
+
/** 细节改变 */
|
|
135
145
|
detail: {
|
|
136
146
|
detail: Partial<LiveRoomDetailInfo>;
|
|
137
147
|
};
|
|
148
|
+
/** 统计信息改变 */
|
|
138
149
|
stats: {
|
|
139
150
|
stats: Partial<LiveRoomStatsInfo>;
|
|
140
151
|
};
|
|
152
|
+
/** 消息 */
|
|
141
153
|
message: {
|
|
142
154
|
message: LiveMessage.All;
|
|
143
155
|
};
|
|
156
|
+
/** 消息源数据 */
|
|
144
157
|
raw: {
|
|
145
158
|
platform: string;
|
|
146
159
|
roomId: string | number;
|
|
147
160
|
data: any;
|
|
148
161
|
};
|
|
162
|
+
/** 初始化 */
|
|
149
163
|
init: {};
|
|
164
|
+
/** 正在连接 */
|
|
150
165
|
connecting: {};
|
|
166
|
+
/** 连接到服务器 */
|
|
151
167
|
connected: {};
|
|
168
|
+
/** 断开连接 */
|
|
152
169
|
disconnect: {};
|
|
170
|
+
/** 连接到房间 */
|
|
153
171
|
enter: {};
|
|
172
|
+
/** 连接超时 */
|
|
173
|
+
timeout: {
|
|
174
|
+
time: number;
|
|
175
|
+
};
|
|
176
|
+
/** 开启直播间连接 */
|
|
154
177
|
open: {};
|
|
178
|
+
/** 关闭直播间连接 */
|
|
155
179
|
close: {};
|
|
156
180
|
}
|
package/dist/live/room.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CustomEventEmitter } from "../utils/EventEmitter";
|
|
2
|
+
/** 直播间客户端API */
|
|
2
3
|
export class LiveRoom extends CustomEventEmitter {
|
|
3
4
|
constructor() {
|
|
4
5
|
super();
|
|
@@ -10,6 +11,8 @@ export class LiveRoom extends CustomEventEmitter {
|
|
|
10
11
|
this.opened = false;
|
|
11
12
|
/** 房间连接状态 */
|
|
12
13
|
this.connection = LiveConnectionStatus.off;
|
|
14
|
+
/** 房间是否可用 */
|
|
15
|
+
this.available = false;
|
|
13
16
|
}
|
|
14
17
|
/** 销毁 */
|
|
15
18
|
destroy() {
|
|
@@ -76,19 +79,6 @@ export class LiveRoom extends CustomEventEmitter {
|
|
|
76
79
|
get key() {
|
|
77
80
|
return `${this.platform}:${this.id}`;
|
|
78
81
|
}
|
|
79
|
-
on(type, listener) {
|
|
80
|
-
super.on(type, listener);
|
|
81
|
-
}
|
|
82
|
-
once(type, listener) {
|
|
83
|
-
super.once(type, listener);
|
|
84
|
-
this.emit("connecting");
|
|
85
|
-
}
|
|
86
|
-
off(type, listener) {
|
|
87
|
-
super.off(type, listener);
|
|
88
|
-
}
|
|
89
|
-
emit(type, detail) {
|
|
90
|
-
super.emit(type, detail);
|
|
91
|
-
}
|
|
92
82
|
}
|
|
93
83
|
/** 直播间状态 */
|
|
94
84
|
export const LiveRoomStatus = {
|
|
@@ -101,11 +101,11 @@ declare module "../.." {
|
|
|
101
101
|
export declare class Room extends BasePlugin {
|
|
102
102
|
static pluginName: string;
|
|
103
103
|
private map;
|
|
104
|
-
private
|
|
104
|
+
private symbolAbortController;
|
|
105
105
|
init(ctx: PluginContext): void;
|
|
106
106
|
expose(): PluginExposes;
|
|
107
107
|
/** 添加房间监听实例 */
|
|
108
|
-
|
|
108
|
+
attach(room: LiveRoom, open?: boolean): void;
|
|
109
109
|
/** 添加房间 */
|
|
110
110
|
add(platform: string, id: number, options?: boolean | Record<string, any>): Promise<void>;
|
|
111
111
|
/** 移除房间 */
|
|
@@ -5,7 +5,7 @@ export class Room extends BasePlugin {
|
|
|
5
5
|
constructor() {
|
|
6
6
|
super(...arguments);
|
|
7
7
|
this.map = new Map();
|
|
8
|
-
this.
|
|
8
|
+
this.symbolAbortController = Symbol("room.abortController");
|
|
9
9
|
}
|
|
10
10
|
init(ctx) {
|
|
11
11
|
ctx.registerCommand("add", bindCommand(this.add, this));
|
|
@@ -29,7 +29,7 @@ export class Room extends BasePlugin {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
/** 添加房间监听实例 */
|
|
32
|
-
|
|
32
|
+
attach(room, open) {
|
|
33
33
|
let key = room.key;
|
|
34
34
|
if (this.map.has(key)) {
|
|
35
35
|
this.ctx.throw(new AppError("room:add_exist", {
|
|
@@ -38,11 +38,11 @@ export class Room extends BasePlugin {
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
this.map.set(key, room);
|
|
41
|
-
const
|
|
42
|
-
room[this.
|
|
41
|
+
const abortController = new AbortController();
|
|
42
|
+
room[this.symbolAbortController] =
|
|
43
|
+
abortController;
|
|
43
44
|
const setHandler = (type, listener) => {
|
|
44
|
-
room.on(type, listener);
|
|
45
|
-
eventHandlers.push([type, listener]);
|
|
45
|
+
room.on(type, listener, abortController.signal);
|
|
46
46
|
};
|
|
47
47
|
// 添加监听事件
|
|
48
48
|
// 直播消息
|
|
@@ -115,7 +115,7 @@ export class Room extends BasePlugin {
|
|
|
115
115
|
this.ctx.throw(this.ctx.error("room:create_fail", { message: "无法创建房间" }));
|
|
116
116
|
}
|
|
117
117
|
else {
|
|
118
|
-
this.
|
|
118
|
+
this.attach(room);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
/** 移除房间 */
|
|
@@ -127,9 +127,7 @@ export class Room extends BasePlugin {
|
|
|
127
127
|
}));
|
|
128
128
|
}
|
|
129
129
|
this.map.delete(key); // 从表中删除房间
|
|
130
|
-
room[this.
|
|
131
|
-
room?.removeEventListener(type, listener);
|
|
132
|
-
}); // 移除房间监听实例
|
|
130
|
+
room[this.symbolAbortController]?.abort(); // 移除房间监听实例
|
|
133
131
|
this.ctx.emit("room:remove", { key });
|
|
134
132
|
}
|
|
135
133
|
/** 获取房间 */
|
|
@@ -147,7 +145,7 @@ export class Room extends BasePlugin {
|
|
|
147
145
|
/** 更新房间信息 */
|
|
148
146
|
update(key) {
|
|
149
147
|
let room = this.map.get(key);
|
|
150
|
-
room && room.
|
|
148
|
+
room && room.update();
|
|
151
149
|
}
|
|
152
150
|
/** 获取房间key列表 */
|
|
153
151
|
get keys() {
|