connect
Connects to the RCserver. This method should be called only once globally in the entire application and must be invoked after init.
When this interface returns a non-business error code, the SDK will initiate a reconnection mechanism. If the connection still fails, it will attempt to reconnect when the device's network status changes.If you are using IMKit, please use the method of the same name in RongIM to establish a connection with the RCserver instead of using this method.
When this interface is called, the SDK will attempt to reconnect after a connection failure, resulting in one of the following two scenarios: First, the connection is successful, and onSuccess(userId) is called back. Second, an error that the SDK cannot handle occurs, and onError(errorCode) is called back (e.g., invalid token), and no further reconnection attempts are made.
If you do not want to keep reconnecting, you can use the connect(String, int, ConnectCallback) interface and set the connection timeout time limit.
Return
An instance of the RongIMClient, the core class of the IM client.
Parameters
The user authentication token (Token) obtained from the server.
The extended connection callback class, which adds a callback for opening the database (OnDatabaseOpened(DatabaseOpenStatus)). It returns the status of the database opening, DatabaseOpenStatus; DATABASE_OPEN_SUCCESS
triggers the operation to fetch the conversation list, while DATABASE_OPEN_ERROR
is not handled.If the connection fails, refer to the specific error codes in .
Connects to the RCserver. This method should be called only once globally within the application and must be invoked after init.
When this interface returns a non-business error code, the SDK will initiate a reconnection mechanism. If the connection still fails, it will attempt to reconnect when the device's network status changes.If you are using IMKit, please use the method of the same name in RongIM to establish a connection with the RCserver, instead of using this method.
Return
An instance of RongIMClient, the core class of the IM client.
Parameters
The user authentication token (Token) obtained from the server.
The connection timeout duration in seconds. If timeLimit <= 0
, the IM will continue to connect until it succeeds or fails (e.g., due to an invalid token). If timeLimit > 0
, the IM will attempt to connect for up to timeLimit seconds: If the connection succeeds within timeLimit seconds, the SDK will automatically reconnect in case of network changes or app state transitions. If the connection fails within timeLimit seconds, no further reconnection attempts will be made, and the connection timeout will be reported via onError. You will need to manually call the connect interface again.
The extended connection callback class, which includes a callback for database opening (OnDatabaseOpened(DatabaseOpenStatus)). It returns the status of the database opening, DatabaseOpenStatus; DATABASE_OPEN_SUCCESS
triggers the operation to fetch the conversation list, while DATABASE_OPEN_ERROR
will not be processed.For connection failures, refer to the specific error codes in .