Skip to content

PolyHx/Node-Seed-Project

Repository files navigation

Node-Seed-Project

This project is using NestJs, go check the NestJs documentation for more details : https://docs.nestjs.com/

WebSockets

By default, the server is using socket.io. However, Ws is supported.

How to use Ws

In server.ts, remove the comment of the line 27

nestApp.useWebSocketAdapter(new WsAdapter());

In Gateways, you must use WsServer

@WebSocketServer()
private WsServer: WebSocket.Server;

To send a message to all connected user

for (let client of this.WsServer.clients) {
    client.send(JSON.stringify({ type: "event", data: "Hello World!" }));
}

All messages must have a type and a data property. The type property is detected by the SubscribeMessage decorator

@SubscribeMessage('event')

{
   type: "event",
   data: {
       some: "Data",
       to: "send"
   }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published