PACKAGES

Rasengan WS

@rasenganjs/ws adds NestJS-inspired WebSocket Gateways to Rasengan Server — rooms, broadcasting, and a { event, data } message envelope, resolved through the same DI container as your HTTP controllers.

Installation

Terminal
npm install @rasenganjs/ws

Usage

main.ts
import { bootstrap } from '@rasenganjs/server'; import { createWsPlugin } from '@rasenganjs/ws'; import appModule from './app.module'; bootstrap((app) => { app.registerPlugin(createWsPlugin()); app.registerModule(appModule); // may declare gateways: [ChatGateway] });
chat.gateway.ts
import { Gateway, GatewayRouter, type GatewayClient } from '@rasenganjs/ws'; export class ChatGateway extends Gateway { path = '/chat'; onConnect(client: GatewayClient) { client.join('lobby'); } messages(router: GatewayRouter) { router.on('sendMessage', (client, data: { text: string }) => { client .to('lobby') .emit('newMessage', { text: data.text, from: client.id }); }); } }
chat.module.ts
import { defineModule } from '@rasenganjs/server'; import { ChatGateway } from './chat.gateway'; export default defineModule({ gateways: [ChatGateway], });

Scaling Across Processes

The default MemoryGatewayAdapter is single-process. Pass a RedisGatewayAdapter to broadcast across multiple processes:

Redis adapter
import { createWsPlugin, RedisGatewayAdapter } from '@rasenganjs/ws'; import Redis from 'ioredis'; app.registerPlugin( createWsPlugin({ adapter: new RedisGatewayAdapter({ client: new Redis() }), }) );

Full Documentation

For the complete API — GatewayClient, GatewayServer, heartbeat configuration, and broadcasting from outside a connection's context — see WebSocket Gateways under the Server docs.

Community

Join the Rasengan.js community to get support, ask questions, and share your projects:

Let's build something amazing with Rasengan.js! 🚀

License

This package is MIT licensed.