@nestjs/websockets 9.2.1 → 9.3.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/Readme.md +6 -3
- package/interfaces/websockets-entrypoint-metadata.interface.d.ts +4 -0
- package/interfaces/websockets-entrypoint-metadata.interface.js +2 -0
- package/package.json +3 -3
- package/socket-module.d.ts +5 -2
- package/socket-module.js +6 -5
- package/web-sockets-controller.d.ts +8 -3
- package/web-sockets-controller.js +26 -4
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(The MIT License)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017-
|
|
3
|
+
Copyright (c) 2017-2023 Kamil Mysliwiec <https://kamilmysliwiec.com>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/Readme.md
CHANGED
|
@@ -80,7 +80,8 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
|
|
|
80
80
|
<a href="https://snyk.co/nestjs" target="_blank"><img src="https://nestjs.com/img/snyk-logo-black.png" width="185" valign="middle" /></a></td><td>
|
|
81
81
|
<a href="https://fuseautotech.com/" target="_blank"><img src="https://nestjs.com/img/fuse-logo.svg" width="105" valign="middle" /></a></td>
|
|
82
82
|
<td>
|
|
83
|
-
<a href="https://ridicorp.com/career/" target="_blank"><img src="https://nestjs.com/img/ridi-logo.svg" width="105" valign="middle" /></a></td
|
|
83
|
+
<a href="https://ridicorp.com/career/" target="_blank"><img src="https://nestjs.com/img/ridi-logo.svg" width="105" valign="middle" /></a></td><td>
|
|
84
|
+
<a href="https://www.movavi.com/imovie-for-windows.html" target="_blank"><img src="https://nestjs.com/img/movavi-logo.svg" width="105" valign="middle" /></a></td></</tr></table>
|
|
84
85
|
|
|
85
86
|
#### Silver Sponsors
|
|
86
87
|
|
|
@@ -93,7 +94,8 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
|
|
|
93
94
|
<td><a href="https://www.tinystacks.com" target="_blank"><img src="https://nestjs.com/img/tinystacks-logo.png#1" width="140" valign="middle" /></td>
|
|
94
95
|
<td><a href="https://n.inc" target="_blank"><img src="https://nestjs.com/img/n-inc-logo.svg" width="120" valign="middle" /></td></tr><tr>
|
|
95
96
|
<td><a href="https://bilberrry.com/" target="_blank"><img src="https://nestjs.com/img/bilberrry-logo.svg" width="180" valign="middle" /></td>
|
|
96
|
-
<td><a href="https://ipinfo.ai/" target="_blank"><img src="https://nestjs.com/img/ipinfo-logo.png" width="130" valign="middle" /></td
|
|
97
|
+
<td><a href="https://ipinfo.ai/" target="_blank"><img src="https://nestjs.com/img/ipinfo-logo.png" width="130" valign="middle" /></td>
|
|
98
|
+
<td><a href="https://chax.at" target="_blank"><img src="https://nestjs.com/img/chaxat-logo.png" width="100" valign="middle" /></td></tr>
|
|
97
99
|
</table>
|
|
98
100
|
|
|
99
101
|
#### Sponsors
|
|
@@ -134,7 +136,8 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
|
|
|
134
136
|
<td align="center" valign="middle"><a href="https://mobilereality.pl/" target="_blank"><img src="https://nestjs.com/img/mobile-reality-logo.png" width="45" valign="middle" /></a></td>
|
|
135
137
|
<td align="center" valign="middle"><a href="https://boringowl.io/" target="_blank"><img src="https://nestjs.com/img/boringowl-logo.svg" width="120" valign="middle" /></a></td>
|
|
136
138
|
<td align="center" valign="middle"><a href="https://www.mobilefactory.jp/" target="_blank"><img src="https://nestjs.com/img/mobilefactory-logo.png" width="100" valign="middle" /></a></td>
|
|
137
|
-
<td align="center" valign="middle"><a href="https://
|
|
139
|
+
<td align="center" valign="middle"><a href="https://nordbot.app/" target="_blank"><img src="https://nestjs.com/img/nordbot-logo.png" width="120" valign="middle" /></a></td>
|
|
140
|
+
<td align="center" valign="middle"><a href="https://doppio.sh/" target="_blank"><img src="https://nestjs.com/img/dopiosh-logo.png" width="50" valign="middle" /></a></td>
|
|
138
141
|
</tr></table>
|
|
139
142
|
|
|
140
143
|
## Backers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/websockets",
|
|
3
|
-
"version": "9.2
|
|
3
|
+
"version": "9.3.0-beta.2",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@websockets)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"tslib": "2.4.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@nestjs/common": "9.2
|
|
21
|
-
"@nestjs/core": "9.2
|
|
20
|
+
"@nestjs/common": "^9.3.0-beta.2",
|
|
21
|
+
"@nestjs/core": "^9.3.0-beta.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@nestjs/common": "^9.0.0",
|
package/socket-module.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common/interfaces/injectable.interface';
|
|
2
|
+
import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
|
|
2
3
|
import { ApplicationConfig } from '@nestjs/core/application-config';
|
|
3
4
|
import { NestContainer } from '@nestjs/core/injector/container';
|
|
4
5
|
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
|
|
5
6
|
import { InstanceToken } from '@nestjs/core/injector/module';
|
|
6
|
-
|
|
7
|
+
import { GraphInspector } from '@nestjs/core/inspector/graph-inspector';
|
|
8
|
+
export declare class SocketModule<THttpServer = any, TAppOptions extends NestApplicationContextOptions = NestApplicationContextOptions> {
|
|
7
9
|
private readonly socketsContainer;
|
|
8
10
|
private applicationConfig;
|
|
9
11
|
private webSocketsController;
|
|
10
12
|
private isAdapterInitialized;
|
|
11
13
|
private httpServer;
|
|
12
|
-
|
|
14
|
+
private appOptions;
|
|
15
|
+
register(container: NestContainer, applicationConfig: ApplicationConfig, graphInspector: GraphInspector, appOptions: TAppOptions, httpServer?: THttpServer): void;
|
|
13
16
|
connectAllGateways(providers: Map<InstanceToken, InstanceWrapper<Injectable>>, moduleName: string): void;
|
|
14
17
|
connectGatewayToServer(wrapper: InstanceWrapper<Injectable>, moduleName: string): void;
|
|
15
18
|
close(): Promise<any>;
|
package/socket-module.js
CHANGED
|
@@ -20,12 +20,13 @@ class SocketModule {
|
|
|
20
20
|
constructor() {
|
|
21
21
|
this.socketsContainer = new sockets_container_1.SocketsContainer();
|
|
22
22
|
}
|
|
23
|
-
register(container,
|
|
24
|
-
this.applicationConfig =
|
|
23
|
+
register(container, applicationConfig, graphInspector, appOptions, httpServer) {
|
|
24
|
+
this.applicationConfig = applicationConfig;
|
|
25
|
+
this.appOptions = appOptions;
|
|
25
26
|
this.httpServer = httpServer;
|
|
26
27
|
const contextCreator = this.getContextCreator(container);
|
|
27
|
-
const serverProvider = new socket_server_provider_1.SocketServerProvider(this.socketsContainer,
|
|
28
|
-
this.webSocketsController = new web_sockets_controller_1.WebSocketsController(serverProvider,
|
|
28
|
+
const serverProvider = new socket_server_provider_1.SocketServerProvider(this.socketsContainer, applicationConfig);
|
|
29
|
+
this.webSocketsController = new web_sockets_controller_1.WebSocketsController(serverProvider, applicationConfig, contextCreator, graphInspector, this.appOptions);
|
|
29
30
|
const modules = container.getModules();
|
|
30
31
|
modules.forEach(({ providers }, moduleName) => this.connectAllGateways(providers, moduleName));
|
|
31
32
|
}
|
|
@@ -43,7 +44,7 @@ class SocketModule {
|
|
|
43
44
|
if (!this.isAdapterInitialized) {
|
|
44
45
|
this.initializeAdapter();
|
|
45
46
|
}
|
|
46
|
-
this.webSocketsController.connectGatewayToServer(instance, metatype, moduleName);
|
|
47
|
+
this.webSocketsController.connectGatewayToServer(instance, metatype, moduleName, wrapper.id);
|
|
47
48
|
}
|
|
48
49
|
async close() {
|
|
49
50
|
if (!this.applicationConfig) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
|
|
1
2
|
import { Type } from '@nestjs/common/interfaces/type.interface';
|
|
2
3
|
import { ApplicationConfig } from '@nestjs/core/application-config';
|
|
4
|
+
import { GraphInspector } from '@nestjs/core/inspector/graph-inspector';
|
|
3
5
|
import { Observable, Subject } from 'rxjs';
|
|
4
6
|
import { WsContextCreator } from './context/ws-context-creator';
|
|
5
7
|
import { MessageMappingProperties } from './gateway-metadata-explorer';
|
|
@@ -11,11 +13,13 @@ export declare class WebSocketsController {
|
|
|
11
13
|
private readonly socketServerProvider;
|
|
12
14
|
private readonly config;
|
|
13
15
|
private readonly contextCreator;
|
|
16
|
+
private readonly graphInspector;
|
|
17
|
+
private readonly appOptions;
|
|
14
18
|
private readonly logger;
|
|
15
19
|
private readonly metadataExplorer;
|
|
16
|
-
constructor(socketServerProvider: SocketServerProvider, config: ApplicationConfig, contextCreator: WsContextCreator);
|
|
17
|
-
connectGatewayToServer(instance: NestGateway, metatype: Type<unknown> | Function, moduleKey: string): void;
|
|
18
|
-
subscribeToServerEvents<T extends GatewayMetadata>(instance: NestGateway, options: T, port: number, moduleKey: string): void;
|
|
20
|
+
constructor(socketServerProvider: SocketServerProvider, config: ApplicationConfig, contextCreator: WsContextCreator, graphInspector: GraphInspector, appOptions?: NestApplicationContextOptions);
|
|
21
|
+
connectGatewayToServer(instance: NestGateway, metatype: Type<unknown> | Function, moduleKey: string, instanceWrapperId: string): void;
|
|
22
|
+
subscribeToServerEvents<T extends GatewayMetadata>(instance: NestGateway, options: T, port: number, moduleKey: string, instanceWrapperId: string): void;
|
|
19
23
|
subscribeEvents(instance: NestGateway, subscribersMap: MessageMappingProperties[], observableServer: ServerAndEventStreamsHost): void;
|
|
20
24
|
getConnectionHandler(context: WebSocketsController, instance: NestGateway, subscribersMap: MessageMappingProperties[], disconnect: Subject<any>, connection: Subject<any>): (...args: unknown[]) => void;
|
|
21
25
|
subscribeInitEvent(instance: NestGateway, event: Subject<any>): void;
|
|
@@ -23,6 +27,7 @@ export declare class WebSocketsController {
|
|
|
23
27
|
subscribeDisconnectEvent(instance: NestGateway, event: Subject<any>): void;
|
|
24
28
|
subscribeMessages<T = any>(subscribersMap: MessageMappingProperties[], client: T, instance: NestGateway): void;
|
|
25
29
|
pickResult(deferredResult: Promise<any>): Promise<Observable<any>>;
|
|
30
|
+
inspectEntrypointDefinitions(instance: NestGateway, port: number, messageHandlers: MessageMappingProperties[], instanceWrapperId: string): void;
|
|
26
31
|
private assignServerToProperties;
|
|
27
32
|
private printSubscriptionLogs;
|
|
28
33
|
}
|
|
@@ -10,30 +10,36 @@ const invalid_socket_port_exception_1 = require("./errors/invalid-socket-port.ex
|
|
|
10
10
|
const gateway_metadata_explorer_1 = require("./gateway-metadata-explorer");
|
|
11
11
|
const compare_element_util_1 = require("./utils/compare-element.util");
|
|
12
12
|
class WebSocketsController {
|
|
13
|
-
constructor(socketServerProvider, config, contextCreator) {
|
|
13
|
+
constructor(socketServerProvider, config, contextCreator, graphInspector, appOptions = {}) {
|
|
14
14
|
this.socketServerProvider = socketServerProvider;
|
|
15
15
|
this.config = config;
|
|
16
16
|
this.contextCreator = contextCreator;
|
|
17
|
+
this.graphInspector = graphInspector;
|
|
18
|
+
this.appOptions = appOptions;
|
|
17
19
|
this.logger = new logger_service_1.Logger(WebSocketsController.name, {
|
|
18
20
|
timestamp: true,
|
|
19
21
|
});
|
|
20
22
|
this.metadataExplorer = new gateway_metadata_explorer_1.GatewayMetadataExplorer(new metadata_scanner_1.MetadataScanner());
|
|
21
23
|
}
|
|
22
|
-
connectGatewayToServer(instance, metatype, moduleKey) {
|
|
24
|
+
connectGatewayToServer(instance, metatype, moduleKey, instanceWrapperId) {
|
|
23
25
|
const options = Reflect.getMetadata(constants_1.GATEWAY_OPTIONS, metatype) || {};
|
|
24
26
|
const port = Reflect.getMetadata(constants_1.PORT_METADATA, metatype) || 0;
|
|
25
27
|
if (!Number.isInteger(port)) {
|
|
26
28
|
throw new invalid_socket_port_exception_1.InvalidSocketPortException(port, metatype);
|
|
27
29
|
}
|
|
28
|
-
this.subscribeToServerEvents(instance, options, port, moduleKey);
|
|
30
|
+
this.subscribeToServerEvents(instance, options, port, moduleKey, instanceWrapperId);
|
|
29
31
|
}
|
|
30
|
-
subscribeToServerEvents(instance, options, port, moduleKey) {
|
|
32
|
+
subscribeToServerEvents(instance, options, port, moduleKey, instanceWrapperId) {
|
|
31
33
|
const nativeMessageHandlers = this.metadataExplorer.explore(instance);
|
|
32
34
|
const messageHandlers = nativeMessageHandlers.map(({ callback, message, methodName }) => ({
|
|
33
35
|
message,
|
|
34
36
|
methodName,
|
|
35
37
|
callback: this.contextCreator.create(instance, callback, moduleKey, methodName),
|
|
36
38
|
}));
|
|
39
|
+
this.inspectEntrypointDefinitions(instance, port, messageHandlers, instanceWrapperId);
|
|
40
|
+
if (this.appOptions.preview) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
37
43
|
const observableServer = this.socketServerProvider.scanForSocketServer(options, port);
|
|
38
44
|
this.assignServerToProperties(instance, observableServer.server);
|
|
39
45
|
this.subscribeEvents(instance, messageHandlers, observableServer);
|
|
@@ -96,6 +102,22 @@ class WebSocketsController {
|
|
|
96
102
|
}
|
|
97
103
|
return (0, rxjs_1.of)(result);
|
|
98
104
|
}
|
|
105
|
+
inspectEntrypointDefinitions(instance, port, messageHandlers, instanceWrapperId) {
|
|
106
|
+
messageHandlers.forEach(handler => {
|
|
107
|
+
var _a;
|
|
108
|
+
this.graphInspector.insertEntrypointDefinition({
|
|
109
|
+
type: 'websocket',
|
|
110
|
+
methodName: handler.methodName,
|
|
111
|
+
className: (_a = instance.constructor) === null || _a === void 0 ? void 0 : _a.name,
|
|
112
|
+
classNodeId: instanceWrapperId,
|
|
113
|
+
metadata: {
|
|
114
|
+
port,
|
|
115
|
+
key: handler.message,
|
|
116
|
+
message: handler.message,
|
|
117
|
+
},
|
|
118
|
+
}, instanceWrapperId);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
99
121
|
assignServerToProperties(instance, server) {
|
|
100
122
|
for (const propertyKey of this.metadataExplorer.scanForServerHooks(instance)) {
|
|
101
123
|
Reflect.set(instance, propertyKey, server);
|