Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nestjs/websockets

Package Overview
Dependencies
Maintainers
1
Versions
342
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestjs/websockets - npm Package Compare versions

Comparing version 5.3.8 to 5.3.11

interfaces/hooks/index.d.ts

1

adapters/ws-adapter.js

@@ -66,2 +66,3 @@ "use strict";

bindErrorHandler(server) {
server.on(constants_1.CONNECTION_EVENT, ws => ws.on(constants_1.ERROR_EVENT, err => this.logger.error(err)));
server.on(constants_1.ERROR_EVENT, err => this.logger.error(err));

@@ -68,0 +69,0 @@ return server;

2

context/ws-context-creator.js

@@ -31,3 +31,3 @@ "use strict";

fnCanActivate && (await fnCanActivate(args));
return await this.interceptorsConsumer.intercept(interceptors, args, instance, callback, handler(args));
return this.interceptorsConsumer.intercept(interceptors, args, instance, callback, handler(args));
}, exceptionHandler);

@@ -34,0 +34,0 @@ }

@@ -1,4 +0,8 @@

import { NestGateway } from './interfaces/nest-gateway.interface';
import { MetadataScanner } from '@nestjs/core/metadata-scanner';
import { Observable } from 'rxjs';
import { NestGateway } from './interfaces/nest-gateway.interface';
export interface MessageMappingProperties {
message: any;
callback: (...args) => Observable<any> | Promise<any> | any;
}
export declare class GatewayMetadataExplorer {

@@ -11,5 +15,1 @@ private readonly metadataScanner;

}
export interface MessageMappingProperties {
message: any;
callback: (...args) => Observable<any> | Promise<any> | any;
}

@@ -27,9 +27,10 @@ "use strict";

for (const propertyKey in instance) {
if (shared_utils_1.isFunction(propertyKey))
if (shared_utils_1.isFunction(propertyKey)) {
continue;
}
const property = String(propertyKey);
const isServer = Reflect.getMetadata(constants_1.GATEWAY_SERVER_METADATA, instance, property);
if (shared_utils_1.isUndefined(isServer))
continue;
yield property;
if (!shared_utils_1.isUndefined(isServer)) {
yield property;
}
}

@@ -36,0 +37,0 @@ }

export * from './gateway-metadata.interface';
export * from './nest-gateway.interface';
export * from './hooks';
export * from './observable-socket-server.interface';
export * from './web-socket-server.interface';
export * from './on-gateway-init.interface';
export * from './on-gateway-connection.interface';
export * from './on-gateway-disconnect.interface';
export * from './gateway-middleware.interface';
export * from './ws-response.interface';
import { ReplaySubject, Subject } from 'rxjs';
export interface ObservableSocketServer {
server: any;
init: ReplaySubject<any>;
export interface ObservableSocketServer<T = any> {
server: T;
init: ReplaySubject<T>;
connection: Subject<any>;
disconnect: Subject<any>;
}

@@ -1,4 +0,4 @@

export interface WebSocketServerData {
export interface WebSocketServerOptions {
port: number;
namespace: string;
}
import { ObservableSocketServer } from './interfaces/observable-socket-server.interface';
export declare class ObservableSocket {
static create(server: any): ObservableSocketServer;
static create<T = any>(server: T): ObservableSocketServer<T>;
}
{
"name": "@nestjs/websockets",
"version": "5.3.8",
"version": "5.3.11",
"description": "Nest - modern, fast, powerful node.js web framework (@websockets)",

@@ -5,0 +5,0 @@ "author": "Kamil Mysliwiec",

@@ -61,3 +61,3 @@ <p align="center">

<a href="https://scal.io"><img src="https://nestjs.com/img/scalio-logo.svg" width="110" /></a> &nbsp; <a href="http://angularity.io"><img src="http://angularity.io/media/logo.svg" height="30" /></a> &nbsp; <a href="http://gojob.com"><img src="https://gojob.com/w/wp-content/uploads/2017/02/cropped-Logo-web-home.png" height="40" /> &nbsp; <!--<a href="https://keycdn.com"><img src="https://nestjs.com/img/keycdn.svg" height="30" /></a> &nbsp;--> <a href="https://hostpresto.com"><img src="https://nestjs.com/img/hostpresto.png" height="30" /></a> &nbsp; <a href="https://genuinebee.com/"><img src="https://nestjs.com/img/genuinebee.svg" height="34" /></a>
<a href="https://scal.io"><img src="https://nestjs.com/img/scalio-logo.svg" width="110" /></a> &nbsp; <a href="http://angularity.io"><img src="http://angularity.io/media/logo.svg" height="30" /></a> &nbsp; <a href="http://gojob.com"><img src="https://gojob.com/w/wp-content/uploads/2017/02/cropped-Logo-web-home.png" height="40" /> &nbsp; <!--<a href="https://keycdn.com"><img src="https://nestjs.com/img/keycdn.svg" height="30" /></a> &nbsp;--> <a href="https://hostpresto.com"><img src="https://nestjs.com/img/hostpresto.png" height="30" /></a> &nbsp; <a href="https://genuinebee.com/"><img src="https://nestjs.com/img/genuinebee.svg" height="38" /></a> &nbsp; <a href="http://architectnow.net/"><img src="https://nestjs.com/img/architectnow.png" height="24" /></a> &nbsp; <a href="https://quander.io/"><img src="https://nestjs.com/img/quander.png" height="28" /></a>

@@ -64,0 +64,0 @@

@@ -0,4 +1,4 @@

import { Injectable } from '@nestjs/common/interfaces/injectable.interface';
import { InstanceWrapper } from '@nestjs/core/injector/container';
import 'reflect-metadata';
import { InstanceWrapper } from '@nestjs/core/injector/container';
import { Injectable } from '@nestjs/common/interfaces/injectable.interface';
export declare class SocketModule {

@@ -5,0 +5,0 @@ private readonly socketsContainer;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const guards_consumer_1 = require("@nestjs/core/guards/guards-consumer");
const guards_context_creator_1 = require("@nestjs/core/guards/guards-context-creator");
const interceptors_consumer_1 = require("@nestjs/core/interceptors/interceptors-consumer");
const interceptors_context_creator_1 = require("@nestjs/core/interceptors/interceptors-context-creator");
const pipes_consumer_1 = require("@nestjs/core/pipes/pipes-consumer");
const pipes_context_creator_1 = require("@nestjs/core/pipes/pipes-context-creator");
const iterare_1 = require("iterare");
require("reflect-metadata");
const iterare_1 = require("iterare");
const constants_1 = require("./constants");
const container_1 = require("./container");
const web_sockets_controller_1 = require("./web-sockets-controller");
const socket_server_provider_1 = require("./socket-server-provider");
const constants_1 = require("./constants");
const exception_filters_context_1 = require("./context/exception-filters-context");
const ws_context_creator_1 = require("./context/ws-context-creator");
const ws_proxy_1 = require("./context/ws-proxy");
const exception_filters_context_1 = require("./context/exception-filters-context");
const pipes_consumer_1 = require("@nestjs/core/pipes/pipes-consumer");
const pipes_context_creator_1 = require("@nestjs/core/pipes/pipes-context-creator");
const guards_context_creator_1 = require("@nestjs/core/guards/guards-context-creator");
const guards_consumer_1 = require("@nestjs/core/guards/guards-consumer");
const interceptors_context_creator_1 = require("@nestjs/core/interceptors/interceptors-context-creator");
const interceptors_consumer_1 = require("@nestjs/core/interceptors/interceptors-consumer");
const socket_server_provider_1 = require("./socket-server-provider");
const web_sockets_controller_1 = require("./web-sockets-controller");
class SocketModule {

@@ -24,3 +24,3 @@ constructor() {

this.applicationConfig = config;
this.webSocketsController = new web_sockets_controller_1.WebSocketsController(new socket_server_provider_1.SocketServerProvider(this.socketsContainer, config), container, config, this.getContextCreator(container));
this.webSocketsController = new web_sockets_controller_1.WebSocketsController(new socket_server_provider_1.SocketServerProvider(this.socketsContainer, config), config, this.getContextCreator(container));
const modules = container.getModules();

@@ -49,3 +49,3 @@ modules.forEach(({ components }, moduleName) => this.hookGatewaysIntoServers(components, moduleName));

const servers = this.socketsContainer.getAllServers();
await Promise.all(iterare_1.default(servers.values()).map(async ({ server }) => server && (await adapter.close(server))));
await Promise.all(iterare_1.default(servers.values()).map(async ({ server }) => server && adapter.close(server)));
this.socketsContainer.clear();

@@ -52,0 +52,0 @@ }

import { Type } from '@nestjs/common/interfaces/type.interface';
import { ApplicationConfig } from '@nestjs/core/application-config';
import { NestContainer } from '@nestjs/core/injector/container';
import 'reflect-metadata';

@@ -13,21 +12,16 @@ import { Observable, Subject } from 'rxjs';

private readonly socketServerProvider;
private readonly container;
private readonly config;
private readonly contextCreator;
private readonly metadataExplorer;
private readonly middlewareInjector;
constructor(socketServerProvider: SocketServerProvider, container: NestContainer, config: ApplicationConfig, contextCreator: WsContextCreator);
constructor(socketServerProvider: SocketServerProvider, config: ApplicationConfig, contextCreator: WsContextCreator);
hookGatewayIntoServer(instance: NestGateway, metatype: Type<any>, module: string): void;
subscribeObservableServer(instance: NestGateway, options: any, port: number, module: string): void;
injectMiddleware({server}: {
server: any;
}, instance: NestGateway, module: string): void;
subscribeEvents(instance: NestGateway, messageHandlers: MessageMappingProperties[], observableServer: ObservableSocketServer): void;
getConnectionHandler(context: WebSocketsController, instance: NestGateway, messageHandlers: MessageMappingProperties[], disconnect: Subject<any>, connection: Subject<any>): (...args: any[]) => void;
subscribeEvents(instance: NestGateway, subscribersMap: MessageMappingProperties[], observableServer: ObservableSocketServer): void;
getConnectionHandler(context: WebSocketsController, instance: NestGateway, subscribersMap: MessageMappingProperties[], disconnect: Subject<any>, connection: Subject<any>): (...args: any[]) => void;
subscribeInitEvent(instance: NestGateway, event: Subject<any>): void;
subscribeConnectionEvent(instance: NestGateway, event: Subject<any>): void;
subscribeDisconnectEvent(instance: NestGateway, event: Subject<any>): void;
subscribeMessages(messageHandlers: MessageMappingProperties[], client: any, instance: NestGateway): void;
subscribeMessages<T = any>(subscribersMap: MessageMappingProperties[], client: T, instance: NestGateway): void;
pickResult(defferedResult: Promise<any>): Promise<Observable<any>>;
private hookServerToProperties(instance, server);
}

@@ -11,11 +11,8 @@ "use strict";

const gateway_metadata_explorer_1 = require("./gateway-metadata-explorer");
const middleware_injector_1 = require("./middleware-injector");
class WebSocketsController {
constructor(socketServerProvider, container, config, contextCreator) {
constructor(socketServerProvider, config, contextCreator) {
this.socketServerProvider = socketServerProvider;
this.container = container;
this.config = config;
this.contextCreator = contextCreator;
this.metadataExplorer = new gateway_metadata_explorer_1.GatewayMetadataExplorer(new metadata_scanner_1.MetadataScanner());
this.middlewareInjector = new middleware_injector_1.MiddlewareInjector(container, config);
}

@@ -31,4 +28,4 @@ hookGatewayIntoServer(instance, metatype, module) {

subscribeObservableServer(instance, options, port, module) {
const plainMessageHandlers = this.metadataExplorer.explore(instance);
const messageHandlers = plainMessageHandlers.map(({ callback, message }) => ({
const nativeMessageHandlers = this.metadataExplorer.explore(instance);
const messageHandlers = nativeMessageHandlers.map(({ callback, message }) => ({
message,

@@ -38,10 +35,6 @@ callback: this.contextCreator.create(instance, callback, module),

const observableServer = this.socketServerProvider.scanForSocketServer(options, port);
this.injectMiddleware(observableServer, instance, module);
this.hookServerToProperties(instance, observableServer.server);
this.subscribeEvents(instance, messageHandlers, observableServer);
}
injectMiddleware({ server }, instance, module) {
this.middlewareInjector.inject(server, instance, module);
}
subscribeEvents(instance, messageHandlers, observableServer) {
subscribeEvents(instance, subscribersMap, observableServer) {
const { init, disconnect, connection, server } = observableServer;

@@ -52,6 +45,6 @@ const adapter = this.config.getIoAdapter();

this.subscribeDisconnectEvent(instance, disconnect);
const handler = this.getConnectionHandler(this, instance, messageHandlers, disconnect, connection);
const handler = this.getConnectionHandler(this, instance, subscribersMap, disconnect, connection);
adapter.bindClientConnect(server, handler);
}
getConnectionHandler(context, instance, messageHandlers, disconnect, connection) {
getConnectionHandler(context, instance, subscribersMap, disconnect, connection) {
const adapter = this.config.getIoAdapter();

@@ -61,3 +54,3 @@ return (...args) => {

connection.next(args);
context.subscribeMessages(messageHandlers, client, instance);
context.subscribeMessages(subscribersMap, client, instance);
const disconnectHook = adapter.bindClientDisconnect;

@@ -87,5 +80,5 @@ disconnectHook &&

}
subscribeMessages(messageHandlers, client, instance) {
subscribeMessages(subscribersMap, client, instance) {
const adapter = this.config.getIoAdapter();
const handlers = messageHandlers.map(({ callback, message }) => ({
const handlers = subscribersMap.map(({ callback, message }) => ({
message,

@@ -92,0 +85,0 @@ callback: callback.bind(instance, client),

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc