please select
RTC Engine
  • Overview
  • Web
    • Run Sample Demo
    • Integration
    • Basic Features
      • Screen Sharing
      • Live Streaming
      • Media Device
      • Audio Volume
      • Set Encoding Profile
      • Detect Network Quality
      • Detect Capabilities
    • Advance Features
      • Enable AI Denoiser
      • Enable Audio Mixer
      • Enable Watermark
      • Enable Virtual Background
      • Enable Beauty and Effects
      • Data Messages
      • Custom Capturing and Rendering
    • API List
    • Released Notes
    • Supported Platforms
    • Web FAQs
      • Optimize Multi-Person Video Calls
      • Handle Autoplay Restriction
      • Handle Firewall Restriction
      • Others
  • Android
    • Run Sample Code
    • Integration
      • 1.Importing the SDK
      • 2.Entering a Room
      • 3.Subscribing to Audio/Video Streams
      • 4.Publish Audio/Video Streams
      • 5.Exiting a Room
      • 6.Sensing Network Quality
      • 7.Enabling Screen Sharing
      • 8.Setting Video Quality
      • 9.Rotating Videos
    • Testing Newwork Quality
    • Custom Capturing and Rendering
    • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • TRTCCloud
      • TRTCStatistics
      • TRTCCloudListener
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • Type Definition
      • Deprecated Interface
      • Error Codes
    • Solution
      • Real-Time Chorus (TUIKaraoke)
        • Quick Integration
        • Implementation Steps
        • Song Synchronization
        • Lyric Synchronization
        • Vocal Synchronization
        • Mixing Stream Solution
        • TRTCKaraoke APIs
        • FAQs
    • Release Notes
  • iOS
    • Run Sample Code
    • Integration
      • 1.Importing the SDK
      • 2.Entering a Room
      • 3.Subscribing to Audio/Video Streams
      • 4.Publish Audio/Video Streams
      • 5.Exiting a Room
      • 6.Sensing Network Quality
      • 7.Enabling Screen Sharing
      • 8.Setting Video Quality
      • 9.Rotating Videos
    • Testing Network Quality
    • Custom Capturing and Rendering
    • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • TRTCCloud
      • TRTCCloudDelegate
      • TRTCStatistics
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • Type Definition
      • Deprecated Interface
      • ErrorCode
    • Solution
      • Quick Integration
      • Implementation Steps
      • Song Synchronization
      • Lyric Synchronization
      • Vocal Synchronization
      • Mixing Stream Solution
      • TRTCKaraoke APIs
      • FAQs
    • Release Notes
  • macOS
    • Run Sample Code
    • Integration
      • 1.Importing the SDK
      • 2.Entering a Room
      • 3.Subscribing to Audio/Video Streams
      • 4.Publish Audio/Video Streams
      • 5.Exiting a Room
      • 6.Sensing Network Quality
      • 7.Enabling Screen Sharing
      • 8.Sharing Computer Audio
      • 9.Setting Video Quality
      • 10.Rotating Videos
    • Testing Hardware Devices
    • Testing Network Quality
    • Custom Capturing and Rendering
    • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • TRTCCloud
      • TRTCCloudDelegate
      • TRTCStatistics
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • Type Definition
      • Deprecated Interface
      • ErrorCode
      • Release Notes
    • Release Notes
  • Windows
    • Run Sample Code
    • Integration
      • 1.Importing the SDK
      • 2.Entering a Room
      • 3.Subscribing to Audio/Video Streams
      • 4.Publish Audio/Video Streams
      • 5.Exiting a Room
      • 6.Sensing Network Quality
      • 7.Enabling Screen Sharing
      • 8.Setting Video Quality
      • 9.Rotating Videos
    • Testing Hardware Devices
    • Testing Network Quality
    • Custom Capturing and Rendering
    • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • ITRTCCloud
      • ITRTCStatistics
      • TRTCCloudCallback
      • ITXAudioEffectManager
      • ITXDeviceManager
      • Type Definition
      • Deprecated Interface
      • Error Codes
    • Release Notes
  • Electron
    • Integration
      • 1.API Examples
      • 2.Importing the SDK
      • 3.Entering a Room
      • 4.Subscribing to Audio/Video Streams
      • 5.Publish Audio/Video Streams
      • 6.Exiting a Room
      • 7.Sensing Network Quality
      • 8.Enabling Screen Sharing
      • 9.Sharing Computer Audio
      • 10.Setting Video Quality
      • 11.Rotating Videos
    • Client APIs
      • Overview
      • Error Codes
  • Flutter
    • Integration
      • 1.API Examples
      • 2.Importing the SDK
      • 3.Entering a Room
      • 4.Subscribing to Audio/Video Streams
      • 5.Publish Audio/Video Streams
      • 6.Exiting a Room
      • 7.Sensing Network Quality
      • 8.Enabling Screen Sharing
      • 9.Sharing Computer Audio
      • 10.Setting Video Quality
      • 11.Rotating Videos
    • Client APIs
      • Overview
      • Error Codes
  • Unity
    • Integration
      • 1.API Examples
      • 2Importing the SDK
    • Client APIs
      • Overview
      • Error Codes
  • Qt
    • Integration
      • 1.Importing the SDK
  • Overview
    • Overview
  • Concepts
  • Features
  • Performance Statistics
  • Pricing
    • Free Minutes
    • RTC-Engine Monthly Packages
    • Billing Explanation for Subscription Package Duration
    • Pay-as-you-go
      • Billing of Audio and Video Duration
      • Billing of On-Cloud Recording and Recording Delivery
      • Billing of MixTranscoding and Relay to CDN
  • FAQs
    • FAQs for Beginners
    • Migration Guide
      • Twilio Video to Tencent RTC
      • Billing
      • Features
      • UserSig
      • Firewall Restrictions
      • How to Downsize Installation Package
      • TRTCCalling for Web
      • Audio and Video Quality
      • Others
RTC Engine

5.Exiting a Room

This document describes how to actively exit the current TRTC room and in which cases will a user be forced to exit a room.



Call Guide



Step 1. Perform prerequisite steps

Import the SDK and configure the application permissions as instructed in iOS. Enter the room as instructed in Entering a Room.


Step 2. Actively exit the current room

Call the exitRoom API to exit the current room, and the SDK will use the onExitRoom(int reason) callback to notify you of the reason the room was exited.
Android
iOS&Mac
Windows
// Exit the current room
mCloud.exitRoom();

self.trtcCloud = [TRTCCloud sharedInstance];
// Exit the current room
[self.trtcCloud exitRoom];

trtc_cloud_ = getTRTCShareInstance();
// Exit the current room
trtc_cloud_->exitRoom();

After the exitRoom API is called, the SDK will enter the room exit process, where two key tasks need to be completed:
1. Notify the exit of the current user Notify other users in the room of the upcoming room exit, and they will receive the onRemoteUserLeaveRoom callback from the current user; otherwise, other users may think the current user's video image is simply frozen.
2. Revoke device permissions If the current user is publishing an audio/video stream before exiting the room, the user needs to turn off the camera and mic and release the device permissions during the room exit process.
Therefore, we recommend you release the TRTCCloud instance after receiving the onExitRoom callback.


Step 3. Be forced to exit the current room

The onExitRoom(int reason) callback will also be received in other two cases in addition to active room exit:
Case 1. A user is kicked out of the room You can use the RemoveUser or RemoveUserByStrRoomId API to kick a user out of a TRTC room. After being kicked out, the user will receive the onExitRoom(1) callback.
Case 2. The current room is closed You can call the DismissRoom or DismissRoomByStrRoomId API to close a TRTC room. After the room is closed, all users in the room will receive the onExitRoom(2) callback.
Android
iOS&Mac
Windows
// Listen for the `onExitRoom` callback to get the reason for room exit
@Override
public void onExitRoom(int reason) {
if (reason == 0) {
Log.d(TAG, "Exit current room by calling the 'exitRoom' api of sdk ...");
} else if (reason == 1) {
Log.d(TAG, "Kicked out of the current room by server through the restful api...");
} else if (reason == 2) {
Log.d(TAG, "Current room is dissolved by server through the restful api...");
}
}

// Listen for the `onExitRoom` callback to get the reason for room exit
- (void)onExitRoom:(NSInteger)reason {
if (reason == 0) {
NSLog(@"Exit current room by calling the 'exitRoom' api of sdk ...");
} else if (reason == 1) {
NSLog(@"Kicked out of the current room by server through the restful api...");
} else if (reason == 2) {
NSLog(@"Current room is dissolved by server through the restful api...");
}
}

// Listen for the `onExitRoom` callback to get the reason for room exit
void onExitRoom(int reason) {
if (reason == 0) {
printf("Exit current room by calling the 'exitRoom' api of sdk ...");
} else if (reason == 1) {
printf("Kicked out of the current room by server through the restful api...");
} else if (reason == 2) {
printf("Current room is dissolved by server through the restful api...");
}
}