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;
-
- upgrades(transport: any): any;
-
- protected verify(req: any, upgrade: any, fn: any): any;
-
- close(): this;
- protected abstract cleanup(): any;
-
- generateId(req: any): any;
-
- protected handshake(transportName: any, req: any, closeConnection: any): Promise<any>;
- protected abstract createTransport(transportName: any, req: any): any;
-
- 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;
-
- protected init(): void;
- protected cleanup(): void;
-
- private prepare;
- protected createTransport(transportName: any, req: any): any;
-
- handleRequest(req: any, res: any): void;
-
- handleUpgrade(req: any, socket: any, upgradeHead: any): void;
-
- private onWebSocket;
-
- attach(server: HttpServer, options?: AttachOptions): void;
- }
- export {};
|