Setu-TS
    Preparing search index...

    Function WebSocketPlugin

    • 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.

      Parameters

      Returns IPlugin

      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 }),
      });

      If idleTimeoutMs is set without a heartbeatMs to sweep on

      0.1.0