Skip to content

Commit 23f911e

Browse files
authored
LiveQuery reconnecting intervals (#414)
* parseFileConstructor was missing at Parse.initialize * add liveListRetryIntervals to Parse.initialize
1 parent 6b6374b commit 23f911e

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,13 @@ LiveQuery server.
524524
liveQuery.client.unSubscribe(subscription);
525525
```
526526

527+
__Disconnection__
528+
In case the client's connection to the server breaks,
529+
LiveQuery will automatically try to reconnect.
530+
LiveQuery will wait at increasing intervals between reconnection attempts.
531+
By default, these intervals are set to `[0, 500, 1000, 2000, 5000, 10000]` for mobile and `[0, 500, 1000, 2000, 5000]` for web.
532+
You can change these by providing a custom list using the `liveListRetryIntervals` parameter at `Parse.initialize()` ("-1" means "do not try to reconnect").
533+
527534
## ParseLiveList
528535
ParseLiveList makes implementing a dynamic List as simple as possible.
529536

lib/parse_server_sdk.dart

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class Parse {
9595
CoreStore coreStore,
9696
Map<String, ParseObjectConstructor> registeredSubClassMap,
9797
ParseUserConstructor parseUserConstructor,
98+
ParseFileConstructor parseFileConstructor,
99+
List<int> liveListRetryIntervals,
98100
}) async {
99101
final String url = removeTrailingSlash(serverUrl);
100102

@@ -112,6 +114,8 @@ class Parse {
112114
store: coreStore,
113115
registeredSubClassMap: registeredSubClassMap,
114116
parseUserConstructor: parseUserConstructor,
117+
parseFileConstructor: parseFileConstructor,
118+
liveListRetryIntervals: liveListRetryIntervals,
115119
);
116120

117121
_hasBeenInitialized = true;

lib/src/data/parse_core_data.dart

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ParseCoreData {
2929
Map<String, ParseObjectConstructor> registeredSubClassMap,
3030
ParseUserConstructor parseUserConstructor,
3131
ParseFileConstructor parseFileConstructor,
32+
List<int> liveListRetryIntervals,
3233
}) async {
3334
_instance = ParseCoreData._init(appId, serverUrl);
3435

@@ -59,6 +60,13 @@ class ParseCoreData {
5960
if (securityContext != null) {
6061
_instance.securityContext = securityContext;
6162
}
63+
if (liveListRetryIntervals != null) {
64+
_instance.liveListRetryIntervals = liveListRetryIntervals;
65+
} else {
66+
_instance.liveListRetryIntervals = kIsWeb
67+
? <int>[0, 500, 1000, 2000, 5000]
68+
: <int>[0, 500, 1000, 2000, 5000, 10000];
69+
}
6270

6371
_instance._subClassHandler = ParseSubClassHandler(
6472
registeredSubClassMap: registeredSubClassMap,
@@ -79,6 +87,7 @@ class ParseCoreData {
7987
bool debug;
8088
CoreStore storage;
8189
ParseSubClassHandler _subClassHandler;
90+
List<int> liveListRetryIntervals;
8291

8392
void registerSubClass(
8493
String className, ParseObjectConstructor objectConstructor) {

lib/src/network/parse_live_query.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ class LiveQueryReconnectingController with WidgetsBindingObserver {
7676
WidgetsBinding.instance.addObserver(this);
7777
}
7878

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

8382
final Function _reconnect;

lib/src/network/parse_live_query_web.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ class LiveQueryReconnectingController with WidgetsBindingObserver {
7171
WidgetsBinding.instance.addObserver(this);
7272
}
7373

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

7877
final Function _reconnect;

0 commit comments

Comments
 (0)