---
name: "ws-native-websockets-heartbeat"
description: "Deploy high-density WebSocket servers in Node.js with strict ping/pong connection healthchecks."
metadata:
  author: "WebSockets"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "setup ws websocket server"
  - "implement websocket heartbeat ping pong"
  - "handle dead websocket connections"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# ws High-Performance Native WebSockets & Heartbeat Pings

Configures ws package: creating WebSocketServer instances, managing client connection pools, implementing heartbeat ping/pong intervals to detect dead sockets, message compression (permessage-deflate), and rate limiting.

## When to Invoke
Invoke this skill whenever you need to:
- setup ws websocket server
- implement websocket heartbeat ping pong
- handle dead websocket connections

## Execution SOP & Rules
1. Initialize: const wss = new WebSocketServer({ port: 8080 }).
2. Attach heartbeat: setInterval(() => { wss.clients.forEach(ws => { if (!ws.isAlive) return ws.terminate(); ws.isAlive = false; ws.ping(); }); }, 30000).
3. Listen for pong: ws.on('pong', () => { ws.isAlive = true; }).
4. Broadcast messages: for (const client of wss.clients) { if (client.readyState === WebSocket.OPEN) client.send(data); }.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
