1 | /// <reference types="node" />
|
---|
2 | import { EventEmitter } from "events";
|
---|
3 | import { IncomingMessage } from "http";
|
---|
4 | import { Transport } from "./transport";
|
---|
5 | export declare class Socket extends EventEmitter {
|
---|
6 | readonly protocol: number;
|
---|
7 | readonly request: IncomingMessage;
|
---|
8 | readonly remoteAddress: string;
|
---|
9 | _readyState: string;
|
---|
10 | transport: Transport;
|
---|
11 | private server;
|
---|
12 | private upgrading;
|
---|
13 | private upgraded;
|
---|
14 | private writeBuffer;
|
---|
15 | private packetsFn;
|
---|
16 | private sentCallbackFn;
|
---|
17 | private cleanupFn;
|
---|
18 | private checkIntervalTimer;
|
---|
19 | private upgradeTimeoutTimer;
|
---|
20 | private pingTimeoutTimer;
|
---|
21 | private pingIntervalTimer;
|
---|
22 | private readonly id;
|
---|
23 | get readyState(): string;
|
---|
24 | set readyState(state: string);
|
---|
25 | /**
|
---|
26 | * Client class (abstract).
|
---|
27 | *
|
---|
28 | * @api private
|
---|
29 | */
|
---|
30 | constructor(id: any, server: any, transport: any, req: any, protocol: any);
|
---|
31 | /**
|
---|
32 | * Called upon transport considered open.
|
---|
33 | *
|
---|
34 | * @api private
|
---|
35 | */
|
---|
36 | private onOpen;
|
---|
37 | /**
|
---|
38 | * Called upon transport packet.
|
---|
39 | *
|
---|
40 | * @param {Object} packet
|
---|
41 | * @api private
|
---|
42 | */
|
---|
43 | private onPacket;
|
---|
44 | /**
|
---|
45 | * Called upon transport error.
|
---|
46 | *
|
---|
47 | * @param {Error} error object
|
---|
48 | * @api private
|
---|
49 | */
|
---|
50 | private onError;
|
---|
51 | /**
|
---|
52 | * Pings client every `this.pingInterval` and expects response
|
---|
53 | * within `this.pingTimeout` or closes connection.
|
---|
54 | *
|
---|
55 | * @api private
|
---|
56 | */
|
---|
57 | private schedulePing;
|
---|
58 | /**
|
---|
59 | * Resets ping timeout.
|
---|
60 | *
|
---|
61 | * @api private
|
---|
62 | */
|
---|
63 | private resetPingTimeout;
|
---|
64 | /**
|
---|
65 | * Attaches handlers for the given transport.
|
---|
66 | *
|
---|
67 | * @param {Transport} transport
|
---|
68 | * @api private
|
---|
69 | */
|
---|
70 | private setTransport;
|
---|
71 | /**
|
---|
72 | * Upgrades socket to the given transport
|
---|
73 | *
|
---|
74 | * @param {Transport} transport
|
---|
75 | * @api private
|
---|
76 | */
|
---|
77 | private maybeUpgrade;
|
---|
78 | /**
|
---|
79 | * Clears listeners and timers associated with current transport.
|
---|
80 | *
|
---|
81 | * @api private
|
---|
82 | */
|
---|
83 | private clearTransport;
|
---|
84 | /**
|
---|
85 | * Called upon transport considered closed.
|
---|
86 | * Possible reasons: `ping timeout`, `client error`, `parse error`,
|
---|
87 | * `transport error`, `server close`, `transport close`
|
---|
88 | */
|
---|
89 | private onClose;
|
---|
90 | /**
|
---|
91 | * Setup and manage send callback
|
---|
92 | *
|
---|
93 | * @api private
|
---|
94 | */
|
---|
95 | private setupSendCallback;
|
---|
96 | /**
|
---|
97 | * Sends a message packet.
|
---|
98 | *
|
---|
99 | * @param {String} message
|
---|
100 | * @param {Object} options
|
---|
101 | * @param {Function} callback
|
---|
102 | * @return {Socket} for chaining
|
---|
103 | * @api public
|
---|
104 | */
|
---|
105 | send(data: any, options: any, callback?: any): this;
|
---|
106 | write(data: any, options: any, callback?: any): this;
|
---|
107 | /**
|
---|
108 | * Sends a packet.
|
---|
109 | *
|
---|
110 | * @param {String} packet type
|
---|
111 | * @param {String} optional, data
|
---|
112 | * @param {Object} options
|
---|
113 | * @api private
|
---|
114 | */
|
---|
115 | private sendPacket;
|
---|
116 | /**
|
---|
117 | * Attempts to flush the packets buffer.
|
---|
118 | *
|
---|
119 | * @api private
|
---|
120 | */
|
---|
121 | private flush;
|
---|
122 | /**
|
---|
123 | * Get available upgrades for this socket.
|
---|
124 | *
|
---|
125 | * @api private
|
---|
126 | */
|
---|
127 | private getAvailableUpgrades;
|
---|
128 | /**
|
---|
129 | * Closes the socket and underlying transport.
|
---|
130 | *
|
---|
131 | * @param {Boolean} discard - optional, discard the transport
|
---|
132 | * @return {Socket} for chaining
|
---|
133 | * @api public
|
---|
134 | */
|
---|
135 | close(discard?: boolean): void;
|
---|
136 | /**
|
---|
137 | * Closes the underlying transport.
|
---|
138 | *
|
---|
139 | * @param {Boolean} discard
|
---|
140 | * @api private
|
---|
141 | */
|
---|
142 | private closeTransport;
|
---|
143 | }
|
---|