Skip to content

Commit 72aaf40

Browse files
authored
Merge pull request #27 from adeeteya/codex/fix-waiting-for-opponents-screen-issue
Fix host screen closing immediately
2 parents d4d5801 + f778d4c commit 72aaf40

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/p2p/p2p_manager.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class P2pManager {
2525
final _controller = StreamController<String>.broadcast();
2626
Stream<String> get messages => _controller.stream;
2727
void Function()? onOpponentLeft;
28+
bool _hadConnectedClient = false;
2829

2930
P2pManager.host() : isHost = true;
3031
P2pManager.client() : isHost = false;
@@ -38,7 +39,9 @@ class P2pManager {
3839
await _host!.initialize();
3940
_host!.streamReceivedTexts().listen(_controller.add);
4041
_host!.streamClientList().listen((clients) {
41-
if (clients.isEmpty) {
42+
if (clients.isNotEmpty) {
43+
_hadConnectedClient = true;
44+
} else if (_hadConnectedClient) {
4245
onOpponentLeft?.call();
4346
}
4447
});

0 commit comments

Comments
 (0)