Optionaloptions: WebSocketPluginOptions
Plugin configuration
The plugin instance
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 }),
});
Creates the WebSocketPlugin.
Registers an
IWebSocketServiceunderCAPABILITIES.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
IHttpAdapterand installs its upgrade router there. When the adapter implements no upgrade seam, the service still registers (so one codebase deploys everywhere) but reportsavailable: falseand failsroute()with aWebSocketUnavailableError.