UNPKG

4.64 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';
18import { Transport } from './Transport';
19export declare function setWebSocketImpl(impl: any): void;
20/**
21 * Create a new websocket connection with the given callbacks.
22 */
23export declare class WebSocketConnection implements Transport {
24 connId: string;
25 private applicationId?;
26 private appCheckToken?;
27 private authToken?;
28 keepaliveTimer: number | null;
29 frames: string[] | null;
30 totalFrames: number;
31 bytesSent: number;
32 bytesReceived: number;
33 connURL: string;
34 onDisconnect: (a?: boolean) => void;
35 onMessage: (msg: {}) => void;
36 mySock: WebSocket | null;
37 private log_;
38 private stats_;
39 private everConnected_;
40 private isClosed_;
41 private nodeAdmin;
42 /**
43 * @param connId identifier for this transport
44 * @param repoInfo The info for the websocket endpoint.
45 * @param applicationId The Firebase App ID for this project.
46 * @param appCheckToken The App Check Token for this client.
47 * @param authToken The Auth Token for this client.
48 * @param transportSessionId Optional transportSessionId if this is connecting
49 * to an existing transport session
50 * @param lastSessionId Optional lastSessionId if there was a previous
51 * connection
52 */
53 constructor(connId: string, repoInfo: RepoInfo, applicationId?: string, appCheckToken?: string, authToken?: string, transportSessionId?: string, lastSessionId?: string);
54 /**
55 * @param repoInfo - The info for the websocket endpoint.
56 * @param transportSessionId - Optional transportSessionId if this is connecting to an existing transport
57 * session
58 * @param lastSessionId - Optional lastSessionId if there was a previous connection
59 * @returns connection url
60 */
61 private static connectionURL_;
62 /**
63 * @param onMessage - Callback when messages arrive
64 * @param onDisconnect - Callback with connection lost.
65 */
66 open(onMessage: (msg: {}) => void, onDisconnect: (a?: boolean) => void): void;
67 /**
68 * No-op for websockets, we don't need to do anything once the connection is confirmed as open
69 */
70 start(): void;
71 static forceDisallow_: boolean;
72 static forceDisallow(): void;
73 static isAvailable(): boolean;
74 /**
75 * Number of response before we consider the connection "healthy."
76 */
77 static responsesRequiredToBeHealthy: number;
78 /**
79 * Time to wait for the connection te become healthy before giving up.
80 */
81 static healthyTimeout: number;
82 /**
83 * Returns true if we previously failed to connect with this transport.
84 */
85 static previouslyFailed(): boolean;
86 markConnectionHealthy(): void;
87 private appendFrame_;
88 /**
89 * @param frameCount - The number of frames we are expecting from the server
90 */
91 private handleNewFrameCount_;
92 /**
93 * Attempts to parse a frame count out of some text. If it can't, assumes a value of 1
94 * @returns Any remaining data to be process, or null if there is none
95 */
96 private extractFrameCount_;
97 /**
98 * Process a websocket frame that has arrived from the server.
99 * @param mess - The frame data
100 */
101 handleIncomingFrame(mess: {
102 [k: string]: unknown;
103 }): void;
104 /**
105 * Send a message to the server
106 * @param data - The JSON object to transmit
107 */
108 send(data: {}): void;
109 private shutdown_;
110 private onClosed_;
111 /**
112 * External-facing close handler.
113 * Close the websocket and kill the connection.
114 */
115 close(): void;
116 /**
117 * Kill the current keepalive timer and start a new one, to ensure that it always fires N seconds after
118 * the last activity.
119 */
120 resetKeepAlive(): void;
121 /**
122 * Send a string over the websocket.
123 *
124 * @param str - String to send.
125 */
126 private sendString_;
127}