-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-18/"/> | ||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/> | ||
<classpathentry kind="output" path="bin/default"/> | ||
</classpath> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import 'package:retry/retry.dart'; | ||
|
||
/// Configuration options for GraphQL Subscriptions and their WebSockets. | ||
class GraphQLSubscriptionOptions { | ||
/// Configure the ping interval for AppSync polling for subscription connections. | ||
final Duration? pingInterval; | ||
|
||
/// Configure the exponential retry strategy options | ||
/// see: https://pub.dev/documentation/retry/latest/retry/RetryOptions-class.html | ||
final RetryOptions? retryOptions; | ||
|
||
const GraphQLSubscriptionOptions({this.pingInterval, this.retryOptions}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import 'package:amplify_core/amplify_core.dart'; | ||
|
||
class ApiHubEvent extends HubEvent<ApiHubEventPayload> { | ||
ApiHubEvent( | ||
super.eventName, { | ||
super.payload, | ||
}); | ||
} | ||
|
||
abstract class ApiHubEventPayload { | ||
const ApiHubEventPayload(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/* | ||
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import 'package:amplify_core/amplify_core.dart'; | ||
|
||
/// {@template amplify_common.hub.api_network_state} | ||
/// Network states for graphql subscriptions. | ||
/// {@endtemplate} | ||
enum NetworkState { | ||
/// {@macro amplify_common.hub.api_network_state_connected} | ||
connected, | ||
|
||
/// {@macro amplify_common.hub.api_network_state_disconnected} | ||
disconnected, | ||
|
||
/// {@macro amplify_common.hub.api_network_state_failed} | ||
failed; | ||
} | ||
|
||
/// {@template amplify_common.hub.api_intended_state} | ||
/// The intended network states for graphql subscriptions. | ||
/// {@endtemplate} | ||
enum IntendedState { | ||
/// {@macro amplify_common.hub.api_intended_state_connected} | ||
connected, | ||
|
||
/// {@macro amplify_common.hub.api_intended_state_disconnected} | ||
disconnected; | ||
} | ||
|
||
/// {@template amplify_common.hub.api_subscription_status} | ||
/// A consolidated subscription connection status determined by the network and | ||
/// intended states. | ||
/// {@endtemplate} | ||
enum SubscriptionStatus { | ||
/// {@macro amplify_common.hub.api_subscription_status_connected} | ||
connected, | ||
|
||
/// {@macro amplify_common.hub.api_subscription_status_disconnected} | ||
disconnected, | ||
|
||
/// {@macro amplify_common.hub.api_subscription_status_connected} | ||
connecting, | ||
|
||
/// {@macro amplify_common.hub.api_subscription_status_disconnected} | ||
pendingDisconnected, | ||
|
||
/// {@macro amplify_common.hub.api_subscription_status_failed} | ||
failed; | ||
} | ||
|
||
class SubscriptionDetails extends ApiHubEventPayload | ||
with | ||
AWSEquatable<SubscriptionDetails>, | ||
AWSSerializable<Map<String, Object?>>, | ||
AWSDebuggable { | ||
/// {@macro amplify_common.hub.api_network_state} | ||
final NetworkState networkState; | ||
|
||
/// {@macro amplify_common.hub.api_intended_state} | ||
final IntendedState intendedState; | ||
|
||
SubscriptionDetails(this.networkState, this.intendedState); | ||
|
||
@override | ||
List<Object?> get props => [intendedState, networkState]; | ||
|
||
@override | ||
Map<String, String> toJson() => { | ||
'networkState': networkState.name, | ||
'intendedState': intendedState.name, | ||
}; | ||
|
||
@override | ||
String get runtimeTypeName => 'SubscriptionDetails'; | ||
} | ||
|
||
class SubscriptionHubEvent extends ApiHubEvent | ||
with | ||
AWSEquatable<SubscriptionHubEvent>, | ||
AWSSerializable<Map<String, Object?>>, | ||
AWSDebuggable { | ||
final SubscriptionDetails details; | ||
|
||
static const String _name = 'SubscriptionHubEvent'; | ||
|
||
SubscriptionHubEvent._(this.details) : super(_name, payload: details); | ||
|
||
/// {@template amplify_common.hub.api_subscription_status} | ||
/// An overall status for GraphQL subscription connection, determined by the | ||
/// underlying details [networkState] & [intendedState] | ||
/// {@endtemplate} | ||
SubscriptionStatus get status { | ||
// Connection failed | ||
if (details.networkState == NetworkState.failed) { | ||
return SubscriptionStatus.failed; | ||
} | ||
// Connected with active subscriptions | ||
if (details.networkState == NetworkState.connected && | ||
details.intendedState == IntendedState.connected) { | ||
return SubscriptionStatus.connected; | ||
} | ||
// Disconnected with active subscriptions | ||
if (details.networkState == NetworkState.disconnected && | ||
details.intendedState == IntendedState.connected) { | ||
return SubscriptionStatus.connecting; | ||
} | ||
// Connected without active subscriptions | ||
if (details.networkState == NetworkState.connected && | ||
details.intendedState == IntendedState.disconnected) { | ||
return SubscriptionStatus.pendingDisconnected; | ||
} | ||
|
||
// disconnected without active subscriptions | ||
return SubscriptionStatus.disconnected; | ||
} | ||
|
||
/// {@template amplify_common.hub.api_subscription_connected} | ||
/// Emitted when a GraphQL subscription is connected. | ||
/// {@endtemplate} | ||
SubscriptionHubEvent.connected() | ||
: this._(SubscriptionDetails( | ||
NetworkState.connected, IntendedState.connected)); | ||
|
||
/// {@template amplify_common.hub.api_subscription_connected} | ||
/// Emitted when a GraphQL subscription is connecting/reconnecting. | ||
/// {@endtemplate} | ||
SubscriptionHubEvent.connecting() | ||
: this._(SubscriptionDetails( | ||
NetworkState.disconnected, IntendedState.connected)); | ||
|
||
/// {@template amplify_common.hub.api_subscription_disconnected} | ||
/// Emitted when a GraphQL subscription connection has disconnected. | ||
/// {@endtemplate} | ||
SubscriptionHubEvent.disconnected() | ||
: this._(SubscriptionDetails( | ||
NetworkState.disconnected, IntendedState.disconnected)); | ||
|
||
/// {@template amplify_common.hub.api_subscription_pending_disconnect} | ||
/// Emitted when a GraphQL subscription connection is pending disconnect, | ||
/// but should exist. | ||
/// {@endtemplate} | ||
SubscriptionHubEvent.pendingDisconnect() | ||
: this._(SubscriptionDetails( | ||
NetworkState.connected, IntendedState.disconnected)); | ||
|
||
/// {@template amplify_common.hub.api_subscription_failed} | ||
/// Emitted when a GraphQL subscription connection has failed. | ||
/// {@endtemplate} | ||
SubscriptionHubEvent.failed() | ||
: this._(SubscriptionDetails( | ||
NetworkState.failed, IntendedState.disconnected)); | ||
|
||
@override | ||
List<Object?> get props => [details, status]; | ||
|
||
@override | ||
String get runtimeTypeName => 'SubscriptionHubEvent'; | ||
|
||
@override | ||
Map<String, Object?> toJson() => <String, dynamic>{ | ||
'status': status.name, | ||
'details': details.toJson(), | ||
}; | ||
} |