Marco
adf8c86692
1. A game is only identified by a passphrase (not a lobby id) 2. We can store multiple passphrase/playerID combinations
40 lines
919 B
Dart
40 lines
919 B
Dart
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import '../connection/ws_connection.dart';
|
|
|
|
class ConnectionCubit extends Cubit<ConnectionCubitState> {
|
|
static final ConnectionCubit _instance = ConnectionCubit._internal();
|
|
|
|
ConnectionCubit._internal() : super(ConnectionCubitState.init());
|
|
|
|
factory ConnectionCubit.getInstance() {
|
|
return ConnectionCubit();
|
|
}
|
|
|
|
factory ConnectionCubit() {
|
|
return _instance;
|
|
}
|
|
|
|
void connect(String playerID, String? passphrase) {
|
|
ServerConnection.getInstance().connect(playerID, passphrase);
|
|
}
|
|
|
|
void disonnect() {
|
|
ServerConnection.getInstance().disconnectExistingConnection();
|
|
}
|
|
|
|
void opponentConnected() {
|
|
emit(ConnectionCubitState(true));
|
|
}
|
|
}
|
|
|
|
class ConnectionCubitState {
|
|
final bool opponentConnected;
|
|
|
|
ConnectionCubitState(this.opponentConnected);
|
|
|
|
factory ConnectionCubitState.init() {
|
|
return ConnectionCubitState(false);
|
|
}
|
|
}
|