I have a REST API, I want to send event to the client via websocket. How to inject websocket instance in controller or another component?
相关问题
- Nest JS - Issue writing Jest Test Case for a funct
- Django & node.js : throw arguments[1]; // Unhandle
- Socket.io Extra Placeholder Frame being sent
- how to Get all connected clients in socket.io
- websocket server, storing the data
相关文章
- Streaming music synchronously from a mp3 file via
- why is socket.id undefined in the browser
- Expressjs 4 route separation
- How to access websocket from controller or another
- Socket IO fails to connect within corporate networ
- Running socket.io on Shared Hosting
- Express - socket.io - reading session
- problems with socket.io on IE8 and 9
Better solution is to create global module. You can then emit events from any other module/controller. A. Afir approach will create multiple instances of Gateway if you try to use it in other modules.
Note: This is just simplest solution
Create
socket.module.ts
socket.service.ts
app.gateway.ts
seeafterInit
functionThen import
SocketModule
into AppModule and you can useSocket service
everywhere.class
Gateway
can be injected in another component, and use the server instance.