blob: 5920cd23820558def55c6f4d7a71b9f33cfc4a35 [file] [log] [blame]
Matteo Scandolo5461a7c2017-08-08 13:05:24 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
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
Matteo Scandolofc4b37b2017-02-02 12:18:47 -080019// Generated by typings
20// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/socket.io-client/socket.io-client.d.ts
21declare var io: SocketIOClientStatic;
22
23declare module 'socket.io-client' {
24 export = io;
25}
26
27interface SocketIOClientStatic {
28
29 /**
30 * Looks up an existing 'Manager' for multiplexing. If the user summons:
31 * 'io( 'http://localhost/a' );'
32 * 'io( 'http://localhost/b' );'
33 *
34 * We reuse the existing instance based on the same scheme/port/host, and
35 * we initialize sockets for each namespace. If autoConnect isn't set to
36 * false in the options, then we'll automatically connect
37 * @param uri The uri that we'll connect to, including the namespace, where '/' is the default one (e.g. http://localhost:4000/somenamespace)
38 * @opts Any connect options that we want to pass along
39 * @return A Socket object
40 */
41 ( uri: string, opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Socket;
42
43 /**
44 * Auto-connects to the window location and defalt namespace.
45 * E.g. window.protocol + '//' + window.host + ':80/'
46 * @opts Any connect options that we want to pass along
47 * @return A Socket object
48 */
49 ( opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Socket;
50
51 /**
52 * @see the default constructor (io(uri, opts))
53 */
54 connect( uri: string, opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Socket;
55
56 /**
57 * @see the default constructor (io(opts))
58 */
59 connect( opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Socket;
60
61 /**
62 * The socket.io protocol revision number this client works with
63 * @default 4
64 */
65 protocol: number;
66
67 /**
68 * Socket constructor - exposed for the standalone build
69 */
70 Socket: SocketIOClient.Socket;
71
72 /**
73 * Manager constructor - exposed for the standalone build
74 */
75 Manager: SocketIOClient.ManagerStatic;
76}
77
78declare namespace SocketIOClient {
79
80 /**
81 * The base emiter class, used by Socket and Manager
82 */
83 interface Emitter {
84 /**
85 * Adds a listener for a particular event. Calling multiple times will add
86 * multiple listeners
87 * @param event The event that we're listening for
88 * @param fn The function to call when we get the event. Parameters depend on the
89 * event in question
90 * @return This Emitter
91 */
92 on( event: string, fn: Function ):Emitter;
93
94 /**
95 * @see on( event, fn )
96 */
97 addEventListener( event: string, fn: Function ):Emitter;
98
99 /**
100 * Adds a listener for a particular event that will be invoked
101 * a single time before being automatically removed
102 * @param event The event that we're listening for
103 * @param fn The function to call when we get the event. Parameters depend on
104 * the event in question
105 * @return This Emitter
106 */
107 once( event: string, fn: Function ):Emitter;
108
109 /**
110 * Removes a listener for a particular type of event. This will either
111 * remove a specific listener, or all listeners for this type of event
112 * @param event The event that we want to remove the listener of
113 * @param fn The function to remove, or null if we want to remove all functions
114 * @return This Emitter
115 */
116 off( event: string, fn?: Function ):Emitter;
117
118 /**
119 * @see off( event, fn )
120 */
121 removeListener( event: string, fn?: Function ):Emitter;
122
123 /**
124 * @see off( event, fn )
125 */
126 removeEventListener( event: string, fn?: Function ):Emitter;
127
128 /**
129 * Removes all event listeners on this object
130 * @return This Emitter
131 */
132 removeAllListeners():Emitter;
133
134 /**
135 * Emits 'event' with the given args
136 * @param event The event that we want to emit
137 * @param args Optional arguments to emit with the event
138 * @return Emitter
139 */
140 emit( event: string, ...args: any[] ):Emitter;
141
142 /**
143 * Returns all the callbacks for a particular event
144 * @param event The event that we're looking for the callbacks of
145 * @return An array of callback Functions, or an empty array if we don't have any
146 */
147 listeners( event: string ):Function[];
148
149 /**
150 * Returns if we have listeners for a particular event
151 * @param event The event that we want to check if we've listeners for
152 * @return True if we have listeners for this event, false otherwise
153 */
154 hasListeners( event: string ):boolean;
155 }
156
157 /**
158 * The Socket static interface
159 */
160 interface SocketStatic {
161
162 /**
163 * Creates a new Socket, used for communicating with a specific namespace
164 * @param io The Manager that's controlling this socket
165 * @param nsp The namespace that this socket is for (@default '/')
166 * @return A new Socket
167 */
168 ( io: SocketIOClient.Manager, nsp: string ): Socket;
169
170 /**
171 * Creates a new Socket, used for communicating with a specific namespace
172 * @param io The Manager that's controlling this socket
173 * @param nsp The namespace that this socket is for (@default '/')
174 * @return A new Socket
175 */
176 new ( url: string, opts: any ): SocketIOClient.Manager;
177 }
178
179 /**
180 * The Socket that we use to connect to a Namespace on the server
181 */
182 interface Socket extends Emitter {
183
184 /**
185 * The Manager that's controller this socket
186 */
187 io: SocketIOClient.Manager;
188
189 /**
190 * The namespace that this socket is for
191 * @default '/'
192 */
193 nsp: string;
194
195 /**
196 * The ID of the socket; matches the server ID and is set when we're connected, and cleared
197 * when we're disconnected
198 */
199 id: string;
200
201 /**
202 * Are we currently connected?
203 * @default false
204 */
205 connected: boolean;
206
207 /**
208 * Are we currently disconnected?
209 * @default true
210 */
211 disconnected: boolean;
212
213 /**
214 * Opens our socket so that it connects. If the 'autoConnect' option for io is
215 * true (default), then this is called automatically when the Socket is created
216 */
217 open(): Socket;
218
219 /**
220 * @see open();
221 */
222 connect(): Socket;
223
224 /**
225 * Sends a 'message' event
226 * @param args Any optional arguments that we want to send
227 * @see emit
228 * @return This Socket
229 */
230 send( ...args: any[] ):Socket;
231
232 /**
233 * An override of the base emit. If the event is one of:
234 * connect
235 * connect_error
236 * connect_timeout
237 * connecting
238 * disconnect
239 * error
240 * reconnect
241 * reconnect_attempt
242 * reconnect_failed
243 * reconnect_error
244 * reconnecting
245 * ping
246 * pong
247 * then the event is emitted normally. Otherwise, if we're connected, the
248 * event is sent. Otherwise, it's buffered.
249 *
250 * If the last argument is a function, then it will be called
251 * as an 'ack' when the response is received. The parameter(s) of the
252 * ack will be whatever data is returned from the event
253 * @param event The event that we're emitting
254 * @param args Optional arguments to send with the event
255 * @return This Socket
256 */
257 emit( event: string, ...args: any[] ):Socket;
258
259 /**
260 * Disconnects the socket manually
261 * @return This Socket
262 */
263 close():Socket;
264
265 /**
266 * @see close()
267 */
268 disconnect():Socket;
269
270 /**
271 * Sets the compress flag.
272 * @param compress If `true`, compresses the sending data
273 * @return this Socket
274 */
275 compress(compress: boolean):Socket;
276 }
277
278 /**
279 * The Manager static interface
280 */
281 interface ManagerStatic {
282 /**
283 * Creates a new Manager
284 * @param uri The URI that we're connecting to (e.g. http://localhost:4000)
285 * @param opts Any connection options that we want to use (and pass to engine.io)
286 * @return A Manager
287 */
288 ( uri: string, opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Manager;
289
290 /**
291 * Creates a new Manager with the default URI (window host)
292 * @param opts Any connection options that we want to use (and pass to engine.io)
293 */
294 ( opts: SocketIOClient.ConnectOpts ):SocketIOClient.Manager;
295
296 /**
297 * @see default constructor
298 */
299 new ( uri: string, opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Manager;
300
301 /**
302 * @see default constructor
303 */
304 new ( opts: SocketIOClient.ConnectOpts ):SocketIOClient.Manager;
305 }
306
307 /**
308 * The Manager class handles all the Namespaces and Sockets that we're using
309 */
310 interface Manager extends Emitter {
311
312 /**
313 * All the namespaces currently controlled by this Manager, and the Sockets
314 * that we're using to communicate with them
315 */
316 nsps: { [namespace:string]: Socket };
317
318 /**
319 * The connect options that we used when creating this Manager
320 */
321 opts: SocketIOClient.ConnectOpts;
322
323 /**
324 * The state of the Manager. Either 'closed', 'opening', or 'open'
325 */
326 readyState: string;
327
328 /**
329 * The URI that this manager is for (host + port), e.g. 'http://localhost:4000'
330 */
331 uri: string;
332
333 /**
334 * The currently connected sockets
335 */
336 connecting: Socket[];
337
338 /**
339 * If we should auto connect (also used when creating Sockets). Set via the
340 * opts object
341 */
342 autoConnect: boolean;
343
344 /**
345 * Gets if we should reconnect automatically
346 * @default true
347 */
348 reconnection(): boolean;
349
350 /**
351 * Sets if we should reconnect automatically
352 * @param v True if we should reconnect automatically, false otherwise
353 * @default true
354 * @return This Manager
355 */
356 reconnection( v: boolean ): Manager;
357
358 /**
359 * Gets the number of reconnection attempts we should try before giving up
360 * @default Infinity
361 */
362 reconnectionAttempts(): number;
363
364 /**
365 * Sets the number of reconnection attempts we should try before giving up
366 * @param v The number of attempts we should do before giving up
367 * @default Infinity
368 * @return This Manager
369 */
370 reconnectionAttempts( v: number ): Manager;
371
372 /**
373 * Gets the delay in milliseconds between each reconnection attempt
374 * @default 1000
375 */
376 reconnectionDelay(): number;
377
378 /**
379 * Sets the delay in milliseconds between each reconnection attempt
380 * @param v The delay in milliseconds
381 * @default 1000
382 * @return This Manager
383 */
384 reconnectionDelay( v: number ): Manager;
385
386 /**
387 * Gets the max reconnection delay in milliseconds between each reconnection
388 * attempt
389 * @default 5000
390 */
391 reconnectionDelayMax(): number;
392
393 /**
394 * Sets the max reconnection delay in milliseconds between each reconnection
395 * attempt
396 * @param v The max reconnection dleay in milliseconds
397 * @return This Manager
398 */
399 reconnectionDelayMax( v: number ): Manager;
400
401 /**
402 * Gets the randomisation factor used in the exponential backoff jitter
403 * when reconnecting
404 * @default 0.5
405 */
406 randomizationFactor(): number;
407
408 /**
409 * Sets the randomisation factor used in the exponential backoff jitter
410 * when reconnecting
411 * @param The reconnection randomisation factor
412 * @default 0.5
413 * @return This Manager
414 */
415 randomizationFactor( v: number ): Manager;
416
417 /**
418 * Gets the timeout in milliseconds for our connection attempts
419 * @default 20000
420 */
421 timeout(): number;
422
423 /**
424 * Sets the timeout in milliseconds for our connection attempts
425 * @param The connection timeout milliseconds
426 * @return This Manager
427 */
428 timeout(v: boolean): Manager;
429
430 /**
431 * Sets the current transport socket and opens our connection
432 * @param fn An optional callback to call when our socket has either opened, or
433 * failed. It can take one optional parameter of type Error
434 * @return This Manager
435 */
436 open( fn?: (err?: any) => void ): Manager;
437
438 /**
439 * @see open( fn );
440 */
441 connect( fn?: (err?: any) => void ): Manager;
442
443 /**
444 * Creates a new Socket for the given namespace
445 * @param nsp The namespace that this Socket is for
446 * @return A new Socket, or if one has already been created for this namespace,
447 * an existing one
448 */
449 socket( nsp: string ): Socket;
450 }
451
452 /**
453 * Options we can pass to the socket when connecting
454 */
455 interface ConnectOpts {
456
457 /**
458 * Should we force a new Manager for this connection?
459 * @default false
460 */
461 forceNew?: boolean;
462
463 /**
464 * Should we multiplex our connection (reuse existing Manager) ?
465 * @default true
466 */
467 multiplex?: boolean;
468
469 /**
470 * The path to get our client file from, in the case of the server
471 * serving it
472 * @default '/socket.io'
473 */
474 path?: string;
475
476 /**
477 * Should we allow reconnections?
478 * @default true
479 */
480 reconnection?: boolean;
481
482 /**
483 * How many reconnection attempts should we try?
484 * @default Infinity
485 */
486 reconnectionAttempts?: number;
487
488 /**
489 * The time delay in milliseconds between reconnection attempts
490 * @default 1000
491 */
492 reconnectionDelay?: number;
493
494 /**
495 * The max time delay in milliseconds between reconnection attempts
496 * @default 5000
497 */
498 reconnectionDelayMax?: number;
499
500 /**
501 * Used in the exponential backoff jitter when reconnecting
502 * @default 0.5
503 */
504 randomizationFactor?: number;
505
506 /**
507 * The timeout in milliseconds for our connection attempt
508 * @default 20000
509 */
510 timeout?: number;
511
512 /**
513 * Should we automically connect?
514 * @default true
515 */
516 autoConnect?: boolean;
517
518 /**
519 * The host that we're connecting to. Set from the URI passed when connecting
520 */
521 host?: string;
522
523 /**
524 * The hostname for our connection. Set from the URI passed when connecting
525 */
526 hostname?: string;
527
528 /**
529 * If this is a secure connection. Set from the URI passed when connecting
530 */
531 secure?: boolean;
532
533 /**
534 * The port for our connection. Set from the URI passed when connecting
535 */
536 port?: string;
537
538 /**
539 * Any query parameters in our uri. Set from the URI passed when connecting
540 */
541 query?: Object;
542
543 /**
544 * `http.Agent` to use, defaults to `false` (NodeJS only)
545 */
546 agent?: string|boolean;
547
548 /**
549 * Whether the client should try to upgrade the transport from
550 * long-polling to something better.
551 * @default true
552 */
553 upgrade?: boolean;
554
555 /**
556 * Forces JSONP for polling transport.
557 */
558 forceJSONP?: boolean;
559
560 /**
561 * Determines whether to use JSONP when necessary for polling. If
562 * disabled (by settings to false) an error will be emitted (saying
563 * "No transports available") if no other transports are available.
564 * If another transport is available for opening a connection (e.g.
565 * WebSocket) that transport will be used instead.
566 * @default true
567 */
568 jsonp?: boolean;
569
570 /**
571 * Forces base 64 encoding for polling transport even when XHR2
572 * responseType is available and WebSocket even if the used standard
573 * supports binary.
574 */
575 forceBase64?: boolean;
576
577 /**
578 * Enables XDomainRequest for IE8 to avoid loading bar flashing with
579 * click sound. default to `false` because XDomainRequest has a flaw
580 * of not sending cookie.
581 * @default false
582 */
583 enablesXDR?: boolean;
584
585 /**
586 * The param name to use as our timestamp key
587 * @default 't'
588 */
589 timestampParam?: string;
590
591 /**
592 * Whether to add the timestamp with each transport request. Note: this
593 * is ignored if the browser is IE or Android, in which case requests
594 * are always stamped
595 * @default false
596 */
597 timestampRequests?: boolean;
598
599 /**
600 * A list of transports to try (in order). Engine.io always attempts to
601 * connect directly with the first one, provided the feature detection test
602 * for it passes.
603 * @default ['polling','websocket']
604 */
605 transports?: string[];
606
607 /**
608 * The port the policy server listens on
609 * @default 843
610 */
611 policyPost?: number;
612
613 /**
614 * If true and if the previous websocket connection to the server succeeded,
615 * the connection attempt will bypass the normal upgrade process and will
616 * initially try websocket. A connection attempt following a transport error
617 * will use the normal upgrade process. It is recommended you turn this on
618 * only when using SSL/TLS connections, or if you know that your network does
619 * not block websockets.
620 * @default false
621 */
622 rememberUpgrade?: boolean;
623
624 /**
625 * Are we only interested in transports that support binary?
626 */
627 onlyBinaryUpgrades?: boolean;
628
629 /**
630 * (SSL) Certificate, Private key and CA certificates to use for SSL.
631 * Can be used in Node.js client environment to manually specify
632 * certificate information.
633 */
634 pfx?: string;
635
636 /**
637 * (SSL) Private key to use for SSL. Can be used in Node.js client
638 * environment to manually specify certificate information.
639 */
640 key?: string;
641
642 /**
643 * (SSL) A string or passphrase for the private key or pfx. Can be
644 * used in Node.js client environment to manually specify certificate
645 * information.
646 */
647 passphrase?: string
648
649 /**
650 * (SSL) Public x509 certificate to use. Can be used in Node.js client
651 * environment to manually specify certificate information.
652 */
653 cert?: string;
654
655 /**
656 * (SSL) An authority certificate or array of authority certificates to
657 * check the remote host against.. Can be used in Node.js client
658 * environment to manually specify certificate information.
659 */
660 ca?: string|string[];
661
662 /**
663 * (SSL) A string describing the ciphers to use or exclude. Consult the
664 * [cipher format list]
665 * (http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT) for
666 * details on the format.. Can be used in Node.js client environment to
667 * manually specify certificate information.
668 */
669 ciphers?: string;
670
671 /**
672 * (SSL) If true, the server certificate is verified against the list of
673 * supplied CAs. An 'error' event is emitted if verification fails.
674 * Verification happens at the connection level, before the HTTP request
675 * is sent. Can be used in Node.js client environment to manually specify
676 * certificate information.
677 */
678 rejectUnauthorized?: boolean;
679
680 }
681}