Merged
Show file tree
Hide file tree
Changes from 1 commit
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
PrevPrevious commit
Next Next commit
feat(firestore, web): expose (webExperimentalAutoDetectLongPolling, w…
…ebExperimentalForceLongPolling, timeoutSeconds)
  • Loading branch information
@SelaseKay
SelaseKay committedAug 21, 2024
commit bfc142b2cdbd20fdea5b0a79ac2da45672e0b8be
Original file line numberDiff line numberDiff line change
Expand Up@@ -316,6 +316,7 @@ class FirebaseFirestore extends FirebasePluginPlatform {
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@@ -42,7 +42,7 @@ class FirestoreMessageCodec extends StandardMessageCodec {
static const int _kNegativeInfinity = 195;
static const int _kFirestoreInstance = 196;
static const int _kFirestoreQuery = 197;
static const int _kFirestoreSettings = 198;
static FirestoreSettingsconst int _k = 198;

static const Map<FieldValueType, int> _kFieldValueCodes =
<FieldValueType, int>{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@ class Settings {
this.sslEnabled,
this.cacheSizeBytes,
this.webExperimentalForceLongPolling = true,
this.webExperimentalAutoDetectLongPolling = true,
this.timeoutSeconds = 30,
this.ignoreUndefinedProperties = false,
});

Expand DownExpand Up@@ -61,6 +63,22 @@ class Settings {
/// 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 {
Expand All@@ -69,6 +87,8 @@ class Settings {
'sslEnabled': sslEnabled,
'cacheSizeBytes': cacheSizeBytes,
'webExperimentalForceLongPolling': webExperimentalForceLongPolling,
'webExperimentalAutoDetectLongPolling': webExperimentalAutoDetectLongPolling,
'timeoutSeconds': timeoutSeconds,
if (kIsWeb) 'ignoreUndefinedProperties': ignoreUndefinedProperties,
};
}
Expand All@@ -79,7 +99,9 @@ class Settings {
bool? sslEnabled,
int? cacheSizeBytes,
bool? webExperimentalForceLongPolling,
bool? webExperimentalAutoDetectLongPolling,
bool? ignoreUndefinedProperties,
int? timeoutSeconds,
}) {
assert(
cacheSizeBytes == null ||
Expand All@@ -94,6 +116,8 @@ class Settings {
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@@ -108,6 +132,8 @@ class Settings {
other.sslEnabled == sslEnabled &&
other.cacheSizeBytes == cacheSizeBytes &&
other.webExperimentalForceLongPolling == webExperimentalForceLongPolling &&
other.webExperimentalAutoDetectLongPolling == webExperimentalAutoDetectLongPolling &&
other.timeoutSeconds == timeoutSeconds &&
other.ignoreUndefinedProperties == ignoreUndefinedProperties;

@override
Expand All@@ -118,6 +144,7 @@ class Settings {
sslEnabled,
cacheSizeBytes,
webExperimentalForceLongPolling,
webExperimentalAutoDetectLongPolling,
ignoreUndefinedProperties,
);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,19 +11,22 @@ void main() {
test('equality', () {
expect(
const Settings(
persistenceEnabled: true,
host: 'foo bar',
sslEnabled: true,
webExperimentalForceLongPolling: false,
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@@ -51,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@@ -63,7 +69,8 @@ void main() {
'host': null,
'sslEnabled': null,
'cacheSizeBytes': null,
'webExperimentalForceLongPolling': true
'webExperimentalForceLongPolling': true,
'webExperimentalAutoDetectLongPolling': true
});

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

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -719,7 +719,9 @@ abstract class FirestoreSettings {
JSString? host,
JSBoolean? ssl,
JSBoolean? ignoreUndefinedProperties,
JSBoolean? webExperimentalForceLongPolling,
JSBoolean? experimentalForceLongPolling,
JSBoolean? experimentalAutoDetectLongPolling,
JSObject? experimentalLongPollingOptions,
JSObject localCache,
});
}
Expand DownExpand Up@@ -749,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