rejectCall static method
void
rejectCall(
- String sessionID,
- String status, {
- required dynamic onSuccess(
- Call call
- required dynamic onError(
- CometChatException excep
Rejects an incoming call.
Migration Note: Migrated from platform channels to native Dart implementation. Uses CallRepository for call rejection. Behavior and signature remain identical for backward compatibility.
Android Reference: CometChat.rejectCall(String sessionID, String status, CallbackListener<Call>)
Implementation
static void rejectCall(String sessionID, String status,
{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;
}
if (status.isEmpty) {
onError(CometChatException(
"Error", "Call status is null", "Call status 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, status);
// Parse using Call.fromMap() to match Android SDK's Call.fromJson()
final publicCall = Call.fromMap(responseData);
// 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(),
));
}
}