acceptCall static method

void acceptCall(
  1. String sessionID, {
  2. required dynamic onSuccess(
    1. Call call
    )?,
  3. required dynamic onError(
    1. CometChatException excep
    ),
})

Accepts an incoming call.

Migration Note: Migrated from platform channels to native Dart implementation. Uses CallRepository for call acceptance. Behavior and signature remain identical for backward compatibility.

Android Reference: CometChat.acceptCall(String sessionID, CallbackListener<Call>)

Implementation

static void acceptCall(
  String sessionID, {
  required Function(Call call)? onSuccess,
  required Function(CometChatException excep) onError,
}) async {
  try {
    // Validate parameters
    if (sessionID.isEmpty) {
      onError(
        CometChatException(
          "Error",
          "Session ID is null",
          "Session ID is null",
        ),
      );
      return;
    }

    // Get SDK instance
    final sdk = SdkRegistry.getInstance();

    // Call native Dart call repository - returns raw response map
    final responseData = await sdk.calls.updateCallStatusRaw(
      sessionID,
      'ongoing',
    );

    // Parse using Call.fromMap() to match Android SDK's Call.fromJson()
    final publicCall = Call.fromMap(responseData);

    // Android: CallManager.joinCall() stores this as the initial call. The
    // response carries the `joinedAt` that endCall() has to echo back.
    _initialCall = publicCall;

    // Call success callback
    if (onSuccess != null) onSuccess(publicCall);
  } on SdkException catch (sdkEx) {
    // Convert SdkException to CometChatException
    final cometChatEx = CometChatException(
      sdkEx.code,
      sdkEx.details ?? sdkEx.message,
      sdkEx.message,
    );
    onError(cometChatEx);
  } catch (e) {
    onError(
      CometChatException(
        ErrorCode.errorUnhandledException,
        e.toString(),
        e.toString(),
      ),
    );
  }
}