Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Way to Reconnect Call When Internet is Lost in sip_ua #504

Open
umaraslam-cs opened this issue Dec 2, 2024 · 4 comments
Open

No Way to Reconnect Call When Internet is Lost in sip_ua #504

umaraslam-cs opened this issue Dec 2, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@umaraslam-cs
Copy link

umaraslam-cs commented Dec 2, 2024

I have noticed that there is currently no clear way in the sip_ua package to handle scenarios where the internet connection is lost during an active call. Specifically, there seems to be no built-in mechanism to detect internet connectivity loss, attempt reconnection, and resume the call.

I attempted to use the renegotiate function as part of a custom reconnection logic. However, when this function is called after the internet is restored, it unexpectedly terminates the call on the other end instead of renegotiating the connection.

This behavior limits the usability of the library for handling real-world scenarios where network stability can fluctuate.

To Reproduce:
Steps to reproduce the behavior:

  1. Start an active call using the sip_ua library.
  2. Disconnect the internet during the call.
  3. Attempt to detect the internet restoration and use the renegotiate function to reconnect.

Expected behavior:
The call should be renegotiated, and the connection should be restored when the internet returns without terminating the call for the other participant.

Code Snippets:

@override
Future<void> callStateChanged(Call call, CallState callState) async {
  if (call.peerConnection != null) {
    monitorConnectionState(call);
  }
}

Timer? connectivityTimer;
int retryCount = 0;

void monitorConnectionState(Call call) {
  if (call.peerConnection?.connectionState == RTCPeerConnectionState.RTCPeerConnectionStateDisconnected) {
    startConnectivityCheck(call);
  }
}

void startConnectivityCheck(Call call) {
  stopConnectivityCheck();
  retryCount = 0;

  connectivityTimer = Timer.periodic(const Duration(seconds: 1), (timer) async {
    retryCount++;
    bool isInternetAvailable = await ConnectivityHelper.hasInternetConnection();

    if (isInternetAvailable) {
      stopConnectivityCheck();
      renegotiateCall(call);
    }

    if (retryCount >= 10) {
      stopConnectivityCheck();
      endCallDueToNetworkIssue();
    }
  });
}

void stopConnectivityCheck() {
  connectivityTimer?.cancel();
  connectivityTimer = null;
}

void renegotiateCall(Call call) {
  try {
    call.renegotiate(
      useUpdate: true,
      options: {'useUpdate': true},
      done: (response) {},
    );
  } catch (e) {}
}

void endCallDueToNetworkIssue() async {
  Provider.of<SipRegisterProvider>(context, listen: false).upDateSipCallSpeaker(false);
  await endAllCalls();
  if (Navigator.of(navigatorKey.currentContext!).canPop()) {
    Navigator.of(navigatorKey.currentContext!).pop();
  }
}

Request:

  1. Please provide a way to handle call reconnection gracefully when the internet is lost and restored.
  2. Clarify the intended behavior of the renegotiate function and how it should be used.
  3. If this is a bug, consider fixing the issue where the renegotiate function ends the call instead of restoring the connection.

Thank you for your support and this useful library!

System Infomation()
Flutter SDK Version: 3.24.4

@umaraslam-cs umaraslam-cs added the bug Something isn't working label Dec 2, 2024
@umaraslam-cs
Copy link
Author

umaraslam-cs commented Dec 5, 2024

@jbg @hiratake55 @ghenry @DooMMasteR @reduxdj Any help would be highly appreciated. Thank you

@VictorUvarov
Copy link
Contributor

I would look at the socket implementations and see if you can do anything about this and handle onDisconnect. There is already logic in retrying to connect.

@umaraslam-cs
Copy link
Author

Thank you for your response, @VictorUvarov. I look forward to hearing back from you.

@VictorUvarov
Copy link
Contributor

@umaraslam-cs You can take a look at this problem. Let me know what you discover and have tried.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants