Leave an open channel
Participants can leave an open channel in two ways:
- Passive removal: The server automatically removes offline participants when preset conditions are met, or when a participant is banned.
- Active leave: The participant explicitly exits via the SDK.
Passive removal
Open channels use an auto-removal mechanism for offline participants. By default, RongCloud server removes offline participants under these conditions:
- Within 30 seconds of going offline, if 31 or more messages are sent in the channel, the participant is removed.
- After 30 seconds offline, any new message in the channel triggers the removal.
tip
These conditions require new messages in the channel. If no messages are sent, offline participants are not removed. Use the Server API's participant whitelist to protect specific users (e.g., hosts or moderators) from auto-removal.
Active leave
Create an NCOpenChannel instance with the channel ID and call exitChannel(completion:):
- Swift
- Objective-C
swift
import NexconnChatSDK
guard let channel = OpenChannel(channelId: "channelId") else {
return
}
channel.exitChannel(extra: nil) { error in
if let error {
print("Failed to leave: \(error.localizedDescription)")
} else {
print("Left the channel.")
}
}
Objective C
NCOpenChannel *channel = [[NCOpenChannel alloc] initWithChannelId:@"channelId"];
[channel exitChannelWithExtra:nil completion:^(NCError *error) {
if (error == nil) {
NSLog(@"Left the channel.");
} else {
NSLog(@"Failed to leave: %@", error);
}
}];