nestjs-gateways

How to access websocket from controller or another component/services?

。_饼干妹妹 提交于 2020-06-13 10:54:53
问题 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? 回答1: 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 import { Module, Global } from '@nestjs/common'; import { SocketService } from './socket

Not able to call Service inside WebSocket listener in Nestjs

霸气de小男生 提交于 2020-02-06 16:21:28
问题 I have implemented WebSockets in Nestjs using below method and one of the requirement is that I need to update the db once I receive any message from websocket server. In order to do that I have done the below code but getting error like this: But if I call the same method inside any other controller method it works fine(check /test1). Only when I call it from websocket listener I'm getting this error. Even if I call simple method from same controller to just print some log, I'm getting the