nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.69k stars 7.63k forks source link

nestjs/websockets #1165

Closed ecrona closed 6 years ago

ecrona commented 6 years ago

I'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

I like NestJS & NestJS' websockets module, but I can't build what I want to build with how Gateway methods use it's arguments. A gateway method looks something like this

  @SubscribeMessage('events')
  findAll(client, data): Observable> {
    return from([1, 2, 3]).pipe(map(item => ({ event: 'events', data: item })));
  }

What I'm trying to do is to share endpoints between backend and frontend, so the arguments of the method in backend and frontend look the same, but the first argument in a websocket method is always client, is there a possible workaround for that?

It would be nicer to only have the parameter data as method arguments, such as when using normal controllers and their methods. Or maybe if the arguments could be switched.

Possibly that the client object could be obtained from the class instance, or by binding the function with client data.

Expected behavior

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Maybe this is more of a question than a request, but I hope you understand my thoughts :)

Environment


Nest version: 5.3.10


For Tooling issues:
- Node version: 8.9.2  
- Platform: Linux  

Others:

kamilmysliwiec commented 6 years ago

You should delegate business logic to services and simply call corresponding methods from within either gateway or controller. I don't think that combining gateway specific decorators and controller ones is a good idea, to be honest.

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.