TUILiveBattleManager
Live PK APIs. Functions on this page only support the live room type (LIVE).
TUIRoomEngine 3.3.0 starts support.
TUILiveBattleManager
Function API | Description |
Initiate a PK request. This API is supported since v3.3.0. | |
Cancel a PK request. This API is supported since v3.3.0. | |
Accept a PK request. This API is supported since v3.3.0. | |
Deny a PK request. This API is supported since v3.3.0. | |
End PK. This API is supported since v3.3.0. | |
TUILiveBattleManagerEvents
Event API | Description |
Receiving the PK start monitoring event. This API is supported since v3.3.0. | |
Receiving the PK end monitoring event. This API is supported since v3.3.0. | |
Receiving the user joined PK monitoring event. This API is supported since v3.3.0. | |
Receiving the user logout PK monitoring event. This API is supported since v3.3.0. | |
Receiving the PK score adjustment monitoring event. This API is supported since v3.3.0. | |
Receiving the PK request monitoring event. This API is supported since v3.3.0. | |
Receiving the PK request cancellation monitoring event. This API is supported since v3.3.0. | |
Receiving the PK request timeout monitoring event. This API is supported since v3.3.0. | |
Receiving the PK request acceptance monitoring event. This API is supported since v3.3.0. | |
Receiving the PK request rejected monitoring event. This API is supported since v3.3.0. |
Type Definition
Type | Description |
PK config | |
PK info | |
PK user information |
Enum Type Definition
Enum Type | Description |
End PK Reason |
Function API Description
requestBattle
Battle request
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.getLiveBattleManager();const { battleId, result }= liveBattleManager.requestBattle({config: {duration: 100, needResponse: true},userIdList: ['userId1'],timeout: 10});
Parameter | Type | Required or Not | Default Value | Description |
options | Object | Yes | - | Request PK parameters. |
options.config | Yes | - | Trigger PK configuration message. | |
options.userIdList | Array<string> | Yes | - | List of users requesting PK. |
options.timeout | number | Yes | - | PK request timeout. |
Return value: Promise<object>
cancelBattleRequest
Cancel battle request
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.getLiveBattleManager();const { battleId, result }= liveBattleManager.cancelBattleRequest({battleId: 'battleId',userIdList: ['userId1']});
Parameter | Type | Required or Not | Default Value | Description |
options | Object | Yes | - | Cancel PK request parameters. |
options.battleId | string | Yes | - | Cancel the PK request ID. |
options.userIdList | Array<string> | Yes | - | Cancel the PK request user list. |
Return value: Promise<void>
acceptBattle
Accept PK request
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.getLiveBattleManager();const { battleId, result }= liveBattleManager.acceptBattle({battleId: 'battleId'});
Parameter | Type | Required or Not | Default Value | Description |
options | Object | Yes | - | Accept PK parameters. |
options.battleId | string | Yes | - | Accept PK ID. |
Return value: Promise<void>
rejectBattle
Reject PK request
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.getLiveBattleManager();const { battleId, result }= liveBattleManager.rejectBattle({battleId: 'battleId'});
Parameter | Type | Required or Not | Default Value | Description |
options | Object | Yes | - | Reject PK parameters. |
options.battleId | string | Yes | - | Reject PK ID. |
Return value: Promise<void>
exitBattle
Log out
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.getLiveBattleManager();const { battleId, result }= liveBattleManager.exitBattle({battleId: 'battleId'});
Parameter | Type | Required or Not | Default Value | Description |
options | Object | Yes | - | Parameters for logging out of PK. |
options.battleId | string | Yes | - | Cancel the PK ID. |
Return value: Promise<void>
on
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.getLiveBattleManager();const callback = (battleInfo) => {console.log('liveBattleManager.onBattleStarted', battleInfo);};liveBattleManager.on(TUILiveBattleManagerEvents.onBattleStarted, callback);
Parameter | Type | Required or Not | Default Value | Description |
eventName | Yes | - | Event name. | |
func | (...args: any[]) => void | Yes | - | event handler |
off
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.getLiveBattleManager();const callback = (battleInfo) => {console.log('liveBattleManager.onBattleStarted', battleInfo);};liveBattleManager.off(TUILiveBattleManagerEvents.onBattleStarted, callback);
Parameter | Type | Required or Not | Default Value | Description |
eventName | Yes | - | Event name. | |
func | (...args: any[]) => void | Yes | - | event handler |
Event API Detail
onBattleStarted
Receiving the PK start monitoring event.
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.TUILiveBattleManager();liveBattleManager.on(TUILiveBattleManagerEvents.onBattleStarted, ({ battleInfo }) => {console.log('liveBattleManager.onBattleStarted', battleInfo);});
Parameter | Type | Description |
options | Object | Parameter Options. |
options.battleInfo | PK info |
onBattleEnded
Receiving the PK end monitoring event.
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.TUILiveBattleManager();liveBattleManager.on(TUILiveBattleManagerEvents.onBattleEnded, ({ battleInfo, reason }) => {console.log('liveBattleManager.onBattleEnded', battleInfo, reason);});
Parameter | Type | Description |
options | Object | Parameter Options. |
options.battleInfo | PK info | |
options.reason | End PK Reason. |
onUserJoinBattle
Receiving the user joined PK monitoring event.
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.TUILiveBattleManager();liveBattleManager.on(TUILiveBattleManagerEvents.onUserJoinBattle, ({ battleId, user }) => {console.log('liveBattleManager.onUserJoinBattle', battleId, user);});
Parameter | Type | Description |
options | Object | Parameter Options. |
options.battleId | string | PK ID. |
options.user | User information added to PK. |
onUserExitBattle
Receiving the user logout PK monitoring event.
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.TUILiveBattleManager();liveBattleManager.on(TUILiveBattleManagerEvents.onUserExitBattle, ({ battleId, user }) => {console.log('liveBattleManager.onUserExitBattle', battleId, user);});
Parameter | Type | Description |
options | Object | Parameter Options. |
options.battleId | string | PK ID. |
options.user | User information added to PK. |
onBattleScoreChanged
Receiving the PK score adjustment monitoring event.
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.TUILiveBattleManager();liveBattleManager.on(TUILiveBattleManagerEvents.onBattleScoreChanged, ({ battleId, battleUserList }) => {console.log('liveBattleManager.onBattleScoreChanged', battleId, battleUserList);});
Parameter | Type | Description |
options | Object | Parameter Options. |
options.battleId | string | PK ID. |
options.battleUserList | PK User Information List |
onBattleRequestReceived
Listening for PK requests.
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.TUILiveBattleManager();liveBattleManager.on(TUILiveBattleManagerEvents.onBattleRequestReceived, ({ battleInfo, inviter, invitee }) => {console.log('liveBattleManager.onBattleRequestReceived', battleInfo, inviter, invitee);});
Parameter | Type | Description |
options | Object | Parameter Options. |
options.battleInfo | PK info | |
options.inviter | The user initiating a PK request | |
options.invitee | The user receiving a PK request |
onBattleRequestCancelled
Listening for PK request cancellation.
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.TUILiveBattleManager();liveBattleManager.on(TUILiveBattleManagerEvents.onBattleRequestCancelled, ({ battleInfo, inviter, invitee }) => {console.log('liveBattleManager.onBattleRequestCancelled', battleInfo, inviter, invitee);});
Parameter | Type | Description |
options | Object | Parameter Options. |
options.battleInfo | PK info | |
options.inviter | The user initiating a PK request | |
options.invitee | The user receiving a PK request |
onBattleRequestTimeout
Listening for PK request timeout.
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.TUILiveBattleManager();liveBattleManager.on(TUILiveBattleManagerEvents.onBattleRequestTimeout, ({ battleInfo, inviter, invitee }) => {console.log('liveBattleManager.onBattleRequestTimeout', battleInfo, inviter, invitee);});
Parameter | Type | Description |
options | Object | Parameter Options. |
options.battleInfo | PK info | |
options.inviter | The user initiating a PK request | |
options.invitee | The user receiving a PK request |
onBattleRequestAccept
Listening for PK requests.
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.TUILiveBattleManager();liveBattleManager.on(TUILiveBattleManagerEvents.onBattleRequestAccept, ({ battleInfo, inviter, invitee }) => {console.log('liveBattleManager.onBattleRequestAccept', battleInfo, inviter, invitee);});
Parameter | Type | Description |
options | Object | Parameter Options. |
options.battleInfo | PK info | |
options.inviter | The user initiating a PK request | |
options.invitee | The user receiving a PK request |
onBattleRequestReject
Listening for PK request rejected events.
const roomEngine = new TUIRoomEngine();const liveBattleManager = roomEngine.TUILiveBattleManager();liveBattleManager.on(TUILiveBattleManagerEvents.onBattleRequestReject, ({ battleInfo, inviter, invitee }) => {console.log('liveBattleManager.onBattleRequestReject', battleInfo, inviter, invitee);});
Parameter | Type | Description |
options | Object | Parameter Options. |
options.battleInfo | PK info | |
options.inviter | The user initiating a PK request | |
options.invitee | The user receiving a PK request |
Type Definition Details
TUIBattleConfig
Attribute | Type | Description |
duration | number | PK duration. |
needResponse | boolean | Whether required. Default false. |
extensionInfo | string | Extended information. Default value: ''. |
TUIBattleInfo
Attribute | Type | Description |
fromUser | User information for initiating PK. | |
toUserList | List of users invited to PK. | |
extensionInfo | string | Extended information. |
battleId | string | PK ID. |
needResponse | boolean | Whether required accordingly |
duration | number | PK duration |
startTime | number | PK start timestamp |
endTime | number | PK end timestamp |
TUIBattleUser
Attribute | Type | Description |
roomId | string | Room ID. |
userId | string | User ID. |
userName | string | Username. |
avatarUrl | string | User profile photo url. |
score | number | PK score |
Enum Definition Details
TUIBattleStoppedReason
Field | Type | Description |
kStoppedByTimeOver | number | PK stopped as time ends. |
kStoppedByOtherExit | number | PK stopped as the user logged out. |