Skip to main content

Quik Framework :: WebSocket Base

Provides the framework-level WebSocket heartbeat implementation. The heartbeat uses normal JSON WebSocket messages so browser clients and app clients can respond without access to native protocol ping frames.

Installation

npm install @quik/websocket

Configuration

  • WEBSOCKET_PATH (default: /ws)
  • WEBSOCKET_HEARTBEAT_ENABLED (default: true)
  • WEBSOCKET_HEARTBEAT_INTERVAL_MILLISECONDS (default: 30000)
  • WEBSOCKET_HEARTBEAT_TIMEOUT_MILLISECONDS (default: 10000)
  • WEBSOCKET_HEARTBEAT_PING_MESSAGE_TYPE (default: quik.websocket.ping)
  • WEBSOCKET_HEARTBEAT_PONG_MESSAGE_TYPE (default: quik.websocket.pong)

Client Usage

Use the helper in browser or app clients to answer heartbeat pings:

import { attachWebSocketHeartbeat } from '@quik/websocket';

const socket = new WebSocket('ws://localhost:7200/ws');
const detachHeartbeat = attachWebSocketHeartbeat(socket);

Call detachHeartbeat() when the socket is no longer used.

API Highlights

  • QWebSocketHeartbeatService tracks peers and sends application-level ping messages.
  • attachWebSocketHeartbeat() responds to heartbeat pings in browser and app clients.
  • IQWebSocketEngine defines the pluggable server adapter contract.
  • getWebSocketEngine() returns the configured adapter instance.

API Reference

Generated API documentation is available in the websocket API section.