userDisconnection method

void userDisconnection(
  1. String callMode,
  2. String userJid,
  3. String callType
)

Implementation

void userDisconnection(String callMode, String userJid, String callType) {
  this.callMode(callMode);
  this.callType(callType);
  debugPrint("Current Route ${Get.currentRoute}");
  if (MirrorflyUikit.instance.navigationManager.getCurrentRoute() ==
      Constants.outGoingCallView) {
    // This if condition is added for the group call remote busy - call action
    if (callList.length < 2) {
      // Get.back();
      MirrorflyUikit.instance.navigationManager
          .navigateBack(context: context);
    }
    return;
  }

  debugPrint("#Mirrorfly call call disconnect called ${callList.length}");
  debugPrint("#Mirrorfly call call disconnect called $callList");

  if (callList.isEmpty) {
    debugPrint("call list is empty returning");
    return;
  }
  debugPrint("call list is not empty");
  var index = callList.indexWhere((user) => user.userJid!.value == userJid);
  // debugPrint("#Mirrorfly call disconnected user Index $index ${Get.currentRoute}");
  if (!index.isNegative) {
    // callList.removeAt(index);
    callList.removeWhere((callUser) => callUser.userJid?.value == userJid);
  } else {
    debugPrint("#Mirrorflycall participant jid is not in the list");
  }
  if (callList.length <= 1 || userJid == SessionManagement.getUserJID()) {
    debugPrint("Entering Call Disconnection Loop");
    isCallTimerEnabled = false;
    //if user is in the participants screen all users end the call then we should close call pages
    if (MirrorflyUikit.instance.navigationManager.getCurrentRoute() ==
        Constants.participantView) {
      // Navigator.pop(context);
      MirrorflyUikit.instance.navigationManager
          .navigateBack(context: context);
    }

    if (MirrorflyUikit.instance.navigationManager.hasPrevRoute()) {
      if (MirrorflyUikit.instance.navigationManager.getCurrentRoute() ==
          Constants.onGoingCallView) {
        callTimer("Disconnected");
        Future.delayed(const Duration(seconds: 1), () {
          // Get.back();
          MirrorflyUikit.instance.navigationManager
              .navigateBack(context: context);
        });
      } else {
        // Get.back();
        MirrorflyUikit.instance.navigationManager
            .navigateBack(context: context);
      }
    } else {
      // Get.offNamed(getInitialRoute());
    }

    /*if (Platform.isIOS) {
      // in iOS needs to call disconnect.
      disconnectCall();
    } else {
      if (MirrorflyUikit.instance.navigationManager.routeHistory.isNotEmpty) {
        if (MirrorflyUikit.instance.navigationManager.getCurrentRoute() == Constants.onGoingCallView) {
          callTimer("Disconnected");
          Future.delayed(const Duration(seconds: 1), () {
            MirrorflyUikit.instance.navigationManager.navigateBack(context: context);
          });
        } else {
          MirrorflyUikit.instance.navigationManager.navigateBack(context: context);
        }
      } else {
        //Get.offNamed(getInitialRoute());
        Navigator.pop(context, true);
      }*/
    //Code Changed to above
    /*if (Get.previousRoute.isNotEmpty) {
        if (Get.currentRoute == Routes.onGoingCallView) {
          callTimer("Disconnected");
          Future.delayed(const Duration(seconds: 1), () {
            Get.back();
          });
        } else {
          Get.back();
        }
      } else {
        Get.offNamed(getInitialRoute());
      }*/
  }
}