123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
-
- import { EventEmitter } from "events";
- import { IncomingMessage, Server as HttpServer } from "http";
- import { CookieSerializeOptions } from "cookie";
- import { CorsOptions, CorsOptionsDelegate } from "cors";
- declare type Transport = "polling" | "websocket";
- export interface AttachOptions {
-
-
- path?: string;
-
-
- destroyUpgrade?: boolean;
-
-
- destroyUpgradeTimeout?: number;
- }
- export interface ServerOptions {
-
-
- pingTimeout?: number;
-
-
- pingInterval?: number;
-
-
- upgradeTimeout?: number;
-
-
- maxHttpBufferSize?: number;
-
-
- allowRequest?: (req: IncomingMessage, fn: (err: string | null | undefined, success: boolean) => void) => void;
-
-
- transports?: Transport[];
-
-
- allowUpgrades?: boolean;
-
-
- perMessageDeflate?: boolean | object;
-
-
- httpCompression?: boolean | object;
-
-
- wsEngine?: any;
-
-
- initialPacket?: any;
-
-
- cookie?: (CookieSerializeOptions & {
- name: string;
- }) | boolean;
-
-
- cors?: CorsOptions | CorsOptionsDelegate;
-
-
- allowEIO3?: boolean;
- }
- export declare abstract class BaseServer extends EventEmitter {
- opts: ServerOptions;
- protected clients: any;
- private clientsCount;
- protected corsMiddleware: Function;
-
-
- constructor(opts?: ServerOptions);
- protected abstract init(): any;
- /**
- * Returns a list of available transports for upgrade given a certain transport.
- *
- * @return {Array}
- * @api public
- */
- upgrades(transport: any): any;
- /**
- * Verifies a request.
- *
- * @param {http.IncomingMessage}
- * @return {Boolean} whether the request is valid
- * @api private
- */
- protected verify(req: any, upgrade: any, fn: any): any;
- /**
- * Closes all clients.
- *
- * @api public
- */
- close(): this;
- protected abstract cleanup(): any;
- /**
- * generate a socket id.
- * Overwrite this method to generate your custom socket id
- *
- * @param {Object} request object
- * @api public
- */
- generateId(req: any): any;
- /**
- * Handshakes a new client.
- *
- * @param {String} transport name
- * @param {Object} request object
- * @param {Function} closeConnection
- *
- * @api protected
- */
- protected handshake(transportName: any, req: any, closeConnection: any): Promise<any>;
- protected abstract createTransport(transportName: any, req: any): any;
- /**
- * Protocol errors mappings.
- */
- static errors: {
- UNKNOWN_TRANSPORT: number;
- UNKNOWN_SID: number;
- BAD_HANDSHAKE_METHOD: number;
- BAD_REQUEST: number;
- FORBIDDEN: number;
- UNSUPPORTED_PROTOCOL_VERSION: number;
- };
- static errorMessages: {
- 0: string;
- 1: string;
- 2: string;
- 3: string;
- 4: string;
- 5: string;
- };
- }
- export declare class Server extends BaseServer {
- httpServer?: HttpServer;
- private ws;
- /**
- * Initialize websocket server
- *
- * @api protected
- */
- protected init(): void;
- protected cleanup(): void;
- /**
- * Prepares a request by processing the query string.
- *
- * @api private
- */
- private prepare;
- protected createTransport(transportName: any, req: any): any;
- /**
- * Handles an Engine.IO HTTP request.
- *
- * @param {http.IncomingMessage} request
- * @param {http.ServerResponse|http.OutgoingMessage} response
- * @api public
- */
- handleRequest(req: any, res: any): void;
- /**
- * Handles an Engine.IO HTTP Upgrade.
- *
- * @api public
- */
- handleUpgrade(req: any, socket: any, upgradeHead: any): void;
- /**
- * Called upon a ws.io connection.
- *
- * @param {ws.Socket} websocket
- * @api private
- */
- private onWebSocket;
- /**
- * Captures upgrade requests for a http.Server.
- *
- * @param {http.Server} server
- * @param {Object} options
- * @api public
- */
- attach(server: HttpServer, options?: AttachOptions): void;
- }
- export {};
|