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.
Gateway extends Provider from @rasenganjs/server, and gateways are
registered through that package's module plugin system. This isn't a
standalone WebSocket library — it's a convenience layer over Rasengan Server's
app.websocket().
Installation
npm install @rasenganjs/ws
Usage
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] });
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 }); }); } }
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:
import { createWsPlugin, RedisGatewayAdapter } from '@rasenganjs/ws'; import Redis from 'ioredis'; app.registerPlugin( createWsPlugin({ adapter: new RedisGatewayAdapter({ client: new Redis() }), }) );
Messages use a minimal { event, data } JSON envelope this package defines itself — plain WebSocket has no built-in concept of a named event. It isn't compatible with the Socket.IO wire protocol.
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:
-
GitHub Discussions
– Ask questions and share ideas. -
X (Twitter)
– Stay updated with the latest news. -
Linkedin
– Follow the company page.
Let's build something amazing with Rasengan.js! 🚀
License
This package is MIT licensed.
