floating-live 0.16.0-alpha.11 → 0.16.0-alpha.12
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 +28 -6
- package/dist/live/room.js +1 -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
|
/** 平台 */
|
|
@@ -30,20 +31,24 @@ export declare abstract class LiveRoom extends CustomEventEmitter implements Liv
|
|
|
30
31
|
abstract open(): void;
|
|
31
32
|
/** 关闭连接 */
|
|
32
33
|
abstract close(): void;
|
|
33
|
-
/**
|
|
34
|
-
abstract
|
|
35
|
-
/**
|
|
36
|
-
|
|
34
|
+
/** 更新房间数据 */
|
|
35
|
+
abstract update(): Promise<void>;
|
|
36
|
+
/** 从服务器获取房间数据 */
|
|
37
|
+
abstract fetchData?(): Promise<void>;
|
|
37
38
|
/** 销毁 */
|
|
38
39
|
destroy(): void;
|
|
40
|
+
/** 销毁事件 */
|
|
41
|
+
protected onDestroy?: () => void;
|
|
39
42
|
protected emitMessage(msg: LiveMessage.All): void;
|
|
40
43
|
/** 发送源消息 */
|
|
41
44
|
protected emitRaw(msg: any): void;
|
|
42
45
|
/** 获取数据 */
|
|
43
46
|
toData(): LiveRoomData;
|
|
44
47
|
get key(): string;
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
}
|
|
49
|
+
export interface LiveRoom {
|
|
50
|
+
on<K extends keyof LiveRoomEventMap>(type: K, listener: (e: LiveRoomEventMap[K]) => void, signal?: AbortSignal): void;
|
|
51
|
+
once<K extends keyof LiveRoomEventMap>(type: K, listener: (e: LiveRoomEventMap[K]) => void, signal?: AbortSignal): void;
|
|
47
52
|
off<K extends keyof LiveRoomEventMap>(type: K, listener: (e: LiveRoomEventMap[K]) => void): void;
|
|
48
53
|
emit<K extends keyof LiveRoomEventMap>(type: LiveRoomEventMap[K] extends Record<string, never> ? K : never): void;
|
|
49
54
|
emit<K extends keyof LiveRoomEventMap>(type: K, detail: LiveRoomEventMap[K]): void;
|
|
@@ -124,33 +129,50 @@ export declare const LiveConnectionStatus: {
|
|
|
124
129
|
};
|
|
125
130
|
export type LiveConnectionStatus = EnumValue<typeof LiveConnectionStatus>;
|
|
126
131
|
export interface LiveRoomEventMap {
|
|
132
|
+
/** */
|
|
127
133
|
status: {
|
|
128
134
|
status: LiveRoomStatus;
|
|
129
135
|
timestamp: number;
|
|
130
136
|
liveId?: string | number;
|
|
131
137
|
};
|
|
138
|
+
/** 房间数据更新 */
|
|
132
139
|
update: {
|
|
133
140
|
room: LiveRoomData;
|
|
134
141
|
};
|
|
142
|
+
/** 细节改变 */
|
|
135
143
|
detail: {
|
|
136
144
|
detail: Partial<LiveRoomDetailInfo>;
|
|
137
145
|
};
|
|
146
|
+
/** 统计信息改变 */
|
|
138
147
|
stats: {
|
|
139
148
|
stats: Partial<LiveRoomStatsInfo>;
|
|
140
149
|
};
|
|
150
|
+
/** 消息 */
|
|
141
151
|
message: {
|
|
142
152
|
message: LiveMessage.All;
|
|
143
153
|
};
|
|
154
|
+
/** 消息源数据 */
|
|
144
155
|
raw: {
|
|
145
156
|
platform: string;
|
|
146
157
|
roomId: string | number;
|
|
147
158
|
data: any;
|
|
148
159
|
};
|
|
160
|
+
/** 初始化 */
|
|
149
161
|
init: {};
|
|
162
|
+
/** 正在连接 */
|
|
150
163
|
connecting: {};
|
|
164
|
+
/** 连接到服务器 */
|
|
151
165
|
connected: {};
|
|
166
|
+
/** 断开连接 */
|
|
152
167
|
disconnect: {};
|
|
168
|
+
/** 连接到房间 */
|
|
153
169
|
enter: {};
|
|
170
|
+
/** 连接超时 */
|
|
171
|
+
timeout: {
|
|
172
|
+
time: number;
|
|
173
|
+
};
|
|
174
|
+
/** 开启直播间连接 */
|
|
154
175
|
open: {};
|
|
176
|
+
/** 关闭直播间连接 */
|
|
155
177
|
close: {};
|
|
156
178
|
}
|
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();
|
|
@@ -76,19 +77,6 @@ export class LiveRoom extends CustomEventEmitter {
|
|
|
76
77
|
get key() {
|
|
77
78
|
return `${this.platform}:${this.id}`;
|
|
78
79
|
}
|
|
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
80
|
}
|
|
93
81
|
/** 直播间状态 */
|
|
94
82
|
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() {
|