Skip to content

Commit ea71067

Browse files
fix: handle failed to create RTCPeerConnection object error in a call
1 parent 352b3fa commit ea71067

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ coverage/
1818
coverage_badge.svg
1919
coverage.xml
2020
TEST-report.*
21+
coverage_dir/*
2122

2223
# IntelliJ related
2324
*.iml

lib/src/voip/call_session.dart

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ class CallSession {
207207
// outgoing call
208208
Future<void> initOutboundCall(CallType type) async {
209209
await _preparePeerConnection();
210+
if (pc == null) {
211+
return;
212+
}
210213
setCallState(CallState.kCreateOffer);
211214
final stream = await _getUserMedia(type);
212215
if (stream != null) {
@@ -262,6 +265,10 @@ class CallSession {
262265
}
263266

264267
await _preparePeerConnection();
268+
if (pc == null) {
269+
return;
270+
}
271+
265272
if (metadata != null) {
266273
_updateRemoteSDPStreamMetadata(metadata);
267274
}
@@ -357,6 +364,10 @@ class CallSession {
357364
// create the peer connection now so it can be gathering candidates while we get user
358365
// media (assuming a candidate pool size is configured)
359366
await _preparePeerConnection();
367+
if (pc == null) {
368+
return;
369+
}
370+
360371
await gotCallFeedsForInvite(
361372
callFeeds,
362373
requestScreenSharing: requestScreenSharing,
@@ -1218,7 +1229,8 @@ class CallSession {
12181229
}
12191230
};
12201231
} catch (e) {
1221-
Logs().v('[VOIP] prepareMediaStream error => ${e.toString()}');
1232+
Logs().v('[VOIP] preparePeerConnection error => ${e.toString()}');
1233+
await _createPeerConnectionFailed(e);
12221234
}
12231235
}
12241236

@@ -1454,10 +1466,19 @@ class CallSession {
14541466
}
14551467
}
14561468

1469+
Future<void> _createPeerConnectionFailed(dynamic err) async {
1470+
Logs().e('Failed to create peer connection object ${err.toString()}');
1471+
fireCallEvent(CallStateChange.kError);
1472+
await terminate(
1473+
CallParty.kLocal,
1474+
CallErrorCode.createPeerConnectionFailed,
1475+
true,
1476+
);
1477+
}
1478+
14571479
Future<void> _getLocalOfferFailed(dynamic err) async {
14581480
Logs().e('Failed to get local offer ${err.toString()}');
14591481
fireCallEvent(CallStateChange.kError);
1460-
14611482
await terminate(CallParty.kLocal, CallErrorCode.localOfferFailed, true);
14621483
}
14631484

lib/src/voip/utils/types.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ enum CallErrorCode {
4040
/// The user chose to end the call
4141
userHangup('user_hangup'),
4242

43+
/// An error code when creating peer connection object fails locally.
44+
createPeerConnectionFailed('create_peer_connection_failed'),
45+
4346
/// An error code when the local client failed to create an offer.
4447
localOfferFailed('local_offer_failed'),
4548

0 commit comments

Comments
 (0)