1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00

Close remote peer connections on exit

This commit is contained in:
Pierre HUBERT 2020-04-20 17:47:51 +02:00
parent e05323c3bb
commit ee6509bb9a
2 changed files with 21 additions and 5 deletions

View File

@ -118,6 +118,8 @@ class _CallScreenState extends SafeState<CallScreen> {
// Connect to ready peers
for (final peer in _membersList.readyPeers)
await this._memberReady(peer.userID);
setState(() {});
} catch (e, stack) {
print("Could not initialize call! $e\n$stack");
setState(() => _error = true);
@ -129,6 +131,10 @@ class _CallScreenState extends SafeState<CallScreen> {
try {
// Leave the call
await CallsHelper.leave(convID);
// Close all ready members
for (final member in _membersList.readyPeers)
await _removeMember(member.userID);
} catch (e, stack) {
print("Could not end call properly! $e\n$stack");
}
@ -205,16 +211,22 @@ class _CallScreenState extends SafeState<CallScreen> {
}
/// Call this when a user has interrupted streaming
void _removeRemotePeerConnection(int memberID) {
Future<void> _removeRemotePeerConnection(int memberID) async {
_membersList.getUser(memberID).status = MemberStatus.JOINED;
setState(() {});
if (_peersConnections.containsKey(memberID)) {
await _peersConnections[memberID].close();
_peersConnections.remove(memberID);
}
}
/// Call this when a members has completely left the call
void _removeMember(int memberID) {
_removeRemotePeerConnection(memberID);
/// Call this when a member has completely left the call
Future<void> _removeMember(int memberID) async {
await _removeRemotePeerConnection(memberID);
_membersList.removeUser(memberID);
setState(() {});
}

View File

@ -10,8 +10,12 @@ import 'package:flutter/material.dart';
abstract class SafeState<T extends StatefulWidget> extends State<T> {
final _subscriptions = List<StreamSubscription>();
bool _unmounted = false;
@override
void dispose() {
_unmounted = true;
// Close subscriptions
_subscriptions.forEach((f) => f.cancel());
@ -20,7 +24,7 @@ abstract class SafeState<T extends StatefulWidget> extends State<T> {
@override
void setState(fn) {
if (mounted) super.setState(fn);
if (mounted && !_unmounted) super.setState(fn);
}
/// Register to a new subscription