question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about WebSocketGateway class - Emit to channel from external component

See original GitHub issue

Hi,

I have a simple WebSocketGateway:

import { WebSocketGateway, SubscribeMessage } from '@nestjs/websockets';

@WebSocketGateway({ port: 3001, namespace: 'ws' })
export class TestGateway {
  @SubscribeMessage('channel-1')
  onMessage(client, data) {
    client.emit('channel-1', data);
  }
}

I’m trying to send messages (broadcast) to this channel from other parts of the application (others components that can be or not inside the same module).

There is a way to do it without connecting via a socket.io client?

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

6reactions
ahmadarifcommented, Jan 17, 2019

Any idea to emit from controller?

3reactions
jgordorcommented, Aug 16, 2017

Solved it using:

  @WebSocketServer() 
  private server: any;

So I can:

this.server.emit('channel-1', 'Hey!');
Read more comments on GitHub >

github_iconTop Results From Across the Web

socket.io - How to access websocket from controller or another ...
Better solution is to create global module. You can then emit events from any other module/controller. A. Afir approach will create multiple ...
Read more >
Gateways | NestJS - A progressive Node.js framework
This section covers the aspects of Nest that are specific to WebSockets. In Nest, a gateway is simply a class annotated with @WebSocketGateway()...
Read more >
ESP32 WebSocket Server: Control Outputs (Arduino IDE)
Build a web server with the ESP32 using WebSocket communication protocol. We'll create a web page to control the ESP32 outputs remotely using...
Read more >
Implementing a Java Server Side component for jWebSocket ...
The Java Class JwebSockClient that I have created will start the jWebSocket Server, then register itself as a listener on it.
Read more >
Service Reference - Kaazing
The URL of a back-end service or message broker to which the proxy service (for example, proxy or amqp.proxy service) or broadcast service...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found