disconnect static method
will disable 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 disables , you will stop 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.disconnect()
Implementation
static Future<Null> disconnect(
{Function(String successMessage)? onSuccess,
Function(CometChatException e)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call realtime repository to disconnect WebSocket
await sdk.realtime.disconnect();
// Call success callback
final result = 'WebSocket connection closed';
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);
}
}