Events
@veloxts/events provides real-time communication.
Installation
Section titled “Installation”pnpm add @veloxts/eventsQuick Start
Section titled “Quick Start”import { eventsPlugin } from '@veloxts/events';
app.register(eventsPlugin, { driver: 'ws', path: '/ws',});Broadcasting
Section titled “Broadcasting”// Public channelawait ctx.events.broadcast('orders', 'order.created', { orderId: '123', total: 99.99,});
// Private channel (user-specific)await ctx.events.broadcast(`user.${userId}`, 'notification', { message: 'New message received',});Drivers
Section titled “Drivers”WebSocket
Section titled “WebSocket”eventsPlugin({ driver: 'ws', path: '/ws', redis: process.env.REDIS_URL, // Optional for scaling})Server-Sent Events
Section titled “Server-Sent Events”eventsPlugin({ driver: 'sse', path: '/events',})Client Usage
Section titled “Client Usage”// WebSocketconst ws = new WebSocket('ws://localhost:3030/ws');ws.onmessage = (event) => { const data = JSON.parse(event.data); console.log(data.event, data.payload);};
// Subscribe to channelws.send(JSON.stringify({ type: 'subscribe', channel: 'orders' }));Next Steps
Section titled “Next Steps”- Ecosystem Overview - All packages