1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import { RepoInfo } from '../core/RepoInfo';
|
18 | import { PacketReceiver } from './polling/PacketReceiver';
|
19 | import { Transport } from './Transport';
|
20 | export declare const FIREBASE_LONGPOLL_START_PARAM = "start";
|
21 | export declare const FIREBASE_LONGPOLL_CLOSE_COMMAND = "close";
|
22 | export declare const FIREBASE_LONGPOLL_COMMAND_CB_NAME = "pLPCommand";
|
23 | export declare const FIREBASE_LONGPOLL_DATA_CB_NAME = "pRTLPCB";
|
24 | export declare const FIREBASE_LONGPOLL_ID_PARAM = "id";
|
25 | export declare const FIREBASE_LONGPOLL_PW_PARAM = "pw";
|
26 | export declare const FIREBASE_LONGPOLL_SERIAL_PARAM = "ser";
|
27 | export declare const FIREBASE_LONGPOLL_CALLBACK_ID_PARAM = "cb";
|
28 | export declare const FIREBASE_LONGPOLL_SEGMENT_NUM_PARAM = "seg";
|
29 | export declare const FIREBASE_LONGPOLL_SEGMENTS_IN_PACKET = "ts";
|
30 | export declare const FIREBASE_LONGPOLL_DATA_PARAM = "d";
|
31 | export declare const FIREBASE_LONGPOLL_DISCONN_FRAME_PARAM = "disconn";
|
32 | export declare const FIREBASE_LONGPOLL_DISCONN_FRAME_REQUEST_PARAM = "dframe";
|
33 |
|
34 |
|
35 |
|
36 | export declare class BrowserPollConnection implements Transport {
|
37 | connId: string;
|
38 | repoInfo: RepoInfo;
|
39 | private applicationId?;
|
40 | private appCheckToken?;
|
41 | private authToken?;
|
42 | transportSessionId?: string;
|
43 | lastSessionId?: string;
|
44 | bytesSent: number;
|
45 | bytesReceived: number;
|
46 | urlFn: (params: object) => string;
|
47 | scriptTagHolder: FirebaseIFrameScriptHolder;
|
48 | myDisconnFrame: HTMLIFrameElement;
|
49 | curSegmentNum: number;
|
50 | myPacketOrderer: PacketReceiver;
|
51 | id: string;
|
52 | password: string;
|
53 | private log_;
|
54 | private stats_;
|
55 | private everConnected_;
|
56 | private isClosed_;
|
57 | private connectTimeoutTimer_;
|
58 | private onDisconnect_;
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | constructor(connId: string, repoInfo: RepoInfo, applicationId?: string, appCheckToken?: string, authToken?: string, transportSessionId?: string, lastSessionId?: string);
|
71 | /**
|
72 | * @param onMessage - Callback when messages arrive
|
73 | * @param onDisconnect - Callback with connection lost.
|
74 | */
|
75 | open(onMessage: (msg: {}) => void, onDisconnect: (a?: boolean) => void): void;
|
76 | /**
|
77 | * Call this when a handshake has completed successfully and we want to consider the connection established
|
78 | */
|
79 | start(): void;
|
80 | static forceAllow_: boolean;
|
81 | /**
|
82 | * Forces long polling to be considered as a potential transport
|
83 | */
|
84 | static forceAllow(): void;
|
85 | static forceDisallow_: boolean;
|
86 | /**
|
87 | * Forces longpolling to not be considered as a potential transport
|
88 | */
|
89 | static forceDisallow(): void;
|
90 | static isAvailable(): boolean;
|
91 | /**
|
92 | * No-op for polling
|
93 | */
|
94 | markConnectionHealthy(): void;
|
95 | /**
|
96 | * Stops polling and cleans up the iframe
|
97 | */
|
98 | private shutdown_;
|
99 | /**
|
100 | * Triggered when this transport is closed
|
101 | */
|
102 | private onClosed_;
|
103 | /**
|
104 | * External-facing close handler. RealTime has requested we shut down. Kill our connection and tell the server
|
105 | * that we've left.
|
106 | */
|
107 | close(): void;
|
108 | /**
|
109 | * Send the JSON object down to the server. It will need to be stringified, base64 encoded, and then
|
110 | * broken into chunks (since URLs have a small maximum length).
|
111 | * @param data - The JSON data to transmit.
|
112 | */
|
113 | send(data: {}): void;
|
114 | /**
|
115 | * This is how we notify the server that we're leaving.
|
116 | * We aren't able to send requests with DHTML on a window close event, but we can
|
117 | * trigger XHR requests in some browsers (everything but Opera basically).
|
118 | */
|
119 | addDisconnectPingFrame(id: string, pw: string): void;
|
120 | /**
|
121 | * Used to track the bytes received by this client
|
122 | */
|
123 | private incrementIncomingBytes_;
|
124 | }
|
125 | export interface IFrameElement extends HTMLIFrameElement {
|
126 | doc: Document;
|
127 | }
|
128 |
|
129 |
|
130 |
|
131 | export declare class FirebaseIFrameScriptHolder {
|
132 | onDisconnect: () => void;
|
133 | urlFn: (a: object) => string;
|
134 | outstandingRequests: Set<number>;
|
135 | pendingSegs: Array<{
|
136 | seg: number;
|
137 | ts: number;
|
138 | d: unknown;
|
139 | }>;
|
140 | currentSerial: number;
|
141 | sendNewPolls: boolean;
|
142 | uniqueCallbackIdentifier: number;
|
143 | myIFrame: IFrameElement;
|
144 | alive: boolean;
|
145 | myID: string;
|
146 | myPW: string;
|
147 | commandCB: (command: string, ...args: unknown[]) => void;
|
148 | onMessageCB: (...args: unknown[]) => void;
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | constructor(commandCB: (command: string, ...args: unknown[]) => void, onMessageCB: (...args: unknown[]) => void, onDisconnect: () => void, urlFn: (a: object) => string);
|
156 | /**
|
157 | * Each browser has its own funny way to handle iframes. Here we mush them all together into one object that I can
|
158 | * actually use.
|
159 | */
|
160 | private static createIFrame_;
|
161 | /**
|
162 | * Cancel all outstanding queries and remove the frame.
|
163 | */
|
164 | close(): void;
|
165 | /**
|
166 | * Actually start the long-polling session by adding the first script tag(s) to the iframe.
|
167 | * @param id - The ID of this connection
|
168 | * @param pw - The password for this connection
|
169 | */
|
170 | startLongPoll(id: string, pw: string): void;
|
171 | /**
|
172 | * This is called any time someone might want a script tag to be added. It adds a script tag when there aren't
|
173 | * too many outstanding requests and we are still alive.
|
174 | *
|
175 | * If there are outstanding packet segments to send, it sends one. If there aren't, it sends a long-poll anyways if
|
176 | * needed.
|
177 | */
|
178 | private newRequest_;
|
179 | /**
|
180 | * Queue a packet for transmission to the server.
|
181 | * @param segnum - A sequential id for this packet segment used for reassembly
|
182 | * @param totalsegs - The total number of segments in this packet
|
183 | * @param data - The data for this segment.
|
184 | */
|
185 | enqueueSegment(segnum: number, totalsegs: number, data: unknown): void;
|
186 | /**
|
187 | * Add a script tag for a regular long-poll request.
|
188 | * @param url - The URL of the script tag.
|
189 | * @param serial - The serial number of the request.
|
190 | */
|
191 | private addLongPollTag_;
|
192 | /**
|
193 | * Add an arbitrary script tag to the iframe.
|
194 | * @param url - The URL for the script tag source.
|
195 | * @param loadCB - A callback to be triggered once the script has loaded.
|
196 | */
|
197 | addTag(url: string, loadCB: () => void): void;
|
198 | }
|