floating-live 0.16.0-alpha.12 → 0.16.0-alpha.14
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 +14 -9
- package/dist/live/room.js +4 -2
- package/dist/plugins/room/index.js +5 -2
- package/package.json +1 -1
package/dist/live/room.d.ts
CHANGED
|
@@ -26,23 +26,28 @@ export declare abstract class LiveRoom extends CustomEventEmitter implements Liv
|
|
|
26
26
|
/** 房间连接状态 */
|
|
27
27
|
connection: LiveConnectionStatus;
|
|
28
28
|
/** 房间是否可用 */
|
|
29
|
-
|
|
29
|
+
available: boolean;
|
|
30
30
|
/** 打开连接 */
|
|
31
31
|
abstract open(): void;
|
|
32
32
|
/** 关闭连接 */
|
|
33
33
|
abstract close(): void;
|
|
34
|
+
/** 重连 */
|
|
35
|
+
abstract reconnect?(): void;
|
|
34
36
|
/** 更新房间数据 */
|
|
35
|
-
abstract update(): Promise<
|
|
37
|
+
abstract update(): Promise<LiveRoomData>;
|
|
36
38
|
/** 从服务器获取房间数据 */
|
|
37
|
-
abstract fetchData?(): Promise<
|
|
39
|
+
abstract fetchData?(): Promise<LiveRoomData>;
|
|
40
|
+
/** 设置房间数据 */
|
|
41
|
+
abstract setData?(data: LiveRoomData): LiveRoomData;
|
|
38
42
|
/** 销毁 */
|
|
39
43
|
destroy(): void;
|
|
40
44
|
/** 销毁事件 */
|
|
41
45
|
protected onDestroy?: () => void;
|
|
46
|
+
/** 发送消息 */
|
|
42
47
|
protected emitMessage(msg: LiveMessage.All): void;
|
|
43
48
|
/** 发送源消息 */
|
|
44
49
|
protected emitRaw(msg: any): void;
|
|
45
|
-
/**
|
|
50
|
+
/** 生成房间数据 */
|
|
46
51
|
toData(): LiveRoomData;
|
|
47
52
|
get key(): string;
|
|
48
53
|
}
|
|
@@ -117,15 +122,15 @@ export type LiveRoomStatus = EnumValue<typeof LiveRoomStatus>;
|
|
|
117
122
|
/** 直播间状态 */
|
|
118
123
|
export declare const LiveConnectionStatus: {
|
|
119
124
|
/** 未连接 */
|
|
120
|
-
off:
|
|
125
|
+
readonly off: 0;
|
|
121
126
|
/** 连接中 */
|
|
122
|
-
connecting:
|
|
127
|
+
readonly connecting: 1;
|
|
123
128
|
/** 连接到服务器 */
|
|
124
|
-
connected:
|
|
129
|
+
readonly connected: 2;
|
|
125
130
|
/** 连接到房间 */
|
|
126
|
-
entered:
|
|
131
|
+
readonly entered: 3;
|
|
127
132
|
/** 连接失败或断开 */
|
|
128
|
-
disconnected:
|
|
133
|
+
readonly disconnected: -1;
|
|
129
134
|
};
|
|
130
135
|
export type LiveConnectionStatus = EnumValue<typeof LiveConnectionStatus>;
|
|
131
136
|
export interface LiveRoomEventMap {
|
package/dist/live/room.js
CHANGED
|
@@ -11,13 +11,15 @@ export class LiveRoom extends CustomEventEmitter {
|
|
|
11
11
|
this.opened = false;
|
|
12
12
|
/** 房间连接状态 */
|
|
13
13
|
this.connection = LiveConnectionStatus.off;
|
|
14
|
+
/** 房间是否可用 */
|
|
15
|
+
this.available = false;
|
|
14
16
|
}
|
|
15
17
|
/** 销毁 */
|
|
16
18
|
destroy() {
|
|
17
19
|
this.close();
|
|
18
20
|
this.onDestroy?.();
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
/** 发送消息 */
|
|
21
23
|
emitMessage(msg) {
|
|
22
24
|
// 其他消息 => 先更改状态再发送消息
|
|
23
25
|
// 直播结束消息 => 先发送消息再更改状态
|
|
@@ -57,7 +59,7 @@ export class LiveRoom extends CustomEventEmitter {
|
|
|
57
59
|
emitRaw(msg) {
|
|
58
60
|
this.emit("raw", { platform: this.platform, roomId: this.id, data: msg });
|
|
59
61
|
}
|
|
60
|
-
/**
|
|
62
|
+
/** 生成房间数据 */
|
|
61
63
|
toData() {
|
|
62
64
|
return {
|
|
63
65
|
platform: this.platform,
|
|
@@ -107,8 +107,11 @@ export class Room extends BasePlugin {
|
|
|
107
107
|
const opt = typeof options == "boolean" ? { open: options } : options || {};
|
|
108
108
|
const ctx = { platform, id, options: opt };
|
|
109
109
|
const res = await this.ctx.callHook("room.add", ctx);
|
|
110
|
-
if (
|
|
111
|
-
this.ctx.throw(this.ctx.error("room:
|
|
110
|
+
if (res.defaultPrevented) {
|
|
111
|
+
this.ctx.throw(this.ctx.error("room:add_hook_prevented", {
|
|
112
|
+
message: "无法添加房间",
|
|
113
|
+
cause: "房间添加被钩子函数阻止",
|
|
114
|
+
}));
|
|
112
115
|
}
|
|
113
116
|
const room = await this.ctx.call(`${platform}.room.create`, id, opt);
|
|
114
117
|
if (!room) {
|