UNPKG

2.79 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Packet } from "socket.io-parser";
3import type { IncomingMessage } from "http";
4import type { Server } from "./index";
5import type { EventsMap } from "./typed-events";
6import type { Socket } from "./socket";
7import type { Socket as RawSocket } from "engine.io";
8interface WriteOptions {
9 compress?: boolean;
10 volatile?: boolean;
11 preEncoded?: boolean;
12 wsPreEncoded?: string;
13}
14export declare class Client<ListenEvents extends EventsMap, EmitEvents extends EventsMap, ServerSideEvents extends EventsMap> {
15 readonly conn: RawSocket;
16 private readonly id;
17 private readonly server;
18 private readonly encoder;
19 private readonly decoder;
20 private sockets;
21 private nsps;
22 private connectTimeout?;
23 /**
24 * Client constructor.
25 *
26 * @param server instance
27 * @param conn
28 * @package
29 */
30 constructor(server: Server<ListenEvents, EmitEvents, ServerSideEvents>, conn: any);
31 /**
32 * @return the reference to the request that originated the Engine.IO connection
33 *
34 * @public
35 */
36 get request(): IncomingMessage;
37 /**
38 * Sets up event listeners.
39 *
40 * @private
41 */
42 private setup;
43 /**
44 * Connects a client to a namespace.
45 *
46 * @param {String} name - the namespace
47 * @param {Object} auth - the auth parameters
48 * @private
49 */
50 private connect;
51 /**
52 * Connects a client to a namespace.
53 *
54 * @param name - the namespace
55 * @param {Object} auth - the auth parameters
56 *
57 * @private
58 */
59 private doConnect;
60 /**
61 * Disconnects from all namespaces and closes transport.
62 *
63 * @private
64 */
65 _disconnect(): void;
66 /**
67 * Removes a socket. Called by each `Socket`.
68 *
69 * @private
70 */
71 _remove(socket: Socket<ListenEvents, EmitEvents, ServerSideEvents>): void;
72 /**
73 * Closes the underlying connection.
74 *
75 * @private
76 */
77 private close;
78 /**
79 * Writes a packet to the transport.
80 *
81 * @param {Object} packet object
82 * @param {Object} opts
83 * @private
84 */
85 _packet(packet: Packet | any[], opts?: WriteOptions): void;
86 private writeToEngine;
87 /**
88 * Called with incoming transport data.
89 *
90 * @private
91 */
92 private ondata;
93 /**
94 * Called when parser fully decodes a packet.
95 *
96 * @private
97 */
98 private ondecoded;
99 /**
100 * Handles an error.
101 *
102 * @param {Object} err object
103 * @private
104 */
105 private onerror;
106 /**
107 * Called upon transport close.
108 *
109 * @param reason
110 * @private
111 */
112 private onclose;
113 /**
114 * Cleans up event listeners.
115 * @private
116 */
117 private destroy;
118}
119export {};