1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import { RepoInfo } from '../core/RepoInfo';
|
18 | import { Transport } from './Transport';
|
19 | export declare function setWebSocketImpl(impl: any): void;
|
20 |
|
21 |
|
22 |
|
23 | export 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 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
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 | }
|