UNPKG

3.94 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 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 */
17import { RepoInfo } from '../core/RepoInfo';
18/**
19 * Creates a new real-time connection to the server using whichever method works
20 * best in the current browser.
21 */
22export declare class Connection {
23 id: string;
24 private repoInfo_;
25 private applicationId_;
26 private appCheckToken_;
27 private authToken_;
28 private onMessage_;
29 private onReady_;
30 private onDisconnect_;
31 private onKill_;
32 lastSessionId?: string;
33 connectionCount: number;
34 pendingDataMessages: unknown[];
35 sessionId: string;
36 private conn_;
37 private healthyTimeout_;
38 private isHealthy_;
39 private log_;
40 private primaryResponsesRequired_;
41 private rx_;
42 private secondaryConn_;
43 private secondaryResponsesRequired_;
44 private state_;
45 private transportManager_;
46 private tx_;
47 /**
48 * @param id - an id for this connection
49 * @param repoInfo_ - the info for the endpoint to connect to
50 * @param applicationId_ - the Firebase App ID for this project
51 * @param appCheckToken_ - The App Check Token for this device.
52 * @param authToken_ - The auth token for this session.
53 * @param onMessage_ - the callback to be triggered when a server-push message arrives
54 * @param onReady_ - the callback to be triggered when this connection is ready to send messages.
55 * @param onDisconnect_ - the callback to be triggered when a connection was lost
56 * @param onKill_ - the callback to be triggered when this connection has permanently shut down.
57 * @param lastSessionId - last session id in persistent connection. is used to clean up old session in real-time server
58 */
59 constructor(id: string, repoInfo_: RepoInfo, applicationId_: string | undefined, appCheckToken_: string | undefined, authToken_: string | undefined, onMessage_: (a: {}) => void, onReady_: (a: number, b: string) => void, onDisconnect_: () => void, onKill_: (a: string) => void, lastSessionId?: string);
60 /**
61 * Starts a connection attempt
62 */
63 private start_;
64 private nextTransportId_;
65 private disconnReceiver_;
66 private connReceiver_;
67 /**
68 * @param dataMsg - An arbitrary data message to be sent to the server
69 */
70 sendRequest(dataMsg: object): void;
71 tryCleanupConnection(): void;
72 private onSecondaryControl_;
73 private onSecondaryMessageReceived_;
74 private upgradeIfSecondaryHealthy_;
75 private proceedWithUpgrade_;
76 private onPrimaryMessageReceived_;
77 private onDataMessage_;
78 private onPrimaryResponse_;
79 private onControl_;
80 /**
81 * @param handshake - The handshake data returned from the server
82 */
83 private onHandshake_;
84 private tryStartUpgrade_;
85 private startUpgrade_;
86 private onReset_;
87 private onConnectionEstablished_;
88 private sendPingOnPrimaryIfNecessary_;
89 private onSecondaryConnectionLost_;
90 /**
91 * @param everConnected - Whether or not the connection ever reached a server. Used to determine if
92 * we should flush the host cache
93 */
94 private onConnectionLost_;
95 private onConnectionShutdown_;
96 private sendData_;
97 /**
98 * Cleans up this connection, calling the appropriate callbacks
99 */
100 close(): void;
101 private closeConnections_;
102}