-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): Reconnect WebSocket when resuming app from a paused state (#…
…5567) * fix(api): Reconnect WebSocket when resuming app from a paused state
- Loading branch information
Showing
11 changed files
with
365 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:amplify_api_dart/amplify_api_dart.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
/// {@template amplify_api.flutter_life_cycle} | ||
/// Creates a stream of [ProcessStatus] mapped from [AppLifecycleListener](https://api.flutter.dev/flutter/widgets/AppLifecycleListener-class.html). | ||
/// {@endtemplate} | ||
@internal | ||
class FlutterLifeCycle extends ProcessLifeCycle { | ||
/// {@macro amplify_api.flutter_life_cycle} | ||
FlutterLifeCycle() { | ||
AppLifecycleListener( | ||
onStateChange: _onStateChange, | ||
); | ||
} | ||
|
||
final _stateController = | ||
StreamController<ProcessStatus>.broadcast(sync: true); | ||
|
||
@override | ||
Stream<ProcessStatus> get onStateChanged => _stateController.stream; | ||
|
||
void _onStateChange(AppLifecycleState state) { | ||
switch (state) { | ||
case AppLifecycleState.detached: | ||
_stateController.add(ProcessStatus.detached); | ||
case AppLifecycleState.paused: | ||
_stateController.add(ProcessStatus.paused); | ||
case AppLifecycleState.hidden: | ||
_stateController.add(ProcessStatus.hidden); | ||
case AppLifecycleState.inactive: | ||
_stateController.add(ProcessStatus.inactive); | ||
case AppLifecycleState.resumed: | ||
_stateController.add(ProcessStatus.resumed); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/api/amplify_api_dart/lib/src/graphql/web_socket/types/process_life_cycle.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/// Possible process life cycle states | ||
enum ProcessStatus { | ||
/// Engine is running without a view. | ||
detached, | ||
|
||
/// Application is not visible to the user or responding to user input. | ||
paused, | ||
|
||
/// All views of an application are hidden. | ||
hidden, | ||
|
||
/// A view of the application is visible, but none have input. | ||
inactive, | ||
|
||
/// Default running mode. | ||
resumed, | ||
} | ||
|
||
/// {@template amplify_api_dart.process_life_cycle} | ||
/// Used to create a stream representing the process life cycle state. | ||
/// | ||
/// The generated stream is empty. | ||
/// {@endtemplate} | ||
class ProcessLifeCycle { | ||
/// {@macro amplify_api_dart.process_life_cycle} | ||
const ProcessLifeCycle(); | ||
|
||
/// Generates a new stream of [ProcessStatus]. | ||
Stream<ProcessStatus> get onStateChanged => const Stream.empty(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.