@@ -29,6 +29,17 @@ import { validateIsNotUsedTogether } from '../util/input_validation';
29
29
export const DEFAULT_HOST = 'firestore.googleapis.com' ;
30
30
export const DEFAULT_SSL = true ;
31
31
32
+ // The minimum long-polling timeout is hardcoded on the server. The value here
33
+ // should be kept in sync with the value used by the server, as the server will
34
+ // silently ignore a value below the minimum and fall back to the default.
35
+ // Googlers see http://google3/net/webchannel/internal/webchannel_config.cc;l=118;rcl=510899643
36
+ const MIN_LONG_POLLING_TIMEOUT = 5000 ;
37
+
38
+ // No maximum long-polling timeout is not enforced by the server; however, a
39
+ // "reasonable" maximum value is set by the client to provide some guard rails.
40
+ // Googlers see b/266868871 for relevant discussion.
41
+ const MAX_LONG_POLLING_TIMEOUT = 600000 ;
42
+
32
43
/**
33
44
* Specifies custom configurations for your Cloud Firestore instance.
34
45
* You must set these before invoking any other methods.
@@ -60,6 +71,8 @@ export interface PrivateSettings extends FirestoreSettings {
60
71
// Used in firestore@exp
61
72
experimentalAutoDetectLongPolling ?: boolean ;
62
73
// Used in firestore@exp
74
+ experimentalLongPollingTimeout ?: number ;
75
+ // Used in firestore@exp
63
76
useFetchStreams ?: boolean ;
64
77
65
78
localCache ?: FirestoreLocalCache ;
@@ -83,6 +96,8 @@ export class FirestoreSettingsImpl {
83
96
84
97
readonly experimentalAutoDetectLongPolling : boolean ;
85
98
99
+ readonly experimentalLongPollingTimeout : number | undefined ;
100
+
86
101
readonly ignoreUndefinedProperties : boolean ;
87
102
88
103
readonly useFetchStreams : boolean ;
@@ -130,6 +145,7 @@ export class FirestoreSettingsImpl {
130
145
this . experimentalForceLongPolling = ! ! settings . experimentalForceLongPolling ;
131
146
this . experimentalAutoDetectLongPolling =
132
147
! ! settings . experimentalAutoDetectLongPolling ;
148
+ this . experimentalLongPollingTimeout = settings ?. experimentalLongPollingTimeout ;
133
149
this . useFetchStreams = ! ! settings . useFetchStreams ;
134
150
135
151
validateIsNotUsedTogether (
@@ -138,6 +154,32 @@ export class FirestoreSettingsImpl {
138
154
'experimentalAutoDetectLongPolling' ,
139
155
settings . experimentalAutoDetectLongPolling
140
156
) ;
157
+
158
+ if ( typeof this . experimentalLongPollingTimeout === 'number' ) {
159
+ if ( ! Number . isInteger ( this . experimentalLongPollingTimeout ) ) {
160
+ throw new FirestoreError (
161
+ Code . INVALID_ARGUMENT ,
162
+ `invalid long polling timeout: ` +
163
+ `${ this . experimentalLongPollingTimeout } (must be an integer)`
164
+ ) ;
165
+ }
166
+ if ( this . experimentalLongPollingTimeout < MIN_LONG_POLLING_TIMEOUT ) {
167
+ throw new FirestoreError (
168
+ Code . INVALID_ARGUMENT ,
169
+ `invalid long polling timeout: ` +
170
+ `${ this . experimentalLongPollingTimeout } ` +
171
+ `(minimum allowed value is ${ MIN_LONG_POLLING_TIMEOUT } )`
172
+ ) ;
173
+ }
174
+ if ( this . experimentalLongPollingTimeout > MAX_LONG_POLLING_TIMEOUT ) {
175
+ throw new FirestoreError (
176
+ Code . INVALID_ARGUMENT ,
177
+ `invalid long polling timeout: ` +
178
+ `${ this . experimentalLongPollingTimeout } ` +
179
+ `(maximum allowed value is ${ MAX_LONG_POLLING_TIMEOUT } )`
180
+ ) ;
181
+ }
182
+ }
141
183
}
142
184
143
185
isEqual ( other : FirestoreSettingsImpl ) : boolean {
@@ -150,6 +192,8 @@ export class FirestoreSettingsImpl {
150
192
other . experimentalForceLongPolling &&
151
193
this . experimentalAutoDetectLongPolling ===
152
194
other . experimentalAutoDetectLongPolling &&
195
+ this . experimentalLongPollingTimeout ===
196
+ other . experimentalLongPollingTimeout &&
153
197
this . ignoreUndefinedProperties === other . ignoreUndefinedProperties &&
154
198
this . useFetchStreams === other . useFetchStreams
155
199
) ;
0 commit comments