-
Notifications
You must be signed in to change notification settings - Fork 260
fix(api): app life cycle 'resume' triggers web socket reconnection #5567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cb57276
fix(api): Reconnect websockets when unpausing app
tyllark 01bc094
chore(api): updated and added tests
tyllark 4810b7c
chore(api): fixed unit tests
tyllark cf8dc5e
chore(api): Fixed formatting
tyllark 70472e0
chore(api): Fixed formatting
tyllark 16c6702
chore(api): renamed ProcessUnpausedEvent to ProcessResumeEvent
tyllark 2e9cf8d
chore(api): auto reconnect is off and the state machine gets shutdown
tyllark 354635b
chore(api): replaced unpaused terminology with resumed
tyllark c8e8aa5
Merge branch 'main' into fix/app-life-cycle-datastore-websockets
tyllark b4b72d7
chore(api): replaced unpaused terminology with resumed
tyllark 8a4b142
Merge branch 'main' into fix/app-life-cycle-datastore-websockets
tyllark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.