title: Emit websocket event from a NestJS controller or service
body: <p>I am trying to listen to model change events in TypeORM through a subscriber, and broadcast an event each time a new one is inserted. While external clients receive the event, the gateway's <code>@SubscribeMessage()</code> method is not receiving it, which suggests that the sender is not getting the event. However, according to <a href="https://socket.io/docs/emit-cheatsheet/" rel="noreferrer">socket.io</a>, the <code>of('namespace').emit('event')</code> should be received to any client, including the sender.</p>
  
  <p>The gateway is injected to the subscriber service without any issue, and the gateway's server seems to be ready when I try to use it, but no event is emitted.</p>
  
  <p>Running on NestJS 6.3.1, I have also tried emitting the event from the controller, with no results.</p>
  
  <pre class="lang-js prettyprint-override"><code>@WebSocketGateway({ namespace: '/posts' })
  export class PostGateway {
  
    @WebSocketServer()
    server: Namespace;
  
    @SubscribeMessage('create')
    handleMessage(client: Socket, payload: Post): void {
      console.log('handling', payload);
    }
  
  }
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>@Injectable()
  export class PostSubscriber implements EntitySubscriberInterface&lt;Post&gt; {
  
    private socket: Namespace;
  
    constructor(
      @InjectConnection() readonly connection: Connection,
      private readonly gateway: PostGateway,
    ) {
      connection.subscribers.push(this);
      this.socket = gateway.server;
    }
  
    listenTo() {
      return Measurement;
    }
  
    afterInsert(event: InsertEvent&lt;Post&gt;): void {
      this.gateway.server.emit('create', event.entity);
    }
  
  }
  
  </code></pre>