initiateCall static method

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

Implementation

static void initiateCall(Call call,
    {required Function(Call call)? onSuccess,
    required Function(CometChatException excep) onError}) async {
  try {
    if (call.receiverUid.isEmpty) {
      onError(CometChatException(
          "Error", "User auth toke is null", "User is not logged in"));
    } else if (call.receiverType.isEmpty) {
      onError(CometChatException(
          "Error", "User auth toke is null", "User is not logged in"));
    } else if (call.type.isEmpty) {
      onError(CometChatException(
          "Error", "User auth toke is null", "User is not logged in"));
    } else {
      Map<String, dynamic> callMap = {};
      callMap["receiverUid"] = call.receiverUid;
      callMap["receiverType"] = call.receiverType;
      callMap["callType"] = call.type;
      if (call.metadata != null && call.metadata!.isNotEmpty) {
        callMap["metadata"] = json.encode(call.metadata);
      }
      if (call.muid.isNotEmpty) {
        callMap["muid"] = call.muid;
      }
      var result = await channel.invokeMethod('initiateCall', callMap);
      if (onSuccess != null) onSuccess(Call.fromMap(result));
    }
  } on PlatformException catch (p) {
    _errorCallbackHandler(null, p, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
}