|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2023 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +/** |
| 19 | + * Options that configure the SDK’s underlying network transport (WebChannel) |
| 20 | + * when long-polling is used. |
| 21 | + * |
| 22 | + * Note: This interface is "experimental" and is subject to change. |
| 23 | + * |
| 24 | + * See `FirestoreSettings.experimentalAutoDetectLongPolling`, |
| 25 | + * `FirestoreSettings.experimentalForceLongPolling`, and |
| 26 | + * `FirestoreSettings.experimentalLongPollingOptions`. |
| 27 | + */ |
| 28 | +export interface ExperimentalLongPollingOptions { |
| 29 | + /** |
| 30 | + * The desired maximum timeout interval, in seconds, to complete a |
| 31 | + * long-polling GET response. Valid values are between 5 and 30, inclusive. |
| 32 | + * Floating point values are allowed and will be rounded to the nearest |
| 33 | + * millisecond. |
| 34 | + * |
| 35 | + * By default, when long-polling is used the "hanging GET" request sent by |
| 36 | + * the client times out after 30 seconds. To request a different timeout |
| 37 | + * from the server, set this setting with the desired timeout. |
| 38 | + * |
| 39 | + * Changing the default timeout may be useful, for example, if the buffering |
| 40 | + * proxy that necessitated enabling long-polling in the first place has a |
| 41 | + * shorter timeout for hanging GET requests, in which case setting the |
| 42 | + * long-polling timeout to a shorter value, such as 25 seconds, may fix |
| 43 | + * prematurely-closed hanging GET requests. |
| 44 | + * For example, see https://github.com/firebase/firebase-js-sdk/issues/6987. |
| 45 | + */ |
| 46 | + timeoutSeconds?: number; |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * Compares two `ExperimentalLongPollingOptions` objects for equality. |
| 51 | + */ |
| 52 | +export function longPollingOptionsEqual( |
| 53 | + options1: ExperimentalLongPollingOptions, |
| 54 | + options2: ExperimentalLongPollingOptions |
| 55 | +): boolean { |
| 56 | + return options1.timeoutSeconds === options2.timeoutSeconds; |
| 57 | +} |
| 58 | + |
| 59 | +/** |
| 60 | + * Creates and returns a new `ExperimentalLongPollingOptions` with the same |
| 61 | + * option values as the given instance. |
| 62 | + */ |
| 63 | +export function cloneLongPollingOptions( |
| 64 | + options: ExperimentalLongPollingOptions |
| 65 | +): ExperimentalLongPollingOptions { |
| 66 | + const clone: ExperimentalLongPollingOptions = {}; |
| 67 | + |
| 68 | + if (options.timeoutSeconds !== undefined) { |
| 69 | + clone.timeoutSeconds = options.timeoutSeconds; |
| 70 | + } |
| 71 | + |
| 72 | + return clone; |
| 73 | +} |
0 commit comments