Skip to content

LiveQuery reconnecting intervals #414

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,13 @@ LiveQuery server.
liveQuery.client.unSubscribe(subscription);
```

__Disconnection__
In case the client's connection to the server breaks,
LiveQuery will automatically try to reconnect.
LiveQuery will wait at increasing intervals between reconnection attempts.
By default, these intervals are set to `[0, 500, 1000, 2000, 5000, 10000]` for mobile and `[0, 500, 1000, 2000, 5000]` for web.
You can change these by providing a custom list using the `liveListRetryIntervals` parameter at `Parse.initialize()` ("-1" means "do not try to reconnect").

## ParseLiveList
ParseLiveList makes implementing a dynamic List as simple as possible.

Expand Down
4 changes: 4 additions & 0 deletions lib/parse_server_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class Parse {
CoreStore coreStore,
Map<String, ParseObjectConstructor> registeredSubClassMap,
ParseUserConstructor parseUserConstructor,
ParseFileConstructor parseFileConstructor,
List<int> liveListRetryIntervals,
}) async {
final String url = removeTrailingSlash(serverUrl);

Expand All @@ -112,6 +114,8 @@ class Parse {
store: coreStore,
registeredSubClassMap: registeredSubClassMap,
parseUserConstructor: parseUserConstructor,
parseFileConstructor: parseFileConstructor,
liveListRetryIntervals: liveListRetryIntervals,
);

_hasBeenInitialized = true;
Expand Down
9 changes: 9 additions & 0 deletions lib/src/data/parse_core_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ParseCoreData {
Map<String, ParseObjectConstructor> registeredSubClassMap,
ParseUserConstructor parseUserConstructor,
ParseFileConstructor parseFileConstructor,
List<int> liveListRetryIntervals,
}) async {
_instance = ParseCoreData._init(appId, serverUrl);

Expand Down Expand Up @@ -59,6 +60,13 @@ class ParseCoreData {
if (securityContext != null) {
_instance.securityContext = securityContext;
}
if (liveListRetryIntervals != null) {
_instance.liveListRetryIntervals = liveListRetryIntervals;
} else {
_instance.liveListRetryIntervals = kIsWeb
? <int>[0, 500, 1000, 2000, 5000]
: <int>[0, 500, 1000, 2000, 5000, 10000];
}

_instance._subClassHandler = ParseSubClassHandler(
registeredSubClassMap: registeredSubClassMap,
Expand All @@ -79,6 +87,7 @@ class ParseCoreData {
bool debug;
CoreStore storage;
ParseSubClassHandler _subClassHandler;
List<int> liveListRetryIntervals;

void registerSubClass(
String className, ParseObjectConstructor objectConstructor) {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/network/parse_live_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class LiveQueryReconnectingController with WidgetsBindingObserver {
WidgetsBinding.instance.addObserver(this);
}

// -1 means "do not try to reconnect",
static const List<int> retryInterval = <int>[0, 500, 1000, 2000, 5000, 10000];
static List<int> get retryInterval => ParseCoreData().liveListRetryIntervals;
static const String DEBUG_TAG = 'LiveQueryReconnectingController';

final Function _reconnect;
Expand Down
3 changes: 1 addition & 2 deletions lib/src/network/parse_live_query_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ class LiveQueryReconnectingController with WidgetsBindingObserver {
WidgetsBinding.instance.addObserver(this);
}

// -1 means "do not try to reconnect",
static const List<int> retryInterval = <int>[0, 500, 1000, 2000, 5000];
static List<int> get retryInterval => ParseCoreData().liveListRetryIntervals;
static const String DEBUG_TAG = 'LiveQueryReconnectingController';

final Function _reconnect;
Expand Down