123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- import { Emitter } from "@socket.io/component-emitter";
- import type { Packet, BinaryType, RawData } from "engine.io-parser";
- import { CloseDetails, Transport } from "./transport.js";
- export interface SocketOptions {
-
- host: string;
-
- hostname: string;
-
- secure: boolean;
-
- port: string | number;
-
- query: {
- [key: string]: any;
- };
-
- agent: string | boolean;
-
- upgrade: boolean;
-
- forceBase64: boolean;
-
- timestampParam: string;
-
- timestampRequests: boolean;
-
- transports: string[];
-
- rememberUpgrade: boolean;
-
- onlyBinaryUpgrades: boolean;
-
- requestTimeout: number;
-
- transportOptions: Object;
-
- pfx: string;
-
- key: string;
-
- passphrase: string;
-
- cert: string;
-
- ca: string | string[];
-
- ciphers: string;
-
- rejectUnauthorized: boolean;
-
- extraHeaders?: {
- [header: string]: string;
- };
-
- withCredentials: boolean;
-
- closeOnBeforeunload: boolean;
-
- useNativeTimers: boolean;
-
- autoUnref: boolean;
-
- perMessageDeflate: {
- threshold: number;
- };
-
- path: string;
-
- addTrailingSlash: boolean;
-
- protocols: string | string[];
- }
- interface HandshakeData {
- sid: string;
- upgrades: string[];
- pingInterval: number;
- pingTimeout: number;
- maxPayload: number;
- }
- interface SocketReservedEvents {
- open: () => void;
- handshake: (data: HandshakeData) => void;
- packet: (packet: Packet) => void;
- packetCreate: (packet: Packet) => void;
- data: (data: any) => void;
- message: (data: any) => void;
- drain: () => void;
- flush: () => void;
- heartbeat: () => void;
- ping: () => void;
- pong: () => void;
- error: (err: string | Error) => void;
- upgrading: (transport: any) => void;
- upgrade: (transport: any) => void;
- upgradeError: (err: Error) => void;
- close: (reason: string, description?: CloseDetails | Error) => void;
- }
- type SocketState = "opening" | "open" | "closing" | "closed";
- export declare class Socket extends Emitter<Record<never, never>, Record<never, never>, SocketReservedEvents> {
- id: string;
- transport: Transport;
- binaryType: BinaryType;
- readyState: SocketState;
- writeBuffer: Packet[];
- private prevBufferLen;
- private upgrades;
- private pingInterval;
- private pingTimeout;
- private pingTimeoutTimer;
- private setTimeoutFn;
- private clearTimeoutFn;
- private readonly beforeunloadEventListener;
- private readonly offlineEventListener;
- private upgrading;
- private maxPayload?;
- private readonly opts;
- private readonly secure;
- private readonly hostname;
- private readonly port;
- private readonly transports;
- static priorWebsocketSuccess: boolean;
- static protocol: number;
-
- constructor(uri: any, opts?: Partial<SocketOptions>);
- /**
- * Creates transport of the given type.
- *
- * @param {String} name - transport name
- * @return {Transport}
- * @private
- */
- private createTransport;
- /**
- * Initializes transport to use and starts probe.
- *
- * @private
- */
- private open;
- /**
- * Sets the current transport. Disables the existing one (if any).
- *
- * @private
- */
- private setTransport;
- /**
- * Probes a transport.
- *
- * @param {String} name - transport name
- * @private
- */
- private probe;
- /**
- * Called when connection is deemed open.
- *
- * @private
- */
- private onOpen;
- /**
- * Handles a packet.
- *
- * @private
- */
- private onPacket;
- /**
- * Called upon handshake completion.
- *
- * @param {Object} data - handshake obj
- * @private
- */
- private onHandshake;
- /**
- * Sets and resets ping timeout timer based on server pings.
- *
- * @private
- */
- private resetPingTimeout;
- /**
- * Called on `drain` event
- *
- * @private
- */
- private onDrain;
- /**
- * Flush write buffers.
- *
- * @private
- */
- private flush;
- /**
- * Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
- * long-polling)
- *
- * @private
- */
- private getWritablePackets;
- /**
- * Sends a message.
- *
- * @param {String} msg - message.
- * @param {Object} options.
- * @param {Function} callback function.
- * @return {Socket} for chaining.
- */
- write(msg: RawData, options?: any, fn?: any): this;
- send(msg: RawData, options?: any, fn?: any): this;
- /**
- * Sends a packet.
- *
- * @param {String} type: packet type.
- * @param {String} data.
- * @param {Object} options.
- * @param {Function} fn - callback function.
- * @private
- */
- private sendPacket;
-
- close(): this;
-
- private onError;
-
- private onClose;
-
- private filterUpgrades;
- }
- export {};
|