outGoingCall method

void outGoingCall({
  1. required String phoneNumber,
  2. required VoidCallback handleRegisterCall,
  3. String nameCaller = '',
  4. String domainUrl = 'google.com',
  5. bool enableLoading = true,
})

Implementation

void outGoingCall({
  required String phoneNumber,
  required VoidCallback handleRegisterCall,
  String nameCaller = '',
  String domainUrl = 'google.com',
  bool enableLoading = true,
}) {
  thr.throttle(() async {
    _dismissLoading();
    if (enableLoading) {
      EasyLoading.show(status: "Connecting...");
    }
    if (!checkIsNumber.hasMatch(phoneNumber)) {
      EasyLoading.showToast(
        'Invalid phone number',
        toastPosition: EasyLoadingToastPosition.center,
      );
      return;
    }
    _outPhone = phoneNumber;
    _nameCaller = nameCaller;

    if (Platform.isIOS) {
      var newUUID = const Uuid().v4();
      CallKitParams params = CallKitParams(
        id: newUUID,
        nameCaller: phoneNumber,
        handle: phoneNumber,
        type: 0,
        ios: IOSParams(handleType: 'generic'),
      );
      await FlutterCallkitIncoming.startCall(params);
    }

    final PitelCall pitelCall = PitelClient.getInstance().pitelCall;
    final PitelClient pitelClient = PitelClient.getInstance();
    final connectivityResult = await (Connectivity().checkConnectivity());
    if (connectivityResult.first == ConnectivityResult.none) {
      _checkConnectivity = [ConnectivityResult.none];
      EasyLoading.showToast(
        'Please check your network',
        toastPosition: EasyLoadingToastPosition.center,
      );
      return;
    }
    if (connectivityResult != _checkConnectivity) {
      _checkConnectivity = connectivityResult;
      handleRegisterCall();
      return;
    }

    if (connectivityResult.first == ConnectivityResult.wifi) {
      try {
        final wifiIP = await NetworkInfo().getWifiIP();
        if (wifiIP != _wifiIP) {
          _wifiIP = wifiIP;
          handleRegisterCall();
          return;
        }
      } catch (error) {
        handleRegisterCall();
        return;
      }
    }

    final isRegistered = pitelCall.getRegisterState();
    if (isRegistered == 'Registered') {
      EasyLoading.dismiss();
      if (Platform.isIOS) {
        await Future.delayed(const Duration(milliseconds: 500));
      }
      pitelClient
          .call(phoneNumber, true)
          .then((value) => value.fold((succ) => "OK", (err) {
                FlutterCallkitIncoming.endAllCalls();
                EasyLoading.showToast(
                  err.toString(),
                  toastPosition: EasyLoadingToastPosition.center,
                );
              }));
    } else {
      handleRegisterCall();
    }
  });
}