initiateCall static method
void
initiateCall(
- Call call, {
- required dynamic onSuccess(
- Call call
- required dynamic onError(
- CometChatException excep
Initiates a call to a user or group.
Android Reference: CometChat.initiateCall(Call call, CallbackListener<Call>)
Response parsing uses Call.fromMap() to match Android SDK's Call.fromJson():
- sessionId from data.entities.on.entity.sessionid
- callInitiator from data.entities.on.entity.data.entities.sender
- callReceiver from data.entities.on.entity.data.entities.receiver
- sender from data.entities.by.entity
- receiver from data.entities.for.entity
Implementation
static void initiateCall(Call call,
{required Function(Call call)? onSuccess,
required Function(CometChatException excep) onError}) async {
try {
// Validate parameters
if (call.receiverUid.isEmpty) {
onError(CometChatException(
"Error", "Receiver UID is empty", "Receiver UID is required"));
return;
}
if (call.receiverType.isEmpty) {
onError(CometChatException(
"Error", "Receiver type is empty", "Receiver type is required"));
return;
}
if (call.type.isEmpty) {
onError(CometChatException(
"Error", "Call type is empty", "Call type is required"));
return;
}
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call native Dart call repository - returns raw response map
final responseData = await sdk.calls.initiateCallRaw(
receiver: call.receiverUid,
receiverType: call.receiverType,
type: call.type,
);
// Parse using Call.fromMap() to match Android SDK's Call.fromJson()
// Android: Call.fromJson(mainObject.getJSONObject("data").toString())
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(),
));
}
}