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

fix: handle failed to create RTCPeerConnection object error in a call #2011

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ coverage/
coverage_badge.svg
coverage.xml
TEST-report.*
coverage_dir/*

# IntelliJ related
*.iml
Expand Down
25 changes: 23 additions & 2 deletions lib/src/voip/call_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ class CallSession {
// outgoing call
Future<void> initOutboundCall(CallType type) async {
await _preparePeerConnection();
if (pc == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't _preparePeerConnection just rethrow? i.e can you even do anything without a pc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you can't do anything without a pc. That's why it's terminating the call with an error code. Do check the createPeerConnection function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so instead of duplicating the early returns, couldn't we just do it in _preparePeerConnection when createPeerConnection throws and then rethrow?

return;
}
setCallState(CallState.kCreateOffer);
final stream = await _getUserMedia(type);
if (stream != null) {
Expand Down Expand Up @@ -262,6 +265,10 @@ class CallSession {
}

await _preparePeerConnection();
if (pc == null) {
return;
}

if (metadata != null) {
_updateRemoteSDPStreamMetadata(metadata);
}
Expand Down Expand Up @@ -357,6 +364,10 @@ class CallSession {
// create the peer connection now so it can be gathering candidates while we get user
// media (assuming a candidate pool size is configured)
await _preparePeerConnection();
if (pc == null) {
return;
}

await gotCallFeedsForInvite(
callFeeds,
requestScreenSharing: requestScreenSharing,
Expand Down Expand Up @@ -1218,7 +1229,8 @@ class CallSession {
}
};
} catch (e) {
Logs().v('[VOIP] prepareMediaStream error => ${e.toString()}');
Logs().v('[VOIP] preparePeerConnection error => ${e.toString()}');
await _createPeerConnectionFailed(e);
}
}

Expand Down Expand Up @@ -1454,10 +1466,19 @@ class CallSession {
}
}

Future<void> _createPeerConnectionFailed(dynamic err) async {
Logs().e('Failed to create peer connection object ${err.toString()}');
fireCallEvent(CallStateChange.kError);
await terminate(
CallParty.kLocal,
CallErrorCode.createPeerConnectionFailed,
true,
);
}

Future<void> _getLocalOfferFailed(dynamic err) async {
Logs().e('Failed to get local offer ${err.toString()}');
fireCallEvent(CallStateChange.kError);

await terminate(CallParty.kLocal, CallErrorCode.localOfferFailed, true);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/src/voip/utils/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ enum CallErrorCode {
/// The user chose to end the call
userHangup('user_hangup'),

/// An error code when creating peer connection object fails locally.
createPeerConnectionFailed('create_peer_connection_failed'),

/// An error code when the local client failed to create an offer.
localOfferFailed('local_offer_failed'),

Expand Down