Skip to main content

Join Chatroom

By default, a single user cannot join multiple chatrooms simultaneously. Joining a new chatroom will automatically exit the previous one.

To enable a single user to join multiple chatrooms, you need to enable this configuration in the Console. For details, refer to Chatroom Service Configuration.

Join Chatroom

Method

Future<int> joinChatRoom(String targetId, int messageCount, bool autoCreate, {IRCIMIWJoinChatRoomCallback? callback});

Parameter Description

ParameterTypeDescription
targetIdStringThe chatroom conversation ID
messageCountintThe number of messages to pull when entering the chatroom. -1 means no messages are pulled, 0 means pulling 10 messages, and the maximum is 50
autoCreateboolWhether to create the chatroom. If TRUE, the SDK will create the chatroom and join if it doesn’t exist. If it already exists, it will join directly
callbackIRCIMIWJoinChatRoomCallbackEvent callback. The SDK supports callback mode starting from version 5.3.1. Other callback methods for this interface are deprecated from version 5.4.0. If the callback parameter is passed, only the callback will be triggered.

Return Value

Return ValueDescription
Future<int>The status code of the current operation. 0 indicates a successful call. The specific result needs to be implemented through the interface callback. Non-zero indicates that the current interface call operation failed, and the interface callback will not be triggered. For detailed errors, refer to the error codes

Code Example

IRCIMIWJoinChatRoomCallback? callback = IRCIMIWJoinChatRoomCallback(onChatRoomJoined: (int? code, String? targetId) {
//...
});

int? ret = await engine?.joinChatRoom(targetId, messageCount, autoCreate, callback:callback);

Callback Methods

  • onChatRoomJoined
Function(int? code, String? targetId)? onChatRoomJoined;

Parameter Description

ParameterTypeDescription
codeintThe status code of the interface callback. 0 indicates success, non-zero indicates an exception
targetIdStringThe conversation ID

Code Example

engine?.onChatRoomJoined = (int? code, String? targetId) {
//...
};
  • onChatRoomJoining

Callback when joining a chatroom

Function(String? targetId)? onChatRoomJoining;

Parameter Description

ParameterTypeDescription
targetIdStringThe chatroom ID

Code Example

engine?.onChatRoomJoining = (String? targetId) {
//...
};
  • The SDK provides a chatroom reconnection mechanism. Once the connection status is restored, if the user had previously joined a chatroom and did not exit, they will rejoin the chatroom.