TUILiveBattleManager

最近更新时间:2025-10-15 22:10:41

我的收藏
Function: 直播PK相关接口,此页面中的函数仅支持直播房间类型(LIVE)。
TUIRoomEngine 3.3.0 版本开始支持。

TUILiveBattleManager

函数接口
说明
发起 PK 请求,该接口自 v3.3.0 版本支持。
取消 PK 请求,该接口自 v3.3.0 版本支持。
接受 PK 请求,该接口自 v3.3.0 版本支持。
拒绝 PK 请求,该接口自 v3.3.0 版本支持。
结束 PK,该接口自 v3.3.0 版本支持。
on
off
取消订阅 TUILiveBattleManagerEvents 事件

TUILiveBattleManagerEvents

事件接口
说明
接收到 PK 开始的监听事件,该接口自 v3.3.0 版本支持。
接收到 PK 结束的监听事件,该接口自 v3.3.0 版本支持。
接收到用户加入 PK 的监听事件,该接口自 v3.3.0 版本支持。
接收到用户退出 PK 的监听事件,该接口自 v3.3.0 版本支持。
接收到 PK 分数变化的监听事件,该接口自 v3.3.0 版本支持。
接收到 PK 请求的监听事件,该接口自 v3.3.0 版本支持。
接收到 PK 请求取消的监听事件,该接口自 v3.3.0 版本支持。
接收到 PK 请求超时的监听事件,该接口自 v3.3.0 版本支持。
接收到 PK 请求接受的监听事件,该接口自 v3.3.0 版本支持。
接收到 PK 请求被拒绝的监听事件,该接口自 v3.3.0 版本支持。

类型定义

类型
说明
PK 配置参数。
PK 信息。
PK 用户信息。

枚举类型定义

枚举类型
说明
PK 结束原因。

函数接口详情

requestBattle

发起 PK 请求
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.getLiveBattleManager();
const { battleId, result }= liveBattleManager.requestBattle({
config: {duration: 100, needResponse: true},
userIdList: ['userId1'],
timeout: 10
});
参数
类型
是否必填
默认值
说明
options
Object
-
请求 PK 的参数。
options.config
-
发起 PK 的配置信息。
options.userIdList
Array<string>
-
请求 PK 的用户列表。
options.timeout
number
-
PK 请求的超时时间。
返回值:Promise<object>

cancelBattleRequest

取消 PK 请求
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.getLiveBattleManager();
const { battleId, result }= liveBattleManager.cancelBattleRequest({
battleId: 'battleId',
userIdList: ['userId1']
});
参数
类型
是否必填
默认值
说明
options
Object
-
取消 PK 请求的参数。
options.battleId
string
-
取消请求 PK 的 ID。
options.userIdList
Array<string>
-
取消 PK 请求的用户列表。
返回值:Promise<void>

acceptBattle

接受 PK 请求
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.getLiveBattleManager();
const { battleId, result }= liveBattleManager.acceptBattle({
battleId: 'battleId'
});
参数
类型
是否必填
默认值
说明
options
Object
-
接受 PK 的参数。
options.battleId
string
-
接受 PK 的 ID。
返回值:Promise<void>

rejectBattle

拒绝 PK 请求
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.getLiveBattleManager();
const { battleId, result }= liveBattleManager.rejectBattle({
battleId: 'battleId'
});
参数
类型
是否必填
默认值
说明
options
Object
-
拒绝 PK 的参数。
options.battleId
string
-
拒绝 PK 的 ID 。
返回值:Promise<void>

exitBattle

退出 PK
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.getLiveBattleManager();
const { battleId, result }= liveBattleManager.exitBattle({
battleId: 'battleId'
});
参数
类型
是否必填
默认值
说明
options
Object
-
退出 PK 的参数。
options.battleId
string
-
退出 PK 的 ID。
返回值:Promise<void>

on

const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.getLiveBattleManager();
const callback = (battleInfo) => {
console.log('liveBattleManager.onBattleStarted', battleInfo);
};
liveBattleManager.on(TUILiveBattleManagerEvents.onBattleStarted, callback);
参数
类型
是否必填
默认值
说明
eventName
-
事件名。
func
(...args: any[]) => void
-
事件处理函数。

off

取消 TUILiveBattleManagerEvents 事件监听。
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.getLiveBattleManager();
const callback = (battleInfo) => {
console.log('liveBattleManager.onBattleStarted', battleInfo);
};
liveBattleManager.off(TUILiveBattleManagerEvents.onBattleStarted, callback);
参数
类型
是否必填
默认值
说明
eventName
-
事件名。
func
(...args: any[]) => void
-
事件处理函数。

事件接口详情

onBattleStarted

接收到 PK 开始的监听事件。
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.TUILiveBattleManager();
liveBattleManager.on(TUILiveBattleManagerEvents.onBattleStarted, ({ battleInfo }) => {
console.log('liveBattleManager.onBattleStarted', battleInfo);
});
参数
类型
说明
options
Object
参数选项。
options.battleInfo
PK 信息。

onBattleEnded

接收到 PK 结束的监听事件。
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.TUILiveBattleManager();
liveBattleManager.on(TUILiveBattleManagerEvents.onBattleEnded, ({ battleInfo, reason }) => {
console.log('liveBattleManager.onBattleEnded', battleInfo, reason);
});
参数
类型
说明
options
Object
参数选项。
options.battleInfo
PK 的信息。
options.reason
PK 结束原因。

onUserJoinBattle

接收到用户加入 PK 的监听事件。
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.TUILiveBattleManager();
liveBattleManager.on(TUILiveBattleManagerEvents.onUserJoinBattle, ({ battleId, user }) => {
console.log('liveBattleManager.onUserJoinBattle', battleId, user);
});
参数
类型
说明
options
Object
参数选项。
options.battleId
string
PK 的 ID。
options.user
加入到 PK 的用户信息。

onUserExitBattle

接收到用户退出 PK 的监听事件。
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.TUILiveBattleManager();
liveBattleManager.on(TUILiveBattleManagerEvents.onUserExitBattle, ({ battleId, user }) => {
console.log('liveBattleManager.onUserExitBattle', battleId, user);
});
参数
类型
说明
options
Object
参数选项。
options.battleId
string
PK 的 ID。
options.user
加入到 PK 的用户信息。

onBattleScoreChanged

接收到 PK 分数变化的监听事件。
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.TUILiveBattleManager();
liveBattleManager.on(TUILiveBattleManagerEvents.onBattleScoreChanged, ({ battleId, battleUserList }) => {
console.log('liveBattleManager.onBattleScoreChanged', battleId, battleUserList);
});
参数
类型
说明
options
Object
参数选项。
options.battleId
string
PK 的 ID。
options.battleUserList
PK 用户信息列表。

onBattleRequestReceived

接收 PK 请求的监听事件。
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.TUILiveBattleManager();
liveBattleManager.on(TUILiveBattleManagerEvents.onBattleRequestReceived, ({ battleInfo, inviter, invitee }) => {
console.log('liveBattleManager.onBattleRequestReceived', battleInfo, inviter, invitee);
});
参数
类型
说明
options
Object
参数选项。
options.battleInfo
PK 信息。
options.inviter
发起 PK 请求的用户。
options.invitee
接收 PK 请求的用户。

onBattleRequestCancelled

接收 PK 请求取消的监听事件。
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.TUILiveBattleManager();
liveBattleManager.on(TUILiveBattleManagerEvents.onBattleRequestCancelled, ({ battleInfo, inviter, invitee }) => {
console.log('liveBattleManager.onBattleRequestCancelled', battleInfo, inviter, invitee);
});
参数
类型
说明
options
Object
参数选项。
options.battleInfo
PK 信息。
options.inviter
发起 PK 请求的用户。
options.invitee
接收 PK 请求的用户。

onBattleRequestTimeout

接收 PK 请求超时的监听事件。
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.TUILiveBattleManager();
liveBattleManager.on(TUILiveBattleManagerEvents.onBattleRequestTimeout, ({ battleInfo, inviter, invitee }) => {
console.log('liveBattleManager.onBattleRequestTimeout', battleInfo, inviter, invitee);
});
参数
类型
说明
options
Object
参数选项。
options.battleInfo
PK 信息。
options.inviter
发起 PK 请求的用户
options.invitee
接收 PK 请求的用户

onBattleRequestAccept

接收 PK 请求被接受的监听事件。
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.TUILiveBattleManager();
liveBattleManager.on(TUILiveBattleManagerEvents.onBattleRequestAccept, ({ battleInfo, inviter, invitee }) => {
console.log('liveBattleManager.onBattleRequestAccept', battleInfo, inviter, invitee);
});
参数
类型
说明
options
Object
参数选项。
options.battleInfo
PK 信息。
options.inviter
发起 PK 请求的用户。
options.invitee
接收 PK 请求的用户。

onBattleRequestReject

接收 PK 请求被拒绝的监听事件。
const roomEngine = new TUIRoomEngine();
const liveBattleManager = roomEngine.TUILiveBattleManager();
liveBattleManager.on(TUILiveBattleManagerEvents.onBattleRequestReject, ({ battleInfo, inviter, invitee }) => {
console.log('liveBattleManager.onBattleRequestReject', battleInfo, inviter, invitee);
});
参数
类型
说明
options
Object
参数选项。
options.battleInfo
PK 信息。
options.inviter
发起 PK 请求的用户。
options.invitee
接收 PK 请求的用户。

类型定义详情

TUIBattleConfig

属性
类型
说明
duration
number
PK 时长。
needResponse
boolean
是否需要回应,默认为 false。
extensionInfo
string
扩展信息,默认为‘’。

TUIBattleInfo

属性
类型
说明
fromUser
发起 PK 的用户信息。
toUserList
被邀请 PK 的用户列表。
extensionInfo
string
扩展信息。
battleId
string
PK 的 ID。
needResponse
boolean
是否需要响应。
duration
number
PK 时长。
startTime
number
PK 开始的时间戳。
endTime
number
PK 结束的时间戳。

TUIBattleUser

属性
类型
说明
roomId
string
房间ID。
userId
string
用户ID。
userName
string
用户名称。
avatarUrl
string
用户头像 URL。
score
number
PK 分数。

枚举定义详情

TUIBattleStoppedReason

字段
类型
说明
kStoppedByTimeOver
number
PK 因时间结束而停止。
kStoppedByOtherExit
number
PK 因其他用户退出而停止。