Merged
Show file tree
Hide file tree
Changes from 5 commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
Original file line numberDiff line numberDiff line change
Expand Up@@ -315,6 +315,8 @@ class FirebaseFirestore extends FirebasePluginPlatform {
persistenceEnabled: settings.persistenceEnabled,
host: settings.host,
cacheSizeBytes: settings.cacheSizeBytes,
webExperimentalForceLongPolling: settings.webExperimentalForceLongPolling,
webExperimentalAutoDetectLongPolling: settings.webExperimentalAutoDetectLongPolling,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing timeoutSeconds exposed in the user facing lib. I think it should be hidden being an objet like in the original web SDK. experimentalLongPollingOptions

);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,9 @@ class Settings {
this.host,
this.sslEnabled,
this.cacheSizeBytes,
this.webExperimentalForceLongPolling = true,
this.webExperimentalAutoDetectLongPolling = true,
this.timeoutSeconds = 30,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably not set any default so we can rely on the default value of the underlying JS SDK.

this.ignoreUndefinedProperties = false,
});

Expand DownExpand Up@@ -51,13 +54,41 @@ class Settings {
/// Web only.
final bool ignoreUndefinedProperties;

/// Forces the SDK’s underlying network transport (WebChannel) to use long-polling.
///
/// Each response from the backend will be closed immediately after the backend sends data
/// (by default responses are kept open in case the backend has more data to send).
/// This avoids incompatibility issues with certain proxies, antivirus software, etc.
/// that incorrectly buffer traffic indefinitely.
/// Use of this option will cause some performance degradation though.
final bool webExperimentalForceLongPolling;

/// Configures the SDK's underlying transport (WebChannel) to automatically detect if long-polling should be used.
///
///This is very similar to [webExperimentalForceLongPolling], but only uses long-polling if required.
final bool webExperimentalAutoDetectLongPolling;

/// The desired maximum timeout interval, in seconds, to complete a long-polling GET response
///
/// Valid values are between 5 and 30, inclusive.
/// By default, when long-polling is used the "hanging GET" request sent by the client times out after 30 seconds.
/// To request a different timeout from the server, set this setting with the desired timeout.
/// Changing the default timeout may be useful, for example,
/// if the buffering proxy that necessitated enabling long-polling in the first place has a shorter timeout for hanging GET requests,
/// in which case setting the long-polling timeout to a shorter value,
/// such as 25 seconds, may fix prematurely-closed hanging GET requests.
final int timeoutSeconds;

/// Returns the settings as a [Map]
Map<String, dynamic> get asMap {
return {
'persistenceEnabled': persistenceEnabled,
'host': host,
'sslEnabled': sslEnabled,
'cacheSizeBytes': cacheSizeBytes,
'webExperimentalForceLongPolling': webExperimentalForceLongPolling,
'webExperimentalAutoDetectLongPolling': webExperimentalAutoDetectLongPolling,
'timeoutSeconds': timeoutSeconds,
if (kIsWeb) 'ignoreUndefinedProperties': ignoreUndefinedProperties,
};
}
Expand All@@ -67,7 +98,10 @@ class Settings {
String? host,
bool? sslEnabled,
int? cacheSizeBytes,
bool? webExperimentalForceLongPolling,
bool? webExperimentalAutoDetectLongPolling,
bool? ignoreUndefinedProperties,
int? timeoutSeconds,
}) {
assert(
cacheSizeBytes == null ||
Expand All@@ -81,6 +115,9 @@ class Settings {
host: host ?? this.host,
sslEnabled: sslEnabled ?? this.sslEnabled,
cacheSizeBytes: cacheSizeBytes ?? this.cacheSizeBytes,
webExperimentalForceLongPolling: webExperimentalForceLongPolling ?? this.webExperimentalForceLongPolling,
webExperimentalAutoDetectLongPolling: webExperimentalAutoDetectLongPolling ?? this.webExperimentalAutoDetectLongPolling,
timeoutSeconds: timeoutSeconds ?? this.timeoutSeconds,
ignoreUndefinedProperties:
ignoreUndefinedProperties ?? this.ignoreUndefinedProperties,
);
Expand All@@ -94,6 +131,9 @@ class Settings {
other.host == host &&
other.sslEnabled == sslEnabled &&
other.cacheSizeBytes == cacheSizeBytes &&
other.webExperimentalForceLongPolling == webExperimentalForceLongPolling &&
other.webExperimentalAutoDetectLongPolling == webExperimentalAutoDetectLongPolling &&
other.timeoutSeconds == timeoutSeconds &&
other.ignoreUndefinedProperties == ignoreUndefinedProperties;

@override
Expand All@@ -103,6 +143,8 @@ class Settings {
host,
sslEnabled,
cacheSizeBytes,
webExperimentalForceLongPolling,
webExperimentalAutoDetectLongPolling,
ignoreUndefinedProperties,
);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,17 +11,22 @@ void main() {
test('equality', () {
expect(
const Settings(
persistenceEnabled: true,
host: 'foo bar',
sslEnabled: true,
cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED,
),
persistenceEnabled: true,
host: 'foo bar',
sslEnabled: true,
webExperimentalForceLongPolling: false,
webExperimentalAutoDetectLongPolling: false,
cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED,
timeoutSeconds: 25),
equals(
const Settings(
persistenceEnabled: true,
host: 'foo bar',
sslEnabled: true,
webExperimentalForceLongPolling: false,
webExperimentalAutoDetectLongPolling: false,
cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED,
timeoutSeconds: 25,
),
),
);
Expand DownExpand Up@@ -49,6 +54,9 @@ void main() {
persistenceEnabled: true,
host: 'foo bar',
sslEnabled: true,
webExperimentalAutoDetectLongPolling: false,
webExperimentalForceLongPolling: false,
timeoutSeconds: 25,
cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED,
);

Expand All@@ -60,7 +68,9 @@ void main() {
'persistenceEnabled': null,
'host': null,
'sslEnabled': null,
'cacheSizeBytes': null
'cacheSizeBytes': null,
'webExperimentalForceLongPolling': true,
'webExperimentalAutoDetectLongPolling': true
});

expect(
Expand All@@ -75,6 +85,8 @@ void main() {
'host': 'foo bar',
'sslEnabled': true,
'cacheSizeBytes': Settings.CACHE_SIZE_UNLIMITED,
'webExperimentalForceLongPolling': true,
'webExperimentalAutoDetectLongPolling': true,
});
});

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -719,6 +719,9 @@ abstract class FirestoreSettings {
JSString? host,
JSBoolean? ssl,
JSBoolean? ignoreUndefinedProperties,
JSBoolean? experimentalForceLongPolling,
JSBoolean? experimentalAutoDetectLongPolling,
JSObject? experimentalLongPollingOptions,
JSObject localCache,
});
}
Expand DownExpand Up@@ -748,6 +751,34 @@ extension FirestoreSettingsExtension on FirestoreSettings {
external set localCache(JSObject u);
}

/// Options that configure the SDK’s underlying network transport (WebChannel) when long-polling is used
/// These options are only used if experimentalForceLongPolling is true
/// or if experimentalAutoDetectLongPolling is true and the auto-detection determined that long-polling was needed.
/// Otherwise, these options have no effect.
@anonymous
@JS()
@staticInterop
abstract class ExperimentalLongPollingOptions {
external factory ExperimentalLongPollingOptions ({
JSNumber? timeoutSeconds,
});
}

extension ExperimentalLongPollingOptionsExtension on ExperimentalLongPollingOptions {
/// The desired maximum timeout interval, in seconds, to complete a long-polling GET response
/// Valid values are between 5 and 30, inclusive.
/// Floating point values are allowed and will be rounded to the nearest millisecond
/// By default, when long-polling is used the "hanging GET" request sent by the client times out after 30 seconds.
/// To request a different timeout from the server, set this setting with the desired timeout.
/// Changing the default timeout may be useful, for example,
/// if the buffering proxy that necessitated enabling long-polling in the first place has a shorter timeout for hanging GET requests,
/// in which case setting the long-polling timeout to a shorter value,
/// such as 25 seconds, may fix prematurely-closed hanging GET requests.
external JSNumber? get timeoutSeconds;

external set timeoutSeconds(JSNumber? v);
}

/// Union type from all supported SDK cache layer.
///
/// [MemoryLocalCache] and [MemoryCacheSettings] are the two only cache types supported by the SDK. Custom implementation is not supported.
Expand Down
Loading