@nestjs/websockets
Advanced tools
Comparing version 6.5.3 to 6.6.0
export * from './gateway-metadata.interface'; | ||
export * from './hooks'; | ||
export * from './observable-socket-server.interface'; | ||
export * from './socket-events-host.interface'; | ||
export * from './web-socket-server.interface'; | ||
export * from './ws-response.interface'; |
{ | ||
"name": "@nestjs/websockets", | ||
"version": "6.5.3", | ||
"version": "6.6.0", | ||
"description": "Nest - modern, fast, powerful node.js web framework (@websockets)", | ||
@@ -5,0 +5,0 @@ "author": "Kamil Mysliwiec", |
@@ -5,8 +5,6 @@ <p align="center"> | ||
[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master | ||
[travis-url]: https://travis-ci.org/nestjs/nest | ||
[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux | ||
[linux-url]: https://travis-ci.org/nestjs/nest | ||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 | ||
[circleci-url]: https://circleci.com/gh/nestjs/nest | ||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications, heavily inspired by <a href="https://angular.io" target="blank">Angular</a>.</p> | ||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p> | ||
<p align="center"> | ||
@@ -16,4 +14,3 @@ <a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a> | ||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a> | ||
<a href="https://travis-ci.org/nestjs/nest" target="_blank"><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a> | ||
<a href="https://travis-ci.org/nestjs/nest" target="_blank"><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a> | ||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a> | ||
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a> | ||
@@ -20,0 +17,0 @@ <a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a> |
@@ -12,3 +12,2 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
const container_1 = require("./container"); | ||
const exception_filters_context_1 = require("./context/exception-filters-context"); | ||
@@ -18,6 +17,7 @@ const ws_context_creator_1 = require("./context/ws-context-creator"); | ||
const socket_server_provider_1 = require("./socket-server-provider"); | ||
const sockets_container_1 = require("./sockets-container"); | ||
const web_sockets_controller_1 = require("./web-sockets-controller"); | ||
class SocketModule { | ||
constructor() { | ||
this.socketsContainer = new container_1.SocketsContainer(); | ||
this.socketsContainer = new sockets_container_1.SocketsContainer(); | ||
} | ||
@@ -57,3 +57,3 @@ register(container, config, httpServer) { | ||
} | ||
const servers = this.socketsContainer.getAllServers(); | ||
const servers = this.socketsContainer.getAllSocketEventHosts(); | ||
await Promise.all(iterare_1.default(servers.values()) | ||
@@ -60,0 +60,0 @@ .filter(({ server }) => server) |
import { ApplicationConfig } from '@nestjs/core/application-config'; | ||
import { SocketsContainer } from './container'; | ||
import { GatewayMetadata } from './interfaces/gateway-metadata.interface'; | ||
import { ObservableSocketServer } from './interfaces/observable-socket-server.interface'; | ||
import { SocketEventsHost } from './interfaces/socket-events-host.interface'; | ||
import { SocketsContainer } from './sockets-container'; | ||
export declare class SocketServerProvider { | ||
@@ -9,3 +9,3 @@ private readonly socketsContainer; | ||
constructor(socketsContainer: SocketsContainer, applicationConfig: ApplicationConfig); | ||
scanForSocketServer<T extends GatewayMetadata>(options: T, port: number): ObservableSocketServer; | ||
scanForSocketServer<T extends GatewayMetadata>(options: T, port: number): SocketEventsHost; | ||
private createSocketServer; | ||
@@ -12,0 +12,0 @@ private createWithNamespace; |
@@ -16,3 +16,3 @@ "use strict"; | ||
const util_1 = require("util"); | ||
const observable_socket_1 = require("./observable-socket"); | ||
const socket_events_host_factory_1 = require("./socket-events-host-factory"); | ||
class SocketServerProvider { | ||
@@ -24,24 +24,24 @@ constructor(socketsContainer, applicationConfig) { | ||
scanForSocketServer(options, port) { | ||
const observableServer = this.socketsContainer.getServerByPort(port); | ||
return observableServer | ||
? this.createWithNamespace(options, port, observableServer) | ||
const socketEventsHost = this.socketsContainer.getSocketEventsHostByPort(port); | ||
return socketEventsHost | ||
? this.createWithNamespace(options, port, socketEventsHost) | ||
: this.createSocketServer(options, port); | ||
} | ||
createSocketServer(options, port) { | ||
const _a = options, { namespace, server } = _a, opt = __rest(_a, ["namespace", "server"]); | ||
const _a = options, { namespace, server } = _a, partialOptions = __rest(_a, ["namespace", "server"]); | ||
const adapter = this.applicationConfig.getIoAdapter(); | ||
const ioServer = adapter.create(port, opt); | ||
const observableSocket = observable_socket_1.ObservableSocket.create(ioServer); | ||
this.socketsContainer.addServer(null, port, observableSocket); | ||
const ioServer = adapter.create(port, partialOptions); | ||
const observableSocket = socket_events_host_factory_1.SocketEventsHostFactory.create(ioServer); | ||
this.socketsContainer.addSocketEventsHost(null, port, observableSocket); | ||
return this.createWithNamespace(options, port, observableSocket); | ||
} | ||
createWithNamespace(options, port, observableSocket) { | ||
createWithNamespace(options, port, socketEventsHost) { | ||
const { namespace } = options; | ||
if (!namespace) { | ||
return observableSocket; | ||
return socketEventsHost; | ||
} | ||
const namespaceServer = this.getServerOfNamespace(options, port, observableSocket.server); | ||
const observableNamespaceSocket = observable_socket_1.ObservableSocket.create(namespaceServer); | ||
this.socketsContainer.addServer(namespace, port, observableNamespaceSocket); | ||
return observableNamespaceSocket; | ||
const namespaceServer = this.getServerOfNamespace(options, port, socketEventsHost.server); | ||
const eventsHost = socket_events_host_factory_1.SocketEventsHostFactory.create(namespaceServer); | ||
this.socketsContainer.addSocketEventsHost(namespace, port, eventsHost); | ||
return eventsHost; | ||
} | ||
@@ -48,0 +48,0 @@ getServerOfNamespace(options, port, server) { |
@@ -7,3 +7,3 @@ import { Type } from '@nestjs/common/interfaces/type.interface'; | ||
import { NestGateway } from './interfaces/nest-gateway.interface'; | ||
import { ObservableSocketServer } from './interfaces/observable-socket-server.interface'; | ||
import { SocketEventsHost } from './interfaces/socket-events-host.interface'; | ||
import { SocketServerProvider } from './socket-server-provider'; | ||
@@ -17,4 +17,4 @@ export declare class WebSocketsController { | ||
mergeGatewayAndServer(instance: NestGateway, metatype: Type<any> | Function, module: string): void; | ||
subscribeObservableServer(instance: NestGateway, options: any, port: number, module: string): void; | ||
subscribeEvents(instance: NestGateway, subscribersMap: MessageMappingProperties[], observableServer: ObservableSocketServer): void; | ||
subscribeToServerEvents(instance: NestGateway, options: any, port: number, module: string): void; | ||
subscribeEvents(instance: NestGateway, subscribersMap: MessageMappingProperties[], observableServer: SocketEventsHost): void; | ||
getConnectionHandler(context: WebSocketsController, instance: NestGateway, subscribersMap: MessageMappingProperties[], disconnect: Subject<any>, connection: Subject<any>): (...args: any[]) => void; | ||
@@ -26,3 +26,3 @@ subscribeInitEvent(instance: NestGateway, event: Subject<any>): void; | ||
pickResult(defferedResult: Promise<any>): Promise<Observable<any>>; | ||
private hookServerToProperties; | ||
private assignServerToProperties; | ||
} |
@@ -23,5 +23,5 @@ "use strict"; | ||
} | ||
this.subscribeObservableServer(instance, options, port, module); | ||
this.subscribeToServerEvents(instance, options, port, module); | ||
} | ||
subscribeObservableServer(instance, options, port, module) { | ||
subscribeToServerEvents(instance, options, port, module) { | ||
const nativeMessageHandlers = this.metadataExplorer.explore(instance); | ||
@@ -33,3 +33,3 @@ const messageHandlers = nativeMessageHandlers.map(({ callback, message }) => ({ | ||
const observableServer = this.socketServerProvider.scanForSocketServer(options, port); | ||
this.hookServerToProperties(instance, observableServer.server); | ||
this.assignServerToProperties(instance, observableServer.server); | ||
this.subscribeEvents(instance, messageHandlers, observableServer); | ||
@@ -94,3 +94,3 @@ } | ||
} | ||
hookServerToProperties(instance, server) { | ||
assignServerToProperties(instance, server) { | ||
for (const propertyKey of this.metadataExplorer.scanForServerHooks(instance)) { | ||
@@ -97,0 +97,0 @@ Reflect.set(instance, propertyKey, server); |
58547
72
926
87