diff --git a/README.md b/README.md index f029e43e5..e30959fd3 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/parse_server_sdk.dart b/lib/parse_server_sdk.dart index 93fca240f..825fa4a7c 100644 --- a/lib/parse_server_sdk.dart +++ b/lib/parse_server_sdk.dart @@ -95,6 +95,8 @@ class Parse { CoreStore coreStore, Map registeredSubClassMap, ParseUserConstructor parseUserConstructor, + ParseFileConstructor parseFileConstructor, + List liveListRetryIntervals, }) async { final String url = removeTrailingSlash(serverUrl); @@ -112,6 +114,8 @@ class Parse { store: coreStore, registeredSubClassMap: registeredSubClassMap, parseUserConstructor: parseUserConstructor, + parseFileConstructor: parseFileConstructor, + liveListRetryIntervals: liveListRetryIntervals, ); _hasBeenInitialized = true; diff --git a/lib/src/data/parse_core_data.dart b/lib/src/data/parse_core_data.dart index 47b7f1a02..b97f13ed4 100644 --- a/lib/src/data/parse_core_data.dart +++ b/lib/src/data/parse_core_data.dart @@ -29,6 +29,7 @@ class ParseCoreData { Map registeredSubClassMap, ParseUserConstructor parseUserConstructor, ParseFileConstructor parseFileConstructor, + List liveListRetryIntervals, }) async { _instance = ParseCoreData._init(appId, serverUrl); @@ -59,6 +60,13 @@ class ParseCoreData { if (securityContext != null) { _instance.securityContext = securityContext; } + if (liveListRetryIntervals != null) { + _instance.liveListRetryIntervals = liveListRetryIntervals; + } else { + _instance.liveListRetryIntervals = kIsWeb + ? [0, 500, 1000, 2000, 5000] + : [0, 500, 1000, 2000, 5000, 10000]; + } _instance._subClassHandler = ParseSubClassHandler( registeredSubClassMap: registeredSubClassMap, @@ -79,6 +87,7 @@ class ParseCoreData { bool debug; CoreStore storage; ParseSubClassHandler _subClassHandler; + List liveListRetryIntervals; void registerSubClass( String className, ParseObjectConstructor objectConstructor) { diff --git a/lib/src/network/parse_live_query.dart b/lib/src/network/parse_live_query.dart index 88aa868df..ca90110c0 100644 --- a/lib/src/network/parse_live_query.dart +++ b/lib/src/network/parse_live_query.dart @@ -76,8 +76,7 @@ class LiveQueryReconnectingController with WidgetsBindingObserver { WidgetsBinding.instance.addObserver(this); } - // -1 means "do not try to reconnect", - static const List retryInterval = [0, 500, 1000, 2000, 5000, 10000]; + static List get retryInterval => ParseCoreData().liveListRetryIntervals; static const String DEBUG_TAG = 'LiveQueryReconnectingController'; final Function _reconnect; diff --git a/lib/src/network/parse_live_query_web.dart b/lib/src/network/parse_live_query_web.dart index d9a6f7602..6d9012785 100644 --- a/lib/src/network/parse_live_query_web.dart +++ b/lib/src/network/parse_live_query_web.dart @@ -71,8 +71,7 @@ class LiveQueryReconnectingController with WidgetsBindingObserver { WidgetsBinding.instance.addObserver(this); } - // -1 means "do not try to reconnect", - static const List retryInterval = [0, 500, 1000, 2000, 5000]; + static List get retryInterval => ParseCoreData().liveListRetryIntervals; static const String DEBUG_TAG = 'LiveQueryReconnectingController'; final Function _reconnect;