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