@nestjs/websockets
Version:
WebSockets for NestJS: gateways with message handlers, guards, pipes and interceptors, on Socket.IO or ws.
36 lines (35 loc) • 1.91 kB
TypeScript
import type { INestApplicationContext, WebSocketAdapter } from '@nestjs/common';
import { Observable } from 'rxjs';
import type { WsMessageHandler } from '@nestjs/common';
export interface BaseWsInstance {
on: (event: string, callback: Function) => void;
close: Function;
}
export declare abstract class AbstractWsAdapter<TServer extends BaseWsInstance = any, TClient extends BaseWsInstance = any, TOptions = any> implements WebSocketAdapter<TServer, TClient, TOptions> {
protected readonly httpServer: any;
private _forceCloseConnections;
set forceCloseConnections(value: boolean);
get forceCloseConnections(): boolean;
constructor(appOrHttpServer?: INestApplicationContext | object);
bindClientConnect(server: TServer, callback: Function): void;
bindClientDisconnect(client: TClient, callback: Function): void;
/**
* Drops a client that connected while the lifecycle hooks of the application
* ("onModuleInit", "onApplicationBootstrap") were still running. Neither the
* connection hook of the gateway nor its message handlers were bound to this
* client, so it is expected to connect again.
*/
closeClient(client: TClient): void;
close(server: TServer): Promise<void>;
dispose(): Promise<void>;
abstract create(port: number, options?: TOptions): TServer;
/**
* Creates the server of a gateway without a port in an application without
* an HTTP server to serve it on, such as a standalone microservice. The
* server does not listen for clients, but it can still be used, e.g. to
* broadcast through an adapter shared with other processes. Without this
* method, `create(0, options)` is called instead.
*/
createWithoutListener?(options?: TOptions): TServer;
abstract bindMessageHandlers(client: TClient, handlers: WsMessageHandler[], transform: (data: any) => Observable<any>): any;
}