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 (exception) {
    onError(CometChatException(exception.code, exception.message, exception.details));
  } catch (e) {
    onError(CometChatException("Error", "Something went wrong", e.toString()));
  }
}