Skip to content

Commit

Permalink
[Application] Crash fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Sep 7, 2022
1 parent 7c81991 commit b8c1bea
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions CastIt.Android/lib/application/server_ws/server_ws_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@ class ServerWsBloc extends Bloc<ServerWsEvent, ServerWsState> {
}

await _castItHub.disconnectFromHub(triggerEvent: false);
final updatedState = currentState.copyWith(
isConnectedToWs: false,
castItUrl: _settings.castItUrl,
connectionRetries: currentState.connectionRetries! + 1,
final updatedState = state.map(
loaded: (state) => state.copyWith(
isConnectedToWs: false,
castItUrl: _settings.castItUrl,
connectionRetries: currentState.connectionRetries! + 1,
),
loading: (_) => ServerWsState.loaded(
isConnectedToWs: false,
castItUrl: _settings.castItUrl,
connectionRetries: 0,
),
);
emit(updatedState);
});
Expand All @@ -41,6 +48,7 @@ class ServerWsBloc extends Bloc<ServerWsEvent, ServerWsState> {
if (!_castItHub.isConnected) {
await _castItHub.connectToHub();
}

final updatedState = ServerWsState.loaded(
castItUrl: _settings.castItUrl,
connectionRetries: 0,
Expand All @@ -51,10 +59,20 @@ class ServerWsBloc extends Bloc<ServerWsEvent, ServerWsState> {

on<_Disconnect>((event, emit) async {
await _castItHub.disconnectFromHub();
final updatedState = currentState.copyWith(
isConnectedToWs: false,
castItUrl: _settings.castItUrl,
connectionRetries: currentState.connectionRetries! + 1,
if (state is! _LoadedState) {
return;
}
final updatedState = state.map(
loading: (_) => ServerWsState.loaded(
isConnectedToWs: false,
castItUrl: _settings.castItUrl,
connectionRetries: 0,
),
loaded: (state) => state.copyWith(
isConnectedToWs: false,
castItUrl: _settings.castItUrl,
connectionRetries: currentState.connectionRetries! + 1,
),
);
emit(updatedState);
});
Expand Down

0 comments on commit b8c1bea

Please sign in to comment.