I have created a websocket gateway (child.ts) that extends an abstract class (parent.ts). When the same event, e.g. @SubscribeMessage('test1') is in both the parent and the child, the event response is fired twice. I.e. on a single event, test1, the server will provide 2 responses: ["test1", "child"] and ["test1", "child"].
Input Code
parent.ts
import { SubscribeMessage, WsResponse } from '@nestjs/websockets';
import { Observable, of } from 'rxjs';
export abstract class Parent {
protected constructor() {
}
@SubscribeMessage('test1')
public onTest1(client: any, data?: any): Observable<WsResponse<any>> {
const event = 'test1';
return of({event, data: 'parent'});
}
@SubscribeMessage('test2')
public onTest2(client: any, data?: any): Observable<WsResponse<any>> {
const event = 'test2';
return of({event, data: 'parent'});
}
}
child.ts
import { SubscribeMessage, WebSocketGateway, WsResponse } from '@nestjs/websockets';
import { Observable, of } from 'rxjs';
import { Parent } from './parent';
@WebSocketGateway()
export class Child extends Parent {
constructor() {
super();
}
@SubscribeMessage('test1')
public onTest1(client: any, data?: any): Observable<WsResponse<any>> {
const event = 'test1';
return of({event, data: 'child'});
}
}
app.module.ts
import { Module } from '@nestjs/common';
import { Child } from './child';
@Module({
imports: [],
providers: [
Child
],
controllers: []
})
export class ApplicationModule {
}
main.ts
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);
await app.listen(80);
}
bootstrap();
Expected Behaviour
The overridden event listener should only fire once based on the method provided in the child. The response ["test1", "child"] should only be received once by the client.
My goal is to have a generic class with standardized event listeners, that can be extended and overridden by a more specific implementation as required based on different project/gateway requirements.
Environment
Nest version: 6.5.2
Typescript: 3.5.3
For Tooling issues:
- Node version: 10.15.0
- Platform: Mac
Bug Report
Current Behaviour
I have created a websocket gateway (child.ts) that extends an abstract class (parent.ts). When the same event, e.g.
@SubscribeMessage('test1')
is in both the parent and the child, the event response is fired twice. I.e. on a single event,test1
, the server will provide 2 responses:["test1", "child"]
and["test1", "child"]
.Input Code
parent.ts
child.ts
app.module.ts
main.ts
Expected Behaviour
The overridden event listener should only fire once based on the method provided in the child. The response
["test1", "child"]
should only be received once by the client.My goal is to have a generic class with standardized event listeners, that can be extended and overridden by a more specific implementation as required based on different project/gateway requirements.
Environment