Skip to content

Commit 3cfd194

Browse files
Add plumbing for useFetchStreams
1 parent cc2132c commit 3cfd194

File tree

7 files changed

+25
-8
lines changed

7 files changed

+25
-8
lines changed

packages/firestore/exp/register.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { name, version } from '../package.json';
2626
import { setSDKVersion } from '../src/core/version';
2727
import { FirebaseFirestore } from '../src/exp/database';
2828
import { Settings } from '../src/exp/settings';
29+
import { PrivateSettings } from '../src/lite/settings';
2930

3031
declare module '@firebase/component' {
3132
interface NameServiceMapping {
@@ -38,15 +39,14 @@ export function registerFirestore(variant?: string): void {
3839
_registerComponent(
3940
new Component(
4041
'firestore-exp',
41-
(container, { options: settings }: { options?: Settings }) => {
42+
(container, { options: settings }: { options?: PrivateSettings }) => {
4243
const app = container.getProvider('app-exp').getImmediate()!;
4344
const firestoreInstance = new FirebaseFirestore(
4445
app,
4546
container.getProvider('auth-internal')
4647
);
47-
if (settings) {
48-
firestoreInstance._setSettings(settings);
49-
}
48+
settings = { useFetchStreams: true, ...settings };
49+
firestoreInstance._setSettings(settings);
5050
return firestoreInstance;
5151
},
5252
ComponentType.PUBLIC

packages/firestore/src/core/database_info.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export class DatabaseInfo {
3030
* when using WebChannel as the network transport.
3131
* @param autoDetectLongPolling - Whether to use the detectBufferingProxy
3232
* option when using WebChannel as the network transport.
33+
* @param useFetchStreams Whether to use the Fetch API instead of
34+
* XMLHTTPRequest
3335
*/
3436
constructor(
3537
readonly databaseId: DatabaseId,
@@ -38,7 +40,8 @@ export class DatabaseInfo {
3840
readonly host: string,
3941
readonly ssl: boolean,
4042
readonly forceLongPolling: boolean,
41-
readonly autoDetectLongPolling: boolean
43+
readonly autoDetectLongPolling: boolean,
44+
readonly useFetchStreams: boolean
4245
) {}
4346
}
4447

packages/firestore/src/lite/components.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export function makeDatabaseInfo(
113113
settings.host,
114114
settings.ssl,
115115
settings.experimentalForceLongPolling,
116-
settings.experimentalAutoDetectLongPolling
116+
settings.experimentalAutoDetectLongPolling,
117+
settings.useFetchStreams
117118
);
118119
}

packages/firestore/src/lite/settings.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export interface PrivateSettings extends Settings {
5858
experimentalForceLongPolling?: boolean;
5959
// Used in firestore@exp
6060
experimentalAutoDetectLongPolling?: boolean;
61+
// Used in firestore@exp
62+
useFetchStreams?: boolean;
6163
}
6264

6365
/**
@@ -80,6 +82,8 @@ export class FirestoreSettings {
8082

8183
readonly ignoreUndefinedProperties: boolean;
8284

85+
readonly useFetchStreams: boolean;
86+
8387
// Can be a google-auth-library or gapi client.
8488
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8589
credentials?: any;
@@ -120,6 +124,7 @@ export class FirestoreSettings {
120124

121125
this.experimentalForceLongPolling = !!settings.experimentalForceLongPolling;
122126
this.experimentalAutoDetectLongPolling = !!settings.experimentalAutoDetectLongPolling;
127+
this.useFetchStreams = !!settings.useFetchStreams;
123128

124129
validateIsNotUsedTogether(
125130
'experimentalForceLongPolling',
@@ -139,7 +144,8 @@ export class FirestoreSettings {
139144
other.experimentalForceLongPolling &&
140145
this.experimentalAutoDetectLongPolling ===
141146
other.experimentalAutoDetectLongPolling &&
142-
this.ignoreUndefinedProperties === other.ignoreUndefinedProperties
147+
this.ignoreUndefinedProperties === other.ignoreUndefinedProperties &&
148+
this.useFetchStreams === other.useFetchStreams
143149
);
144150
}
145151
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ const XHR_TIMEOUT_SECS = 15;
6262
export class WebChannelConnection extends RestConnection {
6363
private readonly forceLongPolling: boolean;
6464
private readonly autoDetectLongPolling: boolean;
65+
private readonly useFetchStreams: boolean;
6566

6667
constructor(info: DatabaseInfo) {
6768
super(info);
6869
this.forceLongPolling = info.forceLongPolling;
6970
this.autoDetectLongPolling = info.autoDetectLongPolling;
71+
this.useFetchStreams = info.useFetchStreams;
7072
}
7173

7274
protected performRPCRequest<Req, Resp>(
@@ -191,7 +193,8 @@ export class WebChannelConnection extends RestConnection {
191193
forwardChannelRequestTimeoutMs: 10 * 60 * 1000
192194
},
193195
forceLongPolling: this.forceLongPolling,
194-
detectBufferingProxy: this.autoDetectLongPolling
196+
detectBufferingProxy: this.autoDetectLongPolling,
197+
useFetchStreams: this.useFetchStreams
195198
};
196199

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

packages/webchannel-wrapper/externs/overrides.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ goog.net.WebChannel.Options.forceLongPolling;
6868
/** @type {boolean|undefined} */
6969
goog.net.WebChannel.Options.detectBufferingProxy;
7070

71+
/** @type {boolean|undefined} */
72+
goog.net.WebChannel.Options.useFetchStreams;
73+
7174
goog.labs.net.webChannel.requestStats.Event = {};
7275
goog.labs.net.webChannel.requestStats.Event.STAT_EVENT;
7376

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export interface WebChannelOptions {
107107
};
108108
xmlHttpFactory?: unknown;
109109
requestRefreshThresholds?: { [key: string]: number };
110+
useFetchStreams?: boolean;
110111
}
111112

112113
export interface EventTarget {

0 commit comments

Comments
 (0)