We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents d4d5801 + f778d4c commit 72aaf40Copy full SHA for 72aaf40
1 file changed
lib/p2p/p2p_manager.dart
@@ -25,6 +25,7 @@ class P2pManager {
25
final _controller = StreamController<String>.broadcast();
26
Stream<String> get messages => _controller.stream;
27
void Function()? onOpponentLeft;
28
+ bool _hadConnectedClient = false;
29
30
P2pManager.host() : isHost = true;
31
P2pManager.client() : isHost = false;
@@ -38,7 +39,9 @@ class P2pManager {
38
39
await _host!.initialize();
40
_host!.streamReceivedTexts().listen(_controller.add);
41
_host!.streamClientList().listen((clients) {
- if (clients.isEmpty) {
42
+ if (clients.isNotEmpty) {
43
+ _hadConnectedClient = true;
44
+ } else if (_hadConnectedClient) {
45
onOpponentLeft?.call();
46
}
47
});
0 commit comments