@banana-universe/plugin-websocket
v0.1.1
Published
WebSocket plugin for BananaJS — @WsController, @OnConnect, @OnMessage decorators backed by the ws library.
Readme
@banana-universe/plugin-websocket
WebSocket plugin for BananaJS using ws with decorator-based handlers.
Homepage
https://surya-manne.github.io/banana-universe/
Installation
npm install @banana-universe/plugin-websocket ws zodCore API Surface
new WebSocketPlugin({ path?, controllers })WsController,OnConnect,OnDisconnect,OnMessage,WsBody
Minimal Working Setup
import { z } from 'zod';
import { BananaApp } from '@banana-universe/bananajs';
import { WebSocketPlugin, WsController, OnMessage, WsBody } from '@banana-universe/plugin-websocket';
@WsController('/chat')
class ChatController {
@OnMessage('message')
onMessage(@WsBody(z.object({ text: z.string().min(1) })) payload: { text: string }) {
return { ok: true, echo: payload.text };
}
}
const wsPlugin = new WebSocketPlugin({ path: '/ws', controllers: [ChatController] });
const app = await BananaApp.create({ controllers: [], plugins: [wsPlugin] });
const server = app.getInstance().listen(3000);
wsPlugin.attachToServer(server);Documentation
- Project docs: https://surya-manne.github.io/banana-universe/
License
MIT
