Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SubscribeMessage Events Fire Multiple Times When using Class Inheritance #2557

Closed
nawilson opened this issue Jul 11, 2019 · 2 comments
Closed

Comments

@nawilson
Copy link

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

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
@nawilson nawilson added the needs triage This issue has not been looked into label Jul 11, 2019
@kamilmysliwiec kamilmysliwiec added this to the 6.7.0 milestone Sep 10, 2019
@kamilmysliwiec
Copy link
Member

Fixed in 6.7.0 :)

@lock
Copy link

lock bot commented Dec 15, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants