[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Gateway handles connections and events but client.emit() or even server.emit() doesn't work. My client doesn't receive messages.
Gateways are able to return acknowledgement to emitter, but only by return of events
I would like client.emit(event, data) send event and data to appropriate clients.
Here a gist of minimal gateway with simple broadcast: https://gist.github.com/nesteban-aldera/8955be4d8edbf41fc64b203525614e0b
My main.ts:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { WsAdapter } from '@nestjs/websockets';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useWebSocketAdapter(new WsAdapter());
await app.listen(3000);
}
bootstrap();
My app.module.ts:
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SimpleWebSocketGateway } from 'simple-web-socket/simple-web-socket.gateway';
@Module({
imports: [],
controllers: [AppController],
providers: [AppService, SimpleWebSocketGateway],
})
export class AppModule {}
I'm working on web editor with collaboration features.
Nest version: 5.4.0
For Tooling issues:
- Node version: 11.2.0
- Platform: Linux
Others:
For client code, I use two clients:
- Browser WebSocket Client (chrome extension)
- Ionic client with rxjs-websockets
I made a simple test using an other server side code (https://github.com/HenningM/express-ws). With same socket clients. Sending data from server to client works like a charm.
I guess there is an issue when I try to use emit() method. It returns false every time.
From my point of view, there is an issue on WebSocket with Nest 5.4.0 or a lack of documentation on socket configuration. I will investigate more on this and I'm ready contribute if necessary.
Could you provide a reproduction repository (so I could test your issue locally)?
Finally, I found the issue !
I replaced c.emit() by c.send() and it works like a charm. Is it normal and do I make a request for updating document ?
I'm glad that you have found a solution to your issue! Feel free to create a PR to docs whenever you want to.
@kamilmysliwiec indeed still with WsAdapter both server.emit and client.emit just return false without sending message or giving any clues what wrong and why its not working. its really confusing and is it how its supposed to be? Why emit dont work? its not throwing any exception or anything but dont send. Is it only issue in documentation or in behaviour too?
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.
Most helpful comment
@kamilmysliwiec indeed still with WsAdapter both server.emit and client.emit just return false without sending message or giving any clues what wrong and why its not working. its really confusing and is it how its supposed to be? Why emit dont work? its not throwing any exception or anything but dont send. Is it only issue in documentation or in behaviour too?