2022-11-19 15:36:29 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
2022-12-13 02:36:22 +00:00
|
|
|
import '../connection/ws_connection.dart';
|
|
|
|
|
2022-11-19 15:36:29 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-05-19 15:22:06 +00:00
|
|
|
void connect(String? passphrase) {
|
|
|
|
ServerConnection.getInstance().connect(passphrase);
|
2023-06-29 23:49:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void opponentConnected() {
|
2022-11-19 15:36:29 +00:00
|
|
|
emit(ConnectionCubitState(true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ConnectionCubitState {
|
2023-06-29 23:49:18 +00:00
|
|
|
final bool opponentConnected;
|
2022-11-19 15:36:29 +00:00
|
|
|
|
2023-06-29 23:49:18 +00:00
|
|
|
ConnectionCubitState(this.opponentConnected);
|
2022-11-19 15:36:29 +00:00
|
|
|
|
|
|
|
factory ConnectionCubitState.init() {
|
|
|
|
return ConnectionCubitState(false);
|
|
|
|
}
|
|
|
|
}
|