agentleFS
NikoxkxNikoxkx/Agent-Skills/skills/web-development/websocket-integration/SKILL.md

websocket-integration

Skill1 starsChanged 5 months agoApache-2.0View on GitHub

Integrates WebSocket real-time communication into a web application. Use when implementing live features like chat, notifications, collaborative editing, or live dashboards.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check browser console for clean connection lifecycle.

    line 59

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Overview

Provides complete guidance and code for integrating native WebSockets or Socket.io into web apps, including reconnection with exponential backoff, message envelope format, React hook for lifecycle management, server-side setup (Node/ws or Socket.io), error handling, and authentication patterns for real-time features.

When to Use This Skill

  • Adding live chat, notifications, presence indicators, collaborative editing, or live data dashboards.
  • The user mentions "real-time", "WebSocket", "live updates", "push", or "socket".

Prerequisites

  • Backend that can run a WebSocket server (Node.js, Deno, or cloud service like Pusher, Ably, Supabase Realtime).
  • Frontend framework (React, vanilla, etc.).
  • For production: load balancer that supports WebSocket upgrade (Nginx, ALB, etc.).

Steps

  1. Choose transport: Native WebSocket (lightweight) vs Socket.io (more features, fallback).
  2. Define message protocol (JSON envelope):
    { "type": "chat.message", "payload": {...}, "id": "uuid", "timestamp": "..." }
  3. Client implementation:
    • Connection, onopen, onmessage, onerror, onclose.
    • Reconnection logic with backoff (max 5 attempts, then show "reconnecting" UI).
    • Heartbeat / ping-pong for keepalive.
  4. React hook (useWebSocket): manages connection, auto-reconnect, typed message handlers.
  5. Server side: auth on connection (JWT in query or subprotocol), room management, broadcast.
  6. Security: validate all incoming messages, rate limit, authenticate every connection.
  7. Output: full hook, example chat component, server route, deployment notes.

Examples

Complete useWebSocket.ts hook, a simple chat UI, and a minimal Node + ws server example are provided.

Edge Cases & Error Handling

  • Network drops: exponential backoff + user notification.
  • Auth expiration: refresh token and reconnect.
  • Large messages: chunk or use binary when appropriate.
  • Browser tab sleep: handle visibilitychange to pause/reconnect.

Verification

  1. Open two browser tabs — messages appear in real time.
  2. Kill the server — client shows reconnecting UI and recovers when server restarts.
  3. Check browser console for clean connection lifecycle.
  4. Success: Real-time features work reliably with graceful degradation.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.