From 32ba85dc743287739156c9dd295fa74537e46954 Mon Sep 17 00:00:00 2001 From: td Date: Wed, 12 Apr 2023 16:36:05 +0530 Subject: [PATCH] chore: stopMediaStream on all streams and make sure dispose runs everytime --- lib/src/voip/call.dart | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/src/voip/call.dart b/lib/src/voip/call.dart index f59537d7..0dff8873 100644 --- a/lib/src/voip/call.dart +++ b/lib/src/voip/call.dart @@ -102,15 +102,15 @@ class WrappedMediaStream { Future dispose() async { renderer.srcObject = null; - if (isLocal()) { - if (isWeb) { - await stopMediaStream(stream); - } else { - if (!isGroupCall) { - await stopMediaStream(stream); - } - } + + /// libwebrtc does not provide a way to clone MediaStreams. So stopping the + /// local stream here would break calls with all other participants if anyone + /// leaves. The local stream is manually disposed when user leaves. On web + /// streams are actually cloned. + if (!isGroupCall || isWeb) { + await stopMediaStream(stream); } + stream = null; await renderer.dispose(); } @@ -1386,12 +1386,17 @@ class CallSession { await stream.dispose(); } streams.clear(); + } catch (e) { + Logs().e('[VOIP] cleaning up streams failed', e); + } + + try { if (pc != null) { await pc!.close(); await pc!.dispose(); } } catch (e) { - Logs().e('cleaning up streams failed', e); + Logs().e('[VOIP] removing pc failed', e); } }