tencent cloud


Last updated: 2023-10-27 10:10:04
    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();
    // After the exit is successful, if you do not need to use the trtc instance later, you can call the trtc.destroy method to destroy the instance and release related resources in a timely manner. The destroyed trtc instance cannot be used again and a new instance needs to be created.
    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}`);
    // error.reason has the following situations
    // 'kick' The user with the same userId enters the same room, causing the user who enters the room first to be kicked out.
    // 'banned' The administrator removed the user from the room
    // 'room-disband' The administrator dissolved the room
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support