ping static method

Future<void> ping({
  1. required Function? onSuccess,
  2. required dynamic onError(
    1. CometChatException e
    )?,
})

Manual ping to check WebSocket connection.

Migration Note: Migrated from platform channels to native Dart implementation. Uses RealtimeRepository for manual ping. Behavior and signature remain identical for backward compatibility.

Android Reference: CometChat.ping(CallbackListener<String> listener)

Implementation

static Future<void> ping(
    {required Function? onSuccess,
    required Function(CometChatException e)? onError}) async {
  try {
    // Get SDK instance
    final sdk = SdkRegistry.getInstance();

    // Call native Dart realtime repository
    await sdk.realtime.ping();

    // Call success callback
    if (onSuccess != null) onSuccess();
  } on SdkException catch (sdkEx) {
    // Convert SdkException to CometChatException
    final cometChatEx = CometChatException(
      sdkEx.code,
      sdkEx.details ?? sdkEx.message,
      sdkEx.message,
    );
    _errorCallbackHandler(cometChatEx, null, null, onError);
  } on CometChatException catch (cce) {
    // Already a CometChatException
    _errorCallbackHandler(cce, null, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
}