UNPKG

1.12 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.AbstractWsAdapter = void 0;
4const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5const core_1 = require("@nestjs/core");
6const constants_1 = require("../constants");
7class AbstractWsAdapter {
8 constructor(appOrHttpServer) {
9 if (appOrHttpServer && appOrHttpServer instanceof core_1.NestApplication) {
10 this.httpServer = appOrHttpServer.getUnderlyingHttpServer();
11 }
12 else {
13 this.httpServer = appOrHttpServer;
14 }
15 }
16 bindClientConnect(server, callback) {
17 server.on(constants_1.CONNECTION_EVENT, callback);
18 }
19 bindClientDisconnect(client, callback) {
20 client.on(constants_1.DISCONNECT_EVENT, callback);
21 }
22 async close(server) {
23 const isCallable = server && shared_utils_1.isFunction(server.close);
24 isCallable && (await new Promise(resolve => server.close(resolve)));
25 }
26 // eslint-disable-next-line @typescript-eslint/no-empty-function
27 async dispose() { }
28}
29exports.AbstractWsAdapter = AbstractWsAdapter;