This document describes how to exit the current TRTC room and in which cases a user is forced to exit the room.
Step 1. Enter a room
Create a trtc instance and enter a room. For detailed directions, see Entering a Room. Step 2. Exit the room
Call the trtc.exitRoom()
method to exit the room and end the audio and video call. await trtc.exitRoom();
trtc.destroy();
Handling being kicked out
In addition to actively exiting the room, users may also be kicked out of the room for the following reasons.
1. kick
: Two users with the same userId enter the same room, and the user who enters the room first will be kicked out. It is not allowed for users with the same name to enter the same room at the same time, which may cause abnormal audio and video calls between the two parties, so this situation should be avoided.
banned
: A user is kicked out of a TRTC room through the server's RemoveUser | RemoveUserByStrRoomId interface. The user will receive a kicked event, and the reason is banned
.2. room-disband
: A TRTC room is dissolved through the server's DismissRoom | DismissRoomByStrRoomId interface. After the room is dissolved, all users in the room will receive a kicked event, and the reason is room-disband
. At this time, the SDK will throw the KICKED_OUT event. There is no need to call trtc.exitRoom()
to exit the room, and the SDK will automatically enter the exit room state. trtc.on(TRTC.EVENT.KICKED_OUT, error => {
console.error(`kicked out, reason:${error.reason}, message:${error.message}`);
});
Was this page helpful?