UNPKG

@nestjs/websockets

Version:

Nest - modern, fast, powerful node.js web framework (@websockets)

37 lines (36 loc) 1.22 kB
import { NestApplication } from '@nestjs/core'; import { CONNECTION_EVENT, DISCONNECT_EVENT } from '../constants.js'; import { isFunction } from '@nestjs/common/internal'; export class AbstractWsAdapter { httpServer; _forceCloseConnections; set forceCloseConnections(value) { this._forceCloseConnections = value; } get forceCloseConnections() { return this._forceCloseConnections; } constructor(appOrHttpServer) { if (appOrHttpServer && appOrHttpServer instanceof NestApplication) { this.httpServer = appOrHttpServer.getUnderlyingHttpServer(); } else { this.httpServer = appOrHttpServer; } } bindClientConnect(server, callback) { server.on(CONNECTION_EVENT, callback); } bindClientDisconnect(client, callback) { if (typeof client.once === 'function') { client.once(DISCONNECT_EVENT, callback); return; } client.on(DISCONNECT_EVENT, callback); } async close(server) { const isCallable = server && isFunction(server.close); isCallable && (await new Promise(resolve => server.close(resolve))); } async dispose() { } }