connect method
ZH
连接融云服务器,在整个应用程序全局,只需要调用一次。调用此接口返回非业务错误码时,SDK 会启动重连机制进行重连;如果仍没有连接成功,会在设备网络状态变化时再次进行重连。
token调用 server api 获取到的 tokentimeout连接超时时间,单位:秒。 timeout ≤ 0,则 IM 将一直连接,直到连接成功或者无法连接(如 token 非法) timeout > 0,则 IM 将最多连接 timeout 秒 如果在 timeout 秒内连接成功,后面再发生了网络变化或前后台切换,SDK 会自动重连; 如果在 timeout 秒无法连接成功则不再进行重连,通过 listener 告知连接超时,您需要再自行调用 connect 接口callback链接事件回调。SDK 从 5.3.1 版本开始支持 callback 方式回调。从 5.4.0 版本废弃该接口的其他回调方式,预计将在 6.x 版本删除此其他回调方式。如果传入了 callback 参数,仅触发 callback 回调。返回值当次接口操作的状态码。0 代表调用成功 具体结果需要实现接口回调,非 0 代表当前接口调用操作失败,不会触发接口回调,详细错误参考错误码接口回调接口回调可以监听 onConnected
EN
Connect to the RongCloud server. This interface should be called only once globally throughout the application. When this interface returns a non-business error code, the SDK will initiate a reconnection mechanism. If the connection is still unsuccessful, the SDK will attempt to reconnect when the device's network status changes.
tokenThe token obtained by calling the server API.timeoutConnection timeout duration in seconds. If timeout ≤ 0, the IM will keep trying to connect until it succeeds or fails (e.g., due to an invalid token). If timeout > 0, the IM will attempt to connect for a maximum of timeout seconds. If the connection is successful 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 listener will notify of a connection timeout. You will need to manually call the connect interface again.callbackConnection event callback. The SDK has supported callback-style callbacks since version 5.3.1. Other callback methods for this interface were deprecated in version 5.4.0 and are expected to be removed in version 6.x. If the callback parameter is provided, only the callback will be triggered. successful call, and the specific result needs to be implemented in the interface callback. A non-zero value indicates that the current interface call operation failed, and no interface callback will be triggered. Refer to the error codes for detailed error information. @listener The interface callback can listen to onConnected.
Implementation
Future<int> connect(String token, int timeout, {RCIMIWConnectCallback? callback}) async {
return RCIMWrapperPlatform.instance.connect(token, timeout, callback: callback);
}