Description
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:
- Start an active call using the sip_ua library.
- Disconnect the internet during the call.
- 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:
- Please provide a way to handle call reconnection gracefully when the internet is lost and restored.
- Clarify the intended behavior of the renegotiate function and how it should be used.
- 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