connect static method
will establish the Web-socket connections manually
While calling the init() function on the app startup, need to inform the SDK that you will be managing the web socket connect from autoEstablishSocketConnection.
Once the connection is established, you will start receiving all the real-time events for the logged in user
Migration Note: Migrated from platform channels to native Dart implementation. Uses RealtimeRepository for WebSocket connection management. Behavior and signature remain identical for backward compatibility.
Android Reference: CometChat.connect()
Implementation
static Future<Null> connect(
{Function(String successMessage)? onSuccess,
Function(CometChatException e)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call realtime repository to establish WebSocket
await sdk.realtime.connect();
// Call success callback
final result = 'WebSocket connection established';
if (onSuccess != null) onSuccess(result);
} on SdkException catch (sdkEx) {
// Convert SdkException to CometChatException
final cometChatEx = CometChatException(
sdkEx.code,
sdkEx.details ?? sdkEx.message,
sdkEx.message,
);
_errorCallbackHandler(cometChatEx, null, null, onError);
} catch (e) {
_errorCallbackHandler(null, null, e, onError);
}
}