125 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-10-10 22:00:26 +02:00
import { EventEmitter } from "events";
2025-01-25 10:46:42 +01:00
import type { IncomingMessage, ServerResponse } from "http";
import { Packet, RawData } from "engine.io-parser";
type ReadyState = "open" | "closing" | "closed";
export type EngineRequest = IncomingMessage & {
_query: Record<string, string>;
res?: ServerResponse;
cleanup?: Function;
websocket?: any;
};
2023-10-10 22:00:26 +02:00
export declare abstract class Transport extends EventEmitter {
2025-01-25 10:46:42 +01:00
/**
* The session ID.
*/
2023-10-10 22:00:26 +02:00
sid: string;
2025-01-25 10:46:42 +01:00
/**
* Whether the transport is currently ready to send packets.
*/
2023-10-10 22:00:26 +02:00
writable: boolean;
2025-01-25 10:46:42 +01:00
/**
* The revision of the protocol:
*
* - 3 is used in Engine.IO v3 / Socket.IO v2
* - 4 is used in Engine.IO v4 and above / Socket.IO v3 and above
*
* It is found in the `EIO` query parameters of the HTTP requests.
*
* @see https://github.com/socketio/engine.io-protocol
*/
2023-10-10 22:00:26 +02:00
protocol: number;
2025-01-25 10:46:42 +01:00
/**
* The current state of the transport.
* @protected
*/
protected _readyState: ReadyState;
/**
* Whether the transport is discarded and can be safely closed (used during upgrade).
* @protected
*/
2023-10-10 22:00:26 +02:00
protected discarded: boolean;
2025-01-25 10:46:42 +01:00
/**
* The parser to use (depends on the revision of the {@link Transport#protocol}.
* @protected
*/
2023-10-10 22:00:26 +02:00
protected parser: any;
2025-01-25 10:46:42 +01:00
/**
* Whether the transport supports binary payloads (else it will be base64-encoded)
* @protected
*/
2023-10-10 22:00:26 +02:00
protected supportsBinary: boolean;
2025-01-25 10:46:42 +01:00
get readyState(): ReadyState;
set readyState(state: ReadyState);
2023-10-10 22:00:26 +02:00
/**
* Transport constructor.
*
2025-01-25 10:46:42 +01:00
* @param {EngineRequest} req
2023-10-10 22:00:26 +02:00
*/
2025-01-25 10:46:42 +01:00
constructor(req: {
_query: Record<string, string>;
});
2023-10-10 22:00:26 +02:00
/**
* Flags the transport as discarded.
*
2025-01-25 10:46:42 +01:00
* @package
2023-10-10 22:00:26 +02:00
*/
discard(): void;
/**
* Called with an incoming HTTP request.
*
2025-01-25 10:46:42 +01:00
* @param req
* @package
2023-10-10 22:00:26 +02:00
*/
2025-01-25 10:46:42 +01:00
onRequest(req: any): void;
2023-10-10 22:00:26 +02:00
/**
* Closes the transport.
*
2025-01-25 10:46:42 +01:00
* @package
2023-10-10 22:00:26 +02:00
*/
2025-01-25 10:46:42 +01:00
close(fn?: () => void): void;
2023-10-10 22:00:26 +02:00
/**
* Called with a transport error.
*
2025-01-25 10:46:42 +01:00
* @param {String} msg - message error
* @param {Object} desc - error description
* @protected
2023-10-10 22:00:26 +02:00
*/
protected onError(msg: string, desc?: any): void;
/**
* Called with parsed out a packets from the data stream.
*
* @param {Object} packet
2025-01-25 10:46:42 +01:00
* @protected
2023-10-10 22:00:26 +02:00
*/
protected onPacket(packet: Packet): void;
/**
* Called with the encoded packet data.
*
* @param {String} data
2025-01-25 10:46:42 +01:00
* @protected
2023-10-10 22:00:26 +02:00
*/
2025-01-25 10:46:42 +01:00
protected onData(data: RawData): void;
2023-10-10 22:00:26 +02:00
/**
* Called upon transport close.
*
2025-01-25 10:46:42 +01:00
* @protected
2023-10-10 22:00:26 +02:00
*/
protected onClose(): void;
2025-01-25 10:46:42 +01:00
/**
* The name of the transport.
*/
abstract get name(): string;
/**
* Sends an array of packets.
*
* @param {Array} packets
* @package
*/
abstract send(packets: Packet[]): void;
/**
* Closes the transport.
*/
abstract doClose(fn?: () => void): void;
2023-10-10 22:00:26 +02:00
}
2025-01-25 10:46:42 +01:00
export {};