acceptCall static method
void
acceptCall(
- String sessionID, {
- required dynamic onSuccess(
- Call call
- required dynamic onError(
- 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);
// 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(),
));
}
}