Inject Websocket into component
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Adding these lines:
@WebSocketServer()
public socketServer: SocketIO.Server;
Results in this.socketServer
being null
in Component
s.
It would be awesome if one could get the native web socket server from everywhere. So I do not need to create a Gateway
everytime I want to emit a simple message.
Expected behavior
Attribute is not null.
Minimal reproduction of the problem with instructions
@Component()
export class SocketService {
// Only connections that are correctly authenticated get into this array
protected authenticatedConnections: Array<SocketConnection> = [];
// this is the SocketIO server (can be used for emit etc.)
@WebSocketServer()
public socketServer: SocketIO.Server;
}
What is the motivation / use case for changing the behavior?
Environment
Nest version: 4.6.7
For Tooling issues:
- Node version: 8
- Platform:
Others:
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top Results From Across the Web
socket.io - How to access websocket from controller or another ...
I have a REST API, I want to send event to the client via websocket. How to inject websocket instance in controller or...
Read more >Using WebSockets with React - DEV Community
For my last project, I had to use Websockets to create a website that displays real-time trading data. I didn't know anything about ......
Read more >Connecting to Websocket Server from React - YouTube
This tutorial will teach you how to connect to a NestJS websocket server from a React application. We will be creating a React...
Read more >Using WebSockets in Your React/Redux App | Pluralsight
WebSockets are a convenient way to create a long-running connection between a server and a client. In an instance where a web client...
Read more >Gateways | NestJS - A progressive Node.js framework
This section covers the aspects of Nest that are specific to WebSockets. ... Hint Gateways can be treated as providers; this means they...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was having the same issue, but i had to inject it in one gateway, that gateway dose not do anything, you can think of it as wrapper around the underlying socket server, and then i used it as a dependency in another gateways. Idk if this the only way to do this, but it works 😃
Honestly, it’s not that easy. What if someone uses multiple gateways at the same time? IMO, you should inject a gateway to the component instead and pick up the server then.