Skip to content

Commit 4f544d8

Browse files
committed
WIP
1 parent 433c8ba commit 4f544d8

File tree

10 files changed

+79
-11
lines changed

10 files changed

+79
-11
lines changed

packages/firebase/index.d.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7735,15 +7735,27 @@ declare namespace firebase.firestore {
77357735
* buffer traffic indefinitely. Use of this option will cause some
77367736
* performance degradation though.
77377737
*
7738-
* This setting may be removed in a future release. If you find yourself
7739-
* using it to work around a specific network reliability issue, please
7740-
* tell us about it in
7741-
* https://github.com/firebase/firebase-js-sdk/issues/1674.
7738+
* This setting cannot be used with experimentalAutodetectLongPolling and
7739+
* may be removed in a future release. If you find yourself using it to
7740+
* work around a specific network reliability issue, please tell us about
7741+
* it in https://github.com/firebase/firebase-js-sdk/issues/1674.
77427742
*
77437743
* @webonly
77447744
*/
77457745
experimentalForceLongPolling?: boolean;
77467746

7747+
/**
7748+
* Configures the SDK's underlying transport (WebChannel) to automatically detect if
7749+
* long-polling should be used and also update as the networking conditions change. This is
7750+
* very similar to experimentalForceLongPolling but does automatic detection.
7751+
*
7752+
* This setting cannot be used with experimentalForceLongPolling and may be removed in a future
7753+
* release.
7754+
*
7755+
* @webonly
7756+
*/
7757+
experimentalAutodetectLongPolling?: boolean;
7758+
77477759
/**
77487760
* Whether to skip nested properties that are set to `undefined` during
77497761
* object serialization. If set to `true`, these properties are skipped

packages/firestore-types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface Settings {
2929
timestampsInSnapshots?: boolean;
3030
cacheSizeBytes?: number;
3131
experimentalForceLongPolling?: boolean;
32+
experimentalAutodetectLongPolling?: boolean;
3233
ignoreUndefinedProperties?: boolean;
3334
}
3435

packages/firestore/lite/src/api/database.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { Settings } from '../../';
4242
export const DEFAULT_HOST = 'firestore.googleapis.com';
4343
export const DEFAULT_SSL = true;
4444
export const DEFAULT_FORCE_LONG_POLLING = false; // Used by full SDK
45+
export const DEFAULT_AUTODETECT_LONG_POLLING = false; // Used by full SDK
4546

4647
/**
4748
* The root reference to the Firestore Lite database.
@@ -107,7 +108,8 @@ export class Firestore
107108
/* persistenceKey= */ 'unsupported',
108109
host ?? DEFAULT_HOST,
109110
ssl ?? DEFAULT_SSL,
110-
DEFAULT_FORCE_LONG_POLLING
111+
DEFAULT_FORCE_LONG_POLLING,
112+
DEFAULT_AUTODETECT_LONG_POLLING
111113
);
112114
}
113115

packages/firestore/src/api/database.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ import {
6767
validateOptionNames,
6868
validatePositiveNumber,
6969
validateStringEnum,
70-
valueDescription
70+
valueDescription,
71+
validateIsNotUsedTogether
7172
} from '../util/input_validation';
7273
import { getLogLevel, logError, LogLevel, setLogLevel } from '../util/log';
7374
import { AutoId } from '../util/misc';
@@ -108,6 +109,7 @@ const DEFAULT_HOST = 'firestore.googleapis.com';
108109
const DEFAULT_SSL = true;
109110
const DEFAULT_TIMESTAMPS_IN_SNAPSHOTS = true;
110111
const DEFAULT_FORCE_LONG_POLLING = false;
112+
const DEFAULT_FORCE_AUTODETECT_LONG_POLLING = false;
111113
const DEFAULT_IGNORE_UNDEFINED_PROPERTIES = false;
112114

113115
/**
@@ -153,6 +155,8 @@ class FirestoreSettings {
153155

154156
readonly forceLongPolling: boolean;
155157

158+
readonly autodetectLongPolling: boolean;
159+
156160
readonly ignoreUndefinedProperties: boolean;
157161

158162
// Can be a google-auth-library or gapi client.
@@ -183,6 +187,7 @@ class FirestoreSettings {
183187
'timestampsInSnapshots',
184188
'cacheSizeBytes',
185189
'experimentalForceLongPolling',
190+
'experimentalAutodetectLongPolling',
186191
'ignoreUndefinedProperties'
187192
]);
188193

@@ -256,6 +261,23 @@ class FirestoreSettings {
256261
);
257262
this.forceLongPolling =
258263
settings.experimentalForceLongPolling ?? DEFAULT_FORCE_LONG_POLLING;
264+
265+
validateNamedOptionalType(
266+
'settings',
267+
'boolean',
268+
'experimentalAutodetectLongPolling',
269+
settings.experimentalAutodetectLongPolling
270+
);
271+
this.autodetectLongPolling =
272+
settings.experimentalAutodetectLongPolling ??
273+
DEFAULT_FORCE_AUTODETECT_LONG_POLLING;
274+
275+
validateIsNotUsedTogether(
276+
'experimentalForceLongPolling',
277+
settings.experimentalForceLongPolling,
278+
'experimentalAutodetectLongPolling',
279+
settings.experimentalAutodetectLongPolling
280+
);
259281
}
260282

261283
isEqual(other: FirestoreSettings): boolean {
@@ -266,6 +288,7 @@ class FirestoreSettings {
266288
this.credentials === other.credentials &&
267289
this.cacheSizeBytes === other.cacheSizeBytes &&
268290
this.forceLongPolling === other.forceLongPolling &&
291+
this.autodetectLongPolling === other.autodetectLongPolling &&
269292
this.ignoreUndefinedProperties === other.ignoreUndefinedProperties
270293
);
271294
}
@@ -501,7 +524,8 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
501524
this._persistenceKey,
502525
this._settings.host,
503526
this._settings.ssl,
504-
this._settings.forceLongPolling
527+
this._settings.forceLongPolling,
528+
this._settings.autodetectLongPolling
505529
);
506530
}
507531

packages/firestore/src/core/database_info.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ export class DatabaseInfo {
2929
* @param ssl Whether to use SSL when connecting.
3030
* @param forceLongPolling Whether to use the forceLongPolling option
3131
* when using WebChannel as the network transport.
32+
* @param autodetectLongPolling TODO
3233
*/
3334
constructor(
3435
readonly databaseId: DatabaseId,
3536
readonly persistenceKey: string,
3637
readonly host: string,
3738
readonly ssl: boolean,
38-
readonly forceLongPolling: boolean
39+
readonly forceLongPolling: boolean,
40+
readonly autodetectLongPolling: boolean
3941
) {}
4042
}
4143

packages/firestore/src/platform/browser/webchannel_connection.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ export class WebChannelConnection implements Connection {
7474
private readonly databaseId: DatabaseId;
7575
private readonly baseUrl: string;
7676
private readonly forceLongPolling: boolean;
77+
private readonly autodetectLongPolling: boolean;
7778

7879
constructor(info: DatabaseInfo) {
7980
this.databaseId = info.databaseId;
8081
const proto = info.ssl ? 'https' : 'http';
8182
this.baseUrl = proto + '://' + info.host;
8283
this.forceLongPolling = info.forceLongPolling;
84+
this.autodetectLongPolling = info.autodetectLongPolling;
8385
}
8486

8587
/**
@@ -248,7 +250,8 @@ export class WebChannelConnection implements Connection {
248250
// timeouts to kick in if the request isn't working.
249251
forwardChannelRequestTimeoutMs: 10 * 60 * 1000
250252
},
251-
forceLongPolling: this.forceLongPolling
253+
forceLongPolling: this.forceLongPolling,
254+
detectBufferingProxy: this.autodetectLongPolling
252255
};
253256

254257
this.modifyHeadersForRequest(request.initMessageHeaders!, token);

packages/firestore/src/util/input_validation.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,27 @@ export function validateNamedOptionalType(
199199
}
200200
}
201201

202+
/**
203+
* Validates that two boolean options are not set at the same time.
204+
*/
205+
export function validateIsNotUsedTogether(
206+
optionName1: string,
207+
argument1: boolean | undefined,
208+
optionName2: string,
209+
argument2: boolean | undefined
210+
): void {
211+
if (
212+
argument1 !== undefined &&
213+
argument2 !== undefined &&
214+
argument1 === argument2
215+
) {
216+
throw new FirestoreError(
217+
Code.INVALID_ARGUMENT,
218+
`${optionName1} and ${optionName2} can not be used together.`
219+
);
220+
}
221+
}
222+
202223
export function validateArrayElements<T>(
203224
functionName: string,
204225
optionName: string,

packages/firestore/test/integration/util/internal_helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export function getDefaultDatabaseInfo(): DatabaseInfo {
4444
'persistenceKey',
4545
DEFAULT_SETTINGS.host!,
4646
!!DEFAULT_SETTINGS.ssl,
47-
!!DEFAULT_SETTINGS.experimentalForceLongPolling
47+
!!DEFAULT_SETTINGS.experimentalForceLongPolling,
48+
/*experimentalAutodetectLongPolling=*/ true
4849
);
4950
}
5051

packages/firestore/test/unit/specs/spec_test_runner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ abstract class TestRunner {
206206
TEST_PERSISTENCE_KEY,
207207
'host',
208208
/*ssl=*/ false,
209-
/*forceLongPolling=*/ false
209+
/*forceLongPolling=*/ false,
210+
/*autodetectLongPolling=*/ true
210211
);
211212

212213
// TODO(mrschmidt): During client startup in `firestore_client`, we block

packages/webchannel-wrapper/src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export interface WebChannelOptions {
8989
httpSessionIdParam?: string;
9090
httpHeadersOverwriteParam?: string;
9191
forceLongPolling?: boolean;
92+
detectBufferingProxy?: boolean;
9293
fastHandshake?: boolean;
9394
disableRedac?: boolean;
9495
clientProfile?: string;

0 commit comments

Comments
 (0)