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