WebSocketPlugin(options?: WebSocketPluginOptions): IPlugin
Creates the WebSocketPlugin.
Registers an IWebSocketService under CAPABILITIES.WEBSOCKET.
Single instance only — the kernel's plugin resolver throws at startup on a
duplicate name or a duplicate capability provider.
The plugin resolves the application's IHttpAdapter and installs
its upgrade router there. When the adapter implements no upgrade seam, the
service still registers (so one codebase deploys everywhere) but reports
available: false and fails route() with a WebSocketUnavailableError.
Example 1
Example 1
import { WebSocketPlugin } from '@setu-ts/websocket-plugin'; import { CAPABILITIES, type IWebSocketService } from '@setu-ts/common'; app.register(WebSocketPlugin({ heartbeatMs: 30_000, idleTimeoutMs: 90_000 })); const ws = app.services.get<IWebSocketService>(CAPABILITIES.WEBSOCKET); ws.route('/ws/chat', { onOpen: (conn) => ws.room('lobby').add(conn), onMessage: (conn, data) => ws.room('lobby').broadcast(data, { except: conn }), });
optional
options: WebSocketPluginOptions
Plugin configuration